Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / editsrc.cxx
blobb48ae1ba33cd4c8b30de4c2db900e696e2045ea1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "editsrc.hxx"
23 #include "scitems.hxx"
24 #include <editeng/eeitem.hxx>
25 #include <editeng/unofored.hxx>
26 #include <vcl/svapp.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svditer.hxx>
29 #include <svx/svdocapt.hxx>
30 #include <editeng/outlobj.hxx>
31 #include <editeng/editobj.hxx>
32 #include <editeng/outliner.hxx>
33 #include "textuno.hxx"
34 #include "editutil.hxx"
35 #include "docsh.hxx"
36 #include "docfunc.hxx"
37 #include "hints.hxx"
38 #include "patattr.hxx"
39 #include "drwlayer.hxx"
40 #include "userdat.hxx"
41 #include "postit.hxx"
42 #include "AccessibleText.hxx"
44 ScHeaderFooterEditSource::ScHeaderFooterEditSource(ScHeaderFooterTextData& rData) :
45 mrTextData(rData) {}
47 ScHeaderFooterEditSource::~ScHeaderFooterEditSource() {}
49 ScEditEngineDefaulter* ScHeaderFooterEditSource::GetEditEngine()
51 return mrTextData.GetEditEngine();
54 SvxEditSource* ScHeaderFooterEditSource::Clone() const
56 return new ScHeaderFooterEditSource(mrTextData);
59 SvxTextForwarder* ScHeaderFooterEditSource::GetTextForwarder()
61 return mrTextData.GetTextForwarder();
64 void ScHeaderFooterEditSource::UpdateData()
66 mrTextData.UpdateData();
69 //------------------------------------------------------------------------
71 ScCellEditSource::ScCellEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
72 pCellTextData(new ScCellTextData(pDocSh, rP)) {}
74 ScCellEditSource::~ScCellEditSource()
76 delete pCellTextData;
79 SvxEditSource* ScCellEditSource::Clone() const
81 return new ScCellEditSource(pCellTextData->GetDocShell(), pCellTextData->GetCellPos());
84 SvxTextForwarder* ScCellEditSource::GetTextForwarder()
86 return pCellTextData->GetTextForwarder();
89 void ScCellEditSource::UpdateData()
91 pCellTextData->UpdateData();
94 void ScCellEditSource::SetDoUpdateData(bool bValue)
96 pCellTextData->SetDoUpdate(bValue);
99 bool ScCellEditSource::IsDirty() const
101 return pCellTextData->IsDirty();
104 ScEditEngineDefaulter* ScCellEditSource::GetEditEngine()
106 return pCellTextData->GetEditEngine();
109 //------------------------------------------------------------------------
111 ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
112 pDocShell( pDocSh ),
113 aCellPos( rP ),
114 pEditEngine( NULL ),
115 pForwarder( NULL ),
116 bDataValid( false )
118 if (pDocShell)
119 pDocShell->GetDocument()->AddUnoObject(*this);
122 ScAnnotationEditSource::~ScAnnotationEditSource()
124 SolarMutexGuard aGuard; // needed for EditEngine dtor
126 if (pDocShell)
127 pDocShell->GetDocument()->RemoveUnoObject(*this);
129 delete pForwarder;
130 delete pEditEngine;
133 SvxEditSource* ScAnnotationEditSource::Clone() const
135 return new ScAnnotationEditSource( pDocShell, aCellPos );
138 SdrObject* ScAnnotationEditSource::GetCaptionObj()
140 ScPostIt* pNote = pDocShell->GetDocument()->GetNote(aCellPos);
141 return pNote ? pNote->GetOrCreateCaption( aCellPos ) : 0;
144 SvxTextForwarder* ScAnnotationEditSource::GetTextForwarder()
146 if (!pEditEngine)
148 // Notizen haben keine Felder
149 if ( pDocShell )
151 pEditEngine = new ScNoteEditEngine( pDocShell->GetDocument()->GetNoteEngine() );
153 else
155 SfxItemPool* pEnginePool = EditEngine::CreatePool();
156 pEnginePool->FreezeIdRanges();
157 pEditEngine = new ScEditEngineDefaulter( pEnginePool, sal_True );
159 pForwarder = new SvxEditEngineForwarder(*pEditEngine);
162 if (bDataValid)
163 return pForwarder;
165 if ( pDocShell )
166 if ( ScPostIt* pNote = pDocShell->GetDocument()->GetNote(aCellPos) )
167 if ( const EditTextObject* pEditObj = pNote->GetEditTextObject() )
168 pEditEngine->SetText( *pEditObj ); // incl. Umbrueche
170 bDataValid = sal_True;
171 return pForwarder;
174 void ScAnnotationEditSource::UpdateData()
176 if ( pDocShell && pEditEngine )
178 ScDocShellModificator aModificator( *pDocShell );
180 if( SdrObject* pObj = GetCaptionObj() )
182 EditTextObject* pEditObj = pEditEngine->CreateTextObject();
183 OutlinerParaObject* pOPO = new OutlinerParaObject( *pEditObj );
184 delete pEditObj;
185 pOPO->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT );
186 pObj->NbcSetOutlinerParaObject( pOPO );
187 pObj->ActionChanged();
190 //! Undo !!!
192 aModificator.SetDocumentModified();
194 // bDataValid wird bei SetDocumentModified zurueckgesetzt
198 void ScAnnotationEditSource::Notify( SfxBroadcaster&, const SfxHint& rHint )
200 if ( rHint.ISA( ScUpdateRefHint ) )
202 //! Ref-Update
204 else if ( rHint.ISA( SfxSimpleHint ) )
206 sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
207 if ( nId == SFX_HINT_DYING )
209 pDocShell = NULL; // ungueltig geworden
211 DELETEZ( pForwarder );
212 DELETEZ( pEditEngine ); // EditEngine uses document's pool
214 else if ( nId == SFX_HINT_DATACHANGED )
215 bDataValid = false; // Text muss neu geholt werden
219 //------------------------------------------------------------------------
221 ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder* pForw ) :
222 pForwarder( pForw )
224 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
225 // Text range and cursor keep a reference to their parent text, so the text object is
226 // always alive and the forwarder is valid as long as there are children.
229 ScSimpleEditSource::~ScSimpleEditSource()
233 SvxEditSource* ScSimpleEditSource::Clone() const
235 return new ScSimpleEditSource( pForwarder );
238 SvxTextForwarder* ScSimpleEditSource::GetTextForwarder()
240 return pForwarder;
243 void ScSimpleEditSource::UpdateData()
245 // nothing
248 //------------------------------------------------------------------------
250 SAL_WNODEPRECATED_DECLARATIONS_PUSH
251 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::auto_ptr < ScAccessibleTextData > pAccessibleCellTextData )
252 : mpAccessibleTextData(pAccessibleCellTextData)
255 SAL_WNODEPRECATED_DECLARATIONS_POP
257 ScAccessibilityEditSource::~ScAccessibilityEditSource()
261 SAL_WNODEPRECATED_DECLARATIONS_PUSH
262 SvxEditSource* ScAccessibilityEditSource::Clone() const
264 return new ScAccessibilityEditSource(::std::auto_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone()));
266 SAL_WNODEPRECATED_DECLARATIONS_POP
268 SvxTextForwarder* ScAccessibilityEditSource::GetTextForwarder()
270 return mpAccessibleTextData->GetTextForwarder();
273 SvxViewForwarder* ScAccessibilityEditSource::GetViewForwarder()
275 return mpAccessibleTextData->GetViewForwarder();
278 SvxEditViewForwarder* ScAccessibilityEditSource::GetEditViewForwarder( sal_Bool bCreate )
280 return mpAccessibleTextData->GetEditViewForwarder(bCreate);
283 void ScAccessibilityEditSource::UpdateData()
285 mpAccessibleTextData->UpdateData();
288 SfxBroadcaster& ScAccessibilityEditSource::GetBroadcaster() const
290 return mpAccessibleTextData->GetBroadcaster();
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */