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