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