1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "editsrc.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "scitems.hxx" 34*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 35*cdf0e10cSrcweir #include <editeng/unofored.hxx> 36*cdf0e10cSrcweir #include <svx/svdpage.hxx> 37*cdf0e10cSrcweir #include <svx/svditer.hxx> 38*cdf0e10cSrcweir #include <svx/svdocapt.hxx> 39*cdf0e10cSrcweir #include <editeng/outlobj.hxx> 40*cdf0e10cSrcweir #include <editeng/editobj.hxx> 41*cdf0e10cSrcweir #include <editeng/outliner.hxx> 42*cdf0e10cSrcweir #include "textuno.hxx" 43*cdf0e10cSrcweir #include "editutil.hxx" 44*cdf0e10cSrcweir #include "docsh.hxx" 45*cdf0e10cSrcweir #include "docfunc.hxx" 46*cdf0e10cSrcweir #include "hints.hxx" 47*cdf0e10cSrcweir #include "patattr.hxx" 48*cdf0e10cSrcweir #include "unoguard.hxx" 49*cdf0e10cSrcweir #include "drwlayer.hxx" 50*cdf0e10cSrcweir #include "userdat.hxx" 51*cdf0e10cSrcweir #include "postit.hxx" 52*cdf0e10cSrcweir #include "AccessibleText.hxx" 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //------------------------------------------------------------------------ 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir TYPEINIT1( ScHeaderFooterChangedHint, SfxHint ); 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir ScHeaderFooterChangedHint::ScHeaderFooterChangedHint(sal_uInt16 nP) : 59*cdf0e10cSrcweir nPart( nP ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir ScHeaderFooterChangedHint::~ScHeaderFooterChangedHint() 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir //------------------------------------------------------------------------ 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir ScSharedHeaderFooterEditSource::ScSharedHeaderFooterEditSource( ScHeaderFooterTextData* pData ) : 70*cdf0e10cSrcweir pTextData( pData ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir // pTextData is held by the ScHeaderFooterTextObj. 73*cdf0e10cSrcweir // Text range and cursor keep a reference to their parent text, so the text object is 74*cdf0e10cSrcweir // always alive and the TextData is valid as long as there are children. 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir ScSharedHeaderFooterEditSource::~ScSharedHeaderFooterEditSource() 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir SvxEditSource* ScSharedHeaderFooterEditSource::Clone() const 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir return new ScSharedHeaderFooterEditSource( pTextData ); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir SvxTextForwarder* ScSharedHeaderFooterEditSource::GetTextForwarder() 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir return pTextData->GetTextForwarder(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir void ScSharedHeaderFooterEditSource::UpdateData() 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir pTextData->UpdateData(); 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir ScEditEngineDefaulter* ScSharedHeaderFooterEditSource::GetEditEngine() 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir return pTextData->GetEditEngine(); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //------------------------------------------------------------------------ 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir // each ScHeaderFooterEditSource object has its own ScHeaderFooterTextData 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj* pContent, 106*cdf0e10cSrcweir sal_uInt16 nP ) : 107*cdf0e10cSrcweir ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( *pContent, nP ) ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj& rContent, 112*cdf0e10cSrcweir sal_uInt16 nP ) : 113*cdf0e10cSrcweir ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( rContent, nP ) ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir ScHeaderFooterEditSource::~ScHeaderFooterEditSource() 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir delete GetTextData(); // not accessed in ScSharedHeaderFooterEditSource dtor 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir SvxEditSource* ScHeaderFooterEditSource::Clone() const 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir const ScHeaderFooterTextData* pData = GetTextData(); 125*cdf0e10cSrcweir return new ScHeaderFooterEditSource( pData->GetContentObj(), pData->GetPart() ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //------------------------------------------------------------------------ 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir ScSharedCellEditSource::ScSharedCellEditSource( ScCellTextData* pData ) : 131*cdf0e10cSrcweir pCellTextData( pData ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir // pCellTextData is part of the ScCellTextObj. 134*cdf0e10cSrcweir // Text range and cursor keep a reference to their parent text, so the text object is 135*cdf0e10cSrcweir // always alive and the CellTextData is valid as long as there are children. 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir ScSharedCellEditSource::~ScSharedCellEditSource() 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir SvxEditSource* ScSharedCellEditSource::Clone() const 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir return new ScSharedCellEditSource( pCellTextData ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir SvxTextForwarder* ScSharedCellEditSource::GetTextForwarder() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir return pCellTextData->GetTextForwarder(); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir void ScSharedCellEditSource::UpdateData() 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir pCellTextData->UpdateData(); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir void ScSharedCellEditSource::SetDoUpdateData(sal_Bool bValue) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir pCellTextData->SetDoUpdate(bValue); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir sal_Bool ScSharedCellEditSource::IsDirty() const 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir return pCellTextData->IsDirty(); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir ScEditEngineDefaulter* ScSharedCellEditSource::GetEditEngine() 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir return pCellTextData->GetEditEngine(); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir //------------------------------------------------------------------------ 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // each ScCellEditSource object has its own ScCellTextData 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir ScCellEditSource::ScCellEditSource( ScDocShell* pDocSh, const ScAddress& rP ) : 177*cdf0e10cSrcweir ScSharedCellEditSource( new ScCellTextData( pDocSh, rP ) ) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir ScCellEditSource::~ScCellEditSource() 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir delete GetCellTextData(); // not accessed in ScSharedCellEditSource dtor 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir SvxEditSource* ScCellEditSource::Clone() const 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir const ScCellTextData* pData = GetCellTextData(); 189*cdf0e10cSrcweir return new ScCellEditSource( pData->GetDocShell(), pData->GetCellPos() ); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir //------------------------------------------------------------------------ 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell* pDocSh, const ScAddress& rP) : 195*cdf0e10cSrcweir pDocShell( pDocSh ), 196*cdf0e10cSrcweir aCellPos( rP ), 197*cdf0e10cSrcweir pEditEngine( NULL ), 198*cdf0e10cSrcweir pForwarder( NULL ), 199*cdf0e10cSrcweir bDataValid( sal_False ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir if (pDocShell) 202*cdf0e10cSrcweir pDocShell->GetDocument()->AddUnoObject(*this); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir ScAnnotationEditSource::~ScAnnotationEditSource() 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir ScUnoGuard aGuard; // needed for EditEngine dtor 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir if (pDocShell) 210*cdf0e10cSrcweir pDocShell->GetDocument()->RemoveUnoObject(*this); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir delete pForwarder; 213*cdf0e10cSrcweir delete pEditEngine; 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir SvxEditSource* ScAnnotationEditSource::Clone() const 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir return new ScAnnotationEditSource( pDocShell, aCellPos ); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir SdrObject* ScAnnotationEditSource::GetCaptionObj() 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir ScPostIt* pNote = pDocShell->GetDocument()->GetNote( aCellPos ); 224*cdf0e10cSrcweir return pNote ? pNote->GetOrCreateCaption( aCellPos ) : 0; 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir SvxTextForwarder* ScAnnotationEditSource::GetTextForwarder() 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir if (!pEditEngine) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir // Notizen haben keine Felder 232*cdf0e10cSrcweir if ( pDocShell ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir pEditEngine = new ScNoteEditEngine( pDocShell->GetDocument()->GetNoteEngine() ); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir else 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir SfxItemPool* pEnginePool = EditEngine::CreatePool(); 239*cdf0e10cSrcweir pEnginePool->FreezeIdRanges(); 240*cdf0e10cSrcweir pEditEngine = new ScEditEngineDefaulter( pEnginePool, sal_True ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir pForwarder = new SvxEditEngineForwarder(*pEditEngine); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir if (bDataValid) 246*cdf0e10cSrcweir return pForwarder; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir if ( pDocShell ) 249*cdf0e10cSrcweir if ( ScPostIt* pNote = pDocShell->GetDocument()->GetNote( aCellPos ) ) 250*cdf0e10cSrcweir if ( const EditTextObject* pEditObj = pNote->GetEditTextObject() ) 251*cdf0e10cSrcweir pEditEngine->SetText( *pEditObj ); // incl. Umbrueche 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir bDataValid = sal_True; 254*cdf0e10cSrcweir return pForwarder; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir void ScAnnotationEditSource::UpdateData() 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir if ( pDocShell && pEditEngine ) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir ScDocShellModificator aModificator( *pDocShell ); 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir if( SdrObject* pObj = GetCaptionObj() ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir EditTextObject* pEditObj = pEditEngine->CreateTextObject(); 266*cdf0e10cSrcweir OutlinerParaObject* pOPO = new OutlinerParaObject( *pEditObj ); 267*cdf0e10cSrcweir delete pEditObj; 268*cdf0e10cSrcweir pOPO->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT ); 269*cdf0e10cSrcweir pObj->NbcSetOutlinerParaObject( pOPO ); 270*cdf0e10cSrcweir pObj->ActionChanged(); 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir //! Undo !!! 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir aModificator.SetDocumentModified(); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir // bDataValid wird bei SetDocumentModified zurueckgesetzt 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir void ScAnnotationEditSource::Notify( SfxBroadcaster&, const SfxHint& rHint ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir if ( rHint.ISA( ScUpdateRefHint ) ) 284*cdf0e10cSrcweir { 285*cdf0e10cSrcweir // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir //! Ref-Update 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir else if ( rHint.ISA( SfxSimpleHint ) ) 290*cdf0e10cSrcweir { 291*cdf0e10cSrcweir sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId(); 292*cdf0e10cSrcweir if ( nId == SFX_HINT_DYING ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir pDocShell = NULL; // ungueltig geworden 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir DELETEZ( pForwarder ); 297*cdf0e10cSrcweir DELETEZ( pEditEngine ); // EditEngine uses document's pool 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir else if ( nId == SFX_HINT_DATACHANGED ) 300*cdf0e10cSrcweir bDataValid = sal_False; // Text muss neu geholt werden 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir //------------------------------------------------------------------------ 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder* pForw ) : 307*cdf0e10cSrcweir pForwarder( pForw ) 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir // The same forwarder (and EditEngine) is shared by all children of the same Text object. 310*cdf0e10cSrcweir // Text range and cursor keep a reference to their parent text, so the text object is 311*cdf0e10cSrcweir // always alive and the forwarder is valid as long as there are children. 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir ScSimpleEditSource::~ScSimpleEditSource() 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir SvxEditSource* ScSimpleEditSource::Clone() const 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir return new ScSimpleEditSource( pForwarder ); 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir SvxTextForwarder* ScSimpleEditSource::GetTextForwarder() 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir return pForwarder; 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir void ScSimpleEditSource::UpdateData() 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir // nothing 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir //------------------------------------------------------------------------ 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::auto_ptr < ScAccessibleTextData > pAccessibleCellTextData ) 336*cdf0e10cSrcweir : mpAccessibleTextData(pAccessibleCellTextData) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir ScAccessibilityEditSource::~ScAccessibilityEditSource() 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir SvxEditSource* ScAccessibilityEditSource::Clone() const 345*cdf0e10cSrcweir { 346*cdf0e10cSrcweir return new ScAccessibilityEditSource(::std::auto_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone())); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir SvxTextForwarder* ScAccessibilityEditSource::GetTextForwarder() 350*cdf0e10cSrcweir { 351*cdf0e10cSrcweir return mpAccessibleTextData->GetTextForwarder(); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir SvxViewForwarder* ScAccessibilityEditSource::GetViewForwarder() 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir return mpAccessibleTextData->GetViewForwarder(); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir SvxEditViewForwarder* ScAccessibilityEditSource::GetEditViewForwarder( sal_Bool bCreate ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir return mpAccessibleTextData->GetEditViewForwarder(bCreate); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir void ScAccessibilityEditSource::UpdateData() 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir mpAccessibleTextData->UpdateData(); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir SfxBroadcaster& ScAccessibilityEditSource::GetBroadcaster() const 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir return mpAccessibleTextData->GetBroadcaster(); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374