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 {
47  return mrTextData.GetEditEngine();
48 }
49 
50 std::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 
72 std::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 
122 std::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  {
144  SfxItemPool* pEnginePool = EditEngine::CreatePool();
145  pEnginePool->FreezeIdRanges();
146  pEditEngine.reset( new ScEditEngineDefaulter( pEnginePool, 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  std::unique_ptr<OutlinerParaObject> pOPO( new OutlinerParaObject(pEditEngine->CreateTextObject()) );
173  pOPO->SetOutlinerMode( OutlinerMode::TextObject );
174  pObj->NbcSetOutlinerParaObject( std::move(pOPO) );
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 
218 std::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 
233 ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr < ScAccessibleTextData > && pAccessibleCellTextData )
234  : mpAccessibleTextData(std::move(pAccessibleCellTextData))
235 {
236 }
237 
239 {
240 }
241 
242 std::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: */
ScSimpleEditSource(SvxTextForwarder *pForw)
Definition: editsrc.cxx:206
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:133
SfxHintId
virtual ScEditEngineDefaulter * GetEditEngine() override
Definition: editsrc.cxx:97
virtual void UpdateData() override
Definition: editsrc.cxx:60
SdrObject * GetCaptionObj()
Definition: editsrc.cxx:127
ScAccessibilityEditSource(::std::unique_ptr< ScAccessibleTextData > &&pAccessibleCellTextData)
Definition: editsrc.cxx:233
virtual SvxEditViewForwarder * GetEditViewForwarder(bool bCreate=false) override
Definition: editsrc.cxx:257
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: editsrc.hxx:100
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: editsrc.hxx:101
sal_Int16 nId
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:55
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:72
void FreezeIdRanges()
virtual ~ScAccessibilityEditSource() override
Definition: editsrc.cxx:238
SfxHintId GetId() const
virtual ~ScHeaderFooterEditSource() override
Definition: editsrc.cxx:43
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:247
SC_DLLPUBLIC ScNoteEditEngine & GetNoteEngine()
Definition: documen2.cxx:467
ScHeaderFooterTextData & mrTextData
Definition: editsrc.hxx:53
virtual void UpdateData() override
Definition: editsrc.cxx:82
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Notes.
Definition: document.cxx:6508
virtual SfxBroadcaster & GetBroadcaster() const override
Definition: editsrc.cxx:267
Additional class containing cell annotation data.
Definition: postit.hxx:160
bool IsDirty() const
Definition: editsrc.cxx:92
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:77
virtual ~ScCellEditSource() override
Definition: editsrc.cxx:68
ScHeaderFooterEditSource(ScHeaderFooterTextData &rData)
Definition: editsrc.cxx:40
ScDocShell * pDocShell
Definition: editsrc.hxx:98
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:242
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: editsrc.cxx:185
SvxTextForwarder * pForwarder
Definition: editsrc.hxx:121
SdrCaptionObj * GetOrCreateCaption(const ScAddress &rPos) const
Returns the caption object of this note.
Definition: postit.cxx:950
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:218
std::unique_ptr< ScCellTextData > pCellTextData
Definition: editsrc.hxx:77
::std::unique_ptr< ScAccessibleTextData > mpAccessibleTextData
Definition: editsrc.hxx:136
virtual void UpdateData() override
Definition: editsrc.cxx:262
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:122
virtual ~ScAnnotationEditSource() override
Definition: editsrc.cxx:111
virtual std::unique_ptr< SvxEditSource > Clone() const override
Definition: editsrc.cxx:50
static SfxItemPool * CreatePool()
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:893
ScEditEngineDefaulter * GetEditEngine()
Definition: textuno.hxx:124
ScAnnotationEditSource(ScDocShell *pDocSh, const ScAddress &rP)
Definition: editsrc.cxx:102
ScCellEditSource(ScDocShell *pDocSh, const ScAddress &rP)
Definition: editsrc.cxx:65
virtual SvxTextForwarder * GetTextForwarder() override
Definition: editsrc.cxx:223
void SetDoUpdateData(bool bValue)
Definition: editsrc.cxx:87
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:190
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
virtual void UpdateData() override
Definition: editsrc.cxx:228
virtual ScEditEngineDefaulter * GetEditEngine() override
Definition: editsrc.cxx:45
void SetDocumentModified()
Definition: docsh.cxx:3158
virtual SvxViewForwarder * GetViewForwarder() override
Definition: editsrc.cxx:252
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:450
virtual void UpdateData() override
Definition: editsrc.cxx:163
virtual ~ScSimpleEditSource() override
Definition: editsrc.cxx:214