diff options
-rw-r--r-- | sc/inc/editsrc.hxx | 42 | ||||
-rw-r--r-- | sc/inc/textuno.hxx | 50 | ||||
-rw-r--r-- | sc/source/ui/unoobj/cellsuno.cxx | 8 | ||||
-rw-r--r-- | sc/source/ui/unoobj/editsrc.cxx | 151 | ||||
-rw-r--r-- | sc/source/ui/unoobj/textuno.cxx | 154 |
5 files changed, 260 insertions, 145 deletions
diff --git a/sc/inc/editsrc.hxx b/sc/inc/editsrc.hxx index d11125861371..c558b6df1852 100644 --- a/sc/inc/editsrc.hxx +++ b/sc/inc/editsrc.hxx @@ -2,9 +2,9 @@ * * $RCSfile: editsrc.hxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: nn $ $Date: 2001-02-15 18:05:39 $ + * last change: $Author: nn $ $Date: 2001-06-07 19:05:35 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -75,12 +75,11 @@ #endif class ScEditEngineDefaulter; -class SfxBroadcaster; -class SfxHint; class SvxEditEngineForwarder; class ScDocShell; class ScHeaderFooterContentObj; +class ScCellTextData; class ScHeaderFooterChangedHint : public SfxHint @@ -122,28 +121,37 @@ public: }; -class ScCellEditSource : public SvxEditSource, public SfxListener +// Data (incl. EditEngine) for cell EditSource is now shared in ScCellTextData + +class ScSharedCellEditSource : public SvxEditSource { private: - ScDocShell* pDocShell; - ScAddress aCellPos; - ScEditEngineDefaulter* pEditEngine; - SvxEditEngineForwarder* pForwarder; - BOOL bDataValid; - BOOL bInUpdate; + ScCellTextData* pCellTextData; + +protected: + ScCellTextData* GetCellTextData() const { return pCellTextData; } // for ScCellEditSource public: - ScCellEditSource(ScDocShell* pDocSh, const ScAddress& rP); - virtual ~ScCellEditSource(); + ScSharedCellEditSource( ScCellTextData* pData ); + virtual ~ScSharedCellEditSource(); - //! 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 SvxEditSource* Clone() const; virtual SvxTextForwarder* GetTextForwarder(); virtual void UpdateData(); +}; - virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); +// ScCellEditSource with local copy of ScCellTextData is used by ScCellFieldsObj, ScCellFieldObj + +class ScCellEditSource : public ScSharedCellEditSource +{ +public: + ScCellEditSource( ScDocShell* pDocSh, const ScAddress& rP ); + virtual ~ScCellEditSource(); + + virtual SvxEditSource* Clone() const; }; diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx index 74596e01a605..0b3a502c9ee6 100644 --- a/sc/inc/textuno.hxx +++ b/sc/inc/textuno.hxx @@ -2,9 +2,9 @@ * * $RCSfile: textuno.hxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: nn $ $Date: 2001-02-15 18:05:39 $ + * last change: $Author: nn $ $Date: 2001-06-07 19:05:34 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -62,6 +62,10 @@ #ifndef SC_TEXTSUNO_HXX #define SC_TEXTSUNO_HXX +#ifndef SC_SCGLOB_HXX +#include "global.hxx" // ScRange, ScAddress +#endif + #ifndef _SVX_UNOTEXT_HXX #include <svx/unotext.hxx> #endif @@ -69,6 +73,9 @@ #ifndef _SFXBRDCST_HXX #include <svtools/brdcst.hxx> #endif +#ifndef _SFXLSTNER_HXX +#include <svtools/lstner.hxx> +#endif #ifndef _COM_SUN_STAR_TEXT_XTEXTFIELDSSUPPLIER_HPP_ #include <com/sun/star/text/XTextFieldsSupplier.hpp> @@ -98,6 +105,7 @@ class ScDocShell; class ScAddress; class ScCellObj; class ScSimpleEditSource; +class ScSharedCellEditSource; class ScEditEngineDefaulter; struct ScHeaderFieldData; @@ -352,5 +360,43 @@ public: }; +// ScCellTextData: shared data between sub objects of a cell text object + +class ScCellTextData : public SfxListener +{ + ScDocShell* pDocShell; + ScAddress aCellPos; + ScEditEngineDefaulter* pEditEngine; + SvxEditEngineForwarder* pForwarder; + BOOL bDataValid; + BOOL bInUpdate; + ScSharedCellEditSource* pOriginalSource; + +public: + ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP); + virtual ~ScCellTextData(); + + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + + // helper functions for ScSharedCellEditSource: + SvxTextForwarder* GetTextForwarder(); + void UpdateData(); + ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; } + + ScSharedCellEditSource* GetOriginalSource(); // used as argument for SvxUnoText ctor + + // used for ScCellEditSource: + ScDocShell* GetDocShell() const { return pDocShell; } + const ScAddress& GetCellPos() const { return aCellPos; } +}; + +class ScCellTextObj : public ScCellTextData, public SvxUnoText +{ +public: + ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP); + virtual ~ScCellTextObj(); +}; + + #endif diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx index 941a67ded046..3f90c29f08de 100644 --- a/sc/source/ui/unoobj/cellsuno.cxx +++ b/sc/source/ui/unoobj/cellsuno.cxx @@ -2,9 +2,9 @@ * * $RCSfile: cellsuno.cxx,v $ * - * $Revision: 1.43 $ + * $Revision: 1.44 $ * - * last change: $Author: sab $ $Date: 2001-06-07 09:40:46 $ + * last change: $Author: nn $ $Date: 2001-06-07 19:06:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -5248,9 +5248,7 @@ SvxUnoText& ScCellObj::GetUnoText() { if (!pUnoText) { - ScCellEditSource aEditSource( GetDocShell(), aCellPos ); - pUnoText = new SvxUnoText( &aEditSource, lcl_GetEditPropertyMap(), - uno::Reference<text::XText>() ); + pUnoText = new ScCellTextObj( GetDocShell(), aCellPos ); pUnoText->acquire(); } return *pUnoText; diff --git a/sc/source/ui/unoobj/editsrc.cxx b/sc/source/ui/unoobj/editsrc.cxx index 589ea60c81b7..50edb66552f8 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.6 $ + * $Revision: 1.7 $ * - * last change: $Author: nn $ $Date: 2001-06-01 19:12:54 $ + * last change: $Author: nn $ $Date: 2001-06-07 19:06:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,22 +65,14 @@ #pragma hdrstop -#ifndef _SFXSMPLHINT_HXX //autogen -#include <svtools/smplhint.hxx> -#endif - #include "scitems.hxx" -#include <tools/debug.hxx> -#include <svx/editeng.hxx> #include <svx/unofored.hxx> -#include <svx/editobj.hxx> -#include "textuno.hxx" #include "editsrc.hxx" +#include "textuno.hxx" #include "editutil.hxx" #include "docsh.hxx" #include "docfunc.hxx" -#include "cell.hxx" #include "hints.hxx" #include "patattr.hxx" #include "scmod.hxx" @@ -216,135 +208,56 @@ void ScHeaderFooterEditSource::Notify( SfxBroadcaster& rBC, const SfxHint& rHint //------------------------------------------------------------------------ -ScCellEditSource::ScCellEditSource(ScDocShell* pDocSh, const ScAddress& rP) : - pDocShell( pDocSh ), - aCellPos( rP ), - pEditEngine( NULL ), - pForwarder( NULL ), - bDataValid( FALSE ), - bInUpdate( FALSE ) +ScSharedCellEditSource::ScSharedCellEditSource( ScCellTextData* pData ) : + pCellTextData( pData ) { - if (pDocShell) - pDocShell->GetDocument()->AddUnoObject(*this); + // pCellTextData is part of the ScCellTextObj. + // Text range and cursor keep a reference to their parent text, so the text object is + // always alive and the CellTextData is valid as long as there are children. } -ScCellEditSource::~ScCellEditSource() +ScSharedCellEditSource::~ScSharedCellEditSource() { - ScUnoGuard aGuard; // needed for EditEngine dtor - - if (pDocShell) - pDocShell->GetDocument()->RemoveUnoObject(*this); - - delete pForwarder; - delete pEditEngine; } -SvxEditSource* ScCellEditSource::Clone() const +SvxEditSource* ScSharedCellEditSource::Clone() const { - return new ScCellEditSource( pDocShell, aCellPos ); + return new ScSharedCellEditSource( pCellTextData ); } -SvxTextForwarder* ScCellEditSource::GetTextForwarder() +SvxTextForwarder* ScSharedCellEditSource::GetTextForwarder() { - if (!pEditEngine) - { - if ( pDocShell ) - { - const ScDocument* pDoc = pDocShell->GetDocument(); - pEditEngine = new ScFieldEditEngine( pDoc->GetEnginePool(), - pDoc->GetEditPool(), FALSE ); - } - else - { - SfxItemPool* pEnginePool = EditEngine::CreatePool(); - pEnginePool->FreezeIdRanges(); - pEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE ); - } -#if SUPD > 600 - // currently, GetPortions doesn't work if UpdateMode is FALSE, - // this will be fixed (in EditEngine) by src600 -// pEditEngine->SetUpdateMode( FALSE ); -#endif - pEditEngine->EnableUndo( FALSE ); - pEditEngine->SetRefMapMode( MAP_100TH_MM ); - pForwarder = new SvxEditEngineForwarder(*pEditEngine); - } - - if (bDataValid) - return pForwarder; - - BOOL bEditCell = FALSE; - String aText; - - if (pDocShell) - { - ScDocument* pDoc = pDocShell->GetDocument(); - - const ScBaseCell* pCell = pDoc->GetCell( aCellPos ); - if ( pCell && pCell->GetCellType() == CELLTYPE_EDIT ) - { - pEditEngine->SetText( *((const ScEditCell*)pCell)->GetData() ); - bEditCell = TRUE; - } - else - pDoc->GetInputString( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aText ); - - SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() ); - const ScPatternAttr* pPattern = - pDoc->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ); - pPattern->FillEditItemSet( &aDefaults ); - pPattern->FillEditParaItems( &aDefaults ); // auch Ausrichtung etc. auslesbar - pEditEngine->SetDefaults( aDefaults ); - } - - if (!bEditCell) - pEditEngine->SetText( aText ); + return pCellTextData->GetTextForwarder(); +} - bDataValid = TRUE; - return pForwarder; +void ScSharedCellEditSource::UpdateData() +{ + pCellTextData->UpdateData(); } -void ScCellEditSource::UpdateData() +ScEditEngineDefaulter* ScSharedCellEditSource::GetEditEngine() { - if ( pDocShell && pEditEngine ) - { - // beim eigenen Update darf bDataValid nicht zurueckgesetzt werden, - // damit z.B. Attribute hinter dem Text nicht verloren gehen - // (werden in die Zelle nicht uebernommen) + return pCellTextData->GetEditEngine(); +} - bInUpdate = TRUE; // damit wird bDataValid nicht zurueckgesetzt +//------------------------------------------------------------------------ - ScDocFunc aFunc(*pDocShell); - aFunc.PutData( aCellPos, *pEditEngine, FALSE, TRUE ); // immer Text +// each ScCellEditSource object has its own ScCellTextData - bInUpdate = FALSE; - } +ScCellEditSource::ScCellEditSource( ScDocShell* pDocSh, const ScAddress& rP ) : + ScSharedCellEditSource( new ScCellTextData( pDocSh, rP ) ) +{ } -void ScCellEditSource::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +ScCellEditSource::~ScCellEditSource() { - if ( rHint.ISA( ScUpdateRefHint ) ) - { - const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; - - //! Ref-Update - } - else if ( rHint.ISA( SfxSimpleHint ) ) - { - ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); - if ( nId == SFX_HINT_DYING ) - { - pDocShell = NULL; // ungueltig geworden + delete GetCellTextData(); // not accessed in ScSharedCellEditSource dtor +} - DELETEZ( pForwarder ); - DELETEZ( pEditEngine ); // EditEngine uses document's pool - } - else if ( nId == SFX_HINT_DATACHANGED ) - { - if (!bInUpdate) // eigene Updates zaehlen nicht - bDataValid = FALSE; // Text muss neu geholt werden - } - } +SvxEditSource* ScCellEditSource::Clone() const +{ + const ScCellTextData* pData = GetCellTextData(); + return new ScCellEditSource( pData->GetDocShell(), pData->GetCellPos() ); } //------------------------------------------------------------------------ diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx index 8142971c686e..b94ba58f6348 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.7 $ + * $Revision: 1.8 $ * - * last change: $Author: nn $ $Date: 2001-06-01 18:56:45 $ + * last change: $Author: nn $ $Date: 2001-06-07 19:06:48 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -92,6 +92,10 @@ #include "unoguard.hxx" #include "miscuno.hxx" #include "cellsuno.hxx" +#include "hints.hxx" +#include "patattr.hxx" +#include "cell.hxx" +#include "docfunc.hxx" using namespace com::sun::star; @@ -788,3 +792,149 @@ EditTextObject* ScEditEngineTextObj::CreateTextObject() //------------------------------------------------------------------------ +ScCellTextData::ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP) : + pDocShell( pDocSh ), + aCellPos( rP ), + pEditEngine( NULL ), + pForwarder( NULL ), + bDataValid( FALSE ), + bInUpdate( FALSE ), + pOriginalSource( NULL ) +{ + if (pDocShell) + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScCellTextData::~ScCellTextData() +{ + ScUnoGuard aGuard; // needed for EditEngine dtor + + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + delete pForwarder; + delete pEditEngine; + + delete pOriginalSource; +} + +ScSharedCellEditSource* ScCellTextData::GetOriginalSource() +{ + if (!pOriginalSource) + pOriginalSource = new ScSharedCellEditSource( this ); + return pOriginalSource; +} + +SvxTextForwarder* ScCellTextData::GetTextForwarder() +{ + if (!pEditEngine) + { + if ( pDocShell ) + { + const ScDocument* pDoc = pDocShell->GetDocument(); + pEditEngine = new ScFieldEditEngine( pDoc->GetEnginePool(), + pDoc->GetEditPool(), FALSE ); + } + else + { + SfxItemPool* pEnginePool = EditEngine::CreatePool(); + pEnginePool->FreezeIdRanges(); + pEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE ); + } +#if SUPD > 600 + // currently, GetPortions doesn't work if UpdateMode is FALSE, + // this will be fixed (in EditEngine) by src600 +// pEditEngine->SetUpdateMode( FALSE ); +#endif + pEditEngine->EnableUndo( FALSE ); + pEditEngine->SetRefMapMode( MAP_100TH_MM ); + pForwarder = new SvxEditEngineForwarder(*pEditEngine); + } + + if (bDataValid) + return pForwarder; + + BOOL bEditCell = FALSE; + String aText; + + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + const ScBaseCell* pCell = pDoc->GetCell( aCellPos ); + if ( pCell && pCell->GetCellType() == CELLTYPE_EDIT ) + { + pEditEngine->SetText( *((const ScEditCell*)pCell)->GetData() ); + bEditCell = TRUE; + } + else + pDoc->GetInputString( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aText ); + + SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() ); + const ScPatternAttr* pPattern = + pDoc->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ); + pPattern->FillEditItemSet( &aDefaults ); + pPattern->FillEditParaItems( &aDefaults ); // including alignment etc. (for reading) + pEditEngine->SetDefaults( aDefaults ); + } + + if (!bEditCell) + pEditEngine->SetText( aText ); + + bDataValid = TRUE; + return pForwarder; +} + +void ScCellTextData::UpdateData() +{ + if ( pDocShell && pEditEngine ) + { + // during the own UpdateData call, bDataValid must not be reset, + // or things like attributes after the text would be lost + // (are not stored in the cell) + + bInUpdate = TRUE; // prevents bDataValid from being reset + + ScDocFunc aFunc(*pDocShell); + aFunc.PutData( aCellPos, *pEditEngine, FALSE, TRUE ); // always as text + + bInUpdate = FALSE; + } +} + +void ScCellTextData::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; + + //! Ref-Update + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + pDocShell = NULL; // invalid now + + DELETEZ( pForwarder ); + DELETEZ( pEditEngine ); // EditEngine uses document's pool + } + else if ( nId == SFX_HINT_DATACHANGED ) + { + if (!bInUpdate) // not for own UpdateData calls + bDataValid = FALSE; // text has to be read from the cell again + } + } +} + +ScCellTextObj::ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP) : + ScCellTextData( pDocSh, rP ), + SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertyMap(), uno::Reference<text::XText>() ) +{ +} + +ScCellTextObj::~ScCellTextObj() +{ +} + |