tdf#42949 Fix IWYU warnings in sc/source/ui/unoobj/*
[LibreOffice.git] / sc / source / ui / unoobj / editsrc.cxx
blob07199891dd9f72ec1e872e297b213a4398f0703f
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 <editeng/unofored.hxx>
28 #include <vcl/svapp.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 <hints.hxx>
37 #include <postit.hxx>
38 #include <AccessibleText.hxx>
40 ScHeaderFooterEditSource::ScHeaderFooterEditSource(ScHeaderFooterTextData& rData) :
41 mrTextData(rData) {}
43 ScHeaderFooterEditSource::~ScHeaderFooterEditSource() {}
45 ScEditEngineDefaulter* ScHeaderFooterEditSource::GetEditEngine()
47 return mrTextData.GetEditEngine();
50 std::unique_ptr<SvxEditSource> ScHeaderFooterEditSource::Clone() const
52 return std::unique_ptr<SvxEditSource>(new ScHeaderFooterEditSource(mrTextData));
55 SvxTextForwarder* ScHeaderFooterEditSource::GetTextForwarder()
57 return mrTextData.GetTextForwarder();
60 void ScHeaderFooterEditSource::UpdateData()
62 mrTextData.UpdateData();
65 ScCellEditSource::ScCellEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
66 pCellTextData(new ScCellTextData(pDocSh, rP)) {}
68 ScCellEditSource::~ScCellEditSource()
72 std::unique_ptr<SvxEditSource> ScCellEditSource::Clone() const
74 return std::unique_ptr<SvxEditSource>(new ScCellEditSource(pCellTextData->GetDocShell(), pCellTextData->GetCellPos()));
77 SvxTextForwarder* ScCellEditSource::GetTextForwarder()
79 return pCellTextData->GetTextForwarder();
82 void ScCellEditSource::UpdateData()
84 pCellTextData->UpdateData();
87 void ScCellEditSource::SetDoUpdateData(bool bValue)
89 pCellTextData->SetDoUpdate(bValue);
92 bool ScCellEditSource::IsDirty() const
94 return pCellTextData->IsDirty();
97 ScEditEngineDefaulter* ScCellEditSource::GetEditEngine()
99 return pCellTextData->GetEditEngine();
102 ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
103 pDocShell( pDocSh ),
104 aCellPos( rP ),
105 bDataValid( false )
107 if (pDocShell)
108 pDocShell->GetDocument().AddUnoObject(*this);
111 ScAnnotationEditSource::~ScAnnotationEditSource()
113 SolarMutexGuard aGuard; // needed for EditEngine dtor
115 if (pDocShell)
116 pDocShell->GetDocument().RemoveUnoObject(*this);
118 pForwarder.reset();
119 pEditEngine.reset();
122 std::unique_ptr<SvxEditSource> ScAnnotationEditSource::Clone() const
124 return std::unique_ptr<SvxEditSource>(new ScAnnotationEditSource( pDocShell, aCellPos ));
127 SdrObject* ScAnnotationEditSource::GetCaptionObj()
129 ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos);
130 return pNote ? pNote->GetOrCreateCaption( aCellPos ) : nullptr;
133 SvxTextForwarder* ScAnnotationEditSource::GetTextForwarder()
135 if (!pEditEngine)
137 // notes don't have fields
138 if ( pDocShell )
140 pEditEngine.reset( new ScNoteEditEngine( pDocShell->GetDocument().GetNoteEngine() ) );
142 else
144 SfxItemPool* pEnginePool = EditEngine::CreatePool();
145 pEnginePool->FreezeIdRanges();
146 pEditEngine.reset( new ScEditEngineDefaulter( pEnginePool, true ) );
148 pForwarder.reset( new SvxEditEngineForwarder(*pEditEngine) );
151 if (bDataValid)
152 return pForwarder.get();
154 if ( pDocShell )
155 if ( ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos) )
156 if ( const EditTextObject* pEditObj = pNote->GetEditTextObject() )
157 pEditEngine->SetText( *pEditObj ); // incl. breaks (line, etc.)
159 bDataValid = true;
160 return pForwarder.get();
163 void ScAnnotationEditSource::UpdateData()
165 if ( pDocShell && pEditEngine )
167 ScDocShellModificator aModificator( *pDocShell );
169 if( SdrObject* pObj = GetCaptionObj() )
171 std::unique_ptr<EditTextObject> pEditObj = pEditEngine->CreateTextObject();
172 std::unique_ptr<OutlinerParaObject> pOPO( new OutlinerParaObject( *pEditObj ) );
173 pEditObj.reset();
174 pOPO->SetOutlinerMode( OutlinerMode::TextObject );
175 pObj->NbcSetOutlinerParaObject( std::move(pOPO) );
176 pObj->ActionChanged();
179 //! Undo !!!
181 aModificator.SetDocumentModified();
183 // SetDocumentModified will reset bDataValid
187 void ScAnnotationEditSource::Notify( SfxBroadcaster&, const SfxHint& rHint )
189 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
191 //! reference update
193 else
195 const SfxHintId nId = rHint.GetId();
196 if ( nId == SfxHintId::Dying )
198 pDocShell = nullptr;
200 pForwarder.reset();
201 pEditEngine.reset(); // EditEngine uses document's pool
203 else if ( nId == SfxHintId::DataChanged )
204 bDataValid = false; // text must be retrieved again
208 ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder* pForw ) :
209 pForwarder( pForw )
211 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
212 // Text range and cursor keep a reference to their parent text, so the text object is
213 // always alive and the forwarder is valid as long as there are children.
216 ScSimpleEditSource::~ScSimpleEditSource()
220 std::unique_ptr<SvxEditSource> ScSimpleEditSource::Clone() const
222 return std::unique_ptr<SvxEditSource>(new ScSimpleEditSource( pForwarder ));
225 SvxTextForwarder* ScSimpleEditSource::GetTextForwarder()
227 return pForwarder;
230 void ScSimpleEditSource::UpdateData()
232 // nothing
235 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr < ScAccessibleTextData > && pAccessibleCellTextData )
236 : mpAccessibleTextData(std::move(pAccessibleCellTextData))
240 ScAccessibilityEditSource::~ScAccessibilityEditSource()
244 std::unique_ptr<SvxEditSource> ScAccessibilityEditSource::Clone() const
246 return std::unique_ptr<SvxEditSource>(new ScAccessibilityEditSource(::std::unique_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone())));
249 SvxTextForwarder* ScAccessibilityEditSource::GetTextForwarder()
251 return mpAccessibleTextData->GetTextForwarder();
254 SvxViewForwarder* ScAccessibilityEditSource::GetViewForwarder()
256 return mpAccessibleTextData->GetViewForwarder();
259 SvxEditViewForwarder* ScAccessibilityEditSource::GetEditViewForwarder( bool bCreate )
261 return mpAccessibleTextData->GetEditViewForwarder(bCreate);
264 void ScAccessibilityEditSource::UpdateData()
266 mpAccessibleTextData->UpdateData();
269 SfxBroadcaster& ScAccessibilityEditSource::GetBroadcaster() const
271 return mpAccessibleTextData->GetBroadcaster();
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */