diff options
author | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-04-25 15:08:36 -0400 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@gmail.com> | 2012-04-26 09:58:04 -0400 |
commit | f0561d3f3d28506a1351cebdd1bbe8d80b67892f (patch) | |
tree | b73b0433e04c11b3d8820dcb37c5b38860b29e2e | |
parent | 98831752bab7827f1d4d6d121daa1d0a0de805ee (diff) |
Define interfance to get edit engine instance without ugly casting.
-rw-r--r-- | sc/inc/editsrc.hxx | 20 | ||||
-rw-r--r-- | sc/inc/fielduno.hxx | 18 | ||||
-rw-r--r-- | sc/source/ui/unoobj/fielduno.cxx | 66 |
3 files changed, 56 insertions, 48 deletions
diff --git a/sc/inc/editsrc.hxx b/sc/inc/editsrc.hxx index 64c5871b32fb..d3258434244f 100644 --- a/sc/inc/editsrc.hxx +++ b/sc/inc/editsrc.hxx @@ -44,11 +44,19 @@ class ScHeaderFooterTextData; class ScAccessibleTextData; class SdrObject; +class ScEditSource : public SvxEditSource +{ +public: + virtual ScEditEngineDefaulter* GetEditEngine() = 0; +}; + /** - * ScHeaderFooterEditSource with local copy of ScHeaderFooterTextData is - * used by field objects. + * ScHeaderFooterTextObj keeps the authoritative copy of + * ScHeaderFooterTextData that this class holds reference to. It's a + * reference instead of a copy to avoid broadcasting changes to the + * authoritative copy. */ -class ScHeaderFooterEditSource : public SvxEditSource +class ScHeaderFooterEditSource : public ScEditSource { private: ScHeaderFooterTextData& mrTextData; @@ -58,7 +66,7 @@ public: virtual ~ScHeaderFooterEditSource(); // GetEditEngine is needed because the forwarder doesn't have field functions - ScEditEngineDefaulter* GetEditEngine(); + virtual ScEditEngineDefaulter* GetEditEngine(); virtual SvxEditSource* Clone() const; virtual SvxTextForwarder* GetTextForwarder(); @@ -72,7 +80,7 @@ public: * ScCellEditSource with local copy of ScCellTextData is used by * ScCellFieldsObj, ScCellFieldObj. */ -class ScCellEditSource : public SvxEditSource +class ScCellEditSource : public ScEditSource { private: ScCellTextData* pCellTextData; @@ -82,7 +90,7 @@ public: virtual ~ScCellEditSource(); // GetEditEngine is needed because the forwarder doesn't have field functions - ScEditEngineDefaulter* GetEditEngine(); + virtual ScEditEngineDefaulter* GetEditEngine(); virtual SvxEditSource* Clone() const; virtual SvxTextForwarder* GetTextForwarder(); diff --git a/sc/inc/fielduno.hxx b/sc/inc/fielduno.hxx index 395a48b8e1a7..6b535ffff8d4 100644 --- a/sc/inc/fielduno.hxx +++ b/sc/inc/fielduno.hxx @@ -51,7 +51,7 @@ #include <boost/noncopyable.hpp> #include <boost/scoped_ptr.hpp> -class SvxEditSource; +class ScEditSource; class SvxFieldItem; class SvxFieldData; class ScEditFieldObj; @@ -71,7 +71,7 @@ class ScCellFieldsObj : public cppu::WeakImplHelper5< private: ScDocShell* pDocShell; ScAddress aCellPos; - SvxEditSource* pEditSource; + ScEditSource* mpEditSource; /// List of refresh listeners. cppu::OInterfaceContainerHelper* mpRefreshListeners; /// mutex to lock the InterfaceContainerHelper @@ -140,7 +140,7 @@ class ScHeaderFieldsObj : public cppu::WeakImplHelper5< private: ScHeaderFooterTextData& mrData; sal_uInt16 nType; - SvxEditSource* pEditSource; + ScEditSource* mpEditSource; /// List of refresh listeners. cppu::OInterfaceContainerHelper* mpRefreshListeners; @@ -208,7 +208,7 @@ private: const SfxItemPropertySet* pPropSet; com::sun::star::uno::Reference<com::sun::star::text::XTextRange> mpContent; sal_uInt16 nType; - SvxEditSource* mpEditSource; + ScEditSource* mpEditSource; ESelection aSelection; sal_Int16 nFileFormat; // enum SvxFileFormat, valid if not inserted @@ -216,7 +216,7 @@ private: public: ScHeaderFieldObj( const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent, - SvxEditSource* pEditSrc, sal_uInt16 nT, const ESelection& rSel); + ScEditSource* pEditSrc, sal_uInt16 nT, const ESelection& rSel); virtual ~ScHeaderFieldObj(); // called by getImplementation: @@ -225,7 +225,7 @@ public: SvxFieldItem CreateFieldItem(); void InitDoc( const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent, - SvxEditSource* pEditSrc, const ESelection& rSel); + ScEditSource* pEditSrc, const ESelection& rSel); virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type & rType ) @@ -340,7 +340,7 @@ public: private: const SfxItemPropertySet* pPropSet; - SvxEditSource* pEditSource; + ScEditSource* mpEditSource; ESelection aSelection; FieldType meType; @@ -364,7 +364,7 @@ public: ScEditFieldObj( const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent, - SvxEditSource* pEditSrc, FieldType eType, const ESelection& rSel); + ScEditSource* pEditSrc, FieldType eType, const ESelection& rSel); virtual ~ScEditFieldObj(); void DeleteField(); @@ -372,7 +372,7 @@ public: SvxFieldItem CreateFieldItem(); void InitDoc( const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent, - SvxEditSource* pEditSrc, const ESelection& rSel); + ScEditSource* pEditSrc, const ESelection& rSel); // XTextField virtual ::rtl::OUString SAL_CALL getPresentation( sal_Bool bShowCommand ) diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx index d8e57ab1d727..ff68c6d22440 100644 --- a/sc/source/ui/unoobj/fielduno.cxx +++ b/sc/source/ui/unoobj/fielduno.cxx @@ -246,7 +246,7 @@ ScCellFieldsObj::ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos) : { pDocShell->GetDocument()->AddUnoObject(*this); - pEditSource = new ScCellEditSource( pDocShell, aCellPos ); + mpEditSource = new ScCellEditSource( pDocShell, aCellPos ); } ScCellFieldsObj::~ScCellFieldsObj() @@ -254,7 +254,7 @@ ScCellFieldsObj::~ScCellFieldsObj() if (pDocShell) pDocShell->GetDocument()->RemoveUnoObject(*this); - delete pEditSource; + delete mpEditSource; // increment refcount to prevent double call off dtor osl_incrementInterlockedCount( &m_refCount ); @@ -291,7 +291,7 @@ void ScCellFieldsObj::Notify( SfxBroadcaster&, const SfxHint& rHint ) uno::Reference<text::XTextField> ScCellFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const { //! Feld-Funktionen muessen an den Forwarder !!! - ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); if ( aTempEngine.FindByIndex( (sal_uInt16)Index, NULL ) ) // in der Zelle ist der Typ egal @@ -312,7 +312,7 @@ sal_Int32 SAL_CALL ScCellFieldsObj::getCount() throw(uno::RuntimeException) SolarMutexGuard aGuard; //! Feld-Funktionen muessen an den Forwarder !!! - ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); return aTempEngine.CountFields(NULL); // Felder zaehlen, in Zelle ist der Typ egal @@ -430,12 +430,12 @@ ScHeaderFieldsObj::ScHeaderFieldsObj(ScHeaderFooterTextData& rData) : nType(SC_SERVICE_INVALID), mpRefreshListeners( NULL ) { - pEditSource = new ScHeaderFooterEditSource(rData); + mpEditSource = new ScHeaderFooterEditSource(rData); } ScHeaderFieldsObj::~ScHeaderFieldsObj() { - delete pEditSource; + delete mpEditSource; // increment refcount to prevent double call off dtor osl_incrementInterlockedCount( &m_refCount ); @@ -485,7 +485,7 @@ ScEditFieldObj::FieldType getFieldType(sal_uInt16 nOldType) ScEditFieldObj* ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) const { //! Feld-Funktionen muessen an den Forwarder !!! - ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); TypeId aTypeId = NULL; @@ -543,7 +543,7 @@ sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() throw(uno::RuntimeException) SolarMutexGuard aGuard; //! Feld-Funktionen muessen an den Forwarder !!! - ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); TypeId aTypeId = NULL; @@ -695,7 +695,7 @@ sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue ) ScHeaderFieldObj::ScHeaderFieldObj( const uno::Reference<text::XTextRange>& rContent, - SvxEditSource* pEditSrc, sal_uInt16 nT, const ESelection& rSel) : + ScEditSource* pEditSrc, sal_uInt16 nT, const ESelection& rSel) : OComponentHelper( getMutex() ), pPropSet( (nT == SC_SERVICE_FILEFIELD) ? lcl_GetFileFieldPropertySet() : lcl_GetHeaderFieldPropertySet() ), mpContent(rContent), @@ -768,7 +768,7 @@ void SAL_CALL ScHeaderFieldObj::release() throw() } void ScHeaderFieldObj::InitDoc( - const uno::Reference<text::XTextRange>& rContent, SvxEditSource* pEditSrc, const ESelection& rSel) + const uno::Reference<text::XTextRange>& rContent, ScEditSource* pEditSrc, const ESelection& rSel) { if (!mpEditSource) { @@ -1115,10 +1115,10 @@ SvxFieldData* ScEditFieldObj::getData() void ScEditFieldObj::setPropertyValueURL(const rtl::OUString& rName, const com::sun::star::uno::Any& rVal) { rtl::OUString aStrVal; - if (pEditSource) + if (mpEditSource) { // Edit engine instance already exists for this field item. Use it. - ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); // Typ egal (in Zellen gibts nur URLs) @@ -1152,7 +1152,7 @@ void ScEditFieldObj::setPropertyValueURL(const rtl::OUString& rName, const com:: throw beans::UnknownPropertyException(); pEditEngine->QuickInsertField( SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection ); - pEditSource->UpdateData(); + mpEditSource->UpdateData(); return; } @@ -1197,10 +1197,10 @@ uno::Any ScEditFieldObj::getPropertyValueURL(const rtl::OUString& rName) } else if (rName == SC_UNONAME_TEXTWRAP) aRet <<= text::WrapTextMode_NONE; - else if (pEditSource) + else if (mpEditSource) { //! Feld-Funktionen muessen an den Forwarder !!! - ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); // Typ egal (in Zellen gibts nur URLs) @@ -1250,9 +1250,9 @@ void ScEditFieldObj::setPropertyValueFile(const rtl::OUString& rName, const uno: if (rVal >>= nIntVal) { SvxFileFormat eFormat = lcl_UnoToSvxFileFormat(nIntVal); - if (pEditSource) + if (mpEditSource) { - ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField)); @@ -1262,7 +1262,7 @@ void ScEditFieldObj::setPropertyValueFile(const rtl::OUString& rName, const uno: SvxExtFileField* pExtFile = static_cast<SvxExtFileField*>(pField); // local to the ScUnoEditEngine pExtFile->SetFormat(eFormat); pEditEngine->QuickInsertField(SvxFieldItem(*pField, EE_FEATURE_FIELD), aSelection); - pEditSource->UpdateData(); + mpEditSource->UpdateData(); } } else @@ -1284,9 +1284,9 @@ uno::Any ScEditFieldObj::getPropertyValueFile(const rtl::OUString& rName) { SvxFileFormat eFormat = SVXFILEFORMAT_NAME_EXT; const SvxFieldData* pField = NULL; - if (pEditSource) + if (mpEditSource) { - ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField)); @@ -1311,10 +1311,10 @@ uno::Any ScEditFieldObj::getPropertyValueFile(const rtl::OUString& rName) ScEditFieldObj::ScEditFieldObj( const uno::Reference<text::XTextRange>& rContent, - SvxEditSource* pEditSrc, FieldType eType, const ESelection& rSel) : + ScEditSource* pEditSrc, FieldType eType, const ESelection& rSel) : OComponentHelper(getMutex()), pPropSet(NULL), - pEditSource(pEditSrc), + mpEditSource(pEditSrc), aSelection(rSel), meType(eType), mpData(NULL), mpContent(rContent) { @@ -1332,36 +1332,36 @@ ScEditFieldObj::ScEditFieldObj( } void ScEditFieldObj::InitDoc( - const uno::Reference<text::XTextRange>& rContent, SvxEditSource* pEditSrc, const ESelection& rSel) + const uno::Reference<text::XTextRange>& rContent, ScEditSource* pEditSrc, const ESelection& rSel) { - if (!pEditSource) + if (!mpEditSource) { mpContent = rContent; mpData.reset(); aSelection = rSel; - pEditSource = pEditSrc; + mpEditSource = pEditSrc; } } ScEditFieldObj::~ScEditFieldObj() { - delete pEditSource; + delete mpEditSource; } SvxFieldItem ScEditFieldObj::CreateFieldItem() { - OSL_ENSURE( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" ); + OSL_ENSURE( !mpEditSource, "CreateFieldItem mit eingefuegtem Feld" ); return SvxFieldItem(*getData(), EE_FEATURE_FIELD); } void ScEditFieldObj::DeleteField() { - if (pEditSource) + if (mpEditSource) { - SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder(); + SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder(); pForwarder->QuickInsertText( String(), aSelection ); - pEditSource->UpdateData(); + mpEditSource->UpdateData(); aSelection.nEndPara = aSelection.nStartPara; aSelection.nEndPos = aSelection.nStartPos; @@ -1373,7 +1373,7 @@ void ScEditFieldObj::DeleteField() bool ScEditFieldObj::IsInserted() const { - return pEditSource != NULL; + return mpEditSource != NULL; } // XTextField @@ -1383,11 +1383,11 @@ rtl::OUString SAL_CALL ScEditFieldObj::getPresentation( sal_Bool bShowCommand ) { SolarMutexGuard aGuard; - if (!pEditSource) + if (!mpEditSource) return rtl::OUString("no edit source!!!"); //! Feld-Funktionen muessen an den Forwarder !!! - ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScEditEngineDefaulter* pEditEngine = mpEditSource->GetEditEngine(); ScUnoEditEngine aTempEngine(pEditEngine); // Typ egal (in Zellen gibts nur URLs) |