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