reintroduce ScCaptionPtr
[LibreOffice.git] / sc / source / ui / unoobj / editsrc.cxx
blob2d426d10533ee5323b6e5d7e7c1c1ddb0dde23e9
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 .
20 #include <memory>
21 #include <sal/config.h>
23 #include <utility>
25 #include <editsrc.hxx>
27 #include <scitems.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <editeng/unofored.hxx>
30 #include <vcl/svapp.hxx>
31 #include <svx/svdpage.hxx>
32 #include <svx/svditer.hxx>
33 #include <svx/svdocapt.hxx>
34 #include <editeng/outlobj.hxx>
35 #include <editeng/editobj.hxx>
36 #include <editeng/outliner.hxx>
37 #include <textuno.hxx>
38 #include <editutil.hxx>
39 #include <docsh.hxx>
40 #include <docfunc.hxx>
41 #include <hints.hxx>
42 #include <patattr.hxx>
43 #include <drwlayer.hxx>
44 #include <userdat.hxx>
45 #include <postit.hxx>
46 #include <AccessibleText.hxx>
48 ScHeaderFooterEditSource::ScHeaderFooterEditSource(ScHeaderFooterTextData& rData) :
49 mrTextData(rData) {}
51 ScHeaderFooterEditSource::~ScHeaderFooterEditSource() {}
53 ScEditEngineDefaulter* ScHeaderFooterEditSource::GetEditEngine()
55 return mrTextData.GetEditEngine();
58 std::unique_ptr<SvxEditSource> ScHeaderFooterEditSource::Clone() const
60 return std::unique_ptr<SvxEditSource>(new ScHeaderFooterEditSource(mrTextData));
63 SvxTextForwarder* ScHeaderFooterEditSource::GetTextForwarder()
65 return mrTextData.GetTextForwarder();
68 void ScHeaderFooterEditSource::UpdateData()
70 mrTextData.UpdateData();
73 ScCellEditSource::ScCellEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
74 pCellTextData(new ScCellTextData(pDocSh, rP)) {}
76 ScCellEditSource::~ScCellEditSource()
80 std::unique_ptr<SvxEditSource> ScCellEditSource::Clone() const
82 return std::unique_ptr<SvxEditSource>(new ScCellEditSource(pCellTextData->GetDocShell(), pCellTextData->GetCellPos()));
85 SvxTextForwarder* ScCellEditSource::GetTextForwarder()
87 return pCellTextData->GetTextForwarder();
90 void ScCellEditSource::UpdateData()
92 pCellTextData->UpdateData();
95 void ScCellEditSource::SetDoUpdateData(bool bValue)
97 pCellTextData->SetDoUpdate(bValue);
100 bool ScCellEditSource::IsDirty() const
102 return pCellTextData->IsDirty();
105 ScEditEngineDefaulter* ScCellEditSource::GetEditEngine()
107 return pCellTextData->GetEditEngine();
110 ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
111 pDocShell( pDocSh ),
112 aCellPos( rP ),
113 bDataValid( false )
115 if (pDocShell)
116 pDocShell->GetDocument().AddUnoObject(*this);
119 ScAnnotationEditSource::~ScAnnotationEditSource()
121 SolarMutexGuard aGuard; // needed for EditEngine dtor
123 if (pDocShell)
124 pDocShell->GetDocument().RemoveUnoObject(*this);
126 pForwarder.reset();
127 pEditEngine.reset();
130 std::unique_ptr<SvxEditSource> ScAnnotationEditSource::Clone() const
132 return std::unique_ptr<SvxEditSource>(new ScAnnotationEditSource( pDocShell, aCellPos ));
135 SdrObject* ScAnnotationEditSource::GetCaptionObj()
137 ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos);
138 return pNote ? pNote->GetOrCreateCaption( aCellPos ) : nullptr;
141 SvxTextForwarder* ScAnnotationEditSource::GetTextForwarder()
143 if (!pEditEngine)
145 // notes don't have fields
146 if ( pDocShell )
148 pEditEngine.reset( new ScNoteEditEngine( pDocShell->GetDocument().GetNoteEngine() ) );
150 else
152 SfxItemPool* pEnginePool = EditEngine::CreatePool();
153 pEnginePool->FreezeIdRanges();
154 pEditEngine.reset( new ScEditEngineDefaulter( pEnginePool, true ) );
156 pForwarder.reset( new SvxEditEngineForwarder(*pEditEngine) );
159 if (bDataValid)
160 return pForwarder.get();
162 if ( pDocShell )
163 if ( ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos) )
164 if ( const EditTextObject* pEditObj = pNote->GetEditTextObject() )
165 pEditEngine->SetText( *pEditObj ); // incl. breaks (line, etc.)
167 bDataValid = true;
168 return pForwarder.get();
171 void ScAnnotationEditSource::UpdateData()
173 if ( pDocShell && pEditEngine )
175 ScDocShellModificator aModificator( *pDocShell );
177 if( SdrObject* pObj = GetCaptionObj() )
179 std::unique_ptr<EditTextObject> pEditObj = pEditEngine->CreateTextObject();
180 std::unique_ptr<OutlinerParaObject> pOPO( new OutlinerParaObject( *pEditObj ) );
181 pEditObj.reset();
182 pOPO->SetOutlinerMode( OutlinerMode::TextObject );
183 pObj->NbcSetOutlinerParaObject( std::move(pOPO) );
184 pObj->ActionChanged();
187 //! Undo !!!
189 aModificator.SetDocumentModified();
191 // SetDocumentModified will reset bDataValid
195 void ScAnnotationEditSource::Notify( SfxBroadcaster&, const SfxHint& rHint )
197 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
199 //! reference update
201 else
203 const SfxHintId nId = rHint.GetId();
204 if ( nId == SfxHintId::Dying )
206 pDocShell = nullptr;
208 pForwarder.reset();
209 pEditEngine.reset(); // EditEngine uses document's pool
211 else if ( nId == SfxHintId::DataChanged )
212 bDataValid = false; // text must be retrieved again
216 ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder* pForw ) :
217 pForwarder( pForw )
219 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
220 // Text range and cursor keep a reference to their parent text, so the text object is
221 // always alive and the forwarder is valid as long as there are children.
224 ScSimpleEditSource::~ScSimpleEditSource()
228 std::unique_ptr<SvxEditSource> ScSimpleEditSource::Clone() const
230 return std::unique_ptr<SvxEditSource>(new ScSimpleEditSource( pForwarder ));
233 SvxTextForwarder* ScSimpleEditSource::GetTextForwarder()
235 return pForwarder;
238 void ScSimpleEditSource::UpdateData()
240 // nothing
243 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr < ScAccessibleTextData > && pAccessibleCellTextData )
244 : mpAccessibleTextData(std::move(pAccessibleCellTextData))
248 ScAccessibilityEditSource::~ScAccessibilityEditSource()
252 std::unique_ptr<SvxEditSource> ScAccessibilityEditSource::Clone() const
254 return std::unique_ptr<SvxEditSource>(new ScAccessibilityEditSource(::std::unique_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone())));
257 SvxTextForwarder* ScAccessibilityEditSource::GetTextForwarder()
259 return mpAccessibleTextData->GetTextForwarder();
262 SvxViewForwarder* ScAccessibilityEditSource::GetViewForwarder()
264 return mpAccessibleTextData->GetViewForwarder();
267 SvxEditViewForwarder* ScAccessibilityEditSource::GetEditViewForwarder( bool bCreate )
269 return mpAccessibleTextData->GetEditViewForwarder(bCreate);
272 void ScAccessibilityEditSource::UpdateData()
274 mpAccessibleTextData->UpdateData();
277 SfxBroadcaster& ScAccessibilityEditSource::GetBroadcaster() const
279 return mpAccessibleTextData->GetBroadcaster();
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */