Line data Source code
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 <sal/config.h>
21 :
22 : #include <utility>
23 :
24 : #include "editsrc.hxx"
25 :
26 : #include "scitems.hxx"
27 : #include <editeng/eeitem.hxx>
28 : #include <editeng/unofored.hxx>
29 : #include <vcl/svapp.hxx>
30 : #include <svx/svdpage.hxx>
31 : #include <svx/svditer.hxx>
32 : #include <svx/svdocapt.hxx>
33 : #include <editeng/outlobj.hxx>
34 : #include <editeng/editobj.hxx>
35 : #include <editeng/outliner.hxx>
36 : #include "textuno.hxx"
37 : #include "editutil.hxx"
38 : #include "docsh.hxx"
39 : #include "docfunc.hxx"
40 : #include "hints.hxx"
41 : #include "patattr.hxx"
42 : #include "drwlayer.hxx"
43 : #include "userdat.hxx"
44 : #include "postit.hxx"
45 : #include "AccessibleText.hxx"
46 :
47 13959 : ScHeaderFooterEditSource::ScHeaderFooterEditSource(ScHeaderFooterTextData& rData) :
48 13959 : mrTextData(rData) {}
49 :
50 21765 : ScHeaderFooterEditSource::~ScHeaderFooterEditSource() {}
51 :
52 37 : ScEditEngineDefaulter* ScHeaderFooterEditSource::GetEditEngine()
53 : {
54 37 : return mrTextData.GetEditEngine();
55 : }
56 :
57 10444 : SvxEditSource* ScHeaderFooterEditSource::Clone() const
58 : {
59 10444 : return new ScHeaderFooterEditSource(mrTextData);
60 : }
61 :
62 82309 : SvxTextForwarder* ScHeaderFooterEditSource::GetTextForwarder()
63 : {
64 82309 : return mrTextData.GetTextForwarder();
65 : }
66 :
67 5706 : void ScHeaderFooterEditSource::UpdateData()
68 : {
69 5706 : mrTextData.UpdateData();
70 5706 : }
71 :
72 51 : ScCellEditSource::ScCellEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
73 51 : pCellTextData(new ScCellTextData(pDocSh, rP)) {}
74 :
75 153 : ScCellEditSource::~ScCellEditSource()
76 : {
77 51 : delete pCellTextData;
78 102 : }
79 :
80 29 : SvxEditSource* ScCellEditSource::Clone() const
81 : {
82 29 : return new ScCellEditSource(pCellTextData->GetDocShell(), pCellTextData->GetCellPos());
83 : }
84 :
85 1589 : SvxTextForwarder* ScCellEditSource::GetTextForwarder()
86 : {
87 1589 : return pCellTextData->GetTextForwarder();
88 : }
89 :
90 220 : void ScCellEditSource::UpdateData()
91 : {
92 220 : pCellTextData->UpdateData();
93 220 : }
94 :
95 0 : void ScCellEditSource::SetDoUpdateData(bool bValue)
96 : {
97 0 : pCellTextData->SetDoUpdate(bValue);
98 0 : }
99 :
100 0 : bool ScCellEditSource::IsDirty() const
101 : {
102 0 : return pCellTextData->IsDirty();
103 : }
104 :
105 49 : ScEditEngineDefaulter* ScCellEditSource::GetEditEngine()
106 : {
107 49 : return pCellTextData->GetEditEngine();
108 : }
109 :
110 12 : ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell* pDocSh, const ScAddress& rP) :
111 : pDocShell( pDocSh ),
112 : aCellPos( rP ),
113 : pEditEngine( NULL ),
114 : pForwarder( NULL ),
115 12 : bDataValid( false )
116 : {
117 12 : if (pDocShell)
118 12 : pDocShell->GetDocument().AddUnoObject(*this);
119 12 : }
120 :
121 30 : ScAnnotationEditSource::~ScAnnotationEditSource()
122 : {
123 12 : SolarMutexGuard aGuard; // needed for EditEngine dtor
124 :
125 12 : if (pDocShell)
126 11 : pDocShell->GetDocument().RemoveUnoObject(*this);
127 :
128 12 : delete pForwarder;
129 12 : delete pEditEngine;
130 18 : }
131 :
132 6 : SvxEditSource* ScAnnotationEditSource::Clone() const
133 : {
134 6 : return new ScAnnotationEditSource( pDocShell, aCellPos );
135 : }
136 :
137 2 : SdrObject* ScAnnotationEditSource::GetCaptionObj()
138 : {
139 2 : ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos);
140 2 : return pNote ? pNote->GetOrCreateCaption( aCellPos ) : 0;
141 : }
142 :
143 34 : SvxTextForwarder* ScAnnotationEditSource::GetTextForwarder()
144 : {
145 34 : if (!pEditEngine)
146 : {
147 : // Notizen haben keine Felder
148 6 : if ( pDocShell )
149 : {
150 6 : pEditEngine = new ScNoteEditEngine( pDocShell->GetDocument().GetNoteEngine() );
151 : }
152 : else
153 : {
154 0 : SfxItemPool* pEnginePool = EditEngine::CreatePool();
155 0 : pEnginePool->FreezeIdRanges();
156 0 : pEditEngine = new ScEditEngineDefaulter( pEnginePool, true );
157 : }
158 6 : pForwarder = new SvxEditEngineForwarder(*pEditEngine);
159 : }
160 :
161 34 : if (bDataValid)
162 26 : return pForwarder;
163 :
164 8 : if ( pDocShell )
165 8 : if ( ScPostIt* pNote = pDocShell->GetDocument().GetNote(aCellPos) )
166 6 : if ( const EditTextObject* pEditObj = pNote->GetEditTextObject() )
167 6 : pEditEngine->SetText( *pEditObj ); // incl. Umbrueche
168 :
169 8 : bDataValid = true;
170 8 : return pForwarder;
171 : }
172 :
173 2 : void ScAnnotationEditSource::UpdateData()
174 : {
175 2 : if ( pDocShell && pEditEngine )
176 : {
177 2 : ScDocShellModificator aModificator( *pDocShell );
178 :
179 2 : if( SdrObject* pObj = GetCaptionObj() )
180 : {
181 1 : EditTextObject* pEditObj = pEditEngine->CreateTextObject();
182 1 : OutlinerParaObject* pOPO = new OutlinerParaObject( *pEditObj );
183 1 : delete pEditObj;
184 1 : pOPO->SetOutlinerMode( OUTLINERMODE_TEXTOBJECT );
185 1 : pObj->NbcSetOutlinerParaObject( pOPO );
186 1 : pObj->ActionChanged();
187 : }
188 :
189 : //! Undo !!!
190 :
191 2 : aModificator.SetDocumentModified();
192 :
193 : // bDataValid wird bei SetDocumentModified zurueckgesetzt
194 : }
195 2 : }
196 :
197 6 : void ScAnnotationEditSource::Notify( SfxBroadcaster&, const SfxHint& rHint )
198 : {
199 6 : if ( dynamic_cast<const ScUpdateRefHint*>(&rHint) )
200 : {
201 : //! Ref-Update
202 : }
203 6 : else if ( dynamic_cast<const SfxSimpleHint*>(&rHint) )
204 : {
205 6 : sal_uLong nId = static_cast<const SfxSimpleHint&>(rHint).GetId();
206 6 : if ( nId == SFX_HINT_DYING )
207 : {
208 1 : pDocShell = NULL; // ungueltig geworden
209 :
210 1 : DELETEZ( pForwarder );
211 1 : DELETEZ( pEditEngine ); // EditEngine uses document's pool
212 : }
213 5 : else if ( nId == SFX_HINT_DATACHANGED )
214 5 : bDataValid = false; // Text muss neu geholt werden
215 : }
216 6 : }
217 :
218 0 : ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder* pForw ) :
219 0 : pForwarder( pForw )
220 : {
221 : // The same forwarder (and EditEngine) is shared by all children of the same Text object.
222 : // Text range and cursor keep a reference to their parent text, so the text object is
223 : // always alive and the forwarder is valid as long as there are children.
224 0 : }
225 :
226 0 : ScSimpleEditSource::~ScSimpleEditSource()
227 : {
228 0 : }
229 :
230 0 : SvxEditSource* ScSimpleEditSource::Clone() const
231 : {
232 0 : return new ScSimpleEditSource( pForwarder );
233 : }
234 :
235 0 : SvxTextForwarder* ScSimpleEditSource::GetTextForwarder()
236 : {
237 0 : return pForwarder;
238 : }
239 :
240 0 : void ScSimpleEditSource::UpdateData()
241 : {
242 : // nothing
243 0 : }
244 :
245 32 : ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::unique_ptr < ScAccessibleTextData > && pAccessibleCellTextData )
246 32 : : mpAccessibleTextData(std::move(pAccessibleCellTextData))
247 : {
248 32 : }
249 :
250 48 : ScAccessibilityEditSource::~ScAccessibilityEditSource()
251 : {
252 48 : }
253 :
254 2 : SvxEditSource* ScAccessibilityEditSource::Clone() const
255 : {
256 2 : return new ScAccessibilityEditSource(::std::unique_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone()));
257 : }
258 :
259 519 : SvxTextForwarder* ScAccessibilityEditSource::GetTextForwarder()
260 : {
261 519 : return mpAccessibleTextData->GetTextForwarder();
262 : }
263 :
264 139 : SvxViewForwarder* ScAccessibilityEditSource::GetViewForwarder()
265 : {
266 139 : return mpAccessibleTextData->GetViewForwarder();
267 : }
268 :
269 60 : SvxEditViewForwarder* ScAccessibilityEditSource::GetEditViewForwarder( bool bCreate )
270 : {
271 60 : return mpAccessibleTextData->GetEditViewForwarder(bCreate);
272 : }
273 :
274 0 : void ScAccessibilityEditSource::UpdateData()
275 : {
276 0 : mpAccessibleTextData->UpdateData();
277 0 : }
278 :
279 42 : SfxBroadcaster& ScAccessibilityEditSource::GetBroadcaster() const
280 : {
281 42 : return mpAccessibleTextData->GetBroadcaster();
282 156 : }
283 :
284 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|