diff options
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/editsrc.hxx | 40 | ||||
-rw-r--r-- | sc/inc/textuno.hxx | 39 | ||||
-rw-r--r-- | sc/source/ui/unoobj/editsrc.cxx | 129 | ||||
-rw-r--r-- | sc/source/ui/unoobj/textuno.cxx | 170 |
4 files changed, 249 insertions, 129 deletions
diff --git a/sc/inc/editsrc.hxx b/sc/inc/editsrc.hxx index 60ddc9c6c..662fd88a6 100644 --- a/sc/inc/editsrc.hxx +++ b/sc/inc/editsrc.hxx @@ -2,9 +2,9 @@ * * $RCSfile: editsrc.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: sab $ $Date: 2001-06-13 17:01:24 $ + * last change: $Author: nn $ $Date: 2001-07-31 17:56:45 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -80,6 +80,7 @@ class SvxEditEngineForwarder; class ScDocShell; class ScHeaderFooterContentObj; class ScCellTextData; +class ScHeaderFooterTextData; class ScHeaderFooterChangedHint : public SfxHint @@ -95,29 +96,38 @@ public: }; -class ScHeaderFooterEditSource : public SvxEditSource, public SfxListener +// all ScSharedHeaderFooterEditSource objects for a single text share the same data + +class ScSharedHeaderFooterEditSource : public SvxEditSource { private: - ScHeaderFooterContentObj* pContentObj; - USHORT nPart; - ScEditEngineDefaulter* pEditEngine; - SvxEditEngineForwarder* pForwarder; - BOOL bDataValid; - BOOL bInUpdate; + ScHeaderFooterTextData* pTextData; + +protected: + ScHeaderFooterTextData* GetTextData() const { return pTextData; } // for ScHeaderFooterEditSource public: - ScHeaderFooterEditSource( ScHeaderFooterContentObj* pContent, - USHORT nP ); - virtual ~ScHeaderFooterEditSource(); + ScSharedHeaderFooterEditSource( ScHeaderFooterTextData* pData ); + virtual ~ScSharedHeaderFooterEditSource(); - //! GetEditEngine nur als Uebergang, bis die Feld-Funktionen am Forwarder sind !!! - ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; } + // GetEditEngine is needed because the forwarder doesn't have field functions + ScEditEngineDefaulter* GetEditEngine(); virtual SvxEditSource* Clone() const ; virtual SvxTextForwarder* GetTextForwarder(); virtual void UpdateData(); +}; - virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); +// ScHeaderFooterEditSource with local copy of ScHeaderFooterTextData is used by field objects + +class ScHeaderFooterEditSource : public ScSharedHeaderFooterEditSource +{ +public: + ScHeaderFooterEditSource( ScHeaderFooterContentObj* pContent, USHORT nP ); + ScHeaderFooterEditSource( ScHeaderFooterContentObj& rContent, USHORT nP ); + virtual ~ScHeaderFooterEditSource(); + + virtual SvxEditSource* Clone() const; }; diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx index 2685e7828..933c5ad11 100644 --- a/sc/inc/textuno.hxx +++ b/sc/inc/textuno.hxx @@ -2,9 +2,9 @@ * * $RCSfile: textuno.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: sab $ $Date: 2001-06-13 17:01:24 $ + * last change: $Author: nn $ $Date: 2001-07-31 17:56:45 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -174,6 +174,34 @@ public: }; +// ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj + +class ScHeaderFooterTextData : public SfxListener +{ +private: + ScHeaderFooterContentObj& rContentObj; + USHORT nPart; + ScEditEngineDefaulter* pEditEngine; + SvxEditEngineForwarder* pForwarder; + BOOL bDataValid; + BOOL bInUpdate; + +public: + ScHeaderFooterTextData( ScHeaderFooterContentObj& rContent, + USHORT nP ); + ~ScHeaderFooterTextData(); + + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + + // helper functions + SvxTextForwarder* GetTextForwarder(); + void UpdateData(); + ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; } + + USHORT GetPart() const { return nPart; } + ScHeaderFooterContentObj& GetContentObj() const { return rContentObj; } +}; + // ScHeaderFooterTextObj veraendert den Text in einem ScHeaderFooterContentObj class ScHeaderFooterTextObj : public cppu::WeakImplHelper5< @@ -184,16 +212,17 @@ class ScHeaderFooterTextObj : public cppu::WeakImplHelper5< com::sun::star::lang::XServiceInfo > { private: - ScHeaderFooterContentObj& rContentObj; - USHORT nPart; + ScHeaderFooterTextData aTextData; SvxUnoText* pUnoText; + void CreateUnoText_Impl(); + public: ScHeaderFooterTextObj( ScHeaderFooterContentObj& rContent, USHORT nP ); virtual ~ScHeaderFooterTextObj(); - const SvxUnoText& GetUnoText() const; + const SvxUnoText& GetUnoText(); static void FillDummyFieldData( ScHeaderFieldData& rData ); diff --git a/sc/source/ui/unoobj/editsrc.cxx b/sc/source/ui/unoobj/editsrc.cxx index b8b2810dd..1b8eab1dd 100644 --- a/sc/source/ui/unoobj/editsrc.cxx +++ b/sc/source/ui/unoobj/editsrc.cxx @@ -2,9 +2,9 @@ * * $RCSfile: editsrc.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: sab $ $Date: 2001-06-13 17:02:55 $ + * last change: $Author: nn $ $Date: 2001-07-31 17:57:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,7 +75,6 @@ #include "docfunc.hxx" #include "hints.hxx" #include "patattr.hxx" -#include "scmod.hxx" #include "unoguard.hxx" //------------------------------------------------------------------------ @@ -93,117 +92,63 @@ ScHeaderFooterChangedHint::~ScHeaderFooterChangedHint() //------------------------------------------------------------------------ -ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj* pContent, - USHORT nP ) : - pContentObj( pContent ), - nPart( nP ), - pEditEngine( NULL ), - pForwarder( NULL ), - bDataValid( FALSE ), - bInUpdate( FALSE ) +ScSharedHeaderFooterEditSource::ScSharedHeaderFooterEditSource( ScHeaderFooterTextData* pData ) : + pTextData( pData ) { - if (pContentObj) // pContentObj can be 0 if constructed via getReflection - { - pContentObj->acquire(); // must not go away - - pContentObj->AddListener( *this ); - } + // pTextData is held by the ScHeaderFooterTextObj. + // Text range and cursor keep a reference to their parent text, so the text object is + // always alive and the TextData is valid as long as there are children. } -ScHeaderFooterEditSource::~ScHeaderFooterEditSource() +ScSharedHeaderFooterEditSource::~ScSharedHeaderFooterEditSource() { - ScUnoGuard aGuard; // needed for EditEngine dtor - - if (pContentObj) - pContentObj->RemoveListener( *this ); - - delete pForwarder; - delete pEditEngine; +} - if (pContentObj) - pContentObj->release(); +SvxEditSource* ScSharedHeaderFooterEditSource::Clone() const +{ + return new ScSharedHeaderFooterEditSource( pTextData ); } -SvxEditSource* ScHeaderFooterEditSource::Clone() const +SvxTextForwarder* ScSharedHeaderFooterEditSource::GetTextForwarder() { - return new ScHeaderFooterEditSource( pContentObj, nPart ); + return pTextData->GetTextForwarder(); } -SvxTextForwarder* ScHeaderFooterEditSource::GetTextForwarder() +void ScSharedHeaderFooterEditSource::UpdateData() { - if (!pEditEngine) - { - SfxItemPool* pEnginePool = EditEngine::CreatePool(); - pEnginePool->FreezeIdRanges(); - ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, TRUE ); - - pHdrEngine->EnableUndo( FALSE ); - pHdrEngine->SetRefMapMode( MAP_TWIP ); - - // default font must be set, independently of document - // -> use global pool from module - - SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() ); - const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN); - rPattern.FillEditItemSet( &aDefaults ); - // FillEditItemSet adjusts font height to 1/100th mm, - // but for header/footer twips is needed, as in the PatternAttr: - aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT ); - aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK ); - aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL ); - pHdrEngine->SetDefaults( aDefaults ); - - ScHeaderFieldData aData; - ScHeaderFooterTextObj::FillDummyFieldData( aData ); - pHdrEngine->SetData( aData ); - - pEditEngine = pHdrEngine; - pForwarder = new SvxEditEngineForwarder(*pEditEngine); - } + pTextData->UpdateData(); +} - if (bDataValid) - return pForwarder; +ScEditEngineDefaulter* ScSharedHeaderFooterEditSource::GetEditEngine() +{ + return pTextData->GetEditEngine(); +} - if (pContentObj) - { - const EditTextObject* pData; - if (nPart == SC_HDFT_LEFT) - pData = pContentObj->GetLeftEditObject(); - else if (nPart == SC_HDFT_CENTER) - pData = pContentObj->GetCenterEditObject(); - else - pData = pContentObj->GetRightEditObject(); +//------------------------------------------------------------------------ - if (pData) - pEditEngine->SetText(*pData); - } +// each ScHeaderFooterEditSource object has its own ScHeaderFooterTextData - bDataValid = TRUE; - return pForwarder; +ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj* pContent, + USHORT nP ) : + ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( *pContent, nP ) ) +{ } -void ScHeaderFooterEditSource::UpdateData() +ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj& rContent, + USHORT nP ) : + ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( rContent, nP ) ) { - if ( pContentObj && pEditEngine ) - { - bInUpdate = TRUE; // don't reset bDataValid during UpdateText - - pContentObj->UpdateText( nPart, *pEditEngine ); +} - bInUpdate = FALSE; - } +ScHeaderFooterEditSource::~ScHeaderFooterEditSource() +{ + delete GetTextData(); // not accessed in ScSharedHeaderFooterEditSource dtor } -void ScHeaderFooterEditSource::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +SvxEditSource* ScHeaderFooterEditSource::Clone() const { - if ( rHint.ISA( ScHeaderFooterChangedHint ) ) - { - if ( ((const ScHeaderFooterChangedHint&)rHint).GetPart() == nPart ) - { - if (!bInUpdate) // not for own updates - bDataValid = FALSE; // text has to be fetched again - } - } + const ScHeaderFooterTextData* pData = GetTextData(); + return new ScHeaderFooterEditSource( pData->GetContentObj(), pData->GetPart() ); } //------------------------------------------------------------------------ diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx index 881221b34..8ef269408 100644 --- a/sc/source/ui/unoobj/textuno.cxx +++ b/sc/source/ui/unoobj/textuno.cxx @@ -2,9 +2,9 @@ * * $RCSfile: textuno.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.10 $ * - * last change: $Author: sab $ $Date: 2001-06-13 17:02:55 $ + * last change: $Author: nn $ $Date: 2001-07-31 17:57:55 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -96,6 +96,7 @@ #include "patattr.hxx" #include "cell.hxx" #include "docfunc.hxx" +#include "scmod.hxx" using namespace com::sun::star; @@ -274,31 +275,137 @@ ScHeaderFooterContentObj* ScHeaderFooterContentObj::getImplementation( //------------------------------------------------------------------------ +ScHeaderFooterTextData::ScHeaderFooterTextData( ScHeaderFooterContentObj& rContent, + USHORT nP ) : + rContentObj( rContent ), + nPart( nP ), + pEditEngine( NULL ), + pForwarder( NULL ), + bDataValid( FALSE ), + bInUpdate( FALSE ) +{ + rContentObj.acquire(); // must not go away + rContentObj.AddListener( *this ); +} + +ScHeaderFooterTextData::~ScHeaderFooterTextData() +{ + ScUnoGuard aGuard; // needed for EditEngine dtor + + rContentObj.RemoveListener( *this ); + + delete pForwarder; + delete pEditEngine; + + rContentObj.release(); +} + +void ScHeaderFooterTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScHeaderFooterChangedHint ) ) + { + if ( ((const ScHeaderFooterChangedHint&)rHint).GetPart() == nPart ) + { + if (!bInUpdate) // not for own updates + bDataValid = FALSE; // text has to be fetched again + } + } +} + +SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder() +{ + if (!pEditEngine) + { + SfxItemPool* pEnginePool = EditEngine::CreatePool(); + pEnginePool->FreezeIdRanges(); + ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, TRUE ); + + pHdrEngine->EnableUndo( FALSE ); + pHdrEngine->SetRefMapMode( MAP_TWIP ); + + // default font must be set, independently of document + // -> use global pool from module + + SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() ); + const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN); + rPattern.FillEditItemSet( &aDefaults ); + // FillEditItemSet adjusts font height to 1/100th mm, + // but for header/footer twips is needed, as in the PatternAttr: + aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT ); + aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK ); + aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL ); + pHdrEngine->SetDefaults( aDefaults ); + + ScHeaderFieldData aData; + ScHeaderFooterTextObj::FillDummyFieldData( aData ); + pHdrEngine->SetData( aData ); + + pEditEngine = pHdrEngine; + pForwarder = new SvxEditEngineForwarder(*pEditEngine); + } + + if (bDataValid) + return pForwarder; + + const EditTextObject* pData; + if (nPart == SC_HDFT_LEFT) + pData = rContentObj.GetLeftEditObject(); + else if (nPart == SC_HDFT_CENTER) + pData = rContentObj.GetCenterEditObject(); + else + pData = rContentObj.GetRightEditObject(); + + if (pData) + pEditEngine->SetText(*pData); + + bDataValid = TRUE; + return pForwarder; +} + +void ScHeaderFooterTextData::UpdateData() +{ + if ( pEditEngine ) + { + bInUpdate = TRUE; // don't reset bDataValid during UpdateText + + rContentObj.UpdateText( nPart, *pEditEngine ); + + bInUpdate = FALSE; + } +} + +//------------------------------------------------------------------------ + ScHeaderFooterTextObj::ScHeaderFooterTextObj( ScHeaderFooterContentObj& rContent, USHORT nP ) : - rContentObj( rContent ), - nPart( nP ) + aTextData( rContent, nP ), + pUnoText( NULL ) { - rContentObj.acquire(); // darf nicht wegkommen + // ScHeaderFooterTextData acquires rContent + // pUnoText is created on demand (getString/setString work without it) +} - //! pUnoText erst bei Bedarf anlegen? - // nicht einfach aggregieren, weil getString/setString selber gemacht wird - ScHeaderFooterEditSource aEditSource( &rContent, nP ); - pUnoText = new SvxUnoText( &aEditSource, lcl_GetHdFtPropertyMap(), uno::Reference<text::XText>() ); - pUnoText->acquire(); +void ScHeaderFooterTextObj::CreateUnoText_Impl() +{ + if ( !pUnoText ) + { + // can't be aggregated because getString/setString is handled here + ScSharedHeaderFooterEditSource aEditSource( &aTextData ); + pUnoText = new SvxUnoText( &aEditSource, lcl_GetHdFtPropertyMap(), uno::Reference<text::XText>() ); + pUnoText->acquire(); + } } ScHeaderFooterTextObj::~ScHeaderFooterTextObj() { - rContentObj.release(); - if (pUnoText) pUnoText->release(); } -const SvxUnoText& ScHeaderFooterTextObj::GetUnoText() const +const SvxUnoText& ScHeaderFooterTextObj::GetUnoText() { - DBG_ASSERT(pUnoText, "GetUnoText: NULL"); + if (!pUnoText) + CreateUnoText_Impl(); return *pUnoText; } @@ -316,6 +423,8 @@ uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCurs throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->createTextCursorByRange(aTextPosition); //! wie ScCellObj::createTextCursorByRange, wenn SvxUnoTextRange_getReflection verfuegbar } @@ -336,6 +445,10 @@ rtl::OUString SAL_CALL ScHeaderFooterTextObj::getString() throw(uno::RuntimeExce ScUnoGuard aGuard; rtl::OUString aRet; const EditTextObject* pData; + + USHORT nPart = aTextData.GetPart(); + ScHeaderFooterContentObj& rContentObj = aTextData.GetContentObj(); + if (nPart == SC_HDFT_LEFT) pData = rContentObj.GetLeftEditObject(); else if (nPart == SC_HDFT_CENTER) @@ -366,7 +479,7 @@ void SAL_CALL ScHeaderFooterTextObj::setString( const rtl::OUString& aText ) thr ScHeaderEditEngine aEditEngine( EditEngine::CreatePool(), TRUE ); aEditEngine.SetText( aString ); - rContentObj.UpdateText( nPart, aEditEngine ); + aTextData.GetContentObj().UpdateText( aTextData.GetPart(), aEditEngine ); } void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XTextRange>& xRange, @@ -374,6 +487,8 @@ void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XT throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); pUnoText->insertString( xRange, aString, bAbsorb ); } @@ -383,6 +498,8 @@ void SAL_CALL ScHeaderFooterTextObj::insertControlCharacter( throw(lang::IllegalArgumentException, uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); pUnoText->insertControlCharacter( xRange, nControlCharacter, bAbsorb ); } @@ -430,7 +547,7 @@ void SAL_CALL ScHeaderFooterTextObj::insertTextContent( aSelection.Adjust(); aSelection.nEndPara = aSelection.nStartPara; aSelection.nEndPos = aSelection.nStartPos + 1; - pHeaderField->InitDoc( &rContentObj, nPart, aSelection ); + pHeaderField->InitDoc( &aTextData.GetContentObj(), aTextData.GetPart(), aSelection ); pTextRange->SetSelection( aSelection ); @@ -438,6 +555,8 @@ void SAL_CALL ScHeaderFooterTextObj::insertTextContent( } } + if (!pUnoText) + CreateUnoText_Impl(); pUnoText->insertTextContent( xRange, xContent, bAbsorb ); } @@ -456,24 +575,32 @@ void SAL_CALL ScHeaderFooterTextObj::removeTextContent( return; } } + if (!pUnoText) + CreateUnoText_Impl(); pUnoText->removeTextContent( xContent ); } uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextObj::getText() throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->getText(); } uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getStart() throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->getStart(); } uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getEnd() throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->getEnd(); } @@ -483,7 +610,8 @@ uno::Reference<container::XEnumerationAccess> SAL_CALL ScHeaderFooterTextObj::ge throw(uno::RuntimeException) { ScUnoGuard aGuard; - return new ScHeaderFieldsObj( &rContentObj, nPart, SC_SERVICE_INVALID ); // alle Felder + // all fields + return new ScHeaderFieldsObj( &aTextData.GetContentObj(), aTextData.GetPart(), SC_SERVICE_INVALID ); } uno::Reference<container::XNameAccess> SAL_CALL ScHeaderFooterTextObj::getTextFieldMasters() @@ -501,6 +629,8 @@ void SAL_CALL ScHeaderFooterTextObj::moveTextRange( throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); pUnoText->moveTextRange( xRange, nParagraphs ); } @@ -510,6 +640,8 @@ uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEn throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->createEnumeration(); } @@ -518,12 +650,16 @@ uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEn uno::Type SAL_CALL ScHeaderFooterTextObj::getElementType() throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->getElementType(); } sal_Bool SAL_CALL ScHeaderFooterTextObj::hasElements() throw(uno::RuntimeException) { ScUnoGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); return pUnoText->hasElements(); } |