diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-25 12:59:53 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-01-27 17:19:26 +0100 |
commit | c95d91ee35ca09379a8a1d415ae77716ddeadaac (patch) | |
tree | 370b0ad6832f3aca2ee0e2ef375bb6f953e5d360 /sd | |
parent | 2d8f17565ebe867210f5769851d91b2e7b612a8f (diff) |
improve subtyping when dealing with tools::WeakReference
tweak the templating to make it easier to declare a WeakReference that
points to a subclass for a weak-capable class.
Which lets us declare some fields with more specific types, and dump a
lot of unnecessary casting.
And make WeakBase be inherited from virtually, so we don't end
up with weird states where two weak refernces could point to two
different parts of the same object.
Change-Id: I3213ea27e087038457b0761b5171c7bce96e71f3
Reviewed-on: https://gerrit.libreoffice.org/48650
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/inc/undo/undoobjects.hxx | 8 | ||||
-rw-r--r-- | sd/source/core/stlfamily.cxx | 4 | ||||
-rw-r--r-- | sd/source/core/undo/undoobjects.cxx | 22 | ||||
-rw-r--r-- | sd/source/ui/func/futext.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/inc/DrawController.hxx | 2 | ||||
-rw-r--r-- | sd/source/ui/inc/futext.hxx | 4 | ||||
-rw-r--r-- | sd/source/ui/view/drawview.cxx | 2 | ||||
-rw-r--r-- | sd/source/ui/view/sdview.cxx | 8 |
8 files changed, 27 insertions, 27 deletions
diff --git a/sd/inc/undo/undoobjects.hxx b/sd/inc/undo/undoobjects.hxx index bd3f05d99b1a..2e0023246e10 100644 --- a/sd/inc/undo/undoobjects.hxx +++ b/sd/inc/undo/undoobjects.hxx @@ -127,7 +127,7 @@ public: private: PresObjKind meOldKind; PresObjKind meNewKind; - ::tools::WeakReference<SdrPage> mxPage; + ::tools::WeakReference<SdPage> mxPage; ::tools::WeakReference<SdrObject> mxSdrObject; }; @@ -143,7 +143,7 @@ public: virtual void Redo() override; private: - ::tools::WeakReference<SdrPage> mxPage; + ::tools::WeakReference<SdPage> mxPage; }; class UndoGeoObject final : public SdrUndoGeoObj @@ -155,7 +155,7 @@ public: virtual void Redo() override; private: - ::tools::WeakReference<SdrPage> mxPage; + ::tools::WeakReference<SdPage> mxPage; ::tools::WeakReference<SdrObject> mxSdrObject; }; @@ -168,7 +168,7 @@ public: virtual void Redo() override; private: - ::tools::WeakReference<SdrPage> mxPage; + ::tools::WeakReference<SdPage> mxPage; ::tools::WeakReference<SdrObject> mxSdrObject; }; diff --git a/sd/source/core/stlfamily.cxx b/sd/source/core/stlfamily.cxx index 0903816ae6ef..7c995c4cbe37 100644 --- a/sd/source/core/stlfamily.cxx +++ b/sd/source/core/stlfamily.cxx @@ -49,7 +49,7 @@ typedef std::map< OUString, rtl::Reference< SdStyleSheet > > PresStyleMap; struct SdStyleFamilyImpl { - tools::WeakReference<SdrPage> mxMasterPage; + tools::WeakReference<SdPage> mxMasterPage; OUString maLayoutName; PresStyleMap& getStyleSheets(); @@ -185,7 +185,7 @@ OUString SAL_CALL SdStyleFamily::getName() { if( mnFamily == SfxStyleFamily::Page ) { - SdPage* pPage = static_cast< SdPage* >( mpImpl->mxMasterPage.get() ); + SdPage* pPage = mpImpl->mxMasterPage.get(); if( pPage == nullptr ) throw DisposedException(); diff --git a/sd/source/core/undo/undoobjects.cxx b/sd/source/core/undo/undoobjects.cxx index 690d45fe2d72..bd3589c2af98 100644 --- a/sd/source/core/undo/undoobjects.cxx +++ b/sd/source/core/undo/undoobjects.cxx @@ -254,20 +254,20 @@ UndoObjectPresentationKind::UndoObjectPresentationKind(SdrObject& rObject) : SdrUndoObj(rObject) , meOldKind(PRESOBJ_NONE) , meNewKind(PRESOBJ_NONE) -, mxPage( rObject.GetPage() ) +, mxPage( static_cast<SdPage*>(rObject.GetPage()) ) , mxSdrObject( &rObject ) { DBG_ASSERT( mxPage.is(), "sd::UndoObjectPresentationKind::UndoObjectPresentationKind(), does not work for shapes without a slide!" ); if( mxPage.is() ) - meOldKind = static_cast< SdPage* >( mxPage.get() )->GetPresObjKind( &rObject ); + meOldKind = mxPage->GetPresObjKind( &rObject ); } void UndoObjectPresentationKind::Undo() { if( mxPage.is() && mxSdrObject.is() ) { - SdPage* pPage = static_cast< SdPage* >( mxPage.get() ); + SdPage* pPage = mxPage.get(); meNewKind = pPage->GetPresObjKind( mxSdrObject.get() ); if( meNewKind != PRESOBJ_NONE ) pPage->RemovePresObj( mxSdrObject.get() ); @@ -280,7 +280,7 @@ void UndoObjectPresentationKind::Redo() { if( mxPage.is() && mxSdrObject.is() ) { - SdPage* pPage = static_cast< SdPage* >( mxPage.get() ); + SdPage* pPage = mxPage.get(); if( meOldKind != PRESOBJ_NONE ) pPage->RemovePresObj( mxSdrObject.get() ); if( meNewKind != PRESOBJ_NONE ) @@ -300,14 +300,14 @@ void UndoAutoLayoutPosAndSize::Undo() void UndoAutoLayoutPosAndSize::Redo() { - SdPage* pPage = static_cast< SdPage* >( mxPage.get() ); + SdPage* pPage = mxPage.get(); if( pPage ) pPage->SetAutoLayout( pPage->GetAutoLayout() ); } UndoGeoObject::UndoGeoObject( SdrObject& rNewObj ) : SdrUndoGeoObj( rNewObj ) -, mxPage( rNewObj.GetPage() ) +, mxPage( static_cast<SdPage*>(rNewObj.GetPage()) ) , mxSdrObject( &rNewObj ) { } @@ -319,7 +319,7 @@ void UndoGeoObject::Undo() { if( mxPage.is() ) { - ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement ); + ScopeLockGuard aGuard( mxPage->maLockAutoLayoutArrangement ); SdrUndoGeoObj::Undo(); } else @@ -336,7 +336,7 @@ void UndoGeoObject::Redo() { if( mxPage.is() ) { - ScopeLockGuard aGuard( static_cast< SdPage* >(mxPage.get())->maLockAutoLayoutArrangement ); + ScopeLockGuard aGuard( mxPage->maLockAutoLayoutArrangement ); SdrUndoGeoObj::Redo(); } else @@ -348,7 +348,7 @@ void UndoGeoObject::Redo() UndoAttrObject::UndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText ) : SdrUndoAttrObj( rObject, bStyleSheet1, bSaveText ) -, mxPage( rObject.GetPage() ) +, mxPage( static_cast<SdPage*>(rObject.GetPage()) ) , mxSdrObject( &rObject ) { } @@ -360,7 +360,7 @@ void UndoAttrObject::Undo() { if( mxPage.is() ) { - ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement ); + ScopeLockGuard aGuard( mxPage->maLockAutoLayoutArrangement ); SdrUndoAttrObj::Undo(); } else @@ -377,7 +377,7 @@ void UndoAttrObject::Redo() { if( mxPage.is() ) { - ScopeLockGuard aGuard( static_cast< SdPage* >( mxPage.get() )->maLockAutoLayoutArrangement ); + ScopeLockGuard aGuard( mxPage->maLockAutoLayoutArrangement ); SdrUndoAttrObj::Redo(); } else diff --git a/sd/source/ui/func/futext.cxx b/sd/source/ui/func/futext.cxx index b2ca0d1111b1..19c0ce638516 100644 --- a/sd/source/ui/func/futext.cxx +++ b/sd/source/ui/func/futext.cxx @@ -1132,7 +1132,7 @@ void FuText::SetInEditMode(const MouseEvent& rMEvt, bool bQuickDrag) } else { - mpView->RestoreDefaultText(dynamic_cast< SdrTextObj* >( mxTextObj.get() )); + mpView->RestoreDefaultText( mxTextObj.get() ); } } } @@ -1244,7 +1244,7 @@ void FuText::ReceiveRequest(SfxRequest& rReq) { // are we currently editing? if(!bTestText) - mxTextObj.reset( dynamic_cast< SdrTextObj* >( mpView->GetTextEditObject() ) ); + mxTextObj.reset( mpView->GetTextEditObject() ); if (!mxTextObj.is()) { diff --git a/sd/source/ui/inc/DrawController.hxx b/sd/source/ui/inc/DrawController.hxx index 7eb8d2c0fe79..d6ecc0d837f9 100644 --- a/sd/source/ui/inc/DrawController.hxx +++ b/sd/source/ui/inc/DrawController.hxx @@ -288,7 +288,7 @@ private: ViewShellBase* mpBase; ::tools::Rectangle maLastVisArea; - ::tools::WeakReference<SdrPage> mpCurrentPage; + ::tools::WeakReference<SdPage> mpCurrentPage; bool mbMasterPageMode; bool mbLayerMode; diff --git a/sd/source/ui/inc/futext.hxx b/sd/source/ui/inc/futext.hxx index 42c02b22d153..5b55c28eb491 100644 --- a/sd/source/ui/inc/futext.hxx +++ b/sd/source/ui/inc/futext.hxx @@ -54,7 +54,7 @@ public: void SetInEditMode(const MouseEvent& rMEvt, bool bQuickDrag); void DeleteDefaultText(); - SdrTextObj* GetTextObj() { return static_cast< SdrTextObj* >( mxTextObj.get() ); } + SdrTextObj* GetTextObj() { return mxTextObj.get(); } virtual SdrObject* CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle) override; @@ -81,7 +81,7 @@ protected: private: virtual void disposing() override; - ::tools::WeakReference<SdrObject> + ::tools::WeakReference<SdrTextObj> mxTextObj; bool bFirstObjCreated; bool bJustEndedEdit; diff --git a/sd/source/ui/view/drawview.cxx b/sd/source/ui/view/drawview.cxx index d635b1bdf804..7620a2cec268 100644 --- a/sd/source/ui/view/drawview.cxx +++ b/sd/source/ui/view/drawview.cxx @@ -137,7 +137,7 @@ bool DrawView::SetAttributes(const SfxItemSet& rSet, { SfxStyleSheetBasePool* pStShPool = mrDoc.GetStyleSheetPool(); SdPage& rPage = *mpDrawViewShell->getCurrentPage(); - SdrTextObj* pEditObject = static_cast< SdrTextObj* >( GetTextEditObject() ); + SdrTextObj* pEditObject = GetTextEditObject(); if (pEditObject) { diff --git a/sd/source/ui/view/sdview.cxx b/sd/source/ui/view/sdview.cxx index 92d7358b088d..be1417f82940 100644 --- a/sd/source/ui/view/sdview.cxx +++ b/sd/source/ui/view/sdview.cxx @@ -761,9 +761,9 @@ SdrEndTextEditKind View::SdrEndTextEdit(bool bDontDeleteReally) { maMasterViewFilter.End(); - ::tools::WeakReference<SdrObject> xObj( GetTextEditObject() ); + ::tools::WeakReference<SdrTextObj> xObj( GetTextEditObject() ); - bool bDefaultTextRestored = RestoreDefaultText( dynamic_cast< SdrTextObj* >( GetTextEditObject() ) ); + bool bDefaultTextRestored = RestoreDefaultText( xObj.get() ); SdrEndTextEditKind eKind = FmFormView::SdrEndTextEdit(bDontDeleteReally); @@ -780,7 +780,7 @@ SdrEndTextEditKind View::SdrEndTextEdit(bool bDontDeleteReally) } else if( xObj.is() && xObj->IsEmptyPresObj() ) { - SdrTextObj* pObj = dynamic_cast< SdrTextObj* >( xObj.get() ); + SdrTextObj* pObj = xObj.get(); if( pObj && pObj->HasText() ) { SdrPage* pPage = pObj->GetPage(); @@ -1194,7 +1194,7 @@ void View::OnBeginPasteOrDrop( PasteOrDropInfos* /*pInfo*/ ) void View::OnEndPasteOrDrop( PasteOrDropInfos* pInfo ) { /* Style Sheet handling */ - SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( GetTextEditObject() ); + SdrTextObj* pTextObj = GetTextEditObject(); SdrOutliner* pOutliner = GetTextEditOutliner(); if( !pOutliner || !pTextObj || !pTextObj->GetPage() ) return; |