1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editsrc.cxx,v $
10 * $Revision: 1.26.128.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "editsrc.hxx"
36 #include "scitems.hxx"
37 #include <svx/eeitem.hxx>
38 #include <svx/unofored.hxx>
39 #include <svx/svdpage.hxx>
40 #include <svx/svditer.hxx>
41 #include <svx/svdocapt.hxx>
42 #include <svx/outlobj.hxx>
43 #include <svx/editobj.hxx>
45 #include "textuno.hxx"
46 #include "editutil.hxx"
48 #include "docfunc.hxx"
50 #include "patattr.hxx"
51 #include "unoguard.hxx"
52 #include "drwlayer.hxx"
53 #include "userdat.hxx"
55 #include "AccessibleText.hxx"
57 //------------------------------------------------------------------------
59 TYPEINIT1( ScHeaderFooterChangedHint
, SfxHint
);
61 ScHeaderFooterChangedHint::ScHeaderFooterChangedHint(USHORT nP
) :
66 ScHeaderFooterChangedHint::~ScHeaderFooterChangedHint()
70 //------------------------------------------------------------------------
72 ScSharedHeaderFooterEditSource::ScSharedHeaderFooterEditSource( ScHeaderFooterTextData
* pData
) :
75 // pTextData is held by the ScHeaderFooterTextObj.
76 // Text range and cursor keep a reference to their parent text, so the text object is
77 // always alive and the TextData is valid as long as there are children.
80 ScSharedHeaderFooterEditSource::~ScSharedHeaderFooterEditSource()
84 SvxEditSource
* ScSharedHeaderFooterEditSource::Clone() const
86 return new ScSharedHeaderFooterEditSource( pTextData
);
89 SvxTextForwarder
* ScSharedHeaderFooterEditSource::GetTextForwarder()
91 return pTextData
->GetTextForwarder();
94 void ScSharedHeaderFooterEditSource::UpdateData()
96 pTextData
->UpdateData();
99 ScEditEngineDefaulter
* ScSharedHeaderFooterEditSource::GetEditEngine()
101 return pTextData
->GetEditEngine();
104 //------------------------------------------------------------------------
106 // each ScHeaderFooterEditSource object has its own ScHeaderFooterTextData
108 ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj
* pContent
,
110 ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( *pContent
, nP
) )
114 ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj
& rContent
,
116 ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( rContent
, nP
) )
120 ScHeaderFooterEditSource::~ScHeaderFooterEditSource()
122 delete GetTextData(); // not accessed in ScSharedHeaderFooterEditSource dtor
125 SvxEditSource
* ScHeaderFooterEditSource::Clone() const
127 const ScHeaderFooterTextData
* pData
= GetTextData();
128 return new ScHeaderFooterEditSource( pData
->GetContentObj(), pData
->GetPart() );
131 //------------------------------------------------------------------------
133 ScSharedCellEditSource::ScSharedCellEditSource( ScCellTextData
* pData
) :
134 pCellTextData( pData
)
136 // pCellTextData is part of the ScCellTextObj.
137 // Text range and cursor keep a reference to their parent text, so the text object is
138 // always alive and the CellTextData is valid as long as there are children.
141 ScSharedCellEditSource::~ScSharedCellEditSource()
145 SvxEditSource
* ScSharedCellEditSource::Clone() const
147 return new ScSharedCellEditSource( pCellTextData
);
150 SvxTextForwarder
* ScSharedCellEditSource::GetTextForwarder()
152 return pCellTextData
->GetTextForwarder();
155 void ScSharedCellEditSource::UpdateData()
157 pCellTextData
->UpdateData();
160 void ScSharedCellEditSource::SetDoUpdateData(sal_Bool bValue
)
162 pCellTextData
->SetDoUpdate(bValue
);
165 sal_Bool
ScSharedCellEditSource::IsDirty() const
167 return pCellTextData
->IsDirty();
170 ScEditEngineDefaulter
* ScSharedCellEditSource::GetEditEngine()
172 return pCellTextData
->GetEditEngine();
175 //------------------------------------------------------------------------
177 // each ScCellEditSource object has its own ScCellTextData
179 ScCellEditSource::ScCellEditSource( ScDocShell
* pDocSh
, const ScAddress
& rP
) :
180 ScSharedCellEditSource( new ScCellTextData( pDocSh
, rP
) )
184 ScCellEditSource::~ScCellEditSource()
186 delete GetCellTextData(); // not accessed in ScSharedCellEditSource dtor
189 SvxEditSource
* ScCellEditSource::Clone() const
191 const ScCellTextData
* pData
= GetCellTextData();
192 return new ScCellEditSource( pData
->GetDocShell(), pData
->GetCellPos() );
195 //------------------------------------------------------------------------
197 ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell
* pDocSh
, const ScAddress
& rP
) :
205 pDocShell
->GetDocument()->AddUnoObject(*this);
208 ScAnnotationEditSource::~ScAnnotationEditSource()
210 ScUnoGuard aGuard
; // needed for EditEngine dtor
213 pDocShell
->GetDocument()->RemoveUnoObject(*this);
219 SvxEditSource
* ScAnnotationEditSource::Clone() const
221 return new ScAnnotationEditSource( pDocShell
, aCellPos
);
224 SdrObject
* ScAnnotationEditSource::GetCaptionObj()
226 ScPostIt
* pNote
= pDocShell
->GetDocument()->GetNote( aCellPos
);
227 return pNote
? pNote
->GetOrCreateCaption( aCellPos
) : 0;
230 SvxTextForwarder
* ScAnnotationEditSource::GetTextForwarder()
234 // Notizen haben keine Felder
237 pEditEngine
= new ScNoteEditEngine( pDocShell
->GetDocument()->GetNoteEngine() );
241 SfxItemPool
* pEnginePool
= EditEngine::CreatePool();
242 pEnginePool
->FreezeIdRanges();
243 pEditEngine
= new ScEditEngineDefaulter( pEnginePool
, TRUE
);
245 pForwarder
= new SvxEditEngineForwarder(*pEditEngine
);
252 if ( ScPostIt
* pNote
= pDocShell
->GetDocument()->GetNote( aCellPos
) )
253 if ( const EditTextObject
* pEditObj
= pNote
->GetEditTextObject() )
254 pEditEngine
->SetText( *pEditObj
); // incl. Umbrueche
260 void ScAnnotationEditSource::UpdateData()
262 if ( pDocShell
&& pEditEngine
)
264 ScDocShellModificator
aModificator( *pDocShell
);
266 if( SdrObject
* pObj
= GetCaptionObj() )
268 EditTextObject
* pEditObj
= pEditEngine
->CreateTextObject();
269 OutlinerParaObject
* pOPO
= new OutlinerParaObject( *pEditObj
);
271 pOPO
->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT
);
272 pObj
->NbcSetOutlinerParaObject( pOPO
);
273 pObj
->ActionChanged();
278 aModificator
.SetDocumentModified();
280 // bDataValid wird bei SetDocumentModified zurueckgesetzt
284 void ScAnnotationEditSource::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
286 if ( rHint
.ISA( ScUpdateRefHint
) )
288 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
292 else if ( rHint
.ISA( SfxSimpleHint
) )
294 ULONG nId
= ((const SfxSimpleHint
&)rHint
).GetId();
295 if ( nId
== SFX_HINT_DYING
)
297 pDocShell
= NULL
; // ungueltig geworden
299 DELETEZ( pForwarder
);
300 DELETEZ( pEditEngine
); // EditEngine uses document's pool
302 else if ( nId
== SFX_HINT_DATACHANGED
)
303 bDataValid
= FALSE
; // Text muss neu geholt werden
307 //------------------------------------------------------------------------
309 ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder
* pForw
) :
312 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
313 // Text range and cursor keep a reference to their parent text, so the text object is
314 // always alive and the forwarder is valid as long as there are children.
317 ScSimpleEditSource::~ScSimpleEditSource()
321 SvxEditSource
* ScSimpleEditSource::Clone() const
323 return new ScSimpleEditSource( pForwarder
);
326 SvxTextForwarder
* ScSimpleEditSource::GetTextForwarder()
331 void ScSimpleEditSource::UpdateData()
336 //------------------------------------------------------------------------
338 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::auto_ptr
< ScAccessibleTextData
> pAccessibleCellTextData
)
339 : mpAccessibleTextData(pAccessibleCellTextData
)
343 ScAccessibilityEditSource::~ScAccessibilityEditSource()
347 SvxEditSource
* ScAccessibilityEditSource::Clone() const
349 return new ScAccessibilityEditSource(::std::auto_ptr
< ScAccessibleTextData
> (mpAccessibleTextData
->Clone()));
352 SvxTextForwarder
* ScAccessibilityEditSource::GetTextForwarder()
354 return mpAccessibleTextData
->GetTextForwarder();
357 SvxViewForwarder
* ScAccessibilityEditSource::GetViewForwarder()
359 return mpAccessibleTextData
->GetViewForwarder();
362 SvxEditViewForwarder
* ScAccessibilityEditSource::GetEditViewForwarder( sal_Bool bCreate
)
364 return mpAccessibleTextData
->GetEditViewForwarder(bCreate
);
367 void ScAccessibilityEditSource::UpdateData()
369 mpAccessibleTextData
->UpdateData();
372 SfxBroadcaster
& ScAccessibilityEditSource::GetBroadcaster() const
374 return mpAccessibleTextData
->GetBroadcaster();