LibreOffice Module sc (master) 1
editsrc.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21#include <sal/config.h>
22
23#include <utility>
24
25#include <editsrc.hxx>
26
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>
39
41 mrTextData(rData) {}
42
44
46{
48}
49
50std::unique_ptr<SvxEditSource> ScHeaderFooterEditSource::Clone() const
51{
52 return std::unique_ptr<SvxEditSource>(new ScHeaderFooterEditSource(mrTextData));
53}
54
56{
58}
59
61{
63}
64
66 pCellTextData(new ScCellTextData(pDocSh, rP)) {}
67
69{
70}
71
72std::unique_ptr<SvxEditSource> ScCellEditSource::Clone() const
73{
74 return std::unique_ptr<SvxEditSource>(new ScCellEditSource(pCellTextData->GetDocShell(), pCellTextData->GetCellPos()));
75}
76
78{
79 return pCellTextData->GetTextForwarder();
80}
81
83{
84 pCellTextData->UpdateData();
85}
86
88{
89 pCellTextData->SetDoUpdate(bValue);
90}
91
93{
94 return pCellTextData->IsDirty();
95}
96
98{
99 return pCellTextData->GetEditEngine();
100}
101
103 pDocShell( pDocSh ),
104 aCellPos( rP ),
105 bDataValid( false )
106{
107 if (pDocShell)
109}
110
112{
113 SolarMutexGuard aGuard; // needed for EditEngine dtor
114
115 if (pDocShell)
117
118 pForwarder.reset();
119 pEditEngine.reset();
120}
121
122std::unique_ptr<SvxEditSource> ScAnnotationEditSource::Clone() const
123{
124 return std::unique_ptr<SvxEditSource>(new ScAnnotationEditSource( pDocShell, aCellPos ));
125}
126
128{
130 return pNote ? pNote->GetOrCreateCaption( aCellPos ) : nullptr;
131}
132
134{
135 if (!pEditEngine)
136 {
137 // notes don't have fields
138 if ( pDocShell )
139 {
141 }
142 else
143 {
145 pEnginePool->FreezeIdRanges();
146 pEditEngine.reset( new ScEditEngineDefaulter( pEnginePool.get(), true ) );
147 }
149 }
150
151 if (bDataValid)
152 return pForwarder.get();
153
154 if ( pDocShell )
155 if ( ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos) )
156 if ( const EditTextObject* pEditObj = pNote->GetEditTextObject() )
157 pEditEngine->SetTextCurrentDefaults( *pEditObj ); // incl. breaks (line, etc.)
158
159 bDataValid = true;
160 return pForwarder.get();
161}
162
164{
165 if ( !(pDocShell && pEditEngine) )
166 return;
167
168 ScDocShellModificator aModificator( *pDocShell );
169
170 if( SdrObject* pObj = GetCaptionObj() )
171 {
172 OutlinerParaObject aOPO( pEditEngine->CreateTextObject() );
173 aOPO.SetOutlinerMode( OutlinerMode::TextObject );
174 pObj->NbcSetOutlinerParaObject( std::move(aOPO) );
175 pObj->ActionChanged();
176 }
177
179
180 aModificator.SetDocumentModified();
181
182 // SetDocumentModified will reset bDataValid
183}
184
186{
187 if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
188 {
190 }
191 else
192 {
193 const SfxHintId nId = rHint.GetId();
194 if ( nId == SfxHintId::Dying )
195 {
196 pDocShell = nullptr;
197
198 pForwarder.reset();
199 pEditEngine.reset(); // EditEngine uses document's pool
200 }
201 else if ( nId == SfxHintId::DataChanged )
202 bDataValid = false; // text must be retrieved again
203 }
204}
205
207 pForwarder( pForw )
208{
209 // The same forwarder (and EditEngine) is shared by all children of the same Text object.
210 // Text range and cursor keep a reference to their parent text, so the text object is
211 // always alive and the forwarder is valid as long as there are children.
212}
213
215{
216}
217
218std::unique_ptr<SvxEditSource> ScSimpleEditSource::Clone() const
219{
220 return std::unique_ptr<SvxEditSource>(new ScSimpleEditSource( pForwarder ));
221}
222
224{
225 return pForwarder;
226}
227
229{
230 // nothing
231}
232
233ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr < ScAccessibleTextData > && pAccessibleCellTextData )
234 : mpAccessibleTextData(std::move(pAccessibleCellTextData))
235{
236}
237
239{
240}
241
242std::unique_ptr<SvxEditSource> ScAccessibilityEditSource::Clone() const
243{
244 return std::unique_ptr<SvxEditSource>(new ScAccessibilityEditSource(::std::unique_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone())));
245}
246
248{
249 return mpAccessibleTextData->GetTextForwarder();
250}
251
253{
254 return mpAccessibleTextData->GetViewForwarder();
255}
256
258{
259 return mpAccessibleTextData->GetEditViewForwarder(bCreate);
260}
261
263{
264 mpAccessibleTextData->UpdateData();
265}
266
268{
269 return mpAccessibleTextData->GetBroadcaster();
270}
271
272/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static rtl::Reference< SfxItemPool > CreatePool()
void SetOutlinerMode(OutlinerMode nNew)
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:247
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:242
virtual SvxEditViewForwarder * GetEditViewForwarder(bool bCreate=false) override
Definition: editsrc.cxx:257
::std::unique_ptr< ScAccessibleTextData > mpAccessibleTextData
Definition: editsrc.hxx:135
virtual ~ScAccessibilityEditSource() override
Definition: editsrc.cxx:238
virtual SvxViewForwarder * GetViewForwarder() override
Definition: editsrc.cxx:252
ScAccessibilityEditSource(::std::unique_ptr< ScAccessibleTextData > &&pAccessibleCellTextData)
Definition: editsrc.cxx:233
virtual void UpdateData() override
Definition: editsrc.cxx:262
virtual SfxBroadcaster & GetBroadcaster() const override
Definition: editsrc.cxx:267
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:133
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:122
ScDocShell * pDocShell
Definition: editsrc.hxx:97
virtual void UpdateData() override
Definition: editsrc.cxx:163
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: editsrc.cxx:185
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: editsrc.hxx:99
virtual ~ScAnnotationEditSource() override
Definition: editsrc.cxx:111
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: editsrc.hxx:100
SdrObject * GetCaptionObj()
Definition: editsrc.cxx:127
ScAnnotationEditSource(ScDocShell *pDocSh, const ScAddress &rP)
Definition: editsrc.cxx:102
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:72
ScCellEditSource(ScDocShell *pDocSh, const ScAddress &rP)
Definition: editsrc.cxx:65
bool IsDirty() const
Definition: editsrc.cxx:92
std::unique_ptr< ScCellTextData > pCellTextData
Definition: editsrc.hxx:76
virtual void UpdateData() override
Definition: editsrc.cxx:82
virtual ScEditEngineDefaulter * GetEditEngine() override
Definition: editsrc.cxx:97
virtual ~ScCellEditSource() override
Definition: editsrc.cxx:68
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:77
void SetDoUpdateData(bool bValue)
Definition: editsrc.cxx:87
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:455
void SetDocumentModified()
Definition: docsh.cxx:3315
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6587
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
SC_DLLPUBLIC ScNoteEditEngine & GetNoteEngine()
Definition: documen2.cxx:496
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:909
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:55
ScHeaderFooterEditSource(ScHeaderFooterTextData &rData)
Definition: editsrc.cxx:40
virtual ScEditEngineDefaulter * GetEditEngine() override
Definition: editsrc.cxx:45
virtual void UpdateData() override
Definition: editsrc.cxx:60
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:50
ScHeaderFooterTextData & mrTextData
Definition: editsrc.hxx:52
virtual ~ScHeaderFooterEditSource() override
Definition: editsrc.cxx:43
SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:163
ScEditEngineDefaulter * GetEditEngine()
Definition: textuno.hxx:116
Additional class containing cell annotation data.
Definition: postit.hxx:58
SdrCaptionObj * GetOrCreateCaption(const ScAddress &rPos) const
Returns the caption object of this note.
Definition: postit.cxx:555
virtual ~ScSimpleEditSource() override
Definition: editsrc.cxx:214
SvxTextForwarder * pForwarder
Definition: editsrc.hxx:120
ScSimpleEditSource(SvxTextForwarder *pForw)
Definition: editsrc.cxx:206
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:223
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:218
virtual void UpdateData() override
Definition: editsrc.cxx:228
SfxHintId GetId() const
SfxHintId
sal_Int16 nId