Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <editeng/eeitem.hxx>
31 : : #include <svx/svdpool.hxx>
32 : : #include <svx/svdobj.hxx>
33 : : #include <editeng/editeng.hxx>
34 : : #include <editeng/editobj.hxx>
35 : : #include <editeng/flditem.hxx>
36 : : #include <svx/unomid.hxx>
37 : : #include <editeng/unoprnms.hxx>
38 : : #include <editeng/unofored.hxx>
39 : : #include <vcl/virdev.hxx>
40 : : #include <vcl/svapp.hxx>
41 : : #include <com/sun/star/awt/FontSlant.hpp>
42 : :
43 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
44 : : #include <editeng/unoipset.hxx>
45 : : #include "textuno.hxx"
46 : : #include "fielduno.hxx"
47 : : #include "servuno.hxx"
48 : : #include "editsrc.hxx"
49 : : #include "docsh.hxx"
50 : : #include "editutil.hxx"
51 : : #include "miscuno.hxx"
52 : : #include "cellsuno.hxx"
53 : : #include "hints.hxx"
54 : : #include "patattr.hxx"
55 : : #include "cell.hxx"
56 : : #include "docfunc.hxx"
57 : : #include "scmod.hxx"
58 : :
59 : : using namespace com::sun::star;
60 : :
61 : : //------------------------------------------------------------------------
62 : :
63 : 921 : const SvxItemPropertySet * lcl_GetHdFtPropertySet()
64 : : {
65 : : static SfxItemPropertyMapEntry aHdFtPropertyMap_Impl[] =
66 : : {
67 [ + - ][ + - ]: 29 : SVX_UNOEDIT_CHAR_PROPERTIES,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
68 [ + - ]: 29 : SVX_UNOEDIT_FONT_PROPERTIES,
69 [ + - ][ + - ]: 29 : SVX_UNOEDIT_PARA_PROPERTIES,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
70 [ + - ][ + - ]: 29 : SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
71 : : {0,0,0,0,0,0}
72 [ + + ][ + - ]: 950 : };
[ # # ]
73 : : static sal_Bool bTwipsSet = false;
74 : :
75 [ + + ]: 921 : if (!bTwipsSet)
76 : : {
77 : : // modify PropertyMap to include CONVERT_TWIPS flag for font height
78 : : // (headers/footers are in twips)
79 : :
80 : 29 : SfxItemPropertyMapEntry* pEntry = aHdFtPropertyMap_Impl;
81 [ + + ]: 1856 : while (pEntry->pName)
82 : : {
83 [ + + ][ + + ]: 1827 : if ( ( pEntry->nWID == EE_CHAR_FONTHEIGHT ||
[ + + ][ - + ]
84 : : pEntry->nWID == EE_CHAR_FONTHEIGHT_CJK ||
85 : : pEntry->nWID == EE_CHAR_FONTHEIGHT_CTL ) &&
86 : : pEntry->nMemberId == MID_FONTHEIGHT )
87 : : {
88 : 0 : pEntry->nMemberId |= CONVERT_TWIPS;
89 : : }
90 : :
91 : 1827 : ++pEntry;
92 : : }
93 : 29 : bTwipsSet = sal_True;
94 : : }
95 [ + + ][ + - ]: 921 : static SvxItemPropertySet aHdFtPropertySet_Impl( aHdFtPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
[ + - ][ + - ]
[ # # ]
96 : 921 : return &aHdFtPropertySet_Impl;
97 : : }
98 : :
99 : : //------------------------------------------------------------------------
100 : :
101 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScHeaderFooterContentObj, "ScHeaderFooterContentObj", "com.sun.star.sheet.HeaderFooterContent" )
102 [ # # ]: 0 : SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj, "ScHeaderFooterTextObj", "stardiv.one.Text.Text" )
103 : :
104 : : //------------------------------------------------------------------------
105 : :
106 : 925 : ScHeaderFooterContentObj::ScHeaderFooterContentObj( const EditTextObject* pLeft,
107 : : const EditTextObject* pCenter,
108 : : const EditTextObject* pRight ) :
109 [ + - ]: 925 : mxLeftText(new ScHeaderFooterTextObj(*this, SC_HDFT_LEFT, pLeft)),
110 [ + - ]: 925 : mxCenterText(new ScHeaderFooterTextObj(*this, SC_HDFT_CENTER, pCenter)),
111 [ + - ]: 2775 : mxRightText(new ScHeaderFooterTextObj(*this, SC_HDFT_RIGHT, pRight))
112 : : {
113 : 925 : }
114 : :
115 [ - + ]: 1850 : ScHeaderFooterContentObj::~ScHeaderFooterContentObj() {}
116 : :
117 : 896 : const EditTextObject* ScHeaderFooterContentObj::GetLeftEditObject() const
118 : : {
119 : 896 : return mxLeftText->GetTextObject();
120 : : }
121 : :
122 : 902 : const EditTextObject* ScHeaderFooterContentObj::GetCenterEditObject() const
123 : : {
124 : 902 : return mxCenterText->GetTextObject();
125 : : }
126 : :
127 : 896 : const EditTextObject* ScHeaderFooterContentObj::GetRightEditObject() const
128 : : {
129 : 896 : return mxRightText->GetTextObject();
130 : : }
131 : :
132 : : // XHeaderFooterContent
133 : :
134 : 1110 : uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getLeftText()
135 : : throw(uno::RuntimeException)
136 : : {
137 [ + - ]: 1110 : SolarMutexGuard aGuard;
138 [ + - ][ + - ]: 1110 : uno::Reference<text::XText> xInt(*mxLeftText, uno::UNO_QUERY);
139 [ + - ]: 1110 : return xInt;
140 : : }
141 : :
142 : 1423 : uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getCenterText()
143 : : throw(uno::RuntimeException)
144 : : {
145 [ + - ]: 1423 : SolarMutexGuard aGuard;
146 [ + - ][ + - ]: 1423 : uno::Reference<text::XText> xInt(*mxCenterText, uno::UNO_QUERY);
147 [ + - ]: 1423 : return xInt;
148 : : }
149 : :
150 : 1106 : uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getRightText()
151 : : throw(uno::RuntimeException)
152 : : {
153 [ + - ]: 1106 : SolarMutexGuard aGuard;
154 [ + - ][ + - ]: 1106 : uno::Reference<text::XText> xInt(*mxRightText, uno::UNO_QUERY);
155 [ + - ]: 1106 : return xInt;
156 : : }
157 : :
158 : : // XUnoTunnel
159 : :
160 : 863 : sal_Int64 SAL_CALL ScHeaderFooterContentObj::getSomething(
161 : : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
162 : : {
163 [ + - + - ]: 1726 : if ( rId.getLength() == 16 &&
[ + - ]
164 : 863 : 0 == memcmp( getUnoTunnelId().getConstArray(),
165 : 863 : rId.getConstArray(), 16 ) )
166 : : {
167 : 863 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
168 : : }
169 : 863 : return 0;
170 : : }
171 : :
172 : : namespace
173 : : {
174 : : class theScHeaderFooterContentObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScHeaderFooterContentObjUnoTunnelId> {};
175 : : }
176 : :
177 : 1726 : const uno::Sequence<sal_Int8>& ScHeaderFooterContentObj::getUnoTunnelId()
178 : : {
179 : 1726 : return theScHeaderFooterContentObjUnoTunnelId::get().getSeq();
180 : : }
181 : :
182 : 863 : ScHeaderFooterContentObj* ScHeaderFooterContentObj::getImplementation(
183 : : const uno::Reference<sheet::XHeaderFooterContent> xObj )
184 : : {
185 : 863 : ScHeaderFooterContentObj* pRet = NULL;
186 [ + - ]: 863 : uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
187 [ + - ]: 863 : if (xUT.is())
188 [ + - ][ + - ]: 863 : pRet = reinterpret_cast<ScHeaderFooterContentObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
[ + - ]
189 : 863 : return pRet;
190 : : }
191 : :
192 : :
193 : : //------------------------------------------------------------------------
194 : :
195 : 2775 : ScHeaderFooterTextData::ScHeaderFooterTextData(
196 : : ScHeaderFooterContentObj& rContent, sal_uInt16 nP, const EditTextObject* pTextObj) :
197 : 129 : mpTextObj(pTextObj ? pTextObj->Clone() : NULL),
198 : : rContentObj( rContent ),
199 : : nPart( nP ),
200 : : pEditEngine( NULL ),
201 : : pForwarder( NULL ),
202 [ + + ]: 2775 : bDataValid(false)
203 : : {
204 : 2775 : }
205 : :
206 : 2775 : ScHeaderFooterTextData::~ScHeaderFooterTextData()
207 : : {
208 [ + - ]: 2775 : SolarMutexGuard aGuard; // needed for EditEngine dtor
209 : :
210 [ + + ][ + - ]: 2775 : delete pForwarder;
211 [ + + ][ + - ]: 2775 : delete pEditEngine;
[ + - ]
212 : 2775 : }
213 : :
214 : 36881 : SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder()
215 : : {
216 [ + + ]: 36881 : if (!pEditEngine)
217 : : {
218 [ + - ]: 921 : SfxItemPool* pEnginePool = EditEngine::CreatePool();
219 [ + - ]: 921 : pEnginePool->FreezeIdRanges();
220 [ + - ][ + - ]: 921 : ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, sal_True );
221 : :
222 [ + - ]: 921 : pHdrEngine->EnableUndo( false );
223 [ + - ][ + - ]: 921 : pHdrEngine->SetRefMapMode( MAP_TWIP );
[ + - ]
224 : :
225 : : // default font must be set, independently of document
226 : : // -> use global pool from module
227 : :
228 [ + - ][ + - ]: 921 : SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
229 [ + - ][ + - ]: 921 : const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
230 [ + - ]: 921 : rPattern.FillEditItemSet( &aDefaults );
231 : : // FillEditItemSet adjusts font height to 1/100th mm,
232 : : // but for header/footer twips is needed, as in the PatternAttr:
233 [ + - ][ + - ]: 921 : aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
234 [ + - ][ + - ]: 921 : aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
235 [ + - ][ + - ]: 921 : aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
236 [ + - ]: 921 : pHdrEngine->SetDefaults( aDefaults );
237 : :
238 [ + - ]: 921 : ScHeaderFieldData aData;
239 [ + - ]: 921 : ScHeaderFooterTextObj::FillDummyFieldData( aData );
240 [ + - ]: 921 : pHdrEngine->SetData( aData );
241 : :
242 : 921 : pEditEngine = pHdrEngine;
243 [ + - ][ + - ]: 921 : pForwarder = new SvxEditEngineForwarder(*pEditEngine);
[ + - ][ + - ]
244 : : }
245 : :
246 [ + + ]: 36881 : if (bDataValid)
247 : 35955 : return pForwarder;
248 : :
249 [ + + ]: 926 : if (mpTextObj)
250 : 572 : pEditEngine->SetText(*mpTextObj);
251 : :
252 : 926 : bDataValid = true;
253 : 36881 : return pForwarder;
254 : : }
255 : :
256 : 3305 : void ScHeaderFooterTextData::UpdateData()
257 : : {
258 [ + - ]: 3305 : if (pEditEngine)
259 : : {
260 [ + + ]: 3305 : delete mpTextObj;
261 : 3305 : mpTextObj = pEditEngine->CreateTextObject();
262 : : }
263 : 3305 : }
264 : :
265 : 2269 : void ScHeaderFooterTextData::UpdateData(EditEngine& rEditEngine)
266 : : {
267 [ + + ]: 2269 : delete mpTextObj;
268 : 2269 : mpTextObj = rEditEngine.CreateTextObject();
269 : 2269 : bDataValid = false;
270 : 2269 : }
271 : :
272 : 2694 : const EditTextObject* ScHeaderFooterTextData::GetTextObject() const
273 : : {
274 : 2694 : return mpTextObj;
275 : : }
276 : :
277 : : //------------------------------------------------------------------------
278 : :
279 : 2775 : ScHeaderFooterTextObj::ScHeaderFooterTextObj(
280 : : ScHeaderFooterContentObj& rContent, sal_uInt16 nP, const EditTextObject* pTextObj) :
281 [ + - ]: 2775 : aTextData(rContent, nP, pTextObj)
282 : : {
283 : : // ScHeaderFooterTextData acquires rContent
284 : : // pUnoText is created on demand (getString/setString work without it)
285 : 2775 : }
286 : :
287 : 921 : void ScHeaderFooterTextObj::CreateUnoText_Impl()
288 : : {
289 [ + - ]: 921 : if (!mxUnoText.is())
290 : : {
291 : : // can't be aggregated because getString/setString is handled here
292 [ + - ]: 921 : ScHeaderFooterEditSource aEditSrc(aTextData);
293 [ + - ][ + - ]: 921 : mxUnoText.set(new SvxUnoText(&aEditSrc, lcl_GetHdFtPropertySet(), uno::Reference<text::XText>()));
294 : : }
295 : 921 : }
296 : :
297 [ + - ][ - + ]: 5550 : ScHeaderFooterTextObj::~ScHeaderFooterTextObj() {}
298 : :
299 : 2694 : const EditTextObject* ScHeaderFooterTextObj::GetTextObject() const
300 : : {
301 : 2694 : return aTextData.GetTextObject();
302 : : }
303 : :
304 : 1112 : const SvxUnoText& ScHeaderFooterTextObj::GetUnoText()
305 : : {
306 [ + + ]: 1112 : if (!mxUnoText.is())
307 : 803 : CreateUnoText_Impl();
308 : 1112 : return *mxUnoText;
309 : : }
310 : :
311 : : // XText
312 : :
313 : 1112 : uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursor()
314 : : throw(uno::RuntimeException)
315 : : {
316 [ + - ]: 1112 : SolarMutexGuard aGuard;
317 [ + - ][ + - ]: 1112 : return new ScHeaderFooterTextCursor( *this );
[ + - ][ + - ]
318 : : }
319 : :
320 : 491 : uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursorByRange(
321 : : const uno::Reference<text::XTextRange>& aTextPosition )
322 : : throw(uno::RuntimeException)
323 : : {
324 [ + - ]: 491 : SolarMutexGuard aGuard;
325 [ - + ]: 491 : if (!mxUnoText.is())
326 [ # # ]: 0 : CreateUnoText_Impl();
327 [ + - ][ + - ]: 491 : return mxUnoText->createTextCursorByRange(aTextPosition);
328 : : //! wie ScCellObj::createTextCursorByRange, wenn SvxUnoTextRange_getReflection verfuegbar
329 : : }
330 : :
331 : 978 : void ScHeaderFooterTextObj::FillDummyFieldData( ScHeaderFieldData& rData )
332 : : {
333 : 978 : rtl::OUString aDummy("???");
334 [ + - ]: 978 : rData.aTitle = aDummy;
335 [ + - ]: 978 : rData.aLongDocName = aDummy;
336 [ + - ]: 978 : rData.aShortDocName = aDummy;
337 [ + - ]: 978 : rData.aTabName = aDummy;
338 : 978 : rData.nPageNo = 1;
339 : 978 : rData.nTotalPages = 99;
340 : 978 : }
341 : :
342 : 105 : rtl::OUString SAL_CALL ScHeaderFooterTextObj::getString() throw(uno::RuntimeException)
343 : : {
344 [ + - ]: 105 : SolarMutexGuard aGuard;
345 : 105 : rtl::OUString aRet;
346 : : const EditTextObject* pData;
347 : :
348 : 105 : sal_uInt16 nPart = aTextData.GetPart();
349 : 105 : ScHeaderFooterContentObj& rContentObj = aTextData.GetContentObj();
350 : :
351 [ + + ]: 105 : if (nPart == SC_HDFT_LEFT)
352 [ + - ]: 33 : pData = rContentObj.GetLeftEditObject();
353 [ + + ]: 72 : else if (nPart == SC_HDFT_CENTER)
354 [ + - ]: 39 : pData = rContentObj.GetCenterEditObject();
355 : : else
356 [ + - ]: 33 : pData = rContentObj.GetRightEditObject();
357 [ + + ]: 105 : if (pData)
358 : : {
359 : : // for pure text, no font info is needed in pool defaults
360 [ + - ][ + - ]: 57 : ScHeaderEditEngine aEditEngine( EditEngine::CreatePool(), sal_True );
361 : :
362 [ + - ]: 57 : ScHeaderFieldData aData;
363 [ + - ]: 57 : FillDummyFieldData( aData );
364 [ + - ]: 57 : aEditEngine.SetData( aData );
365 : :
366 [ + - ]: 57 : aEditEngine.SetText(*pData);
367 [ + - ][ + - ]: 57 : aRet = ScEditUtil::GetSpaceDelimitedString( aEditEngine );
[ + - ][ + - ]
[ + - ]
368 : : }
369 [ + - ]: 105 : return aRet;
370 : : }
371 : :
372 : 2269 : void SAL_CALL ScHeaderFooterTextObj::setString( const rtl::OUString& aText ) throw(uno::RuntimeException)
373 : : {
374 [ + - ]: 2269 : SolarMutexGuard aGuard;
375 [ + - ]: 2269 : String aString(aText);
376 : :
377 : : // for pure text, no font info is needed in pool defaults
378 [ + - ][ + - ]: 2269 : ScHeaderEditEngine aEditEngine(EditEngine::CreatePool(), true);
379 [ + - ]: 2269 : aEditEngine.SetText( aString );
380 [ + - ][ + - ]: 2269 : aTextData.UpdateData(aEditEngine);
[ + - ][ + - ]
381 : 2269 : }
382 : :
383 : 1067 : void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XTextRange>& xRange,
384 : : const rtl::OUString& aString, sal_Bool bAbsorb )
385 : : throw(uno::RuntimeException)
386 : : {
387 [ + - ]: 1067 : SolarMutexGuard aGuard;
388 [ - + ]: 1067 : if (!mxUnoText.is())
389 [ # # ]: 0 : CreateUnoText_Impl();
390 [ + - ][ + - ]: 1067 : mxUnoText->insertString( xRange, aString, bAbsorb );
391 : 1067 : }
392 : :
393 : 499 : void SAL_CALL ScHeaderFooterTextObj::insertControlCharacter(
394 : : const uno::Reference<text::XTextRange>& xRange,
395 : : sal_Int16 nControlCharacter, sal_Bool bAbsorb )
396 : : throw(lang::IllegalArgumentException, uno::RuntimeException)
397 : : {
398 [ + - ]: 499 : SolarMutexGuard aGuard;
399 [ - + ]: 499 : if (!mxUnoText.is())
400 [ # # ]: 0 : CreateUnoText_Impl();
401 [ + - ][ + - ]: 499 : mxUnoText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
402 : 499 : }
403 : :
404 : 875 : void SAL_CALL ScHeaderFooterTextObj::insertTextContent(
405 : : const uno::Reference<text::XTextRange >& xRange,
406 : : const uno::Reference<text::XTextContent >& xContent,
407 : : sal_Bool bAbsorb )
408 : : throw(lang::IllegalArgumentException, uno::RuntimeException)
409 : : {
410 [ + - ]: 875 : SolarMutexGuard aGuard;
411 [ + + ][ + - ]: 875 : if ( xContent.is() && xRange.is() )
[ + + ]
412 : : {
413 [ + - ]: 874 : ScEditFieldObj* pHeaderField = ScEditFieldObj::getImplementation( xContent );
414 : :
415 : : SvxUnoTextRangeBase* pTextRange =
416 [ + - ]: 874 : ScHeaderFooterTextCursor::getImplementation( xRange );
417 : :
418 [ + - ][ + - ]: 874 : if ( pHeaderField && !pHeaderField->IsInserted() && pTextRange )
[ + - ][ + - ]
[ + - ]
419 : : {
420 : 874 : SvxEditSource* pEditSource = pTextRange->GetEditSource();
421 : 874 : ESelection aSelection(pTextRange->GetSelection());
422 : :
423 [ + - ]: 874 : if (!bAbsorb)
424 : : {
425 : : // don't replace -> append at end
426 : 874 : aSelection.Adjust();
427 : 874 : aSelection.nStartPara = aSelection.nEndPara;
428 : 874 : aSelection.nStartPos = aSelection.nEndPos;
429 : : }
430 : :
431 [ + - ]: 874 : SvxFieldItem aItem(pHeaderField->CreateFieldItem());
432 : :
433 [ + - ]: 874 : SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
434 [ + - ]: 874 : pForwarder->QuickInsertField( aItem, aSelection );
435 [ + - ]: 874 : pEditSource->UpdateData();
436 : :
437 : : // neue Selektion: ein Zeichen
438 : 874 : aSelection.Adjust();
439 : 874 : aSelection.nEndPara = aSelection.nStartPara;
440 : 874 : aSelection.nEndPos = aSelection.nStartPos + 1;
441 : :
442 : 874 : uno::Reference<text::XTextRange> xTextRange;
443 [ + + + - ]: 874 : switch (aTextData.GetPart())
444 : : {
445 : : case SC_HDFT_LEFT:
446 : : {
447 : : uno::Reference<text::XTextRange> xTemp(
448 [ + - ][ + - ]: 189 : aTextData.GetContentObj().getLeftText(), uno::UNO_QUERY);
449 [ + - ]: 189 : xTextRange = xTemp;
450 : : }
451 : 189 : break;
452 : : case SC_HDFT_CENTER:
453 : : {
454 : : uno::Reference<text::XTextRange> xTemp(
455 [ + - ][ + - ]: 499 : aTextData.GetContentObj().getCenterText(), uno::UNO_QUERY);
456 [ + - ]: 499 : xTextRange = xTemp;
457 : : }
458 : 499 : break;
459 : : case SC_HDFT_RIGHT:
460 : : {
461 : : uno::Reference<text::XTextRange> xTemp(
462 [ + - ][ + - ]: 186 : aTextData.GetContentObj().getRightText(), uno::UNO_QUERY);
463 [ + - ]: 186 : xTextRange = xTemp;
464 : : }
465 : 186 : break;
466 : : }
467 : :
468 [ + - ][ + - ]: 874 : pHeaderField->InitDoc(xTextRange, new ScHeaderFooterEditSource(aTextData), aSelection);
[ + - ]
469 : :
470 : : // for bAbsorb=FALSE, the new selection must be behind the inserted content
471 : : // (the xml filter relies on this)
472 [ + - ]: 874 : if (!bAbsorb)
473 : 874 : aSelection.nStartPos = aSelection.nEndPos;
474 : :
475 : 874 : pTextRange->SetSelection( aSelection );
476 : :
477 [ + - ]: 1748 : return;
478 : : }
479 : : }
480 : :
481 [ - + ]: 1 : if (!mxUnoText.is())
482 [ # # ]: 0 : CreateUnoText_Impl();
483 [ - + ][ + - ]: 875 : mxUnoText->insertTextContent( xRange, xContent, bAbsorb );
[ - + ]
484 : : }
485 : :
486 : 1 : void SAL_CALL ScHeaderFooterTextObj::removeTextContent(
487 : : const uno::Reference<text::XTextContent>& xContent )
488 : : throw(container::NoSuchElementException, uno::RuntimeException)
489 : : {
490 [ + - ]: 1 : SolarMutexGuard aGuard;
491 [ + - ]: 1 : if ( xContent.is() )
492 : : {
493 [ + - ]: 1 : ScEditFieldObj* pHeaderField = ScEditFieldObj::getImplementation(xContent);
494 [ + - ][ + - ]: 1 : if ( pHeaderField && pHeaderField->IsInserted() )
[ + - ][ + - ]
495 : : {
496 : : //! Testen, ob das Feld in dieser Zelle ist
497 [ + - ]: 1 : pHeaderField->DeleteField();
498 : 1 : return;
499 : : }
500 : : }
501 [ # # ]: 0 : if (!mxUnoText.is())
502 [ # # ]: 0 : CreateUnoText_Impl();
503 [ # # ][ + - ]: 1 : mxUnoText->removeTextContent( xContent );
[ - + ]
504 : : }
505 : :
506 : 6 : uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextObj::getText() throw(uno::RuntimeException)
507 : : {
508 [ + - ]: 6 : SolarMutexGuard aGuard;
509 [ + + ]: 6 : if (!mxUnoText.is())
510 [ + - ]: 2 : CreateUnoText_Impl();
511 [ + - ][ + - ]: 6 : return mxUnoText->getText();
512 : : }
513 : :
514 : 1 : uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getStart() throw(uno::RuntimeException)
515 : : {
516 [ + - ]: 1 : SolarMutexGuard aGuard;
517 [ - + ]: 1 : if (!mxUnoText.is())
518 [ # # ]: 0 : CreateUnoText_Impl();
519 [ + - ][ + - ]: 1 : return mxUnoText->getStart();
520 : : }
521 : :
522 : 2 : uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getEnd() throw(uno::RuntimeException)
523 : : {
524 [ + - ]: 2 : SolarMutexGuard aGuard;
525 [ - + ]: 2 : if (!mxUnoText.is())
526 [ # # ]: 0 : CreateUnoText_Impl();
527 [ + - ][ + - ]: 2 : return mxUnoText->getEnd();
528 : : }
529 : :
530 : : // XTextFieldsSupplier
531 : :
532 : 1 : uno::Reference<container::XEnumerationAccess> SAL_CALL ScHeaderFooterTextObj::getTextFields()
533 : : throw(uno::RuntimeException)
534 : : {
535 [ + - ]: 1 : SolarMutexGuard aGuard;
536 : : // all fields
537 [ + - ][ + - ]: 1 : return new ScHeaderFieldsObj(aTextData);
[ + - ][ + - ]
538 : : }
539 : :
540 : 0 : uno::Reference<container::XNameAccess> SAL_CALL ScHeaderFooterTextObj::getTextFieldMasters()
541 : : throw(uno::RuntimeException)
542 : : {
543 : : // sowas gibts nicht im Calc (?)
544 : 0 : return NULL;
545 : : }
546 : :
547 : : // XTextRangeMover
548 : :
549 : 0 : void SAL_CALL ScHeaderFooterTextObj::moveTextRange(
550 : : const uno::Reference<text::XTextRange>& xRange,
551 : : sal_Int16 nParagraphs )
552 : : throw(uno::RuntimeException)
553 : : {
554 [ # # ]: 0 : SolarMutexGuard aGuard;
555 [ # # ]: 0 : if (!mxUnoText.is())
556 [ # # ]: 0 : CreateUnoText_Impl();
557 [ # # ][ # # ]: 0 : mxUnoText->moveTextRange( xRange, nParagraphs );
558 : 0 : }
559 : :
560 : : // XEnumerationAccess
561 : :
562 : 117 : uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEnumeration()
563 : : throw(uno::RuntimeException)
564 : : {
565 [ + - ]: 117 : SolarMutexGuard aGuard;
566 [ + + ]: 117 : if (!mxUnoText.is())
567 [ + - ]: 116 : CreateUnoText_Impl();
568 [ + - ][ + - ]: 117 : return mxUnoText->createEnumeration();
569 : : }
570 : :
571 : : // XElementAccess
572 : :
573 : 1 : uno::Type SAL_CALL ScHeaderFooterTextObj::getElementType() throw(uno::RuntimeException)
574 : : {
575 [ + - ]: 1 : SolarMutexGuard aGuard;
576 [ - + ]: 1 : if (!mxUnoText.is())
577 [ # # ]: 0 : CreateUnoText_Impl();
578 [ + - ][ + - ]: 1 : return mxUnoText->getElementType();
579 : : }
580 : :
581 : 1 : sal_Bool SAL_CALL ScHeaderFooterTextObj::hasElements() throw(uno::RuntimeException)
582 : : {
583 [ + - ]: 1 : SolarMutexGuard aGuard;
584 [ - + ]: 1 : if (!mxUnoText.is())
585 [ # # ]: 0 : CreateUnoText_Impl();
586 [ + - ][ + - ]: 1 : return mxUnoText->hasElements();
587 : : }
588 : :
589 : : //------------------------------------------------------------------------
590 : :
591 : 21 : ScCellTextCursor::ScCellTextCursor(const ScCellTextCursor& rOther) :
592 : : SvxUnoTextCursor( rOther ),
593 : 21 : rTextObj( rOther.rTextObj )
594 : : {
595 : 21 : rTextObj.acquire();
596 : 21 : }
597 : :
598 : 27 : ScCellTextCursor::ScCellTextCursor(ScCellObj& rText) :
599 : 27 : SvxUnoTextCursor( rText.GetUnoText() ),
600 : 27 : rTextObj( rText )
601 : : {
602 : 27 : rTextObj.acquire();
603 : 27 : }
604 : :
605 : 48 : ScCellTextCursor::~ScCellTextCursor() throw()
606 : : {
607 : 48 : rTextObj.release();
608 [ - + ]: 96 : }
609 : :
610 : : // SvxUnoTextCursor methods reimplemented here to return the right objects:
611 : :
612 : 12 : uno::Reference<text::XText> SAL_CALL ScCellTextCursor::getText() throw(uno::RuntimeException)
613 : : {
614 [ + - ]: 12 : SolarMutexGuard aGuard;
615 [ + - ][ + - ]: 12 : return &rTextObj;
616 : : }
617 : :
618 : 20 : uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getStart() throw(uno::RuntimeException)
619 : : {
620 [ + - ]: 20 : SolarMutexGuard aGuard;
621 : :
622 : : //! use other object for range than cursor?
623 : :
624 : 20 : ScCellTextCursor* pNew = new ScCellTextCursor( *this );
625 [ + - ][ + - ]: 20 : uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
626 : :
627 : 20 : ESelection aNewSel(GetSelection());
628 : 20 : aNewSel.nEndPara = aNewSel.nStartPara;
629 : 20 : aNewSel.nEndPos = aNewSel.nStartPos;
630 : 20 : pNew->SetSelection( aNewSel );
631 : :
632 [ + - ]: 20 : return xRange;
633 : : }
634 : :
635 : 1 : uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getEnd() throw(uno::RuntimeException)
636 : : {
637 [ + - ]: 1 : SolarMutexGuard aGuard;
638 : :
639 : : //! use other object for range than cursor?
640 : :
641 : 1 : ScCellTextCursor* pNew = new ScCellTextCursor( *this );
642 [ + - ][ + - ]: 1 : uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
643 : :
644 : 1 : ESelection aNewSel(GetSelection());
645 : 1 : aNewSel.nStartPara = aNewSel.nEndPara;
646 : 1 : aNewSel.nStartPos = aNewSel.nEndPos;
647 : 1 : pNew->SetSelection( aNewSel );
648 : :
649 [ + - ]: 1 : return xRange;
650 : : }
651 : :
652 : : // XUnoTunnel
653 : :
654 : 59 : sal_Int64 SAL_CALL ScCellTextCursor::getSomething(
655 : : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
656 : : {
657 [ + - + + ]: 118 : if ( rId.getLength() == 16 &&
[ + + ]
658 : 59 : 0 == memcmp( getUnoTunnelId().getConstArray(),
659 : 59 : rId.getConstArray(), 16 ) )
660 : : {
661 : 11 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
662 : : }
663 : 59 : return SvxUnoTextCursor::getSomething( rId );
664 : : }
665 : :
666 : : namespace
667 : : {
668 : : class theScCellTextCursorUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScCellTextCursorUnoTunnelId> {};
669 : : }
670 : :
671 : 170 : const uno::Sequence<sal_Int8>& ScCellTextCursor::getUnoTunnelId()
672 : : {
673 : 170 : return theScCellTextCursorUnoTunnelId::get().getSeq();
674 : : }
675 : :
676 : 111 : ScCellTextCursor* ScCellTextCursor::getImplementation( const uno::Reference<uno::XInterface> xObj )
677 : : {
678 : 111 : ScCellTextCursor* pRet = NULL;
679 [ + - ]: 111 : uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
680 [ + - ]: 111 : if (xUT.is())
681 [ + - ][ + - ]: 111 : pRet = reinterpret_cast<ScCellTextCursor*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
[ + - ]
682 : 111 : return pRet;
683 : : }
684 : :
685 : : //------------------------------------------------------------------------
686 : :
687 : 1053 : ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor& rOther) :
688 : : SvxUnoTextCursor( rOther ),
689 : 1053 : rTextObj( rOther.rTextObj )
690 : : {
691 : 1053 : rTextObj.acquire();
692 : 1053 : }
693 : :
694 : 1112 : ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(ScHeaderFooterTextObj& rText) :
695 : 1112 : SvxUnoTextCursor( rText.GetUnoText() ),
696 : 1112 : rTextObj( rText )
697 : : {
698 : 1112 : rTextObj.acquire();
699 : 1112 : }
700 : :
701 : 2165 : ScHeaderFooterTextCursor::~ScHeaderFooterTextCursor() throw()
702 : : {
703 : 2165 : rTextObj.release();
704 [ - + ]: 4330 : }
705 : :
706 : : // SvxUnoTextCursor methods reimplemented here to return the right objects:
707 : :
708 : 490 : uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextCursor::getText() throw(uno::RuntimeException)
709 : : {
710 [ + - ]: 490 : SolarMutexGuard aGuard;
711 [ + - ][ + - ]: 490 : return &rTextObj;
712 : : }
713 : :
714 : 1052 : uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getStart() throw(uno::RuntimeException)
715 : : {
716 [ + - ]: 1052 : SolarMutexGuard aGuard;
717 : :
718 : : //! use other object for range than cursor?
719 : :
720 : 1052 : ScHeaderFooterTextCursor* pNew = new ScHeaderFooterTextCursor( *this );
721 [ + - ][ + - ]: 1052 : uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
722 : :
723 : 1052 : ESelection aNewSel(GetSelection());
724 : 1052 : aNewSel.nEndPara = aNewSel.nStartPara;
725 : 1052 : aNewSel.nEndPos = aNewSel.nStartPos;
726 : 1052 : pNew->SetSelection( aNewSel );
727 : :
728 [ + - ]: 1052 : return xRange;
729 : : }
730 : :
731 : 1 : uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getEnd() throw(uno::RuntimeException)
732 : : {
733 [ + - ]: 1 : SolarMutexGuard aGuard;
734 : :
735 : : //! use other object for range than cursor?
736 : :
737 : 1 : ScHeaderFooterTextCursor* pNew = new ScHeaderFooterTextCursor( *this );
738 [ + - ][ + - ]: 1 : uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
739 : :
740 : 1 : ESelection aNewSel(GetSelection());
741 : 1 : aNewSel.nStartPara = aNewSel.nEndPara;
742 : 1 : aNewSel.nStartPos = aNewSel.nEndPos;
743 : 1 : pNew->SetSelection( aNewSel );
744 : :
745 [ + - ]: 1 : return xRange;
746 : : }
747 : :
748 : : // XUnoTunnel
749 : :
750 : 3648 : sal_Int64 SAL_CALL ScHeaderFooterTextCursor::getSomething(
751 : : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
752 : : {
753 [ + - + + ]: 7296 : if ( rId.getLength() == 16 &&
[ + + ]
754 : 3648 : 0 == memcmp( getUnoTunnelId().getConstArray(),
755 : 3648 : rId.getConstArray(), 16 ) )
756 : : {
757 : 874 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
758 : : }
759 : 3648 : return SvxUnoTextCursor::getSomething( rId );
760 : : }
761 : :
762 : : namespace
763 : : {
764 : : class theScHeaderFooterTextCursorUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScHeaderFooterTextCursorUnoTunnelId> {};
765 : : }
766 : :
767 : 4522 : const uno::Sequence<sal_Int8>& ScHeaderFooterTextCursor::getUnoTunnelId()
768 : : {
769 : 4522 : return theScHeaderFooterTextCursorUnoTunnelId::get().getSeq();
770 : : }
771 : :
772 : 874 : ScHeaderFooterTextCursor* ScHeaderFooterTextCursor::getImplementation(
773 : : const uno::Reference<uno::XInterface> xObj )
774 : : {
775 : 874 : ScHeaderFooterTextCursor* pRet = NULL;
776 [ + - ]: 874 : uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
777 [ + - ]: 874 : if (xUT.is())
778 [ + - ][ + - ]: 874 : pRet = reinterpret_cast<ScHeaderFooterTextCursor*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
[ + - ]
779 : 874 : return pRet;
780 : : }
781 : :
782 : : //------------------------------------------------------------------------
783 : :
784 : 32 : ScDrawTextCursor::ScDrawTextCursor(const ScDrawTextCursor& rOther) :
785 : : SvxUnoTextCursor( rOther ),
786 : 32 : xParentText( rOther.xParentText )
787 : : {
788 : 32 : }
789 : :
790 : 32 : ScDrawTextCursor::ScDrawTextCursor( const uno::Reference<text::XText>& xParent,
791 : : const SvxUnoTextBase& rText ) :
792 : : SvxUnoTextCursor( rText ),
793 : 32 : xParentText( xParent )
794 : :
795 : : {
796 : 32 : }
797 : :
798 : 64 : ScDrawTextCursor::~ScDrawTextCursor() throw()
799 : : {
800 [ - + ]: 128 : }
801 : :
802 : : // SvxUnoTextCursor methods reimplemented here to return the right objects:
803 : :
804 : 16 : uno::Reference<text::XText> SAL_CALL ScDrawTextCursor::getText() throw(uno::RuntimeException)
805 : : {
806 [ + - ]: 16 : SolarMutexGuard aGuard;
807 [ + - ]: 16 : return xParentText;
808 : : }
809 : :
810 : 32 : uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getStart() throw(uno::RuntimeException)
811 : : {
812 [ + - ]: 32 : SolarMutexGuard aGuard;
813 : :
814 : : //! use other object for range than cursor?
815 : :
816 [ + - ]: 32 : ScDrawTextCursor* pNew = new ScDrawTextCursor( *this );
817 [ + - ][ + - ]: 32 : uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
818 : :
819 : 32 : ESelection aNewSel(GetSelection());
820 : 32 : aNewSel.nEndPara = aNewSel.nStartPara;
821 : 32 : aNewSel.nEndPos = aNewSel.nStartPos;
822 : 32 : pNew->SetSelection( aNewSel );
823 : :
824 [ + - ]: 32 : return xRange;
825 : : }
826 : :
827 : 0 : uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getEnd() throw(uno::RuntimeException)
828 : : {
829 [ # # ]: 0 : SolarMutexGuard aGuard;
830 : :
831 : : //! use other object for range than cursor?
832 : :
833 [ # # ]: 0 : ScDrawTextCursor* pNew = new ScDrawTextCursor( *this );
834 [ # # ][ # # ]: 0 : uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
835 : :
836 : 0 : ESelection aNewSel(GetSelection());
837 : 0 : aNewSel.nStartPara = aNewSel.nEndPara;
838 : 0 : aNewSel.nStartPos = aNewSel.nEndPos;
839 : 0 : pNew->SetSelection( aNewSel );
840 : :
841 [ # # ]: 0 : return xRange;
842 : : }
843 : :
844 : : // XUnoTunnel
845 : :
846 : 62 : sal_Int64 SAL_CALL ScDrawTextCursor::getSomething(
847 : : const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException)
848 : : {
849 [ + - + + ]: 124 : if ( rId.getLength() == 16 &&
[ + + ]
850 : 62 : 0 == memcmp( getUnoTunnelId().getConstArray(),
851 : 62 : rId.getConstArray(), 16 ) )
852 : : {
853 : 3 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
854 : : }
855 : 62 : return SvxUnoTextCursor::getSomething( rId );
856 : : }
857 : :
858 : : namespace
859 : : {
860 : : class theScDrawTextCursorUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScDrawTextCursorUnoTunnelId> {};
861 : : }
862 : :
863 : 162 : const uno::Sequence<sal_Int8>& ScDrawTextCursor::getUnoTunnelId()
864 : : {
865 : 162 : return theScDrawTextCursorUnoTunnelId::get().getSeq();
866 : : }
867 : :
868 : 100 : ScDrawTextCursor* ScDrawTextCursor::getImplementation( const uno::Reference<uno::XInterface> xObj )
869 : : {
870 : 100 : ScDrawTextCursor* pRet = NULL;
871 [ + - ]: 100 : uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY );
872 [ + - ]: 100 : if (xUT.is())
873 [ + - ][ + - ]: 100 : pRet = reinterpret_cast<ScDrawTextCursor*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething(getUnoTunnelId())));
[ + - ]
874 : 100 : return pRet;
875 : : }
876 : :
877 : : //------------------------------------------------------------------------
878 : :
879 : 0 : ScSimpleEditSourceHelper::ScSimpleEditSourceHelper()
880 : : {
881 : 0 : SfxItemPool* pEnginePool = EditEngine::CreatePool();
882 : 0 : pEnginePool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM );
883 : 0 : pEnginePool->FreezeIdRanges();
884 : :
885 [ # # ]: 0 : pEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true); // TRUE: become owner of pool
886 [ # # ]: 0 : pForwarder = new SvxEditEngineForwarder( *pEditEngine );
887 [ # # ]: 0 : pOriginalSource = new ScSimpleEditSource( pForwarder );
888 : 0 : }
889 : :
890 : 0 : ScSimpleEditSourceHelper::~ScSimpleEditSourceHelper()
891 : : {
892 [ # # ]: 0 : SolarMutexGuard aGuard; // needed for EditEngine dtor
893 : :
894 [ # # ][ # # ]: 0 : delete pOriginalSource;
895 [ # # ][ # # ]: 0 : delete pForwarder;
896 [ # # ][ # # ]: 0 : delete pEditEngine;
[ # # ]
897 : 0 : }
898 : :
899 : 0 : ScEditEngineTextObj::ScEditEngineTextObj() :
900 [ # # ]: 0 : SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
901 : : {
902 : 0 : }
903 : :
904 : 0 : ScEditEngineTextObj::~ScEditEngineTextObj() throw()
905 : : {
906 [ # # ]: 0 : }
907 : :
908 : 0 : void ScEditEngineTextObj::SetText( const EditTextObject& rTextObject )
909 : : {
910 [ # # ]: 0 : GetEditEngine()->SetText( rTextObject );
911 : :
912 : 0 : ESelection aSel;
913 [ # # ]: 0 : ::GetSelection( aSel, GetEditSource()->GetTextForwarder() );
914 : 0 : SetSelection( aSel );
915 : 0 : }
916 : :
917 : 0 : EditTextObject* ScEditEngineTextObj::CreateTextObject()
918 : : {
919 : 0 : return GetEditEngine()->CreateTextObject();
920 : : }
921 : :
922 : : //------------------------------------------------------------------------
923 : :
924 : 160 : ScCellTextData::ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP) :
925 : : pDocShell( pDocSh ),
926 : : aCellPos( rP ),
927 : : pEditEngine( NULL ),
928 : : pForwarder( NULL ),
929 : : pOriginalSource( NULL ),
930 : : bDataValid( false ),
931 : : bInUpdate( false ),
932 : : bDirty( false ),
933 : 160 : bDoUpdate( sal_True )
934 : : {
935 [ + - ]: 160 : if (pDocShell)
936 [ + - ]: 160 : pDocShell->GetDocument()->AddUnoObject(*this);
937 : 160 : }
938 : :
939 : 149 : ScCellTextData::~ScCellTextData()
940 : : {
941 [ + - ]: 149 : SolarMutexGuard aGuard; // needed for EditEngine dtor
942 : :
943 [ + + ]: 149 : if (pDocShell)
944 : : {
945 [ + - ]: 87 : pDocShell->GetDocument()->RemoveUnoObject(*this);
946 [ + - ]: 87 : pDocShell->GetDocument()->DisposeFieldEditEngine(pEditEngine);
947 : : }
948 : : else
949 [ - + ][ # # ]: 62 : delete pEditEngine;
950 : :
951 [ + + ][ + - ]: 149 : delete pForwarder;
952 : :
953 [ + + ][ + - ]: 149 : delete pOriginalSource;
[ + - ]
954 [ - + ]: 250 : }
955 : :
956 : 18 : ScCellEditSource* ScCellTextData::GetOriginalSource()
957 : : {
958 [ + - ]: 18 : if (!pOriginalSource)
959 [ + - ]: 18 : pOriginalSource = new ScCellEditSource(pDocShell, aCellPos);
960 : 18 : return pOriginalSource;
961 : : }
962 : :
963 : 93 : void ScCellTextData::GetCellText(const ScAddress& rCellPos, String& rText)
964 : : {
965 [ + - ]: 93 : if (pDocShell)
966 : : {
967 : 93 : ScDocument* pDoc = pDocShell->GetDocument();
968 : 93 : pDoc->GetInputString( rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText );
969 : : }
970 : 93 : }
971 : :
972 : 2557 : SvxTextForwarder* ScCellTextData::GetTextForwarder()
973 : : {
974 [ + + ]: 2557 : if (!pEditEngine)
975 : : {
976 [ + - ]: 104 : if ( pDocShell )
977 : : {
978 : 104 : ScDocument* pDoc = pDocShell->GetDocument();
979 [ + - ]: 104 : pEditEngine = pDoc->CreateFieldEditEngine();
980 : : }
981 : : else
982 : : {
983 [ # # ]: 0 : SfxItemPool* pEnginePool = EditEngine::CreatePool();
984 [ # # ]: 0 : pEnginePool->FreezeIdRanges();
985 [ # # ][ # # ]: 0 : pEditEngine = new ScFieldEditEngine(NULL, pEnginePool, NULL, true);
986 : : }
987 : : // currently, GetPortions doesn't work if UpdateMode is sal_False,
988 : : // this will be fixed (in EditEngine) by src600
989 : : // pEditEngine->SetUpdateMode( sal_False );
990 [ + - ]: 104 : pEditEngine->EnableUndo( false );
991 [ + - ]: 104 : if (pDocShell)
992 [ + - ][ + - ]: 104 : pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
993 : : else
994 [ # # ][ # # ]: 0 : pEditEngine->SetRefMapMode( MAP_100TH_MM );
[ # # ]
995 [ + - ][ + - ]: 104 : pForwarder = new SvxEditEngineForwarder(*pEditEngine);
996 : : }
997 : :
998 [ + + ]: 2557 : if (bDataValid)
999 : 2391 : return pForwarder;
1000 : :
1001 [ + - ]: 166 : String aText;
1002 : :
1003 [ + - ]: 166 : if (pDocShell)
1004 : : {
1005 : 166 : ScDocument* pDoc = pDocShell->GetDocument();
1006 : :
1007 [ + - ][ + - ]: 166 : SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() );
1008 [ + - ]: 166 : if( const ScPatternAttr* pPattern =
1009 [ + - ]: 166 : pDoc->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
1010 : : {
1011 [ + - ]: 166 : pPattern->FillEditItemSet( &aDefaults );
1012 [ + - ]: 166 : pPattern->FillEditParaItems( &aDefaults ); // including alignment etc. (for reading)
1013 : : }
1014 : :
1015 [ + - ]: 166 : const ScBaseCell* pCell = pDoc->GetCell( aCellPos );
1016 [ + + ][ + + ]: 166 : if ( pCell && pCell->GetCellType() == CELLTYPE_EDIT )
[ + + ]
1017 [ + - ]: 64 : pEditEngine->SetTextNewDefaults( *((const ScEditCell*)pCell)->GetData(), aDefaults );
1018 : : else
1019 : : {
1020 [ + - ]: 102 : GetCellText( aCellPos, aText );
1021 [ + + ]: 102 : if (aText.Len())
1022 [ + - ]: 59 : pEditEngine->SetTextNewDefaults( aText, aDefaults );
1023 : : else
1024 [ + - ]: 43 : pEditEngine->SetDefaults(aDefaults);
1025 [ + - ]: 166 : }
1026 : : }
1027 : :
1028 : 166 : bDataValid = sal_True;
1029 [ + - ]: 2557 : return pForwarder;
1030 : : }
1031 : :
1032 : 262 : void ScCellTextData::UpdateData()
1033 : : {
1034 [ + - ]: 262 : if ( bDoUpdate )
1035 : : {
1036 : : OSL_ENSURE(pEditEngine != NULL, "no EditEngine for UpdateData()");
1037 [ + - ][ + - ]: 262 : if ( pDocShell && pEditEngine )
1038 : : {
1039 : : // during the own UpdateData call, bDataValid must not be reset,
1040 : : // or things like attributes after the text would be lost
1041 : : // (are not stored in the cell)
1042 : 262 : bInUpdate = sal_True; // prevents bDataValid from being reset
1043 : 262 : pDocShell->GetDocFunc().PutData( aCellPos, *pEditEngine, false, sal_True ); // always as text
1044 : :
1045 : 262 : bInUpdate = false;
1046 : 262 : bDirty = false;
1047 : : }
1048 : : }
1049 : : else
1050 : 0 : bDirty = sal_True;
1051 : 262 : }
1052 : :
1053 : 2590 : void ScCellTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
1054 : : {
1055 [ + - ]: 2590 : if ( rHint.ISA( ScUpdateRefHint ) )
1056 : : {
1057 : : // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
1058 : :
1059 : : //! Ref-Update
1060 : : }
1061 [ + - ]: 2590 : else if ( rHint.ISA( SfxSimpleHint ) )
1062 : : {
1063 : 2590 : sal_uLong nId = ((const SfxSimpleHint&)rHint).GetId();
1064 [ + + ]: 2590 : if ( nId == SFX_HINT_DYING )
1065 : : {
1066 : 73 : pDocShell = NULL; // invalid now
1067 : :
1068 [ + + ]: 73 : DELETEZ( pForwarder );
1069 [ + + ]: 73 : DELETEZ( pEditEngine ); // EditEngine uses document's pool
1070 : : }
1071 [ + - ]: 2517 : else if ( nId == SFX_HINT_DATACHANGED )
1072 : : {
1073 [ + + ]: 2517 : if (!bInUpdate) // not for own UpdateData calls
1074 : 2142 : bDataValid = false; // text has to be read from the cell again
1075 : : }
1076 : : }
1077 : 2590 : }
1078 : :
1079 : 18 : ScCellTextObj::ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP) :
1080 : : ScCellTextData( pDocSh, rP ),
1081 [ + - ][ + - ]: 18 : SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
1082 : : {
1083 : 18 : }
1084 : :
1085 : 18 : ScCellTextObj::~ScCellTextObj() throw()
1086 : : {
1087 [ - + ]: 36 : }
1088 : :
1089 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|