1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
22 #include <svx/svdpool.hxx>
23 #include <svx/svdobj.hxx>
24 #include <editeng/editeng.hxx>
25 #include <editeng/editobj.hxx>
26 #include <editeng/flditem.hxx>
27 #include <svx/unomid.hxx>
28 #include <editeng/unoprnms.hxx>
29 #include <editeng/unofored.hxx>
30 #include <vcl/virdev.hxx>
31 #include <vcl/svapp.hxx>
32 #include <com/sun/star/awt/FontSlant.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <editeng/unoipset.hxx>
36 #include "textuno.hxx"
37 #include "fielduno.hxx"
38 #include "servuno.hxx"
39 #include "editsrc.hxx"
41 #include "editutil.hxx"
42 #include "miscuno.hxx"
43 #include "cellsuno.hxx"
45 #include "patattr.hxx"
46 #include "formulacell.hxx"
47 #include "docfunc.hxx"
50 using namespace com::sun::star
;
52 static const SvxItemPropertySet
* lcl_GetHdFtPropertySet()
54 static SfxItemPropertyMapEntry aHdFtPropertyMap_Impl
[] =
56 SVX_UNOEDIT_CHAR_PROPERTIES
,
57 SVX_UNOEDIT_FONT_PROPERTIES
,
58 SVX_UNOEDIT_PARA_PROPERTIES
,
59 SVX_UNOEDIT_NUMBERING_PROPERTIE
, // for completeness of service ParagraphProperties
60 { OUString(), 0, css::uno::Type(), 0, 0 }
62 static bool bTwipsSet
= false;
66 // modify PropertyMap to include CONVERT_TWIPS flag for font height
67 // (headers/footers are in twips)
69 SfxItemPropertyMapEntry
* pEntry
= aHdFtPropertyMap_Impl
;
70 while (!pEntry
->aName
.isEmpty())
72 if ( ( pEntry
->nWID
== EE_CHAR_FONTHEIGHT
||
73 pEntry
->nWID
== EE_CHAR_FONTHEIGHT_CJK
||
74 pEntry
->nWID
== EE_CHAR_FONTHEIGHT_CTL
) &&
75 pEntry
->nMemberId
== MID_FONTHEIGHT
)
77 pEntry
->nMemberId
|= CONVERT_TWIPS
;
84 static SvxItemPropertySet
aHdFtPropertySet_Impl( aHdFtPropertyMap_Impl
, SdrObject::GetGlobalDrawObjectItemPool() );
85 return &aHdFtPropertySet_Impl
;
88 SC_SIMPLE_SERVICE_INFO( ScHeaderFooterContentObj
, "ScHeaderFooterContentObj", "com.sun.star.sheet.HeaderFooterContent" )
89 SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj
, "ScHeaderFooterTextObj", "stardiv.one.Text.Text" )
91 ScHeaderFooterContentObj::ScHeaderFooterContentObj( const EditTextObject
* pLeft
,
92 const EditTextObject
* pCenter
,
93 const EditTextObject
* pRight
) :
94 mxLeftText(new ScHeaderFooterTextObj(this, SC_HDFT_LEFT
, pLeft
)),
95 mxCenterText(new ScHeaderFooterTextObj(this, SC_HDFT_CENTER
, pCenter
)),
96 mxRightText(new ScHeaderFooterTextObj(this, SC_HDFT_RIGHT
, pRight
))
100 ScHeaderFooterContentObj::~ScHeaderFooterContentObj() {}
102 const EditTextObject
* ScHeaderFooterContentObj::GetLeftEditObject() const
104 return mxLeftText
->GetTextObject();
107 const EditTextObject
* ScHeaderFooterContentObj::GetCenterEditObject() const
109 return mxCenterText
->GetTextObject();
112 const EditTextObject
* ScHeaderFooterContentObj::GetRightEditObject() const
114 return mxRightText
->GetTextObject();
117 // XHeaderFooterContent
119 uno::Reference
<text::XText
> SAL_CALL
ScHeaderFooterContentObj::getLeftText()
120 throw(uno::RuntimeException
, std::exception
)
122 SolarMutexGuard aGuard
;
123 uno::Reference
<text::XText
> xInt(*mxLeftText
, uno::UNO_QUERY
);
127 uno::Reference
<text::XText
> SAL_CALL
ScHeaderFooterContentObj::getCenterText()
128 throw(uno::RuntimeException
, std::exception
)
130 SolarMutexGuard aGuard
;
131 uno::Reference
<text::XText
> xInt(*mxCenterText
, uno::UNO_QUERY
);
135 uno::Reference
<text::XText
> SAL_CALL
ScHeaderFooterContentObj::getRightText()
136 throw(uno::RuntimeException
, std::exception
)
138 SolarMutexGuard aGuard
;
139 uno::Reference
<text::XText
> xInt(*mxRightText
, uno::UNO_QUERY
);
145 sal_Int64 SAL_CALL
ScHeaderFooterContentObj::getSomething(
146 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
148 if ( rId
.getLength() == 16 &&
149 0 == memcmp( getUnoTunnelId().getConstArray(),
150 rId
.getConstArray(), 16 ) )
152 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
159 class theScHeaderFooterContentObjUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScHeaderFooterContentObjUnoTunnelId
> {};
162 const uno::Sequence
<sal_Int8
>& ScHeaderFooterContentObj::getUnoTunnelId()
164 return theScHeaderFooterContentObjUnoTunnelId::get().getSeq();
167 rtl::Reference
<ScHeaderFooterContentObj
> ScHeaderFooterContentObj::getImplementation(
168 const uno::Reference
<sheet::XHeaderFooterContent
>& rObj
)
170 rtl::Reference
<ScHeaderFooterContentObj
> pRet
;
171 uno::Reference
<lang::XUnoTunnel
> xUT(rObj
, uno::UNO_QUERY
);
173 pRet
= reinterpret_cast<ScHeaderFooterContentObj
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
177 ScHeaderFooterTextData::ScHeaderFooterTextData(
178 rtl::Reference
<ScHeaderFooterContentObj
> const & rContent
, sal_uInt16 nP
, const EditTextObject
* pTextObj
) :
179 mpTextObj(pTextObj
? pTextObj
->Clone() : NULL
),
180 rContentObj( rContent
),
188 ScHeaderFooterTextData::~ScHeaderFooterTextData()
190 SolarMutexGuard aGuard
; // needed for EditEngine dtor
197 SvxTextForwarder
* ScHeaderFooterTextData::GetTextForwarder()
201 SfxItemPool
* pEnginePool
= EditEngine::CreatePool();
202 pEnginePool
->FreezeIdRanges();
203 ScHeaderEditEngine
* pHdrEngine
= new ScHeaderEditEngine( pEnginePool
, true );
205 pHdrEngine
->EnableUndo( false );
206 pHdrEngine
->SetRefMapMode( MAP_TWIP
);
208 // default font must be set, independently of document
209 // -> use global pool from module
211 SfxItemSet
aDefaults( pHdrEngine
->GetEmptyItemSet() );
212 const ScPatternAttr
& rPattern
= static_cast<const ScPatternAttr
&>(SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN
));
213 rPattern
.FillEditItemSet( &aDefaults
);
214 // FillEditItemSet adjusts font height to 1/100th mm,
215 // but for header/footer twips is needed, as in the PatternAttr:
216 aDefaults
.Put( rPattern
.GetItem(ATTR_FONT_HEIGHT
), EE_CHAR_FONTHEIGHT
);
217 aDefaults
.Put( rPattern
.GetItem(ATTR_CJK_FONT_HEIGHT
), EE_CHAR_FONTHEIGHT_CJK
);
218 aDefaults
.Put( rPattern
.GetItem(ATTR_CTL_FONT_HEIGHT
), EE_CHAR_FONTHEIGHT_CTL
);
219 pHdrEngine
->SetDefaults( aDefaults
);
221 ScHeaderFieldData aData
;
222 ScHeaderFooterTextObj::FillDummyFieldData( aData
);
223 pHdrEngine
->SetData( aData
);
225 pEditEngine
= pHdrEngine
;
226 pForwarder
= new SvxEditEngineForwarder(*pEditEngine
);
233 pEditEngine
->SetText(*mpTextObj
);
239 void ScHeaderFooterTextData::UpdateData()
244 mpTextObj
= pEditEngine
->CreateTextObject();
248 void ScHeaderFooterTextData::UpdateData(EditEngine
& rEditEngine
)
251 mpTextObj
= rEditEngine
.CreateTextObject();
255 ScHeaderFooterTextObj::ScHeaderFooterTextObj(
256 rtl::Reference
<ScHeaderFooterContentObj
> const & rContent
, sal_uInt16 nP
, const EditTextObject
* pTextObj
) :
257 aTextData(rContent
, nP
, pTextObj
)
259 // ScHeaderFooterTextData acquires rContent
260 // pUnoText is created on demand (getString/setString work without it)
263 void ScHeaderFooterTextObj::CreateUnoText_Impl()
267 // can't be aggregated because getString/setString is handled here
268 ScHeaderFooterEditSource
aEditSrc(aTextData
);
269 mxUnoText
.set(new SvxUnoText(&aEditSrc
, lcl_GetHdFtPropertySet(), uno::Reference
<text::XText
>()));
273 ScHeaderFooterTextObj::~ScHeaderFooterTextObj() {}
275 const EditTextObject
* ScHeaderFooterTextObj::GetTextObject() const
277 return aTextData
.GetTextObject();
280 const SvxUnoText
& ScHeaderFooterTextObj::GetUnoText()
283 CreateUnoText_Impl();
289 uno::Reference
<text::XTextCursor
> SAL_CALL
ScHeaderFooterTextObj::createTextCursor()
290 throw(uno::RuntimeException
, std::exception
)
292 SolarMutexGuard aGuard
;
293 return new ScHeaderFooterTextCursor( *this );
296 uno::Reference
<text::XTextCursor
> SAL_CALL
ScHeaderFooterTextObj::createTextCursorByRange(
297 const uno::Reference
<text::XTextRange
>& aTextPosition
)
298 throw(uno::RuntimeException
, std::exception
)
300 SolarMutexGuard aGuard
;
302 CreateUnoText_Impl();
303 return mxUnoText
->createTextCursorByRange(aTextPosition
);
304 //! wie ScCellObj::createTextCursorByRange, wenn SvxUnoTextRange_getReflection verfuegbar
307 void ScHeaderFooterTextObj::FillDummyFieldData( ScHeaderFieldData
& rData
)
309 OUString
aDummy("???");
310 rData
.aTitle
= aDummy
;
311 rData
.aLongDocName
= aDummy
;
312 rData
.aShortDocName
= aDummy
;
313 rData
.aTabName
= aDummy
;
315 rData
.nTotalPages
= 99;
318 OUString SAL_CALL
ScHeaderFooterTextObj::getString() throw(uno::RuntimeException
, std::exception
)
320 SolarMutexGuard aGuard
;
322 const EditTextObject
* pData
;
324 sal_uInt16 nPart
= aTextData
.GetPart();
325 rtl::Reference
<ScHeaderFooterContentObj
> rContentObj
= aTextData
.GetContentObj();
327 if (nPart
== SC_HDFT_LEFT
)
328 pData
= rContentObj
->GetLeftEditObject();
329 else if (nPart
== SC_HDFT_CENTER
)
330 pData
= rContentObj
->GetCenterEditObject();
332 pData
= rContentObj
->GetRightEditObject();
335 // for pure text, no font info is needed in pool defaults
336 ScHeaderEditEngine
aEditEngine( EditEngine::CreatePool(), true );
338 ScHeaderFieldData aData
;
339 FillDummyFieldData( aData
);
340 aEditEngine
.SetData( aData
);
342 aEditEngine
.SetText(*pData
);
343 aRet
= ScEditUtil::GetSpaceDelimitedString( aEditEngine
);
348 void SAL_CALL
ScHeaderFooterTextObj::setString( const OUString
& aText
) throw(uno::RuntimeException
, std::exception
)
350 SolarMutexGuard aGuard
;
351 OUString
aString(aText
);
353 // for pure text, no font info is needed in pool defaults
354 ScHeaderEditEngine
aEditEngine(EditEngine::CreatePool(), true);
355 aEditEngine
.SetText( aString
);
356 aTextData
.UpdateData(aEditEngine
);
359 void SAL_CALL
ScHeaderFooterTextObj::insertString( const uno::Reference
<text::XTextRange
>& xRange
,
360 const OUString
& aString
, sal_Bool bAbsorb
)
361 throw(uno::RuntimeException
, std::exception
)
363 SolarMutexGuard aGuard
;
365 CreateUnoText_Impl();
366 mxUnoText
->insertString( xRange
, aString
, bAbsorb
);
369 void SAL_CALL
ScHeaderFooterTextObj::insertControlCharacter(
370 const uno::Reference
<text::XTextRange
>& xRange
,
371 sal_Int16 nControlCharacter
, sal_Bool bAbsorb
)
372 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
374 SolarMutexGuard aGuard
;
376 CreateUnoText_Impl();
377 mxUnoText
->insertControlCharacter( xRange
, nControlCharacter
, bAbsorb
);
380 void SAL_CALL
ScHeaderFooterTextObj::insertTextContent(
381 const uno::Reference
<text::XTextRange
>& xRange
,
382 const uno::Reference
<text::XTextContent
>& xContent
,
384 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
386 SolarMutexGuard aGuard
;
387 if ( xContent
.is() && xRange
.is() )
389 ScEditFieldObj
* pHeaderField
= ScEditFieldObj::getImplementation( xContent
);
391 SvxUnoTextRangeBase
* pTextRange
=
392 ScHeaderFooterTextCursor::getImplementation( xRange
);
394 if ( pHeaderField
&& !pHeaderField
->IsInserted() && pTextRange
)
396 SvxEditSource
* pEditSource
= pTextRange
->GetEditSource();
397 ESelection
aSelection(pTextRange
->GetSelection());
401 // don't replace -> append at end
403 aSelection
.nStartPara
= aSelection
.nEndPara
;
404 aSelection
.nStartPos
= aSelection
.nEndPos
;
407 SvxFieldItem
aItem(pHeaderField
->CreateFieldItem());
409 SvxTextForwarder
* pForwarder
= pEditSource
->GetTextForwarder();
410 pForwarder
->QuickInsertField( aItem
, aSelection
);
411 pEditSource
->UpdateData();
413 // neue Selektion: ein Zeichen
415 aSelection
.nEndPara
= aSelection
.nStartPara
;
416 aSelection
.nEndPos
= aSelection
.nStartPos
+ 1;
418 uno::Reference
<text::XTextRange
> xTextRange
;
419 switch (aTextData
.GetPart())
423 uno::Reference
<text::XTextRange
> xTemp(
424 aTextData
.GetContentObj()->getLeftText(), uno::UNO_QUERY
);
430 uno::Reference
<text::XTextRange
> xTemp(
431 aTextData
.GetContentObj()->getCenterText(), uno::UNO_QUERY
);
437 uno::Reference
<text::XTextRange
> xTemp(
438 aTextData
.GetContentObj()->getRightText(), uno::UNO_QUERY
);
444 pHeaderField
->InitDoc(xTextRange
, new ScHeaderFooterEditSource(aTextData
), aSelection
);
446 // for bAbsorb=FALSE, the new selection must be behind the inserted content
447 // (the xml filter relies on this)
449 aSelection
.nStartPos
= aSelection
.nEndPos
;
451 pTextRange
->SetSelection( aSelection
);
458 CreateUnoText_Impl();
459 mxUnoText
->insertTextContent( xRange
, xContent
, bAbsorb
);
462 void SAL_CALL
ScHeaderFooterTextObj::removeTextContent(
463 const uno::Reference
<text::XTextContent
>& xContent
)
464 throw(container::NoSuchElementException
, uno::RuntimeException
, std::exception
)
466 SolarMutexGuard aGuard
;
469 ScEditFieldObj
* pHeaderField
= ScEditFieldObj::getImplementation(xContent
);
470 if ( pHeaderField
&& pHeaderField
->IsInserted() )
472 //! Testen, ob das Feld in dieser Zelle ist
473 pHeaderField
->DeleteField();
478 CreateUnoText_Impl();
479 mxUnoText
->removeTextContent( xContent
);
482 uno::Reference
<text::XText
> SAL_CALL
ScHeaderFooterTextObj::getText() throw(uno::RuntimeException
, std::exception
)
484 SolarMutexGuard aGuard
;
486 CreateUnoText_Impl();
487 return mxUnoText
->getText();
490 uno::Reference
<text::XTextRange
> SAL_CALL
ScHeaderFooterTextObj::getStart() throw(uno::RuntimeException
, std::exception
)
492 SolarMutexGuard aGuard
;
494 CreateUnoText_Impl();
495 return mxUnoText
->getStart();
498 uno::Reference
<text::XTextRange
> SAL_CALL
ScHeaderFooterTextObj::getEnd() throw(uno::RuntimeException
, std::exception
)
500 SolarMutexGuard aGuard
;
502 CreateUnoText_Impl();
503 return mxUnoText
->getEnd();
506 // XTextFieldsSupplier
508 uno::Reference
<container::XEnumerationAccess
> SAL_CALL
ScHeaderFooterTextObj::getTextFields()
509 throw(uno::RuntimeException
, std::exception
)
511 SolarMutexGuard aGuard
;
513 return new ScHeaderFieldsObj(aTextData
);
516 uno::Reference
<container::XNameAccess
> SAL_CALL
ScHeaderFooterTextObj::getTextFieldMasters()
517 throw(uno::RuntimeException
, std::exception
)
519 // sowas gibts nicht im Calc (?)
525 void SAL_CALL
ScHeaderFooterTextObj::moveTextRange(
526 const uno::Reference
<text::XTextRange
>& xRange
,
527 sal_Int16 nParagraphs
)
528 throw(uno::RuntimeException
, std::exception
)
530 SolarMutexGuard aGuard
;
532 CreateUnoText_Impl();
533 mxUnoText
->moveTextRange( xRange
, nParagraphs
);
536 // XEnumerationAccess
538 uno::Reference
<container::XEnumeration
> SAL_CALL
ScHeaderFooterTextObj::createEnumeration()
539 throw(uno::RuntimeException
, std::exception
)
541 SolarMutexGuard aGuard
;
543 CreateUnoText_Impl();
544 return mxUnoText
->createEnumeration();
549 uno::Type SAL_CALL
ScHeaderFooterTextObj::getElementType() throw(uno::RuntimeException
, std::exception
)
551 SolarMutexGuard aGuard
;
553 CreateUnoText_Impl();
554 return mxUnoText
->getElementType();
557 sal_Bool SAL_CALL
ScHeaderFooterTextObj::hasElements() throw(uno::RuntimeException
, std::exception
)
559 SolarMutexGuard aGuard
;
561 CreateUnoText_Impl();
562 return mxUnoText
->hasElements();
565 ScCellTextCursor::ScCellTextCursor(const ScCellTextCursor
& rOther
) :
566 SvxUnoTextCursor( rOther
),
567 rTextObj( rOther
.rTextObj
)
572 ScCellTextCursor::ScCellTextCursor(ScCellObj
& rText
) :
573 SvxUnoTextCursor( rText
.GetUnoText() ),
579 ScCellTextCursor::~ScCellTextCursor() throw()
584 // SvxUnoTextCursor methods reimplemented here to return the right objects:
586 uno::Reference
<text::XText
> SAL_CALL
ScCellTextCursor::getText() throw(uno::RuntimeException
, std::exception
)
588 SolarMutexGuard aGuard
;
592 uno::Reference
<text::XTextRange
> SAL_CALL
ScCellTextCursor::getStart() throw(uno::RuntimeException
, std::exception
)
594 SolarMutexGuard aGuard
;
596 //! use other object for range than cursor?
598 ScCellTextCursor
* pNew
= new ScCellTextCursor( *this );
599 uno::Reference
<text::XTextRange
> xRange( static_cast<SvxUnoTextRangeBase
*>(pNew
) );
601 ESelection
aNewSel(GetSelection());
602 aNewSel
.nEndPara
= aNewSel
.nStartPara
;
603 aNewSel
.nEndPos
= aNewSel
.nStartPos
;
604 pNew
->SetSelection( aNewSel
);
609 uno::Reference
<text::XTextRange
> SAL_CALL
ScCellTextCursor::getEnd() throw(uno::RuntimeException
, std::exception
)
611 SolarMutexGuard aGuard
;
613 //! use other object for range than cursor?
615 ScCellTextCursor
* pNew
= new ScCellTextCursor( *this );
616 uno::Reference
<text::XTextRange
> xRange( static_cast<SvxUnoTextRangeBase
*>(pNew
) );
618 ESelection
aNewSel(GetSelection());
619 aNewSel
.nStartPara
= aNewSel
.nEndPara
;
620 aNewSel
.nStartPos
= aNewSel
.nEndPos
;
621 pNew
->SetSelection( aNewSel
);
628 sal_Int64 SAL_CALL
ScCellTextCursor::getSomething(
629 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
631 if ( rId
.getLength() == 16 &&
632 0 == memcmp( getUnoTunnelId().getConstArray(),
633 rId
.getConstArray(), 16 ) )
635 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
637 return SvxUnoTextCursor::getSomething( rId
);
642 class theScCellTextCursorUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScCellTextCursorUnoTunnelId
> {};
645 const uno::Sequence
<sal_Int8
>& ScCellTextCursor::getUnoTunnelId()
647 return theScCellTextCursorUnoTunnelId::get().getSeq();
650 ScCellTextCursor
* ScCellTextCursor::getImplementation(const uno::Reference
<uno::XInterface
>& rObj
)
652 ScCellTextCursor
* pRet
= NULL
;
653 uno::Reference
<lang::XUnoTunnel
> xUT(rObj
, uno::UNO_QUERY
);
655 pRet
= reinterpret_cast<ScCellTextCursor
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
659 ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor
& rOther
) :
660 SvxUnoTextCursor( rOther
),
661 rTextObj( rOther
.rTextObj
)
666 ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(ScHeaderFooterTextObj
& rText
) :
667 SvxUnoTextCursor( rText
.GetUnoText() ),
673 ScHeaderFooterTextCursor::~ScHeaderFooterTextCursor() throw()
678 // SvxUnoTextCursor methods reimplemented here to return the right objects:
680 uno::Reference
<text::XText
> SAL_CALL
ScHeaderFooterTextCursor::getText() throw(uno::RuntimeException
, std::exception
)
682 SolarMutexGuard aGuard
;
686 uno::Reference
<text::XTextRange
> SAL_CALL
ScHeaderFooterTextCursor::getStart() throw(uno::RuntimeException
, std::exception
)
688 SolarMutexGuard aGuard
;
690 //! use other object for range than cursor?
692 ScHeaderFooterTextCursor
* pNew
= new ScHeaderFooterTextCursor( *this );
693 uno::Reference
<text::XTextRange
> xRange( static_cast<SvxUnoTextRangeBase
*>(pNew
) );
695 ESelection
aNewSel(GetSelection());
696 aNewSel
.nEndPara
= aNewSel
.nStartPara
;
697 aNewSel
.nEndPos
= aNewSel
.nStartPos
;
698 pNew
->SetSelection( aNewSel
);
703 uno::Reference
<text::XTextRange
> SAL_CALL
ScHeaderFooterTextCursor::getEnd() throw(uno::RuntimeException
, std::exception
)
705 SolarMutexGuard aGuard
;
707 //! use other object for range than cursor?
709 ScHeaderFooterTextCursor
* pNew
= new ScHeaderFooterTextCursor( *this );
710 uno::Reference
<text::XTextRange
> xRange( static_cast<SvxUnoTextRangeBase
*>(pNew
) );
712 ESelection
aNewSel(GetSelection());
713 aNewSel
.nStartPara
= aNewSel
.nEndPara
;
714 aNewSel
.nStartPos
= aNewSel
.nEndPos
;
715 pNew
->SetSelection( aNewSel
);
722 sal_Int64 SAL_CALL
ScHeaderFooterTextCursor::getSomething(
723 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
725 if ( rId
.getLength() == 16 &&
726 0 == memcmp( getUnoTunnelId().getConstArray(),
727 rId
.getConstArray(), 16 ) )
729 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
731 return SvxUnoTextCursor::getSomething( rId
);
736 class theScHeaderFooterTextCursorUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScHeaderFooterTextCursorUnoTunnelId
> {};
739 const uno::Sequence
<sal_Int8
>& ScHeaderFooterTextCursor::getUnoTunnelId()
741 return theScHeaderFooterTextCursorUnoTunnelId::get().getSeq();
744 ScHeaderFooterTextCursor
* ScHeaderFooterTextCursor::getImplementation(
745 const uno::Reference
<uno::XInterface
>& rObj
)
747 ScHeaderFooterTextCursor
* pRet
= NULL
;
748 uno::Reference
<lang::XUnoTunnel
> xUT(rObj
, uno::UNO_QUERY
);
750 pRet
= reinterpret_cast<ScHeaderFooterTextCursor
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
754 ScDrawTextCursor::ScDrawTextCursor(const ScDrawTextCursor
& rOther
) :
755 SvxUnoTextCursor( rOther
),
756 xParentText( rOther
.xParentText
)
760 ScDrawTextCursor::ScDrawTextCursor( const uno::Reference
<text::XText
>& xParent
,
761 const SvxUnoTextBase
& rText
) :
762 SvxUnoTextCursor( rText
),
763 xParentText( xParent
)
768 ScDrawTextCursor::~ScDrawTextCursor() throw()
772 // SvxUnoTextCursor methods reimplemented here to return the right objects:
774 uno::Reference
<text::XText
> SAL_CALL
ScDrawTextCursor::getText() throw(uno::RuntimeException
, std::exception
)
776 SolarMutexGuard aGuard
;
780 uno::Reference
<text::XTextRange
> SAL_CALL
ScDrawTextCursor::getStart() throw(uno::RuntimeException
, std::exception
)
782 SolarMutexGuard aGuard
;
784 //! use other object for range than cursor?
786 ScDrawTextCursor
* pNew
= new ScDrawTextCursor( *this );
787 uno::Reference
<text::XTextRange
> xRange( static_cast<SvxUnoTextRangeBase
*>(pNew
) );
789 ESelection
aNewSel(GetSelection());
790 aNewSel
.nEndPara
= aNewSel
.nStartPara
;
791 aNewSel
.nEndPos
= aNewSel
.nStartPos
;
792 pNew
->SetSelection( aNewSel
);
797 uno::Reference
<text::XTextRange
> SAL_CALL
ScDrawTextCursor::getEnd() throw(uno::RuntimeException
, std::exception
)
799 SolarMutexGuard aGuard
;
801 //! use other object for range than cursor?
803 ScDrawTextCursor
* pNew
= new ScDrawTextCursor( *this );
804 uno::Reference
<text::XTextRange
> xRange( static_cast<SvxUnoTextRangeBase
*>(pNew
) );
806 ESelection
aNewSel(GetSelection());
807 aNewSel
.nStartPara
= aNewSel
.nEndPara
;
808 aNewSel
.nStartPos
= aNewSel
.nEndPos
;
809 pNew
->SetSelection( aNewSel
);
816 sal_Int64 SAL_CALL
ScDrawTextCursor::getSomething(
817 const uno::Sequence
<sal_Int8
>& rId
) throw(uno::RuntimeException
, std::exception
)
819 if ( rId
.getLength() == 16 &&
820 0 == memcmp( getUnoTunnelId().getConstArray(),
821 rId
.getConstArray(), 16 ) )
823 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
825 return SvxUnoTextCursor::getSomething( rId
);
830 class theScDrawTextCursorUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theScDrawTextCursorUnoTunnelId
> {};
833 const uno::Sequence
<sal_Int8
>& ScDrawTextCursor::getUnoTunnelId()
835 return theScDrawTextCursorUnoTunnelId::get().getSeq();
838 ScDrawTextCursor
* ScDrawTextCursor::getImplementation(const uno::Reference
<uno::XInterface
>& rObj
)
840 ScDrawTextCursor
* pRet
= NULL
;
841 uno::Reference
<lang::XUnoTunnel
> xUT(rObj
, uno::UNO_QUERY
);
843 pRet
= reinterpret_cast<ScDrawTextCursor
*>(sal::static_int_cast
<sal_IntPtr
>(xUT
->getSomething(getUnoTunnelId())));
847 ScSimpleEditSourceHelper::ScSimpleEditSourceHelper()
849 SfxItemPool
* pEnginePool
= EditEngine::CreatePool();
850 pEnginePool
->SetDefaultMetric( SFX_MAPUNIT_100TH_MM
);
851 pEnginePool
->FreezeIdRanges();
853 pEditEngine
= new ScFieldEditEngine(NULL
, pEnginePool
, NULL
, true); // TRUE: become owner of pool
854 pForwarder
= new SvxEditEngineForwarder( *pEditEngine
);
855 pOriginalSource
= new ScSimpleEditSource( pForwarder
);
858 ScSimpleEditSourceHelper::~ScSimpleEditSourceHelper()
860 SolarMutexGuard aGuard
; // needed for EditEngine dtor
862 delete pOriginalSource
;
867 ScEditEngineTextObj::ScEditEngineTextObj() :
868 SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference
<text::XText
>() )
872 ScEditEngineTextObj::~ScEditEngineTextObj() throw()
876 void ScEditEngineTextObj::SetText( const EditTextObject
& rTextObject
)
878 GetEditEngine()->SetText( rTextObject
);
881 ::GetSelection( aSel
, GetEditSource()->GetTextForwarder() );
882 SetSelection( aSel
);
885 EditTextObject
* ScEditEngineTextObj::CreateTextObject()
887 return GetEditEngine()->CreateTextObject();
890 ScCellTextData::ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
) :
895 pOriginalSource( NULL
),
902 pDocShell
->GetDocument().AddUnoObject(*this);
905 ScCellTextData::~ScCellTextData()
907 SolarMutexGuard aGuard
; // needed for EditEngine dtor
911 pDocShell
->GetDocument().RemoveUnoObject(*this);
912 pDocShell
->GetDocument().DisposeFieldEditEngine(pEditEngine
);
919 delete pOriginalSource
;
922 ScCellEditSource
* ScCellTextData::GetOriginalSource()
924 if (!pOriginalSource
)
925 pOriginalSource
= new ScCellEditSource(pDocShell
, aCellPos
);
926 return pOriginalSource
;
929 void ScCellTextData::GetCellText(const ScAddress
& rCellPos
, OUString
& rText
)
933 ScDocument
& rDoc
= pDocShell
->GetDocument();
934 rDoc
.GetInputString( rCellPos
.Col(), rCellPos
.Row(), rCellPos
.Tab(), rText
);
938 SvxTextForwarder
* ScCellTextData::GetTextForwarder()
944 ScDocument
& rDoc
= pDocShell
->GetDocument();
945 pEditEngine
= rDoc
.CreateFieldEditEngine();
949 SfxItemPool
* pEnginePool
= EditEngine::CreatePool();
950 pEnginePool
->FreezeIdRanges();
951 pEditEngine
= new ScFieldEditEngine(NULL
, pEnginePool
, NULL
, true);
953 // currently, GetPortions doesn't work if UpdateMode is sal_False,
954 // this will be fixed (in EditEngine) by src600
955 // pEditEngine->SetUpdateMode( sal_False );
956 pEditEngine
->EnableUndo( false );
958 pEditEngine
->SetRefDevice(pDocShell
->GetRefDevice());
960 pEditEngine
->SetRefMapMode( MAP_100TH_MM
);
961 pForwarder
= new SvxEditEngineForwarder(*pEditEngine
);
971 ScDocument
& rDoc
= pDocShell
->GetDocument();
973 SfxItemSet
aDefaults( pEditEngine
->GetEmptyItemSet() );
974 if( const ScPatternAttr
* pPattern
=
975 rDoc
.GetPattern( aCellPos
.Col(), aCellPos
.Row(), aCellPos
.Tab() ) )
977 pPattern
->FillEditItemSet( &aDefaults
);
978 pPattern
->FillEditParaItems( &aDefaults
); // including alignment etc. (for reading)
981 if (rDoc
.GetCellType(aCellPos
) == CELLTYPE_EDIT
)
983 const EditTextObject
* pObj
= rDoc
.GetEditText(aCellPos
);
985 pEditEngine
->SetTextNewDefaults(*pObj
, aDefaults
);
989 GetCellText(aCellPos
, aText
);
990 if (!aText
.isEmpty())
991 pEditEngine
->SetTextNewDefaults(aText
, aDefaults
);
993 pEditEngine
->SetDefaults(aDefaults
);
1001 void ScCellTextData::UpdateData()
1005 OSL_ENSURE(pEditEngine
!= NULL
, "no EditEngine for UpdateData()");
1006 if ( pDocShell
&& pEditEngine
)
1008 // during the own UpdateData call, bDataValid must not be reset,
1009 // or things like attributes after the text would be lost
1010 // (are not stored in the cell)
1011 bInUpdate
= true; // prevents bDataValid from being reset
1012 pDocShell
->GetDocFunc().PutData(aCellPos
, *pEditEngine
, true); // always as text
1022 void ScCellTextData::Notify( SfxBroadcaster
&, const SfxHint
& rHint
)
1024 if ( dynamic_cast<const ScUpdateRefHint
*>(&rHint
) )
1026 // const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint;
1030 else if ( dynamic_cast<const SfxSimpleHint
*>(&rHint
) )
1032 sal_uLong nId
= static_cast<const SfxSimpleHint
&>(rHint
).GetId();
1033 if ( nId
== SFX_HINT_DYING
)
1035 pDocShell
= NULL
; // invalid now
1037 DELETEZ( pForwarder
);
1038 DELETEZ( pEditEngine
); // EditEngine uses document's pool
1040 else if ( nId
== SFX_HINT_DATACHANGED
)
1042 if (!bInUpdate
) // not for own UpdateData calls
1043 bDataValid
= false; // text has to be read from the cell again
1048 ScCellTextObj::ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
) :
1049 ScCellTextData( pDocSh
, rP
),
1050 SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference
<text::XText
>() )
1054 ScCellTextObj::~ScCellTextObj() throw()
1058 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */