Revert "SOSAW080: Added first bunch of basic changes to helpers"

This reverts commit 6c14c27c75a03e2363f2b363ddf0a6f2f46cfa91.
diff --git a/basctl/source/dlged/dlged.cxx b/basctl/source/dlged/dlged.cxx
index 186e835..ec3a2e0 100644
--- a/basctl/source/dlged/dlged.cxx
+++ b/basctl/source/dlged/dlged.cxx
@@ -347,7 +347,7 @@ void DlgEditor::SetDialog( const uno::Reference< container::XNameContainer >& xU
    m_xUnoControlDialogModel = xUnoControlDialogModel;

    // create dialog form
    pDlgEdForm = new DlgEdForm(*pDlgEdModel, *this);
    pDlgEdForm = new DlgEdForm(*this);
    uno::Reference< awt::XControlModel > xDlgMod( m_xUnoControlDialogModel , uno::UNO_QUERY );
    pDlgEdForm->SetUnoControlModel(xDlgMod);
    static_cast<DlgEdPage*>(pDlgEdModel->GetPage(0))->SetDlgEdForm( pDlgEdForm );
@@ -391,7 +391,7 @@ void DlgEditor::SetDialog( const uno::Reference< container::XNameContainer >& xU
            Any aCtrl = xNameAcc->getByName( indexToName.second );
            Reference< css::awt::XControlModel > xCtrlModel;
            aCtrl >>= xCtrlModel;
            DlgEdObj* pCtrlObj = new DlgEdObj(*pDlgEdModel);
            DlgEdObj* pCtrlObj = new DlgEdObj();
            pCtrlObj->SetUnoControlModel( xCtrlModel );
            pCtrlObj->SetDlgEdForm( pDlgEdForm );
            pDlgEdForm->AddChild( pCtrlObj );
@@ -609,11 +609,7 @@ void DlgEditor::SetInsertObj( sal_uInt16 eObj )
void DlgEditor::CreateDefaultObject()
{
    // create object by factory
    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDlgEdModel,
        pDlgEdView->GetCurrentObjInventor(),
        pDlgEdView->GetCurrentObjIdentifier(),
        pDlgEdPage);
    SdrObject* pObj = SdrObjFactory::MakeNewObject( pDlgEdView->GetCurrentObjInventor(), pDlgEdView->GetCurrentObjIdentifier(), pDlgEdPage );

    if (DlgEdObj* pDlgEdObj = dynamic_cast<DlgEdObj*>(pObj))
    {
@@ -924,7 +920,7 @@ void DlgEditor::Paste()
                        Reference< util::XCloneable > xClone( xCM, uno::UNO_QUERY );
                        Reference< awt::XControlModel > xCtrlModel( xClone->createClone(), uno::UNO_QUERY );

                        DlgEdObj* pCtrlObj = new DlgEdObj(*pDlgEdModel);
                        DlgEdObj* pCtrlObj = new DlgEdObj();
                        pCtrlObj->SetDlgEdForm(pDlgEdForm);         // set parent form
                        pDlgEdForm->AddChild(pCtrlObj);             // add child to parent form
                        pCtrlObj->SetUnoControlModel( xCtrlModel ); // set control model
diff --git a/basctl/source/dlged/dlgedfac.cxx b/basctl/source/dlged/dlgedfac.cxx
index be8e592..a3e7b62 100644
--- a/basctl/source/dlged/dlgedfac.cxx
+++ b/basctl/source/dlged/dlgedfac.cxx
@@ -69,27 +69,27 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
        switch( aParams.nObjIdentifier )
        {
            case OBJ_DLG_PUSHBUTTON:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlButtonModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlButtonModel", xDialogSFact );
                 break;
            case OBJ_DLG_RADIOBUTTON:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlRadioButtonModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlRadioButtonModel", xDialogSFact );
                 break;
            case OBJ_DLG_FORMRADIO:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.RadioButton", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.form.component.RadioButton", xDialogSFact );
                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
                 break;
            case OBJ_DLG_CHECKBOX:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlCheckBoxModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlCheckBoxModel", xDialogSFact );
                 break;
            case OBJ_DLG_FORMCHECK:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.CheckBox", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.form.component.CheckBox", xDialogSFact );
                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
                 break;
            case OBJ_DLG_LISTBOX:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlListBoxModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlListBoxModel", xDialogSFact );
                 break;
            case OBJ_DLG_FORMLIST:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ListBox", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.form.component.ListBox", xDialogSFact );
                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
                 break;
            case OBJ_DLG_FORMCOMBO:
@@ -97,10 +97,10 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
            {
                 DlgEdObj* pNew = nullptr;
                 if ( aParams.nObjIdentifier == OBJ_DLG_COMBOBOX )
                     pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlComboBoxModel", xDialogSFact );
                     pNew = new DlgEdObj( "com.sun.star.awt.UnoControlComboBoxModel", xDialogSFact );
                 else
                 {
                     pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ComboBox", xDialogSFact );
                     pNew = new DlgEdObj( "com.sun.star.form.component.ComboBox", xDialogSFact );
                     pNew->MakeDataAware( mxModel );
                 }
                 pNewObj = pNew;
@@ -118,25 +118,25 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
            }
            break;
            case OBJ_DLG_GROUPBOX:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlGroupBoxModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlGroupBoxModel", xDialogSFact );
                 break;
            case OBJ_DLG_EDIT:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlEditModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlEditModel", xDialogSFact );
                 break;
            case OBJ_DLG_FIXEDTEXT:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedTextModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlFixedTextModel", xDialogSFact );
                 break;
            case OBJ_DLG_IMAGECONTROL:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlImageControlModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlImageControlModel", xDialogSFact );
                 break;
            case OBJ_DLG_PROGRESSBAR:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlProgressBarModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlProgressBarModel", xDialogSFact );
                 break;
            case OBJ_DLG_HSCROLLBAR:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
                 break;
            case OBJ_DLG_FORMHSCROLL:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ScrollBar", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.form.component.ScrollBar", xDialogSFact );
                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
                 break;
            case OBJ_DLG_FORMVSCROLL:
@@ -144,10 +144,10 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
            {
                 DlgEdObj* pNew = nullptr;
                 if ( aParams.nObjIdentifier ==  OBJ_DLG_VSCROLLBAR )
                     pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
                     pNew = new DlgEdObj( "com.sun.star.awt.UnoControlScrollBarModel", xDialogSFact );
                 else
                 {
                     pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.ScrollBar", xDialogSFact );
                     pNew = new DlgEdObj( "com.sun.star.form.component.ScrollBar", xDialogSFact );
                     pNew->MakeDataAware( mxModel );
                 }
                 pNewObj = pNew;
@@ -165,11 +165,11 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
                 }
            }    break;
            case OBJ_DLG_HFIXEDLINE:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
                 break;
            case OBJ_DLG_VFIXEDLINE:
            {
                 DlgEdObj* pNew = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
                 DlgEdObj* pNew = new DlgEdObj( "com.sun.star.awt.UnoControlFixedLineModel", xDialogSFact );
                 pNewObj = pNew;
                 // set vertical orientation
                 try
@@ -185,35 +185,35 @@ IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
                 }
            }    break;
            case OBJ_DLG_DATEFIELD:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlDateFieldModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlDateFieldModel", xDialogSFact );
                 break;
            case OBJ_DLG_TIMEFIELD:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlTimeFieldModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlTimeFieldModel", xDialogSFact );
                 break;
            case OBJ_DLG_NUMERICFIELD:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlNumericFieldModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlNumericFieldModel", xDialogSFact );
                 break;
            case OBJ_DLG_CURRENCYFIELD:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlCurrencyFieldModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlCurrencyFieldModel", xDialogSFact );
                 break;
            case OBJ_DLG_FORMATTEDFIELD:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFormattedFieldModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlFormattedFieldModel", xDialogSFact );
                 break;
            case OBJ_DLG_PATTERNFIELD:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlPatternFieldModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlPatternFieldModel", xDialogSFact );
                 break;
            case OBJ_DLG_FILECONTROL:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlFileControlModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlFileControlModel", xDialogSFact );
                 break;
            case OBJ_DLG_SPINBUTTON:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.UnoControlSpinButtonModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.UnoControlSpinButtonModel", xDialogSFact );
                 break;
            case OBJ_DLG_FORMSPIN:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.form.component.SpinButton", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.form.component.SpinButton", xDialogSFact );
                 static_cast< DlgEdObj* >( pNewObj )->MakeDataAware( mxModel );
                 break;
            case OBJ_DLG_TREECONTROL:
                 pNewObj = new DlgEdObj(aParams.rSdrModel, "com.sun.star.awt.tree.TreeControlModel", xDialogSFact );
                 pNewObj = new DlgEdObj( "com.sun.star.awt.tree.TreeControlModel", xDialogSFact );
                 break;
        }
    }
diff --git a/basctl/source/dlged/dlgedobj.cxx b/basctl/source/dlged/dlgedobj.cxx
index 44d7b7a..41158fe 100644
--- a/basctl/source/dlged/dlgedobj.cxx
+++ b/basctl/source/dlged/dlgedobj.cxx
@@ -63,20 +63,18 @@ DlgEditor& DlgEdObj::GetDialogEditor ()
        return pDlgEdForm->GetDlgEditor();
}

DlgEdObj::DlgEdObj(SdrModel& rSdrModel)
:   SdrUnoObj(rSdrModel, OUString())
    ,bIsListening(false)
    ,pDlgEdForm( nullptr )
DlgEdObj::DlgEdObj()
          :SdrUnoObj(OUString())
          ,bIsListening(false)
          ,pDlgEdForm( nullptr )
{
}

DlgEdObj::DlgEdObj(
    SdrModel& rSdrModel,
    const OUString& rModelName,
    const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSFac)
:   SdrUnoObj(rSdrModel, rModelName, rxSFac)
    ,bIsListening(false)
    ,pDlgEdForm( nullptr )
DlgEdObj::DlgEdObj(const OUString& rModelName,
                   const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSFac)
          :SdrUnoObj(rModelName, rxSFac)
          ,bIsListening(false)
          ,pDlgEdForm( nullptr )
{
}

@@ -502,7 +500,7 @@ void DlgEdObj::UpdateStep()
    sal_Int32 nCurStep = GetDlgEdForm()->GetStep();
    sal_Int32 nStep = GetStep();

    SdrLayerAdmin& rLayerAdmin(getSdrModelFromSdrObject().GetLayerAdmin());
    SdrLayerAdmin& rLayerAdmin = GetModel()->GetLayerAdmin();
    SdrLayerID nHiddenLayerId   = rLayerAdmin.GetLayerID( "HiddenLayer" );
    SdrLayerID nControlLayerId   = rLayerAdmin.GetLayerID( rLayerAdmin.GetControlLayerName() );

@@ -606,7 +604,7 @@ void DlgEdObj::TabIndexChange( const beans::PropertyChangeEvent& evt )
            }

            // reorder objects in drawing page
            getSdrModelFromSdrObject().GetPage(0)->SetObjectOrdNum( nOldTabIndex + 1, nNewTabIndex + 1 );
            GetModel()->GetPage(0)->SetObjectOrdNum( nOldTabIndex + 1, nNewTabIndex + 1 );

            pForm->UpdateTabOrderAndGroups();
        }
@@ -886,9 +884,9 @@ void DlgEdObj::clonedFrom(const DlgEdObj* _pSource)
    StartListening();
}

DlgEdObj* DlgEdObj::Clone(SdrModel* pTargetModel) const
DlgEdObj* DlgEdObj::Clone() const
{
    DlgEdObj* pDlgEdObj = CloneHelper< DlgEdObj >(pTargetModel);
    DlgEdObj* pDlgEdObj = CloneHelper< DlgEdObj >();
    DBG_ASSERT( pDlgEdObj != nullptr, "DlgEdObj::Clone: invalid clone!" );
    if ( pDlgEdObj )
        pDlgEdObj->clonedFrom( this );
@@ -900,9 +898,7 @@ SdrObject* DlgEdObj::getFullDragClone() const
{
    // no need to really add the clone for dragging, it's a temporary
    // object
    SdrObject* pObj = new SdrUnoObj(
        getSdrModelFromSdrObject(),
        OUString());
    SdrObject* pObj = new SdrUnoObj(OUString());
    *pObj = *static_cast<const SdrUnoObj*>(this);

    return pObj;
@@ -1197,10 +1193,8 @@ void DlgEdObj::SetLayer(SdrLayerID nLayer)
    }
}

DlgEdForm::DlgEdForm(
    SdrModel& rSdrModel,
    DlgEditor& rDlgEditor_)
:   DlgEdObj(rSdrModel),

DlgEdForm::DlgEdForm (DlgEditor& rDlgEditor_) :
    rDlgEditor(rDlgEditor_)
{
}
diff --git a/basctl/source/dlged/dlgedpage.cxx b/basctl/source/dlged/dlgedpage.cxx
index da9ba12..211aa86 100644
--- a/basctl/source/dlged/dlgedpage.cxx
+++ b/basctl/source/dlged/dlgedpage.cxx
@@ -27,8 +27,14 @@ namespace basctl


DlgEdPage::DlgEdPage(DlgEdModel& rModel, bool bMasterPage)
:   SdrPage(rModel, bMasterPage)
    ,pDlgEdForm(nullptr)
    : SdrPage(rModel, bMasterPage)
    , pDlgEdForm(nullptr)
{
}

DlgEdPage::DlgEdPage(const DlgEdPage& rSrcPage)
    : SdrPage(rSrcPage)
    , pDlgEdForm(nullptr)
{
}

@@ -37,15 +43,23 @@ DlgEdPage::~DlgEdPage()
    Clear();
}


SdrPage* DlgEdPage::Clone() const
{
    return Clone(nullptr);
}

SdrPage* DlgEdPage::Clone(SdrModel* const pNewModel) const
{
    DlgEdModel& rDlgEdModel(static_cast< DlgEdModel& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    DlgEdPage* pClonedDlgEdPage(
        new DlgEdPage(
            rDlgEdModel,
            IsMasterPage()));
    pClonedDlgEdPage->SdrPage::lateInit(*this);
    return pClonedDlgEdPage;
    DlgEdPage* const pNewPage = new DlgEdPage( *this );
    DlgEdModel* pDlgEdModel = nullptr;
    if ( pNewModel )
    {
        pDlgEdModel = dynamic_cast<DlgEdModel*>( pNewModel );
        assert(pDlgEdModel);
    }
    pNewPage->lateInit( *this, pDlgEdModel );
    return pNewPage;
}


diff --git a/basctl/source/dlged/dlgedview.cxx b/basctl/source/dlged/dlgedview.cxx
index 12d2d57..aa7f1e4 100644
--- a/basctl/source/dlged/dlgedview.cxx
+++ b/basctl/source/dlged/dlgedview.cxx
@@ -31,11 +31,9 @@
namespace basctl
{

DlgEdView::DlgEdView(
    SdrModel& rSdrModel,
    OutputDevice& rOut,
    DlgEditor& rEditor)
:   SdrView(rSdrModel, &rOut),

DlgEdView::DlgEdView (SdrModel& rModel, OutputDevice& rOut, DlgEditor& rEditor) :
    SdrView(&rModel, &rOut),
    rDlgEditor(rEditor)
{
    SetBufferedOutputAllowed(true);
diff --git a/basctl/source/inc/dlgedobj.hxx b/basctl/source/inc/dlgedobj.hxx
index 4660c29..58f6044 100644
--- a/basctl/source/inc/dlgedobj.hxx
+++ b/basctl/source/inc/dlgedobj.hxx
@@ -57,11 +57,9 @@ private:
    DlgEditor& GetDialogEditor ();

protected:
    DlgEdObj(SdrModel& rSdrModel);
    DlgEdObj(
        SdrModel& rSdrModel,
        const OUString& rModelName,
        const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSFac);
    DlgEdObj();
    DlgEdObj(const OUString& rModelName,
             const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSFac);

    virtual void NbcMove( const Size& rSize ) override;
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
@@ -96,7 +94,7 @@ public:
    virtual SdrInventor GetObjInventor() const override;
    virtual sal_uInt16 GetObjIdentifier() const override;

    virtual DlgEdObj* Clone(SdrModel* pTargetModel = nullptr) const override;                                          // not working yet
    virtual DlgEdObj*   Clone() const override;                                          // not working yet
    void clonedFrom(const DlgEdObj* _pSource);                          // not working yet

    // FullDrag support
@@ -154,9 +152,7 @@ private:
    mutable ::boost::optional< css::awt::DeviceInfo >   mpDeviceInfo;

private:
    explicit DlgEdForm(
        SdrModel& rSdrModel,
        DlgEditor&);
    explicit DlgEdForm (DlgEditor&);

protected:
    virtual void NbcMove( const Size& rSize ) override;
diff --git a/basctl/source/inc/dlgedpage.hxx b/basctl/source/inc/dlgedpage.hxx
index 164f725f..814826e 100644
--- a/basctl/source/inc/dlgedpage.hxx
+++ b/basctl/source/inc/dlgedpage.hxx
@@ -35,7 +35,6 @@ class DlgEdForm;
class DlgEdPage final : public SdrPage
{
    DlgEdPage& operator=(const DlgEdPage&) = delete;
    DlgEdPage(const DlgEdPage&) = delete;

    DlgEdForm*      pDlgEdForm;

@@ -44,12 +43,16 @@ public:
    explicit DlgEdPage( DlgEdModel& rModel, bool bMasterPage = false );
    virtual ~DlgEdPage() override;

    virtual SdrPage* Clone(SdrModel* pNewModel = nullptr) const override;
    virtual SdrPage* Clone() const override;
    virtual SdrPage* Clone( SdrModel* pNewModel ) const override;

    void            SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
    DlgEdForm*      GetDlgEdForm() const { return pDlgEdForm; }

    virtual SdrObject* SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum) override;

private:
    DlgEdPage(const DlgEdPage& rSrcPage);
};

} // namespace basctl
diff --git a/basctl/source/inc/dlgedview.hxx b/basctl/source/inc/dlgedview.hxx
index c194c12..511abfc 100644
--- a/basctl/source/inc/dlgedview.hxx
+++ b/basctl/source/inc/dlgedview.hxx
@@ -39,11 +39,7 @@ private:

public:

    DlgEdView(
        SdrModel& rSdrModel,
        OutputDevice& rOut,
        DlgEditor& rEditor);

    DlgEdView (SdrModel& rModel, OutputDevice& rOut, DlgEditor& rEditor);
    virtual ~DlgEdView() override;

    virtual void MarkListHasChanged() override;
diff --git a/basegfx/Library_basegfx.mk b/basegfx/Library_basegfx.mk
index de744b5..087e4a0 100644
--- a/basegfx/Library_basegfx.mk
+++ b/basegfx/Library_basegfx.mk
@@ -38,7 +38,6 @@ $(eval $(call gb_Library_add_exception_objects,basegfx,\
    basegfx/source/matrix/b2dhommatrix \
    basegfx/source/matrix/b2dhommatrixtools \
    basegfx/source/matrix/b3dhommatrix \
    basegfx/source/matrix/b3dhommatrixtools \
	basegfx/source/numeric/ftools \
    basegfx/source/pixel/bpixel \
    basegfx/source/point/b2dpoint \
diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx
index 466e903..9f7d5bff 100644
--- a/basegfx/source/matrix/b2dhommatrix.cxx
+++ b/basegfx/source/matrix/b2dhommatrix.cxx
@@ -115,11 +115,6 @@ namespace basegfx

    bool B2DHomMatrix::invert()
    {
        if(isIdentity())
        {
            return true;
        }

        Impl2DHomMatrix aWork(*mpImpl);
        std::unique_ptr<sal_uInt16[]> pIndex( new sal_uInt16[Impl2DHomMatrix_Base::getEdgeLength()] );
        sal_Int16 nParity;
@@ -218,11 +213,6 @@ namespace basegfx
        }
    }

    void B2DHomMatrix::translate(const B2DTuple& rTuple)
    {
        translate(rTuple.getX(), rTuple.getY());
    }

    void B2DHomMatrix::scale(double fX, double fY)
    {
        const double fOne(1.0);
@@ -238,11 +228,6 @@ namespace basegfx
        }
    }

    void B2DHomMatrix::scale(const B2DTuple& rTuple)
    {
        scale(rTuple.getX(), rTuple.getY());
    }

    void B2DHomMatrix::shearX(double fSx)
    {
        // #i76239# do not test against 1.0, but against 0.0. We are talking about a value not on the diagonal (!)
diff --git a/basegfx/source/matrix/b3dhommatrix.cxx b/basegfx/source/matrix/b3dhommatrix.cxx
index b55dd07..6cfd054 100644
--- a/basegfx/source/matrix/b3dhommatrix.cxx
+++ b/basegfx/source/matrix/b3dhommatrix.cxx
@@ -203,11 +203,6 @@ namespace basegfx
        }
    }

    void B3DHomMatrix::rotate(const B3DTuple& rRotation)
    {
        rotate(rRotation.getX(), rRotation.getY(), rRotation.getZ());
    }

    void B3DHomMatrix::translate(double fX, double fY, double fZ)
    {
        if(!fTools::equalZero(fX) || !fTools::equalZero(fY) || !fTools::equalZero(fZ))
@@ -222,11 +217,6 @@ namespace basegfx
        }
    }

    void B3DHomMatrix::translate(const B3DTuple& rRotation)
    {
        translate(rRotation.getX(), rRotation.getY(), rRotation.getZ());
    }

    void B3DHomMatrix::scale(double fX, double fY, double fZ)
    {
        const double fOne(1.0);
@@ -243,11 +233,6 @@ namespace basegfx
        }
    }

    void B3DHomMatrix::scale(const B3DTuple& rRotation)
    {
        scale(rRotation.getX(), rRotation.getY(), rRotation.getZ());
    }

    void B3DHomMatrix::shearXY(double fSx, double fSy)
    {
        // #i76239# do not test against 1.0, but against 0.0. We are talking about a value not on the diagonal (!)
diff --git a/basegfx/source/matrix/b3dhommatrixtools.cxx b/basegfx/source/matrix/b3dhommatrixtools.cxx
deleted file mode 100755
index 677c978..0000000
--- a/basegfx/source/matrix/b3dhommatrixtools.cxx
+++ /dev/null
@@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <basegfx/matrix/b3dhommatrixtools.hxx>

namespace basegfx
{
    namespace utils
    {
        B3DHomMatrix UnoHomogenMatrixToB3DHomMatrix(
            const com::sun::star::drawing::HomogenMatrix& rMatrixIn)
        {
            B3DHomMatrix aRetval;

            aRetval.set(0, 0, rMatrixIn.Line1.Column1);
            aRetval.set(0, 1, rMatrixIn.Line1.Column2);
            aRetval.set(0, 2, rMatrixIn.Line1.Column3);
            aRetval.set(0, 3, rMatrixIn.Line1.Column4);
            aRetval.set(1, 0, rMatrixIn.Line2.Column1);
            aRetval.set(1, 1, rMatrixIn.Line2.Column2);
            aRetval.set(1, 2, rMatrixIn.Line2.Column3);
            aRetval.set(1, 3, rMatrixIn.Line2.Column4);
            aRetval.set(2, 0, rMatrixIn.Line3.Column1);
            aRetval.set(2, 1, rMatrixIn.Line3.Column2);
            aRetval.set(2, 2, rMatrixIn.Line3.Column3);
            aRetval.set(2, 3, rMatrixIn.Line3.Column4);
            aRetval.set(3, 0, rMatrixIn.Line4.Column1);
            aRetval.set(3, 1, rMatrixIn.Line4.Column2);
            aRetval.set(3, 2, rMatrixIn.Line4.Column3);
            aRetval.set(3, 3, rMatrixIn.Line4.Column4);

            return aRetval;
        }

        void B3DHomMatrixToUnoHomogenMatrix(
            const B3DHomMatrix& rMatrixIn,
            com::sun::star::drawing::HomogenMatrix& rMatrixOut)
        {
            rMatrixOut.Line1.Column1 = rMatrixIn.get(0, 0);
            rMatrixOut.Line1.Column2 = rMatrixIn.get(0, 1);
            rMatrixOut.Line1.Column3 = rMatrixIn.get(0, 2);
            rMatrixOut.Line1.Column4 = rMatrixIn.get(0, 3);
            rMatrixOut.Line2.Column1 = rMatrixIn.get(1, 0);
            rMatrixOut.Line2.Column2 = rMatrixIn.get(1, 1);
            rMatrixOut.Line2.Column3 = rMatrixIn.get(1, 2);
            rMatrixOut.Line2.Column4 = rMatrixIn.get(1, 3);
            rMatrixOut.Line3.Column1 = rMatrixIn.get(2, 0);
            rMatrixOut.Line3.Column2 = rMatrixIn.get(2, 1);
            rMatrixOut.Line3.Column3 = rMatrixIn.get(2, 2);
            rMatrixOut.Line3.Column4 = rMatrixIn.get(2, 3);
            rMatrixOut.Line4.Column1 = rMatrixIn.get(3, 0);
            rMatrixOut.Line4.Column2 = rMatrixIn.get(3, 1);
            rMatrixOut.Line4.Column3 = rMatrixIn.get(3, 2);
            rMatrixOut.Line4.Column4 = rMatrixIn.get(3, 3);
        }

    } // end of namespace tools
} // end of namespace basegfx

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/source/numeric/ftools.cxx b/basegfx/source/numeric/ftools.cxx
index d1eca66..994bd29 100644
--- a/basegfx/source/numeric/ftools.cxx
+++ b/basegfx/source/numeric/ftools.cxx
@@ -45,59 +45,6 @@ namespace basegfx
        }
    }

    double snapToZeroRange(double v, double fWidth)
    {
        if(fTools::equalZero(fWidth))
        {
            // with no range all snaps to range bound
            return 0.0;
        }
        else
        {
            if(v < 0.0 || v > fWidth)
            {
                double fRetval(fmod(v, fWidth));

                if(fRetval < 0.0)
                {
                    fRetval += fWidth;
                }

                return fRetval;
            }
            else
            {
                return v;
            }
        }
    }

    double snapToRange(double v, double fLow, double fHigh)
    {
        if(fTools::equal(fLow, fHigh))
        {
            // with no range all snaps to range bound
            return 0.0;
        }
        else
        {
            if(fLow > fHigh)
            {
                // correct range order. Evtl. assert this (?)
                std::swap(fLow, fHigh);
            }

            if(v < fLow || v > fHigh)
            {
                return snapToZeroRange(v - fLow, fHigh - fLow) + fLow;
            }
            else
            {
                return v;
            }
        }
    }

    double normalizeToRange(double v, const double fRange)
    {
        if(fTools::lessOrEqual(fRange, 0.0))
diff --git a/basegfx/source/range/b2drange.cxx b/basegfx/source/range/b2drange.cxx
index 331c543..2f4a3e0 100644
--- a/basegfx/source/range/b2drange.cxx
+++ b/basegfx/source/range/b2drange.cxx
@@ -51,19 +51,6 @@ namespace basegfx
        }
    }

    B2DRange& B2DRange::operator*=( const ::basegfx::B2DHomMatrix& rMat )
    {
        transform(rMat);
        return *this;
    }

    const B2DRange& B2DRange::getUnitB2DRange()
    {
        static const B2DRange aUnitB2DRange(0.0, 0.0, 1.0, 1.0);

        return aUnitB2DRange;
    }

    B2IRange fround(const B2DRange& rRange)
    {
        return rRange.isEmpty() ?
@@ -71,13 +58,6 @@ namespace basegfx
            B2IRange(fround(rRange.getMinimum()),
                     fround(rRange.getMaximum()));
    }

    B2DRange operator*( const ::basegfx::B2DHomMatrix& rMat, const B2DRange& rB2DRange )
    {
        B2DRange aRes( rB2DRange );
        return aRes *= rMat;
    }

} // end of namespace basegfx

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/source/range/b3drange.cxx b/basegfx/source/range/b3drange.cxx
index 879dbb0..f779f18 100644
--- a/basegfx/source/range/b3drange.cxx
+++ b/basegfx/source/range/b3drange.cxx
@@ -40,25 +40,6 @@ namespace basegfx
        }
    }

    B3DRange& B3DRange::operator*=( const ::basegfx::B3DHomMatrix& rMat )
    {
        transform(rMat);
        return *this;
    }

    const B3DRange& B3DRange::getUnitB3DRange()
    {
        static const B3DRange aUnitB3DRange(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);

        return aUnitB3DRange;
    }

    B3DRange operator*( const ::basegfx::B3DHomMatrix& rMat, const B3DRange& rB3DRange )
    {
        B3DRange aRes( rB3DRange );
        return aRes *= rMat;
    }

} // end of namespace basegfx

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
index b86980f..5efd976 100644
--- a/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
+++ b/chart2/source/controller/drawinglayer/DrawViewWrapper.cxx
@@ -96,13 +96,11 @@ OutputDevice * lcl_GetParentRefDevice( const uno::Reference< frame::XModel > & x

}

DrawViewWrapper::DrawViewWrapper(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   E3dView(rSdrModel, pOut)
    ,m_pMarkHandleProvider(nullptr)
    ,m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, rSdrModel))
    ,m_bRestoreMapMode( false )
DrawViewWrapper::DrawViewWrapper( SdrModel* pSdrModel, OutputDevice* pOut)
            : E3dView(pSdrModel, pOut)
            , m_pMarkHandleProvider(nullptr)
            , m_apOutliner(SdrMakeOutliner(OutlinerMode::TextObject, *pSdrModel))
            , m_bRestoreMapMode( false )
{
    SetBufferedOutputAllowed(true);
    SetBufferedOverlayAllowed(true);
diff --git a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
index 500488a..954426f 100644
--- a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
+++ b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
@@ -161,7 +161,7 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co
    SdrPage* pPage = new SdrPage( *pModel, false );
    pPage->SetSize(Size(1000,1000));
    pModel->InsertPage( pPage, 0 );
    std::unique_ptr<SdrView> pView( new SdrView( *pModel.get(), pVDev ) );
    std::unique_ptr<SdrView> pView( new SdrView( pModel.get(), pVDev ) );
    pView->hideMarkHandles();
    SdrPageView* pPageView = pView->ShowSdrPage(pPage);

diff --git a/chart2/source/controller/inc/DrawViewWrapper.hxx b/chart2/source/controller/inc/DrawViewWrapper.hxx
index 2adf512..91ffdf7 100644
--- a/chart2/source/controller/inc/DrawViewWrapper.hxx
+++ b/chart2/source/controller/inc/DrawViewWrapper.hxx
@@ -46,10 +46,7 @@ protected:
class DrawViewWrapper : public E3dView
{
public:
    DrawViewWrapper(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    DrawViewWrapper(SdrModel* pModel, OutputDevice* pOut);
    virtual ~DrawViewWrapper() override;

    //triggers the use of an updated first page
diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx
index 02c444d..139f172 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -727,7 +727,7 @@ void ChartController::impl_createDrawViewController()
    {
        if( m_pDrawModelWrapper )
        {
            m_pDrawViewWrapper = new DrawViewWrapper(m_pDrawModelWrapper->getSdrModel(),GetChartWindow());
            m_pDrawViewWrapper = new DrawViewWrapper(&m_pDrawModelWrapper->getSdrModel(),GetChartWindow());
            m_pDrawViewWrapper->attachParentReferenceDevice( getModel() );
        }
    }
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 00abbf6..d065244 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -395,12 +395,11 @@ void ChartController::impl_PasteShapes( SdrModel* pModel )
                SdrObjListIter aIter( *pPage, SdrIterMode::DeepNoGroups );
                while ( aIter.IsMore() )
                {
                    SdrObject* pObj(aIter.Next());
                    // Clone to new SdrModel
                    SdrObject* pNewObj(pObj ? pObj->Clone(&pDrawModelWrapper->getSdrModel()) : nullptr);

                    SdrObject* pObj = aIter.Next();
                    SdrObject* pNewObj = ( pObj ? pObj->Clone() : nullptr );
                    if ( pNewObj )
                    {
                        pNewObj->SetModel( &pDrawModelWrapper->getSdrModel() );
                        pNewObj->SetPage( pDestPage );

                        // set position
@@ -517,9 +516,7 @@ void ChartController::executeDispatch_Copy()
                    if ( pSelectedObj )
                    {
                        xTransferable.set( new ChartTransferable(
                                m_pDrawModelWrapper->getSdrModel(),
                                pSelectedObj,
                                aSelOID.isAdditionalShape() ) );
                                &m_pDrawModelWrapper->getSdrModel(), pSelectedObj, aSelOID.isAdditionalShape() ) );
                    }
                }
            }
diff --git a/chart2/source/controller/main/ChartTransferable.cxx b/chart2/source/controller/main/ChartTransferable.cxx
index 4888c480..2eeb46a 100644
--- a/chart2/source/controller/main/ChartTransferable.cxx
+++ b/chart2/source/controller/main/ChartTransferable.cxx
@@ -46,15 +46,12 @@ using ::com::sun::star::uno::Reference;
namespace chart
{

ChartTransferable::ChartTransferable(
    SdrModel& rSdrModel,
    SdrObject* pSelectedObj,
    bool bDrawing)
:   m_pMarkedObjModel( nullptr )
ChartTransferable::ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing )
    :m_pMarkedObjModel( nullptr )
    ,m_bDrawing( bDrawing )
{
    std::unique_ptr<SdrExchangeView> pExchgView(o3tl::make_unique<SdrView>( rSdrModel ));
    SdrPageView* pPv = pExchgView->ShowSdrPage( rSdrModel.GetPage( 0 ));
    std::unique_ptr<SdrExchangeView> pExchgView(o3tl::make_unique<SdrView>( pDrawModel ));
    SdrPageView* pPv = pExchgView->ShowSdrPage( pDrawModel->GetPage( 0 ));
    if( pSelectedObj )
        pExchgView->MarkObj( pSelectedObj, pPv );
    else
diff --git a/chart2/source/controller/main/ChartTransferable.hxx b/chart2/source/controller/main/ChartTransferable.hxx
index 6fc8b4c..35e4f5d 100644
--- a/chart2/source/controller/main/ChartTransferable.hxx
+++ b/chart2/source/controller/main/ChartTransferable.hxx
@@ -36,19 +36,16 @@ namespace chart
class ChartTransferable : public TransferableHelper
{
public:
    explicit ChartTransferable(
        SdrModel& rSdrModel,
        SdrObject* pSelectedObj,
        bool bDrawing );
    explicit ChartTransferable( SdrModel* pDrawModel, SdrObject* pSelectedObj, bool bDrawing );
    virtual ~ChartTransferable() override;

protected:

    // implementation of TransferableHelper methods
    virtual void AddSupportedFormats() override;
    virtual void        AddSupportedFormats() override;
    virtual bool GetData( const css::datatransfer::DataFlavor& rFlavor, const OUString& rDestDoc ) override;
    virtual bool WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
        const css::datatransfer::DataFlavor& rFlavor ) override;
    virtual bool        WriteObject( tools::SvRef<SotStorageStream>& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId,
                                        const css::datatransfer::DataFlavor& rFlavor ) override;

private:
    css::uno::Reference< css::graphic::XGraphic > m_xMetaFileGraphic;
diff --git a/chart2/source/controller/main/DrawCommandDispatch.cxx b/chart2/source/controller/main/DrawCommandDispatch.cxx
index 6c59620..7e31864 100644
--- a/chart2/source/controller/main/DrawCommandDispatch.cxx
+++ b/chart2/source/controller/main/DrawCommandDispatch.cxx
@@ -74,7 +74,7 @@ bool DrawCommandDispatch::isFeatureSupported( const OUString& rCommandURL )
    return parseCommandURL( rCommandURL, &nFeatureId, &aBaseCommand, &aCustomShapeType );
}

::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, SdrModel const & rModel)
{
    ::basegfx::B2DPolyPolygon aReturn;
    XLineEndListRef pLineEndList = rModel.GetLineEndList();
@@ -123,7 +123,7 @@ void DrawCommandDispatch::setAttributes( SdrObject* pObj )
                                {
                                    const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                                    SfxItemSet aDest(
                                        pObj->getSdrModelFromSdrObject().GetItemPool(),
                                        pObj->GetModel()->GetItemPool(),
                                        svl::Items<
                                            // Ranges from SdrAttrObj:
                                            SDRATTR_START, SDRATTR_SHADOW_LAST,
@@ -425,13 +425,8 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID )
        if ( pPage )
        {
            SolarMutexGuard aGuard;

            pObj = SdrObjFactory::MakeNewObject(
                pDrawModelWrapper->getSdrModel(),
                pDrawViewWrapper->GetCurrentObjInventor(),
                pDrawViewWrapper->GetCurrentObjIdentifier(),
                pPage);

            pObj = SdrObjFactory::MakeNewObject( pDrawViewWrapper->GetCurrentObjInventor(),
                pDrawViewWrapper->GetCurrentObjIdentifier(), pPage );
            if ( pObj )
            {
                Size aObjectSize( 4000, 2500 );
diff --git a/chart2/source/view/diagram/VDiagram.cxx b/chart2/source/view/diagram/VDiagram.cxx
index 897bbe3..4c5bac5 100644
--- a/chart2/source/view/diagram/VDiagram.cxx
+++ b/chart2/source/view/diagram/VDiagram.cxx
@@ -436,7 +436,7 @@ void VDiagram::adjustAspectRatio3d( const awt::Size& rAvailableSize )
            // To get the 3D aspect ratio's effect on the 2D scene size, the scene's 2D size needs to be adapted to
            // 3D content changes here. The tooling class remembers the current 3D transformation stack
            // and in its destructor, calculates a new 2D SnapRect for the scene and it's modified 3D geometry.
            E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene(m_xOuterGroupShape));
            E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene( m_xOuterGroupShape ));

            m_xAspectRatio3D->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX
                , uno::Any(BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aResult )) );
@@ -599,8 +599,7 @@ void VDiagram::createShapes_3d()
                aEffectiveTranformation.shearXY(m_fYAnglePi,-m_fXAnglePi);

            //#i98497# 3D charts are rendered with wrong size
            E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene(m_xOuterGroupShape));

            E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene( m_xOuterGroupShape ));
            xDestProp->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX,
                    uno::Any( BaseGFXHelper::B3DHomMatrixToHomogenMatrix( aEffectiveTranformation ) ) );
        }
@@ -657,8 +656,7 @@ void VDiagram::createShapes_3d()
                ::basegfx::B3DHomMatrix aM;
                aM.translate(GRID_TO_WALL_DISTANCE/fXScale, GRID_TO_WALL_DISTANCE/fYScale, GRID_TO_WALL_DISTANCE/fZScale);
                aM.scale( fXScale, fYScale, fZScale );
                E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene(m_xOuterGroupShape));

                E3DModifySceneSnapRectUpdater aUpdater(lcl_getE3dScene( m_xOuterGroupShape ));
                xShapeProp->setPropertyValue( UNO_NAME_3D_TRANSFORM_MATRIX
                    , uno::Any(BaseGFXHelper::B3DHomMatrixToHomogenMatrix(aM)) );
            }
diff --git a/cui/source/dialogs/sdrcelldlg.cxx b/cui/source/dialogs/sdrcelldlg.cxx
index a7de7c1..7789ddd 100644
--- a/cui/source/dialogs/sdrcelldlg.cxx
+++ b/cui/source/dialogs/sdrcelldlg.cxx
@@ -26,14 +26,14 @@
#include <border.hxx>
#include <svx/dialogs.hrc>

SvxFormatCellsDialog::SvxFormatCellsDialog( vcl::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel )
SvxFormatCellsDialog::SvxFormatCellsDialog( vcl::Window* pParent, const SfxItemSet* pAttr, SdrModel const * pModel )
    : SfxTabDialog(pParent, "FormatCellsDialog", "cui/ui/formatcellsdialog.ui", pAttr)
    , mrOutAttrs(*pAttr)
    , mpColorTab(rModel.GetColorList())
    , mpGradientList(rModel.GetGradientList())
    , mpHatchingList(rModel.GetHatchList())
    , mpBitmapList(rModel.GetBitmapList())
    , mpPatternList(rModel.GetPatternList())
    , mpColorTab(pModel->GetColorList())
    , mpGradientList(pModel->GetGradientList())
    , mpHatchingList(pModel->GetHatchList())
    , mpBitmapList(pModel->GetBitmapList())
    , mpPatternList(pModel->GetPatternList())
    , m_nAreaPageId(0)
{
    AddTabPage("name", RID_SVXPAGE_CHAR_NAME);
diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx
index 51c7d5a..8a8647b 100644
--- a/cui/source/factory/dlgfact.cxx
+++ b/cui/source/factory/dlgfact.cxx
@@ -1524,9 +1524,9 @@ VclPtr<SfxAbstractLinksDialog> AbstractDialogFactory_Impl::CreateLinksDialog( vc
    return VclPtr<AbstractLinksDialog_Impl>::Create( pLinkDlg );
}

VclPtr<SfxAbstractTabDialog> AbstractDialogFactory_Impl::CreateSvxFormatCellsDialog( const SfxItemSet* pAttr, const SdrModel& rModel, const SdrObject* /*pObj*/ )
VclPtr<SfxAbstractTabDialog> AbstractDialogFactory_Impl::CreateSvxFormatCellsDialog( const SfxItemSet* pAttr, SdrModel* pModel, const SdrObject* /*pObj*/ )
{
    return VclPtr<CuiAbstractTabDialog_Impl>::Create( VclPtr<SvxFormatCellsDialog>::Create( nullptr, pAttr, rModel ) );
    return VclPtr<CuiAbstractTabDialog_Impl>::Create( VclPtr<SvxFormatCellsDialog>::Create( nullptr, pAttr, pModel ) );
}

VclPtr<SvxAbstractSplitTableDialog> AbstractDialogFactory_Impl::CreateSvxSplitTableDialog(weld::Window* pParent, bool bIsTableVertical, long nMaxVertical)
diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx
index e9ea89b..ae87ab2 100644
--- a/cui/source/factory/dlgfact.hxx
+++ b/cui/source/factory/dlgfact.hxx
@@ -690,7 +690,7 @@ public:
                const sal_uInt16 _nInitiallySelectedEvent
            ) override;

    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog( const SfxItemSet* pAttr, const SdrModel& rModel, const SdrObject* pObj ) override;
    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog( const SfxItemSet* pAttr, SdrModel* pModel, const SdrObject* pObj ) override;

    virtual VclPtr<SvxAbstractSplitTableDialog> CreateSvxSplitTableDialog(weld::Window* pParent, bool bIsTableVertical, long nMaxVertical) override;

diff --git a/cui/source/inc/sdrcelldlg.hxx b/cui/source/inc/sdrcelldlg.hxx
index 0a38f75..97a2abe 100644
--- a/cui/source/inc/sdrcelldlg.hxx
+++ b/cui/source/inc/sdrcelldlg.hxx
@@ -40,7 +40,7 @@ private:
    sal_uInt16          m_nBorderPageId;

public:
    SvxFormatCellsDialog( vcl::Window* pParent, const SfxItemSet* pAttr, const SdrModel& rModel );
    SvxFormatCellsDialog( vcl::Window* pParent, const SfxItemSet* pAttr, SdrModel const * pModel );

    virtual void PageCreated( sal_uInt16 nId, SfxTabPage &rPage ) override;

diff --git a/cui/source/tabpages/measure.cxx b/cui/source/tabpages/measure.cxx
index 58ae066..adfb0ec 100644
--- a/cui/source/tabpages/measure.cxx
+++ b/cui/source/tabpages/measure.cxx
@@ -598,14 +598,7 @@ void SvxMeasurePage::Construct()
{
    DBG_ASSERT( pView, "No valid View transferred!" );

    // TTTT
    // pMeasureObj is member of SvxXMeasurePreview and can only be accessed due to
    // SvxMeasurePage being a friend. It has it's own SdrModel (also in SvxXMeasurePreview)
    // and 'setting' the SdrModel is a hack. The comment above about 'notify unit and
    // floatingpoint-values' is not clear, but has to be done another way - if needed.
    // Checked on original aw080, is just commented out there, too.

    // m_pCtlPreview->pMeasureObj->SetModel( pView->GetModel() );
    m_pCtlPreview->pMeasureObj->SetModel( pView->GetModel() );
    m_pCtlPreview->Invalidate();
}

diff --git a/cui/source/tabpages/tpline.cxx b/cui/source/tabpages/tpline.cxx
index 145a304..85f2d85 100644
--- a/cui/source/tabpages/tpline.cxx
+++ b/cui/source/tabpages/tpline.cxx
@@ -349,7 +349,7 @@ void SvxLineTabPage::InitSymbols(MenuButton const * pButton)
        pModel->InsertPage( pPage, 0 );
        {
        // 3D View
        std::unique_ptr<SdrView> pView(new SdrView( *pModel, pVDev ));
        std::unique_ptr<SdrView> pView(new SdrView( pModel.get(), pVDev ));
        pView->hideMarkHandles();
        pView->ShowSdrPage(pPage);

@@ -1119,7 +1119,7 @@ void SvxLineTabPage::Reset( const SfxItemSet* rAttrs )
        pPage->SetSize(Size(1000,1000));
        pModel->InsertPage( pPage, 0 );
        {
        std::unique_ptr<SdrView> pView(new SdrView( *pModel, pVDev ));
        std::unique_ptr<SdrView> pView(new SdrView( pModel.get(), pVDev ));
        pView->hideMarkHandles();
        pView->ShowSdrPage(pPage);
        SdrObject *pObj=nullptr;
diff --git a/cui/source/tabpages/transfrm.cxx b/cui/source/tabpages/transfrm.cxx
index ee3f76b..2269470 100644
--- a/cui/source/tabpages/transfrm.cxx
+++ b/cui/source/tabpages/transfrm.cxx
@@ -566,15 +566,15 @@ bool SvxSlantTabPage::FillItemSet(SfxItemSet* rAttrs)
        SdrObjCustomShape& rSdrObjCustomShape(
            static_cast< SdrObjCustomShape& >(
                *pView->GetMarkedObjectList().GetMark(0)->GetMarkedSdrObj()));
        SdrModel& rModel(rSdrObjCustomShape.getSdrModelFromSdrObject());
        SdrModel* pModel(rSdrObjCustomShape.GetModel());
        SdrUndoAction* pUndo(
            rModel.IsUndoEnabled()
                ? rModel.GetSdrUndoFactory().CreateUndoAttrObject(rSdrObjCustomShape)
            pModel->IsUndoEnabled()
                ? pModel->GetSdrUndoFactory().CreateUndoAttrObject(rSdrObjCustomShape)
                : nullptr);

        if(pUndo)
        {
            rModel.BegUndo(pUndo->GetComment());
            pModel->BegUndo(pUndo->GetComment());
        }

        EnhancedCustomShape2d aShape(rSdrObjCustomShape);
@@ -602,8 +602,8 @@ bool SvxSlantTabPage::FillItemSet(SfxItemSet* rAttrs)

        if (pUndo)
        {
            rModel.AddUndo(pUndo);
            rModel.EndUndo();
            pModel->AddUndo(pUndo);
            pModel->EndUndo();
        }
    }

diff --git a/filter/source/msfilter/escherex.cxx b/filter/source/msfilter/escherex.cxx
index 3b3fc05..0eb9efe 100644
--- a/filter/source/msfilter/escherex.cxx
+++ b/filter/source/msfilter/escherex.cxx
@@ -3774,9 +3774,10 @@ bool EscherPropertyContainer::CreateBlipPropertiesforOLEControl(const uno::Refer
    SdrObject* pShape = GetSdrObjectFromXShape( rXShape );
    if ( pShape )
    {
        const Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pShape));
        const GraphicObject aGraphicObject(aGraphic);
        SdrModel* pMod = pShape->GetModel();
        Graphic aGraphic(SdrExchangeView::GetObjGraphic( pMod, pShape));

        GraphicObject aGraphicObject(aGraphic);
        if (!aGraphicObject.GetUniqueID().isEmpty())
        {
            if ( pGraphicProvider && pPicOutStrm && pShapeBoundRect )
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index e958c81..ac281e0 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -3955,7 +3955,7 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons
        }
        if( !pRet )
        {
            pRet = new SdrGrafObj(*pSdrModel);
            pRet = new SdrGrafObj;
            if( bGrfRead )
                static_cast<SdrGrafObj*>(pRet)->SetGraphic( aGraf );

@@ -3997,6 +3997,7 @@ SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, cons
                pRet->SetName( aFileName );
        }
    }
    pRet->SetModel( pSdrModel ); // required for GraphicLink
    pRet->SetLogicRect( rObjData.aBoundRect );

    if ( dynamic_cast<const SdrGrafObj* >(pRet) !=  nullptr )
@@ -4306,7 +4307,7 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r

        if ( aObjData.nSpFlags & ShapeFlag::Group )
        {
            pRet = new SdrObjGroup(*pSdrModel);
            pRet = new SdrObjGroup;
            /*  After CWS aw033 has been integrated, an empty group object
                cannot store its resulting bounding rectangle anymore. We have
                to return this rectangle via rClientRect now, but only, if
@@ -4336,10 +4337,8 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
                basegfx::B2DPolygon aPoly;
                aPoly.append(basegfx::B2DPoint(aObjData.aBoundRect.Left(), aObjData.aBoundRect.Top()));
                aPoly.append(basegfx::B2DPoint(aObjData.aBoundRect.Right(), aObjData.aBoundRect.Bottom()));
                pRet = new SdrPathObj(
                    *pSdrModel,
                    OBJ_LINE,
                    basegfx::B2DPolyPolygon(aPoly));
                pRet = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
                pRet->SetModel( pSdrModel );
                ApplyAttributes( rSt, aSet, aObjData );
                pRet->SetMergedItemSet(aSet);
            }
@@ -4350,7 +4349,8 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r

                    ApplyAttributes( rSt, aSet, aObjData );

                    pRet = new SdrObjCustomShape(*pSdrModel);
                    pRet = new SdrObjCustomShape();
                    pRet->SetModel( pSdrModel );

                    sal_uInt32 ngtextFStrikethrough = GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 );
                    bool bIsFontwork = ( ngtextFStrikethrough & 0x4000 ) != 0;
@@ -4471,7 +4471,9 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
                        {
                            SdrOutliner& rOutliner = static_cast<SdrObjCustomShape*>(pRet)->ImpGetDrawOutliner();
                            bool bOldUpdateMode = rOutliner.GetUpdateMode();
                            rOutliner.SetStyleSheetPool(static_cast< SfxStyleSheetPool* >(pRet->getSdrModelFromSdrObject().GetStyleSheetPool()));
                            SdrModel* pModel = pRet->GetModel();
                            if ( pModel )
                                rOutliner.SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(pModel->GetStyleSheetPool()) );
                            rOutliner.SetUpdateMode( false );
                            rOutliner.SetText( *pParaObj );
                            ScopedVclPtrInstance< VirtualDevice > pVirDev(DeviceFormat::BITMASK);
@@ -4733,7 +4735,7 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
                        basegfx::B2DPolyPolygon aPoly( static_cast<SdrObjCustomShape*>(pRet)->GetLineGeometry( true ) );
                        SdrObject::Free( pRet );

                        pRet = new SdrEdgeObj(*pSdrModel);
                        pRet = new SdrEdgeObj();
                        ApplyAttributes( rSt, aSet, aObjData );
                        pRet->SetLogicRect( aObjData.aBoundRect );
                        pRet->SetMergedItemSet(aSet);
@@ -5233,10 +5235,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
                }
            }

            pTextObj = new SdrRectObj(
                *pSdrModel,
                OBJ_TEXT,
                rTextRect);
            pTextObj = new SdrRectObj(OBJ_TEXT, rTextRect);
            pTextImpRec = new SvxMSDffImportRec(*pImpRec);
            bDeleteTextImpRec = true;

@@ -5365,6 +5364,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
            }

            pTextObj->SetMergedItemSet(aSet);
            pTextObj->SetModel(pSdrModel);

            if (bVerticalText)
                pTextObj->SetVerticalWriting(true);
@@ -5397,7 +5397,7 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
            {
                if( pTextObj != pObj )
                {
                    SdrObject* pGroup = new SdrObjGroup(*pSdrModel);
                    SdrObject* pGroup = new SdrObjGroup;
                    pGroup->GetSubList()->NbcInsertObject( pObj );
                    pGroup->GetSubList()->NbcInsertObject( pTextObj );
                    if (pOrgObj == pObj)
@@ -5413,11 +5413,9 @@ SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
            // simple rectangular objects are ignored by ImportObj()  :-(
            // this is OK for Draw but not for Calc and Writer
            // cause here these objects have a default border
            pObj = new SdrRectObj(
                *pSdrModel,
                rTextRect);

            pObj = new SdrRectObj(rTextRect);
            pOrgObj = pObj;
            pObj->SetModel( pSdrModel );
            SfxItemSet aSet( pSdrModel->GetItemPool() );
            ApplyAttributes( rSt, aSet, rObjData );

@@ -6617,19 +6615,9 @@ SdrObject* SvxMSDffManager::ImportOLE( sal_uInt32 nOLEId,
    ErrCode nError = ERRCODE_NONE;
    uno::Reference < embed::XStorage > xDstStg;
    if( GetOLEStorageName( nOLEId, sStorageName, xSrcStg, xDstStg ))
        pRet = CreateSdrOLEFromStorage(
            *GetModel(),
            sStorageName,
            xSrcStg,
            xDstStg,
            rGrf,
            rBoundRect,
            rVisArea,
            pStData,
            nError,
            nSvxMSDffOLEConvFlags,
            embed::Aspects::MSOLE_CONTENT,
            maBaseURL);
        pRet = CreateSdrOLEFromStorage( sStorageName, xSrcStg, xDstStg,
                                        rGrf, rBoundRect, rVisArea, pStData, nError,
                                        nSvxMSDffOLEConvFlags, embed::Aspects::MSOLE_CONTENT, maBaseURL);
    return pRet;
}

@@ -7118,18 +7106,17 @@ css::uno::Reference < css::embed::XEmbeddedObject >  SvxMSDffManager::CheckForCo

// TODO/MBA: code review and testing!
SdrOle2Obj* SvxMSDffManager::CreateSdrOLEFromStorage(
    SdrModel& rSdrModel,
    const OUString& rStorageName,
    tools::SvRef<SotStorage> const & rSrcStorage,
    const uno::Reference < embed::XStorage >& xDestStorage,
    const Graphic& rGrf,
    const tools::Rectangle& rBoundRect,
    const tools::Rectangle& rVisArea,
    SvStream* pDataStrm,
    ErrCode& rError,
    sal_uInt32 nConvertFlags,
    sal_Int64 nRecommendedAspect,
    OUString const& rBaseURL)
                const OUString& rStorageName,
                tools::SvRef<SotStorage> const & rSrcStorage,
                const uno::Reference < embed::XStorage >& xDestStorage,
                const Graphic& rGrf,
                const tools::Rectangle& rBoundRect,
                const tools::Rectangle& rVisArea,
                SvStream* pDataStrm,
                ErrCode& rError,
                sal_uInt32 nConvertFlags,
                sal_Int64 nRecommendedAspect,
                OUString const& rBaseURL)
{
    sal_Int64 nAspect = nRecommendedAspect;
    SdrOle2Obj* pRet = nullptr;
@@ -7197,12 +7184,7 @@ SdrOle2Obj* SvxMSDffManager::CreateSdrOLEFromStorage(
                        aObj.SetGraphic( rGrf, OUString() );

                        // TODO/MBA: check setting of PersistName
                        pRet = new SdrOle2Obj(
                            rSdrModel,
                            aObj,
                            OUString(),
                            rBoundRect);

                        pRet = new SdrOle2Obj( aObj, OUString(), rBoundRect);
                        // we have the Object, don't create another
                        bValidStorage = false;
                    }
@@ -7298,11 +7280,7 @@ SdrOle2Obj* SvxMSDffManager::CreateSdrOLEFromStorage(
                // TODO/LATER: need MediaType
                aObj.SetGraphic( rGrf, OUString() );

                pRet = new SdrOle2Obj(
                    rSdrModel,
                    aObj,
                    aDstStgName,
                    rBoundRect);
                pRet = new SdrOle2Obj( aObj, aDstStgName, rBoundRect);
            }
        }
    }
diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx
index 5758ca6..22d21cb 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -807,10 +807,7 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi

            // replacing the object which we will return with a SdrPageObj
            SdrObject::Free( pRet );
            pRet = new SdrPageObj(
                *pSdrModel,
                rObjData.aBoundRect,
                pSdrModel->GetPage(nPageNum - 1));
            pRet = new SdrPageObj( rObjData.aBoundRect, pSdrModel->GetPage( nPageNum - 1 ) );
        }
        else
        {
@@ -1072,9 +1069,8 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi
                        SdrObject::Free( pRet );
                        pRet = nullptr;
                    }
                    pTObj = new SdrRectObj(
                        *pSdrModel,
                        eTextKind != OBJ_RECT ? eTextKind : OBJ_TEXT);
                    pTObj = new SdrRectObj( eTextKind != OBJ_RECT ? eTextKind : OBJ_TEXT );
                    pTObj->SetModel( pSdrModel );
                    SfxItemSet aSet( pSdrModel->GetItemPool() );
                    if ( !pRet )
                        ApplyAttributes( rSt, aSet, rObjData );
@@ -1201,7 +1197,7 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi
                    }
                    if ( pRet )
                    {
                        SdrObject* pGroup = new SdrObjGroup(*pSdrModel);
                        SdrObject* pGroup = new SdrObjGroup;
                        pGroup->GetSubList()->NbcInsertObject( pRet );
                        pGroup->GetSubList()->NbcInsertObject( pTObj );
                        pRet = pGroup;
@@ -1884,11 +1880,7 @@ SdrObject* SdrPowerPointImport::ImportOLE( sal_uInt32 nOLEId,

                                        // TODO/LATER: need MediaType for Graphic
                                        aObj.SetGraphic( rGraf, OUString() );
                                        pRet = new SdrOle2Obj(
                                            *pSdrModel,
                                            aObj,
                                            aNm,
                                            rBoundRect);
                                        pRet = new SdrOle2Obj( aObj, aNm, rBoundRect );
                                    }
                                }
                                if ( !pRet && ( rOe.nType == PPT_PST_ExControl ) )
@@ -1951,11 +1943,7 @@ SdrObject* SdrPowerPointImport::ImportOLE( sal_uInt32 nOLEId,
                                        // TODO/LATER: need MediaType for Graphic
                                        aObj.SetGraphic( aGraphic, OUString() );

                                        pRet = new SdrOle2Obj(
                                            *pSdrModel,
                                            aObj,
                                            aNm,
                                            rBoundRect);
                                        pRet = new SdrOle2Obj( aObj, aNm, rBoundRect );
                                    }
                                }
                            }
@@ -3074,17 +3062,12 @@ SdrObject* SdrPowerPointImport::ImportPageBackgroundObject( const SdrPage& rPage
        pSet->Put( XFillStyleItem( drawing::FillStyle_NONE ) );
    }
    pSet->Put( XLineStyleItem( drawing::LineStyle_NONE ) );
    tools::Rectangle aRect(
        rPage.GetLeftBorder(),
        rPage.GetUpperBorder(),
        rPage.GetWidth() - rPage.GetRightBorder(),
        rPage.GetHeight() - rPage.GetLowerBorder());

    pRet = new SdrRectObj(
        *pSdrModel,
        aRect);
    tools::Rectangle aRect( rPage.GetLeftBorder(), rPage.GetUpperBorder(), rPage.GetWidth()-rPage.GetRightBorder(), rPage.GetHeight()-rPage.GetLowerBorder() );
    pRet = new SdrRectObj( aRect );
    pRet->SetModel( pSdrModel );

    pRet->SetMergedItemSet(*pSet);

    pRet->SetMarkProtect( true );
    pRet->SetMoveProtect( true );
    pRet->SetResizeProtect( true );
@@ -7589,7 +7572,7 @@ SdrObject* SdrPowerPointImport::CreateTable( SdrObject* pGroup, const sal_uInt32
    if (aRows.empty())
        return pRet;

    sdr::table::SdrTableObj* pTable = new sdr::table::SdrTableObj(*pSdrModel);
    sdr::table::SdrTableObj* pTable = new sdr::table::SdrTableObj( pSdrModel );
    pTable->uno_lock();
    Reference< XTable > xTable( pTable->getTable() );

diff --git a/filter/source/svg/svgexport.cxx b/filter/source/svg/svgexport.cxx
index 056c1c7..e923eb9 100644
--- a/filter/source/svg/svgexport.cxx
+++ b/filter/source/svg/svgexport.cxx
@@ -560,9 +560,9 @@ bool SVGFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
                        if( pSvxDrawPage )
                        {
                            mpDefaultSdrPage = pSvxDrawPage->GetSdrPage();
                            mpSdrModel = &mpDefaultSdrPage->getSdrModelFromSdrPage();
                            mpSdrModel = mpDefaultSdrPage->GetModel();

                            if( mpSdrModel ) // TTTT should be reference
                            if( mpSdrModel )
                            {
                                SdrOutliner& rOutl = mpSdrModel->GetDrawOutliner();

@@ -921,8 +921,8 @@ void SVGFilter::implGenerateMetaData()
        if( pSvxDrawPage )
        {
            SdrPage* pSdrPage = pSvxDrawPage->GetSdrPage();
            SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
            nPageNumberingType = rSdrModel.GetPageNumType();
            SdrModel* pSdrModel = pSdrPage->GetModel();
            nPageNumberingType = pSdrModel->GetPageNumType();

            // That is used by CalcFieldHdl method.
            mVisiblePagePropSet.nPageNumberingType = nPageNumberingType;
@@ -1384,8 +1384,8 @@ void SVGFilter::implGetPagePropSet( const Reference< css::drawing::XDrawPage > &
                if( pSvxDrawPage )
                {
                    SdrPage* pSdrPage = pSvxDrawPage->GetSdrPage();
                    SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
                    mVisiblePagePropSet.nPageNumberingType = rSdrModel.GetPageNumType();
                    SdrModel* pSdrModel = pSdrPage->GetModel();
                    mVisiblePagePropSet.nPageNumberingType = pSdrModel->GetPageNumType();
                }
            }
        }
@@ -1931,7 +1931,7 @@ bool SVGFilter::implCreateObjectsFromShape( const Reference< css::drawing::XDraw

        if( pObj )
        {
            const Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pObj));
            Graphic aGraphic( SdrExchangeView::GetObjGraphic( pObj->GetModel(), pObj ) );

            if( aGraphic.GetType() != GraphicType::NONE )
            {
diff --git a/include/basegfx/matrix/b2dhommatrix.hxx b/include/basegfx/matrix/b2dhommatrix.hxx
index 9f2c8a3..a7ab0c3 100644
--- a/include/basegfx/matrix/b2dhommatrix.hxx
+++ b/include/basegfx/matrix/b2dhommatrix.hxx
@@ -74,10 +74,8 @@ namespace basegfx
        void rotate(double fRadiant);

        void translate(double fX, double fY);
        void translate(const B2DTuple& rTuple);

        void scale(double fX, double fY);
        void scale(const B2DTuple& rTuple);

        // Shearing-Matrices
        void shearX(double fSx);
diff --git a/include/basegfx/matrix/b3dhommatrix.hxx b/include/basegfx/matrix/b3dhommatrix.hxx
index 6d5d5c4..09d7005 100644
--- a/include/basegfx/matrix/b3dhommatrix.hxx
+++ b/include/basegfx/matrix/b3dhommatrix.hxx
@@ -64,15 +64,12 @@ namespace basegfx

        /// Rotation
        void rotate(double fAngleX,double fAngleY,double fAngleZ);
        void rotate(const B3DTuple& rRotation);

        /// Translation
        void translate(double fX, double fY, double fZ);
        void translate(const B3DTuple& rTranslation);

        /// Scaling
        void scale(double fX, double fY, double fZ);
        void scale(const B3DTuple& rScale);

        // Shearing-Matrices
        void shearXY(double fSx, double fSy);
diff --git a/include/basegfx/matrix/b3dhommatrixtools.hxx b/include/basegfx/matrix/b3dhommatrixtools.hxx
deleted file mode 100755
index 3c5e8e8..0000000
--- a/include/basegfx/matrix/b3dhommatrixtools.hxx
+++ /dev/null
@@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_BASEGFX_MATRIX_B3DHOMMATRIXTOOLS_HXX
#define INCLUDED_BASEGFX_MATRIX_B3DHOMMATRIXTOOLS_HXX

#include <sal/types.h>
#include <basegfx/matrix/b3dhommatrix.hxx>
#include <com/sun/star/drawing/HomogenMatrix.hpp>

namespace basegfx
{
    namespace utils
    {
        /* tooling methods for converting API matrices (drawing::HomogenMatrix) to
           B3DHomMatrix. drawing::HomogenMatrix4 is not used by OOo
         */
        BASEGFX_DLLPUBLIC B3DHomMatrix UnoHomogenMatrixToB3DHomMatrix(
            const com::sun::star::drawing::HomogenMatrix& rMatrixIn);

        BASEGFX_DLLPUBLIC void B3DHomMatrixToUnoHomogenMatrix(
            const B3DHomMatrix& rMatrixIn,
            com::sun::star::drawing::HomogenMatrix& rMatrixOut);

    } // end of namespace tools
} // end of namespace basegfx

#endif // INCLUDED_BASEGFX_MATRIX_B3DHOMMATRIXTOOLS_HXX

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/basegfx/numeric/ftools.hxx b/include/basegfx/numeric/ftools.hxx
index 1ade3bb..52909c9 100644
--- a/include/basegfx/numeric/ftools.hxx
+++ b/include/basegfx/numeric/ftools.hxx
@@ -153,25 +153,6 @@ namespace basegfx
     */
    BASEGFX_DLLPUBLIC double snapToNearestMultiple(double v, const double fStep);

    /** Snap v to the range [0.0 .. fWidth] using modulo
     */
    double snapToZeroRange(double v, double fWidth);

    /** Snap v to the range [fLow .. fHigh] using modulo
     */
    double snapToRange(double v, double fLow, double fHigh);

    /** return fValue with the sign of fSignCarrier, thus evtl. changed
    */
    inline double copySign(double fValue, double fSignCarrier)
    {
#ifdef WNT
        return _copysign(fValue, fSignCarrier);
#else
        return copysign(fValue, fSignCarrier);
#endif
    }

    /** RotateFlyFrame3: Normalize to range defined by [0.0 ... fRange[, independent
        if v is positive or negative.

diff --git a/include/basegfx/range/b1drange.hxx b/include/basegfx/range/b1drange.hxx
index 7b0d228..c1e35b1 100644
--- a/include/basegfx/range/b1drange.hxx
+++ b/include/basegfx/range/b1drange.hxx
@@ -141,11 +141,6 @@ namespace basegfx
            maRange.intersect(rRange.maRange);
        }

        /// clamp value on range
        double clamp(double fValue) const
        {
            return maRange.clamp(fValue);
        }
    };

} // end of namespace basegfx
diff --git a/include/basegfx/range/b2drange.hxx b/include/basegfx/range/b2drange.hxx
index 00eab63..0de9dba 100644
--- a/include/basegfx/range/b2drange.hxx
+++ b/include/basegfx/range/b2drange.hxx
@@ -274,29 +274,8 @@ namespace basegfx
            maRangeY.grow(fValue);
        }

        /// clamp value on range
        B2DTuple clamp(const B2DTuple& rTuple) const
        {
            return B2DTuple(
                maRangeX.clamp(rTuple.getX()),
                maRangeY.clamp(rTuple.getY()));
        }

        /** Transform Range by given transformation matrix. */
        BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix& rMatrix);

        /** Transform Range by given transformation matrix.

            This operation transforms the Range by transforming all four possible
            extrema points (corners) of the given range and building a new one.
            This means that the range will grow evtl. when a shear and/or rotation
            is part of the transformation.
        */
        B2DRange& operator*=( const ::basegfx::B2DHomMatrix& rMat );

        /** Get a range filled with (0.0, 0.0, 1.0, 1.0) */
        static const B2DRange& getUnitB2DRange();

    private:
        typedef ::basegfx::BasicRange< ValueType, TraitsType >  MyBasicRange;

@@ -304,10 +283,6 @@ namespace basegfx
        MyBasicRange        maRangeY;
    };

    /** Transform B2DRange by given transformation matrix (see operator*=())
    */
    B2DRange operator*( const B2DHomMatrix& rMat, const B2DRange& rB2DRange );

    /** Round double to nearest integer for 2D range

        @return the nearest integer for this range
diff --git a/include/basegfx/range/b2irange.hxx b/include/basegfx/range/b2irange.hxx
index a8a95d6..3d7d0ed 100644
--- a/include/basegfx/range/b2irange.hxx
+++ b/include/basegfx/range/b2irange.hxx
@@ -208,13 +208,6 @@ namespace basegfx
            maRangeY.intersect(rRange.maRangeY);
        }

        B2ITuple clamp(const B2ITuple& rTuple) const
        {
            return B2ITuple(
                maRangeX.clamp(rTuple.getX()),
                maRangeY.clamp(rTuple.getY()));
        }

    private:
        typedef ::basegfx::BasicRange< ValueType, TraitsType >  MyBasicRange;

diff --git a/include/basegfx/range/b3drange.hxx b/include/basegfx/range/b3drange.hxx
index e1c4439..881dce6 100644
--- a/include/basegfx/range/b3drange.hxx
+++ b/include/basegfx/range/b3drange.hxx
@@ -195,34 +195,9 @@ namespace basegfx
            maRangeZ.grow(fValue);
        }

        /// clamp value on range
        B3DTuple clamp(const B3DTuple& rTuple) const
        {
            return B3DTuple(
                maRangeX.clamp(rTuple.getX()),
                maRangeY.clamp(rTuple.getY()),
                maRangeZ.clamp(rTuple.getZ()));
        }

         BASEGFX_DLLPUBLIC void transform(const B3DHomMatrix& rMatrix);

        /** Transform Range by given transformation matrix.

            This operation transforms the Range by transforming all eight possible
            extrema points (corners) of the given range and building a new one.
            This means that the range will grow evtl. when a shear and/or rotation
            is part of the transformation.
        */
        B3DRange& operator*=( const ::basegfx::B3DHomMatrix& rMat );

        /** Get a range filled with (0.0, 0.0, 0.0, 1.0, 1.0, 1.0) */
        static const B3DRange& getUnitB3DRange();
    };

    /** Transform B3DRange by given transformation matrix (see operator*=())
    */
    B3DRange operator*( const B3DHomMatrix& rMat, const B3DRange& rB2DRange );

} // end of namespace basegfx


diff --git a/include/basegfx/range/basicrange.hxx b/include/basegfx/range/basicrange.hxx
index 17f31ea..bea40dd 100644
--- a/include/basegfx/range/basicrange.hxx
+++ b/include/basegfx/range/basicrange.hxx
@@ -248,28 +248,6 @@ namespace basegfx
            }
        }

        T clamp(T nValue) const
        {
            if(isEmpty())
            {
                return nValue;
            }
            else
            {
                if(nValue < mnMinimum)
                {
                    return mnMinimum;
                }

                if(nValue > mnMaximum)
                {
                    return mnMaximum;
                }

                return nValue;
            }
        }

        typename Traits::DifferenceType getRange() const
        {
            if(isEmpty())
diff --git a/include/filter/msfilter/msdffimp.hxx b/include/filter/msfilter/msdffimp.hxx
index fedce1b..ba8e689 100644
--- a/include/filter/msfilter/msdffimp.hxx
+++ b/include/filter/msfilter/msdffimp.hxx
@@ -697,19 +697,17 @@ public:

    void RemoveFromShapeOrder( SdrObject const * pObject ) const;

    static SdrOle2Obj* CreateSdrOLEFromStorage(
        SdrModel& rSdrModel,
        const OUString& rStorageName,
        tools::SvRef<SotStorage> const & rSrcStorage,
        const css::uno::Reference < css::embed::XStorage >& xDestStg,
        const Graphic& rGraf,
        const tools::Rectangle& rBoundRect,
        const tools::Rectangle& rVisArea,
        SvStream* pDataStrrm,
        ErrCode& rError,
        sal_uInt32 nConvertFlags,
        sal_Int64 nAspect,
        OUString const& rBaseURL);
    static SdrOle2Obj* CreateSdrOLEFromStorage( const OUString& rStorageName,
                                                tools::SvRef<SotStorage> const & rSrcStorage,
                                                const css::uno::Reference < css::embed::XStorage >& xDestStg,
                                                const Graphic& rGraf,
                                                const tools::Rectangle& rBoundRect,
                                                const tools::Rectangle& rVisArea,
                                                SvStream* pDataStrrm,
                                                ErrCode& rError,
                                                sal_uInt32 nConvertFlags,
                                                sal_Int64 nAspect,
                                                OUString const& rBaseURL);

    /** Create connections between shapes.
        This method should be called after a page is imported.
diff --git a/include/svx/connctrl.hxx b/include/svx/connctrl.hxx
index 106140d..360ff38 100644
--- a/include/svx/connctrl.hxx
+++ b/include/svx/connctrl.hxx
@@ -32,7 +32,7 @@ namespace vcl { class Window; }
class SfxItemSet;
class SdrEdgeObj;
class SdrView;
class SdrPage;
class SdrObjList;

/*************************************************************************
|*
@@ -45,7 +45,7 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxXConnectionPreview : public Control

private:
    SdrEdgeObj*         pEdgeObj;
    SdrPage*            pSdrPage;
    SdrObjList*         pObjList;
    const SdrView*      pView;

    SVX_DLLPRIVATE void SetStyles();
diff --git a/include/svx/cube3d.hxx b/include/svx/cube3d.hxx
index 95acaab..4a74777 100644
--- a/include/svx/cube3d.hxx
+++ b/include/svx/cube3d.hxx
@@ -54,23 +54,17 @@ class SAL_WARN_UNUSED SVX_DLLPUBLIC E3dCubeObj final : public E3dCompoundObject
    // BOOLeans
    bool                                bPosIsCenter : 1;

    void SetDefaultAttributes(const E3dDefaultAttributes& rDefault);
    void SetDefaultAttributes(E3dDefaultAttributes& rDefault);
    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;

public:
    E3dCubeObj(SdrModel& rSdrModel,
        const E3dDefaultAttributes& rDefault,
        const basegfx::B3DPoint& aPos,
        const basegfx::B3DVector& r3DSize);
    E3dCubeObj(SdrModel& rSdrModel);
    E3dCubeObj(E3dDefaultAttributes& rDefault, const basegfx::B3DPoint& aPos, const basegfx::B3DVector& r3DSize);
    E3dCubeObj();

    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual SdrObject* DoConvertToPolyObj(bool bBezier, bool bAddText) const override;

    virtual E3dCubeObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    E3dCubeObj& operator=(const E3dCubeObj& rObj);
    virtual E3dCubeObj* Clone() const override;

    // Set local parameters with geometry recreation
    void SetCubePos(const basegfx::B3DPoint& rNew);
diff --git a/include/svx/deflt3d.hxx b/include/svx/deflt3d.hxx
index e08e994..e69a62a 100644
--- a/include/svx/deflt3d.hxx
+++ b/include/svx/deflt3d.hxx
@@ -65,13 +65,13 @@ public:
    void Reset();

    // Cube object
    const basegfx::B3DPoint& GetDefaultCubePos() const { return aDefaultCubePos; }
    const basegfx::B3DVector& GetDefaultCubeSize() const { return aDefaultCubeSize; }
    const basegfx::B3DPoint& GetDefaultCubePos() { return aDefaultCubePos; }
    const basegfx::B3DVector& GetDefaultCubeSize() { return aDefaultCubeSize; }
    bool GetDefaultCubePosIsCenter() const { return bDefaultCubePosIsCenter; }

    // Sphere object
    const basegfx::B3DPoint& GetDefaultSphereCenter() const { return aDefaultSphereCenter; }
    const basegfx::B3DVector& GetDefaultSphereSize() const { return aDefaultSphereSize; }
    const basegfx::B3DPoint& GetDefaultSphereCenter() { return aDefaultSphereCenter; }
    const basegfx::B3DVector& GetDefaultSphereSize() { return aDefaultSphereSize; }

    // Lathe object
    bool GetDefaultLatheSmoothed() const { return bDefaultLatheSmoothed; }
diff --git a/include/svx/e3dsceneupdater.hxx b/include/svx/e3dsceneupdater.hxx
index e6800e8..ad01d66 100644
--- a/include/svx/e3dsceneupdater.hxx
+++ b/include/svx/e3dsceneupdater.hxx
@@ -50,7 +50,7 @@ class SVX_DLLPUBLIC E3DModifySceneSnapRectUpdater
    // of the to-be-changed 3D object when the scene has a 3d transformation
    // stack at construction time. In all other cases it's set to zero and
    // no action needs to be taken
    E3dScene*       mpScene;
    E3dScene*                                   mpScene;

    // the 3d transformation stack at the time of construction, valid when
    // mpScene is not zero
@@ -58,7 +58,7 @@ class SVX_DLLPUBLIC E3DModifySceneSnapRectUpdater

public:
    // the constructor evaluates and sets the members at construction time
    E3DModifySceneSnapRectUpdater(const SdrObject* mpObject);
    E3DModifySceneSnapRectUpdater(const SdrObject* pObject);

    // the destructor will take action if mpScene is not zero and modify the
    // 2D geomeztry of the target scene
diff --git a/include/svx/e3dundo.hxx b/include/svx/e3dundo.hxx
index 17335ea..8be61b7 100644
--- a/include/svx/e3dundo.hxx
+++ b/include/svx/e3dundo.hxx
@@ -31,15 +31,17 @@
\************************************************************************/
class SAL_WARN_UNUSED E3dUndoAction : public SdrUndoAction
{

    protected:
        E3dObject&      mrMy3DObj;
        E3dObject *pMy3DObj;

    public:
        E3dUndoAction(E3dObject &r3DObj)
        :   SdrUndoAction(r3DObj.getSdrModelFromSdrObject()),
            mrMy3DObj(r3DObj)
        {
        }
        E3dUndoAction (SdrModel  *pModel,
                       E3dObject *p3DObj) :
            SdrUndoAction (*pModel),
            pMy3DObj (p3DObj)
            {
            }

        virtual ~E3dUndoAction () override;

@@ -53,25 +55,25 @@ class SAL_WARN_UNUSED E3dUndoAction : public SdrUndoAction
\************************************************************************/
class SAL_WARN_UNUSED E3dRotateUndoAction : public E3dUndoAction
{
private:
    basegfx::B3DHomMatrix   maMyOldRotation;
    basegfx::B3DHomMatrix   maMyNewRotation;
        basegfx::B3DHomMatrix aMyOldRotation;
        basegfx::B3DHomMatrix aMyNewRotation;

public:
    E3dRotateUndoAction(
        E3dObject& r3DObj,
        const basegfx::B3DHomMatrix &aOldRotation,
        const basegfx::B3DHomMatrix &aNewRotation)
    :   E3dUndoAction(r3DObj),
        maMyOldRotation(aOldRotation),
        maMyNewRotation(aNewRotation)
    {
    }
    public:
        E3dRotateUndoAction (SdrModel       *pModel,
                             E3dObject      *p3DObj,
                             const basegfx::B3DHomMatrix &aOldRotation,
                             const basegfx::B3DHomMatrix &aNewRotation) :
            E3dUndoAction (pModel, p3DObj),
            aMyOldRotation (aOldRotation),
            aMyNewRotation (aNewRotation)
            {
            }

    virtual ~E3dRotateUndoAction () override;
        virtual ~E3dRotateUndoAction () override;

    virtual void Undo() override;
    virtual void Redo() override;
        virtual void Undo() override;
        virtual void Redo() override;

};

/************************************************************************\
@@ -81,16 +83,16 @@ public:
\************************************************************************/
class SAL_WARN_UNUSED SVX_DLLPUBLIC E3dAttributesUndoAction : public SdrUndoAction
{
private:
    using SdrUndoAction::Repeat;

    SdrObject&          mrObject;
    const SfxItemSet    maNewSet;
    const SfxItemSet    maOldSet;
    SdrObject*  pObject;

    const SfxItemSet aNewSet;
    const SfxItemSet aOldSet;

 public:
        E3dAttributesUndoAction(
            E3dObject& rInObject,
        E3dAttributesUndoAction( SdrModel &rModel,
            E3dObject* pInObject,
            const SfxItemSet& rNewSet,
            const SfxItemSet& rOldSet);

diff --git a/include/svx/extedit.hxx b/include/svx/extedit.hxx
index 82afea2..5ee2864 100644
--- a/include/svx/extedit.hxx
+++ b/include/svx/extedit.hxx
@@ -43,20 +43,18 @@ class FmFormView;
class SdrObject;

class SAL_WARN_UNUSED SVX_DLLPUBLIC SdrExternalToolEdit
:   public ExternalToolEdit
    ,public SfxListener
    : public ExternalToolEdit
    , public SfxListener
{
private:
    FmFormView* m_pView;
    SdrObject*  m_pObj;
    FmFormView * m_pView;
    SdrObject *  m_pObj;

    SAL_DLLPRIVATE virtual void Update(Graphic&) override;
    SAL_DLLPRIVATE virtual void Notify(SfxBroadcaster&, const SfxHint&) override;

public:
    SdrExternalToolEdit(
        FmFormView* pView,
        SdrObject* pObj);
    SdrExternalToolEdit(FmFormView * pView, SdrObject * pObj);
};

#endif
diff --git a/include/svx/extrud3d.hxx b/include/svx/extrud3d.hxx
index 5c12134..1b78d45 100644
--- a/include/svx/extrud3d.hxx
+++ b/include/svx/extrud3d.hxx
@@ -40,15 +40,12 @@ private:

    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
    virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;
    void SetDefaultAttributes(const E3dDefaultAttributes& rDefault);
    void SetDefaultAttributes(E3dDefaultAttributes const & rDefault);

public:
    E3dExtrudeObj(
        SdrModel& rSdrModel,
        const E3dDefaultAttributes& rDefault,
        const basegfx::B2DPolyPolygon& rPP,
        double fDepth);
    E3dExtrudeObj(SdrModel& rSdrModel);

    E3dExtrudeObj(E3dDefaultAttributes const & rDefault, const basegfx::B2DPolyPolygon& rPP, double fDepth);
    E3dExtrudeObj();

    // PercentDiagonal: 0..100, before 0.0..0.5
    sal_uInt16 GetPercentDiagonal() const
@@ -84,10 +81,7 @@ public:

    virtual sal_uInt16 GetObjIdentifier() const override;

    virtual E3dExtrudeObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    E3dExtrudeObj& operator=(const E3dExtrudeObj& rObj);
    virtual E3dExtrudeObj* Clone() const override;

    // TakeObjName...() is for the display in the UI (for example "3 frames selected")
    virtual OUString TakeObjNameSingul() const override;
diff --git a/include/svx/fmpage.hxx b/include/svx/fmpage.hxx
index 2605a60..808d814 100644
--- a/include/svx/fmpage.hxx
+++ b/include/svx/fmpage.hxx
@@ -42,7 +42,6 @@ class HelpEvent;
class SVX_DLLPUBLIC FmFormPage : public SdrPage
{
    FmFormPage& operator=(const FmFormPage&) = delete;
    FmFormPage(const FmFormPage&) = delete;

    friend class FmFormObj;
    std::unique_ptr<FmFormPageImpl>     m_pImpl;
@@ -53,7 +52,10 @@ public:
    explicit FmFormPage(FmFormModel& rModel, bool bMasterPage=false);
    virtual ~FmFormPage() override;

    virtual SdrPage* Clone(SdrModel* pNewModel = nullptr) const override;
    virtual void    SetModel(SdrModel* pNewModel) override;

    virtual SdrPage* Clone() const override;
    virtual SdrPage* Clone(SdrModel* pNewModel) const override;

    virtual void    InsertObject(SdrObject* pObj, size_t nPos = SAL_MAX_SIZE) override;

@@ -73,8 +75,9 @@ public:
                            const HelpEvent& rEvt );

protected:
    // lateInit -> copyValuesToClonedInstance (?)
    void lateInit(const FmFormPage& rPage);
    FmFormPage(const FmFormPage& rPage);

    void lateInit(const FmFormPage& rPage, FmFormModel* pNewModel = nullptr);
};

#endif // INCLUDED_SVX_FMPAGE_HXX
diff --git a/include/svx/fmview.hxx b/include/svx/fmview.hxx
index d0a7eb7..a424515 100644
--- a/include/svx/fmview.hxx
+++ b/include/svx/fmview.hxx
@@ -61,10 +61,8 @@ class SVX_DLLPUBLIC FmFormView : public E3dView
    void Init();

public:
    FmFormView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    FmFormView(FmFormModel* pModel, OutputDevice* pOut);
    virtual ~FmFormView() override;

    /** create a control pair (label/bound control) for the database field description given.
diff --git a/include/svx/graphctl.hxx b/include/svx/graphctl.hxx
index f32454a..85ecc62 100644
--- a/include/svx/graphctl.hxx
+++ b/include/svx/graphctl.hxx
@@ -141,13 +141,10 @@ protected:
    }

public:
    GraphCtrlView(
        SdrModel& rSdrModel,
        GraphCtrl* pWindow)
        :   SdrView(rSdrModel, pWindow)
        ,rGraphCtrl(*pWindow)
    {
    }
    GraphCtrlView(SdrModel* pModel, GraphCtrl* pWindow)
        : SdrView(pModel, pWindow)
        , rGraphCtrl(*pWindow)
    {}
};

#endif // INCLUDED_SVX_GRAPHCTL_HXX
diff --git a/include/svx/lathe3d.hxx b/include/svx/lathe3d.hxx
index 89df103..3c5a0e2 100644
--- a/include/svx/lathe3d.hxx
+++ b/include/svx/lathe3d.hxx
@@ -39,14 +39,11 @@ class SVX_DLLPUBLIC E3dLatheObj final : public E3dCompoundObject

    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
    virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;
    void SetDefaultAttributes(const E3dDefaultAttributes& rDefault);
    void SetDefaultAttributes(E3dDefaultAttributes const & rDefault);

public:
    E3dLatheObj(
        SdrModel& rSdrModel,
        const E3dDefaultAttributes& rDefault,
        const basegfx::B2DPolyPolygon& rPoly2D);
    E3dLatheObj(SdrModel& rSdrModel);
    E3dLatheObj(E3dDefaultAttributes const & rDefault, const basegfx::B2DPolyPolygon& rPoly2D);
    E3dLatheObj();

    // HorizontalSegments:
    sal_uInt32 GetHorizontalSegments() const
@@ -90,10 +87,7 @@ public:

    virtual sal_uInt16 GetObjIdentifier() const override;

    virtual E3dLatheObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    E3dLatheObj& operator=(const E3dLatheObj& rObj);
    virtual E3dLatheObj* Clone() const override;

    virtual SdrObject* DoConvertToPolyObj(bool bBezier, bool bAddText) const override;

diff --git a/include/svx/obj3d.hxx b/include/svx/obj3d.hxx
index 7ad1884..87117cc 100644
--- a/include/svx/obj3d.hxx
+++ b/include/svx/obj3d.hxx
@@ -81,8 +81,6 @@ public:
    E3dObjList();
    SVX_DLLPUBLIC virtual ~E3dObjList() override;

    virtual E3dObjList* CloneSdrObjList(SdrModel* pNewModel = nullptr) const override;

    virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
    virtual void InsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
    virtual SdrObject* NbcRemoveObject(size_t nObjNum) override;
@@ -90,7 +88,8 @@ public:

private:
    E3dObjList &operator=(const E3dObjList& rSrcList) = delete;
    E3dObjList(const E3dObjList& rSrcList) = delete;

    SVX_DLLPUBLIC E3dObjList(const E3dObjList& rSrcList);
};

/*************************************************************************
@@ -132,7 +131,7 @@ protected:
    // E3dObject is only a helper class (for E3DScene and E3DCompoundObject)
    // and no instances should be created from anyone, so i move the constructors
    // to protected area
    E3dObject(SdrModel& rSdrModel);
    E3dObject();

public:
    virtual void RecalcSnapRect() override;
@@ -149,6 +148,7 @@ public:

    virtual void        SetObjList(SdrObjList* pNewObjList) override;
    virtual void        SetPage(SdrPage* pNewPage) override;
    virtual void        SetModel(SdrModel* pNewModel) override;
    virtual void        NbcMove(const Size& rSize) override;
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
    virtual SdrObjList* GetSubList() const override;
@@ -183,7 +183,7 @@ public:
    // TakeObjName...() is for the display in the UI, for example "3 frames selected".
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;
    virtual E3dObject* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual E3dObject* Clone() const override;
    E3dObject& operator=( const E3dObject& rObj );

    virtual SdrObjGeoData *NewGeoData() const override;
@@ -232,7 +232,7 @@ protected:

public:

    E3dCompoundObject(SdrModel& rSdrModel);
    E3dCompoundObject();
    virtual ~E3dCompoundObject() override;

    virtual basegfx::B2DPolyPolygon TakeXorPoly() const override;
@@ -242,10 +242,7 @@ public:
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual void RecalcSnapRect() override;

    virtual E3dCompoundObject* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    E3dCompoundObject& operator=(const E3dCompoundObject& rObj);
    virtual E3dCompoundObject* Clone() const override;

    bool IsAOrdNumRemapCandidate(E3dScene*& prScene) const;
};
diff --git a/include/svx/polygn3d.hxx b/include/svx/polygn3d.hxx
index 9f5acca..98778dd 100644
--- a/include/svx/polygn3d.hxx
+++ b/include/svx/polygn3d.hxx
@@ -43,11 +43,10 @@ public:
    void SetPolyNormals3D(const basegfx::B3DPolyPolygon& rNewPolyPoly3D);
    void SetPolyTexture2D(const basegfx::B2DPolyPolygon& rNewPolyPoly2D);

    E3dPolygonObj(
        SdrModel& rSdrModel,
        const basegfx::B3DPolyPolygon& rPolyPoly3D);
    E3dPolygonObj(SdrModel& rSdrModel);

    E3dPolygonObj(const basegfx::B3DPolyPolygon& rPolyPoly3D);

    E3dPolygonObj();
    virtual ~E3dPolygonObj() override;

    const basegfx::B3DPolyPolygon& GetPolyPolygon3D() const { return aPolyPoly3D; }
@@ -57,10 +56,7 @@ public:
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual SdrObject* DoConvertToPolyObj(bool bBezier, bool bAddText) const override;

    virtual E3dPolygonObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    E3dPolygonObj& operator=(const E3dPolygonObj& rObj);
    virtual E3dPolygonObj* Clone() const override;

    // LineOnly?
    bool GetLineOnly() const { return bLineOnly; }
diff --git a/include/svx/scene3d.hxx b/include/svx/scene3d.hxx
index eef2c04..b656209 100644
--- a/include/svx/scene3d.hxx
+++ b/include/svx/scene3d.hxx
@@ -90,7 +90,7 @@ protected:
    void ImpCleanup3DDepthMapper();

public:
    E3dScene(SdrModel& rSdrModel);
    E3dScene();
    virtual ~E3dScene() override;

    virtual void SetBoundRectDirty() override;
@@ -130,7 +130,7 @@ public:
    const Camera3D& GetCamera() const { return aCamera; }
    void removeAllNonSelectedObjects();

    virtual E3dScene* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual E3dScene* Clone() const override;
    E3dScene& operator=(const E3dScene&);

    virtual SdrObjGeoData *NewGeoData() const override;
diff --git a/include/svx/sdr/properties/defaultproperties.hxx b/include/svx/sdr/properties/defaultproperties.hxx
index b339538..fec5963 100644
--- a/include/svx/sdr/properties/defaultproperties.hxx
+++ b/include/svx/sdr/properties/defaultproperties.hxx
@@ -54,9 +54,6 @@ namespace sdr
            // react on ItemSet changes
            virtual void ItemSetChanged(const SfxItemSet& rSet) override;

            // check if SfxItemSet exists
            bool HasSfxItemSet() const { return bool(mpItemSet); }

        public:
            // basic constructor
            explicit DefaultProperties(SdrObject& rObj);
diff --git a/include/svx/sdr/properties/properties.hxx b/include/svx/sdr/properties/properties.hxx
index 3bfca76..71dad7f 100644
--- a/include/svx/sdr/properties/properties.hxx
+++ b/include/svx/sdr/properties/properties.hxx
@@ -44,32 +44,6 @@ namespace sdr
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  BaseProperties
//      DefaultProperties                   ->SfxItemSet
//          AttributeProperties             ->SfxStyleSheet
//              E3dProperties
//                  E3dCompoundProperties
//                      E3dExtrudeProperties
//                      E3dLatheProperties
//                      E3dSphereProperties
//                  E3dSceneProperties
//              TextProperties              ->maVersion
//                  ConnectorProperties
//                  CustomShapeProperties
//                  MeasureProperties
//                  RectangleProperties
//                      CaptionProperties
//                      CircleProperties
//                      GraphicProperties
//                      OleProperties
//                  CellProperties
//                  TableProperties
//          GroupProperties
//      EmptyProperties
//          PageProperties

namespace sdr
{
    namespace properties
@@ -167,6 +141,13 @@ namespace sdr
            // Get the installed StyleSheet.
            virtual SfxStyleSheet* GetStyleSheet() const = 0;

            // Move local items to a new ItemPool.
            // Override this to do it for hierarchical objects like e.g. groups.
            virtual void MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel);

            // Set new model.
            virtual void SetModel(SdrModel* pOldModel, SdrModel* pNewModel);

            // force all attributes which come from styles to hard attributes
            // to be able to live without the style.
            virtual void ForceStyleToHardAttributes();
diff --git a/include/svx/sdr/table/tablecontroller.hxx b/include/svx/sdr/table/tablecontroller.hxx
index fe03d73..6a999a7 100644
--- a/include/svx/sdr/table/tablecontroller.hxx
+++ b/include/svx/sdr/table/tablecontroller.hxx
@@ -29,7 +29,7 @@
#include <svx/svdotable.hxx>
#include <svx/svdview.hxx>

class SdrView;
class SdrObjEditView;
class SdrObject;
class SfxItemSet;
class SvxBoxInfoItem;
@@ -39,12 +39,10 @@ namespace sdr { namespace table {

class TableModel;

class SVX_DLLPUBLIC SvxTableController : public sdr::SelectionController
class SVX_DLLPUBLIC SvxTableController: public sdr::SelectionController
{
public:
    SVX_DLLPRIVATE SvxTableController(
        SdrView& rView,
        const SdrTableObj& rObj);
    SVX_DLLPRIVATE SvxTableController( SdrObjEditView* pView, const SdrTableObj* pObj );
    SVX_DLLPRIVATE virtual ~SvxTableController() override;

    // from sdr::SelectionController
@@ -78,10 +76,7 @@ public:
    SVX_DLLPRIVATE void DistributeRows();
    SVX_DLLPRIVATE void SetVertical( sal_uInt16 nSId );

    SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create(
        SdrView& rView,
        const SdrTableObj& rObj,
        const rtl::Reference< sdr::SelectionController >& xRefController);
    SVX_DLLPRIVATE static rtl::Reference< sdr::SelectionController > create( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );

    SVX_DLLPRIVATE void MergeAttrFromSelectedCells(SfxItemSet& rAttr, bool bOnlyHardAttr) const;
    SVX_DLLPRIVATE void SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll);
@@ -98,7 +93,7 @@ public:
    SVX_DLLPRIVATE virtual bool GetMarkedObjModel( SdrPage* pNewPage ) override;
    SVX_DLLPRIVATE virtual bool PasteObjModel( const SdrModel& rModel ) override;

    SVX_DLLPRIVATE virtual bool hasSelectedCells() const override { return mbCellSelectionMode || mrView.IsTextEdit(); }
    SVX_DLLPRIVATE virtual bool hasSelectedCells() const override { return mbCellSelectionMode || mpView->IsTextEdit(); }
    /// @see sdr::SelectionController::setCursorLogicPosition().
    SVX_DLLPRIVATE virtual bool setCursorLogicPosition(const Point& rPosition, bool bPoint) override;

@@ -179,16 +174,17 @@ private:
    CellPos maMouseDownPos;
    bool mbLeftButtonDown;
    sdr::overlay::OverlayObjectList*  mpSelectionOverlay;
    SdrView& mrView;

    SdrView* mpView;
    tools::WeakReference<SdrTableObj> mxTableObj;
    SdrModel* mpModel;

    css::uno::Reference< css::util::XModifyListener > mxModifyListener;

    ImplSVEvent * mnUpdateEvent;
};

rtl::Reference< sdr::SelectionController > CreateTableController(
     SdrView& rView,
     const SdrTableObj& rObj,
     const rtl::Reference< sdr::SelectionController >& xRefController );
rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController );

} }

diff --git a/include/svx/sphere3d.hxx b/include/svx/sphere3d.hxx
index e5534e5..9c4bc5d2 100644
--- a/include/svx/sphere3d.hxx
+++ b/include/svx/sphere3d.hxx
@@ -35,19 +35,16 @@ private:

    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
    virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;
    void SetDefaultAttributes(const E3dDefaultAttributes& rDefault);
    void SetDefaultAttributes(E3dDefaultAttributes& rDefault);

public:
    E3dSphereObj(
        SdrModel& rSdrModel,
        const E3dDefaultAttributes& rDefault,
        const basegfx::B3DPoint& rCenter,
        const basegfx::B3DVector& r3DSize);
    E3dSphereObj(E3dDefaultAttributes& rDefault, const basegfx::B3DPoint& rCenter, const basegfx::B3DVector& r3DSize);

    // FG: This constructor is only called from MakeObject from the 3d-Objectfactory
    //     when a document with a sphere is loaded.  This constructor does not call
    //     CreateSphere, or create any spheres.
    E3dSphereObj(SdrModel& rSdrModel);
    enum Dummy { DUMMY };
    E3dSphereObj(Dummy dummy);

    // horizontal segments:
    sal_uInt32 GetHorizontalSegments() const
@@ -60,10 +57,7 @@ public:
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual SdrObject* DoConvertToPolyObj(bool bBezier, bool bAddText) const override;

    virtual E3dSphereObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    E3dSphereObj& operator=(const E3dSphereObj& rObj);
    virtual E3dSphereObj* Clone() const override;

    const basegfx::B3DPoint& Center() const { return aCenter; }
    const basegfx::B3DVector& Size() const { return aSize; }
diff --git a/include/svx/svdcrtv.hxx b/include/svx/svdcrtv.hxx
index 47858b2..3b71a50 100644
--- a/include/svx/svdcrtv.hxx
+++ b/include/svx/svdcrtv.hxx
@@ -31,7 +31,7 @@ class SdrObjConnection;
class ImplConnectMarkerOverlay;
class ImpSdrCreateViewExtraData;

class SVX_DLLPUBLIC SdrCreateView : public SdrDragView
class SVX_DLLPUBLIC SdrCreateView: public SdrDragView
{
    friend class                SdrPageView;

@@ -69,10 +69,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrCreateView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrCreateView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrCreateView() override;

public:
diff --git a/include/svx/svddrgv.hxx b/include/svx/svddrgv.hxx
index 180d8cc..19b5641 100644
--- a/include/svx/svddrgv.hxx
+++ b/include/svx/svddrgv.hxx
@@ -25,7 +25,7 @@

class SdrUndoGeoObj;

class SVX_DLLPUBLIC SdrDragView : public SdrExchangeView
class SVX_DLLPUBLIC SdrDragView: public SdrExchangeView
{
    friend class                SdrPageView;
    friend class                SdrDragMethod;
@@ -69,10 +69,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrDragView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrDragView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrDragView() override;

public:
diff --git a/include/svx/svdedtv.hxx b/include/svx/svdedtv.hxx
index 51dbb48..0c1e2f6 100644
--- a/include/svx/svdedtv.hxx
+++ b/include/svx/svdedtv.hxx
@@ -68,7 +68,7 @@ namespace o3tl
    template<> struct typed_flags<SdrInsertFlags> : is_typed_flags<SdrInsertFlags, 0x1f> {};
}

class SVX_DLLPUBLIC SdrEditView : public SdrMarkView
class SVX_DLLPUBLIC SdrEditView: public SdrMarkView
{
    friend class                SdrPageView;
    friend class                SdrDragDistort;
@@ -163,10 +163,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrEditView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrEditView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrEditView() override;

public:
diff --git a/include/svx/svdedxv.hxx b/include/svx/svdedxv.hxx
index 70472aa..324a611 100644
--- a/include/svx/svdedxv.hxx
+++ b/include/svx/svdedxv.hxx
@@ -58,7 +58,7 @@ enum class SdrEndTextEditKind
// - macromod


class SVX_DLLPUBLIC SdrObjEditView : public SdrGlueEditView, public EditViewCallbacks
class SVX_DLLPUBLIC SdrObjEditView: public SdrGlueEditView, public EditViewCallbacks
{
    friend class                SdrPageView;
    friend class                ImpSdrEditPara;
@@ -150,10 +150,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrObjEditView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrObjEditView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrObjEditView() override;

public:
diff --git a/include/svx/svdglev.hxx b/include/svx/svdglev.hxx
index be365e3..10645f0 100644
--- a/include/svx/svdglev.hxx
+++ b/include/svx/svdglev.hxx
@@ -29,7 +29,7 @@ class SdrGluePoint;
//  Edit GluePoints at the objects (GluePoints for connector)


class SVX_DLLPUBLIC SdrGlueEditView : public SdrPolyEditView
class SVX_DLLPUBLIC SdrGlueEditView: public SdrPolyEditView
{
    // copy marked GluePoints and mark instead of the old ones
    void ImpCopyMarkedGluePoints();
@@ -40,10 +40,7 @@ class SVX_DLLPUBLIC SdrGlueEditView : public SdrPolyEditView

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrGlueEditView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrGlueEditView() override;

public:
diff --git a/include/svx/svdmrkv.hxx b/include/svx/svdmrkv.hxx
index 36e8041..981b1e2 100644
--- a/include/svx/svdmrkv.hxx
+++ b/include/svx/svdmrkv.hxx
@@ -166,10 +166,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrMarkView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrMarkView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrMarkView() override;

public:
diff --git a/include/svx/svdoashp.hxx b/include/svx/svdoashp.hxx
index 3ce7833..85f5e9d 100644
--- a/include/svx/svdoashp.hxx
+++ b/include/svx/svdoashp.hxx
@@ -98,8 +98,15 @@ public:

    css::uno::Reference< css::drawing::XCustomShapeEngine > const & GetCustomShapeEngine() const;

//  SVX_DLLPRIVATE css::uno::Sequence< css::uno::Reference< css::drawing::XCustomShapeHandle > >
//      SdrObjCustomShape::GetInteraction( const SdrObjCustomShape* pCustomShape ) const;
// #i47293#
//  SVX_DLLPRIVATE std::vector< css::uno::Reference< css::drawing::XCustomShapeHandle > > GetFixedInteractionHandle() const;

    SVX_DLLPRIVATE std::vector< SdrCustomShapeInteraction > GetInteractionHandles() const;

    SVX_DLLPRIVATE void DragCreateObject( SdrDragStat& rDrag );

    SVX_DLLPRIVATE void DragResizeCustomShape( const tools::Rectangle& rNewRect );
    SVX_DLLPRIVATE void DragMoveCustomShapeHdl( const Point& rDestination,
            const sal_uInt16 nCustomShapeHdlNum, bool bMoveCalloutRectangle );
@@ -140,7 +147,7 @@ public:
    double GetObjectRotation() const { return fObjectRotation;}
    double GetExtraTextRotation( const bool bPreRotation = false ) const;

    SdrObjCustomShape(SdrModel& rSdrModel);
    SdrObjCustomShape();
    virtual ~SdrObjCustomShape() override;

    /* is merging default attributes from type-shape into the SdrCustomShapeGeometryItem. If pType
@@ -165,6 +172,8 @@ public:
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;

    virtual void SetModel(SdrModel* pNewModel) override;

    virtual void Move(const Size& rSiz) override;
    virtual void Shear(const Point& rRef, long nAngle, double tn, bool bVShear) override;
    virtual void SetSnapRect(const tools::Rectangle& rRect) override;
@@ -207,7 +216,7 @@ public:
    virtual void TakeTextAnchorRect( tools::Rectangle& rAnchorRect ) const override;
    virtual void TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRect, bool bNoEditText,
        tools::Rectangle* pAnchorRect, bool bLineWidth = true ) const override;
    virtual SdrObjCustomShape* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrObjCustomShape* Clone() const override;
    SdrObjCustomShape& operator=(const SdrObjCustomShape& rObj);

    virtual OUString TakeObjNameSingul() const override;
diff --git a/include/svx/svdoattr.hxx b/include/svx/svdoattr.hxx
index a39a919..10c163b 100644
--- a/include/svx/svdoattr.hxx
+++ b/include/svx/svdoattr.hxx
@@ -28,14 +28,20 @@
#include <svx/svdattr.hxx>
#include <svx/svxdllapi.h>


//   Initial Declarations


class SfxPoolItem;
class SfxSetItem;
class SdrOutliner;
class SfxItemSet;
class SfxItemPool;


//   SdrAttrObj


class SVX_DLLPUBLIC SdrAttrObj : public SdrObject
{
private:
@@ -53,7 +59,7 @@ protected:
    /// Detects when a stylesheet is changed
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;

    SdrAttrObj(SdrModel& rSdrModel);
    SdrAttrObj();
    virtual ~SdrAttrObj() override;

public:
@@ -65,6 +71,8 @@ public:
    bool HasLine() const;

    virtual const tools::Rectangle& GetSnapRect() const override;

    virtual void SetModel(SdrModel* pNewModel) override;
};


diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index 7d03360..3f01cbb8 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -74,11 +74,10 @@ class SdrLayerIDSet;
class OutputDevice;
class Fraction;

namespace basegfx
{
    class B2DPoint;
    class B2DPolyPolygon;
    class B2DHomMatrix;
namespace basegfx {
class B2DPoint;
class B2DPolyPolygon;
class B2DHomMatrix;
}

namespace sdr
@@ -104,8 +103,6 @@ namespace svx
    class PropertyChangeNotifier;
}

class SvxShape;

enum SdrObjKind {
    OBJ_NONE       = 0,  /// abstract object (SdrObject)
    OBJ_GRUP       = 1,  /// object group
@@ -268,45 +265,9 @@ public:
    SdrObjTransformInfoRec();
};

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  SdrObject
//      SdrAttrObj
//          E3dObject
//              E3dCompoundObject
//                  E3dCubeObj
//                  E3dExtrudeObj
//                  E3dLatheObj
//                  E3dPolygonObj
//                  E3dSphereObj
//              E3dScene
//          SdrTextObj
//              SdrObjCustomShape
//                  OCustomShape
//              SdrEdgeObj
//              SdrMeasureObj
//              SdrPathObj
//              SdrRectObj
//                  SdrCaptionObj
//                  SdrCircObj
//                  SdrGrafObj
//                  SdrMediaObj
//                  SdrOle2Obj
//                      OOle2Obj
//                  SdrUnoObj
//                      DlgEdObj
//                          DlgEdForm
//                      OUnoObject
//                      FmFormObj
//              SdrTableObj
//      SdrObjGroup
//      SdrPageObj
//      SdrVirtObj
//          SwDrawVirtObj
//          SwVirtFlyDrawObj
//      SwFlyDrawObj

/// Abstract DrawObject

class SvxShape;
class SVX_DLLPUBLIC SdrObject: public SfxListener, public virtual tools::WeakBase
{
private:
@@ -335,16 +296,8 @@ private:
public:
    const SdrObject* getFillGeometryDefiningShape() const { return mpFillGeometryDefiningShape; }

private:
    // the SdrModel this objects was created with, unchanged during SdrObject lifetime
    SdrModel&                   mrSdrModelFromSdrObject;

public:
    // A SdrObject always needs a SdrModel for lifetime (Pool, ...)
    SdrObject(SdrModel& rSdrModel);

    // SdrModel access on SdrObject level
    SdrModel& getSdrModelFromSdrObject() const { return mrSdrModelFromSdrObject; }
    SdrObject();

    void AddObjectUser(sdr::ObjectUser& rNewUser);
    void RemoveObjectUser(sdr::ObjectUser& rOldUser);
@@ -388,6 +341,9 @@ public:

    virtual void SetPage(SdrPage* pNewPage);
    SdrPage* GetPage() const { return pPage;}

    virtual void SetModel(SdrModel* pNewModel);
    SdrModel* GetModel() const { return pModel;}
    SfxItemPool & GetObjectItemPool() const;

    void AddListener(SfxListener& rListener);
@@ -482,7 +438,7 @@ public:
    // Returns a copy of the object. Every inherited class must reimplement this (in class Foo
    // it should be sufficient to do "virtual Foo* Clone() const { return CloneHelper< Foo >(); }".
    // Note that this function uses operator= internally.
    virtual SdrObject* Clone(SdrModel* pTargetModel = nullptr) const;
    virtual SdrObject* Clone() const;

    // implemented mainly for the purposes of Clone()
    SdrObject& operator=(const SdrObject& rObj);
@@ -768,9 +724,7 @@ public:
    // when there is no filled new polygon created from line-to-polygon conversion,
    // specially used for XLINE_DASH and 3D conversion
    SdrObject* ConvertToContourObj(SdrObject* pRet, bool bForceLineDash = false) const;
private:
    SdrObject* ImpConvertToContourObj(bool bForceLineDash);
public:
    static SdrObject* ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDash);

    // if true, reference onto an object
    bool IsVirtualObj() const { return bVirtObj;}
@@ -808,6 +762,9 @@ public:
    // removes the record from the list and performs delete (FreeMem+Dtor).
    void DeleteUserData(sal_uInt16 nNum);

    // switch ItemPool for this object
    void MigrateItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel);

    // access to the UNO representation of the shape
    virtual css::uno::Reference< css::uno::XInterface > getUnoShape();

@@ -910,6 +867,7 @@ protected:
    tools::Rectangle                   aOutRect;     // surrounding rectangle for Paint (incl. LineWdt, ...)
    Point                       aAnchor;      // anchor position (Writer)
    SdrPage*                    pPage;
    SdrModel*                   pModel;
    SdrObjUserCall*             pUserCall;
    std::unique_ptr<SdrObjPlusData>
                                pPlusData;    // Broadcaster, UserData, connectors, ... (this is the Bitsack)
@@ -951,6 +909,7 @@ protected:

    void ImpForcePlusData();

    OUString GetAngleStr(long nAngle) const;
    OUString GetMetrStr(long nVal) const;

    /// A derived class must override these 3 methods if it has own geometric
@@ -986,7 +945,7 @@ protected:
    virtual void impl_setUnoShape( const css::uno::Reference< css::uno::XInterface >& _rxUnoShape );

    // helper function for reimplementing Clone().
    template< typename T > T* CloneHelper(SdrModel* pTargetModel) const;
    template< typename T > T* CloneHelper() const;

private:
    struct Impl;
@@ -1047,7 +1006,6 @@ struct SdrObjCreatorParams
{
    SdrInventor nInventor;
    sal_uInt16  nObjIdentifier;
    SdrModel&   rSdrModel;
};

/**
@@ -1061,40 +1019,23 @@ struct SdrObjCreatorParams
class SVX_DLLPUBLIC SdrObjFactory
{
public:
    static SdrObject* MakeNewObject(
        SdrModel& rSdrModel,
        SdrInventor nInventor,
        sal_uInt16 nObjIdentifier,
        SdrPage* pPage = nullptr,
        const tools::Rectangle* pSnapRect = nullptr);

    static SdrObject* MakeNewObject(SdrInventor nInventor, sal_uInt16 nObjIdentifier, SdrPage* pPage, SdrModel* pModel=nullptr);
    static SdrObject* MakeNewObject(SdrInventor nInventor, sal_uInt16 nObjIdentifier, const tools::Rectangle& rSnapRect, SdrPage* pPage);
    static void InsertMakeObjectHdl(Link<SdrObjCreatorParams, SdrObject*> const & rLink);
    static void RemoveMakeObjectHdl(Link<SdrObjCreatorParams, SdrObject*> const & rLink);

private:
    static SVX_DLLPRIVATE SdrObject* CreateObjectFromFactory(
        SdrModel& rSdrModel,
        SdrInventor nInventor,
        sal_uInt16 nIdentifier);
    static SVX_DLLPRIVATE SdrObject* CreateObjectFromFactory( SdrInventor nInventor, sal_uInt16 nIdentifier );

    SdrObjFactory() = delete;
};

template< typename T > T* SdrObject::CloneHelper(SdrModel* pTargetModel) const
template< typename T > T* SdrObject::CloneHelper() const
{
    OSL_ASSERT( typeid( T ) == typeid( *this ));
    T* pObj = dynamic_cast< T* >(
        SdrObjFactory::MakeNewObject(
            nullptr == pTargetModel ? getSdrModelFromSdrObject() : *pTargetModel,
            GetObjInventor(),
            GetObjIdentifier()));

    if(nullptr != pObj)
    {
        // use ::operator=()
        *pObj = *static_cast< const T* >( this );
    }

    T* pObj = dynamic_cast< T* >( SdrObjFactory::MakeNewObject(GetObjInventor(),GetObjIdentifier(),nullptr));
    if (pObj!=nullptr)
        *pObj=*static_cast< const T* >( this );
    return pObj;
}

diff --git a/include/svx/svdocapt.hxx b/include/svx/svdocapt.hxx
index baa0e039..3dd6829 100644
--- a/include/svx/svdocapt.hxx
+++ b/include/svx/svdocapt.hxx
@@ -25,20 +25,28 @@


//   Forward Declarations


class ImpCaptParams;

namespace sdr { namespace properties {
    class CaptionProperties;
}}


//   Helper Class SdrCaptObjGeoData


class SdrCaptObjGeoData : public SdrTextObjGeoData
{
public:
    tools::Polygon aTailPoly;
};


//   SdrCaptionObj


class SVX_DLLPUBLIC SdrCaptionObj : public SdrRectObj
{
private:
@@ -65,20 +73,13 @@ private:
    SVX_DLLPRIVATE void ImpRecalcTail();

public:
    SdrCaptionObj(SdrModel& rSdrModel);
    SdrCaptionObj(
        SdrModel& rSdrModel,
        const tools::Rectangle& rRect,
        const Point& rTail);

    SdrCaptionObj();
    SdrCaptionObj(const tools::Rectangle& rRect, const Point& rTail);
    virtual ~SdrCaptionObj() override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual SdrCaptionObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    SdrCaptionObj& operator=(const SdrCaptionObj& rObj);
    virtual SdrCaptionObj* Clone() const override;

    // for calc: special shadow only for text box
    void SetSpecialTextBoxShadow() { mbSpecialTextBoxShadow = true; }
@@ -91,6 +92,7 @@ public:
    virtual OUString TakeObjNamePlural() const override;

    virtual basegfx::B2DPolyPolygon TakeXorPoly() const override;
    virtual void SetModel(SdrModel* pNewModel) override;
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;

    virtual sal_uInt32 GetHdlCount() const override;
diff --git a/include/svx/svdocirc.hxx b/include/svx/svdocirc.hxx
index fc30455..d3bc9c2 100644
--- a/include/svx/svdocirc.hxx
+++ b/include/svx/svdocirc.hxx
@@ -66,25 +66,14 @@ private:
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;

public:
    SdrCircObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewKind); // Circ, CArc, Sect or CCut
    SdrCircObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewKind,
        const tools::Rectangle& rRect);
    SdrCircObj(SdrObjKind eNewKind); // Circ, CArc, Sect or CCut
    SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect);

    // 0=0.00Deg=3h 9000=90.00Deg=12h 18000=180.00Deg=9h 27000=270.00Deg=6h
    // The circle is build up from StartAngle to EndWink anti-clockwise.
    // If nNewStartAngle==nNewEndWink, then arc has an angle of 0 degrees.
    // If nNewStartAngle+36000==nNewEndWink, then the arc has angle of 360 degrees.
    SdrCircObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewKind,
        const tools::Rectangle& rRect,
        long nNewStartAngle,
        long nNewEndWink);

    SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect, long nNewStartAngle, long nNewEndWink);
    virtual ~SdrCircObj() override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
@@ -94,11 +83,7 @@ public:
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;

    virtual SdrCircObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    SdrCircObj& operator=(const SdrCircObj& rObj);

    virtual SdrCircObj* Clone() const override;
    virtual void RecalcSnapRect() override;
    virtual void NbcSetSnapRect(const tools::Rectangle& rRect) override;
    virtual basegfx::B2DPolyPolygon TakeXorPoly() const override;
diff --git a/include/svx/svdoedge.hxx b/include/svx/svdoedge.hxx
index ae28ad7..5b11da0 100644
--- a/include/svx/svdoedge.hxx
+++ b/include/svx/svdoedge.hxx
@@ -187,7 +187,8 @@ protected:
    void ImpSetEdgeInfoToAttr(); // copying values from the aEdgeInfo to the pool

public:
    SdrEdgeObj(SdrModel& rSdrModel);

    SdrEdgeObj();
    virtual ~SdrEdgeObj() override;

    SdrObjConnection& GetConnection(bool bTail1) { return *(bTail1 ? &aCon1 : &aCon2); }
@@ -213,7 +214,7 @@ public:

    virtual void RecalcSnapRect() override;
    virtual void TakeUnrotatedSnapRect(tools::Rectangle& rRect) const override;
    virtual SdrEdgeObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrEdgeObj* Clone() const override;
    SdrEdgeObj& operator=(const SdrEdgeObj& rObj);
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;
diff --git a/include/svx/svdograf.hxx b/include/svx/svdograf.hxx
index d11a289..65b9348 100644
--- a/include/svx/svdograf.hxx
+++ b/include/svx/svdograf.hxx
@@ -129,16 +129,10 @@ private:

public:

    SdrGrafObj(SdrModel& rSdrModel);
    SdrGrafObj(
        SdrModel& rSdrModel,
        const Graphic& rGrf);
    SdrGrafObj(
        SdrModel& rSdrModel,
        const Graphic& rGrf,
        const tools::Rectangle& rRect);

    virtual ~SdrGrafObj() override;
                            SdrGrafObj();
                            SdrGrafObj(const Graphic& rGrf);
                            SdrGrafObj(const Graphic& rGrf, const tools::Rectangle& rRect);
    virtual                 ~SdrGrafObj() override;

    void                    SetGraphicObject( const GraphicObject& rGrfObj );
    const GraphicObject&    GetGraphicObject(bool bForceSwapIn = false) const;
@@ -149,7 +143,9 @@ public:
    const Graphic&          GetGraphic() const;

    Graphic                 GetTransformedGraphic( SdrGrafObjTransformsAttrs nTransformFlags = SdrGrafObjTransformsAttrs::ALL ) const;

    GraphicType             GetGraphicType() const;

    GraphicAttr             GetGraphicAttr( SdrGrafObjTransformsAttrs nTransformFlags = SdrGrafObjTransformsAttrs::ALL  ) const;

    // Keep ATM for SD.
@@ -186,7 +182,7 @@ public:
    // #i25616#
    virtual basegfx::B2DPolyPolygon TakeXorPoly() const override;

    virtual SdrGrafObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrGrafObj* Clone() const override;
    SdrGrafObj&             operator=(const SdrGrafObj& rObj);

    virtual sal_uInt32 GetHdlCount() const override;
@@ -201,6 +197,7 @@ public:
    bool                    HasGDIMetaFile() const;

    virtual void            SetPage(SdrPage* pNewPage) override;
    virtual void            SetModel(SdrModel* pNewModel) override;

    bool isEmbeddedVectorGraphicData() const;
    GDIMetaFile getMetafileFromEmbeddedVectorGraphicData() const;
diff --git a/include/svx/svdogrp.hxx b/include/svx/svdogrp.hxx
index 7f0fb234..f15a9b9 100644
--- a/include/svx/svdogrp.hxx
+++ b/include/svx/svdogrp.hxx
@@ -23,23 +23,30 @@
#include <memory>
#include <svx/svdobj.hxx>
#include <svx/svxdllapi.h>
#include <svx/svdpage.hxx>


// Forward declarations


class SdrObjList;
class SdrObjListIter;
class SfxItemSet;


//   SdrObjGroup


class SVX_DLLPUBLIC SdrObjGroup final : public SdrObject
{
private:
    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
    virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;

    SdrObjList                  maSdrObjList;   // sub list (children)
    Point                       aRefPoint;      // Reference point inside the object group
    std::unique_ptr<SdrObjList> pSub;    // sub list (children)
    Point                       aRefPoint; // Reference point inside the object group

public:
    SdrObjGroup(SdrModel& rSdrModel);
    SdrObjGroup();
    virtual ~SdrObjGroup() override;

    virtual void SetBoundRectDirty() override;
@@ -49,12 +56,13 @@ public:
    virtual void NbcSetLayer(SdrLayerID nLayer) override;
    virtual void SetObjList(SdrObjList* pNewObjList) override;
    virtual void SetPage(SdrPage* pNewPage) override;
    virtual void SetModel(SdrModel* pNewModel) override;
    virtual SdrObjList* GetSubList() const override;

    virtual const tools::Rectangle& GetCurrentBoundRect() const override;
    virtual const tools::Rectangle& GetSnapRect() const override;

    virtual SdrObjGroup* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrObjGroup* Clone() const override;
    SdrObjGroup& operator=(const SdrObjGroup& rObj);

    virtual OUString TakeObjNameSingul() const override;
diff --git a/include/svx/svdomeas.hxx b/include/svx/svdomeas.hxx
index 00a4a95..be2ce84 100644
--- a/include/svx/svdomeas.hxx
+++ b/include/svx/svdomeas.hxx
@@ -85,20 +85,14 @@ protected:
    virtual void RestGeoData(const SdrObjGeoData& rGeo) override;

public:
    SdrMeasureObj(SdrModel& rSdrModel);
    SdrMeasureObj(
        SdrModel& rSdrModel,
        const Point& rPt1,
        const Point& rPt2);
    SdrMeasureObj();
    SdrMeasureObj(const Point& rPt1, const Point& rPt2);
    virtual ~SdrMeasureObj() override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual void TakeUnrotatedSnapRect(tools::Rectangle& rRect) const override;
    virtual SdrMeasureObj* Clone(SdrModel* pTargetModel = nullptr) const override;

    // implemented mainly for the purposes of Clone()
    SdrMeasureObj& operator=(const SdrMeasureObj& rObj);
    virtual SdrMeasureObj* Clone() const override;

    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;
diff --git a/include/svx/svdomedia.hxx b/include/svx/svdomedia.hxx
index a45410f..43356da 100644
--- a/include/svx/svdomedia.hxx
+++ b/include/svx/svdomedia.hxx
@@ -37,12 +37,10 @@ class SVX_DLLPUBLIC SdrMediaObj final : public SdrRectObj
public:


        SdrMediaObj(SdrModel& rSdrModel);
        SdrMediaObj(
                SdrModel& rSdrModel,
                const tools::Rectangle& rRect);
                                    SdrMediaObj();
                                    SdrMediaObj( const tools::Rectangle& rRect );

        virtual ~SdrMediaObj() override;
        virtual                     ~SdrMediaObj() override;

        virtual bool                HasTextEdit() const override;

@@ -52,7 +50,7 @@ public:
        virtual OUString            TakeObjNameSingul() const override;
        virtual OUString            TakeObjNamePlural() const override;

        virtual SdrMediaObj*            Clone(SdrModel* pTargetModel = nullptr) const override;
        virtual SdrMediaObj*            Clone() const override;
        SdrMediaObj&                operator=(const SdrMediaObj& rObj);

        virtual void                AdjustToMaxRect( const tools::Rectangle& rMaxRect, bool bShrinkOnly = false ) override;
diff --git a/include/svx/svdoole2.hxx b/include/svx/svdoole2.hxx
index b170f6a..edeccfa 100644
--- a/include/svx/svdoole2.hxx
+++ b/include/svx/svdoole2.hxx
@@ -60,8 +60,6 @@ private:
    SVX_DLLPRIVATE SdrObject* createSdrGrafObjReplacement(bool bAddText) const;
    SVX_DLLPRIVATE void ImpSetVisAreaSize();

    SVX_DLLPRIVATE void Init();

protected:
    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;
    virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;
@@ -69,15 +67,8 @@ protected:
public:
    OUString GetStyleString();

    SdrOle2Obj(
        SdrModel& rSdrModel,
        bool bFrame_ = false);
    SdrOle2Obj(
        SdrModel& rSdrModel,
        const svt::EmbeddedObjectRef& rNewObjRef,
        const OUString& rNewObjName,
        const tools::Rectangle& rNewRect);

    SdrOle2Obj( bool bFrame_ = false );
    SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const OUString& rNewObjName, const tools::Rectangle& rNewRect );
    virtual ~SdrOle2Obj() override;

    const svt::EmbeddedObjectRef& getEmbeddedObjectRef() const;
@@ -121,6 +112,7 @@ public:
    void AbandonObject();

    virtual void SetPage(SdrPage* pNewPage) override;
    virtual void SetModel(SdrModel* pModel) override;

    /** Change the IsClosedObj attribute

@@ -137,7 +129,7 @@ public:
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;

    virtual SdrOle2Obj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrOle2Obj* Clone() const override;

    SdrOle2Obj& assignFrom(const SdrOle2Obj& rObj);
    SdrOle2Obj& operator=(const SdrOle2Obj& rObj);
diff --git a/include/svx/svdopage.hxx b/include/svx/svdopage.hxx
index 1f349a9..8893e81 100644
--- a/include/svx/svdopage.hxx
+++ b/include/svx/svdopage.hxx
@@ -41,14 +41,8 @@ protected:
    virtual sdr::properties::BaseProperties* CreateObjectSpecificProperties() override;

public:
    SdrPageObj(
        SdrModel& rSdrModel,
        SdrPage* pNewPage = nullptr);
    SdrPageObj(
        SdrModel& rSdrModel,
        const tools::Rectangle& rRect,
        SdrPage* pNewPage = nullptr);

    SdrPageObj(SdrPage* pNewPage = nullptr);
    SdrPageObj(const tools::Rectangle& rRect, SdrPage* pNewPage = nullptr);
    virtual ~SdrPageObj() override;

    SdrPage* GetReferencedPage() const { return mpShownPage;}
@@ -59,7 +53,7 @@ public:

    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual SdrPageObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrPageObj* Clone() const override;
    SdrPageObj& operator=(const SdrPageObj& rObj);

    virtual OUString TakeObjNameSingul() const override;
diff --git a/include/svx/svdopath.hxx b/include/svx/svdopath.hxx
index 6c21fd0..e32ccf5 100644
--- a/include/svx/svdopath.hxx
+++ b/include/svx/svdopath.hxx
@@ -62,20 +62,14 @@ private:
    ImpPathForDragAndCreate& impGetDAC() const;

public:
    SdrPathObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewKind);
    SdrPathObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewKind,
        const basegfx::B2DPolyPolygon& rPathPoly);

    SdrPathObj(SdrObjKind eNewKind);
    SdrPathObj(SdrObjKind eNewKind, const basegfx::B2DPolyPolygon& rPathPoly);
    virtual ~SdrPathObj() override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual void TakeUnrotatedSnapRect(tools::Rectangle& rRect) const override;
    virtual SdrPathObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrPathObj* Clone() const override;
    SdrPathObj& operator=(const SdrPathObj& rObj);

    virtual OUString TakeObjNameSingul() const override;
diff --git a/include/svx/svdorect.hxx b/include/svx/svdorect.hxx
index f9c1c34..729d3f22 100644
--- a/include/svx/svdorect.hxx
+++ b/include/svx/svdorect.hxx
@@ -66,22 +66,14 @@ public:
     *
     * Constructor of a rectangular drawing object
     */
    SdrRectObj(SdrModel& rSdrModel);
    SdrRectObj(
        SdrModel& rSdrModel,
        const tools::Rectangle& rRect);
    SdrRectObj();
    SdrRectObj(const tools::Rectangle& rRect);

    SdrRectObj& operator=(const SdrRectObj& rCopy);

    // Constructor of a text frame
    SdrRectObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewTextKind);
    SdrRectObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewTextKind,
        const tools::Rectangle& rRect);

    SdrRectObj(SdrObjKind eNewTextKind);
    SdrRectObj(SdrObjKind eNewTextKind, const tools::Rectangle& rRect);
    virtual ~SdrRectObj() override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
@@ -91,7 +83,7 @@ public:
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;

    virtual SdrRectObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrRectObj* Clone() const override;
    virtual void RecalcSnapRect() override;
    virtual void NbcSetSnapRect(const tools::Rectangle& rRect) override;
    virtual void NbcSetLogicRect(const tools::Rectangle& rRect) override;
diff --git a/include/svx/svdotable.hxx b/include/svx/svdotable.hxx
index 7c5e30e..c33551c 100644
--- a/include/svx/svdotable.hxx
+++ b/include/svx/svdotable.hxx
@@ -98,20 +98,13 @@ class SVX_DLLPUBLIC SdrTableObj : public ::SdrTextObj
    friend class SdrTableObjImpl;

public:
    SdrTableObj(SdrModel& rSdrModel);
    SdrTableObj(
        SdrModel& rSdrModel,
        const ::tools::Rectangle& rNewRect,
        sal_Int32 nColumns,
        sal_Int32 nRows);

    SdrTableObj(SdrModel* _pModel);
    SdrTableObj(SdrModel* _pModel, const ::tools::Rectangle& rNewRect, sal_Int32 nColumns, sal_Int32 nRows);
    virtual ~SdrTableObj() override;


    // Table stuff
    SdrTableObj* CloneRange(
        const CellPos& rStartPos,
        const CellPos& rEndPos,
        SdrModel& rTargetModel);
    SdrTableObj* CloneRange( const CellPos& rStartPos, const CellPos& rEndPos );
    void DistributeColumns( sal_Int32 nFirstColumn, sal_Int32 nLastColumn );
    void DistributeRows( sal_Int32 nFirstRow, sal_Int32 nLastRow );

@@ -191,6 +184,7 @@ public:

    virtual bool IsFontwork() const override;

    virtual void SetModel(SdrModel* pNewModel) override;
    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual void SetChanged() override;
@@ -199,7 +193,7 @@ public:
    virtual bool AdjustTextFrameWidthAndHeight() override;
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;
    virtual SdrTableObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrTableObj* Clone() const override;
    SdrTableObj& operator=(const SdrTableObj& rObj);
    virtual void RecalcSnapRect() override;
    virtual const tools::Rectangle& GetSnapRect() const override;
diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index 13ff894..277f51e 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -136,13 +136,16 @@ class SVX_DLLPUBLIC SdrTextObj : public SdrAttrObj, public svx::ITextProvider
{
private:
    // Cell needs access to ImpGetDrawOutliner();

    friend class                sdr::table::Cell;
    friend class                sdr::table::SdrTableRtfExporter;
    friend class                sdr::table::SdrTableRTFParser;

    friend class                TextChain;
    friend class                TextChainFlow;
    friend class                EditingTextChainFlow;


    // CustomShapeproperties need to access the "bTextFrame" member:
    friend class sdr::properties::CustomShapeProperties;

@@ -269,6 +272,7 @@ private:
    SVX_DLLPRIVATE void ImpRegisterLink();
    SVX_DLLPRIVATE void ImpDeregisterLink();
    SVX_DLLPRIVATE ImpSdrObjTextLinkUserData* GetLinkUserData() const;
//  void ImpCheckItemSetChanges(const SfxItemSet& rAttr);

    /** Appends the style family to a provided style name */
    static void AppendFamilyToStyleName(OUString& styleName, SfxStyleFamily family);
@@ -302,19 +306,12 @@ protected:
    virtual void AdaptTextMinSize();

    // constructors for labeled graphical objects
    SdrTextObj(SdrModel& rSdrModel);
    SdrTextObj(
        SdrModel& rSdrModel,
        const tools::Rectangle& rNewRect);
    SdrTextObj();
    SdrTextObj(const tools::Rectangle& rNewRect);

    // constructors for text frames
    SdrTextObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewTextKind);
    SdrTextObj(
        SdrModel& rSdrModel,
        SdrObjKind eNewTextKind,
        const tools::Rectangle& rNewRect);
    SdrTextObj(SdrObjKind eNewTextKind);
    SdrTextObj(SdrObjKind eNewTextKind, const tools::Rectangle& rNewRect);

    virtual ~SdrTextObj() override;

@@ -437,6 +434,7 @@ public:
    SdrTextAniDirection GetTextAniDirection() const;

    virtual void SetPage(SdrPage* pNewPage) override;
    virtual void SetModel(SdrModel* pNewModel) override;
    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual sal_uInt16 GetObjIdentifier() const override;

@@ -444,7 +442,7 @@ public:
    virtual void TakeUnrotatedSnapRect(tools::Rectangle& rRect) const;
    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;
    virtual SdrTextObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrTextObj* Clone() const override;
    SdrTextObj& operator=(const SdrTextObj& rObj);
    virtual basegfx::B2DPolyPolygon TakeXorPoly() const override;
    virtual basegfx::B2DPolyPolygon TakeContour() const override;
diff --git a/include/svx/svdouno.hxx b/include/svx/svdouno.hxx
index d9dfb5d..48098ae 100644
--- a/include/svx/svdouno.hxx
+++ b/include/svx/svdouno.hxx
@@ -61,19 +61,15 @@ private:

public:

    explicit SdrUnoObj(
        SdrModel& rSdrModel,
        const OUString& rModelName);
    SdrUnoObj(
        SdrModel& rSdrModel,
        const OUString& rModelName,
    explicit SdrUnoObj(const OUString& rModelName);
    SdrUnoObj(const OUString& rModelName,
        const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSFac);
    virtual ~SdrUnoObj() override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual sal_uInt16 GetObjIdentifier() const override;

    virtual SdrUnoObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrUnoObj* Clone() const override;
    SdrUnoObj& operator= (const SdrUnoObj& rObj);
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
    virtual void NbcSetLayer(SdrLayerID nLayer) override;
@@ -81,6 +77,10 @@ public:
    // SpecialDrag support
    virtual bool hasSpecialDrag() const override;

    // FullDrag support
    virtual bool supportsFullDrag() const override;
    virtual SdrObject* getFullDragClone() const override;

    virtual OUString TakeObjNameSingul() const override;
    virtual OUString TakeObjNamePlural() const override;

diff --git a/include/svx/svdovirt.hxx b/include/svx/svdovirt.hxx
index 9e4e6d9..c6d626e 100644
--- a/include/svx/svdovirt.hxx
+++ b/include/svx/svdovirt.hxx
@@ -37,7 +37,7 @@ protected:
    virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;

    SdrObject&                  rRefObj; // Referenced drawing object
    tools::Rectangle            aSnapRect;
    tools::Rectangle                   aSnapRect;

protected:
    virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
@@ -47,14 +47,12 @@ protected:
    virtual void RestGeoData(const SdrObjGeoData& rGeo) override;

public:
    SdrVirtObj(
        SdrModel& rSdrModel,
        SdrObject& rNewObj);
    SdrVirtObj(SdrObject& rNewObj);
    virtual ~SdrVirtObj() override;

    SdrObject& ReferencedObj();
    const SdrObject& GetReferencedObj() const;
    virtual void NbcSetAnchorPos(const Point& rAnchorPos) override;
    virtual void SetModel(SdrModel* pNewModel) override;

    virtual void TakeObjInfo(SdrObjTransformInfoRec& rInfo) const override;
    virtual SdrInventor GetObjInventor() const override;
@@ -64,7 +62,7 @@ public:
    virtual const tools::Rectangle& GetCurrentBoundRect() const override;
    virtual const tools::Rectangle& GetLastBoundRect() const override;
    virtual void RecalcBoundRect() override;
    virtual SdrVirtObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual SdrVirtObj* Clone() const override;
    SdrVirtObj& operator=(const SdrVirtObj& rObj);

    virtual OUString TakeObjNameSingul() const override;
diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index 1ea8f1f..1a7fdb5 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -53,26 +53,21 @@ class Color;
class SfxStyleSheet;
class SvxUnoDrawPagesAccess;

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  SdrObjList
//      E3dObjList
//      SdrPage -> see continuation there

// class SdrObjList

class SVX_DLLPUBLIC SdrObjList
{
private:
    SdrObjList(const SdrObjList& rSrcList) = delete;
    SdrObjList &operator=(const SdrObjList& rSrcList) = delete;

private:
    ::std::vector<SdrObject*>   maList;
    ::std::vector<SdrObject*> maList;

protected:
friend class SdrObjListIter;
friend class SdrEditView;
    SdrObjList* pUpList;   /// parent list
    SdrModel*   pModel;    /// model to which the list belongs (Layer,ItemPool,Storage)
    SdrPage*    pPage;     /// Page containing the list, may be "this".
    SdrObject*  pOwnerObj; /// OwnerObject, if it's list of a Group object.
    tools::Rectangle   aOutRect;
@@ -80,20 +75,20 @@ friend class SdrEditView;
    SdrObjListKind eListKind;
    bool        bObjOrdNumsDirty;
    bool        bRectsDirty;

protected:
    void RecalcRects();
    void lateInitSdrObjList(const SdrObjList& rSrcList, SdrModel* pNewModel = nullptr);

    SdrObjList();
    void lateInit(const SdrObjList& rSrcList);

private:
    /// simple ActionChildInserted forwarder to have it on a central place
    static void impChildInserted(SdrObject const & rChild);
public:
    SdrObjList(SdrPage* pNewPage = nullptr);
    SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage);
    virtual ~SdrObjList();
    virtual SdrObjList* CloneSdrObjList(SdrModel* pNewModel = nullptr) const;

    void CopyObjects(const SdrObjList& rSrcList, SdrModel* pNewModel = nullptr);
    void CopyObjects(const SdrObjList& rSrcList);
    /// clean up everything (without Undo)
    void    Clear();
    SdrObjListKind GetListKind() const                  { return eListKind; }
@@ -104,7 +99,8 @@ public:
    void           SetOwnerObj(SdrObject* pNewOwner)    { pOwnerObj=pNewOwner; }
    SdrPage*       GetPage() const;
    void           SetPage(SdrPage* pNewPage);

    SdrModel*      GetModel() const;
    virtual void   SetModel(SdrModel* pNewModel);
    /// recalculate order numbers / ZIndex
    void           RecalcObjOrdNums();
    bool           IsObjOrdNumsDirty() const        { return bObjOrdNumsDirty; }
@@ -352,17 +348,6 @@ public:
  Also it's possible to request and directly set the order number (ZOrder)
  of SdrObjects.
*/

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  SdrPage
//      DlgEdPage
//      FmFormPage
//          ScDrawPage
//          SdPage
//          SwDPage
//      OReportPage

class SVX_DLLPUBLIC SdrPage : public SdrObjList, public virtual tools::WeakBase
{
    // #i9076#
@@ -373,8 +358,7 @@ class SVX_DLLPUBLIC SdrPage : public SdrObjList, public virtual tools::WeakBase
    // and thus has to set mxUnoPage (it also relies on mxUnoPage not being WeakRef)
    friend class reportdesign::OSection;

    SdrPage& operator=(const SdrPage&) = delete;
    SdrPage(const SdrPage&) = delete;
    SdrPage& operator=(const SdrPage& rSrcPage) = delete;

    // start PageUser section
private:
@@ -387,9 +371,6 @@ public:
    void AddPageUser(sdr::PageUser& rNewUser);
    void RemovePageUser(sdr::PageUser& rOldUser);

    // SdrModel access on SdrPage level
    SdrModel& getSdrModelFromSdrPage() const { return mrSdrModelFromSdrPage; }

protected:
    sdr::contact::ViewContact* CreateObjectSpecificViewContact();
public:
@@ -400,10 +381,6 @@ public:
    void ActionChanged();

private:
    // the SdrModel this page was created with, unchanged during SdrPage lifetime
    SdrModel&                   mrSdrModelFromSdrPage;

private:
    sal_Int32 mnWidth;     // Seitengroesse
    sal_Int32 mnHeight;     // Seitengroesse
    sal_Int32 mnBorderLeft; // Seitenrand links
@@ -443,13 +420,14 @@ protected:
    // to call lateInit() after copy-construction of a new object. Any initialization in derived
    // classes that needs access to the page objects must be deferred to lateInit. And it must
    // call lateInit() of its parent class.
    void lateInit(const SdrPage& rSrcPage);
    SdrPage(const SdrPage& rSrcPage);
    void lateInit(const SdrPage& rSrcPage, SdrModel* pNewModel = nullptr);

public:
    explicit SdrPage(SdrModel& rModel, bool bMasterPage=false);
    explicit SdrPage(SdrModel& rNewModel, bool bMasterPage=false);
    virtual ~SdrPage() override;

    virtual SdrPage* Clone(SdrModel* pNewModel = nullptr) const;
    virtual SdrPage* Clone() const;
    virtual SdrPage* Clone(SdrModel* pNewModel) const;
    bool             IsMasterPage() const       { return mbMaster; }
    void             SetInserted(bool bNew = true);
    bool             IsInserted() const         { return mbInserted; }
@@ -480,6 +458,8 @@ public:
    sal_Int32 GetRightBorder() const;
    sal_Int32 GetLowerBorder() const;

    virtual void SetModel(SdrModel* pNewModel) override;

    // New MasterPage interface
    bool TRG_HasMasterPage() const { return (nullptr != mpMasterPageDescriptor); }
    void TRG_SetMasterPage(SdrPage& rNew);
@@ -525,6 +505,9 @@ public:
        const sdr::contact::ViewObjectContact& rOriginal,
        const sdr::contact::DisplayInfo& rDisplayInfo,
        bool bEdit );

private:
    void impl_setModelForLayerAdmin(SdrModel* pNewModel);
};


diff --git a/include/svx/svdpntv.hxx b/include/svx/svdpntv.hxx
index 2405ad9..eb48416a 100644
--- a/include/svx/svdpntv.hxx
+++ b/include/svx/svdpntv.hxx
@@ -100,39 +100,12 @@ BitmapEx SVX_DLLPUBLIC convertMetafileToBitmapEx(
    const basegfx::B2DRange& rTargetRange,
    const sal_uInt32 nMaximumQuadraticPixels);

////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  SdrPaintView
//      SdrSnapView
//          SdrMarkView
//              SdrEditView
//                  SdrPolyEditView
//                      SdrGlueEditView
//                          SdrObjEditView
//                              SdrExchangeView
//                                  SdrDragView
//                                      SdrCreateView
//                                          SdrView
//                                              DlgEdView
//                                              GraphCtrlView
//                                              E3dView
//                                                  DrawViewWrapper
//                                                  FmFormView
//                                                      ScDrawView
//                                                      sd::View (may have more?)
//                                                          sd::DrawView
//                                                      SwDrawView
//                                              OSectionView

class SVX_DLLPUBLIC SdrPaintView : public SfxListener, public SfxRepeatTarget, public SfxBroadcaster, public ::utl::ConfigurationListener
{
private:
    friend class                SdrPageView;
    friend class                SdrGrafObj;

    // the SdrModel this view was created with, unchanged during lifetime
    SdrModel&                   mrSdrModelFromSdrView;

    SdrPageView*                mpPageView;
protected:
    SdrModel*                   mpModel;
@@ -265,13 +238,10 @@ protected:
    virtual void ModelHasChanged();

    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    // A SdrView always needs a SdrModel for lifetime (Pool, ...)
    SdrPaintView(SdrModel& rSdrModel, OutputDevice* pOut);
    SdrPaintView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrPaintView() override;

public:
    // SdrModel access on SdrView level
    SdrModel& getSdrModelFromSdrView() const { return mrSdrModelFromSdrView; }

    virtual void ClearPageView();
    SdrModel* GetModel() const { return mpModel; }
diff --git a/include/svx/svdpoev.hxx b/include/svx/svdpoev.hxx
index 187eadd..c7a33ba 100644
--- a/include/svx/svdpoev.hxx
+++ b/include/svx/svdpoev.hxx
@@ -25,7 +25,7 @@

#include <svx/ipolypolygoneditorcontroller.hxx>

class SVX_DLLPUBLIC SdrPolyEditView : public SdrEditView, public IPolyPolygonEditorController
class SVX_DLLPUBLIC SdrPolyEditView: public SdrEditView, public IPolyPolygonEditorController
{
    friend class                SdrEditView;

@@ -45,10 +45,7 @@ private:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrPolyEditView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrPolyEditView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrPolyEditView() override;

public:
diff --git a/include/svx/svdsnpv.hxx b/include/svx/svdsnpv.hxx
index 0a40c9ac..a90bdf3 100644
--- a/include/svx/svdsnpv.hxx
+++ b/include/svx/svdsnpv.hxx
@@ -90,7 +90,7 @@ enum class SdrCrookMode {
// #114409#-1 Migrate PageOrigin
class ImplPageOriginOverlay;

class SVX_DLLPUBLIC SdrSnapView : public SdrPaintView
class SVX_DLLPUBLIC SdrSnapView: public SdrPaintView
{
protected:
    // #114409#-1 Migrate PageOrigin
@@ -127,10 +127,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrSnapView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    SdrSnapView(SdrModel* pModel1, OutputDevice* pOut);
    virtual ~SdrSnapView() override;

public:
diff --git a/include/svx/svdtext.hxx b/include/svx/svdtext.hxx
index 11b91f0..020d8a4 100644
--- a/include/svx/svdtext.hxx
+++ b/include/svx/svdtext.hxx
@@ -47,6 +47,7 @@ public:
    explicit SdrText( SdrTextObj& rObject );
    virtual ~SdrText() override;

    virtual void SetModel(SdrModel* pNewModel);
    void ForceOutlinerParaObject( OutlinerMode nOutlMode );

    virtual void SetOutlinerParaObject( OutlinerParaObject* pTextObject );
@@ -59,8 +60,7 @@ public:
    // return a text-specific ItemSet
    virtual const SfxItemSet& GetItemSet() const;

    // This class does not need an own SdrModel reference - always
    // has the SdrTextObj working with so can use SdrModel::getSdrModelFromSdrObject()
    SdrModel* GetModel() const { return mpModel; }
    SdrTextObj& GetObject() const { return mrObject; }

    /** returns the current OutlinerParaObject and removes it from this instance */
@@ -76,6 +76,7 @@ protected:
private:
    std::unique_ptr<OutlinerParaObject> mpOutlinerParaObject;
    SdrTextObj& mrObject;
    SdrModel* mpModel;
    bool mbPortionInfoChecked;
};

diff --git a/include/svx/svdview.hxx b/include/svx/svdview.hxx
index 2bab7ea..e9d0f51 100644
--- a/include/svx/svdview.hxx
+++ b/include/svx/svdview.hxx
@@ -144,7 +144,7 @@ public:
};


class SVX_DLLPUBLIC SdrView : public SdrCreateView, public virtual tools::WeakBase
class SVX_DLLPUBLIC SdrView: public SdrCreateView, public virtual tools::WeakBase
{
    friend class                SdrPageView;

@@ -156,10 +156,7 @@ protected:
    SvtAccessibilityOptions maAccessibilityOptions;

public:
    explicit SdrView(
        SdrModel& rSdrModel,
        OutputDevice* pOut = nullptr);

    explicit SdrView(SdrModel* pModel1, OutputDevice* pOut = nullptr);
    virtual ~SdrView() override;

    // The default value for all dispatchers is activated. If the app for example
diff --git a/include/svx/svdxcgv.hxx b/include/svx/svdxcgv.hxx
index 52dc63b..8c4deca 100644
--- a/include/svx/svdxcgv.hxx
+++ b/include/svx/svdxcgv.hxx
@@ -25,7 +25,7 @@
#include <vcl/gdimtf.hxx>
#include <svx/svxdllapi.h>

class SVX_DLLPUBLIC SdrExchangeView : public SdrObjEditView
class SVX_DLLPUBLIC SdrExchangeView: public SdrObjEditView
{
    friend class SdrPageView;

@@ -40,9 +40,7 @@ protected:

protected:
    // #i71538# make constructors of SdrView sub-components protected to avoid incomplete incarnations which may get casted to SdrView
    SdrExchangeView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);
    SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut);

public:
    // Output all marked objects on the specified OutputDevice
@@ -74,16 +72,20 @@ public:

    Graphic         GetAllMarkedGraphic() const;

    /** Generate a Graphic for the given draw object
    /** Generate a Graphic for the given draw object in the given model

        @param rSdrObject
        @param pModel
        Must not be NULL. Denotes the draw model the object is a part
        of.

        @param pObj
        The object (can also be a group object) to retrieve a Graphic
        for.
        for. Must not be NULL.

        @return a graphical representation of the given object, as it
        appears on screen (e.g. with rotation, if any, applied).
     */
    static Graphic GetObjGraphic(const SdrObject& rSdrObject);
    static Graphic  GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj );

    // The new Draw objects are marked for all paste methods.
    // If bAddMark is true, the new Draw objects are added to an existing
diff --git a/include/svx/svxdlg.hxx b/include/svx/svxdlg.hxx
index ae84bb3..77f4437 100644
--- a/include/svx/svxdlg.hxx
+++ b/include/svx/svxdlg.hxx
@@ -464,7 +464,7 @@ public:
                const sal_uInt16 _nInitiallySelectedEvent
            ) = 0;

    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog( const SfxItemSet* pAttr, const SdrModel& rModel, const SdrObject* pObj )=0;
    virtual VclPtr<SfxAbstractTabDialog> CreateSvxFormatCellsDialog( const SfxItemSet* pAttr, SdrModel* pModel, const SdrObject* pObj )=0;

    virtual VclPtr<SvxAbstractSplitTableDialog> CreateSvxSplitTableDialog(weld::Window* pParent, bool bIsTableVertical, long nMaxVertical) = 0;

diff --git a/include/svx/unomod.hxx b/include/svx/unomod.hxx
index 04571c9..630c51c 100644
--- a/include/svx/unomod.hxx
+++ b/include/svx/unomod.hxx
@@ -32,10 +32,6 @@ SVX_DLLPUBLIC css::uno::Reference< css::container::XIndexReplace > SvxCreateNumR

class SVX_DLLPUBLIC SvxUnoDrawMSFactory : public css::lang::XMultiServiceFactory
{
protected:
    /** abstract SdrModel provider */
    virtual SdrModel* getSdrModelFromUnoModel() const = 0; //TTTT make reference return

public:
    SvxUnoDrawMSFactory() throw() {};

diff --git a/include/svx/unomodel.hxx b/include/svx/unomodel.hxx
index e637e44..ab9ab9e 100644
--- a/include/svx/unomodel.hxx
+++ b/include/svx/unomodel.hxx
@@ -31,12 +31,11 @@

class SdrModel;

class SVX_DLLPUBLIC SvxUnoDrawingModel
:   public SfxBaseModel, // implements SfxListener, OWEAKOBJECT & other
    public SvxFmMSFactory,
    public css::drawing::XDrawPagesSupplier,
    public css::lang::XServiceInfo,
    public css::ucb::XAnyCompareFactory
class SVX_DLLPUBLIC SvxUnoDrawingModel : public SfxBaseModel, // implements SfxListener, OWEAKOBJECT & other
                           public SvxFmMSFactory,
                           public css::drawing::XDrawPagesSupplier,
                           public css::lang::XServiceInfo,
                           public css::ucb::XAnyCompareFactory
{
    friend class SvxUnoDrawPagesAccess;

@@ -54,10 +53,6 @@ private:

    css::uno::Sequence< css::uno::Type > maTypeSequence;

protected:
    // SvxUnoDrawMSFactory
    virtual SdrModel* getSdrModelFromUnoModel() const override;

public:
    SvxUnoDrawingModel( SdrModel* pDoc ) throw();
    virtual ~SvxUnoDrawingModel() throw() override;
diff --git a/include/svx/unopage.hxx b/include/svx/unopage.hxx
index eefc11c6..6f84e72 100644
--- a/include/svx/unopage.hxx
+++ b/include/svx/unopage.hxx
@@ -68,8 +68,8 @@ class SVX_DLLPUBLIC SvxDrawPage : public ::cppu::WeakAggImplHelper6< css::drawin
 protected:
    cppu::OBroadcastHelper mrBHelper;

    SdrPage*        mpPage;     // TTTT should be reference
    SdrModel*       mpModel;    // TTTT probably not needed -> use from SdrPage
    SdrPage*        mpPage;
    SdrModel*       mpModel;
    SdrView*        mpView;

    void    SelectObjectsInView( const css::uno::Reference< css::drawing::XShapes >& aShapes, SdrPageView*   pPageView ) throw ();
@@ -83,6 +83,7 @@ class SVX_DLLPUBLIC SvxDrawPage : public ::cppu::WeakAggImplHelper6< css::drawin

    // Internals
    SdrPage* GetSdrPage() const { return mpPage; }
    void ChangeModel( SdrModel* pNewModel );

    // Creation of a SdrObject and insertion into the SdrPage
    SdrObject *CreateSdrObject( const css::uno::Reference< css::drawing::XShape >& xShape, bool bBeginning = false ) throw();
diff --git a/include/svx/unoshape.hxx b/include/svx/unoshape.hxx
index 422f6b1..4bb90d8 100644
--- a/include/svx/unoshape.hxx
+++ b/include/svx/unoshape.hxx
@@ -137,10 +137,8 @@ protected:
    const SvxItemPropertySet* mpPropSet;
    const SfxItemPropertyMapEntry* maPropMapEntries;

private:
    ::tools::WeakReference< SdrObject > mpSdrObjectWeakReference;

protected:
    ::tools::WeakReference< SdrObject > mpObj;
    SdrModel* mpModel;
    // translations for writer, which works in TWIPS
    void ForceMetricToItemPoolMetric(Pair& rPoint) const throw();
    void ForceMetricToItemPoolMetric(Point& rPoint) const throw() { ForceMetricToItemPoolMetric(rPoint.toPair()); }
@@ -208,13 +206,10 @@ public:
    void TakeSdrObjectOwnership();
    bool HasSdrObjectOwnership() const;

    // used exclusively by SdrObject
    void InvalidateSdrObject();
    void ChangeModel( SdrModel* pNewModel );

    // Encapsulated access to SdrObject
    SdrObject* GetSdrObject() const { return mpSdrObjectWeakReference.get(); }
    bool HasSdrObject() const { return mpSdrObjectWeakReference.is(); }

    void InvalidateSdrObject() { mpObj.reset( nullptr ); };
    SdrObject* GetSdrObject() const {return mpObj.get();}
    void SetShapeType( const OUString& ShapeType ) { maShapeType = ShapeType; }
    /// @throws css::uno::RuntimeException
    css::uno::Any GetBitmap( bool bMetaFile = false ) const;
diff --git a/include/svx/unoshtxt.hxx b/include/svx/unoshtxt.hxx
index f16358d..f38cf8a 100644
--- a/include/svx/unoshtxt.hxx
+++ b/include/svx/unoshtxt.hxx
@@ -77,6 +77,8 @@ public:
    virtual Point       LogicToPixel( const Point&, const MapMode& ) const override;
    virtual Point       PixelToLogic( const Point&, const MapMode& ) const override;

    void ChangeModel( SdrModel* pNewModel );

    void UpdateOutliner();

private:
diff --git a/include/svx/view3d.hxx b/include/svx/view3d.hxx
index be4381c..48ff9b6f 100644
--- a/include/svx/view3d.hxx
+++ b/include/svx/view3d.hxx
@@ -63,10 +63,7 @@ protected:
    void BreakSingle3DObj(E3dObject* pObj);

public:
    E3dView(
        SdrModel& rSdrModel,
        OutputDevice* pOut);

    E3dView(SdrModel* pModel, OutputDevice* pOut);
    virtual ~E3dView() override;

    // Output all marked Objects on the given OutputDevice.
diff --git a/reportdesign/inc/ReportDefinition.hxx b/reportdesign/inc/ReportDefinition.hxx
index 79c58c9..6c0883c 100644
--- a/reportdesign/inc/ReportDefinition.hxx
+++ b/reportdesign/inc/ReportDefinition.hxx
@@ -186,14 +186,7 @@ namespace reportdesign

        css::uno::Reference< css::uno::XComponentContext > getContext();

    protected:
        /** abstract SdrModel provider */
        virtual SdrModel* getSdrModelFromUnoModel() const override;

    public:
        //TTTT Needed? Or same as above?
        static std::shared_ptr<rptui::OReportModel> getSdrModel(const css::uno::Reference< css::report::XReportDefinition >& _xReportDefinition);

    private:
        DECLARE_XINTERFACE( )
        DECLARE_XTYPEPROVIDER( )
diff --git a/reportdesign/inc/RptObject.hxx b/reportdesign/inc/RptObject.hxx
index 17f4336..2017828 100644
--- a/reportdesign/inc/RptObject.hxx
+++ b/reportdesign/inc/RptObject.hxx
@@ -112,9 +112,7 @@ public:
    */
    void    releaseUnoShape() { m_xKeepShapeAlive.clear(); }

    static SdrObject* createObject(
        SdrModel& rTargetModel,
        const css::uno::Reference< css::report::XReportComponent>& _xComponent);
    static SdrObject* createObject(const css::uno::Reference< css::report::XReportComponent>& _xComponent);
    static sal_uInt16 getObjectType(const css::uno::Reference< css::report::XReportComponent>& _xComponent);
};

@@ -125,11 +123,9 @@ class REPORTDESIGN_DLLPUBLIC OCustomShape final : public SdrObjCustomShape , pub
    friend class OReportPage;
    friend class DlgEdFactory;
public:
    static OCustomShape* Create(
        SdrModel& rSdrModel,
        const css::uno::Reference< css::report::XReportComponent>& _xComponent)
    static OCustomShape* Create( const css::uno::Reference< css::report::XReportComponent>& _xComponent )
    {
        return new OCustomShape(rSdrModel, _xComponent );
        return new OCustomShape( _xComponent );
    }

    virtual ~OCustomShape() override;
@@ -143,12 +139,8 @@ public:
private:
    virtual void impl_setUnoShape( const css::uno::Reference< css::uno::XInterface >& rxUnoShape ) override;

    OCustomShape(
        SdrModel& rSdrModel,
        const css::uno::Reference< css::report::XReportComponent>& _xComponent);
    OCustomShape(
        SdrModel& rSdrModel,
        const OUString& _sComponentName);
    OCustomShape(const css::uno::Reference< css::report::XReportComponent>& _xComponent);
    OCustomShape(const OUString& _sComponentName);

    virtual void NbcMove( const Size& rSize ) override;
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
@@ -166,12 +158,9 @@ class REPORTDESIGN_DLLPUBLIC OOle2Obj final : public SdrOle2Obj , public OObject
    friend class OReportPage;
    friend class DlgEdFactory;
public:
    static OOle2Obj* Create(
        SdrModel& rSdrModel,
        const css::uno::Reference< css::report::XReportComponent>& _xComponent,
        sal_uInt16 _nType)
    static OOle2Obj* Create( const css::uno::Reference< css::report::XReportComponent>& _xComponent,sal_uInt16 _nType )
    {
        return new OOle2Obj(rSdrModel, _xComponent, _nType);
        return new OOle2Obj( _xComponent,_nType );
    }

    virtual ~OOle2Obj() override;
@@ -182,7 +171,7 @@ public:
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual SdrInventor GetObjInventor() const override;
    // Clone() should make a complete copy of the object.
    virtual OOle2Obj* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual OOle2Obj* Clone() const override;
    virtual void initializeOle() override;

    OOle2Obj& operator=(const OOle2Obj& rObj);
@@ -190,14 +179,9 @@ public:
    void initializeChart( const css::uno::Reference< css::frame::XModel>& _xModel);

private:
    OOle2Obj(
        SdrModel& rSdrModel,
        const css::uno::Reference< css::report::XReportComponent>& _xComponent,
        sal_uInt16 _nType);
    OOle2Obj(
        SdrModel& rSdrModel,
        const OUString& _sComponentName,
        sal_uInt16 _nType);
    OOle2Obj(const css::uno::Reference< css::report::XReportComponent>& _xComponent,sal_uInt16 _nType);
    OOle2Obj(const OUString& _sComponentName,sal_uInt16 _nType);


    virtual void NbcMove( const Size& rSize ) override;
    virtual void NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) override;
@@ -224,15 +208,12 @@ class REPORTDESIGN_DLLPUBLIC OUnoObject: public SdrUnoObj , public OObjectBase

    sal_uInt16   m_nObjectType;
protected:
    OUnoObject(SdrModel& rSdrModel,
        const OUString& _sComponentName,
        const OUString& rModelName,
        sal_uInt16   _nObjectType);
    OUnoObject(
        SdrModel& rSdrModel,
        const css::uno::Reference< css::report::XReportComponent>& _xComponent,
        const OUString& rModelName,
        sal_uInt16 _nObjectType);
    OUnoObject(const OUString& _sComponentName
                ,const OUString& rModelName
                ,sal_uInt16   _nObjectType);
    OUnoObject(  const css::uno::Reference< css::report::XReportComponent>& _xComponent
                ,const OUString& rModelName
                ,sal_uInt16   _nObjectType);

    virtual ~OUnoObject() override;

@@ -259,7 +240,7 @@ public:
    virtual css::uno::Reference< css::uno::XInterface > getUnoShape() override;
    virtual sal_uInt16 GetObjIdentifier() const override;
    virtual SdrInventor GetObjInventor() const override;
    virtual OUnoObject* Clone(SdrModel* pTargetModel = nullptr) const override;
    virtual OUnoObject* Clone() const override;

    OUnoObject& operator=(const OUnoObject& rObj);

diff --git a/reportdesign/inc/RptPage.hxx b/reportdesign/inc/RptPage.hxx
index 2c45c93..c168cd5 100644
--- a/reportdesign/inc/RptPage.hxx
+++ b/reportdesign/inc/RptPage.hxx
@@ -35,21 +35,20 @@ class OReportModel;
class REPORTDESIGN_DLLPUBLIC OReportPage : public SdrPage
{
    OReportPage& operator=(const OReportPage&) = delete;
    OReportPage(const OReportPage&) = delete;

    OReportModel&           rModel;
    css::uno::Reference< css::report::XSection > m_xSection;
    bool                    m_bSpecialInsertMode;
    std::vector<SdrObject*> m_aTemporaryObjectList;

    OReportPage(const OReportPage&);

    // method to remove temporary objects, created by 'special mode'
    // (BegDragObj)
    void removeTempObject(SdrObject const *_pToRemoveObj);

    virtual ~OReportPage() override;

    OReportModel& getOReportModelFromOReportPage() const { return rModel; }

protected:
    virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override;
public:
@@ -57,7 +56,9 @@ public:
    OReportPage( OReportModel& rModel
                ,const css::uno::Reference< css::report::XSection >& _xSection );

    virtual SdrPage* Clone(SdrModel* pNewModel = nullptr) const override;

    virtual SdrPage* Clone() const override;
    virtual SdrPage* Clone( SdrModel* pNewModel ) const override;

    virtual void NbcInsertObject(SdrObject* pObj, size_t nPos=SAL_MAX_SIZE) override;
    virtual SdrObject* RemoveObject(size_t nObjNum) override;
diff --git a/reportdesign/source/core/api/ReportDefinition.cxx b/reportdesign/source/core/api/ReportDefinition.cxx
index 11064f2..641b88d 100644
--- a/reportdesign/source/core/api/ReportDefinition.cxx
+++ b/reportdesign/source/core/api/ReportDefinition.cxx
@@ -532,12 +532,10 @@ struct OReportDefinitionImpl
};

OReportDefinition::OReportDefinition(uno::Reference< uno::XComponentContext > const & _xContext)
:   ::cppu::BaseMutex(),
    ReportDefinitionBase(m_aMutex),
    ReportDefinitionPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >()),
    ::comphelper::IEmbeddedHelper(),
    m_aProps(new OReportComponentProperties(_xContext)),
    m_pImpl(new OReportDefinitionImpl(m_aMutex))
: ReportDefinitionBase(m_aMutex)
,ReportDefinitionPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >())
,m_aProps(new OReportComponentProperties(_xContext))
,m_pImpl(new OReportDefinitionImpl(m_aMutex))
{
    m_aProps->m_sName  = RptResId(RID_STR_REPORT);
    osl_atomic_increment(&m_refCount);
@@ -550,16 +548,13 @@ OReportDefinition::OReportDefinition(uno::Reference< uno::XComponentContext > co
    osl_atomic_decrement( &m_refCount );
}

OReportDefinition::OReportDefinition(
    uno::Reference< uno::XComponentContext > const & _xContext,
    const uno::Reference< lang::XMultiServiceFactory>& _xFactory,
    uno::Reference< drawing::XShape >& _xShape)
:   ::cppu::BaseMutex(),
    ReportDefinitionBase(m_aMutex),
    ReportDefinitionPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >()),
    ::comphelper::IEmbeddedHelper(),
    m_aProps(new OReportComponentProperties(_xContext)),
    m_pImpl(new OReportDefinitionImpl(m_aMutex))
OReportDefinition::OReportDefinition(uno::Reference< uno::XComponentContext > const & _xContext
                                     ,const uno::Reference< lang::XMultiServiceFactory>& _xFactory
                                     ,uno::Reference< drawing::XShape >& _xShape)
: ReportDefinitionBase(m_aMutex)
,ReportDefinitionPropertySet(_xContext,IMPLEMENTS_PROPERTY_SET,uno::Sequence< OUString >())
,m_aProps(new OReportComponentProperties(_xContext))
,m_pImpl(new OReportDefinitionImpl(m_aMutex))
{
    m_aProps->m_sName  = RptResId(RID_STR_REPORT);
    m_aProps->m_xFactory = _xFactory;
@@ -2020,11 +2015,6 @@ std::shared_ptr<rptui::OReportModel> OReportDefinition::getSdrModel(const uno::R
    return pReportModel;
}

SdrModel* OReportDefinition::getSdrModelFromUnoModel() const
{
    return m_pImpl->m_pReportModel.get();
}

uno::Reference< uno::XInterface > SAL_CALL OReportDefinition::createInstanceWithArguments( const OUString& aServiceSpecifier, const uno::Sequence< uno::Any >& _aArgs)
{
    ::osl::MutexGuard aGuard(m_aMutex);
diff --git a/reportdesign/source/core/sdr/ReportDrawPage.cxx b/reportdesign/source/core/sdr/ReportDrawPage.cxx
index cf73d9c..e67f7a9 100644
--- a/reportdesign/source/core/sdr/ReportDrawPage.cxx
+++ b/reportdesign/source/core/sdr/ReportDrawPage.cxx
@@ -29,9 +29,9 @@
#include <svx/svdmodel.hxx>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/embed/Aspects.hpp>

#include <tools/diagnose_ex.h>
#include <svx/unoshape.hxx>
#include <svx/svdpage.hxx>

namespace reportdesign
{
@@ -49,12 +49,7 @@ SdrObject* OReportDrawPage::CreateSdrObject_(const uno::Reference< drawing::XSha
{
    uno::Reference< report::XReportComponent> xReportComponent(xDescr,uno::UNO_QUERY);
    if ( xReportComponent.is() )
    {
        return OObjectBase::createObject(
            GetSdrPage()->getSdrModelFromSdrPage(),
            xReportComponent);
    }

        return OObjectBase::createObject(xReportComponent);
    return SvxDrawPage::CreateSdrObject_( xDescr );
}

@@ -106,7 +101,7 @@ uno::Reference< drawing::XShape >  OReportDrawPage::CreateShape( SdrObject *pObj
                sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
                uno::Reference < embed::XEmbeddedObject > xObj;
                OUString sName;
                xObj = pObj->getSdrModelFromSdrObject().GetPersist()->getEmbeddedObjectContainer().CreateEmbeddedObject(
                xObj = pObj->GetModel()->GetPersist()->getEmbeddedObjectContainer().CreateEmbeddedObject(
                    ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(
                    "80243D39-6741-46C5-926E-069164FF87BB"), sName );
                OSL_ENSURE(xObj.is(),"Embedded Object could not be created!");
@@ -136,8 +131,8 @@ uno::Reference< drawing::XShape >  OReportDrawPage::CreateShape( SdrObject *pObj

        try
        {
            OReportModel& rRptModel(static_cast< OReportModel& >(pObj->getSdrModelFromSdrObject()));
            xRet.set( rRptModel.createShape(sServiceName,xShape,bChangeOrientation ? 0 : 1), uno::UNO_QUERY_THROW );
            OReportModel* pRptModel = static_cast<OReportModel*>(pObj->GetModel());
            xRet.set( pRptModel->createShape(sServiceName,xShape,bChangeOrientation ? 0 : 1), uno::UNO_QUERY_THROW );
        }
        catch( const uno::Exception& )
        {
diff --git a/reportdesign/source/core/sdr/ReportUndoFactory.cxx b/reportdesign/source/core/sdr/ReportUndoFactory.cxx
index ee64aed..e40411c3 100644
--- a/reportdesign/source/core/sdr/ReportUndoFactory.cxx
+++ b/reportdesign/source/core/sdr/ReportUndoFactory.cxx
@@ -35,9 +35,9 @@ SdrUndoAction* lcl_createUndo(SdrObject& rObject, Action _eAction, const char* p
    uno::Reference< report::XGroup> xGroup = xSection->getGroup();
    SdrUndoAction* pUndo = nullptr;
    if ( xGroup.is() )
        pUndo = new OUndoGroupSectionAction(rObject.getSdrModelFromSdrObject(),_eAction,OGroupHelper::getMemberFunction(xSection),xGroup,xReportComponent,pCommentId);
        pUndo = new OUndoGroupSectionAction(*rObject.GetModel(),_eAction,OGroupHelper::getMemberFunction(xSection),xGroup,xReportComponent,pCommentId);
    else
        pUndo = new OUndoReportSectionAction(rObject.getSdrModelFromSdrObject(),_eAction,OReportHelper::getMemberFunction(xSection),xSection->getReportDefinition(),xReportComponent,pCommentId);
        pUndo = new OUndoReportSectionAction(*rObject.GetModel(),_eAction,OReportHelper::getMemberFunction(xSection),xSection->getReportDefinition(),xReportComponent,pCommentId);
    return pUndo;
}

diff --git a/reportdesign/source/core/sdr/RptObject.cxx b/reportdesign/source/core/sdr/RptObject.cxx
index 737c87e..a0af522 100644
--- a/reportdesign/source/core/sdr/RptObject.cxx
+++ b/reportdesign/source/core/sdr/RptObject.cxx
@@ -107,9 +107,7 @@ sal_uInt16 OObjectBase::getObjectType(const uno::Reference< report::XReportCompo
    return 0;
}

SdrObject* OObjectBase::createObject(
    SdrModel& rTargetModel,
    const uno::Reference< report::XReportComponent>& _xComponent)
SdrObject* OObjectBase::createObject(const uno::Reference< report::XReportComponent>& _xComponent)
{
    SdrObject* pNewObj = nullptr;
    sal_uInt16 nType = OObjectBase::getObjectType(_xComponent);
@@ -117,11 +115,9 @@ SdrObject* OObjectBase::createObject(
    {
        case OBJ_DLG_FIXEDTEXT:
            {
                OUnoObject* pUnoObj = new OUnoObject(
                    rTargetModel,
                    _xComponent,
                    OUString("com.sun.star.form.component.FixedText"),
                    OBJ_DLG_FIXEDTEXT);
                OUnoObject* pUnoObj = new OUnoObject( _xComponent
                                    ,OUString("com.sun.star.form.component.FixedText")
                                    ,OBJ_DLG_FIXEDTEXT);
                pNewObj = pUnoObj;

                uno::Reference<beans::XPropertySet> xControlModel(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
@@ -130,31 +126,23 @@ SdrObject* OObjectBase::createObject(
            }
            break;
        case OBJ_DLG_IMAGECONTROL:
            pNewObj = new OUnoObject(
                rTargetModel,
                _xComponent,
                OUString("com.sun.star.form.component.DatabaseImageControl"),
                OBJ_DLG_IMAGECONTROL);
            pNewObj = new OUnoObject(_xComponent
                                    ,OUString("com.sun.star.form.component.DatabaseImageControl")
                                    ,OBJ_DLG_IMAGECONTROL);
            break;
        case OBJ_DLG_FORMATTEDFIELD:
            pNewObj = new OUnoObject(
                rTargetModel,
                _xComponent,
                OUString("com.sun.star.form.component.FormattedField"),
                OBJ_DLG_FORMATTEDFIELD);
            pNewObj = new OUnoObject( _xComponent
                                    ,OUString("com.sun.star.form.component.FormattedField")
                                    ,OBJ_DLG_FORMATTEDFIELD);
            break;
        case OBJ_DLG_HFIXEDLINE:
        case OBJ_DLG_VFIXEDLINE:
            pNewObj = new OUnoObject(
                rTargetModel,
                _xComponent,
                OUString("com.sun.star.awt.UnoControlFixedLineModel"),
                nType);
            pNewObj = new OUnoObject( _xComponent
                                    ,OUString("com.sun.star.awt.UnoControlFixedLineModel")
                                    ,nType);
            break;
        case OBJ_CUSTOMSHAPE:
            pNewObj = OCustomShape::Create(
                rTargetModel,
                _xComponent);
            pNewObj = OCustomShape::Create( _xComponent );
            try
            {
                bool bOpaque = false;
@@ -168,10 +156,7 @@ SdrObject* OObjectBase::createObject(
            break;
        case OBJ_DLG_SUBREPORT:
        case OBJ_OLE2:
            pNewObj = OOle2Obj::Create(
                rTargetModel,
                _xComponent,
                nType);
            pNewObj = OOle2Obj::Create( _xComponent,nType );
            break;
        default:
            OSL_FAIL("Unknown object id");
@@ -470,21 +455,19 @@ uno::Reference< uno::XInterface > OObjectBase::getUnoShapeOf( SdrObject& _rSdrOb
    return xShape;
}

OCustomShape::OCustomShape(
    SdrModel& rSdrModel,
    const uno::Reference< report::XReportComponent>& _xComponent)
:   SdrObjCustomShape(rSdrModel)
    ,OObjectBase(_xComponent)

OCustomShape::OCustomShape(const uno::Reference< report::XReportComponent>& _xComponent
                           )
          :SdrObjCustomShape()
          ,OObjectBase(_xComponent)
{
    impl_setUnoShape( uno::Reference< uno::XInterface >(_xComponent,uno::UNO_QUERY) );
    m_bIsListening = true;
}

OCustomShape::OCustomShape(
    SdrModel& rSdrModel,
    const OUString& _sComponentName)
:   SdrObjCustomShape(rSdrModel)
    ,OObjectBase(_sComponentName)
OCustomShape::OCustomShape(const OUString& _sComponentName)
          :SdrObjCustomShape()
          ,OObjectBase(_sComponentName)
{
    m_bIsListening = true;
}
@@ -517,8 +500,8 @@ void OCustomShape::NbcMove( const Size& rSize )

        if ( m_xReportComponent.is() )
        {
            OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
            OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
            OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
            OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
            m_xReportComponent->setPositionX(m_xReportComponent->getPositionX() + rSize.Width());
            m_xReportComponent->setPositionY(m_xReportComponent->getPositionY() + rSize.Height());
        }
@@ -550,12 +533,13 @@ bool OCustomShape::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
    bool bResult = SdrObjCustomShape::EndCreate(rStat, eCmd);
    if ( bResult )
    {
        OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
        OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());

        if ( !m_xReportComponent.is() )
            m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);

        OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
        if ( pRptModel )
        {
            OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
            if ( !m_xReportComponent.is() )
                m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
        }
        SetPropsFromRect(GetSnapRect());
    }

@@ -574,8 +558,8 @@ uno::Reference< uno::XInterface > OCustomShape::getUnoShape()
    uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
    if ( !m_xReportComponent.is() )
    {
        OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
        OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
        OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
        OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
        m_xReportComponent.set(xShape,uno::UNO_QUERY);
    }
    return xShape;
@@ -588,27 +572,24 @@ void OCustomShape::impl_setUnoShape( const uno::Reference< uno::XInterface >& rx
    m_xReportComponent.clear();
}

OUnoObject::OUnoObject(
    SdrModel& rSdrModel,
    const OUString& _sComponentName,
    const OUString& rModelName,
    sal_uInt16 _nObjectType)
:   SdrUnoObj(rSdrModel, rModelName)
    ,OObjectBase(_sComponentName)
    ,m_nObjectType(_nObjectType)

OUnoObject::OUnoObject(const OUString& _sComponentName
                       ,const OUString& rModelName
                       ,sal_uInt16   _nObjectType)
          :SdrUnoObj(rModelName)
          ,OObjectBase(_sComponentName)
          ,m_nObjectType(_nObjectType)
{
    if ( !rModelName.isEmpty() )
        impl_initializeModel_nothrow();
}

OUnoObject::OUnoObject(
    SdrModel& rSdrModel,
    const uno::Reference< report::XReportComponent>& _xComponent,
    const OUString& rModelName,
    sal_uInt16 _nObjectType)
:   SdrUnoObj(rSdrModel, rModelName)
    ,OObjectBase(_xComponent)
    ,m_nObjectType(_nObjectType)
OUnoObject::OUnoObject(const uno::Reference< report::XReportComponent>& _xComponent
                       ,const OUString& rModelName
                       ,sal_uInt16   _nObjectType)
          :SdrUnoObj(rModelName)
          ,OObjectBase(_xComponent)
          ,m_nObjectType(_nObjectType)
{
    impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );

@@ -645,8 +626,12 @@ void OUnoObject::impl_setReportComponent_nothrow()
    if ( m_xReportComponent.is() )
        return;

    OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
    OXUndoEnvironment::OUndoEnvLock aLock( rRptModel.GetUndoEnv() );
    OReportModel* pReportModel = static_cast<OReportModel*>(GetModel());
    OSL_ENSURE( pReportModel, "OUnoObject::impl_setReportComponent_nothrow: no report model!" );
    if ( !pReportModel )
        return;

    OXUndoEnvironment::OUndoEnvLock aLock( pReportModel->GetUndoEnv() );
    m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);

    impl_initializeModel_nothrow();
@@ -680,14 +665,13 @@ void OUnoObject::NbcMove( const Size& rSize )
        if ( m_xReportComponent.is() )
        {
            bool bUndoMode = false;
            OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));

            if (rRptModel.GetUndoEnv().IsUndoMode())
            OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
            if (pRptModel->GetUndoEnv().IsUndoMode())
            {
                // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
                bUndoMode = true;
            }
            OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
            OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());

            // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
            int nNewX = m_xReportComponent->getPositionX() + rSize.Width();
@@ -703,7 +687,7 @@ void OUnoObject::NbcMove( const Size& rSize )
        }
        if (bPositionFixed)
        {
            getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
            GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
        }
        // set geometry properties
        SetPropsFromRect(GetLogicRect());
@@ -883,11 +867,6 @@ void OUnoObject::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUn
    releaseUnoShape();
}

OUnoObject* OUnoObject::Clone(SdrModel* pTargetModel) const
{
    return CloneHelper< OUnoObject >(pTargetModel);
}

OUnoObject& OUnoObject::operator=(const OUnoObject& rObj)
{
    if( this == &rObj )
@@ -902,28 +881,29 @@ OUnoObject& OUnoObject::operator=(const OUnoObject& rObj)
    return *this;
}

// OOle2Obj
OOle2Obj::OOle2Obj(
    SdrModel& rSdrModel,
    const uno::Reference< report::XReportComponent>& _xComponent,
    sal_uInt16 _nType)
:   SdrOle2Obj(rSdrModel)
    ,OObjectBase(_xComponent)
    ,m_nType(_nType)
    ,m_bOnlyOnce(true)
OUnoObject* OUnoObject::Clone() const
{
    return CloneHelper< OUnoObject >();
}

// OOle2Obj

OOle2Obj::OOle2Obj(const uno::Reference< report::XReportComponent>& _xComponent,sal_uInt16 _nType)
          :SdrOle2Obj()
          ,OObjectBase(_xComponent)
          ,m_nType(_nType)
          ,m_bOnlyOnce(true)
{

    impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );
    m_bIsListening = true;
}

OOle2Obj::OOle2Obj(
    SdrModel& rSdrModel,
    const OUString& _sComponentName,
    sal_uInt16 _nType)
:   SdrOle2Obj(rSdrModel)
    ,OObjectBase(_sComponentName)
    ,m_nType(_nType)
    ,m_bOnlyOnce(true)
OOle2Obj::OOle2Obj(const OUString& _sComponentName,sal_uInt16 _nType)
          :SdrOle2Obj()
          ,OObjectBase(_sComponentName)
          ,m_nType(_nType)
          ,m_bOnlyOnce(true)
{
    m_bIsListening = true;
}
@@ -960,14 +940,13 @@ void OOle2Obj::NbcMove( const Size& rSize )
        if ( m_xReportComponent.is() )
        {
            bool bUndoMode = false;
            OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));

            if (rRptModel.GetUndoEnv().IsUndoMode())
            OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
            if (pRptModel->GetUndoEnv().IsUndoMode())
            {
                // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
                bUndoMode = true;
            }
            OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
            OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());

            // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
            int nNewX = m_xReportComponent->getPositionX() + rSize.Width();
@@ -988,7 +967,7 @@ void OOle2Obj::NbcMove( const Size& rSize )
        }
        if (bPositionFixed)
        {
            getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
            GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
        }
        // set geometry properties
        SetPropsFromRect(GetLogicRect());
@@ -1034,12 +1013,13 @@ bool OOle2Obj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
    bool bResult = SdrOle2Obj::EndCreate(rStat, eCmd);
    if ( bResult )
    {
        OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
        OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());

        if ( !m_xReportComponent.is() )
            m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);

        OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
        if ( pRptModel )
        {
            OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
            if ( !m_xReportComponent.is() )
                m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
        }
        // set geometry properties
        SetPropsFromRect(GetLogicRect());
    }
@@ -1058,8 +1038,8 @@ uno::Reference< uno::XInterface > OOle2Obj::getUnoShape()
    uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
    if ( !m_xReportComponent.is() )
    {
        OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
        OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
        OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
        OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
        m_xReportComponent.set(xShape,uno::UNO_QUERY);
    }
    return xShape;
@@ -1088,32 +1068,33 @@ uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider(const 
    return xSource;
}

// Clone() should make a complete copy of the object.
OOle2Obj* OOle2Obj::Clone(SdrModel* pTargetModel) const
{
    return CloneHelper< OOle2Obj >(pTargetModel);
}

OOle2Obj& OOle2Obj::operator=(const OOle2Obj& rObj)
{
    if( this == &rObj )
        return *this;
    SdrOle2Obj::operator=(rObj);

    OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
    OReportModel* pRptModel = static_cast<OReportModel*>(rObj.GetModel());
    svt::EmbeddedObjectRef::TryRunningState( GetObjRef() );
    impl_createDataProvider_nothrow(rRptModel.getReportDefinition().get());
    impl_createDataProvider_nothrow(pRptModel->getReportDefinition().get());

    uno::Reference< chart2::data::XDatabaseDataProvider > xSource( lcl_getDataProvider(rObj.GetObjRef()) );
    uno::Reference< chart2::data::XDatabaseDataProvider > xDest( lcl_getDataProvider(GetObjRef()) );
    if ( xSource.is() && xDest.is() )
        comphelper::copyProperties(xSource.get(),xDest.get());

    initializeChart(rRptModel.getReportDefinition().get());
    initializeChart(pRptModel->getReportDefinition().get());

    return *this;
}


// Clone() should make a complete copy of the object.
OOle2Obj* OOle2Obj::Clone() const
{
    return CloneHelper< OOle2Obj >();
}

void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference< frame::XModel>& _xModel)
{
    try
@@ -1142,8 +1123,8 @@ void OOle2Obj::initializeOle()
    {
        m_bOnlyOnce = false;
        uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
        OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
        rRptModel.GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
        OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
        pRptModel->GetUndoEnv().AddElement(lcl_getDataProvider(xObj));

        uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
        if( xCompSupp.is() )
@@ -1174,8 +1155,8 @@ void OOle2Obj::initializeChart( const uno::Reference< frame::XModel>& _xModel)
        if ( !lcl_getDataProvider(xObj).is() )
            impl_createDataProvider_nothrow(_xModel);

        OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
        rRptModel.GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
        OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
        pRptModel->GetUndoEnv().AddElement(lcl_getDataProvider(xObj));

        ::comphelper::NamedValueCollection aArgs;
        aArgs.put( "CellRangeRepresentation", uno::makeAny( OUString( "all" ) ) );
diff --git a/reportdesign/source/core/sdr/RptPage.cxx b/reportdesign/source/core/sdr/RptPage.cxx
index b4e0980..0d3465e 100644
--- a/reportdesign/source/core/sdr/RptPage.cxx
+++ b/reportdesign/source/core/sdr/RptPage.cxx
@@ -28,29 +28,48 @@ namespace rptui
{
using namespace ::com::sun::star;

OReportPage::OReportPage(
    OReportModel& _rModel,
    const uno::Reference< report::XSection >& _xSection)
:   SdrPage(_rModel, false/*bMasterPage*/)

OReportPage::OReportPage( OReportModel& _rModel
                         ,const uno::Reference< report::XSection >& _xSection )
    :SdrPage( _rModel, false/*bMasterPage*/ )
    ,rModel(_rModel)
    ,m_xSection(_xSection)
    ,m_bSpecialInsertMode(false)
     ,m_bSpecialInsertMode(false)
{
}


OReportPage::OReportPage( const OReportPage& rPage )
    :SdrPage( rPage )
    ,rModel(rPage.rModel)
     ,m_xSection(rPage.m_xSection)
     ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode)
     ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList)
{
}


OReportPage::~OReportPage()
{
}

SdrPage* OReportPage::Clone(SdrModel* pNewModel) const

SdrPage* OReportPage::Clone() const
{
    OReportModel& rOReportModel(static_cast< OReportModel& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    OReportPage* pClonedOReportPage(
        new OReportPage(
            rOReportModel,
            m_xSection));
    pClonedOReportPage->SdrPage::lateInit(*this);
    return pClonedOReportPage;
    return Clone(nullptr);
}

SdrPage* OReportPage::Clone( SdrModel* const pNewModel ) const
{
    OReportPage *const pNewPage = new OReportPage( *this );
    OReportModel* pReportModel = nullptr;
    if ( pNewModel )
    {
        pReportModel = dynamic_cast<OReportModel*>( pNewModel );
        assert( pReportModel );
    }
    pNewPage->lateInit( *this, pReportModel );
    return pNewPage;
}


diff --git a/reportdesign/source/ui/inc/SectionView.hxx b/reportdesign/source/ui/inc/SectionView.hxx
index df3cbc7..c5c4866 100644
--- a/reportdesign/source/ui/inc/SectionView.hxx
+++ b/reportdesign/source/ui/inc/SectionView.hxx
@@ -42,11 +42,7 @@ private:
    void operator =(const OSectionView&) = delete;
public:

    OSectionView(
        SdrModel& rSdrModel,
        OReportSection* _pSectionWindow,
        OReportWindow* pEditor);

    OSectionView( SdrModel* pModel, OReportSection* _pSectionWindow, OReportWindow* pEditor );
    virtual ~OSectionView() override;

    virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
diff --git a/reportdesign/source/ui/report/ReportController.cxx b/reportdesign/source/ui/report/ReportController.cxx
index 84a8569..10e813d 100644
--- a/reportdesign/source/ui/report/ReportController.cxx
+++ b/reportdesign/source/ui/report/ReportController.cxx
@@ -3107,11 +3107,7 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co
    uno::Reference< report::XReportComponent> xShapeProp;
    if ( _nObjectId == OBJ_CUSTOMSHAPE )
    {
        pNewControl = SdrObjFactory::MakeNewObject(
            *m_aReportModel,
            SdrInventor::ReportDesign,
            _nObjectId,
            pSectionWindow->getReportSection().getPage());
        pNewControl = SdrObjFactory::MakeNewObject( SdrInventor::ReportDesign, _nObjectId, pSectionWindow->getReportSection().getPage(),m_aReportModel.get() );
        xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY);
        OUString sCustomShapeType = getDesignView()->GetInsertObjString();
        if ( sCustomShapeType.isEmpty() )
@@ -3121,11 +3117,7 @@ void OReportController::createControl(const Sequence< PropertyValue >& _aArgs,co
    }
    else if ( _nObjectId == OBJ_OLE2 || OBJ_DLG_SUBREPORT == _nObjectId  )
    {
        pNewControl = SdrObjFactory::MakeNewObject(
            *m_aReportModel,
            SdrInventor::ReportDesign,
            _nObjectId,
            pSectionWindow->getReportSection().getPage());
        pNewControl = SdrObjFactory::MakeNewObject( SdrInventor::ReportDesign, _nObjectId, pSectionWindow->getReportSection().getPage(),m_aReportModel.get() );

        pNewControl->SetLogicRect(tools::Rectangle(3000,500,8000,5500)); // switch height and width
        xShapeProp.set(pNewControl->getUnoShape(),uno::UNO_QUERY_THROW);
diff --git a/reportdesign/source/ui/report/ReportSection.cxx b/reportdesign/source/ui/report/ReportSection.cxx
index 27e46710..9cca7d8 100644
--- a/reportdesign/source/ui/report/ReportSection.cxx
+++ b/reportdesign/source/ui/report/ReportSection.cxx
@@ -183,10 +183,7 @@ void OReportSection::fill()
    m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
    m_pPage = m_pModel->getPage(m_xSection);

    m_pView = new OSectionView(
        *m_pModel,
        this,
        m_pParent->getViewsWindow()->getView());
    m_pView = new OSectionView( m_pModel.get(), this, m_pParent->getViewsWindow()->getView() );

    // #i93597# tell SdrPage that only left and right page border is defined
    // instead of the full rectangle definition
@@ -265,10 +262,10 @@ void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyC
                        SdrObject* pObject = pShape ? pShape->GetSdrObject() : nullptr;
                        if ( pObject )
                        {
                            // Clone to target SdrModel
                            SdrObject* pNewObj(pObject->Clone(m_pModel.get()));
                            SdrObject* pNewObj = pObject->Clone();

                            pNewObj->SetPage( m_pPage );
                            pNewObj->SetModel( m_pModel.get() );
                            m_pPage->InsertObject(pNewObj, SAL_MAX_SIZE);

                            tools::Rectangle aRet(VCLPoint((*pCopiesIter)->getPosition()),VCLSize((*pCopiesIter)->getSize()));
@@ -609,7 +606,7 @@ void OReportSection::createDefault(const OUString& _sType,SdrObject* _pObj)
                        {
                            const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                            SfxItemSet aDest(
                                _pObj->getSdrModelFromSdrObject().GetItemPool(),
                                _pObj->GetModel()->GetItemPool(),
                                svl::Items<
                                    // Ranges from SdrAttrObj:
                                    SDRATTR_START, SDRATTR_SHADOW_LAST,
diff --git a/reportdesign/source/ui/report/SectionView.cxx b/reportdesign/source/ui/report/SectionView.cxx
index ea01291..06b594f 100644
--- a/reportdesign/source/ui/report/SectionView.cxx
+++ b/reportdesign/source/ui/report/SectionView.cxx
@@ -34,11 +34,9 @@ namespace rptui
{
    using namespace ::com::sun::star;

OSectionView::OSectionView(
    SdrModel& rSdrModel,
    OReportSection* _pSectionWindow,
    OReportWindow* pEditor)
:   SdrView(rSdrModel, _pSectionWindow)

OSectionView::OSectionView( SdrModel* pModel, OReportSection* _pSectionWindow, OReportWindow* pEditor )
    :SdrView( pModel, _pSectionWindow )
    ,m_pReportWindow( pEditor )
    ,m_pSectionWindow(_pSectionWindow)
{
diff --git a/reportdesign/source/ui/report/ViewsWindow.cxx b/reportdesign/source/ui/report/ViewsWindow.cxx
index 72f74f2..341dc46 100644
--- a/reportdesign/source/ui/report/ViewsWindow.cxx
+++ b/reportdesign/source/ui/report/ViewsWindow.cxx
@@ -1015,11 +1015,9 @@ void OViewsWindow::BegDragObj_createInvisibleObjectAtPosition(const tools::Recta

        if ( &rView != &_rSection )
        {
            SdrObject *pNewObj = new SdrUnoObj(
                rView.getSdrModelFromSdrView(),
                "com.sun.star.form.component.FixedText");

            SdrObject *pNewObj = new SdrUnoObj("com.sun.star.form.component.FixedText");
            pNewObj->SetLogicRect(_aRect);

            pNewObj->Move(Size(0, aNewPos.Y()));
            bool bChanged = rView.GetModel()->IsChanged();
            rReportSection.getPage()->InsertObject(pNewObj);
diff --git a/reportdesign/source/ui/report/dlgedfac.cxx b/reportdesign/source/ui/report/dlgedfac.cxx
index 4a41683..1a59852 100644
--- a/reportdesign/source/ui/report/dlgedfac.cxx
+++ b/reportdesign/source/ui/report/dlgedfac.cxx
@@ -47,30 +47,29 @@ IMPL_STATIC_LINK(
    DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
{
    SdrObject* pNewObj = nullptr;

    if ( aParams.nInventor == SdrInventor::ReportDesign )
    {
        switch( aParams.nObjIdentifier )
        {
            case OBJ_DLG_FIXEDTEXT:
                    pNewObj = new OUnoObject(aParams.rSdrModel, SERVICE_FIXEDTEXT
                    pNewObj = new OUnoObject( SERVICE_FIXEDTEXT
                                                        ,OUString("com.sun.star.form.component.FixedText")
                                                        ,OBJ_DLG_FIXEDTEXT);
                    break;
            case OBJ_DLG_IMAGECONTROL:
                    pNewObj = new OUnoObject(aParams.rSdrModel, SERVICE_IMAGECONTROL
                    pNewObj = new OUnoObject( SERVICE_IMAGECONTROL
                                                        ,OUString("com.sun.star.form.component.DatabaseImageControl")
                                                        ,OBJ_DLG_IMAGECONTROL);
                    break;
            case OBJ_DLG_FORMATTEDFIELD:
                    pNewObj = new OUnoObject(aParams.rSdrModel, SERVICE_FORMATTEDFIELD
                    pNewObj = new OUnoObject( SERVICE_FORMATTEDFIELD
                                                        ,OUString("com.sun.star.form.component.FormattedField")
                                                        ,OBJ_DLG_FORMATTEDFIELD);
                    break;
            case OBJ_DLG_VFIXEDLINE:
            case OBJ_DLG_HFIXEDLINE:
                {
                    OUnoObject* pObj = new OUnoObject(aParams.rSdrModel, SERVICE_FIXEDLINE
                    OUnoObject* pObj = new OUnoObject( SERVICE_FIXEDLINE
                                                        ,OUString("com.sun.star.awt.UnoControlFixedLineModel")
                                                        ,aParams.nObjIdentifier);
                    pNewObj = pObj;
@@ -82,13 +81,13 @@ IMPL_STATIC_LINK(
                }
                break;
            case OBJ_CUSTOMSHAPE:
                pNewObj = new OCustomShape(aParams.rSdrModel, SERVICE_SHAPE);
                pNewObj = new OCustomShape(SERVICE_SHAPE);
                break;
            case OBJ_DLG_SUBREPORT:
                pNewObj = new OOle2Obj(aParams.rSdrModel, SERVICE_REPORTDEFINITION, OBJ_DLG_SUBREPORT);
                pNewObj = new OOle2Obj(SERVICE_REPORTDEFINITION,OBJ_DLG_SUBREPORT);
                break;
            case OBJ_OLE2:
                pNewObj = new OOle2Obj(aParams.rSdrModel, OUString("com.sun.star.chart2.ChartDocument"),OBJ_OLE2);
                pNewObj = new OOle2Obj(OUString("com.sun.star.chart2.ChartDocument"),OBJ_OLE2);
                break;
            default:
                OSL_FAIL("Unknown object id");
diff --git a/reportdesign/source/ui/report/dlgedfunc.cxx b/reportdesign/source/ui/report/dlgedfunc.cxx
index 0c465d1..c66e3d0 100644
--- a/reportdesign/source/ui/report/dlgedfunc.cxx
+++ b/reportdesign/source/ui/report/dlgedfunc.cxx
@@ -450,15 +450,18 @@ void DlgEdFunc::colorizeOverlappedObject(SdrObject* _pOverlappedObj)
        uno::Reference<report::XReportComponent> xComponent = pObj->getReportComponent();
        if (xComponent.is() && xComponent != m_xOverlappingObj)
        {
            OReportModel& rRptModel(static_cast< OReportModel& >(_pOverlappedObj->getSdrModelFromSdrObject()));
            OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
            OReportModel* pRptModel = static_cast<OReportModel*>(_pOverlappedObj->GetModel());
            if ( pRptModel )
            {
                OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());

            // uncolorize an old object, if there is one
            unColorizeOverlappedObj();
                // uncolorize an old object, if there is one
                unColorizeOverlappedObj();

            m_nOldColor = lcl_setColorOfObject(xComponent, m_nOverlappedControlColor);
            m_xOverlappingObj = xComponent;
            m_pOverlappingObj = _pOverlappedObj;
                m_nOldColor = lcl_setColorOfObject(xComponent, m_nOverlappedControlColor);
                m_xOverlappingObj = xComponent;
                m_pOverlappingObj = _pOverlappedObj;
            }
        }
    }
}
@@ -468,12 +471,15 @@ void DlgEdFunc::unColorizeOverlappedObj()
    // uncolorize an old object, if there is one
    if (m_xOverlappingObj.is())
    {
        OReportModel& rRptModel(static_cast< OReportModel& >(m_pOverlappingObj->getSdrModelFromSdrObject()));
        OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
        OReportModel* pRptModel = static_cast<OReportModel*>(m_pOverlappingObj->GetModel());
        if ( pRptModel )
        {
            OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());

        lcl_setColorOfObject(m_xOverlappingObj, m_nOldColor);
        m_xOverlappingObj = nullptr;
        m_pOverlappingObj = nullptr;
            lcl_setColorOfObject(m_xOverlappingObj, m_nOldColor);
            m_xOverlappingObj = nullptr;
            m_pOverlappingObj = nullptr;
        }
    }
}

diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 8c7382c..f86c904 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -124,9 +124,6 @@ private:
protected:
    const SfxItemPropertySet&   GetPropertySet() const { return aPropSet; }

    /** abstract SdrModel provider */
    virtual SdrModel* getSdrModelFromUnoModel() const override;

public:
                            ScModelObj(ScDocShell* pDocSh);
    virtual                 ~ScModelObj() override;
diff --git a/sc/inc/drawpage.hxx b/sc/inc/drawpage.hxx
index cbbaff9..8f93482 100644
--- a/sc/inc/drawpage.hxx
+++ b/sc/inc/drawpage.hxx
@@ -24,18 +24,21 @@

class ScDrawLayer;

class ScDrawPage : public FmFormPage
class ScDrawPage: public FmFormPage
{
    ScDrawPage& operator=(const ScDrawPage&) = delete;
    ScDrawPage(const ScDrawPage&) = delete;

public:
    explicit ScDrawPage(ScDrawLayer& rNewModel, bool bMasterPage);
    virtual ~ScDrawPage() override;

    virtual ScDrawPage* Clone(SdrModel* pNewModel = nullptr) const override;
    virtual ScDrawPage* Clone() const override;
    virtual ScDrawPage* Clone(SdrModel* pNewModel) const override;

    virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override;

private:
    ScDrawPage(const ScDrawPage& rSrcPage);
};

#endif
diff --git a/sc/qa/extras/anchor.cxx b/sc/qa/extras/anchor.cxx
index baa609a..e1130b7 100644
--- a/sc/qa/extras/anchor.cxx
+++ b/sc/qa/extras/anchor.cxx
@@ -170,7 +170,7 @@ void ScAnchorTest::testTdf76183()

    // Add a circle somewhere below first row.
    const tools::Rectangle aOrigRect = tools::Rectangle(1000, 1000, 1200, 1200);
    SdrCircObj* pObj = new SdrCircObj(*pDrawLayer, OBJ_CIRC, aOrigRect);
    SdrCircObj* pObj = new SdrCircObj(OBJ_CIRC, aOrigRect);
    pPage->InsertObject(pObj);
    // Anchor to cell
    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0, false);
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 907c8f6..eff48bf 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -2708,7 +2708,7 @@ void Test::testGraphicsInGroup()
    {
        //Add a square
        tools::Rectangle aOrigRect(2,2,100,100);
        SdrRectObj *pObj = new SdrRectObj(*pDrawLayer, aOrigRect);
        SdrRectObj *pObj = new SdrRectObj(aOrigRect);
        pPage->InsertObject(pObj);
        const tools::Rectangle &rNewRect = pObj->GetLogicRect();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("must have equal position and size",
@@ -2749,7 +2749,7 @@ void Test::testGraphicsInGroup()
    {
        // Add a circle.
        tools::Rectangle aOrigRect = tools::Rectangle(10,10,210,210); // 200 x 200
        SdrCircObj* pObj = new SdrCircObj(*pDrawLayer, OBJ_CIRC, aOrigRect);
        SdrCircObj* pObj = new SdrCircObj(OBJ_CIRC, aOrigRect);
        pPage->InsertObject(pObj);
        const tools::Rectangle& rNewRect = pObj->GetLogicRect();
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Position and size of the circle shouldn't change when inserted into the page.",
@@ -2781,7 +2781,7 @@ void Test::testGraphicsInGroup()
        tools::Rectangle aOrigRect(10,200,110,300); // 100 x 100
        aTempPoly.append(basegfx::B2DPoint(aStartPos.X(), aStartPos.Y()));
        aTempPoly.append(basegfx::B2DPoint(aEndPos.X(), aEndPos.Y()));
        SdrPathObj* pObj = new SdrPathObj(*pDrawLayer, OBJ_LINE, basegfx::B2DPolyPolygon(aTempPoly));
        SdrPathObj* pObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aTempPoly));
        pObj->NbcSetLogicRect(aOrigRect);
        pPage->InsertObject(pObj);
        const tools::Rectangle& rNewRect = pObj->GetLogicRect();
@@ -2822,7 +2822,7 @@ void Test::testGraphicsOnSheetMove()

    // Insert an object.
    tools::Rectangle aObjRect(2,2,100,100);
    SdrObject* pObj = new SdrRectObj(*pDrawLayer, aObjRect);
    SdrObject* pObj = new SdrRectObj(aObjRect);
    pPage->InsertObject(pObj);
    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);

@@ -5342,7 +5342,7 @@ void Test::testNoteLifeCycle()
    SdrCaptionObj* pCaption = pNote->GetOrCreateCaption(aPos);
    CPPUNIT_ASSERT_MESSAGE("Failed to create a caption object.", pCaption);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("This caption should belong to the drawing layer of the document.",
                           m_pDoc->GetDrawLayer(), static_cast<ScDrawLayer*>(&pCaption->getSdrModelFromSdrObject()));
                           m_pDoc->GetDrawLayer(), static_cast<ScDrawLayer*>(pCaption->GetModel()));

    // Copy B2 with note to a clipboard.

@@ -5648,7 +5648,7 @@ void Test::testAnchoredRotatedShape()
        tools::Rectangle aRect( 4000, 5000, 10000, 7000 );

        tools::Rectangle aRotRect( 6000, 3000, 8000, 9000 );
        SdrRectObj *pObj = new SdrRectObj(*pDrawLayer, aRect);
        SdrRectObj *pObj = new SdrRectObj(aRect);
        pPage->InsertObject(pObj);
        Point aRef1(pObj->GetSnapRect().Center());
        int nAngle = 9000; //90 deg.
@@ -6421,7 +6421,7 @@ void Test::testUndoDataAnchor()

    // Insert an object.
    tools::Rectangle aObjRect(2,1000,100,1100);
    SdrObject* pObj = new SdrRectObj(*pDrawLayer, aObjRect);
    SdrObject* pObj = new SdrRectObj(aObjRect);
    pPage->InsertObject(pObj);
    ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0, false);

diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index 38c3e1a..048b53b 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -1911,7 +1911,7 @@ void Test::testSortImages()

    // Insert graphic in cell B2.
    const tools::Rectangle aOrigRect = tools::Rectangle(1000, 1000, 1200, 1200);
    SdrCircObj* pObj = new SdrCircObj(*pDrawLayer, OBJ_CIRC, aOrigRect);
    SdrCircObj* pObj = new SdrCircObj(OBJ_CIRC, aOrigRect);
    SdrPage* pPage = pDrawLayer->GetPage(0);
    CPPUNIT_ASSERT(pPage);
    pPage->InsertObject(pObj);
diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx
index 8b9b4de..70b99bd 100644
--- a/sc/source/core/data/documen9.cxx
+++ b/sc/source/core/data/documen9.cxx
@@ -84,9 +84,11 @@ void ScDocument::TransferDrawPage(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDes
            SdrObject* pOldObject = aIter.Next();
            while (pOldObject)
            {
                // Clone to target SdrModel
                SdrObject* pNewObject = pOldObject->Clone(mpDrawLayer);
                SdrObject* pNewObject = pOldObject->Clone();
                // SdrObject* pNewObject = pOldObject->Clone( pNewPage, mpDrawLayer );
                pNewObject->SetModel(mpDrawLayer);
                pNewObject->SetPage(pNewPage);

                pNewObject->NbcMove(Size(0,0));
                pNewPage->InsertObject( pNewObject );

diff --git a/sc/source/core/data/drawpage.cxx b/sc/source/core/data/drawpage.cxx
index 5ccd3cd..5d44598 100644
--- a/sc/source/core/data/drawpage.cxx
+++ b/sc/source/core/data/drawpage.cxx
@@ -24,25 +24,37 @@
#include <document.hxx>
#include <pageuno.hxx>

ScDrawPage::ScDrawPage(ScDrawLayer& rNewModel, bool bMasterPage)
:   FmFormPage(rNewModel, bMasterPage)
ScDrawPage::ScDrawPage(ScDrawLayer& rNewModel, bool bMasterPage) :
    FmFormPage(rNewModel, bMasterPage)
{
    SetSize( Size( RECT_MAX, RECT_MAX ) );
}

ScDrawPage::ScDrawPage(const ScDrawPage& rSrcPage)
    : FmFormPage(rSrcPage)
{
}

ScDrawPage::~ScDrawPage()
{
}

ScDrawPage* ScDrawPage::Clone() const
{
    return Clone(nullptr);
}

ScDrawPage* ScDrawPage::Clone(SdrModel* const pNewModel) const
{
    ScDrawLayer& rScDrawLayer(static_cast< ScDrawLayer& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    ScDrawPage* pClonedScDrawPage(
        new ScDrawPage(
            rScDrawLayer,
            IsMasterPage()));
    pClonedScDrawPage->FmFormPage::lateInit(*this);
    return pClonedScDrawPage;
    ScDrawPage* const pNewPage = new ScDrawPage(*this);
    FmFormModel* pScDrawModel = nullptr;
    if (pNewModel)
    {
        pScDrawModel = dynamic_cast<FmFormModel*>(pNewModel);
        assert(pScDrawModel);
    }
    pNewPage->lateInit(*this, pScDrawModel);
    return pNewPage;
}

css::uno::Reference< css::uno::XInterface > ScDrawPage::createUnoPage()
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 0665e09..e694fed 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -155,10 +155,10 @@ ScUndoAnchorData::~ScUndoAnchorData()
void ScUndoAnchorData::Undo()
{
    // Trigger Object Change
    if (pObj->IsInserted() && pObj->GetPage())
    if (pObj->IsInserted() && pObj->GetPage() && pObj->GetModel())
    {
        SdrHint aHint(SdrHintKind::ObjectChange, *pObj);
        pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        pObj->GetModel()->Broadcast(aHint);
    }

    if (mbWasCellAnchored)
@@ -175,10 +175,10 @@ void ScUndoAnchorData::Redo()
        ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab, mbWasResizeWithCell);

    // Trigger Object Change
    if (pObj->IsInserted() && pObj->GetPage())
    if (pObj->IsInserted() && pObj->GetPage() && pObj->GetModel())
    {
        SdrHint aHint(SdrHintKind::ObjectChange, *pObj);
        pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        pObj->GetModel()->Broadcast(aHint);
    }
}

@@ -463,10 +463,10 @@ void ScDrawLayer::ScCopyPage( sal_uInt16 nOldPos, sal_uInt16 nNewPos )
                pOldData->maStart.SetTab(nOldTab);
                pOldData->maEnd.SetTab(nOldTab);
            }

            // Clone to target SdrModel
            SdrObject* pNewObject = pOldObject->Clone(this);
            SdrObject* pNewObject = pOldObject->Clone();
            pNewObject->SetModel(this);
            pNewObject->SetPage(pNewPage);

            pNewObject->NbcMove(Size(0,0));
            pNewPage->InsertObject( pNewObject );
            ScDrawObjData* pNewData = GetObjData(pNewObject);
@@ -1492,8 +1492,8 @@ void ScDrawLayer::CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const tools::Rec
                OSL_ENSURE( pDestPage, "no page" );
                if (pDestPage)
                {
                    // Clone to target SdrModel
                    SdrObject* pNewObject = pOldObject->Clone(pDestModel);
                    SdrObject* pNewObject = pOldObject->Clone();
                    pNewObject->SetModel(pDestModel);
                    pNewObject->SetPage(pDestPage);

                    uno::Reference< chart2::XChartDocument > xOldChart( ScChartHelper::GetChartFromSdrObject( pOldObject ) );
@@ -1667,8 +1667,8 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const
        if (bObjectInArea && (pOldObject->GetLayer() != SC_LAYER_INTERN)
            && !IsNoteCaption(pOldObject))
        {
            // Clone to target SdrModel
            SdrObject* pNewObject = pOldObject->Clone(this);
            SdrObject* pNewObject = pOldObject->Clone();
            pNewObject->SetModel(this);
            pNewObject->SetPage(pDestPage);

            if ( bMirrorObj )
diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx
index 676a0da..d70e87f 100644
--- a/sc/source/core/data/postit.cxx
+++ b/sc/source/core/data/postit.cxx
@@ -375,11 +375,7 @@ void ScCaptionCreator::CreateCaption( bool bShown, bool bTailFront )
    // create the caption drawing object
    tools::Rectangle aTextRect( Point( 0 , 0 ), Size( SC_NOTECAPTION_WIDTH, SC_NOTECAPTION_HEIGHT ) );
    Point aTailPos = CalcTailPos( bTailFront );
    mxCaption.reset(
        new SdrCaptionObj(
            *mrDoc.GetDrawLayer(), // TTTT should ret a ref?
            aTextRect,
            aTailPos));
    mxCaption.reset( new SdrCaptionObj( aTextRect, aTailPos ));
    // basic caption settings
    ScCaptionUtil::SetBasicCaptionSettings( *mxCaption, bShown );
}
@@ -758,7 +754,7 @@ void ScCaptionPtr::removeFromDrawPageAndFree( bool bIgnoreUndo )
        bool bRecording = false;
        if (!bIgnoreUndo)
        {
            ScDrawLayer* pDrawLayer(dynamic_cast< ScDrawLayer* >(&mpCaption->getSdrModelFromSdrObject()));
            ScDrawLayer* pDrawLayer = dynamic_cast<ScDrawLayer*>(mpCaption->GetModel());
            SAL_WARN_IF( !pDrawLayer, "sc.core", "ScCaptionPtr::removeFromDrawPageAndFree - object without drawing layer");
            // create drawing undo action (before removing the object to have valid draw page in undo action)
            bRecording = (pDrawLayer && pDrawLayer->IsRecording());
@@ -1141,9 +1137,8 @@ void ScPostIt::RemoveCaption()
    /*  Remove caption object only, if this note is its owner (e.g. notes in
        undo documents refer to captions in original document, do not remove
        them from drawing layer here). */
    // TTTT maybe no longer needed - can that still happen?
    ScDrawLayer* pDrawLayer = mrDoc.GetDrawLayer();
    if (pDrawLayer == &maNoteData.mxCaption->getSdrModelFromSdrObject())
    if (pDrawLayer == maNoteData.mxCaption->GetModel())
        maNoteData.mxCaption.removeFromDrawPageAndFree();

    SAL_INFO("sc.core","ScPostIt::RemoveCaption - refs: " << maNoteData.mxCaption.getRefs() <<
diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx
index 77f19b2..f8f5ac0 100644
--- a/sc/source/core/tool/detfunc.cxx
+++ b/sc/source/core/tool/detfunc.cxx
@@ -453,9 +453,7 @@ bool ScDetectiveFunc::InsertArrow( SCCOL nCol, SCROW nRow,
        // insert the rectangle before the arrow - this is relied on in FindFrameForObject

        tools::Rectangle aRect = GetDrawRect( nRefStartCol, nRefStartRow, nRefEndCol, nRefEndRow );
        SdrRectObj* pBox = new SdrRectObj(
            *pModel,
            aRect);
        SdrRectObj* pBox = new SdrRectObj( aRect );

        pBox->SetMergedItemSetAndBroadcast(rData.GetBoxSet());

@@ -496,10 +494,7 @@ bool ScDetectiveFunc::InsertArrow( SCCOL nCol, SCROW nRow,
    basegfx::B2DPolygon aTempPoly;
    aTempPoly.append(basegfx::B2DPoint(aStartPos.X(), aStartPos.Y()));
    aTempPoly.append(basegfx::B2DPoint(aEndPos.X(), aEndPos.Y()));
    SdrPathObj* pArrow = new SdrPathObj(
        *pModel,
        OBJ_LINE,
        basegfx::B2DPolyPolygon(aTempPoly));
    SdrPathObj* pArrow = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aTempPoly));
    pArrow->NbcSetLogicRect(tools::Rectangle(aStartPos,aEndPos));  //TODO: needed ???
    pArrow->SetMergedItemSetAndBroadcast(rAttrSet);

@@ -531,9 +526,7 @@ bool ScDetectiveFunc::InsertToOtherTab( SCCOL nStartCol, SCROW nStartRow,
    if (bArea)
    {
        tools::Rectangle aRect = GetDrawRect( nStartCol, nStartRow, nEndCol, nEndRow );
        SdrRectObj* pBox = new SdrRectObj(
            *pModel,
            aRect);
        SdrRectObj* pBox = new SdrRectObj( aRect );

        pBox->SetMergedItemSetAndBroadcast(rData.GetBoxSet());

@@ -566,10 +559,7 @@ bool ScDetectiveFunc::InsertToOtherTab( SCCOL nStartCol, SCROW nStartRow,
    basegfx::B2DPolygon aTempPoly;
    aTempPoly.append(basegfx::B2DPoint(aStartPos.X(), aStartPos.Y()));
    aTempPoly.append(basegfx::B2DPoint(aEndPos.X(), aEndPos.Y()));
    SdrPathObj* pArrow = new SdrPathObj(
        *pModel,
        OBJ_LINE,
        basegfx::B2DPolyPolygon(aTempPoly));
    SdrPathObj* pArrow = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aTempPoly));
    pArrow->NbcSetLogicRect(tools::Rectangle(aStartPos,aEndPos));  //TODO: needed ???

    pArrow->SetMergedItemSetAndBroadcast(rAttrSet);
@@ -635,10 +625,7 @@ void ScDetectiveFunc::DrawCircle( SCCOL nCol, SCROW nRow, ScDetectiveData& rData
    aRect.AdjustTop( -70 );
    aRect.AdjustBottom(70 );

    SdrCircObj* pCircle = new SdrCircObj(
        *pModel,
        OBJ_CIRC,
        aRect);
    SdrCircObj* pCircle = new SdrCircObj( OBJ_CIRC, aRect );
    SfxItemSet& rAttrSet = rData.GetCircleSet();

    pCircle->SetMergedItemSetAndBroadcast(rAttrSet);
diff --git a/sc/source/filter/excel/xichart.cxx b/sc/source/filter/excel/xichart.cxx
index 055663d..cad44b7 100644
--- a/sc/source/filter/excel/xichart.cxx
+++ b/sc/source/filter/excel/xichart.cxx
@@ -4221,7 +4221,7 @@ void XclImpChartDrawing::ConvertObjects( XclImpDffConverter& rDffConv,
            Reference< XDrawPageSupplier > xDrawPageSupp( rxModel, UNO_QUERY_THROW );
            Reference< XDrawPage > xDrawPage( xDrawPageSupp->getDrawPage(), UNO_SET_THROW );
            pSdrPage = ::GetSdrPageFromXDrawPage( xDrawPage );
            pSdrModel = pSdrPage ? &pSdrPage->getSdrModelFromSdrPage() : nullptr;
            pSdrModel = pSdrPage ? pSdrPage->GetModel() : nullptr;
        }
        catch( Exception& )
        {
diff --git a/sc/source/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx
index 989c9b6..94b2d01 100644
--- a/sc/source/filter/excel/xiescher.cxx
+++ b/sc/source/filter/excel/xiescher.cxx
@@ -425,7 +425,8 @@ SdrObjectPtr XclImpDrawObjBase::CreateSdrObject( XclImpDffConverter& rDffConv, c
    else
    {
        xSdrObj = DoCreateSdrObj( rDffConv, rAnchorRect );

        if( xSdrObj )
            xSdrObj->SetModel( rDffConv.GetModel() );
        //added for exporting OCX control
        /*  mnObjType value set should be as below table:
                    0x0000      Group               0x0001      Line
@@ -1011,9 +1012,7 @@ std::size_t XclImpGroupObj::DoGetProgressSize() const

SdrObjectPtr XclImpGroupObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& /*rAnchorRect*/ ) const
{
    std::unique_ptr<SdrObjGroup, SdrObjectFree> xSdrObj(
        new SdrObjGroup(
            *GetDoc().GetDrawLayer()));
    std::unique_ptr<SdrObjGroup, SdrObjectFree> xSdrObj( new SdrObjGroup );
    // child objects in BIFF2-BIFF5 have absolute size, not needed to pass own anchor rectangle
    SdrObjList& rObjList = *xSdrObj->GetSubList();  // SdrObjGroup always returns existing sublist
    for( ::std::vector< XclImpDrawObjRef >::const_iterator aIt = maChildren.begin(), aEnd = maChildren.end(); aIt != aEnd; ++aIt )
@@ -1081,11 +1080,7 @@ SdrObjectPtr XclImpLineObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const 
            aB2DPolygon.append( ::basegfx::B2DPoint( rAnchorRect.Right(), rAnchorRect.Top() ) );
        break;
    }
    SdrObjectPtr xSdrObj(
        new SdrPathObj(
            *GetDoc().GetDrawLayer(),
            OBJ_LINE,
            ::basegfx::B2DPolyPolygon(aB2DPolygon)));
    SdrObjectPtr xSdrObj( new SdrPathObj( OBJ_LINE, ::basegfx::B2DPolyPolygon( aB2DPolygon ) ) );
    ConvertLineStyle( *xSdrObj, maLineData );

    // line ends
@@ -1200,10 +1195,7 @@ void XclImpRectObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uI

SdrObjectPtr XclImpRectObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
    SdrObjectPtr xSdrObj(
        new SdrRectObj(
            *GetDoc().GetDrawLayer(),
            rAnchorRect));
    SdrObjectPtr xSdrObj( new SdrRectObj( rAnchorRect ) );
    ConvertRectStyle( *xSdrObj );
    rDffConv.Progress();
    return xSdrObj;
@@ -1216,11 +1208,7 @@ XclImpOvalObj::XclImpOvalObj( const XclImpRoot& rRoot ) :

SdrObjectPtr XclImpOvalObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
    SdrObjectPtr xSdrObj(
        new SdrCircObj(
            *GetDoc().GetDrawLayer(),
            OBJ_CIRC,
            rAnchorRect));
    SdrObjectPtr xSdrObj( new SdrCircObj( OBJ_CIRC, rAnchorRect ) );
    ConvertRectStyle( *xSdrObj );
    rDffConv.Progress();
    return xSdrObj;
@@ -1292,13 +1280,7 @@ SdrObjectPtr XclImpArcObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const t
        break;
    }
    SdrObjKind eObjKind = maFillData.IsFilled() ? OBJ_SECT : OBJ_CARC;
    SdrObjectPtr xSdrObj(
        new SdrCircObj(
            *GetDoc().GetDrawLayer(),
            eObjKind,
            aNewRect,
            nStartAngle,
            nEndAngle));
    SdrObjectPtr xSdrObj( new SdrCircObj( eObjKind, aNewRect, nStartAngle, nEndAngle ) );
    ConvertFillStyle( *xSdrObj, maFillData );
    ConvertLineStyle( *xSdrObj, maLineData );
    rDffConv.Progress();
@@ -1376,11 +1358,7 @@ SdrObjectPtr XclImpPolygonObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, con
            aB2DPolygon.append( lclGetPolyPoint( rAnchorRect, maCoords.front() ) );
        // create the SdrObject
        SdrObjKind eObjKind = maFillData.IsFilled() ? OBJ_PATHPOLY : OBJ_PATHPLIN;
        xSdrObj.reset(
            new SdrPathObj(
                *GetDoc().GetDrawLayer(),
                eObjKind,
                ::basegfx::B2DPolyPolygon(aB2DPolygon)));
        xSdrObj.reset( new SdrPathObj( eObjKind, ::basegfx::B2DPolyPolygon( aB2DPolygon ) ) );
        ConvertRectStyle( *xSdrObj );
    }
    rDffConv.Progress();
@@ -1442,9 +1420,7 @@ void XclImpTextObj::DoReadObj5( XclImpStream& rStrm, sal_uInt16 nNameLen, sal_uI

SdrObjectPtr XclImpTextObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const tools::Rectangle& rAnchorRect ) const
{
    std::unique_ptr<SdrObjCustomShape, SdrObjectFree> xSdrObj(
        new SdrObjCustomShape(
            *GetDoc().GetDrawLayer()));
    std::unique_ptr<SdrObjCustomShape, SdrObjectFree> xSdrObj( new SdrObjCustomShape );
    xSdrObj->NbcSetSnapRect( rAnchorRect );
    OUString aRectType = "rectangle";
    xSdrObj->MergeDefaultAttributes( &aRectType );
@@ -1734,12 +1710,7 @@ SdrObjectPtr XclImpChartObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, const
        // ChartHelper::AdaptDefaultsForChart( xEmbObj );

        // create the container OLE object
        xSdrObj.reset(
            new SdrOle2Obj(
                *GetDoc().GetDrawLayer(),
                svt::EmbeddedObjectRef(xEmbObj, nAspect),
                aEmbObjName,
                rAnchorRect));
        xSdrObj.reset( new SdrOle2Obj( svt::EmbeddedObjectRef( xEmbObj, nAspect ), aEmbObjName, rAnchorRect ) );
    }

    return xSdrObj;
@@ -2982,11 +2953,7 @@ SdrObjectPtr XclImpPictureObj::DoCreateSdrObj( XclImpDffConverter& rDffConv, con
    // no OLE - create a plain picture from IMGDATA record data
    if( !xSdrObj && (maGraphic.GetType() != GraphicType::NONE) )
    {
        xSdrObj.reset(
            new SdrGrafObj(
                *GetDoc().GetDrawLayer(),
                maGraphic,
                rAnchorRect));
        xSdrObj.reset( new SdrGrafObj( maGraphic, rAnchorRect ) );
        ConvertRectStyle( *xSdrObj );
    }

@@ -3467,20 +3434,9 @@ SdrObjectPtr XclImpDffConverter::CreateSdrObject( const XclImpPictureObj& rPicOb
                    ErrCode nError = ERRCODE_NONE;
                    namespace cssea = ::com::sun::star::embed::Aspects;
                    sal_Int64 nAspects = rPicObj.IsSymbol() ? cssea::MSOLE_ICON : cssea::MSOLE_CONTENT;
                    xSdrObj.reset(
                        CreateSdrOLEFromStorage(
                            GetConvData().mrSdrModel,
                            aStrgName,
                            xSrcStrg,
                            pDocShell->GetStorage(),
                            aGraphic,
                            rAnchorRect,
                            aVisArea,
                            nullptr,
                            nError,
                            mnOleImpFlags,
                            nAspects,
                            GetRoot().GetMedium().GetBaseURL()));
                    xSdrObj.reset( CreateSdrOLEFromStorage(
                        aStrgName, xSrcStrg, pDocShell->GetStorage(), aGraphic,
                        rAnchorRect, aVisArea, nullptr, nError, mnOleImpFlags, nAspects, GetRoot().GetMedium().GetBaseURL()) );
                }
            }
        }
diff --git a/sc/source/filter/html/htmlexp2.cxx b/sc/source/filter/html/htmlexp2.cxx
index d688774..a6b73fd 100644
--- a/sc/source/filter/html/htmlexp2.cxx
+++ b/sc/source/filter/html/htmlexp2.cxx
@@ -165,7 +165,8 @@ void ScHTMLExport::WriteGraphEntry( ScHTMLGraphEntry* pE )
        break;
        default:
        {
            Graphic aGraph(SdrExchangeView::GetObjGraphic(*pObject));
            Graphic aGraph( SdrExchangeView::GetObjGraphic(
                pDoc->GetDrawLayer(), pObject ) );
            OUString aLinkName;
            WriteImage( aLinkName, aGraph, aOpt );
            pE->bWritten = true;
diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index e553df1..d691530 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -602,11 +602,7 @@ void ScEEImport::InsertGraphic( SCCOL nCol, SCROW nRow, SCTAB nTab,
        if ( pI->pGraphic )
        {
            tools::Rectangle aRect ( aInsertPos, aLogicSize );
            SdrGrafObj* pObj = new SdrGrafObj(
                *pModel,
                *pI->pGraphic,
                aRect);

            SdrGrafObj* pObj = new SdrGrafObj( *pI->pGraphic, aRect );
            // calling SetGraphicLink here doesn't work
            pObj->SetName( pI->aURL );

diff --git a/sc/source/ui/app/drwtrans.cxx b/sc/source/ui/app/drwtrans.cxx
index 12cfa00..1e4c9c8 100644
--- a/sc/source/ui/app/drwtrans.cxx
+++ b/sc/source/ui/app/drwtrans.cxx
@@ -188,7 +188,7 @@ ScDrawTransferObj::ScDrawTransferObj( SdrModel* pClipModel, ScDocShell* pContain

    // #i71538# use complete SdrViews
    // SdrExchangeView aView(pModel);
    SdrView aView(*pModel);
    SdrView aView(pModel);
    SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
    aView.MarkAllObj(pPv);
    aSrcSize = aView.GetAllMarkedRect().GetSize();
@@ -395,7 +395,7 @@ bool ScDrawTransferObj::GetData( const css::datatransfer::DataFlavor& rFlavor, c
        {
            // #i71538# use complete SdrViews
            // SdrExchangeView aView( pModel );
            SdrView aView(*pModel);
            SdrView aView( pModel );
            SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
            OSL_ENSURE( pPv, "pPv not there..." );
            aView.MarkAllObj( pPv );
@@ -632,7 +632,7 @@ static void lcl_InitMarks( SdrMarkView& rDest, const SdrMarkView& rSource, SCTAB
void ScDrawTransferObj::SetDragSource( const ScDrawView* pView )
{
    DELETEZ( pDragSourceView );
    pDragSourceView = new SdrView(pView->getSdrModelFromSdrView()); // TTTT pView should be reference
    pDragSourceView = new SdrView( pView->GetModel() );
    lcl_InitMarks( *pDragSourceView, *pView, pView->GetTab() );

    //! add as listener with document, delete pDragSourceView if document gone
@@ -641,7 +641,7 @@ void ScDrawTransferObj::SetDragSource( const ScDrawView* pView )
void ScDrawTransferObj::SetDragSourceObj( SdrObject* pObj, SCTAB nTab )
{
    DELETEZ( pDragSourceView );
    pDragSourceView = new SdrView(pObj->getSdrModelFromSdrObject()); // TTTT pObj should be reference
    pDragSourceView = new SdrView( pObj->GetModel() );
    pDragSourceView->ShowSdrPage(pDragSourceView->GetModel()->GetPage(nTab));
    SdrPageView* pPV = pDragSourceView->GetSdrPageView();
    pDragSourceView->MarkObj(pObj, pPV);
@@ -719,7 +719,7 @@ void ScDrawTransferObj::InitDocShell()
        SdrModel* pDestModel = rDestDoc.GetDrawLayer();
        // #i71538# use complete SdrViews
        // SdrExchangeView aDestView( pDestModel );
        SdrView aDestView(*pDestModel);
        SdrView aDestView( pDestModel );
        aDestView.ShowSdrPage(aDestView.GetModel()->GetPage(0));
        aDestView.Paste(
            *pModel,
diff --git a/sc/source/ui/drawfunc/fuconarc.cxx b/sc/source/ui/drawfunc/fuconarc.cxx
index d167649..7ada210 100644
--- a/sc/source/ui/drawfunc/fuconarc.cxx
+++ b/sc/source/ui/drawfunc/fuconarc.cxx
@@ -123,9 +123,8 @@ SdrObject* FuConstArc::CreateDefaultObject(const sal_uInt16 nID, const tools::Re
    // case SID_DRAW_CIRCLECUT:

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrDoc,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());
        pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
        nullptr, pDrDoc);

    if(pObj)
    {
diff --git a/sc/source/ui/drawfunc/fuconcustomshape.cxx b/sc/source/ui/drawfunc/fuconcustomshape.cxx
index e028a4d..f5a0339 100644
--- a/sc/source/ui/drawfunc/fuconcustomshape.cxx
+++ b/sc/source/ui/drawfunc/fuconcustomshape.cxx
@@ -132,10 +132,8 @@ void FuConstCustomShape::Deactivate()
SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, const tools::Rectangle& rRectangle)
{
    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrDoc,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());

        pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
        nullptr, pDrDoc);
    if( pObj )
    {
        tools::Rectangle aRectangle( rRectangle );
@@ -144,7 +142,6 @@ SdrObject* FuConstCustomShape::CreateDefaultObject(const sal_uInt16 /* nID */, c
            ImpForceQuadratic( aRectangle );
        pObj->SetLogicRect( aRectangle );
    }

    return pObj;
}

@@ -171,7 +168,7 @@ void FuConstCustomShape::SetAttributes( SdrObject* pObj )
                        {
                            const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                            SfxItemSet aDest(
                                pObj->getSdrModelFromSdrObject().GetItemPool(),
                                pObj->GetModel()->GetItemPool(),
                                svl::Items<
                                    // Ranges from SdrAttrObj:
                                    SDRATTR_START, SDRATTR_SHADOW_LAST,
diff --git a/sc/source/ui/drawfunc/fuconpol.cxx b/sc/source/ui/drawfunc/fuconpol.cxx
index cc9ec05..330ebf09 100644
--- a/sc/source/ui/drawfunc/fuconpol.cxx
+++ b/sc/source/ui/drawfunc/fuconpol.cxx
@@ -185,9 +185,8 @@ SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const tools
    // case SID_DRAW_FREELINE_NOFILL:

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrDoc,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());
        pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
        nullptr, pDrDoc);

    if(pObj)
    {
diff --git a/sc/source/ui/drawfunc/fuconrec.cxx b/sc/source/ui/drawfunc/fuconrec.cxx
index 6aba5fa..d3ae4c9 100644
--- a/sc/source/ui/drawfunc/fuconrec.cxx
+++ b/sc/source/ui/drawfunc/fuconrec.cxx
@@ -58,10 +58,10 @@ FuConstRectangle::~FuConstRectangle()

namespace {

::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel* pDoc)
{
    ::basegfx::B2DPolyPolygon aRetval;
    XLineEndListRef pLineEndList(rModel.GetLineEndList());
    XLineEndListRef pLineEndList = pDoc->GetLineEndList();

    if( pLineEndList.is() )
    {
@@ -116,7 +116,7 @@ bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)

        if (pObj)
        {
            SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
            SfxItemSet aAttr(pObj->GetModel()->GetItemPool());
            SetLineEnds(aAttr, pObj, aSfxRequest.GetSlot());
            pObj->SetMergedItemSet(aAttr);
        }
@@ -216,7 +216,7 @@ void FuConstRectangle::Activate()

void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject* pObj, sal_uInt16 nSlotId)
{
    SdrModel& rModel(pObj->getSdrModelFromSdrObject()); // TTTT pObj should be reference
    SdrModel *pDoc = pObj->GetModel();

    if ( nSlotId == SID_LINE_ARROW_START      ||
         nSlotId == SID_LINE_ARROW_END        ||
@@ -230,7 +230,7 @@ void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject* pObj, sal
        // set attributes of line start and ends

        // arrowhead
        ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
        ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, pDoc ) );
        if( !aArrow.count() )
        {
            ::basegfx::B2DPolygon aNewArrow;
@@ -242,7 +242,7 @@ void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject* pObj, sal
        }

        // Circles
        ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
        ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, pDoc ) );
        if( !aCircle.count() )
        {
            ::basegfx::B2DPolygon aNewCircle;
@@ -252,7 +252,7 @@ void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject* pObj, sal
        }

        // Square
        ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
        ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, pDoc ) );
        if( !aSquare.count() )
        {
            ::basegfx::B2DPolygon aNewSquare;
@@ -264,7 +264,7 @@ void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject* pObj, sal
            aSquare.append(aNewSquare);
        }

        SfxItemSet aSet( rModel.GetItemPool() );
        SfxItemSet aSet( pDoc->GetItemPool() );
        long nWidth = 200; // (1/100th mm)

        // determine line width and calculate with it the line end width
@@ -356,9 +356,8 @@ void FuConstRectangle::Deactivate()
SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle& rRectangle)
{
    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrDoc,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());
        pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
        nullptr, pDrDoc);

    if(pObj)
    {
diff --git a/sc/source/ui/drawfunc/fuconuno.cxx b/sc/source/ui/drawfunc/fuconuno.cxx
index a3a141a..619ad1c 100644
--- a/sc/source/ui/drawfunc/fuconuno.cxx
+++ b/sc/source/ui/drawfunc/fuconuno.cxx
@@ -111,9 +111,8 @@ SdrObject* FuConstUnoControl::CreateDefaultObject(const sal_uInt16 /* nID */, co
    // case SID_FM_CREATE_CONTROL:

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrDoc,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());
        pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
        nullptr, pDrDoc);

    if(pObj)
    {
diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx
index d1efc9f..5574a6f 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -177,13 +177,10 @@ static void lcl_InsertGraphic( const Graphic& rGraphic,

    tools::Rectangle aRect ( aInsertPos, aLogicSize );

    SdrGrafObj* pObj = new SdrGrafObj(
        pView->getSdrModelFromSdrView(), // TTTT pView should be reference
        rGraphic1,
        aRect);
    SdrGrafObj* pObj = new SdrGrafObj( rGraphic1, aRect );

    // calling SetGraphicLink here doesn't work
    // Yes, due to the SdrObject had no SdrModel

    //  Path is no longer used as name for the graphics object

    ScDrawLayer* pLayer = static_cast<ScDrawLayer*>(pView->GetModel());
@@ -247,10 +244,9 @@ static void lcl_InsertMedia( const OUString& rMediaURL, bool bApi,
#endif
    }

    SdrMediaObj* pObj = new SdrMediaObj(
        *rData.GetDocument()->GetDrawLayer(),
        tools::Rectangle(aInsertPos, aSize));
    SdrMediaObj* pObj = new SdrMediaObj( tools::Rectangle( aInsertPos, aSize ) );

    pObj->SetModel(rData.GetDocument()->GetDrawLayer()); // set before setURL
    pObj->setURL( realURL, ""/*TODO?*/ );
    pView->InsertObjectAtView( pObj, *pPV, bApi ? SdrInsertFlags::DONTMARK : SdrInsertFlags::NONE );
}
diff --git a/sc/source/ui/drawfunc/fuins2.cxx b/sc/source/ui/drawfunc/fuins2.cxx
index bcee011..b56a1c1 100644
--- a/sc/source/ui/drawfunc/fuins2.cxx
+++ b/sc/source/ui/drawfunc/fuins2.cxx
@@ -350,11 +350,7 @@ FuInsertOLE::FuInsertOLE(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView*
            if ( rData.GetDocument()->IsNegativePage( rData.GetTabNo() ) )
                aPnt.AdjustX( -(aSize.Width()) );      // move position to left edge
            tools::Rectangle aRect (aPnt, aSize);
            SdrOle2Obj* pObj = new SdrOle2Obj(
                *pDoc, // TTTT should be reference
                aObjRef,
                aName,
                aRect);
            SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);
            SdrPageView* pPV = pView->GetSdrPageView();
            pView->InsertObjectAtView(pObj, *pPV);

@@ -592,11 +588,7 @@ FuInsertChart::FuInsertChart(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawV
    Point aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );

    tools::Rectangle aRect (aStart, aSize);
    SdrOle2Obj* pObj = new SdrOle2Obj(
        *pDoc, // TTTT should be reference
        svt::EmbeddedObjectRef(xObj, nAspect),
        aName,
        aRect);
    SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);
    SdrPageView* pPV = pView->GetSdrPageView();

    // #i121334# This call will change the chart's default background fill from white to transparent.
@@ -755,11 +747,7 @@ FuInsertChartFromFile::FuInsertChartFromFile( ScTabViewShell* pViewSh, vcl::Wind
    ScRange aPositionRange = pViewSh->GetViewData().GetCurPos();
    Point aStart = pViewSh->GetChartInsertPos( aSize, aPositionRange );
    tools::Rectangle aRect (aStart, aSize);
    SdrOle2Obj* pObj = new SdrOle2Obj(
        *pDoc, // TTTT should be reference
        svt::EmbeddedObjectRef(xObj, nAspect),
        aName,
        aRect);
    SdrOle2Obj* pObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect);

    SdrPageView* pPV = pView->GetSdrPageView();

diff --git a/sc/source/ui/drawfunc/futext.cxx b/sc/source/ui/drawfunc/futext.cxx
index 7914c87..3858359 100644
--- a/sc/source/ui/drawfunc/futext.cxx
+++ b/sc/source/ui/drawfunc/futext.cxx
@@ -643,9 +643,8 @@ SdrObject* FuText::CreateDefaultObject(const sal_uInt16 nID, const tools::Rectan
    // case SID_DRAW_NOTEEDIT:

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrDoc,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());
        pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
        nullptr, pDrDoc);

    if(pObj)
    {
diff --git a/sc/source/ui/inc/drawview.hxx b/sc/source/ui/inc/drawview.hxx
index ad353cd..9574cdb 100644
--- a/sc/source/ui/inc/drawview.hxx
+++ b/sc/source/ui/inc/drawview.hxx
@@ -56,11 +56,8 @@ class ScDrawView final : public FmFormView
    virtual SdrUndoManager* getSdrUndoManagerForEnhancedTextEdit() const override;

public:
    ScDrawView(
        OutputDevice* pOut,
        ScViewData* pData);

    virtual ~ScDrawView() override;
                    ScDrawView( OutputDevice* pOut, ScViewData* pData );
    virtual         ~ScDrawView() override;

    virtual void    MarkListHasChanged() override;
    virtual void    Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index a4141607..52c3fb9 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -1248,7 +1248,7 @@ static void lcl_DoDragObject( ScDocShell* pSrcShell, const OUString& rName, ScCo
        SdrObject* pObject = pModel->GetNamedObject( rName, nDrawId, nTab );
        if (pObject)
        {
            SdrView aEditView(*pModel);
            SdrView aEditView( pModel );
            aEditView.ShowSdrPage(aEditView.GetModel()->GetPage(nTab));
            SdrPageView* pPV = aEditView.GetSdrPageView();
            aEditView.MarkObj(pObject, pPV);
diff --git a/sc/source/ui/unoobj/TablePivotCharts.cxx b/sc/source/ui/unoobj/TablePivotCharts.cxx
index 7f150e2..a8c19f3 100644
--- a/sc/source/ui/unoobj/TablePivotCharts.cxx
+++ b/sc/source/ui/unoobj/TablePivotCharts.cxx
@@ -154,11 +154,8 @@ void SAL_CALL TablePivotCharts::addNewByName(OUString const & rName,
                xReceiver->setArguments(aArgs);
            }

            SdrOle2Obj* pObject = new SdrOle2Obj(
                *pModel,
                svt::EmbeddedObjectRef(xObject, embed::Aspects::MSOLE_CONTENT),
                aName,
                aInsRect);
            SdrOle2Obj* pObject = new SdrOle2Obj(svt::EmbeddedObjectRef(xObject, embed::Aspects::MSOLE_CONTENT),
                                                 aName, aInsRect);

            if (xObject.is())
                xObject->setVisualAreaSize(nAspect, aAwtSize);
diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx
index 1c98dc4..c146e3a 100644
--- a/sc/source/ui/unoobj/chartuno.cxx
+++ b/sc/source/ui/unoobj/chartuno.cxx
@@ -246,11 +246,7 @@ void SAL_CALL ScChartsObj::addNewByName( const OUString& rName,
            rDoc.GetChartListenerCollection()->insert( pChartListener );
            pChartListener->StartListeningTo();

            SdrOle2Obj* pObj = new SdrOle2Obj(
                *pModel,
                ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
                aName,
                aInsRect);
            SdrOle2Obj* pObj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aName, aInsRect );

            // set VisArea
            if( xObj.is())
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index ee46cd1..d16bc89 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -373,18 +373,6 @@ void ScModelObj::CreateAndSet(ScDocShell* pDocSh)
        pDocSh->SetBaseModel( new ScModelObj(pDocSh) );
}

SdrModel* ScModelObj::getSdrModelFromUnoModel() const
{
    ScDocument& rDoc(pDocShell->GetDocument());

    if(!rDoc.GetDrawLayer())
    {
        rDoc.InitDrawLayer();
    }

    return rDoc.GetDrawLayer();
}

ScModelObj::ScModelObj( ScDocShell* pDocSh ) :
    SfxBaseModel( pDocSh ),
    aPropSet( lcl_GetDocOptPropertyMap() ),
@@ -1959,9 +1947,7 @@ void SAL_CALL ScModelObj::render( sal_Int32 nSelRenderer, const uno::Any& aSelec

    if( pModel )
    {
        aDrawViewKeeper.mpDrawView = new FmFormView(
            *pModel,
            pDev);
        aDrawViewKeeper.mpDrawView = new FmFormView( pModel, pDev );
        aDrawViewKeeper.mpDrawView->ShowSdrPage(aDrawViewKeeper.mpDrawView->GetModel()->GetPage(nTab));
        aDrawViewKeeper.mpDrawView->SetPrintPreview();
    }
diff --git a/sc/source/ui/unoobj/shapeuno.cxx b/sc/source/ui/unoobj/shapeuno.cxx
index 8c590d6..a938851 100644
--- a/sc/source/ui/unoobj/shapeuno.cxx
+++ b/sc/source/ui/unoobj/shapeuno.cxx
@@ -333,13 +333,11 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const 
        SdrObject *pObj = GetSdrObject();
        if (pObj)
        {
            ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
            SdrPage* pPage(pObj->GetPage());

            if ( pPage )
            ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
            SdrPage* pPage = pObj->GetPage();
            if ( pModel && pPage )
            {
                ScDocument* pDoc(rModel.GetDocument());

                ScDocument* pDoc = pModel->GetDocument();
                if ( pDoc )
                {
                    SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
@@ -348,7 +346,7 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const 
                        ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);

                        SCTAB nTab = 0;
                        if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                        if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                        {
                            table::CellRangeAddress aAddress = xRangeAdd->getRangeAddress();
                            if (nTab == aAddress.Sheet)
@@ -465,15 +463,14 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const 
            SdrObject *pObj = GetSdrObject();
            if (pObj)
            {
                ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
                SdrPage* pPage(pObj->GetPage());

                if ( pPage )
                ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
                SdrPage* pPage = pObj->GetPage();
                if ( pModel && pPage )
                {
                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        ScDocument* pDoc = rModel.GetDocument();
                        ScDocument* pDoc = pModel->GetDocument();
                        if ( pDoc )
                        {
                            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
@@ -564,15 +561,14 @@ void SAL_CALL ScShapeObj::setPropertyValue(const OUString& aPropertyName, const 
            SdrObject *pObj = GetSdrObject();
            if (pObj)
            {
                ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
                SdrPage* pPage(pObj->GetPage());

                if ( pPage )
                ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
                SdrPage* pPage = pObj->GetPage();
                if ( pModel && pPage )
                {
                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        ScDocument* pDoc = rModel.GetDocument();
                        ScDocument* pDoc = pModel->GetDocument();
                        if ( pDoc )
                        {
                            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
@@ -661,16 +657,15 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const OUString& aPropertyName )
        SdrObject *pObj = GetSdrObject();
        if (pObj)
        {
            ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
            SdrPage* pPage(pObj->GetPage());

            if ( pPage )
            ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
            SdrPage* pPage = pObj->GetPage();
            if ( pModel && pPage )
            {
                ScDocument* pDoc = rModel.GetDocument();
                ScDocument* pDoc = pModel->GetDocument();
                if ( pDoc )
                {
                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
                        if ( pObjSh && dynamic_cast<const ScDocShell*>( pObjSh) !=  nullptr )
@@ -710,16 +705,15 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const OUString& aPropertyName )
        SdrObject *pObj = GetSdrObject();
        if (pObj)
        {
            ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
            SdrPage* pPage(pObj->GetPage());

            if ( pPage )
            ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
            SdrPage* pPage = pObj->GetPage();
            if ( pModel && pPage )
            {
                ScDocument* pDoc = rModel.GetDocument();
                ScDocument* pDoc = pModel->GetDocument();
                if ( pDoc )
                {
                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
                        if (xShape.is())
@@ -770,16 +764,15 @@ uno::Any SAL_CALL ScShapeObj::getPropertyValue( const OUString& aPropertyName )
        SdrObject *pObj = GetSdrObject();
        if (pObj)
        {
            ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
            SdrPage* pPage(pObj->GetPage());

            if ( pPage )
            ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
            SdrPage* pPage = pObj->GetPage();
            if ( pModel && pPage )
            {
                ScDocument* pDoc = rModel.GetDocument();
                ScDocument* pDoc = pModel->GetDocument();
                if ( pDoc )
                {
                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        uno::Reference<drawing::XShape> xShape( mxShapeAgg, uno::UNO_QUERY );
                        if (xShape.is())
@@ -1004,26 +997,28 @@ uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getAnchor()
    SdrObject* pObj = GetSdrObject();
    if( pObj )
    {
        ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
        SdrPage* pPage(pObj->GetPage());
        ScDocument* pDoc = rModel.GetDocument();

        if ( pPage && pDoc )
        ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
        SdrPage* pPage = pObj->GetPage();
        if ( pModel )
        {
            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
            if ( pObjSh && dynamic_cast<const ScDocShell*>( pObjSh) !=  nullptr )
            ScDocument* pDoc = pModel->GetDocument();
            if ( pDoc )
            {
                ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);

                SCTAB nTab = 0;
                if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
                if ( pObjSh && dynamic_cast<const ScDocShell*>( pObjSh) !=  nullptr )
                {
                    Point aPos(pObj->GetCurrentBoundRect().TopLeft());
                    ScRange aRange(pDoc->GetRange( nTab, tools::Rectangle( aPos, aPos ) ));
                    ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);

                    //  anchor is always the cell
                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        Point aPos(pObj->GetCurrentBoundRect().TopLeft());
                        ScRange aRange(pDoc->GetRange( nTab, tools::Rectangle( aPos, aPos ) ));

                    xRet.set(new ScCellObj( pDocSh, aRange.aStart ));
                        //  anchor is always the cell

                        xRet.set(new ScCellObj( pDocSh, aRange.aStart ));
                    }
                }
            }
        }
@@ -1247,23 +1242,25 @@ uno::Reference< uno::XInterface > SAL_CALL ScShapeObj::getParent()
    SdrObject* pObj = GetSdrObject();
    if( pObj )
    {
        ScDrawLayer& rModel(static_cast< ScDrawLayer& >(pObj->getSdrModelFromSdrObject()));
        SdrPage* pPage(pObj->GetPage());
        ScDocument* pDoc = rModel.GetDocument();

        if ( pPage && pDoc )
        ScDrawLayer* pModel = static_cast<ScDrawLayer*>(pObj->GetModel());
        SdrPage* pPage = pObj->GetPage();
        if ( pModel )
        {
            SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
            if ( pObjSh && dynamic_cast<const ScDocShell*>( pObjSh) !=  nullptr )
            ScDocument* pDoc = pModel->GetDocument();
            if ( pDoc )
            {
                ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);

                SCTAB nTab = 0;
                if ( lcl_GetPageNum( pPage, rModel, nTab ) )
                SfxObjectShell* pObjSh = pDoc->GetDocumentShell();
                if ( pObjSh && dynamic_cast<const ScDocShell*>( pObjSh) !=  nullptr )
                {
                    const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab );
                    if( pCaptData )
                        return static_cast< ::cppu::OWeakObject* >( new ScCellObj( pDocSh, pCaptData->maStart ) );
                    ScDocShell* pDocSh = static_cast<ScDocShell*>(pObjSh);

                    SCTAB nTab = 0;
                    if ( lcl_GetPageNum( pPage, *pModel, nTab ) )
                    {
                        const ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( pObj, nTab );
                        if( pCaptData )
                            return static_cast< ::cppu::OWeakObject* >( new ScCellObj( pDocSh, pCaptData->maStart ) );
                    }
                }
            }
        }
diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx
index bbe58cd..4be43b13 100644
--- a/sc/source/ui/view/drawvie3.cxx
+++ b/sc/source/ui/view/drawvie3.cxx
@@ -34,10 +34,8 @@
#include <tabvwsh.hxx>
#include <docsh.hxx>

ScDrawView::ScDrawView(
    OutputDevice* pOut,
    ScViewData* pData )
:   FmFormView(*pData->GetDocument()->GetDrawLayer(), pOut),
ScDrawView::ScDrawView( OutputDevice* pOut, ScViewData* pData ) :
    FmFormView( pData->GetDocument()->GetDrawLayer(), pOut ),
    pViewData( pData ),
    pDev( pOut ),
    pDoc( pData->GetDocument() ),
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index 0561a41..de4ff2c 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -1197,10 +1197,7 @@ void ScGridWindow::PaintTile( VirtualDevice& rDevice,
    ScDrawLayer* pModel = pDoc->GetDrawLayer();
    if (pModel)
    {
        mpLOKDrawView.reset(
            new FmFormView(
                *pModel,
                &rDevice));
        mpLOKDrawView.reset(new FmFormView(pModel, &rDevice));
        mpLOKDrawView->ShowSdrPage(mpLOKDrawView->GetModel()->GetPage(nTab));
        aOutputData.SetDrawView(mpLOKDrawView.get());
        aOutputData.SetSpellCheckContext(mpSpellCheckCxt.get());
diff --git a/sc/source/ui/view/preview.cxx b/sc/source/ui/view/preview.cxx
index 11596ac..ae4a3fc 100644
--- a/sc/source/ui/view/preview.cxx
+++ b/sc/source/ui/view/preview.cxx
@@ -165,9 +165,7 @@ void ScPreview::UpdateDrawView()        // nTab must be right

        if ( !pDrawView )                                   // New Drawing?
        {
            pDrawView = new FmFormView(
                *pModel,
                this);
            pDrawView = new FmFormView( pModel, this );

            // The DrawView takes over the Design-Mode from the Model
            // (Settings "In opening Draftmode"), therefore to restore here
diff --git a/sc/source/ui/view/printfun.cxx b/sc/source/ui/view/printfun.cxx
index 58316cf..cdafc45 100644
--- a/sc/source/ui/view/printfun.cxx
+++ b/sc/source/ui/view/printfun.cxx
@@ -564,10 +564,7 @@ void ScPrintFunc::DrawToDev( ScDocument* pDoc, OutputDevice* pDev, double /* nPr

    if( pModel )
    {
        pDrawView.reset(
            new FmFormView(
                *pModel,
                pDev));
        pDrawView.reset(new FmFormView( pModel, pDev ));
        pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
        pDrawView->SetPrintPreview();
        aOutputData.SetDrawView( pDrawView.get() );
diff --git a/sc/source/ui/view/tabvwshg.cxx b/sc/source/ui/view/tabvwshg.cxx
index d081c87..ba44266 100644
--- a/sc/source/ui/view/tabvwshg.cxx
+++ b/sc/source/ui/view/tabvwshg.cxx
@@ -60,11 +60,8 @@ void ScTabViewShell::InsertURLButton( const OUString& rName, const OUString& rUR
    ScDrawView* pDrView = pView->GetScDrawView();
    SdrModel*   pModel  = pDrView->GetModel();

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pModel,
        SdrInventor::FmForm,
        OBJ_FM_BUTTON,
        pDrView->GetSdrPageView()->GetPage());
    SdrObject* pObj = SdrObjFactory::MakeNewObject(SdrInventor::FmForm, OBJ_FM_BUTTON,
                               pDrView->GetSdrPageView()->GetPage(), pModel);
    SdrUnoObj* pUnoCtrl = dynamic_cast<SdrUnoObj*>( pObj );
    OSL_ENSURE( pUnoCtrl, "no SdrUnoObj");
    if( !pUnoCtrl )
diff --git a/sc/source/ui/view/viewfun7.cxx b/sc/source/ui/view/viewfun7.cxx
index cfbd4be..e1f521c 100644
--- a/sc/source/ui/view/viewfun7.cxx
+++ b/sc/source/ui/view/viewfun7.cxx
@@ -153,12 +153,11 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, SdrModel* pModel,
                const SdrMark* pM=aMark.GetMark(nm);
                const SdrObject* pObj=pM->GetMarkedSdrObj();

                // Directly Clone to taget  SdrModel
                SdrObject* pNewObj(pObj->Clone(pDrawModel));
                SdrObject* pNewObj=pObj->Clone();

                if (pNewObj!=nullptr)
                {
                    // pNewObj->SetModel(pDrawModel);
                    pNewObj->SetModel(pDrawModel);
                    pNewObj->SetPage(pDestPage);

                    //  copy graphics within the same model - always needs new name
@@ -194,9 +193,8 @@ void ScViewFunc::PasteDraw( const Point& rLogicPos, SdrModel* pModel,
    else
    {
        bPasteIsMove = false;       // no internal move happened
        // TTTT hide all non-direct SdrView constr to disable construct
        // in-between classes in one of the next steps (!)
        SdrView aView(*pModel);     // #i71529# never create a base class of SdrView directly!

        SdrView aView(pModel);      // #i71529# never create a base class of SdrView directly!
        SdrPageView* pPv = aView.ShowSdrPage(aView.GetModel()->GetPage(0));
        aView.MarkAllObj(pPv);
        Size aSize = aView.GetAllMarkedRect().GetSize();
@@ -355,11 +353,7 @@ bool ScViewFunc::PasteObject( const Point& rPos, const uno::Reference < embed::X
        tools::Rectangle aRect( aInsPos, aSize );

        ScDrawView* pDrView = GetScDrawView();
        SdrOle2Obj* pSdrObj = new SdrOle2Obj(
            pDrView->getSdrModelFromSdrView(),
            aObjRef,
            aName,
            aRect);
        SdrOle2Obj* pSdrObj = new SdrOle2Obj( aObjRef, aName, aRect );

        SdrPageView* pPV = pDrView->GetSdrPageView();
        pDrView->InsertObjectSafe( pSdrObj, *pPV );             // don't mark if OLE
@@ -438,10 +432,7 @@ bool ScViewFunc::PasteGraphic( const Point& rPos, const Graphic& rGraphic,

    GetViewData().GetViewShell()->SetDrawShell( true );
    tools::Rectangle aRect(aPos, aSize);
    SdrGrafObj* pGrafObj = new SdrGrafObj(
        pScDrawView->getSdrModelFromSdrView(),
        rGraphic,
        aRect);
    SdrGrafObj* pGrafObj = new SdrGrafObj(rGraphic, aRect);

    // path was the name of the graphic in history

diff --git a/sd/inc/CustomAnimationEffect.hxx b/sd/inc/CustomAnimationEffect.hxx
index 53e08b7..6322d36 100644
--- a/sd/inc/CustomAnimationEffect.hxx
+++ b/sd/inc/CustomAnimationEffect.hxx
@@ -25,15 +25,17 @@
#include <com/sun/star/animations/XAudio.hpp>
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/util/XChangesListener.hpp>

#include <vcl/timer.hxx>

#include "sddllapi.h"

#include <list>
#include <vector>
#include <map>
#include <memory>

class SdrPathObj;
class SdrModel;

namespace sd {

@@ -165,7 +167,7 @@ public:
    SAL_DLLPRIVATE static sal_Int32 get_node_type( const css::uno::Reference< css::animations::XAnimationNode >& xNode );
    SAL_DLLPRIVATE static sal_Int32 getNumberOfSubitems( const css::uno::Any& aTarget, sal_Int16 nIterateType );

    SAL_DLLPRIVATE SdrPathObj* createSdrPathObjFromPath(SdrModel& rTargetModel);
    SAL_DLLPRIVATE SdrPathObj* createSdrPathObjFromPath();
    SAL_DLLPRIVATE void updateSdrPathObjFromPath( SdrPathObj& rPathObj );
    SAL_DLLPRIVATE void updatePathFromSdrPathObj( const SdrPathObj& rPathObj );

diff --git a/sd/inc/sdpage.hxx b/sd/inc/sdpage.hxx
index 5dedec0..42af131 100644
--- a/sd/inc/sdpage.hxx
+++ b/sd/inc/sdpage.hxx
@@ -93,7 +93,6 @@ namespace sd {
class SD_DLLPUBLIC SdPage final : public FmFormPage, public SdrObjUserCall
{
    SdPage& operator=(const SdPage&) = delete;
    SdPage(const SdPage&) = delete;

friend class SdGenericDrawPage;
friend class SdDrawPage;
@@ -148,14 +147,15 @@ friend class sd::UndoAttrObject;
    sal_Int32 mnTransitionFadeColor;
    double mfTransitionDuration;

    SdPage(const SdPage& rSrcPage);
    void lateInit(const SdPage& rSrcPage);

public:

    SdPage(SdDrawDocument& rNewDoc, bool bMasterPage);
    virtual ~SdPage() override;

    virtual SdrPage* Clone(SdrModel* pNewModel = nullptr) const override;
    virtual SdrPage* Clone() const override;
    virtual SdrPage* Clone(SdrModel* pNewModel) const override;

    virtual void    SetSize(const Size& aSize) override;
    virtual void    SetBorder(sal_Int32 nLft, sal_Int32 nUpp, sal_Int32 nRgt, sal_Int32 Lwr) override;
@@ -163,6 +163,7 @@ public:
    virtual void    SetRightBorder(sal_Int32 nBorder) override;
    virtual void    SetUpperBorder(sal_Int32 nBorder) override;
    virtual void    SetLowerBorder(sal_Int32 nBorder) override;
    virtual void    SetModel(SdrModel* pNewModel) override;
    virtual bool    IsReadOnly() const override;

    sd::ShapeList&  GetPresentationShapeList() { return maPresentationShapeList; }
@@ -387,8 +388,6 @@ private:
    sal_uInt16 mnPageId;

    /** clone the animations from this and set them to rTargetPage
     *  TTTT: Order is strange, should be the other way around by
     *  convention/convenience and makes usage a little dangerous...
    */
    void cloneAnimations( SdPage& rTargetPage ) const;

diff --git a/sd/source/core/CustomAnimationEffect.cxx b/sd/source/core/CustomAnimationEffect.cxx
index 1473358..2d1025d 100644
--- a/sd/source/core/CustomAnimationEffect.cxx
+++ b/sd/source/core/CustomAnimationEffect.cxx
@@ -1528,9 +1528,9 @@ bool CustomAnimationEffect::getStopAudio() const
    return mnCommand == EffectCommands::STOPAUDIO;
}

SdrPathObj* CustomAnimationEffect::createSdrPathObjFromPath(SdrModel& rTargetModel)
SdrPathObj* CustomAnimationEffect::createSdrPathObjFromPath()
{
    SdrPathObj * pPathObj = new SdrPathObj(rTargetModel, OBJ_PATHLINE);
    SdrPathObj * pPathObj = new SdrPathObj( OBJ_PATHLINE );
    updateSdrPathObjFromPath( *pPathObj );
    return pPathObj;
}
diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx
index 38c6db7..ce442b4 100644
--- a/sd/source/core/annotations/Annotation.cxx
+++ b/sd/source/core/annotations/Annotation.cxx
@@ -69,7 +69,7 @@ public:
    static sal_uInt32 m_nLastId;

    SdPage* GetPage() const { return mpPage; }
    SdrModel* GetModel() { return (mpPage != nullptr) ? &mpPage->getSdrModelFromSdrPage() : nullptr; }
    SdrModel* GetModel() { return (mpPage != nullptr) ? mpPage->GetModel() : nullptr; }
    sal_uInt32 GetId() const { return m_nId; }

    // XInterface:
@@ -366,7 +366,7 @@ Reference< XText > SAL_CALL Annotation::getTextRange()
    osl::MutexGuard g(m_aMutex);
    if( !m_TextRange.is() && (mpPage != nullptr) )
    {
        m_TextRange = TextApiObject::create( static_cast< SdDrawDocument* >( &mpPage->getSdrModelFromSdrPage() ) );
        m_TextRange = TextApiObject::create( static_cast< SdDrawDocument* >( mpPage->GetModel() ) );
    }
    return Reference< XText >( m_TextRange.get() );
}
diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 500a88c..d6335e3 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -657,7 +657,22 @@ void SdDrawDocument::NewOrLoadCompleted(DocCreationMode eMode)
    }

    mbNewOrLoadCompleted = true;

    // Update all linked pages
    sal_uInt16 nMaxSdPages = GetSdPageCount(PageKind::Standard);

    for (sal_uInt16 nSdPage=0; nSdPage < nMaxSdPages; nSdPage++)
    {
        SdPage* pPage = GetSdPage(nSdPage, PageKind::Standard);

        if (pPage && !pPage->GetFileName().isEmpty() && pPage->GetBookmarkName().getLength())
        {
            pPage->SetModel(this);
        }
    }

    UpdateAllLinks();

    SetChanged( false );
}

diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx
index 00a6056..9bc68bc 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -608,6 +608,7 @@ bool SdDrawDocument::InsertBookmarkAsPage(
                // Assemble all link names
                pPage->SetFileName(aBookmarkName);
                pPage->SetBookmarkName(aName);
                pPage->SetModel(this);
            }

            nActualInsertPos += 2;
@@ -704,6 +705,7 @@ bool SdDrawDocument::InsertBookmarkAsPage(
                    SdPage* pPage = static_cast<SdPage*>( GetPage(nActualInsertPos) );
                    pPage->SetFileName(aBookmarkName);
                    pPage->SetBookmarkName(aPgName);
                    pPage->SetModel(this);
                }

                if (bReplace)
diff --git a/sd/source/core/pglink.cxx b/sd/source/core/pglink.cxx
index 6762dcd..93180e1 100644
--- a/sd/source/core/pglink.cxx
+++ b/sd/source/core/pglink.cxx
@@ -57,7 +57,7 @@ SdPageLink::~SdPageLink()
::sfx2::SvBaseLink::UpdateResult SdPageLink::DataChanged(
    const OUString&, const css::uno::Any& )
{
    SdDrawDocument* pDoc = static_cast<SdDrawDocument*>( &pPage->getSdrModelFromSdrPage() );
    SdDrawDocument* pDoc = static_cast<SdDrawDocument*>( pPage->GetModel() );
    sfx2::LinkManager* pLinkManager = pDoc!=nullptr ? pDoc->GetLinkManager() : nullptr;

    if (pLinkManager)
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx
index eed4fa2..ad906e2 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -129,9 +129,6 @@ SdPage::SdPage(SdDrawDocument& rNewDoc, bool bMasterPage)
    // presentation template of the outline objects. Therefore, it already
    // contains the designator for the outline (STR_LAYOUT_OUTLINE).
    maLayoutName = SdResId(STR_LAYOUT_DEFAULT_NAME)+ SD_LT_SEPARATOR STR_LAYOUT_OUTLINE;

    // Stuff that former SetModel did also:
    ConnectLink();
}

namespace
@@ -270,7 +267,7 @@ void SdPage::EnsureMasterPageDefaultBackground()
*/
SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::tools::Rectangle& rRect )
{
    ::svl::IUndoManager* pUndoManager(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetUndoManager());
    ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : nullptr;
    const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();

    SdrObject* pSdrObj = nullptr;
@@ -282,7 +279,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
    {
        case PRESOBJ_TITLE:
        {
            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), OBJ_TITLETEXT);
            pSdrObj = new SdrRectObj(OBJ_TITLETEXT);

            if (mbMaster)
            {
@@ -293,7 +290,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        case PRESOBJ_OUTLINE:
        {
            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), OBJ_OUTLINETEXT);
            pSdrObj = new SdrRectObj(OBJ_OUTLINETEXT);

            if (mbMaster)
            {
@@ -304,7 +301,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        case PRESOBJ_NOTES:
        {
            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), OBJ_TEXT);
            pSdrObj = new SdrRectObj(OBJ_TEXT);

            if (mbMaster)
            {
@@ -315,7 +312,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        case PRESOBJ_TEXT:
        {
            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), OBJ_TEXT);
            pSdrObj = new SdrRectObj(OBJ_TEXT);
        }
        break;

@@ -333,7 +330,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
            Size aSize = aOutDev.PixelToLogic(aSizePix);
            Point aPnt (0, 0);
            ::tools::Rectangle aRect (aPnt, aSize);
            pSdrObj = new SdrGrafObj(getSdrModelFromSdrPage(), aGraphic, aRect);
            pSdrObj = new SdrGrafObj(aGraphic, aRect);
            aOutDev.Pop();
        }
        break;
@@ -341,7 +338,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
        case PRESOBJ_MEDIA:
        case PRESOBJ_OBJECT:
        {
            pSdrObj = new SdrOle2Obj(getSdrModelFromSdrPage());
            pSdrObj = new SdrOle2Obj();
            BitmapEx aBmpEx(BMP_PRESOBJ_OBJECT);
            Graphic aGraphic( aBmpEx );
            static_cast<SdrOle2Obj*>(pSdrObj)->SetGraphic(aGraphic);
@@ -350,7 +347,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        case PRESOBJ_CHART:
        {
            pSdrObj = new SdrOle2Obj(getSdrModelFromSdrPage());
            pSdrObj = new SdrOle2Obj();
            static_cast<SdrOle2Obj*>(pSdrObj)->SetProgName( "StarChart" );
            BitmapEx aBmpEx(BMP_PRESOBJ_CHART);
            Graphic aGraphic( aBmpEx );
@@ -360,7 +357,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        case PRESOBJ_ORGCHART:
        {
            pSdrObj = new SdrOle2Obj(getSdrModelFromSdrPage());
            pSdrObj = new SdrOle2Obj();
            static_cast<SdrOle2Obj*>(pSdrObj)->SetProgName( "StarOrg" );
            BitmapEx aBmpEx(BMP_PRESOBJ_ORGCHART);
            Graphic aGraphic( aBmpEx );
@@ -371,7 +368,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
        case PRESOBJ_TABLE:
        case PRESOBJ_CALC:
        {
            pSdrObj = new SdrOle2Obj(getSdrModelFromSdrPage());
            pSdrObj = new SdrOle2Obj();
            static_cast<SdrOle2Obj*>(pSdrObj)->SetProgName( "StarCalc" );
            BitmapEx aBmpEx(BMP_PRESOBJ_TABLE);
            Graphic aGraphic( aBmpEx );
@@ -384,7 +381,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
            // Save the first standard page at SdrPageObj
            // #i105146# We want no content to be displayed for PageKind::Handout,
            // so just never set a page as content
            pSdrObj = new SdrPageObj(getSdrModelFromSdrPage(), nullptr);
            pSdrObj = new SdrPageObj(nullptr);
        }
        break;

@@ -399,13 +396,13 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
                nDestPageNum -= 1;
            }

            if (nDestPageNum < getSdrModelFromSdrPage().GetPageCount())
            if (pModel && nDestPageNum < pModel->GetPageCount())
            {
                pSdrObj = new SdrPageObj(getSdrModelFromSdrPage(), getSdrModelFromSdrPage().GetPage(nDestPageNum));
                pSdrObj = new SdrPageObj(pModel->GetPage(nDestPageNum));
            }
            else
            {
                pSdrObj = new SdrPageObj(getSdrModelFromSdrPage());
                pSdrObj = new SdrPageObj();
            }

            pSdrObj->SetResizeProtect(true);
@@ -417,7 +414,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
        case PRESOBJ_DATETIME:
        case PRESOBJ_SLIDENUMBER:
        {
            pSdrObj = new SdrRectObj(getSdrModelFromSdrPage(), OBJ_TEXT);
            pSdrObj = new SdrRectObj(OBJ_TEXT);
            bEmptyPresObj = false;
            bForceText = true;
        }
@@ -440,7 +437,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
            if(bVertical)
                static_cast<SdrTextObj*>(pSdrObj)->SetVerticalWriting(true);

            SfxItemSet aTempAttr(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool());
            SfxItemSet aTempAttr( static_cast<SdDrawDocument*>(pModel)->GetPool() );
            if( bVertical )
                aTempAttr.Put( makeSdrTextMinFrameWidthItem( rRect.GetSize().Width() ) );
            else
@@ -482,7 +479,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
        OUString aString = GetPresObjText(eObjKind);
        if( (!aString.isEmpty() || bForceText) && dynamic_cast< const SdrTextObj *>( pSdrObj ) !=  nullptr )
        {
            SdrOutliner* pOutliner = static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetInternalOutliner();
            SdrOutliner* pOutliner = static_cast<SdDrawDocument*>( GetModel() )->GetInternalOutliner();

            OutlinerMode nOutlMode = pOutliner->GetMode();
            pOutliner->Init( OutlinerMode::TextObject );
@@ -497,7 +494,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        if( (eObjKind == PRESOBJ_HEADER) || (eObjKind == PRESOBJ_FOOTER) || (eObjKind == PRESOBJ_SLIDENUMBER) || (eObjKind == PRESOBJ_DATETIME) )
        {
            SfxItemSet aTempAttr(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool());
            SfxItemSet aTempAttr( static_cast<SdDrawDocument*>(pModel)->GetPool() );
            aTempAttr.Put( SvxFontHeightItem( 493, 100, EE_CHAR_FONTHEIGHT ) );
            aTempAttr.Put( SvxFontHeightItem( 493, 100, EE_CHAR_FONTHEIGHT_CTL ) );
            aTempAttr.Put( SvxFontHeightItem( 493, 100, EE_CHAR_FONTHEIGHT_CJK ) );
@@ -525,7 +522,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        if (mbMaster)
        {
            SdrLayerAdmin& rLayerAdmin(getSdrModelFromSdrPage().GetLayerAdmin());
            SdrLayerAdmin& rLayerAdmin = pModel->GetLayerAdmin();

            // background objects of the master page
            pSdrObj->SetLayer( rLayerAdmin.
@@ -546,7 +543,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
            for (sal_uInt16 nLevel = 1; nLevel < 10; nLevel++)
            {
                OUString aName( maLayoutName + " " + OUString::number( nLevel ) );
                SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page));
                SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pModel->GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page));
                DBG_ASSERT(pSheet, "StyleSheet for outline object not found");
                if (pSheet)
                    pSdrObj->StartListening(*pSheet);
@@ -559,7 +556,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t
             eObjKind == PRESOBJ_CALC    ||
             eObjKind == PRESOBJ_GRAPHIC )
        {
            SfxItemSet aSet( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool() );
            SfxItemSet aSet( static_cast<SdDrawDocument*>(pModel)->GetPool() );
            aSet.Put( makeSdrTextContourFrameItem( true ) );
            aSet.Put( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST ) );

@@ -568,7 +565,7 @@ SdrObject* SdPage::CreatePresObj(PresObjKind eObjKind, bool bVertical, const ::t

        if( bUndo )
        {
            pUndoManager->AddUndoAction(getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoNewObject(*pSdrObj));
            pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoNewObject(*pSdrObj));
        }

        if( bUndo )
@@ -607,7 +604,7 @@ SfxStyleSheet* SdPage::GetStyleSheetForMasterPageBackground() const

    aName += STR_LAYOUT_BACKGROUND;

    SfxStyleSheetBasePool* pStShPool = getSdrModelFromSdrPage().GetStyleSheetPool();
    SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
    SfxStyleSheetBase*     pResult   = pStShPool->Find(aName, SfxStyleFamily::Page);
    return static_cast<SfxStyleSheet*>(pResult);
}
@@ -654,7 +651,7 @@ SfxStyleSheet* SdPage::GetStyleSheetForPresObj(PresObjKind eObjKind) const
            break;
    }

    SfxStyleSheetBasePool* pStShPool = getSdrModelFromSdrPage().GetStyleSheetPool();
    SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
    SfxStyleSheetBase*     pResult   = pStShPool->Find(aName, SfxStyleFamily::Page);
    return static_cast<SfxStyleSheet*>(pResult);
}
@@ -699,7 +696,7 @@ SdStyleSheet* SdPage::getPresentationStyle( sal_uInt32 nHelpId ) const
        aStyleName += OUString::number( sal_Int32( nHelpId - HID_PSEUDOSHEET_OUTLINE ));
    }

    SfxStyleSheetBasePool* pStShPool = getSdrModelFromSdrPage().GetStyleSheetPool();
    SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();
    SfxStyleSheetBase*     pResult   = pStShPool->Find(aStyleName, SfxStyleFamily::Page);
    return dynamic_cast<SdStyleSheet*>(pResult);
}
@@ -721,7 +718,7 @@ void SdPage::Changed(const SdrObject& rObj, SdrUserCallType eType, const ::tools
            case SdrUserCallType::MoveOnly:
            case SdrUserCallType::Resize:
            {
                if ( getSdrModelFromSdrPage().isLocked())
                if (!pModel || pModel->isLocked())
                    break;

                SdrObject* pObj = const_cast<SdrObject*>(&rObj);
@@ -732,7 +729,7 @@ void SdPage::Changed(const SdrObject& rObj, SdrUserCallType eType, const ::tools
                    {
                        if( pObj->GetUserCall() )
                        {
                            ::svl::IUndoManager* pUndoManager = static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetUndoManager();
                            ::svl::IUndoManager* pUndoManager = static_cast<SdDrawDocument*>(pModel)->GetUndoManager();
                            const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();

                            if( bUndo )
@@ -746,11 +743,11 @@ void SdPage::Changed(const SdrObject& rObj, SdrUserCallType eType, const ::tools
                    {
                        // Object of the master page changed, therefore adjust
                        // object on all pages
                        sal_uInt16 nPageCount = static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetSdPageCount(mePageKind);
                        sal_uInt16 nPageCount = static_cast<SdDrawDocument*>(pModel)->GetSdPageCount(mePageKind);

                        for (sal_uInt16 i = 0; i < nPageCount; i++)
                        {
                            SdPage* pLoopPage = static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetSdPage(i, mePageKind);
                            SdPage* pLoopPage = static_cast<SdDrawDocument*>(pModel)->GetSdPage(i, mePageKind);

                            if (pLoopPage && this == &(pLoopPage->TRG_GetMasterPage()))
                            {
@@ -780,7 +777,7 @@ void SdPage::Changed(const SdrObject& rObj, SdrUserCallType eType, const ::tools

void SdPage::CreateTitleAndLayout(bool bInit, bool bCreate )
{
    ::svl::IUndoManager* pUndoManager(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetUndoManager());
    ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : nullptr;
    const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();

    SdPage* pMasterPage = this;
@@ -803,7 +800,7 @@ void SdPage::CreateTitleAndLayout(bool bInit, bool bCreate )
        pMasterPage->EnsureMasterPageDefaultBackground();
    }

    if (static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetDocumentType() == DocumentType::Impress)
    if (GetModel() && static_cast<SdDrawDocument*>(GetModel())->GetDocumentType() == DocumentType::Impress)
    {
        if( mePageKind == PageKind::Handout && bInit )
        {
@@ -817,7 +814,7 @@ void SdPage::CreateTitleAndLayout(bool bInit, bool bCreate )

                if( bUndo )
                {
                    pUndoManager->AddUndoAction(getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
                    pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
                }
                else
                {
@@ -826,7 +823,7 @@ void SdPage::CreateTitleAndLayout(bool bInit, bool bCreate )
            }

            std::vector< ::tools::Rectangle > aAreas;
            CalculateHandoutAreas( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()), pMasterPage->GetAutoLayout(), false, aAreas );
            CalculateHandoutAreas( *static_cast< SdDrawDocument* >(GetModel() ), pMasterPage->GetAutoLayout(), false, aAreas );

            const bool bSkip = pMasterPage->GetAutoLayout() == AUTOLAYOUT_HANDOUT3;
            std::vector< ::tools::Rectangle >::iterator iter( aAreas.begin() );
@@ -900,7 +897,7 @@ void getPresObjProp( const SdPage& rPage, const char* sObjKind, const char* sPag
{
    bool bNoObjectFound = true;  //used to break from outer loop

    const std::vector< Reference<XNode> >& objectInfo = static_cast< const SdDrawDocument& >(rPage.getSdrModelFromSdrPage()).GetObjectVector();
    const std::vector< Reference<XNode> >& objectInfo = static_cast<const SdDrawDocument*>(rPage.GetModel())->GetObjectVector();
    for( std::vector< Reference<XNode> >::const_iterator aIter=objectInfo.begin(); aIter != objectInfo.end(); ++aIter )
    {
        if(bNoObjectFound)
@@ -1050,7 +1047,8 @@ void SdPage::DestroyDefaultPresObj(PresObjKind eObjKind)

    if( pObject )
    {
        SdDrawDocument* pDoc(static_cast< SdDrawDocument* >(&getSdrModelFromSdrPage()));
        SdDrawDocument *pDoc = static_cast<SdDrawDocument*>(pModel);

        const bool bUndo = pDoc->IsUndoEnabled();
        if( bUndo )
            pDoc->AddUndo(pDoc->GetSdrUndoFactory().CreateUndoDeleteObject(*pObject));
@@ -1115,9 +1113,9 @@ void SdPage::DestroyDefaultPresObj(PresObjKind eObjKind)
                nDestPageNum -= 1;
            }

            if(nDestPageNum < getSdrModelFromSdrPage().GetPageCount())
            if(nDestPageNum < pModel->GetPageCount())
            {
                pRefPage = getSdrModelFromSdrPage().GetPage(nDestPageNum);
                pRefPage = pModel->GetPage(nDestPageNum);
            }

            if ( pRefPage )
@@ -1364,7 +1362,7 @@ static void CalcAutoLayoutRectangles( SdPage const & rPage,::tools::Rectangle* r
    const Point aLayoutPos( aLayoutRect.TopLeft() );
    double propvalue[] = {0,0,0,0};

    const std::vector< Reference<XNode> >& layoutInfo = static_cast< const SdDrawDocument& >(rPage.getSdrModelFromSdrPage()).GetLayoutVector();
    const std::vector< Reference<XNode> >& layoutInfo = static_cast<const SdDrawDocument*>(rPage.GetModel())->GetLayoutVector();
    for( std::vector< Reference<XNode> >::const_iterator aIter=layoutInfo.begin(); aIter != layoutInfo.end(); ++aIter )
    {
        Reference<XNode> layoutNode = *aIter;
@@ -1523,10 +1521,10 @@ void findAutoLayoutShapesImpl( SdPage& rPage, const LayoutDescriptor& rDescripto
                        {
                            if( pOle2->IsEmpty() )
                                bFound = true;
                            else
                            else if( rPage.GetModel() )
                            {
                                ::comphelper::IEmbeddedHelper* pPersist(rPage.getSdrModelFromSdrPage().GetPersist());

                                SdrModel* pSdrModel = rPage.GetModel();
                                ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
                                if( pPersist )
                                {
                                    uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
@@ -1600,7 +1598,7 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, bool bInit, bool bCreate )

    const bool bSwitchLayout = eLayout != GetAutoLayout();

    ::svl::IUndoManager* pUndoManager(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetUndoManager());
    ::svl::IUndoManager* pUndoManager = pModel ? static_cast<SdDrawDocument*>(pModel)->GetUndoManager() : nullptr;
    const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();

    meAutoLayout = eLayout;
@@ -1649,7 +1647,7 @@ void SdPage::SetAutoLayout(AutoLayout eLayout, bool bInit, bool bCreate )
                if( pObj->IsEmptyPresObj() )
                {
                    if( bUndo )
                        pUndoManager->AddUndoAction(getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));
                        pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pObj));

                    RemoveObject( pObj->GetOrdNum() );

@@ -1672,7 +1670,7 @@ void SdPage::NbcInsertObject(SdrObject* pObj, size_t nPos)
{
    FmFormPage::NbcInsertObject(pObj, nPos);

    static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).InsertObject(pObj);
    static_cast<SdDrawDocument*>(pModel)->InsertObject(pObj);

    SdrLayerID nId = pObj->GetLayer();
    if( mbMaster )
@@ -1735,7 +1733,8 @@ void SdPage::onRemoveObject( SdrObject* pObject )
    {
        RemovePresObj(pObject);

        static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).RemoveObject(pObject);
        if( pModel )
            static_cast<SdDrawDocument*>(pModel)->RemoveObject(pObject);

        removeAnimations( pObject );
    }
@@ -1957,7 +1956,7 @@ void SdPage::ScaleObjects(const Size& rNewPageSize, const ::tools::Rectangle& rN
                            for (sal_Int32 i=1; i<=9; i++)
                            {
                                OUString sLayoutName( aName + OUString::number( i ) );
                                SfxStyleSheet* pOutlineSheet = static_cast<SfxStyleSheet*>(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetStyleSheetPool()->Find(sLayoutName, SfxStyleFamily::Page));
                                SfxStyleSheet* pOutlineSheet = static_cast<SfxStyleSheet*>(static_cast<SdDrawDocument*>(pModel)->GetStyleSheetPool()->Find(sLayoutName, SfxStyleFamily::Page));

                                if (pOutlineSheet)
                                {
@@ -2078,11 +2077,12 @@ void SdPage::ScaleObjects(const Size& rNewPageSize, const ::tools::Rectangle& rN

SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, PresObjKind& eObjKind, bool bVertical, const ::tools::Rectangle& rRect)
{
    SdDrawDocument& rModel(static_cast< SdDrawDocument& >(rPage.getSdrModelFromSdrPage()));
    if( !pSourceObj )
    SdDrawDocument* pModel = static_cast< SdDrawDocument* >( rPage.GetModel() );
    DBG_ASSERT( pModel, "sd::convertPresentationObjectImpl(), no model on page!" );
    if( !pModel || !pSourceObj )
        return pSourceObj;

    ::svl::IUndoManager* pUndoManager = rModel.GetUndoManager();
    ::svl::IUndoManager* pUndoManager = pModel->GetUndoManager();
    const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && rPage.IsInserted();

    SdrObject* pNewObj = pSourceObj;
@@ -2096,7 +2096,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
        if(pOutlParaObj)
        {
            // assign text
            SdOutliner* pOutl = rModel.GetInternalOutliner();
            SdOutliner* pOutl = pModel->GetInternalOutliner();
            pOutl->Clear();
            pOutl->SetText( *pOutlParaObj );
            pOutlParaObj = pOutl->CreateParaObject();
@@ -2108,7 +2108,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
            {
                // assign new template
                OUString aName( rPage.GetLayoutName() + " " + OUString::number( nLevel ) );
                SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>( rModel.GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page) );
                SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>( pModel->GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page) );

                if (pSheet)
                {
@@ -2125,7 +2125,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
            }

            // Remove LRSpace item
            SfxItemSet aSet(rModel.GetPool(), svl::Items<EE_PARA_LRSPACE, EE_PARA_LRSPACE>{} );
            SfxItemSet aSet(pModel->GetPool(), svl::Items<EE_PARA_LRSPACE, EE_PARA_LRSPACE>{} );

            aSet.Put(pNewObj->GetMergedItemSet());

@@ -2134,7 +2134,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
            pNewObj->SetMergedItemSet(aSet);

            if( bUndo )
                pUndoManager->AddUndoAction( rModel.GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj) );
                pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj) );

            // Remove outline shape from page
            rPage.RemoveObject( pSourceObj->GetOrdNum() );
@@ -2154,7 +2154,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
        if(pOutlParaObj)
        {
            // assign text
            SdOutliner* pOutl = rModel.GetInternalOutliner();
            SdOutliner* pOutl = pModel->GetInternalOutliner();
            pOutl->Clear();
            pOutl->SetText( *pOutlParaObj );
            pOutlParaObj = pOutl->CreateParaObject();
@@ -2163,7 +2163,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
            pNewObj->SetEmptyPresObj(false);

            // reset left indent
            SfxItemSet aSet(rModel.GetPool(), svl::Items<EE_PARA_LRSPACE, EE_PARA_LRSPACE>{} );
            SfxItemSet aSet(pModel->GetPool(), svl::Items<EE_PARA_LRSPACE, EE_PARA_LRSPACE>{} );

            aSet.Put(pNewObj->GetMergedItemSet());

@@ -2180,7 +2180,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P

            // Remove subtitle shape from page
            if( bUndo )
                pUndoManager->AddUndoAction(rModel.GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj));
                pUndoManager->AddUndoAction(pModel->GetSdrUndoFactory().CreateUndoDeleteObject(*pSourceObj));

            rPage.RemoveObject( pSourceObj->GetOrdNum() );

@@ -2220,7 +2220,7 @@ SdrObject* convertPresentationObjectImpl(SdPage& rPage, SdrObject* pSourceObj, P
*/
SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, bool bVertical, const ::tools::Rectangle& rRect, bool bInit)
{
    ::svl::IUndoManager* pUndoManager(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetUndoManager());
    ::svl::IUndoManager* pUndoManager = static_cast<SdDrawDocument*>(pModel)->GetUndoManager();
    const bool bUndo = pUndoManager && pUndoManager->IsInListAction() && IsInserted();

    if (!pObj && bInit)
@@ -2235,8 +2235,8 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, 

        if( bUndo )
        {
            pUndoManager->AddUndoAction( getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
            pUndoManager->AddUndoAction( getSdrModelFromSdrPage().GetSdrUndoFactory().CreateUndoAttrObject( *pObj, true, true ) );
            pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoGeoObject( *pObj ) );
            pUndoManager->AddUndoAction( pModel->GetSdrUndoFactory().CreateUndoAttrObject( *pObj, true, true ) );
            pUndoManager->AddUndoAction( new UndoObjectUserCall( *pObj ) );
        }

@@ -2262,7 +2262,7 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, 
                if ( pTextObject->IsAutoGrowHeight() )
                {
                    // switch off AutoGrowHeight, set new MinHeight
                    SfxItemSet aTempAttr( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool() );
                    SfxItemSet aTempAttr( static_cast<SdDrawDocument*>(pModel)->GetPool() );
                    SdrMetricItem aMinHeight( makeSdrTextMinFrameHeightItem(rRect.GetSize().Height()) );
                    aTempAttr.Put( aMinHeight );
                    aTempAttr.Put( makeSdrTextAutoGrowHeightItem(false) );
@@ -2270,7 +2270,7 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, 
                    pTextObject->SetLogicRect(rRect);

                    // switch on AutoGrowHeight
                    SfxItemSet aAttr( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool() );
                    SfxItemSet aAttr( static_cast<SdDrawDocument*>(pModel)->GetPool() );
                    aAttr.Put( makeSdrTextAutoGrowHeightItem(true) );

                    pTextObject->SetMergedItemSet(aAttr);
@@ -2279,7 +2279,7 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, 
                if ( pTextObject->IsAutoGrowWidth() )
                {
                    // switch off AutoGrowWidth , set new MinWidth
                    SfxItemSet aTempAttr( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool() );
                    SfxItemSet aTempAttr( static_cast<SdDrawDocument*>(pModel)->GetPool() );
                    SdrMetricItem aMinWidth( makeSdrTextMinFrameWidthItem(rRect.GetSize().Width()) );
                    aTempAttr.Put( aMinWidth );
                    aTempAttr.Put( makeSdrTextAutoGrowWidthItem(false) );
@@ -2287,7 +2287,7 @@ SdrObject* SdPage::InsertAutoLayoutShape(SdrObject* pObj, PresObjKind eObjKind, 
                    pTextObject->SetLogicRect(rRect);

                    // switch on AutoGrowWidth
                    SfxItemSet aAttr( static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetPool() );
                    SfxItemSet aAttr( static_cast<SdDrawDocument*>(pModel)->GetPool() );
                    aAttr.Put( makeSdrTextAutoGrowWidthItem(true) );
                    pTextObject->SetMergedItemSet(aAttr);
                }
@@ -2389,11 +2389,11 @@ void SdPage::SetObjText(SdrTextObj* pObj, SdrOutliner* pOutliner, PresObjKind eO

        if (!pOutliner)
        {
            SfxItemPool* pPool(static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetDrawOutliner().GetEmptyItemSet().GetPool());
            SfxItemPool* pPool = static_cast<SdDrawDocument*>(GetModel())->GetDrawOutliner().GetEmptyItemSet().GetPool();
            pOutl = new ::Outliner( pPool, OutlinerMode::OutlineObject );
            pOutl->SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
            pOutl->SetEditTextObjectPool(pPool);
            pOutl->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(getSdrModelFromSdrPage().GetStyleSheetPool()));
            pOutl->SetStyleSheetPool(static_cast<SfxStyleSheetPool*>(GetModel()->GetStyleSheetPool()));
            pOutl->EnableUndo(false);
            pOutl->SetUpdateMode( false );
        }
@@ -2549,7 +2549,7 @@ const OUString& SdPage::GetName() const

            aCreatedPageName = SdResId(STR_PAGE);
            aCreatedPageName += " ";
            if( getSdrModelFromSdrPage().GetPageNumType() == css::style::NumberingType::NUMBER_NONE )
            if( GetModel()->GetPageNumType() == css::style::NumberingType::NUMBER_NONE )
            {
                // if the document has number none as a formatting
                // for page numbers we still default to arabic numbering
@@ -2558,7 +2558,7 @@ const OUString& SdPage::GetName() const
            }
            else
            {
                aCreatedPageName += static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).CreatePageNumValue(nNum);
                aCreatedPageName += static_cast<SdDrawDocument*>(GetModel())->CreatePageNumValue(nNum);
            }
        }
        else
@@ -2721,7 +2721,7 @@ void SdPage::SetName (const OUString& rName)
{
    OUString aOldName( GetName() );
    FmFormPage::SetName (rName);
    static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).UpdatePageRelativeURLs(aOldName, rName);
    static_cast<SdDrawDocument*>(pModel)->UpdatePageRelativeURLs(aOldName, rName);
    ActionChanged();
}

diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index 3b6e42f..61fd29d 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -95,13 +95,13 @@ void SdPage::SetPresentationLayout(const OUString& rLayoutName,
        SdPage* pMaster;
        SdPage* pFoundMaster = nullptr;
        sal_uInt16 nMaster = 0;
        sal_uInt16 nMasterCount = getSdrModelFromSdrPage().GetMasterPageCount();
        sal_uInt16 nMasterCount = pModel->GetMasterPageCount();

        if( !bReverseOrder )
        {
            for ( nMaster = 0; nMaster < nMasterCount; nMaster++ )
            {
                pMaster = static_cast<SdPage*>(getSdrModelFromSdrPage().GetMasterPage(nMaster));
                pMaster = static_cast<SdPage*>(pModel->GetMasterPage(nMaster));
                if (pMaster->GetPageKind() == mePageKind && pMaster->GetLayoutName() == maLayoutName)
                {
                    pFoundMaster = pMaster;
@@ -113,7 +113,7 @@ void SdPage::SetPresentationLayout(const OUString& rLayoutName,
        {
            for ( nMaster = nMasterCount; nMaster > 0; nMaster-- )
            {
                pMaster = static_cast<SdPage*>(getSdrModelFromSdrPage().GetMasterPage(nMaster - 1));
                pMaster = static_cast<SdPage*>(pModel->GetMasterPage(nMaster - 1));
                if (pMaster->GetPageKind() == mePageKind && pMaster->GetLayoutName() == maLayoutName)
                {
                    pFoundMaster = pMaster;
@@ -126,7 +126,7 @@ void SdPage::SetPresentationLayout(const OUString& rLayoutName,

        // this should never happen, but we play failsafe here
        if( pFoundMaster == nullptr )
            pFoundMaster = static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetSdPage( 0, mePageKind );
            pFoundMaster = static_cast< SdDrawDocument *>(pModel)->GetSdPage( 0, mePageKind );

        if( pFoundMaster )
            TRG_SetMasterPage(*pFoundMaster);
@@ -157,7 +157,7 @@ void SdPage::SetPresentationLayout(const OUString& rLayoutName,
                OUString aFullName;
                OUString aOldFullName;
                SfxStyleSheetBase* pSheet = nullptr;
                SfxStyleSheetBasePool* pStShPool = getSdrModelFromSdrPage().GetStyleSheetPool();
                SfxStyleSheetBasePool* pStShPool = pModel->GetStyleSheetPool();

                for (sal_Int16 i = -1; i < 9; i++)
                {
@@ -261,7 +261,7 @@ void SdPage::EndListenOutlineText()

    if (pOutlineTextObj)
    {
        SdStyleSheetPool* pSPool = static_cast<SdStyleSheetPool*>(getSdrModelFromSdrPage().GetStyleSheetPool());
        SdStyleSheetPool* pSPool = static_cast<SdStyleSheetPool*>(pModel->GetStyleSheetPool());
        DBG_ASSERT(pSPool, "StyleSheetPool missing");
        OUString aTrueLayoutName(maLayoutName);
        sal_Int32 nIndex = aTrueLayoutName.indexOf( SD_LT_SEPARATOR );
@@ -282,6 +282,22 @@ void SdPage::EndListenOutlineText()

/*************************************************************************
|*
|* Set new model
|*
\************************************************************************/

void SdPage::SetModel(SdrModel* pNewModel)
{
    DisconnectLink();

    // assign model
    FmFormPage::SetModel(pNewModel);

    ConnectLink();
}

/*************************************************************************
|*
|* Is this page read-only?
|*
\************************************************************************/
@@ -299,17 +315,17 @@ bool SdPage::IsReadOnly() const

void SdPage::ConnectLink()
{
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrPage().GetLinkManager());
    sfx2::LinkManager* pLinkManager = pModel!=nullptr ? pModel->GetLinkManager() : nullptr;

    if (pLinkManager && !mpPageLink && !maFileName.isEmpty() && !maBookmarkName.isEmpty() &&
        mePageKind==PageKind::Standard && !IsMasterPage() &&
        static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).IsNewOrLoadCompleted())
        static_cast<SdDrawDocument*>(pModel)->IsNewOrLoadCompleted())
    {
        /**********************************************************************
        * Connect
        * Only standard pages are allowed to be linked
        **********************************************************************/
        ::sd::DrawDocShell* pDocSh = static_cast< SdDrawDocument& >(getSdrModelFromSdrPage()).GetDocSh();
        ::sd::DrawDocShell* pDocSh = static_cast<SdDrawDocument*>(pModel)->GetDocSh();

        if (!pDocSh || pDocSh->GetMedium()->GetOrigURL() != maFileName)
        {
@@ -331,7 +347,7 @@ void SdPage::ConnectLink()

void SdPage::DisconnectLink()
{
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrPage().GetLinkManager());
    sfx2::LinkManager* pLinkManager = pModel!=nullptr ? pModel->GetLinkManager() : nullptr;

    if (pLinkManager && mpPageLink)
    {
@@ -344,41 +360,57 @@ void SdPage::DisconnectLink()
    }
}

void SdPage::lateInit(const SdPage& rSrcPage)
{
    // call parent
    FmFormPage::lateInit(rSrcPage);
/*************************************************************************
|*
|* Copy-Ctor
|*
\************************************************************************/

    // copy local variables (former stuff from copy constructor)
    mePageKind = rSrcPage.mePageKind;
    meAutoLayout = rSrcPage.meAutoLayout;
    mbSelected = false;
    mnTransitionType = rSrcPage.mnTransitionType;
SdPage::SdPage(const SdPage& rSrcPage)
:   FmFormPage(rSrcPage)
,   SdrObjUserCall()
,   mpItems(nullptr)
,   mnPageId(mnLastPageId++)
{
    mePageKind           = rSrcPage.mePageKind;
    meAutoLayout         = rSrcPage.meAutoLayout;

    mbSelected           = false;
    mnTransitionType    = rSrcPage.mnTransitionType;
    mnTransitionSubtype = rSrcPage.mnTransitionSubtype;
    mbTransitionDirection = rSrcPage.mbTransitionDirection;
    mnTransitionFadeColor = rSrcPage.mnTransitionFadeColor;
    mfTransitionDuration = rSrcPage.mfTransitionDuration;
    mePresChange = rSrcPage.mePresChange;
    mfTime = rSrcPage.mfTime;
    mbSoundOn = rSrcPage.mbSoundOn;
    mbExcluded = rSrcPage.mbExcluded;
    maLayoutName = rSrcPage.maLayoutName;
    maSoundFile = rSrcPage.maSoundFile;
    mbLoopSound = rSrcPage.mbLoopSound;
    mbStopSound = rSrcPage.mbStopSound;
    mePresChange            = rSrcPage.mePresChange;
    mfTime               = rSrcPage.mfTime;
    mbSoundOn            = rSrcPage.mbSoundOn;
    mbExcluded           = rSrcPage.mbExcluded;

    maLayoutName         = rSrcPage.maLayoutName;
    maSoundFile          = rSrcPage.maSoundFile;
    mbLoopSound          = rSrcPage.mbLoopSound;
    mbStopSound          = rSrcPage.mbStopSound;
    maCreatedPageName.clear();
    maFileName = rSrcPage.maFileName;
    maBookmarkName = rSrcPage.maBookmarkName;
    mbScaleObjects = rSrcPage.mbScaleObjects;
    maFileName           = rSrcPage.maFileName;
    maBookmarkName       = rSrcPage.maBookmarkName;
    mbScaleObjects       = rSrcPage.mbScaleObjects;
    mbBackgroundFullSize = rSrcPage.mbBackgroundFullSize;
    meCharSet = rSrcPage.meCharSet;
    mnPaperBin = rSrcPage.mnPaperBin;
    mpPageLink = nullptr;    // is set when inserting via ConnectLink()
    mbIsPrecious = false;
    meCharSet            = rSrcPage.meCharSet;
    mnPaperBin           = rSrcPage.mnPaperBin;

    mpPageLink           = nullptr;    // is set when inserting via ConnectLink()

    mbIsPrecious         = false;
}

void SdPage::lateInit(const SdPage& rSrcPage)
{
    FmFormPage::lateInit(rSrcPage);

    // use shape list directly to preserve constness of rSrcPage
    const std::list< SdrObject* >& rShapeList = rSrcPage.maPresentationShapeList.getList();
    for( std::list< SdrObject* >::const_iterator aIter = rShapeList.begin(); aIter != rShapeList.end(); ++aIter )
    for( std::list< SdrObject* >::const_iterator aIter = rShapeList.begin();
         aIter != rShapeList.end(); ++aIter )
    {
        SdrObject* pObj = *aIter;
        InsertPresObj(GetObj(pObj->GetOrdNum()), rSrcPage.GetPresObjKind(pObj));
@@ -386,22 +418,6 @@ void SdPage::lateInit(const SdPage& rSrcPage)

    // header footer
    setHeaderFooterSettings( rSrcPage.getHeaderFooterSettings() );

    // animations
    rSrcPage.cloneAnimations(*this);

    // fix user calls for duplicated slide
    SdrObjListIter aSourceIter( rSrcPage, SdrIterMode::DeepWithGroups );
    SdrObjListIter aTargetIter( *this, SdrIterMode::DeepWithGroups );

    while( aSourceIter.IsMore() && aTargetIter.IsMore() )
    {
        SdrObject* pSource = aSourceIter.Next();
        SdrObject* pTarget = aTargetIter.Next();

        if( pSource->GetUserCall() )
            pTarget->SetUserCall(this);
    }
}

/*************************************************************************
@@ -410,15 +426,34 @@ void SdPage::lateInit(const SdPage& rSrcPage)
|*
\************************************************************************/

SdrPage* SdPage::Clone() const
{
    return Clone(nullptr);
}

SdrPage* SdPage::Clone(SdrModel* pNewModel) const
{
    SdDrawDocument& rSdDrawDocument(static_cast< SdDrawDocument& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    SdPage* pClonedSdPage(
        new SdPage(
            rSdDrawDocument,
            IsMasterPage()));
    pClonedSdPage->lateInit(*this);
    return pClonedSdPage;
    DBG_ASSERT( pNewModel == nullptr, "sd::SdPage::Clone(), new page ignored, please check code! CL" );

    SdPage* pNewPage = new SdPage(*this);
    pNewPage->lateInit( *this );

    cloneAnimations( *pNewPage );

    // fix user calls for duplicated slide
    SdrObjListIter aSourceIter( *this, SdrIterMode::DeepWithGroups );
    SdrObjListIter aTargetIter( *pNewPage, SdrIterMode::DeepWithGroups );

    while( aSourceIter.IsMore() && aTargetIter.IsMore() )
    {
        SdrObject* pSource = aSourceIter.Next();
        SdrObject* pTarget = aTargetIter.Next();

        if( pSource->GetUserCall() )
            pTarget->SetUserCall( pNewPage );
    }

    return pNewPage;
}

/*************************************************************************
@@ -441,7 +476,7 @@ SfxStyleSheet* SdPage::GetTextStyleSheetForObject( SdrObject* pObj ) const
SfxItemSet* SdPage::getOrCreateItems()
{
    if( mpItems == nullptr )
        mpItems = o3tl::make_unique<SfxItemSet>( getSdrModelFromSdrPage().GetItemPool(), svl::Items<SDRATTR_XMLATTRIBUTES, SDRATTR_XMLATTRIBUTES>{} );
        mpItems = o3tl::make_unique<SfxItemSet>( pModel->GetItemPool(), svl::Items<SDRATTR_XMLATTRIBUTES, SDRATTR_XMLATTRIBUTES>{} );

    return mpItems.get();
}
@@ -569,37 +604,40 @@ void SdPage::addAnnotation( const Reference< XAnnotation >& xAnnotation, int nIn
        maAnnotations.insert( maAnnotations.begin() + nIndex, xAnnotation );
    }

    if( getSdrModelFromSdrPage().IsUndoEnabled() )
    if( pModel && pModel->IsUndoEnabled() )
    {
        SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, true );
        if( pAction )
            getSdrModelFromSdrPage().AddUndo( pAction );
            pModel->AddUndo( pAction );
    }

    SetChanged();
    getSdrModelFromSdrPage().SetChanged();
    // TTTT NotifyDocumentEvent should be reference
    NotifyDocumentEvent(
        static_cast< SdDrawDocument* >(&getSdrModelFromSdrPage()),
        "OnAnnotationInserted",
        Reference<XInterface>(xAnnotation, UNO_QUERY));

    if( pModel )
    {
        pModel->SetChanged();
        NotifyDocumentEvent( static_cast< SdDrawDocument* >( pModel ), "OnAnnotationInserted", Reference<XInterface>( xAnnotation, UNO_QUERY ) );
    }
}

void SdPage::removeAnnotation( const Reference< XAnnotation >& xAnnotation )
{
    if( getSdrModelFromSdrPage().IsUndoEnabled() )
    if( pModel && pModel->IsUndoEnabled() )
    {
        SdrUndoAction* pAction = CreateUndoInsertOrRemoveAnnotation( xAnnotation, false );
        if( pAction )
            getSdrModelFromSdrPage().AddUndo( pAction );
            pModel->AddUndo( pAction );
    }

    AnnotationVector::iterator iter = std::find( maAnnotations.begin(), maAnnotations.end(), xAnnotation );
    if( iter != maAnnotations.end() )
        maAnnotations.erase( iter );

    getSdrModelFromSdrPage().SetChanged();
    NotifyDocumentEvent( static_cast< SdDrawDocument* >( &getSdrModelFromSdrPage() ), "OnAnnotationRemoved", Reference<XInterface>( xAnnotation, UNO_QUERY ) );
    if( pModel )
    {
        pModel->SetChanged();
        NotifyDocumentEvent( static_cast< SdDrawDocument* >( pModel ), "OnAnnotationRemoved", Reference<XInterface>( xAnnotation, UNO_QUERY ) );
    }
}

void SdPage::dumpAsXml(xmlTextWriterPtr pWriter) const
diff --git a/sd/source/core/undo/undoobjects.cxx b/sd/source/core/undo/undoobjects.cxx
index d8db132..6b3a4e8 100644
--- a/sd/source/core/undo/undoobjects.cxx
+++ b/sd/source/core/undo/undoobjects.cxx
@@ -58,10 +58,7 @@ UndoRemovePresObjectImpl::UndoRemovePresObjectImpl( SdrObject& rObject )
            css::uno::Reference< css::drawing::XShape > xShape( rObject.getUnoShape(), css::uno::UNO_QUERY );
            if( pPage->getMainSequence()->hasEffect( xShape ) )
            {
                mpUndoAnimation.reset(
                    new UndoAnimation( // TTTT may use ref? Or just *SdrPage?
                        static_cast< SdDrawDocument* >(&pPage->getSdrModelFromSdrPage()),
                        pPage));
                mpUndoAnimation.reset( new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage ) );
            }
        }
    }
@@ -183,10 +180,7 @@ UndoObjectSetText::UndoObjectSetText( SdrObject& rObject, sal_Int32 nText )
        css::uno::Reference< css::drawing::XShape > xShape( rObject.getUnoShape(), css::uno::UNO_QUERY );
        if( pPage->getMainSequence()->hasEffect( xShape ) )
        {
            mpUndoAnimation.reset(
                new UndoAnimation(
                    static_cast< SdDrawDocument* >(&pPage->getSdrModelFromSdrPage()),
                    pPage));
            mpUndoAnimation.reset( new UndoAnimation( static_cast< SdDrawDocument* >( pPage->GetModel() ), pPage ) );
        }
    }
}
diff --git a/sd/source/filter/grf/sdgrffilter.cxx b/sd/source/filter/grf/sdgrffilter.cxx
index 985d625..522f2ba 100644
--- a/sd/source/filter/grf/sdgrffilter.cxx
+++ b/sd/source/filter/grf/sdgrffilter.cxx
@@ -163,66 +163,62 @@ bool SdGRFFilter::Import()
    const sal_uInt16 nFilter = rGraphicFilter.GetImportFormatNumberForTypeName( mrMedium.GetFilter()->GetTypeName() );
    bool        bRet = false;

    SvStream*       pIStm = mrMedium.GetInStream();
    ErrCode         nReturn = pIStm ? rGraphicFilter.ImportGraphic( aGraphic, aFileName, *pIStm, nFilter ) : ErrCode(1);
        SvStream*       pIStm = mrMedium.GetInStream();
        ErrCode         nReturn = pIStm ? rGraphicFilter.ImportGraphic( aGraphic, aFileName, *pIStm, nFilter ) : ErrCode(1);

    if( nReturn )
        HandleGraphicFilterError( nReturn, rGraphicFilter.GetLastError().nStreamError );
    else
    {
        if( mrDocument.GetPageCount() == 0 )
            mrDocument.CreateFirstPages();

        SdPage*     pPage = mrDocument.GetSdPage( 0, PageKind::Standard );
        Point       aPos;
        Size        aPagSize( pPage->GetSize() );
        Size        aGrfSize( OutputDevice::LogicToLogic( aGraphic.GetPrefSize(),
                                aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)));

        aPagSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) );
        aPagSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) );

        // scale to fit page
        if ( ( ( aGrfSize.Height() > aPagSize.Height() ) || ( aGrfSize.Width() > aPagSize.Width() ) ) &&
                aGrfSize.Height() && aPagSize.Height() )
        if( nReturn )
            HandleGraphicFilterError( nReturn, rGraphicFilter.GetLastError().nStreamError );
        else
        {
            double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height();
            double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height();
            if( mrDocument.GetPageCount() == 0 )
                mrDocument.CreateFirstPages();

            // adjust graphic to page size (scales)
            if( fGrfWH < fWinWH )
            SdPage*     pPage = mrDocument.GetSdPage( 0, PageKind::Standard );
            Point       aPos;
            Size        aPagSize( pPage->GetSize() );
            Size        aGrfSize( OutputDevice::LogicToLogic( aGraphic.GetPrefSize(),
                                  aGraphic.GetPrefMapMode(), MapMode(MapUnit::Map100thMM)));

            aPagSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) );
            aPagSize.AdjustHeight( -(pPage->GetUpperBorder() + pPage->GetLowerBorder()) );

            // scale to fit page
            if ( ( ( aGrfSize.Height() > aPagSize.Height() ) || ( aGrfSize.Width() > aPagSize.Width() ) ) &&
                 aGrfSize.Height() && aPagSize.Height() )
            {
                aGrfSize.setWidth( static_cast<long>( aPagSize.Height() * fGrfWH ) );
                aGrfSize.setHeight( aPagSize.Height() );
                double fGrfWH = static_cast<double>(aGrfSize.Width()) / aGrfSize.Height();
                double fWinWH = static_cast<double>(aPagSize.Width()) / aPagSize.Height();

                // adjust graphic to page size (scales)
                if( fGrfWH < fWinWH )
                {
                    aGrfSize.setWidth( static_cast<long>( aPagSize.Height() * fGrfWH ) );
                    aGrfSize.setHeight( aPagSize.Height() );
                }
                else if( fGrfWH > 0.F )
                {
                    aGrfSize.setWidth( aPagSize.Width() );
                    aGrfSize.setHeight( static_cast<long>( aPagSize.Width() / fGrfWH ) );
                }
            }
            else if( fGrfWH > 0.F )
            {
                aGrfSize.setWidth( aPagSize.Width() );
                aGrfSize.setHeight( static_cast<long>( aPagSize.Width() / fGrfWH ) );
            }

            // set output rectangle for graphic
            aPos.setX( ( ( aPagSize.Width() - aGrfSize.Width() ) >> 1 ) + pPage->GetLeftBorder() );
            aPos.setY( ( ( aPagSize.Height() - aGrfSize.Height() ) >> 1 )  + pPage->GetUpperBorder() );

            pPage->InsertObject( new SdrGrafObj( aGraphic, ::tools::Rectangle( aPos, aGrfSize ) ) );
            bRet = true;
        }

        // set output rectangle for graphic
        aPos.setX( ( ( aPagSize.Width() - aGrfSize.Width() ) >> 1 ) + pPage->GetLeftBorder() );
        aPos.setY( ( ( aPagSize.Height() - aGrfSize.Height() ) >> 1 )  + pPage->GetUpperBorder() );

        pPage->InsertObject(
            new SdrGrafObj(
                pPage->getSdrModelFromSdrPage(),
                aGraphic,
                ::tools::Rectangle(aPos, aGrfSize)));
        bRet = true;
    }

    return bRet;
}

bool SdGRFFilter::Export()
{
    // SJ: todo: error handling, the GraphicExportFilter does not support proper errorhandling

    bool bRet = false;

    uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
    uno::Reference< drawing::XGraphicExportFilter > xExporter = drawing::GraphicExportFilter::create( xContext );

    SdPage* pPage = nullptr;
diff --git a/sd/source/filter/ppt/pptin.cxx b/sd/source/filter/ppt/pptin.cxx
index 056b2924..d93fa3d 100644
--- a/sd/source/filter/ppt/pptin.cxx
+++ b/sd/source/filter/ppt/pptin.cxx
@@ -2688,9 +2688,8 @@ SdrObject* ImplSdPPTImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, voi
                                            aMediaURL = ReadSound( nRef );
                                        if ( !aMediaURL.isEmpty() )
                                        {
                                            SdrMediaObj* pMediaObj = new SdrMediaObj(
                                                pObj->getSdrModelFromSdrObject(),
                                                pObj->GetSnapRect());
                                            SdrMediaObj* pMediaObj = new SdrMediaObj( pObj->GetSnapRect() );
                                            pMediaObj->SetModel( pObj->GetModel() );
                                            pMediaObj->SetMergedItemSet( pObj->GetMergedItemSet() );

                                            //--remove object from maAnimations list and add the new object instead
diff --git a/sd/source/ui/animations/motionpathtag.cxx b/sd/source/ui/animations/motionpathtag.cxx
index c54d991..373f251 100644
--- a/sd/source/ui/animations/motionpathtag.cxx
+++ b/sd/source/ui/animations/motionpathtag.cxx
@@ -316,7 +316,7 @@ MotionPathTag::MotionPathTag( CustomAnimationPane& rPane, ::sd::View& rView, con
, msLastPath( pEffect->getPath() )
, mbInUpdatePath( false )
{
    mpPathObj = mpEffect->createSdrPathObjFromPath(rView.getSdrModelFromSdrView());
    mpPathObj = mpEffect->createSdrPathObjFromPath();
    mxPolyPoly = mpPathObj->GetPathPoly();
    if (mxOrigin.is())
        maOriginPos = mxOrigin->getPosition();
diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx
index 37a8622..e9d185c 100644
--- a/sd/source/ui/app/sdmod2.cxx
+++ b/sd/source/ui/app/sdmod2.cxx
@@ -160,7 +160,7 @@ IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void)
        const SdrTextObj* pTextObj = pSdrOutliner->GetTextObj();

        if( pTextObj )
            pDoc = dynamic_cast< SdDrawDocument* >( &pTextObj->getSdrModelFromSdrObject() );
            pDoc = dynamic_cast< SdDrawDocument* >( pTextObj->GetModel() );

        if( pDoc )
            pDocShell = pDoc->GetDocSh();
diff --git a/sd/source/ui/dlg/animobjs.cxx b/sd/source/ui/dlg/animobjs.cxx
index 5ca6bab..a9b324d 100644
--- a/sd/source/ui/dlg/animobjs.cxx
+++ b/sd/source/ui/dlg/animobjs.cxx
@@ -777,8 +777,12 @@ void AnimationWindow::AddObj (::sd::View& rView )

                for( size_t nObject = 0; nObject < pObjList->GetObjCount(); ++nObject )
                {
                    SdrObject* pSnapShot(pObjList->GetObj(nObject));
                    BitmapEx *const pBitmapEx = new BitmapEx(SdrExchangeView::GetObjGraphic(*pSnapShot).GetBitmapEx());
                    SdrObject* pSnapShot = pObjList->GetObj( nObject );

                    BitmapEx *const pBitmapEx = new BitmapEx(
                        SdrExchangeView::GetObjGraphic(
                            pSnapShot->GetModel(), pSnapShot).GetBitmapEx() );

                    ::tools::Time* pTime = new ::tools::Time( m_pTimeField->GetTime() );
                    size_t nIndex = m_nCurrentFrame + 1;
                    m_FrameList.insert(
@@ -826,9 +830,14 @@ void AnimationWindow::AddObj (::sd::View& rView )
                for( size_t nObject= 0; nObject < nMarkCount; ++nObject )
                {
                    // Clone
                    SdrObject* pObject(rMarkList.GetMark(nObject)->GetMarkedSdrObj());
                    BitmapEx *const pBitmapEx = new BitmapEx(SdrExchangeView::GetObjGraphic(*pObject).GetBitmapEx());
                    SdrObject* pObject = rMarkList.GetMark( nObject )->GetMarkedSdrObj();

                    BitmapEx *const pBitmapEx = new BitmapEx(
                        SdrExchangeView::GetObjGraphic(
                            pObject->GetModel(), pObject).GetBitmapEx() );

                    ::tools::Time* pTime = new ::tools::Time( m_pTimeField->GetTime() );

                    size_t nIndex = m_nCurrentFrame + 1;
                    m_FrameList.insert(
                        m_FrameList.begin() + nIndex,
@@ -843,7 +852,7 @@ void AnimationWindow::AddObj (::sd::View& rView )
            }
            else
            {
                SdrObjGroup* pCloneGroup = new SdrObjGroup(rView.getSdrModelFromSdrView());
                SdrObjGroup* pCloneGroup = new SdrObjGroup;
                SdrObjList*  pObjList    = pCloneGroup->GetSubList();

                for (size_t nObject= 0; nObject < nMarkCount; ++nObject)
@@ -991,9 +1000,7 @@ void AnimationWindow::CreateAnimObj (::sd::View& rView )
            aAnimation.SetLoopCount( nLoopCount );
        }

        SdrGrafObj* pGrafObj = new SdrGrafObj(
            rView.getSdrModelFromSdrView(),
            Graphic(aAnimation));
        SdrGrafObj* pGrafObj = new SdrGrafObj( Graphic( aAnimation ) );
        const Point aOrg( aWindowCenter.X() - ( aMaxSizeLog.Width() >> 1 ), aWindowCenter.Y() - ( aMaxSizeLog.Height() >> 1 ) );

        pGrafObj->SetLogicRect( ::tools::Rectangle( aOrg, aMaxSizeLog ) );
@@ -1066,7 +1073,7 @@ void AnimationWindow::CreateAnimObj (::sd::View& rView )
        if(pTargetSdPage)
        {
            // create animation group
            SdrObjGroup* pGroup   = new SdrObjGroup(rView.getSdrModelFromSdrView());
            SdrObjGroup* pGroup   = new SdrObjGroup;
            SdrObjList*  pObjList = pGroup->GetSubList();

            for (size_t i = 0; i < nCount; ++i)
diff --git a/sd/source/ui/func/fucon3d.cxx b/sd/source/ui/func/fucon3d.cxx
index f74db13..5fe0977 100644
--- a/sd/source/ui/func/fucon3d.cxx
+++ b/sd/source/ui/func/fucon3d.cxx
@@ -89,7 +89,6 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
        case SID_3D_CUBE:
        {
            p3DObj = new E3dCubeObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B3DPoint(-2500, -2500, -2500),
                ::basegfx::B3DVector(5000, 5000, 5000));
@@ -99,7 +98,6 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
        case SID_3D_SPHERE:
        {
            p3DObj = new E3dSphereObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B3DPoint(0, 0, 0),
                ::basegfx::B3DVector(5000, 5000, 5000));
@@ -116,10 +114,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
            {
                aB2DPolygon = ::basegfx::utils::adaptiveSubdivideByAngle(aB2DPolygon);
            }
            p3DObj = new E3dLatheObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B2DPolyPolygon(aB2DPolygon));
            p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aB2DPolygon));

            /* this is an open object, therefore it has to be handled double-
               sided by default */
@@ -146,10 +141,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
            {
                aB2DPolygon = ::basegfx::utils::adaptiveSubdivideByAngle(aB2DPolygon);
            }
            p3DObj = new E3dLatheObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B2DPolyPolygon(aB2DPolygon));
            p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aB2DPolygon));
            break;
        }

@@ -160,10 +152,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
            {
                aB2DPolygon = ::basegfx::utils::adaptiveSubdivideByAngle(aB2DPolygon);
            }
            p3DObj = new E3dLatheObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B2DPolyPolygon(aB2DPolygon));
            p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aB2DPolygon));
            break;
        }

@@ -189,10 +178,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
            aInnerPoly.append(::basegfx::B2DPoint(0,    -1000*5));
            aInnerPoly.setClosed(true);

            p3DObj = new E3dLatheObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B2DPolyPolygon(aInnerPoly));
            p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aInnerPoly));
            break;
        }

@@ -216,10 +202,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
            aInnerPoly.append(::basegfx::B2DPoint(0,    1000*5));
            aInnerPoly.setClosed(true);

            p3DObj = new E3dLatheObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B2DPolyPolygon(aInnerPoly));
            p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aInnerPoly));
            break;
        }

@@ -243,10 +226,7 @@ E3dCompoundObject* FuConstruct3dObject::ImpCreateBasic3DShape()
            aInnerPoly.append(::basegfx::B2DPoint(0, 1000*5));
            aInnerPoly.setClosed(true);

            p3DObj = new E3dLatheObj(
                mpView->getSdrModelFromSdrView(),
                mpView->Get3DDefaultAttributes(),
                ::basegfx::B2DPolyPolygon(aInnerPoly));
            p3DObj = new E3dLatheObj(mpView->Get3DDefaultAttributes(), ::basegfx::B2DPolyPolygon(aInnerPoly));
            p3DObj->SetMergedItem(makeSvx3DHorizontalSegmentsItem(4));
            break;
        }
@@ -393,7 +373,7 @@ SdrObject* FuConstruct3dObject::CreateDefaultObject(const sal_uInt16 nID, const 
    double fW(aVolume.getWidth());
    double fH(aVolume.getHeight());
    ::tools::Rectangle a3DRect(0, 0, static_cast<long>(fW), static_cast<long>(fH));
    E3dScene* pScene = new E3dScene(*mpDoc);
    E3dScene* pScene = new E3dScene;

    // copied code from E3dView::InitScene
    double fCamZ(aVolume.getMaxZ() + ((fW + fH) / 4.0));
@@ -407,9 +387,13 @@ SdrObject* FuConstruct3dObject::CreateDefaultObject(const sal_uInt16 nID, const 
    aCam.SetFocalLength(mpView->GetDefaultCamFocal());
    aCam.SetDefaults(::basegfx::B3DPoint(0.0, 0.0, fDefaultCamPosZ), aLookAt);
    pScene->SetCamera(aCam);

    pScene->Insert3DObj(p3DObj);
    pScene->NbcSetSnapRect(a3DRect);
    pScene->SetModel(mpDoc);

    ImpPrepareBasic3DShape(p3DObj, pScene);

    SfxItemSet aAttr(mpDoc->GetPool());
    SetStyleSheet(aAttr, p3DObj);
    aAttr.Put(XLineStyleItem (drawing::LineStyle_NONE));
diff --git a/sd/source/ui/func/fuconarc.cxx b/sd/source/ui/func/fuconarc.cxx
index 6967a14..7d6aca6 100644
--- a/sd/source/ui/func/fuconarc.cxx
+++ b/sd/source/ui/func/fuconarc.cxx
@@ -91,12 +91,10 @@ void FuConstructArc::DoExecute( SfxRequest& rReq )

        Activate();  // sets aObjKind
        SdrCircObj* pNewCircle =
        new SdrCircObj(
            mpView->getSdrModelFromSdrView(),
            static_cast<SdrObjKind>(mpView->GetCurrentObjIdentifier()),
            aNewRectangle,
            static_cast<long>(pPhiStart->GetValue () * 10.0),
            static_cast<long>(pPhiEnd->GetValue () * 10.0));
        new SdrCircObj(static_cast<SdrObjKind>(mpView->GetCurrentObjIdentifier()),
                       aNewRectangle,
                       static_cast<long>(pPhiStart->GetValue () * 10.0),
                       static_cast<long>(pPhiEnd->GetValue () * 10.0));
        SdrPageView *pPV = mpView->GetSdrPageView();

        mpView->InsertObjectAtView(pNewCircle, *pPV, SdrInsertFlags::SETDEFLAYER);
@@ -204,9 +202,8 @@ SdrObject* FuConstructArc::CreateDefaultObject(const sal_uInt16 nID, const ::too
{

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        mpView->getSdrModelFromSdrView(),
        mpView->GetCurrentObjInventor(),
        mpView->GetCurrentObjIdentifier());
        mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
        nullptr, mpDoc);

    if(pObj)
    {
diff --git a/sd/source/ui/func/fuconbez.cxx b/sd/source/ui/func/fuconbez.cxx
index cad7080..e7cc868 100644
--- a/sd/source/ui/func/fuconbez.cxx
+++ b/sd/source/ui/func/fuconbez.cxx
@@ -309,9 +309,8 @@ SdrObject* FuConstructBezierPolygon::CreateDefaultObject(const sal_uInt16 nID, c
    // case SID_DRAW_BEZIER_NOFILL:        // BASIC

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        mpView->getSdrModelFromSdrView(),
        mpView->GetCurrentObjInventor(),
        mpView->GetCurrentObjIdentifier());
        mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
        nullptr, mpDoc);

    if(pObj)
    {
diff --git a/sd/source/ui/func/fuconcs.cxx b/sd/source/ui/func/fuconcs.cxx
index 97a60a3..6396eeb 100644
--- a/sd/source/ui/func/fuconcs.cxx
+++ b/sd/source/ui/func/fuconcs.cxx
@@ -188,7 +188,7 @@ void FuConstructCustomShape::SetAttributes( SdrObject* pObj )
                            {
                                const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                                SfxItemSet aDest(
                                    pObj->getSdrModelFromSdrObject().GetItemPool(),
                                    pObj->GetModel()->GetItemPool(),
                                    svl::Items<
                                        // Ranges from SdrAttrObj:
                                        SDRATTR_START, SDRATTR_SHADOW_LAST,
@@ -236,9 +236,8 @@ const OUString& FuConstructCustomShape::GetShapeType() const
SdrObject* FuConstructCustomShape::CreateDefaultObject(const sal_uInt16, const ::tools::Rectangle& rRectangle)
{
    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        mpView->getSdrModelFromSdrView(),
        mpView->GetCurrentObjInventor(),
        mpView->GetCurrentObjIdentifier());
        mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
        nullptr, mpDoc);

    if( pObj )
    {
diff --git a/sd/source/ui/func/fuconrec.cxx b/sd/source/ui/func/fuconrec.cxx
index d78fd86..1377429 100644
--- a/sd/source/ui/func/fuconrec.cxx
+++ b/sd/source/ui/func/fuconrec.cxx
@@ -109,10 +109,7 @@ void FuConstructRectangle::DoExecute( SfxRequest& rReq )
                                           pCenterY->GetValue () - pAxisY->GetValue () / 2,
                                           pCenterX->GetValue () + pAxisX->GetValue () / 2,
                                           pCenterY->GetValue () + pAxisY->GetValue () / 2);
                SdrCircObj  *pNewCircle = new SdrCircObj(
                    mpView->getSdrModelFromSdrView(),
                    OBJ_CIRC,
                    aNewRectangle);
                SdrCircObj  *pNewCircle = new SdrCircObj (OBJ_CIRC, aNewRectangle);
                SdrPageView *pPV = mpView->GetSdrPageView();

                mpView->InsertObjectAtView(pNewCircle, *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
@@ -130,9 +127,7 @@ void FuConstructRectangle::DoExecute( SfxRequest& rReq )
                                           pMouseStartY->GetValue (),
                                           pMouseEndX->GetValue (),
                                           pMouseEndY->GetValue ());
                SdrRectObj  *pNewRect = new SdrRectObj(
                    mpView->getSdrModelFromSdrView(),
                    aNewRectangle);
                SdrRectObj  *pNewRect = new SdrRectObj (aNewRectangle);
                SdrPageView *pPV = mpView->GetSdrPageView();

                mpView->InsertObjectAtView(pNewRect, *pPV, SdrInsertFlags::SETDEFLAYER | SdrInsertFlags::SETDEFATTR);
@@ -482,9 +477,9 @@ void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
        // dimension line
        SdPage* pPage = static_cast<SdPage*>( mpView->GetSdrPageView()->GetPage() );
        OUString aName(SdResId(STR_POOLSHEET_MEASURE));
        SfxStyleSheet* pSheet(
            static_cast< SfxStyleSheet* >(
                pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
        SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>( pPage->GetModel()->
                                     GetStyleSheetPool()->
                                     Find(aName, SfxStyleFamily::Para));
        DBG_ASSERT(pSheet, "StyleSheet missing");

        if (pSheet)
@@ -501,10 +496,10 @@ void FuConstructRectangle::SetAttributes(SfxItemSet& rAttr, SdrObject* pObj)
/**
 * set line starts and ends for the object to be created
 */
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, SdrModel const * pDoc)
{
    ::basegfx::B2DPolyPolygon aRetval;
    XLineEndListRef pLineEndList(rModel.GetLineEndList());
    XLineEndListRef pLineEndList = pDoc->GetLineEndList();

    if( pLineEndList.is() )
    {
@@ -541,10 +536,9 @@ void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj
          nSlotId == SID_LINE_SQUARE_ARROW )
    {
        // set attributes of line start and ends
        SdrModel& rModel(pObj->getSdrModelFromSdrObject()); // TTTT pObj should be reference

        // arrowhead
        ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
        ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, mpDoc ) );
        if( !aArrow.count() )
        {
            ::basegfx::B2DPolygon aNewArrow;
@@ -556,7 +550,7 @@ void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj
        }

        // Circles
        ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
        ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, mpDoc ) );
        if( !aCircle.count() )
        {
            ::basegfx::B2DPolygon aNewCircle;
@@ -566,7 +560,7 @@ void FuConstructRectangle::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj
        }

        // Square
        ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
        ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, mpDoc ) );
        if( !aSquare.count() )
        {
            ::basegfx::B2DPolygon aNewSquare;
@@ -770,9 +764,8 @@ SdrObject* FuConstructRectangle::CreateDefaultObject(const sal_uInt16 nID, const
    // case SID_CONNECTOR_LINES_CIRCLES:

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        mpView->getSdrModelFromSdrView(),
        mpView->GetCurrentObjInventor(),
        mpView->GetCurrentObjIdentifier());
        mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
        nullptr, mpDoc);

    if(pObj)
    {
diff --git a/sd/source/ui/func/fuconstr.cxx b/sd/source/ui/func/fuconstr.cxx
index 9e15f47..8f376fb 100644
--- a/sd/source/ui/func/fuconstr.cxx
+++ b/sd/source/ui/func/fuconstr.cxx
@@ -318,9 +318,9 @@ void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
        OUString aName( pPage->GetLayoutName() );
        sal_Int32 n = aName.indexOf(SD_LT_SEPARATOR) + strlen(SD_LT_SEPARATOR);
        aName = aName.copy(0, n) + STR_LAYOUT_BACKGROUNDOBJECTS;
        SfxStyleSheet* pSheet(
            static_cast< SfxStyleSheet* >(
                pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Page)));
        SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pPage->GetModel()->
                                                GetStyleSheetPool()->
                                                Find(aName, SfxStyleFamily::Page));
        DBG_ASSERT(pSheet, "StyleSheet missing");
        if (pSheet)
        {
@@ -348,9 +348,9 @@ void FuConstruct::SetStyleSheet( SfxItemSet& rAttr, SdrObject* pObj,
        if ( bForceNoFillStyle )
        {
            OUString aName(SdResId(STR_POOLSHEET_OBJWITHOUTFILL));
            SfxStyleSheet* pSheet(
                static_cast< SfxStyleSheet* >(
                    pPage->getSdrModelFromSdrPage().GetStyleSheetPool()->Find(aName, SfxStyleFamily::Para)));
            SfxStyleSheet* pSheet = static_cast<SfxStyleSheet*>(pPage->GetModel()->
                                         GetStyleSheetPool()->
                                         Find(aName, SfxStyleFamily::Para));
            DBG_ASSERT(pSheet, "Stylesheet missing");
            if (pSheet)
            {
diff --git a/sd/source/ui/func/fuconuno.cxx b/sd/source/ui/func/fuconuno.cxx
index 8ff99fd..935cb0c 100644
--- a/sd/source/ui/func/fuconuno.cxx
+++ b/sd/source/ui/func/fuconuno.cxx
@@ -138,9 +138,8 @@ SdrObject* FuConstructUnoControl::CreateDefaultObject(const sal_uInt16, const ::
    // case SID_FM_CREATE_CONTROL:

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        mpView->getSdrModelFromSdrView(),
        mpView->GetCurrentObjInventor(),
        mpView->GetCurrentObjIdentifier());
        mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
        nullptr, mpDoc);

    if(pObj)
    {
diff --git a/sd/source/ui/func/fuinsert.cxx b/sd/source/ui/func/fuinsert.cxx
index ad22e00..0cdd22d 100644
--- a/sd/source/ui/func/fuinsert.cxx
+++ b/sd/source/ui/func/fuinsert.cxx
@@ -386,11 +386,7 @@ void FuInsertOLE::DoExecute( SfxRequest& rReq )
                aRect = ::tools::Rectangle(aPos, aSize);
            }

            SdrOle2Obj* pOleObj = new SdrOle2Obj(
                mpView->getSdrModelFromSdrView(),
                svt::EmbeddedObjectRef( xObj, nAspect ),
                aObjName,
                aRect);
            SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aObjName, aRect );
            SdrPageView* pPV = mpView->GetSdrPageView();

            // if we have a pick obj we need to make this new ole a pres obj replacing the current pick obj
@@ -617,11 +613,8 @@ void FuInsertOLE::DoExecute( SfxRequest& rReq )
                    Point aPnt ((aPageSize.Width()  - aSize.Width())  / 2,
                        (aPageSize.Height() - aSize.Height()) / 2);
                    ::tools::Rectangle aRect (aPnt, aSize);
                    SdrOle2Obj* pObj = new SdrOle2Obj(
                        mpView->getSdrModelFromSdrView(),
                        aObjRef,
                        aName,
                        aRect);

                    SdrOle2Obj* pObj = new SdrOle2Obj( aObjRef, aName, aRect);

                    if( mpView->InsertObjectAtView(pObj, *pPV, SdrInsertFlags::SETDEFLAYER) )
                    {
diff --git a/sd/source/ui/func/fuinsfil.cxx b/sd/source/ui/func/fuinsfil.cxx
index 5ad65b6..fae8452 100644
--- a/sd/source/ui/func/fuinsfil.cxx
+++ b/sd/source/ui/func/fuinsfil.cxx
@@ -506,9 +506,7 @@ void FuInsertFile::InsTextOrRTFinDrMode(SfxMedium* pMedium)
            }
            else
            {
                SdrRectObj* pTO = new SdrRectObj(
                    mpView->getSdrModelFromSdrView(),
                    OBJ_TEXT);
                SdrRectObj* pTO = new SdrRectObj(OBJ_TEXT);
                pTO->SetOutlinerParaObject(pOPO);

                const bool bUndo = mpView->IsUndoEnabled();
diff --git a/sd/source/ui/func/fumorph.cxx b/sd/source/ui/func/fumorph.cxx
index 03aa0b0..b78c018 100644
--- a/sd/source/ui/func/fumorph.cxx
+++ b/sd/source/ui/func/fumorph.cxx
@@ -384,7 +384,7 @@ void FuMorph::ImpInsertPolygons(
    if ( pPageView )
    {
        SfxItemSet      aSet( aSet1 );
        SdrObjGroup*    pObjGroup = new SdrObjGroup(mpView->getSdrModelFromSdrView());
        SdrObjGroup*    pObjGroup = new SdrObjGroup;
        SdrObjList*     pObjList = pObjGroup->GetSubList();
        const size_t    nCount = rPolyPolyList3D.size();
        const double    fStep = 1. / ( nCount + 1 );
@@ -397,10 +397,7 @@ void FuMorph::ImpInsertPolygons(
        for ( size_t i = 0; i < nCount; i++, fFactor += fStep )
        {
            const ::basegfx::B2DPolyPolygon& rPolyPoly3D = *rPolyPolyList3D[ i ];
            SdrPathObj* pNewObj = new SdrPathObj(
                mpView->getSdrModelFromSdrView(),
                OBJ_POLY,
                rPolyPoly3D);
            SdrPathObj* pNewObj = new SdrPathObj(OBJ_POLY, rPolyPoly3D);

            // line color
            if ( bLineColor )
diff --git a/sd/source/ui/func/futext.cxx b/sd/source/ui/func/futext.cxx
index b6d81901..300e17c 100644
--- a/sd/source/ui/func/futext.cxx
+++ b/sd/source/ui/func/futext.cxx
@@ -691,7 +691,7 @@ bool FuText::MouseButtonUp(const MouseEvent& rMEvt)
            // outliner object up to now; also it needs to be set back to not
            // vertical when there was a vertical one used last time.
            OutlinerParaObject* pOPO = GetTextObj()->GetOutlinerParaObject();
            SdrOutliner& rOutl(mxTextObj->getSdrModelFromSdrObject().GetDrawOutliner(GetTextObj()));
            SdrOutliner& rOutl = mxTextObj->GetModel()->GetDrawOutliner(GetTextObj());
            bool bVertical((pOPO && pOPO->IsVertical())
                || nSlotId == SID_ATTR_CHAR_VERTICAL
                || nSlotId == SID_TEXT_FITTOSIZE_VERTICAL);
@@ -1304,11 +1304,10 @@ void FuText::DoubleClick(const MouseEvent& )
*/
SdrObject* FuText::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle)
{

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        mpView->getSdrModelFromSdrView(),
        mpView->GetCurrentObjInventor(),
        mpView->GetCurrentObjIdentifier(),
        nullptr);
        mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
        nullptr, mpDoc);

    if(pObj)
    {
diff --git a/sd/source/ui/func/unoaprms.cxx b/sd/source/ui/func/unoaprms.cxx
index ab46b90..021dc5b 100644
--- a/sd/source/ui/func/unoaprms.cxx
+++ b/sd/source/ui/func/unoaprms.cxx
@@ -27,7 +27,7 @@ void SdAnimationPrmsUndoAction::Undo()
    // no new info created: restore data
    if (!bInfoCreated)
    {
        SdDrawDocument* pDoc(dynamic_cast< SdDrawDocument* >(&pObject->getSdrModelFromSdrObject()));
        SdDrawDocument* pDoc   = static_cast<SdDrawDocument*>(pObject->GetModel());
        if( pDoc )
        {
            SdAnimationInfo* pInfo = SdDrawDocument::GetAnimationInfo( pObject );
diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 381b22b..67770cc 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -128,10 +128,6 @@ private:

    sd::DrawViewShell* GetViewShell();

protected:
    /** abstract SdrModel provider */
    virtual SdrModel* getSdrModelFromUnoModel() const override;

public:
    SdXImpressDocument(::sd::DrawDocShell* pShell, bool bClipBoard);
    SdXImpressDocument(SdDrawDocument* pDoc, bool bClipBoard);
diff --git a/sd/source/ui/sidebar/DocumentHelper.cxx b/sd/source/ui/sidebar/DocumentHelper.cxx
index b933612..dc76d90 100644
--- a/sd/source/ui/sidebar/DocumentHelper.cxx
+++ b/sd/source/ui/sidebar/DocumentHelper.cxx
@@ -53,11 +53,14 @@ SdPage* DocumentHelper::CopyMasterPageToLocalDocument (
            break;

        // Check the presence of the source document.
        SdDrawDocument& rSourceDocument(static_cast< SdDrawDocument& >(pMasterPage->getSdrModelFromSdrPage()));
        SdDrawDocument* pSourceDocument = static_cast<SdDrawDocument*>(
            pMasterPage->GetModel());
        if (pSourceDocument == nullptr)
            break;

        // When the given master page already belongs to the target document
        // then there is nothing more to do.
        if (&rSourceDocument == &rTargetDocument)
        if (pSourceDocument == &rTargetDocument)
        {
            pNewMasterPage = pMasterPage;
            break;
@@ -67,7 +70,7 @@ SdPage* DocumentHelper::CopyMasterPageToLocalDocument (
        // present.  This is not the case when we are called during the
        // creation of the slide master page because then the notes master
        // page is not there.
        sal_uInt16 nSourceMasterPageCount = rSourceDocument.GetMasterPageCount();
        sal_uInt16 nSourceMasterPageCount = pSourceDocument->GetMasterPageCount();
        if (nSourceMasterPageCount%2 == 0)
            // There should be 1 handout page + n slide masters + n notes
            // masters = 2*n+1.  An even value indicates that a new slide
@@ -78,11 +81,11 @@ SdPage* DocumentHelper::CopyMasterPageToLocalDocument (
            break;
        // Get the slide master page.
        if (pMasterPage != static_cast<SdPage*>(
            rSourceDocument.GetMasterPage(nIndex)))
            pSourceDocument->GetMasterPage(nIndex)))
            break;
        // Get the notes master page.
        SdPage* pNotesMasterPage = static_cast<SdPage*>(
            rSourceDocument.GetMasterPage(nIndex+1));
            pSourceDocument->GetMasterPage(nIndex+1));
        if (pNotesMasterPage == nullptr)
            break;

@@ -158,7 +161,7 @@ SdPage* DocumentHelper::GetSlideForMasterPage (SdPage const * pMasterPage)

    SdDrawDocument* pDocument = nullptr;
    if (pMasterPage != nullptr)
        pDocument = dynamic_cast< SdDrawDocument* >(&pMasterPage->getSdrModelFromSdrPage());
        pDocument = dynamic_cast<SdDrawDocument*>(pMasterPage->GetModel());

    // Iterate over all pages and check if it references the given master
    // page.
@@ -212,8 +215,10 @@ SdPage* DocumentHelper::AddMasterPage (
            pClonedMasterPage = static_cast<SdPage*>(pMasterPage->Clone());

            // Copy the necessary styles.
            SdDrawDocument& rSourceDocument(static_cast< SdDrawDocument& >(pMasterPage->getSdrModelFromSdrPage()));
            ProvideStyles(rSourceDocument, rTargetDocument, pClonedMasterPage);
            SdDrawDocument* pSourceDocument
                = static_cast<SdDrawDocument*>(pMasterPage->GetModel());
            if (pSourceDocument != nullptr)
                ProvideStyles (*pSourceDocument, rTargetDocument, pClonedMasterPage);

            // Copy the precious flag.
            pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious());
@@ -305,7 +310,7 @@ void DocumentHelper::AssignMasterPageToPageList (
    ::std::vector<SdPage*> aCleanedList;
    for (iPage=rpPageList->begin(); iPage!=rpPageList->end(); ++iPage)
    {
        OSL_ASSERT(*iPage!=nullptr && &(*iPage)->getSdrModelFromSdrPage() == &rTargetDocument);
        OSL_ASSERT(*iPage!=nullptr && (*iPage)->GetModel() == &rTargetDocument);
        if (*iPage != nullptr && (*iPage)->GetLayoutName() != sFullLayoutName)
        {
            aCleanedList.push_back(*iPage);
@@ -353,24 +358,28 @@ SdPage* DocumentHelper::AddMasterPage (
        pClonedMasterPage->SetPrecious(pMasterPage->IsPrecious());

        // Copy the necessary styles.
        SdDrawDocument& rSourceDocument(static_cast< SdDrawDocument& >(pMasterPage->getSdrModelFromSdrPage()));
        ProvideStyles(rSourceDocument, rTargetDocument, pClonedMasterPage);
        SdDrawDocument* pSourceDocument
            = static_cast<SdDrawDocument*>(pMasterPage->GetModel());
        if (pSourceDocument != nullptr)
        {
            ProvideStyles (*pSourceDocument, rTargetDocument, pClonedMasterPage);

        // Now that the styles are available we can insert the cloned
        // master page.
        rTargetDocument.InsertMasterPage (pClonedMasterPage, nInsertionIndex);
            // Now that the styles are available we can insert the cloned
            // master page.
            rTargetDocument.InsertMasterPage (pClonedMasterPage, nInsertionIndex);

        // Adapt the size of the new master page to that of the pages in
        // the document.
        Size aNewSize (rTargetDocument.GetSdPage(0, pMasterPage->GetPageKind())->GetSize());
        ::tools::Rectangle aBorders (
            pClonedMasterPage->GetLeftBorder(),
            pClonedMasterPage->GetUpperBorder(),
            pClonedMasterPage->GetRightBorder(),
            pClonedMasterPage->GetLowerBorder());
        pClonedMasterPage->ScaleObjects(aNewSize, aBorders, true);
        pClonedMasterPage->SetSize(aNewSize);
        pClonedMasterPage->CreateTitleAndLayout(true);
            // Adapt the size of the new master page to that of the pages in
            // the document.
            Size aNewSize (rTargetDocument.GetSdPage(0, pMasterPage->GetPageKind())->GetSize());
            ::tools::Rectangle aBorders (
                pClonedMasterPage->GetLeftBorder(),
                pClonedMasterPage->GetUpperBorder(),
                pClonedMasterPage->GetRightBorder(),
                pClonedMasterPage->GetLowerBorder());
            pClonedMasterPage->ScaleObjects(aNewSize, aBorders, true);
            pClonedMasterPage->SetSize(aNewSize);
            pClonedMasterPage->CreateTitleAndLayout(true);
        }
    }

    return pClonedMasterPage;
@@ -397,24 +406,25 @@ void DocumentHelper::AssignMasterPageToPage (
    // Leave early when the parameters are invalid.
    if (pPage == nullptr || pMasterPage == nullptr)
        return;

    SdDrawDocument& rDocument(dynamic_cast< SdDrawDocument& >(pPage->getSdrModelFromSdrPage()));
    SdDrawDocument* pDocument = dynamic_cast<SdDrawDocument*>(pPage->GetModel());
    if (pDocument == nullptr)
        return;

    if ( ! pPage->IsMasterPage())
    {
        // 1. Remove the background object (so that, if it exists, does
        // not override the new master page) and assign the master page to
        // the regular slide.
        rDocument.GetDocSh()->GetUndoManager()->AddUndoAction(
        pDocument->GetDocSh()->GetUndoManager()->AddUndoAction(
            new SdBackgroundObjUndoAction(
                rDocument, *pPage, pPage->getSdrPageProperties().GetItemSet()),
                *pDocument, *pPage, pPage->getSdrPageProperties().GetItemSet()),
            true);
        pPage->getSdrPageProperties().PutItem(XFillStyleItem(drawing::FillStyle_NONE));

        rDocument.SetMasterPage (
        pDocument->SetMasterPage (
            (pPage->GetPageNum()-1)/2,
            rsBaseLayoutName,
            &rDocument,
            pDocument,
            false,
            false);
    }
@@ -422,10 +432,10 @@ void DocumentHelper::AssignMasterPageToPage (
    {
        // Find first slide that uses the master page.
        SdPage* pSlide = nullptr;
        sal_uInt16 nPageCount = rDocument.GetSdPageCount(PageKind::Standard);
        sal_uInt16 nPageCount = pDocument->GetSdPageCount(PageKind::Standard);
        for (sal_uInt16 nPage=0; nPage<nPageCount&&pSlide==nullptr; nPage++)
        {
            SdrPage* pCandidate = rDocument.GetSdPage(nPage,PageKind::Standard);
            SdrPage* pCandidate = pDocument->GetSdPage(nPage,PageKind::Standard);
            if (pCandidate != nullptr
                && pCandidate->TRG_HasMasterPage()
                && &(pCandidate->TRG_GetMasterPage()) == pPage)
@@ -438,10 +448,10 @@ void DocumentHelper::AssignMasterPageToPage (
        {
            // 2. Assign the given master pages to the first slide that was
            // found above that uses the master page.
            rDocument.SetMasterPage (
            pDocument->SetMasterPage (
                (pSlide->GetPageNum()-1)/2,
                rsBaseLayoutName,
                &rDocument,
                pDocument,
                false,
                false);
        }
@@ -449,7 +459,7 @@ void DocumentHelper::AssignMasterPageToPage (
        {
            // 3. Replace the master page A by a copy of the given master
            // page B.
            rDocument.RemoveUnnecessaryMasterPages (
            pDocument->RemoveUnnecessaryMasterPages (
                pPage);
        }
    }
@@ -469,9 +479,11 @@ SdPage* DocumentHelper::ProvideMasterPage (
        OSL_ASSERT(pMasterPage != nullptr);
        return nullptr;
    }
    SdDrawDocument& rSourceDocument(static_cast< SdDrawDocument& >(pMasterPage->getSdrModelFromSdrPage()));
    SdDrawDocument* pSourceDocument = static_cast<SdDrawDocument*>(pMasterPage->GetModel());
    if (pSourceDocument == nullptr)
        return nullptr;
    SdPage* pNotesMasterPage = static_cast<SdPage*>(
        rSourceDocument.GetMasterPage(pMasterPage->GetPageNum()+1));
        pSourceDocument->GetMasterPage(pMasterPage->GetPageNum()+1));
    if (pNotesMasterPage == nullptr)
    {
        // The model is not in a valid state.  Maybe a new master page
@@ -509,7 +521,7 @@ SdPage* DocumentHelper::ProvideMasterPage (
    }

    // Clone the master page.
    if (&pMasterPage->getSdrModelFromSdrPage() != &rTargetDocument)
    if (pMasterPage->GetModel() != &rTargetDocument)
    {
        pMasterPageInDocument = AddMasterPage (rTargetDocument, pMasterPage, nInsertionIndex);
        if( rTargetDocument.IsUndoEnabled() )
@@ -520,7 +532,7 @@ SdPage* DocumentHelper::ProvideMasterPage (
        pMasterPageInDocument = pMasterPage;

    // Clone the notes master.
    if (&pNotesMasterPage->getSdrModelFromSdrPage() != &rTargetDocument)
    if (pNotesMasterPage->GetModel() != &rTargetDocument)
    {
        SdPage* pClonedNotesMasterPage
            = AddMasterPage (rTargetDocument, pNotesMasterPage, nInsertionIndex+1);
diff --git a/sd/source/ui/table/tablefunction.cxx b/sd/source/ui/table/tablefunction.cxx
index e85d27a..dd3e6a4 100644
--- a/sd/source/ui/table/tablefunction.cxx
+++ b/sd/source/ui/table/tablefunction.cxx
@@ -183,11 +183,7 @@ void DrawViewShell::FuTable(SfxRequest& rReq)
            aRect = ::tools::Rectangle(aPos, aSize);
        }

        sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj(
            *GetDoc(), // TTTT should be reference
            aRect,
            nColumns,
            nRows);
        sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( GetDoc(), aRect, nColumns, nRows );
        pObj->NbcSetStyleSheet( GetDoc()->GetDefaultStyleSheet(), true );
        apply_table_style( pObj, GetDoc(), sTableStyle );
        SdrPageView* pPV = mpView->GetSdrPageView();
@@ -275,11 +271,7 @@ void CreateTableFromRTF( SvStream& rStream, SdDrawDocument* pModel )
        {
            Size aSize( 200, 200 );
            ::tools::Rectangle aRect (Point(), aSize);
            sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj(
                *pModel,
                aRect,
                1,
                1);
            sdr::table::SdrTableObj* pObj = new sdr::table::SdrTableObj( pModel, aRect, 1, 1 );
            pObj->NbcSetStyleSheet( pModel->GetDefaultStyleSheet(), true );
            apply_table_style( pObj, pModel, OUString() );

diff --git a/sd/source/ui/tools/PreviewRenderer.cxx b/sd/source/ui/tools/PreviewRenderer.cxx
index 23717ea..158b160 100644
--- a/sd/source/ui/tools/PreviewRenderer.cxx
+++ b/sd/source/ui/tools/PreviewRenderer.cxx
@@ -202,9 +202,15 @@ bool PreviewRenderer::Initialize (
    if (pPage == nullptr)
        return false;

    SdrModel* pModel = pPage->GetModel();
    if (pModel == nullptr)
        return false;

    SetupOutputSize(*pPage, rPixelSize);
    SdDrawDocument& rDocument(static_cast< SdDrawDocument& >(pPage->getSdrModelFromSdrPage()));
    DrawDocShell* pDocShell = rDocument.GetDocSh();

    SdDrawDocument* pDocument
        = static_cast<SdDrawDocument*>(pPage->GetModel());
    DrawDocShell* pDocShell = pDocument->GetDocSh();

    // Create view
    ProvideView (pDocShell);
@@ -254,9 +260,9 @@ bool PreviewRenderer::Initialize (
    }

    pPageView->SetApplicationDocumentColor(aApplicationDocumentColor);
    SdrOutliner& rOutliner(rDocument.GetDrawOutliner());
    SdrOutliner& rOutliner(pDocument->GetDrawOutliner());
    rOutliner.SetBackgroundColor(aApplicationDocumentColor);
    rOutliner.SetDefaultLanguage(rDocument.GetLanguage(EE_CHAR_LANGUAGE));
    rOutliner.SetDefaultLanguage(pDocument->GetLanguage(EE_CHAR_LANGUAGE));
    mpPreviewDevice->SetBackground(Wallpaper(aApplicationDocumentColor));
    mpPreviewDevice->Erase();

diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index b6ee7d5..afe7ede 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2714,11 +2714,6 @@ void SdXImpressDocument::initializeDocument()
    }
}

SdrModel* SdXImpressDocument::getSdrModelFromUnoModel() const
{
    return GetDoc();
}

void SAL_CALL SdXImpressDocument::dispose()
{
    if( !mbDisposed )
diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx
index 7a34f2a..619d842 100644
--- a/sd/source/ui/unoidl/unopage.cxx
+++ b/sd/source/ui/unoidl/unopage.cxx
@@ -406,20 +406,23 @@ SdrObject * SdGenericDrawPage::CreateSdrObject_( const Reference< drawing::XShap
        SdrObject* pObj = SvxFmDrawPage::CreateSdrObject_( xShape );
        if( pObj && ( (pObj->GetObjInventor() != SdrInventor::Default) || (pObj->GetObjIdentifier() != OBJ_PAGE) ) )
        {
            SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
            // #i119287# similar to the code in the SdrObject methods the graphic and ole
            // SdrObjects need another default style than the rest, see task. Adding here, too.
            // TTTT: Same as for #i119287#: Can be removed in branch aw080 again
            const bool bIsSdrGrafObj(dynamic_cast< const SdrGrafObj* >(pObj) !=  nullptr);
            const bool bIsSdrOle2Obj(dynamic_cast< const SdrOle2Obj* >(pObj) !=  nullptr);
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
            if( pDoc )
            {
                // #i119287# similar to the code in the SdrObject methods the graphic and ole
                // SdrObjects need another default style than the rest, see task. Adding here, too.
                // TTTT: Same as for #i119287#: Can be removed in branch aw080 again
                const bool bIsSdrGrafObj(dynamic_cast< const SdrGrafObj* >(pObj) !=  nullptr);
                const bool bIsSdrOle2Obj(dynamic_cast< const SdrOle2Obj* >(pObj) !=  nullptr);

            if(bIsSdrGrafObj || bIsSdrOle2Obj)
            {
                pObj->NbcSetStyleSheet(rDoc.GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(), true);
            }
            else
            {
                pObj->NbcSetStyleSheet(rDoc.GetDefaultStyleSheet(), true);
                if(bIsSdrGrafObj || bIsSdrOle2Obj)
                {
                    pObj->NbcSetStyleSheet(pDoc->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(), true);
                }
                else
                {
                    pObj->NbcSetStyleSheet(pDoc->GetDefaultStyleSheet(), true);
                }
            }
        }
        return pObj;
@@ -515,8 +518,9 @@ SdrObject * SdGenericDrawPage::CreateSdrObject_( const Reference< drawing::XShap
        pPresObj = SvxFmDrawPage::CreateSdrObject_( xShape );
        if( pPresObj )
        {
            SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
            pPresObj->NbcSetStyleSheet(rDoc.GetDefaultStyleSheet(), true);
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
            if( pDoc )
                pPresObj->NbcSetStyleSheet( pDoc->GetDefaultStyleSheet(), true );
            GetPage()->InsertPresObj( pPresObj, eObjKind );
        }
    }
@@ -681,21 +685,21 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const OUString& aPropertyName

            if( eOri != GetPage()->GetOrientation() )
            {
                SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
                SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
                const PageKind ePageKind = GetPage()->GetPageKind();

                sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
                sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
                for (i = 0; i < nPageCnt; i++)
                {
                    SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
                    SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
                    pPage->SetOrientation( eOri );
                }

                nPageCnt = rDoc.GetSdPageCount(ePageKind);
                nPageCnt = pDoc->GetSdPageCount(ePageKind);

                for (i = 0; i < nPageCnt; i++)
                {
                    SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
                    SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
                    pPage->SetOrientation( eOri );
                }
            }
@@ -777,10 +781,10 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const OUString& aPropertyName
            SdrPage* pPage = GetPage();
            if( pPage )
            {
                SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(pPage->getSdrModelFromSdrPage()));
                if( rDoc.GetMasterPageCount() )
                SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pPage->GetModel());
                if( pDoc->GetMasterPageCount() )
                {
                    SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
                    SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
                    SdrLayerIDSet aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
                    aVisibleLayers.Set(rLayerAdmin.GetLayerID(SdResId(STR_LAYER_BCKGRND)), bVisible);
                    pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
@@ -797,10 +801,10 @@ void SAL_CALL SdGenericDrawPage::setPropertyValue( const OUString& aPropertyName
            SdrPage* pPage = GetPage();
            if( pPage )
            {
                SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(pPage->getSdrModelFromSdrPage()));
                if( rDoc.GetMasterPageCount() )
                SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pPage->GetModel());
                if( pDoc->GetMasterPageCount() )
                {
                    SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
                    SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
                    SdrLayerIDSet aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
                    aVisibleLayers.Set(rLayerAdmin.GetLayerID(SdResId(STR_LAYER_BCKGRNDOBJ)), bVisible);
                    pPage->TRG_SetMasterPageVisibleLayers(aVisibleLayers);
@@ -1096,36 +1100,39 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName )
    case WID_PAGE_PREVIEW :
    case WID_PAGE_PREVIEWMETAFILE :
        {
            SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
            ::sd::DrawDocShell* pDocShell = rDoc.GetDocSh();
            if ( pDocShell )
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
            if ( pDoc )
            {
                sal_uInt16 nPgNum = 0;
                sal_uInt16 nPageCount = rDoc.GetSdPageCount( PageKind::Standard );
                sal_uInt16 nPageNumber = static_cast<sal_uInt16>( ( GetPage()->GetPageNum() - 1 ) >> 1 );
                while( nPgNum < nPageCount )
                ::sd::DrawDocShell* pDocShell = pDoc->GetDocSh();
                if ( pDocShell )
                {
                    rDoc.SetSelected( rDoc.GetSdPage( nPgNum, PageKind::Standard ), nPgNum == nPageNumber );
                    nPgNum++;
                }
                std::shared_ptr<GDIMetaFile> xMetaFile = pDocShell->GetPreviewMetaFile();
                if (xMetaFile)
                {
                    Size    aSize( GetPage()->GetSize() );
                    xMetaFile->AddAction( static_cast<MetaAction*>(new MetaFillColorAction( COL_WHITE, true )), 0 );
                    xMetaFile->AddAction( static_cast<MetaAction*>(new MetaRectAction( ::tools::Rectangle( Point(), aSize ) )), 1 );
                    xMetaFile->SetPrefMapMode(MapMode(MapUnit::Map100thMM));
                    xMetaFile->SetPrefSize( aSize );
                    sal_uInt16 nPgNum = 0;
                    sal_uInt16 nPageCount = pDoc->GetSdPageCount( PageKind::Standard );
                    sal_uInt16 nPageNumber = static_cast<sal_uInt16>( ( GetPage()->GetPageNum() - 1 ) >> 1 );
                    while( nPgNum < nPageCount )
                    {
                        pDoc->SetSelected( pDoc->GetSdPage( nPgNum, PageKind::Standard ), nPgNum == nPageNumber );
                        nPgNum++;
                    }
                    std::shared_ptr<GDIMetaFile> xMetaFile = pDocShell->GetPreviewMetaFile();
                    if (xMetaFile)
                    {
                        Size    aSize( GetPage()->GetSize() );
                        xMetaFile->AddAction( static_cast<MetaAction*>(new MetaFillColorAction( COL_WHITE, true )), 0 );
                        xMetaFile->AddAction( static_cast<MetaAction*>(new MetaRectAction( ::tools::Rectangle( Point(), aSize ) )), 1 );
                        xMetaFile->SetPrefMapMode(MapMode(MapUnit::Map100thMM));
                        xMetaFile->SetPrefSize( aSize );

                    SvMemoryStream aDestStrm( 65535, 65535 );
                    if (nEntry == WID_PAGE_PREVIEW)
                        // Preview: WMF format.
                        ConvertGDIMetaFileToWMF(*xMetaFile, aDestStrm, nullptr, false);
                    else
                        // PreviewMetafile: SVM format.
                        xMetaFile->Write(aDestStrm);
                    Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aDestStrm.GetData()), aDestStrm.Tell() );
                    aAny <<= aSeq;
                        SvMemoryStream aDestStrm( 65535, 65535 );
                        if (nEntry == WID_PAGE_PREVIEW)
                            // Preview: WMF format.
                            ConvertGDIMetaFileToWMF(*xMetaFile, aDestStrm, nullptr, false);
                        else
                            // PreviewMetafile: SVM format.
                            xMetaFile->Write(aDestStrm);
                        Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aDestStrm.GetData()), aDestStrm.Tell() );
                        aAny <<= aSeq;
                    }
                }
            }
        }
@@ -1133,26 +1140,29 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName )

    case WID_PAGE_PREVIEWBITMAP :
        {
            SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
            ::sd::DrawDocShell* pDocShell = rDoc.GetDocSh();
            if ( pDocShell )
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
            if ( pDoc )
            {
                sal_uInt16 nPgNum = 0;
                sal_uInt16 nPageCount = rDoc.GetSdPageCount( PageKind::Standard );
                sal_uInt16 nPageNumber = static_cast<sal_uInt16>( ( GetPage()->GetPageNum() - 1 ) >> 1 );
                while( nPgNum < nPageCount )
                ::sd::DrawDocShell* pDocShell = pDoc->GetDocSh();
                if ( pDocShell )
                {
                    rDoc.SetSelected( rDoc.GetSdPage( nPgNum, PageKind::Standard ), nPgNum == nPageNumber );
                    nPgNum++;
                }
                std::shared_ptr<GDIMetaFile> xMetaFile = pDocShell->GetPreviewMetaFile();
                BitmapEx aBitmap;
                if (xMetaFile && xMetaFile->CreateThumbnail(aBitmap))
                {
                    SvMemoryStream aMemStream;
                    WriteDIB(aBitmap.GetBitmap(), aMemStream, false, false);
                    uno::Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aMemStream.GetData()), aMemStream.Tell() );
                    aAny <<= aSeq;
                    sal_uInt16 nPgNum = 0;
                    sal_uInt16 nPageCount = pDoc->GetSdPageCount( PageKind::Standard );
                    sal_uInt16 nPageNumber = static_cast<sal_uInt16>( ( GetPage()->GetPageNum() - 1 ) >> 1 );
                    while( nPgNum < nPageCount )
                    {
                        pDoc->SetSelected( pDoc->GetSdPage( nPgNum, PageKind::Standard ), nPgNum == nPageNumber );
                        nPgNum++;
                    }
                    std::shared_ptr<GDIMetaFile> xMetaFile = pDocShell->GetPreviewMetaFile();
                    BitmapEx aBitmap;
                    if (xMetaFile && xMetaFile->CreateThumbnail(aBitmap))
                    {
                        SvMemoryStream aMemStream;
                        WriteDIB(aBitmap.GetBitmap(), aMemStream, false, false);
                        uno::Sequence<sal_Int8> aSeq( static_cast<sal_Int8 const *>(aMemStream.GetData()), aMemStream.Tell() );
                        aAny <<= aSeq;
                    }
                }
            }
        }
@@ -1196,10 +1206,10 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName )
        SdrPage* pPage = GetPage();
        if( pPage )
        {
            SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(pPage->getSdrModelFromSdrPage()));
            if( rDoc.GetMasterPageCount() )
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pPage->GetModel());
            if( pDoc->GetMasterPageCount() )
            {
                SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
                SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
                SdrLayerIDSet aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
                aAny <<= aVisibleLayers.IsSet(rLayerAdmin.GetLayerID(SdResId(STR_LAYER_BCKGRND)));
            }
@@ -1215,10 +1225,10 @@ Any SAL_CALL SdGenericDrawPage::getPropertyValue( const OUString& PropertyName )
        SdrPage* pPage = GetPage();
        if( pPage )
        {
            SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(pPage->getSdrModelFromSdrPage()));
            if( rDoc.GetMasterPageCount() )
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(pPage->GetModel());
            if( pDoc->GetMasterPageCount() )
            {
                SdrLayerAdmin& rLayerAdmin = rDoc.GetLayerAdmin();
                SdrLayerAdmin& rLayerAdmin = pDoc->GetLayerAdmin();
                SdrLayerIDSet aVisibleLayers = pPage->TRG_GetMasterPageVisibleLayers();
                aAny <<= aVisibleLayers.IsSet(rLayerAdmin.GetLayerID(SdResId(STR_LAYER_BCKGRNDOBJ)));
            }
@@ -1674,21 +1684,21 @@ void SdGenericDrawPage::SetLeftBorder( sal_Int32 nValue )
{
    if( nValue != GetPage()->GetLeftBorder() )
    {
        SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
        SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
        const PageKind ePageKind = GetPage()->GetPageKind();

        sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
        sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
            pPage->SetLeftBorder( nValue );
        }

        nPageCnt = rDoc.GetSdPageCount(ePageKind);
        nPageCnt = pDoc->GetSdPageCount(ePageKind);

        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
            pPage->SetLeftBorder( nValue );
        }
    }
@@ -1698,21 +1708,21 @@ void SdGenericDrawPage::SetRightBorder( sal_Int32 nValue )
{
    if( nValue != GetPage()->GetRightBorder() )
    {
        SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
        SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
        const PageKind ePageKind = GetPage()->GetPageKind();

        sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
        sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
            pPage->SetRightBorder( nValue );
        }

        nPageCnt = rDoc.GetSdPageCount(ePageKind);
        nPageCnt = pDoc->GetSdPageCount(ePageKind);

        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
            pPage->SetRightBorder( nValue );
        }
    }
@@ -1722,21 +1732,21 @@ void SdGenericDrawPage::SetUpperBorder( sal_Int32 nValue )
{
    if( nValue != GetPage()->GetUpperBorder() )
    {
        SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
        SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
        const PageKind ePageKind = GetPage()->GetPageKind();

        sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
        sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
            pPage->SetUpperBorder( nValue );
        }

        nPageCnt = rDoc.GetSdPageCount(ePageKind);
        nPageCnt = pDoc->GetSdPageCount(ePageKind);

        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
            pPage->SetUpperBorder( nValue );
        }
    }
@@ -1746,21 +1756,21 @@ void SdGenericDrawPage::SetLowerBorder( sal_Int32 nValue )
{
    if( nValue != GetPage()->GetLowerBorder() )
    {
        SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
        SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
        const PageKind ePageKind = GetPage()->GetPageKind();

        sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
        sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
            pPage->SetLowerBorder( nValue );
        }

        nPageCnt = rDoc.GetSdPageCount(ePageKind);
        nPageCnt = pDoc->GetSdPageCount(ePageKind);

        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
            pPage->SetLowerBorder( nValue );
        }
    }
@@ -1801,25 +1811,25 @@ void SdGenericDrawPage::SetWidth( sal_Int32 nWidth )
    {
        aSize.setWidth( nWidth );

        SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
        SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
        const PageKind ePageKind = GetPage()->GetPageKind();

        sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
        sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
            pPage->SetSize(aSize);
        }

        nPageCnt = rDoc.GetSdPageCount(ePageKind);
        nPageCnt = pDoc->GetSdPageCount(ePageKind);

        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
            pPage->SetSize(aSize);
        }

        refreshpage( &rDoc, ePageKind );
        refreshpage( pDoc, ePageKind );
    }
}

@@ -1830,25 +1840,25 @@ void SdGenericDrawPage::SetHeight( sal_Int32 nHeight )
    {
        aSize.setHeight( nHeight );

        SdDrawDocument& rDoc(static_cast< SdDrawDocument& >(GetPage()->getSdrModelFromSdrPage()));
        SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(GetPage()->GetModel());
        const PageKind ePageKind = GetPage()->GetPageKind();

        sal_uInt16 i, nPageCnt = rDoc.GetMasterSdPageCount(ePageKind);
        sal_uInt16 i, nPageCnt = pDoc->GetMasterSdPageCount(ePageKind);
        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetMasterSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetMasterSdPage(i, ePageKind);
            pPage->SetSize(aSize);
        }

        nPageCnt = rDoc.GetSdPageCount(ePageKind);
        nPageCnt = pDoc->GetSdPageCount(ePageKind);

        for (i = 0; i < nPageCnt; i++)
        {
            SdPage* pPage = rDoc.GetSdPage(i, ePageKind);
            SdPage* pPage = pDoc->GetSdPage(i, ePageKind);
            pPage->SetSize(aSize);
        }

        refreshpage( &rDoc, ePageKind );
        refreshpage( pDoc, ePageKind );
    }
}

@@ -2379,7 +2389,7 @@ void SAL_CALL SdDrawPage::setMasterPage( const Reference< drawing::XDrawPage >& 

            pNotesPage->TRG_ClearMasterPage();
            sal_uInt16 nNum = SvxFmDrawPage::mpPage->TRG_GetMasterPage().GetPageNum() + 1;
            pNotesPage->TRG_SetMasterPage(*SvxFmDrawPage::mpPage->getSdrModelFromSdrPage().GetMasterPage(nNum));
            pNotesPage->TRG_SetMasterPage(*SvxFmDrawPage::mpPage->GetModel()->GetMasterPage(nNum));
            pNotesPage->SetLayoutName( pSdPage->GetLayoutName() );

            GetModel()->SetModified();
@@ -2476,7 +2486,7 @@ void SdDrawPage::setBackground( const Any& rValue )

    if( pBack )
    {
        pBack->fillItemSet( static_cast<SdDrawDocument*>(&GetPage()->getSdrModelFromSdrPage()), aSet );
        pBack->fillItemSet( static_cast<SdDrawDocument*>(GetPage()->GetModel()), aSet );
    }
    else
    {
@@ -2500,7 +2510,7 @@ void SdDrawPage::setBackground( const Any& rValue )
            pProp++;
        }

        pBackground->fillItemSet( static_cast<SdDrawDocument*>(&GetPage()->getSdrModelFromSdrPage()), aSet );
        pBackground->fillItemSet( static_cast<SdDrawDocument*>(GetPage()->GetModel()), aSet );
    }

    if( aSet.Count() == 0 )
@@ -2862,7 +2872,7 @@ void SdMasterPage::setBackground( const Any& rValue )

            if( pBack )
            {
                pBack->fillItemSet( static_cast<SdDrawDocument*>(&GetPage()->getSdrModelFromSdrPage()), aSet );
                pBack->fillItemSet( static_cast<SdDrawDocument*>(GetPage()->GetModel()), aSet );
            }
            else
            {
@@ -2885,11 +2895,11 @@ void SdMasterPage::setBackground( const Any& rValue )
                    pProp++;
                }

                pBackground->fillItemSet( static_cast<SdDrawDocument*>(&SvxFmDrawPage::mpPage->getSdrModelFromSdrPage()), aSet );
                pBackground->fillItemSet( static_cast<SdDrawDocument*>(SvxFmDrawPage::mpPage->GetModel()), aSet );
            }

            // if we find the background style, copy the set to the background
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(&SvxFmDrawPage::mpPage->getSdrModelFromSdrPage());
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(SvxFmDrawPage::mpPage->GetModel());
            SfxStyleSheetBasePool* pSSPool = pDoc->GetStyleSheetPool();
            if(pSSPool)
            {
@@ -2933,7 +2943,7 @@ void SdMasterPage::getBackground( Any& rValue )
        }
        else
        {
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(&SvxFmDrawPage::mpPage->getSdrModelFromSdrPage());
            SdDrawDocument* pDoc = static_cast<SdDrawDocument*>(SvxFmDrawPage::mpPage->GetModel());
            SfxStyleSheetBasePool* pSSPool = pDoc->GetStyleSheetPool();
            if(pSSPool)
            {
@@ -3082,9 +3092,9 @@ Reference< uno::XInterface > createUnoPageImpl( SdPage* pPage )
{
    Reference< uno::XInterface > xPage;

    if( pPage )
    if( pPage && pPage->GetModel() )
    {
        SdXImpressDocument* pModel = SdXImpressDocument::getImplementation( pPage->getSdrModelFromSdrPage().getUnoModel() );
        SdXImpressDocument* pModel = SdXImpressDocument::getImplementation( pPage->GetModel()->getUnoModel() );
        if( pModel )
        {
            if( pPage->IsMasterPage() )
diff --git a/sd/source/ui/view/DocumentRenderer.cxx b/sd/source/ui/view/DocumentRenderer.cxx
index 4321466..c89213c 100644
--- a/sd/source/ui/view/DocumentRenderer.cxx
+++ b/sd/source/ui/view/DocumentRenderer.cxx
@@ -1526,10 +1526,7 @@ private:
        std::vector< ::tools::Rectangle >::iterator iter( aAreas.begin() );
        while( iter != aAreas.end() )
        {
            pHandout->NbcInsertObject(
                new SdrPageObj(
                    rModel,
                    (*iter++)));
            pHandout->NbcInsertObject( new SdrPageObj((*iter++)) );

            if( bDrawLines && (iter != aAreas.end())  )
            {
@@ -1549,10 +1546,7 @@ private:
                    aPathPoly.append( aPoly );
                }

                SdrPathObj* pPathObj = new SdrPathObj(
                    rModel,
                    OBJ_PATHLINE,
                    aPathPoly);
                SdrPathObj* pPathObj = new SdrPathObj(OBJ_PATHLINE, aPathPoly );
                pPathObj->SetMergedItem(XLineStyleItem(drawing::LineStyle_SOLID));
                pPathObj->SetMergedItem(XLineColorItem(OUString(), COL_BLACK));

diff --git a/sd/source/ui/view/drawview.cxx b/sd/source/ui/view/drawview.cxx
index 95a4807..56a07fd 100644
--- a/sd/source/ui/view/drawview.cxx
+++ b/sd/source/ui/view/drawview.cxx
@@ -78,15 +78,12 @@ namespace sd {
 * that there is no page a page is created.
 */

DrawView::DrawView(
    DrawDocShell* pDocSh,
    OutputDevice* pOutDev,
    DrawViewShell* pShell)
:   ::sd::View(*pDocSh->GetDoc(), pOutDev, pShell)
    ,mpDocShell(pDocSh)
    ,mpDrawViewShell(pShell)
    ,mpVDev(nullptr)
    ,mnPOCHSmph(0)
DrawView::DrawView( DrawDocShell* pDocSh, OutputDevice* pOutDev, DrawViewShell* pShell)
: ::sd::View(*pDocSh->GetDoc(), pOutDev, pShell)
, mpDocShell(pDocSh)
, mpDrawViewShell(pShell)
, mpVDev(nullptr)
, mnPOCHSmph(0)
{
    SetCurrentObj(OBJ_RECT);
}
diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx
index bbfd4e0..f61052b 100644
--- a/sd/source/ui/view/drviews2.cxx
+++ b/sd/source/ui/view/drviews2.cxx
@@ -520,9 +520,7 @@ public:
            if (!pMasterPage)
                continue;

            SdrRectObj* pObject = new SdrRectObj(
                *m_rDrawViewShell.GetDoc(), // TTTT should be reference
                OBJ_TEXT);
            SdrRectObj* pObject = new SdrRectObj(OBJ_TEXT);
            pObject->SetMergedItem(makeSdrTextAutoGrowWidthItem(true));
            pObject->SetOutlinerParaObject(pOutliner->CreateParaObject());
            pMasterPage->InsertObject(pObject);
@@ -1087,9 +1085,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                }

                // create new object
                SdrGrafObj* pGraphicObj = new SdrGrafObj(
                    *GetDoc(),
                    aGraphic);
                SdrGrafObj* pGraphicObj = new SdrGrafObj (aGraphic);

                // get some necessary info and ensure it
                const SdrMarkList& rMarkList(mpDrawView->GetMarkedObjectList());
@@ -2343,9 +2339,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
                pOutl->QuickInsertField( *pFieldItem, ESelection() );
                OutlinerParaObject* pOutlParaObject = pOutl->CreateParaObject();

                SdrRectObj* pRectObj = new SdrRectObj(
                    *GetDoc(),
                    OBJ_TEXT);
                SdrRectObj* pRectObj = new SdrRectObj( OBJ_TEXT );
                pRectObj->SetMergedItem(makeSdrTextAutoGrowWidthItem(true));

                pOutl->UpdateFields();
diff --git a/sd/source/ui/view/drviews8.cxx b/sd/source/ui/view/drviews8.cxx
index e396b8e..1181d6c 100644
--- a/sd/source/ui/view/drviews8.cxx
+++ b/sd/source/ui/view/drviews8.cxx
@@ -120,10 +120,7 @@ void DrawViewShell::ScannerEvent()

                    if( bInsertNewObject )
                    {
                        auto pGrafObj = new SdrGrafObj(
                            GetView()->getSdrModelFromSdrView(),
                            Graphic(aScanBmp),
                            aRect);
                        auto pGrafObj = new SdrGrafObj( Graphic( aScanBmp ), aRect );
                        SdrPageView* pPV = GetView()->GetSdrPageView();
                        GetView()->InsertObjectAtView( pGrafObj, *pPV, SdrInsertFlags::SETDEFLAYER );
                    }
diff --git a/sd/source/ui/view/drviews9.cxx b/sd/source/ui/view/drviews9.cxx
index afc151b..4c2e6b1 100644
--- a/sd/source/ui/view/drviews9.cxx
+++ b/sd/source/ui/view/drviews9.cxx
@@ -169,10 +169,7 @@ void DrawViewShell::ExecGallery(SfxRequest const & rReq)

        if( bInsertNewObject )
        {
            pGrafObj = new SdrGrafObj(
                GetView()->getSdrModelFromSdrView(),
                aGraphic,
                aRect);
            pGrafObj = new SdrGrafObj(aGraphic, aRect);
            SdrPageView* pPV = mpDrawView->GetSdrPageView();
            mpDrawView->InsertObjectAtView(pGrafObj, *pPV, SdrInsertFlags::SETDEFLAYER);
        }
diff --git a/sd/source/ui/view/drviewse.cxx b/sd/source/ui/view/drviewse.cxx
index 8b69d36..0b082d9 100644
--- a/sd/source/ui/view/drviewse.cxx
+++ b/sd/source/ui/view/drviewse.cxx
@@ -1458,9 +1458,7 @@ void DrawViewShell::InsertURLField(const OUString& rURL, const OUString& rText,
        pOutl->QuickInsertField( aURLItem, ESelection() );
        OutlinerParaObject* pOutlParaObject = pOutl->CreateParaObject();

        SdrRectObj* pRectObj = new SdrRectObj(
            GetView()->getSdrModelFromSdrView(),
            OBJ_TEXT);
        SdrRectObj* pRectObj = new SdrRectObj(OBJ_TEXT);

        pOutl->UpdateFields();
        pOutl->SetUpdateMode( true );
@@ -1536,12 +1534,8 @@ void DrawViewShell::InsertURLButton(const OUString& rURL, const OUString& rText,

    if (bNewObj) try
    {
        SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >(
            SdrObjFactory::MakeNewObject(
                GetView()->getSdrModelFromSdrView(),
                SdrInventor::FmForm,
                OBJ_FM_BUTTON,
                mpDrawView->GetSdrPageView()->GetPage()));
        SdrUnoObj* pUnoCtrl = static_cast< SdrUnoObj* >( SdrObjFactory::MakeNewObject(SdrInventor::FmForm, OBJ_FM_BUTTON,
                                mpDrawView->GetSdrPageView()->GetPage(), GetDoc()) );

        Reference< awt::XControlModel > xControlModel( pUnoCtrl->GetUnoControlModel(), uno::UNO_QUERY_THROW );
        Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY_THROW );
diff --git a/sd/source/ui/view/frmview.cxx b/sd/source/ui/view/frmview.cxx
index b08896a..3795f9e 100644
--- a/sd/source/ui/view/frmview.cxx
+++ b/sd/source/ui/view/frmview.cxx
@@ -51,7 +51,7 @@ using namespace ::std;
namespace sd {

FrameView::FrameView(SdDrawDocument* pDrawDoc, FrameView* pFrameView /* = NULK */)
:   SdrView(*pDrawDoc, nullptr), // TTTT SdDrawDocument* -> should be reference
  : SdrView(pDrawDoc, nullptr),
    mnRefCount(0),
    mnPresViewShellId(SID_VIEWSHELL0),
    mbIsNavigatorShowingAllShapes(false)
diff --git a/sd/source/ui/view/sdview.cxx b/sd/source/ui/view/sdview.cxx
index 7bff930..d0344d2 100644
--- a/sd/source/ui/view/sdview.cxx
+++ b/sd/source/ui/view/sdview.cxx
@@ -104,11 +104,10 @@ using namespace com::sun::star::uno;
using namespace sdr::table;
namespace sd {

View::View(
    SdDrawDocument& rDrawDoc,
    OutputDevice* pOutDev,
    ViewShell* pViewShell)
:   FmFormView(rDrawDoc, pOutDev),

View::View(SdDrawDocument& rDrawDoc, OutputDevice* pOutDev,
               ViewShell* pViewShell)
  : FmFormView(&rDrawDoc, pOutDev),
    mrDoc(rDrawDoc),
    mpDocSh(rDrawDoc.GetDocSh()),
    mpViewSh(pViewShell),
@@ -659,7 +658,7 @@ bool View::SdrBeginTextEdit(
        EventMultiplexerEventId::BeginTextEdit, static_cast<void*>(pObj) );

    if( pOutl==nullptr && pObj )
        pOutl = SdrMakeOutliner(OutlinerMode::TextObject, pObj->getSdrModelFromSdrObject());
        pOutl = SdrMakeOutliner(OutlinerMode::TextObject, *pObj->GetModel());

    // make draw&impress specific initialisations
    if( pOutl )
diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx
index cf6f728..c0f5f5e 100644
--- a/sd/source/ui/view/sdview3.cxx
+++ b/sd/source/ui/view/sdview3.cxx
@@ -797,11 +797,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
                                aNewSet.Put( pObj->GetMergedItemSet() );

                                if( bUndo )
                                    AddUndo(
                                        new E3dAttributesUndoAction(
                                            *static_cast< E3dObject* >(pPickObj),
                                            aNewSet,
                                            aOldSet));
                                    AddUndo( new E3dAttributesUndoAction( mrDoc, static_cast<E3dObject*>(pPickObj), aNewSet, aOldSet ) );
                                pPickObj->SetMergedItemSetAndBroadcast( aNewSet );
                            }

@@ -999,11 +995,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
                    maDropPos.AdjustY( -(std::min( aSize.Height(), aMaxSize.Height() ) >> 1) );

                    ::tools::Rectangle       aRect( maDropPos, aSize );
                    SdrOle2Obj*     pObj = new SdrOle2Obj(
                        getSdrModelFromSdrView(),
                        aObjRef,
                        aName,
                        aRect);
                    SdrOle2Obj*     pObj = new SdrOle2Obj( aObjRef, aName, aRect );
                    SdrPageView*    pPV = GetSdrPageView();
                    SdrInsertFlags  nOptions = SdrInsertFlags::SETDEFLAYER;

@@ -1173,11 +1165,7 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
                    maDropPos.AdjustY( -(std::min( aSize.Height(), aMaxSize.Height() ) >> 1) );

                    ::tools::Rectangle       aRect( maDropPos, aSize );
                    SdrOle2Obj*     pObj = new SdrOle2Obj(
                        getSdrModelFromSdrView(),
                        aObjRef,
                        aName,
                        aRect);
                    SdrOle2Obj*     pObj = new SdrOle2Obj( aObjRef, aName, aRect );
                    SdrPageView*    pPV = GetSdrPageView();
                    SdrInsertFlags  nOptions = SdrInsertFlags::SETDEFLAYER;

diff --git a/sd/source/ui/view/sdview4.cxx b/sd/source/ui/view/sdview4.cxx
index fb17fcc..f98a8ab 100644
--- a/sd/source/ui/view/sdview4.cxx
+++ b/sd/source/ui/view/sdview4.cxx
@@ -116,10 +116,7 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction,
        }
        else
        {
            pNewGrafObj = new SdrGrafObj(
                getSdrModelFromSdrView(),
                rGraphic,
                pPickObj->GetLogicRect());
            pNewGrafObj = new SdrGrafObj( rGraphic, pPickObj->GetLogicRect() );
            pNewGrafObj->SetEmptyPresObj(true);
        }

@@ -192,10 +189,7 @@ SdrGrafObj* View::InsertGraphic( const Graphic& rGraphic, sal_Int8& rAction,
                                                MapMode( MapUnit::Map100thMM ) );
        }

        pNewGrafObj = new SdrGrafObj(
            getSdrModelFromSdrView(),
            rGraphic,
            ::tools::Rectangle(rPos, aSize));
        pNewGrafObj = new SdrGrafObj( rGraphic, ::tools::Rectangle( rPos, aSize ) );
        SdrPage* pPage = pPV->GetPage();
        Size aPageSize( pPage->GetSize() );
        aPageSize.AdjustWidth( -(pPage->GetLeftBorder() + pPage->GetRightBorder()) );
@@ -335,9 +329,7 @@ SdrMediaObj* View::InsertMediaObj( const OUString& rMediaURL, const OUString& rM
            pUserCall = pPickObj->GetUserCall(); // ReplaceObjectAtView can free pPickObj
        }

        pNewMediaObj = new SdrMediaObj(
            getSdrModelFromSdrView(),
            aRect);
        pNewMediaObj = new SdrMediaObj( aRect );

        bool bIsPres = false;
        if( pPickObj )
@@ -537,11 +529,7 @@ IMPL_LINK_NOARG(View, DropInsertFileHdl, Timer *, void)

                            aRect = ::tools::Rectangle( maDropPos, aSize );

                            SdrOle2Obj* pOleObj = new SdrOle2Obj(
                                getSdrModelFromSdrView(),
                                svt::EmbeddedObjectRef(xObj, nAspect),
                                aName,
                                aRect);
                            SdrOle2Obj* pOleObj = new SdrOle2Obj( svt::EmbeddedObjectRef( xObj, nAspect ), aName, aRect );
                            SdrInsertFlags nOptions = SdrInsertFlags::SETDEFLAYER;

                            if (mpViewSh != nullptr)
diff --git a/svx/inc/dragmt3d.hxx b/svx/inc/dragmt3d.hxx
index 2ac1274..d8eba43 100644
--- a/svx/inc/dragmt3d.hxx
+++ b/svx/inc/dragmt3d.hxx
@@ -30,7 +30,7 @@
class E3dDragMethodUnit
{
public:
    E3dObject&                      mr3DObj;
    E3dObject*                      mp3DObj;
    basegfx::B3DPolyPolygon         maWireframePoly;
    basegfx::B3DHomMatrix           maDisplayTransform;
    basegfx::B3DHomMatrix           maInvDisplayTransform;
@@ -39,8 +39,8 @@ public:
    sal_Int32                       mnStartAngle;
    sal_Int32                       mnLastAngle;

    E3dDragMethodUnit(E3dObject& r3DObj)
    :   mr3DObj(r3DObj),
    E3dDragMethodUnit()
    :   mp3DObj(nullptr),
        maWireframePoly(),
        maDisplayTransform(),
        maInvDisplayTransform(),
@@ -48,8 +48,7 @@ public:
        maTransform(),
        mnStartAngle(0),
        mnLastAngle(0)
    {
    }
    {}
};

// Derivative of SdrDragMethod for 3D objects
diff --git a/svx/inc/sdr/properties/attributeproperties.hxx b/svx/inc/sdr/properties/attributeproperties.hxx
index d12374f3..6034426 100644
--- a/svx/inc/sdr/properties/attributeproperties.hxx
+++ b/svx/inc/sdr/properties/attributeproperties.hxx
@@ -31,12 +31,6 @@ namespace sdr
    {
        class AttributeProperties : public DefaultProperties, public SfxListener, public svl::StyleSheetUser
        {
            // get the correct (#119287#) default SfyStyleSheet from SdrObject's SdrModel
            SfxStyleSheet* ImpGetDefaultStyleSheet() const;

            // core to set parent at SfxItemSet and to execute the hard attribute computations
            void ImpSetParentAtSfxItemSet(bool bDontRemoveHardAttr);

            // add style sheet, do all the necessary handling
            void ImpAddStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr);

@@ -66,10 +60,6 @@ namespace sdr
            // Clone() operator, normally just calls the local copy constructor
            virtual BaseProperties& Clone(SdrObject& rObj) const override;

            // Get the local ItemSet. This directly returns the local ItemSet of the object. No
            // merging of ItemSets is done for e.g. Group objects.
            virtual const SfxItemSet& GetObjectItemSet() const override;

            // destructor
            virtual ~AttributeProperties() override;

@@ -79,6 +69,12 @@ namespace sdr
            // get the installed StyleSheet
            virtual SfxStyleSheet* GetStyleSheet() const override;

            // Move properties to a new ItemPool.
            virtual void MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel) override;

            // Set new model.
            virtual void SetModel(SdrModel* pOldModel, SdrModel* pNewModel) override;

            // force all attributes which come from styles to hard attributes
            // to be able to live without the style.
            virtual void ForceStyleToHardAttributes() override;
diff --git a/svx/inc/sdr/properties/e3dsceneproperties.hxx b/svx/inc/sdr/properties/e3dsceneproperties.hxx
index 00d3777..3705fd6 100644
--- a/svx/inc/sdr/properties/e3dsceneproperties.hxx
+++ b/svx/inc/sdr/properties/e3dsceneproperties.hxx
@@ -68,6 +68,9 @@ namespace sdr
            // get the installed StyleSheet
            virtual SfxStyleSheet* GetStyleSheet() const override;

            // Move properties to a new ItemPool. Default implementation does nothing.
            virtual void MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel) override;

            // Special for scene:
            void SetSceneItemsFromCamera();
        };
diff --git a/svx/inc/sdr/properties/groupproperties.hxx b/svx/inc/sdr/properties/groupproperties.hxx
index 9b6b28a..af197dc 100644
--- a/svx/inc/sdr/properties/groupproperties.hxx
+++ b/svx/inc/sdr/properties/groupproperties.hxx
@@ -103,6 +103,9 @@ namespace sdr
            // DefaultProperties::GetObjectItemSet() if a new ItemSet is created
            virtual void ForceDefaultAttributes() override;

            // Move properties to a new ItemPool.
            virtual void MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel) override;

            // force all attributes which come from styles to hard attributes
            // to be able to live without the style.
            virtual void ForceStyleToHardAttributes() override;
diff --git a/svx/source/accessibility/AccessibleEmptyEditSource.cxx b/svx/source/accessibility/AccessibleEmptyEditSource.cxx
index 19a09ec..6cbd41f 100644
--- a/svx/source/accessibility/AccessibleEmptyEditSource.cxx
+++ b/svx/source/accessibility/AccessibleEmptyEditSource.cxx
@@ -218,7 +218,8 @@ namespace accessibility
        mrViewWindow(rViewWindow),
        mbEditSourceEmpty( true )
    {
        StartListening( mrObj.getSdrModelFromSdrObject() );
        if( mrObj.GetModel() )
            StartListening( *mrObj.GetModel() );
    }

    AccessibleEmptyEditSource::~AccessibleEmptyEditSource()
@@ -231,7 +232,8 @@ namespace accessibility
        }
        else
        {
            EndListening( mrObj.getSdrModelFromSdrObject() );
            if( mrObj.GetModel() )
                EndListening( *mrObj.GetModel() );
        }
    }

@@ -254,7 +256,8 @@ namespace accessibility
    void AccessibleEmptyEditSource::Switch2ProxyEditSource()
    {
        // deregister EmptyEditSource model listener
        EndListening( mrObj.getSdrModelFromSdrObject() );
        if( mrObj.GetModel() )
            EndListening( *mrObj.GetModel() );

        ::std::unique_ptr< SvxEditSource > pProxySource( new AccessibleProxyEditSource_Impl(mrObj, mrView, mrViewWindow) );
        mpEditSource.swap(pProxySource);
diff --git a/svx/source/accessibility/AccessibleGraphicShape.cxx b/svx/source/accessibility/AccessibleGraphicShape.cxx
index fba25f4..31c4690 100644
--- a/svx/source/accessibility/AccessibleGraphicShape.cxx
+++ b/svx/source/accessibility/AccessibleGraphicShape.cxx
@@ -169,7 +169,7 @@ OUString AccessibleGraphicShape::CreateAccessibleDescription()
//  Return this object's role.
sal_Int16 SAL_CALL AccessibleGraphicShape::getAccessibleRole()
{
    if( m_pShape->getSdrModelFromSdrObject().GetImageMapForObject(m_pShape) != nullptr )
    if( m_pShape->GetModel()->GetImageMapForObject(m_pShape) != nullptr )
        return AccessibleRole::IMAGE_MAP;
    else
        return AccessibleShape::getAccessibleRole();
diff --git a/svx/source/core/extedit.cxx b/svx/source/core/extedit.cxx
index dab3052..a00216d 100644
--- a/svx/source/core/extedit.cxx
+++ b/svx/source/core/extedit.cxx
@@ -154,13 +154,12 @@ void ExternalToolEdit::Edit(GraphicObject const*const pGraphicObject)
}

SdrExternalToolEdit::SdrExternalToolEdit(
    FmFormView* pView,
    SdrObject* pObj)
:   m_pView(pView)
    ,m_pObj(pObj)
        FmFormView *const pView, SdrObject *const pObj)
    : m_pView(pView)
    , m_pObj(pObj)
{
    assert(m_pObj && m_pView);
    StartListening(m_pObj->getSdrModelFromSdrObject());
    StartListening(*m_pObj->GetModel());
}


diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index f2a00fe..2386b58 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -1980,10 +1980,7 @@ void EnhancedCustomShape2d::CreateSubPath(
            {
                basegfx::B2DPolyPolygon aClosedPolyPolygon(aNewB2DPolyPolygon);
                aClosedPolyPolygon.setClosed(true);
                SdrPathObj* pFill = new SdrPathObj(
                    mrSdrObjCustomShape.getSdrModelFromSdrObject(),
                    OBJ_POLY,
                    aClosedPolyPolygon);
                SdrPathObj* pFill = new SdrPathObj(OBJ_POLY, aClosedPolyPolygon);
                SfxItemSet aTempSet(*this);
                aTempSet.Put(makeSdrShadowItem(false));
                aTempSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1998,7 +1995,6 @@ void EnhancedCustomShape2d::CreateSubPath(
                // to correct the polygon (here: open it) using the type, the last edge may get lost.
                // Thus, use a type that fits the polygon
                SdrPathObj* pStroke = new SdrPathObj(
                    mrSdrObjCustomShape.getSdrModelFromSdrObject(),
                    aNewB2DPolyPolygon.isClosed() ? OBJ_POLY : OBJ_PLIN,
                    aNewB2DPolyPolygon);
                SfxItemSet aTempSet(*this);
@@ -2018,7 +2014,6 @@ void EnhancedCustomShape2d::CreateSubPath(
            {
                // see comment above about OBJ_PLIN
                pObj = new SdrPathObj(
                    mrSdrObjCustomShape.getSdrModelFromSdrObject(),
                    aNewB2DPolyPolygon.isClosed() ? OBJ_POLY : OBJ_PLIN,
                    aNewB2DPolyPolygon);
                aTempSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
@@ -2026,10 +2021,7 @@ void EnhancedCustomShape2d::CreateSubPath(
            else
            {
                aNewB2DPolyPolygon.setClosed(true);
                pObj = new SdrPathObj(
                    mrSdrObjCustomShape.getSdrModelFromSdrObject(),
                    OBJ_POLY,
                    aNewB2DPolyPolygon);
                pObj = new SdrPathObj(OBJ_POLY, aNewB2DPolyPolygon);
            }

            if(bNoStroke)
@@ -2380,7 +2372,7 @@ SdrObject* EnhancedCustomShape2d::CreatePathObj( bool bLineGeometryNeededOnly )
        // copy remaining objects to pRet
        if(vObjectList.size() > 1)
        {
            pRet = new SdrObjGroup(mrSdrObjCustomShape.getSdrModelFromSdrObject());
            pRet = new SdrObjGroup;

            for ( std::pair< SdrPathObj*, double >& rCandidate : vObjectList )
            {
@@ -2412,7 +2404,7 @@ SdrObject* EnhancedCustomShape2d::CreateObject( bool bLineGeometryNeededOnly )

    if ( eSpType == mso_sptRectangle )
    {
        pRet = new SdrRectObj(mrSdrObjCustomShape.getSdrModelFromSdrObject(), aLogicRect);
        pRet = new SdrRectObj( aLogicRect );
        pRet->SetMergedItemSet( *this );
    }
    if ( !pRet )
diff --git a/svx/source/customshapes/EnhancedCustomShape3d.cxx b/svx/source/customshapes/EnhancedCustomShape3d.cxx
index a0e2a6b..60177fc 100644
--- a/svx/source/customshapes/EnhancedCustomShape3d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape3d.cxx
@@ -255,24 +255,27 @@ SdrObject* EnhancedCustomShape3d::Create3DObject(
    const SdrObject* pShape2d,
    const SdrObjCustomShape& rSdrObjCustomShape)
{
    SdrObject* pRet(nullptr);
    const SdrCustomShapeGeometryItem& rGeometryItem(rSdrObjCustomShape.GetMergedItem(SDRATTR_CUSTOMSHAPE_GEOMETRY));
    double fMap(1.0), *pMap = nullptr;
    Fraction aFraction( rSdrObjCustomShape.getSdrModelFromSdrObject().GetScaleFraction() );
    SdrObject*  pRet = nullptr;
    SdrModel*   pModel = rSdrObjCustomShape.GetModel();
    const SdrCustomShapeGeometryItem& rGeometryItem = rSdrObjCustomShape.GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );

    if ( aFraction.GetNumerator() != 1 || aFraction.GetDenominator() != 1 )
    double      fMap, *pMap = nullptr;
    if ( pModel )
    {
        fMap *= double(aFraction);
        pMap = &fMap;
        fMap = 1.0;
        Fraction aFraction( pModel->GetScaleFraction() );
        if ( aFraction.GetNumerator() != 1 || aFraction.GetDenominator() != 1 )
         {
            fMap *= double(aFraction);
            pMap = &fMap;
        }
        if ( pModel->GetScaleUnit() != MapUnit::Map100thMM )
        {
            DBG_ASSERT( pModel->GetScaleUnit() == MapUnit::MapTwip, "EnhancedCustomShape3d::Current MapMode is Unsupported" );
            fMap *= 1440.0 / 2540.0;
            pMap = &fMap;
        }
    }

    if ( rSdrObjCustomShape.getSdrModelFromSdrObject().GetScaleUnit() != MapUnit::Map100thMM )
    {
        DBG_ASSERT( rSdrObjCustomShape.getSdrModelFromSdrObject().GetScaleUnit() == MapUnit::MapTwip, "EnhancedCustomShape3d::Current MapMode is Unsupported" );
        fMap *= 1440.0 / 2540.0;
        pMap = &fMap;
    }

    if ( GetBool( rGeometryItem, "Extrusion", false ) )
    {
        bool bIsMirroredX(rSdrObjCustomShape.IsMirroredX());
@@ -323,7 +326,7 @@ SdrObject* EnhancedCustomShape3d::Create3DObject(
        a3DDefaultAttr.SetDefaultLatheCharacterMode( true );
        a3DDefaultAttr.SetDefaultExtrudeCharacterMode( true );

        E3dScene* pScene = new E3dScene(rSdrObjCustomShape.getSdrModelFromSdrObject());
        E3dScene* pScene = new E3dScene;

        bool bSceneHasObjects ( false );
        bool bUseTwoFillStyles( false );
@@ -477,15 +480,10 @@ SdrObject* EnhancedCustomShape3d::Create3DObject(
                aBoundRect2d.Union( aBoundRect );

                // #i122777# depth 0 is okay for planes when using double-sided
                E3dCompoundObject* p3DObj = new E3dExtrudeObj(
                    rSdrObjCustomShape.getSdrModelFromSdrObject(),
                    a3DDefaultAttr,
                    aPolyPoly,
                    bUseTwoFillStyles ? 0 : fDepth );
                E3dCompoundObject* p3DObj = new E3dExtrudeObj( a3DDefaultAttr, aPolyPoly, bUseTwoFillStyles ? 0 : fDepth );

                p3DObj->NbcSetLayer( pShape2d->GetLayer() );
                p3DObj->SetMergedItemSet( aLocalSet );

                if ( bIsPlaceholderObject )
                    aPlaceholderObjectList.push_back( p3DObj );
                else if ( bUseTwoFillStyles )
@@ -532,11 +530,7 @@ SdrObject* EnhancedCustomShape3d::Create3DObject(
                        }
                    }
                    pScene->Insert3DObj( p3DObj );
                    p3DObj = new E3dExtrudeObj(
                        rSdrObjCustomShape.getSdrModelFromSdrObject(),
                        a3DDefaultAttr,
                        aPolyPoly,
                        fDepth);
                    p3DObj = new E3dExtrudeObj( a3DDefaultAttr, aPolyPoly, fDepth );
                    p3DObj->NbcSetLayer( pShape2d->GetLayer() );
                    p3DObj->SetMergedItemSet( aLocalSet );
                    if ( bUseExtrusionColor )
@@ -547,11 +541,7 @@ SdrObject* EnhancedCustomShape3d::Create3DObject(
                    pScene->Insert3DObj( p3DObj );

                    // #i122777# depth 0 is okay for planes when using double-sided
                    p3DObj = new E3dExtrudeObj(
                        rSdrObjCustomShape.getSdrModelFromSdrObject(),
                        a3DDefaultAttr,
                        aPolyPoly,
                        0);
                    p3DObj = new E3dExtrudeObj( a3DDefaultAttr, aPolyPoly, 0 );

                    p3DObj->NbcSetLayer( pShape2d->GetLayer() );
                    p3DObj->SetMergedItemSet( aLocalSet );
diff --git a/svx/source/customshapes/EnhancedCustomShapeEngine.cxx b/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
index 753d43c..133c008 100644
--- a/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeEngine.cxx
@@ -167,7 +167,7 @@ SdrObject* EnhancedCustomShapeEngine::ImplForceGroupWithText(
                if ( dynamic_cast<const SdrObjGroup*>( pRenderedShape) ==  nullptr )
                {
                    SdrObject* pTmp = pRenderedShape;
                    pRenderedShape = new SdrObjGroup(rSdrObjCustomShape.getSdrModelFromSdrObject());
                    pRenderedShape = new SdrObjGroup();
                    static_cast<SdrObjGroup*>(pRenderedShape)->GetSubList()->NbcInsertObject( pTmp );
                }
                static_cast<SdrObjGroup*>(pRenderedShape)->GetSubList()->NbcInsertObject( pShadowGeometry->Clone(), 0 );
@@ -181,9 +181,10 @@ SdrObject* EnhancedCustomShapeEngine::ImplForceGroupWithText(
        {
            // #i37011# also create a text object and add at rPos + 1
            SdrObject* pTextObj = SdrObjFactory::MakeNewObject(
                rSdrObjCustomShape.getSdrModelFromSdrObject(),
                rSdrObjCustomShape.GetObjInventor(),
                OBJ_TEXT);
                OBJ_TEXT,
                nullptr,
                rSdrObjCustomShape.GetModel());

            // Copy text content
            OutlinerParaObject* pParaObj(rSdrObjCustomShape.GetOutlinerParaObject());
@@ -232,7 +233,7 @@ SdrObject* EnhancedCustomShapeEngine::ImplForceGroupWithText(
                if ( dynamic_cast<const SdrObjGroup*>( pRenderedShape) ==  nullptr )
                {
                    SdrObject* pTmp = pRenderedShape;
                    pRenderedShape = new SdrObjGroup(rSdrObjCustomShape.getSdrModelFromSdrObject());
                    pRenderedShape = new SdrObjGroup();
                    static_cast<SdrObjGroup*>(pRenderedShape)->GetSubList()->NbcInsertObject( pTmp );
                }
                static_cast<SdrObjGroup*>(pRenderedShape)->GetSubList()->NbcInsertObject( pTextObj );
@@ -247,11 +248,12 @@ SdrObject* EnhancedCustomShapeEngine::ImplForceGroupWithText(
            if ( dynamic_cast<const SdrObjGroup*>( pRenderedShape) ==  nullptr )
            {
                SdrObject* pTmp = pRenderedShape;
                pRenderedShape = new SdrObjGroup(rSdrObjCustomShape.getSdrModelFromSdrObject());
                pRenderedShape = new SdrObjGroup();
                static_cast<SdrObjGroup*>(pRenderedShape)->GetSubList()->NbcInsertObject( pTmp );
            }

            pRenderedShape->SetPage(rSdrObjCustomShape.GetPage());
            pRenderedShape->SetModel(rSdrObjCustomShape.GetModel());
        }
    }

@@ -389,7 +391,9 @@ awt::Rectangle SAL_CALL EnhancedCustomShapeEngine::getTextBounds()
        SdrObjCustomShape& rSdrObjCustomShape(static_cast< SdrObjCustomShape& >(*GetSdrObjectFromXShape(mxShape)));
        uno::Reference< document::XActionLockable > xLockable( mxShape, uno::UNO_QUERY );

        if(xLockable.is() && !xLockable->isActionLocked())
        if(rSdrObjCustomShape.GetModel()
            && xLockable.is()
            && !xLockable->isActionLocked())
        {
            EnhancedCustomShape2d aCustomShape2d(rSdrObjCustomShape);
            tools::Rectangle aRect( aCustomShape2d.GetTextRect() );
diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
index 9bfed5d..71dc441 100644
--- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
+++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx
@@ -853,17 +853,13 @@ SdrObject* CreateSdrObjectFromParagraphOutlines(
            ++aTextAreaIter;
        }

        pRet = new SdrPathObj(
            rSdrObjCustomShape.getSdrModelFromSdrObject(),
            OBJ_POLY,
            aPolyPoly);
        pRet = new SdrPathObj( OBJ_POLY, aPolyPoly );

        SfxItemSet aSet(rSdrObjCustomShape.GetMergedItemSet());
        aSet.ClearItem( SDRATTR_TEXTDIRECTION );    //SJ: vertical writing is not required, by removing this item no outliner is created
        aSet.Put(makeSdrShadowItem(false)); // #i37011# NO shadow for FontWork geometry
        pRet->SetMergedItemSet( aSet );             // * otherwise we would crash, because the outliner tries to create a Paraobject, but there is no model
    }

    return pRet;
}

diff --git a/svx/source/dialog/connctrl.cxx b/svx/source/dialog/connctrl.cxx
index 9440ce67..b9a8ea7 100644
--- a/svx/source/dialog/connctrl.cxx
+++ b/svx/source/dialog/connctrl.cxx
@@ -39,7 +39,7 @@
SvxXConnectionPreview::SvxXConnectionPreview( vcl::Window* pParent, WinBits nStyle)
    : Control(pParent, nStyle)
    , pEdgeObj(nullptr)
    , pSdrPage(nullptr)
    , pObjList(nullptr)
    , pView(nullptr)
{
    SetMapMode(MapMode(MapUnit::Map100thMM));
@@ -55,7 +55,7 @@ SvxXConnectionPreview::~SvxXConnectionPreview()

void SvxXConnectionPreview::dispose()
{
    delete pSdrPage;
    delete pObjList;
    Control::dispose();
}

@@ -76,13 +76,13 @@ Size SvxXConnectionPreview::GetOptimalSize() const
void SvxXConnectionPreview::AdaptSize()
{
    // Adapt size
    if( !pSdrPage )
    if( !pObjList )
        return;

    SetMapMode(MapMode(MapUnit::Map100thMM));

    OutputDevice* pOD = pView->GetFirstOutputDevice(); // GetWin( 0 );
    tools::Rectangle aRect = pSdrPage->GetAllObjBoundRect();
    tools::Rectangle aRect = pObjList->GetAllObjBoundRect();

    MapMode aMapMode = GetMapMode();
    aMapMode.SetMapUnit( pOD->GetMapMode().GetMapUnit() );
@@ -171,43 +171,37 @@ void SvxXConnectionPreview::Construct()

                // potential memory leak here (!). Create SdrObjList only when there is
                // not yet one.
                if(!pSdrPage)
                if(!pObjList)
                {
                    pSdrPage = new SdrPage(
                        pView->getSdrModelFromSdrView(),
                        false);
                    pObjList = new SdrObjList( pView->GetModel(), nullptr );
                }

                if( pTmpObj1 )
                {
                    SdrObject* pObj1 = pTmpObj1->Clone();
                    pSdrPage->InsertObject( pObj1 );
                    pObjList->InsertObject( pObj1 );
                    pEdgeObj->ConnectToNode( true, pObj1 );
                }

                if( pTmpObj2 )
                {
                    SdrObject* pObj2 = pTmpObj2->Clone();
                    pSdrPage->InsertObject( pObj2 );
                    pObjList->InsertObject( pObj2 );
                    pEdgeObj->ConnectToNode( false, pObj2 );
                }

                pSdrPage->InsertObject( pEdgeObj );
                pObjList->InsertObject( pEdgeObj );
            }
        }
    }

    if( !pEdgeObj )
    {
        pEdgeObj = new SdrEdgeObj(pView->getSdrModelFromSdrView());
    }
        pEdgeObj = new SdrEdgeObj();

    AdaptSize();
}

void SvxXConnectionPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
{
    if (pSdrPage)
    if (pObjList)
    {
        // This will not work anymore. To not start at Adam and Eve, i will
        // ATM not try to change all this stuff to really using an own model
@@ -218,9 +212,9 @@ void SvxXConnectionPreview::Paint(vcl::RenderContext& rRenderContext, const tool
        // New stuff: Use a ObjectContactOfObjListPainter.
        sdr::contact::SdrObjectVector aObjectVector;

        for (size_t a = 0; a < pSdrPage->GetObjCount(); ++a)
        for (size_t a = 0; a < pObjList->GetObjCount(); ++a)
        {
            SdrObject* pObject = pSdrPage->GetObj(a);
            SdrObject* pObject = pObjList->GetObj(a);
            DBG_ASSERT(pObject,
                "SvxXConnectionPreview::Paint: Corrupt ObjectList (!)");
            aObjectVector.push_back(pObject);
diff --git a/svx/source/dialog/contwnd.cxx b/svx/source/dialog/contwnd.cxx
index c041a72..e404154 100644
--- a/svx/source/dialog/contwnd.cxx
+++ b/svx/source/dialog/contwnd.cxx
@@ -61,10 +61,7 @@ void ContourWindow::SetPolyPolygon(const tools::PolyPolygon& rPolyPoly)
    {
        basegfx::B2DPolyPolygon aPolyPolygon;
        aPolyPolygon.append(aPolyPoly[ i ].getB2DPolygon());
        SdrPathObj* pPathObj = new SdrPathObj(
            *pModel,
            OBJ_PATHFILL,
            aPolyPolygon);
        SdrPathObj* pPathObj = new SdrPathObj( OBJ_PATHFILL, aPolyPolygon );

        SfxItemSet aSet(pModel->GetItemPool());

diff --git a/svx/source/dialog/dlgctl3d.cxx b/svx/source/dialog/dlgctl3d.cxx
index 22bb53b..0eee458 100644
--- a/svx/source/dialog/dlgctl3d.cxx
+++ b/svx/source/dialog/dlgctl3d.cxx
@@ -92,12 +92,12 @@ void Svx3DPreviewControl::Construct()
    mpModel->InsertPage( mpFmPage, 0 );

    // 3D View
    mp3DView = new E3dView(*mpModel, this );
    mp3DView = new E3dView( mpModel, this );
    mp3DView->SetBufferedOutputAllowed(true);
    mp3DView->SetBufferedOverlayAllowed(true);

    // 3D Scene
    mpScene = new E3dScene(*mpModel);
    mpScene = new E3dScene;

    // initially create object
    SetObjectType(SvxPreviewObjectType::SPHERE);
@@ -204,7 +204,6 @@ void Svx3DPreviewControl::SetObjectType(SvxPreviewObjectType nType)
            case SvxPreviewObjectType::SPHERE:
            {
                mp3DObj = new E3dSphereObj(
                    *mpModel,
                    mp3DView->Get3DDefaultAttributes(),
                    basegfx::B3DPoint( 0, 0, 0 ),
                    basegfx::B3DVector( 5000, 5000, 5000 ));
@@ -214,7 +213,6 @@ void Svx3DPreviewControl::SetObjectType(SvxPreviewObjectType nType)
            case SvxPreviewObjectType::CUBE:
            {
                mp3DObj = new E3dCubeObj(
                    *mpModel,
                    mp3DView->Get3DDefaultAttributes(),
                    basegfx::B3DPoint( -2500, -2500, -2500 ),
                    basegfx::B3DVector( 5000, 5000, 5000 ));
@@ -288,7 +286,6 @@ void Svx3DLightControl::Construct2()
        // create invisible expansion object
        const double fMaxExpansion(RADIUS_LAMP_BIG + RADIUS_LAMP_PREVIEW_SIZE);
        mpExpansionObject = new E3dCubeObj(
            *mpModel,
            mp3DView->Get3DDefaultAttributes(),
            basegfx::B3DPoint(-fMaxExpansion, -fMaxExpansion, -fMaxExpansion),
            basegfx::B3DVector(2.0 * fMaxExpansion, 2.0 * fMaxExpansion, 2.0 * fMaxExpansion));
@@ -312,7 +309,6 @@ void Svx3DLightControl::Construct2()

        // create object for it
        mpLampBottomObject = new E3dPolygonObj(
            *mpModel,
            basegfx::B3DPolyPolygon(a3DCircle));
        mpScene->Insert3DObj( mpLampBottomObject );

@@ -326,7 +322,6 @@ void Svx3DLightControl::Construct2()

        // create object for it
        mpLampShaftObject = new E3dPolygonObj(
            *mpModel,
            basegfx::B3DPolyPolygon(a3DHalfCircle));
        mpScene->Insert3DObj( mpLampShaftObject );

@@ -388,7 +383,6 @@ void Svx3DLightControl::ConstructLightObjects()

            const double fLampSize(bIsSelectedLight ? RADIUS_LAMP_BIG : RADIUS_LAMP_SMALL);
            E3dObject* pNewLight = new E3dSphereObj(
                *mpModel,
                mp3DView->Get3DDefaultAttributes(),
                basegfx::B3DPoint( 0, 0, 0 ),
                basegfx::B3DVector( fLampSize, fLampSize, fLampSize));
diff --git a/svx/source/dialog/dlgctrl.cxx b/svx/source/dialog/dlgctrl.cxx
index 7e2ffb67..d89b71b 100644
--- a/svx/source/dialog/dlgctrl.cxx
+++ b/svx/source/dialog/dlgctrl.cxx
@@ -1468,9 +1468,14 @@ SvxXLinePreview::SvxXLinePreview(vcl::Window* pParent)
{
    InitSettings( true, true );

    mpLineObjA = new SdrPathObj(getModel(), OBJ_LINE);
    mpLineObjB = new SdrPathObj(getModel(), OBJ_PLIN);
    mpLineObjC = new SdrPathObj(getModel(), OBJ_PLIN);
    mpLineObjA = new SdrPathObj(OBJ_LINE);
    mpLineObjA->SetModel(&getModel());

    mpLineObjB = new SdrPathObj(OBJ_PLIN);
    mpLineObjB->SetModel(&getModel());

    mpLineObjC = new SdrPathObj(OBJ_PLIN);
    mpLineObjC->SetModel(&getModel());
}

VCL_BUILDER_FACTORY(SvxXLinePreview)
@@ -1558,16 +1563,15 @@ void SvxXLinePreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rec
}

SvxXRectPreview::SvxXRectPreview(vcl::Window* pParent)
:   SvxPreviewBase(pParent)
    ,mpRectangleObject(nullptr)
    : SvxPreviewBase(pParent)
    , mpRectangleObject(nullptr)
{
    InitSettings(true, true);

    // create RectangleObject
    const tools::Rectangle aObjectSize(Point(), GetOutputSize());
    mpRectangleObject = new SdrRectObj(
        getModel(),
        aObjectSize);
    mpRectangleObject = new SdrRectObj(aObjectSize);
    mpRectangleObject->SetModel(&getModel());
}

void SvxXRectPreview::Resize()
@@ -1576,9 +1580,8 @@ void SvxXRectPreview::Resize()
    SdrObject *pOrigObject = mpRectangleObject;
    if (pOrigObject)
    {
        mpRectangleObject = new SdrRectObj(
            getModel(),
            aObjectSize);
        mpRectangleObject = new SdrRectObj(aObjectSize);
        mpRectangleObject->SetModel(&getModel());
        SetAttributes(pOrigObject->GetMergedItemSet());
        SdrObject::Free(pOrigObject);
    }
@@ -1634,15 +1637,13 @@ SvxXShadowPreview::SvxXShadowPreview( vcl::Window* pParent )

    // create RectangleObject
    const tools::Rectangle aObjectSize( Point( aSize.Width(), aSize.Height() ), aSize );
    mpRectangleObject = new SdrRectObj(
        getModel(),
        aObjectSize);
    mpRectangleObject = new SdrRectObj(aObjectSize);
    mpRectangleObject->SetModel(&getModel());

    // create ShadowObject
    const tools::Rectangle aShadowSize( Point( aSize.Width(), aSize.Height() ), aSize );
    mpRectangleShadow = new SdrRectObj(
        getModel(),
        aShadowSize);
    mpRectangleShadow = new SdrRectObj(aShadowSize);
    mpRectangleShadow->SetModel(&getModel());
}

VCL_BUILDER_FACTORY(SvxXShadowPreview)
diff --git a/svx/source/dialog/graphctl.cxx b/svx/source/dialog/graphctl.cxx
index 07ff51e..481c55c 100644
--- a/svx/source/dialog/graphctl.cxx
+++ b/svx/source/dialog/graphctl.cxx
@@ -142,7 +142,7 @@ void GraphCtrl::InitSdrModel()
    pModel->SetChanged( false );

    // Creating a View
    pView = new GraphCtrlView(*pModel, this);
    pView = new GraphCtrlView( pModel, this );
    pView->SetWorkArea( tools::Rectangle( Point(), aGraphSize ) );
    pView->EnableExtendedMouseEventDispatcher( true );
    pView->ShowSdrPage(pView->GetModel()->GetPage(0));
diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx
index 557bbb0..da1a22a 100644
--- a/svx/source/dialog/imapwnd.cxx
+++ b/svx/source/dialog/imapwnd.cxx
@@ -195,10 +195,7 @@ SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )
            // clipped on CanvasPane
            aDrawRect.Intersection( aClipRect );

            pSdrObj = static_cast<SdrObject*>(
                new SdrRectObj(
                    *pModel,
                    aDrawRect));
            pSdrObj = static_cast<SdrObject*>(new SdrRectObj( aDrawRect ));
            pCloneIMapObj.reset(static_cast<IMapObject*>(new IMapRectangleObject( *pIMapRectObj )));
        }
        break;
@@ -214,13 +211,7 @@ SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )
            // limited to CanvasPane
            aCircle.Intersection( aClipRect );

            pSdrObj = static_cast<SdrObject*>(
                new SdrCircObj(
                    *pModel,
                    OBJ_CIRC,
                    aCircle,
                    0,
                    36000));
            pSdrObj = static_cast<SdrObject*>(new SdrCircObj( OBJ_CIRC, aCircle, 0, 36000 ));
            pCloneIMapObj.reset(static_cast<IMapObject*>(new IMapCircleObject( *pIMapCircleObj )));
        }
        break;
@@ -237,13 +228,7 @@ SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )
                // clipped on CanvasPane
                aDrawRect.Intersection( aClipRect );

                pSdrObj = static_cast<SdrObject*>(
                    new SdrCircObj(
                        *pModel,
                        OBJ_CIRC,
                        aDrawRect,
                        0,
                        36000));
                pSdrObj = static_cast<SdrObject*>(new SdrCircObj( OBJ_CIRC, aDrawRect, 0, 36000 ));
            }
            else
            {
@@ -255,11 +240,7 @@ SdrObject* IMapWindow::CreateObj( const IMapObject* pIMapObj )

                basegfx::B2DPolygon aPolygon;
                aPolygon.append(aDrawPoly.getB2DPolygon());
                pSdrObj = static_cast<SdrObject*>(
                    new SdrPathObj(
                        *pModel,
                        OBJ_POLY,
                        basegfx::B2DPolyPolygon(aPolygon)));
                pSdrObj = static_cast<SdrObject*>(new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aPolygon)));
            }

            pCloneIMapObj.reset(static_cast<IMapObject*>(new IMapPolygonObject( *pIMapPolyObj )));
@@ -764,10 +745,7 @@ void IMapWindow::CreateDefaultObject()
    aPagePos.AdjustY((aPageSize.Height() / 2) - (nDefaultObjectSizeHeight / 2) );
    tools::Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));

    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pModel,
        pView->GetCurrentObjInventor(),
        pView->GetCurrentObjIdentifier());
    SdrObject* pObj = SdrObjFactory::MakeNewObject( pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(), nullptr, pModel);
    pObj->SetLogicRect(aNewObjectRectangle);

    switch( pObj->GetObjIdentifier() )
diff --git a/svx/source/dialog/measctrl.cxx b/svx/source/dialog/measctrl.cxx
index 03e6300..ddca770 100644
--- a/svx/source/dialog/measctrl.cxx
+++ b/svx/source/dialog/measctrl.cxx
@@ -42,11 +42,9 @@ SvxXMeasurePreview::SvxXMeasurePreview(vcl::Window* pParent, WinBits nStyle)
    Point aPt1 = Point(aSize.Width() / 5, static_cast<long>(aSize.Height() / 2));
    Point aPt2 = Point(aSize.Width() * 4 / 5, static_cast<long>(aSize.Height() / 2));

    pMeasureObj = new SdrMeasureObj(aPt1, aPt2);
    pModel = new SdrModel();
    pMeasureObj = new SdrMeasureObj(
        *pModel,
        aPt1,
        aPt2);
    pMeasureObj->SetModel(pModel);

    bool bHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
    SetDrawMode(bHighContrast ? OUTPUT_DRAWMODE_CONTRAST : OUTPUT_DRAWMODE_COLOR);
diff --git a/svx/source/engine3d/cube3d.cxx b/svx/source/engine3d/cube3d.cxx
index 509688fe..6583969 100644
--- a/svx/source/engine3d/cube3d.cxx
+++ b/svx/source/engine3d/cube3d.cxx
@@ -35,31 +35,25 @@ sdr::contact::ViewContact* E3dCubeObj::CreateObjectSpecificViewContact()
}


E3dCubeObj::E3dCubeObj(
    SdrModel& rSdrModel,
    const E3dDefaultAttributes& rDefault,
    const basegfx::B3DPoint& aPos,
    const basegfx::B3DVector& r3DSize)
:   E3dCompoundObject(rSdrModel)
E3dCubeObj::E3dCubeObj(E3dDefaultAttributes& rDefault, const basegfx::B3DPoint& aPos, const basegfx::B3DVector& r3DSize)
:   E3dCompoundObject()
{
    // Set Defaults
    SetDefaultAttributes(rDefault);

    // position centre or left, bottom, back (dependent on bPosIsCenter)
    aCubePos = aPos;
    aCubePos = aPos; // position centre or left, bottom, back (dependent on bPosIsCenter)
    aCubeSize = r3DSize;
}

E3dCubeObj::E3dCubeObj(SdrModel& rSdrModel)
:   E3dCompoundObject(rSdrModel)
E3dCubeObj::E3dCubeObj()
:   E3dCompoundObject()
{
    // Set Defaults
    const E3dDefaultAttributes aDefault;

    E3dDefaultAttributes aDefault;
    SetDefaultAttributes(aDefault);
}

void E3dCubeObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
void E3dCubeObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
{
    aCubePos = rDefault.GetDefaultCubePos();
    aCubeSize = rDefault.GetDefaultCubeSize();
@@ -78,22 +72,9 @@ SdrObject *E3dCubeObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/) c
    return nullptr;
}

E3dCubeObj* E3dCubeObj::Clone(SdrModel* pTargetModel) const
E3dCubeObj* E3dCubeObj::Clone() const
{
    return CloneHelper< E3dCubeObj >(pTargetModel);
}

E3dCubeObj& E3dCubeObj::operator=(const E3dCubeObj& rObj)
{
    if( this == &rObj )
        return *this;
    E3dCompoundObject::operator=(rObj);

    aCubePos = rObj.aCubePos;
    aCubeSize = rObj.aCubeSize;
    bPosIsCenter = rObj.bPosIsCenter;

    return *this;
    return CloneHelper< E3dCubeObj >();
}

// Set local parameters with geometry re-creating
diff --git a/svx/source/engine3d/dragmt3d.cxx b/svx/source/engine3d/dragmt3d.cxx
index 5e070ab..e55931b 100644
--- a/svx/source/engine3d/dragmt3d.cxx
+++ b/svx/source/engine3d/dragmt3d.cxx
@@ -73,7 +73,8 @@ E3dDragMethod::E3dDragMethod (
        if(pE3dObj)
        {
            // fill new interaction unit
            E3dDragMethodUnit aNewUnit(*pE3dObj);
            E3dDragMethodUnit aNewUnit;
            aNewUnit.mp3DObj = pE3dObj;

            // get transformations
            aNewUnit.maInitTransform = aNewUnit.maTransform = pE3dObj->GetTransform();
@@ -156,15 +157,13 @@ bool E3dDragMethod::EndSdrDrag(bool /*bCopy*/)
        for(nOb=0;nOb<nCnt;nOb++)
        {
            E3dDragMethodUnit& rCandidate = maGrp[nOb];
            E3DModifySceneSnapRectUpdater aUpdater(&rCandidate.mr3DObj);
            rCandidate.mr3DObj.SetTransform(rCandidate.maTransform);
            E3DModifySceneSnapRectUpdater aUpdater(rCandidate.mp3DObj);
            rCandidate.mp3DObj->SetTransform(rCandidate.maTransform);
            if( bUndo )
            {
                getSdrDragView().AddUndo(
                    new E3dRotateUndoAction(
                        rCandidate.mr3DObj,
                        rCandidate.maInitTransform,
                        rCandidate.maTransform));
                getSdrDragView().AddUndo(new E3dRotateUndoAction(rCandidate.mp3DObj->GetModel(),
                    rCandidate.mp3DObj, rCandidate.maInitTransform,
                    rCandidate.maTransform));
            }
        }
        if( bUndo )
@@ -186,8 +185,8 @@ void E3dDragMethod::CancelSdrDrag()
            {
                // Restore transformation
                E3dDragMethodUnit& rCandidate = maGrp[nOb];
                E3DModifySceneSnapRectUpdater aUpdater(&rCandidate.mr3DObj);
                rCandidate.mr3DObj.SetTransform(rCandidate.maInitTransform);
                E3DModifySceneSnapRectUpdater aUpdater(rCandidate.mp3DObj);
                rCandidate.mp3DObj->SetTransform(rCandidate.maInitTransform);
            }
        }
    }
@@ -225,7 +224,7 @@ void E3dDragMethod::CreateOverlayGeometry(sdr::overlay::OverlayManager& rOverlay

            if(nPlyCnt)
            {
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mr3DObj.GetScene()->GetViewContact());
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mp3DObj->GetScene()->GetViewContact());
                const drawinglayer::geometry::ViewInformation3D& aViewInfo3D(rVCScene.getViewInformation3D());
                const basegfx::B3DHomMatrix aWorldToView(aViewInfo3D.getDeviceToView() * aViewInfo3D.getProjection() * aViewInfo3D.getOrientation());
                const basegfx::B3DHomMatrix aTransform(aWorldToView * rCandidate.maDisplayTransform);
@@ -262,7 +261,7 @@ E3dDragRotate::E3dDragRotate(SdrDragView &_rView,

    if(nCnt)
    {
        const E3dScene *pScene = maGrp[0].mr3DObj.GetScene();
        const E3dScene *pScene = maGrp[0].mp3DObj->GetScene();

        if(pScene)
        {
@@ -272,7 +271,7 @@ E3dDragRotate::E3dDragRotate(SdrDragView &_rView,
            for(sal_uInt32 nOb(0); nOb < nCnt; nOb++)
            {
                E3dDragMethodUnit& rCandidate = maGrp[nOb];
                basegfx::B3DPoint aObjCenter = rCandidate.mr3DObj.GetBoundVolume().getCenter();
                basegfx::B3DPoint aObjCenter = rCandidate.mp3DObj->GetBoundVolume().getCenter();
                const basegfx::B3DHomMatrix aTransform(aViewInfo3D.getOrientation() * rCandidate.maDisplayTransform * rCandidate.maInitTransform);

                aObjCenter = aTransform * aObjCenter;
@@ -388,7 +387,7 @@ void E3dDragRotate::MoveSdrDrag(const Point& rPnt)
            }

            // Transformation in eye coordinates, there rotate then and back
            const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mr3DObj.GetScene()->GetViewContact());
            const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mp3DObj->GetScene()->GetViewContact());
            const drawinglayer::geometry::ViewInformation3D& aViewInfo3D(rVCScene.getViewInformation3D());
            basegfx::B3DHomMatrix aInverseOrientation(aViewInfo3D.getOrientation());
            aInverseOrientation.invert();
@@ -406,8 +405,8 @@ void E3dDragRotate::MoveSdrDrag(const Point& rPnt)

            if(mbMoveFull)
            {
                E3DModifySceneSnapRectUpdater aUpdater(&rCandidate.mr3DObj);
                rCandidate.mr3DObj.SetTransform(rCandidate.maTransform);
                E3DModifySceneSnapRectUpdater aUpdater(rCandidate.mp3DObj);
                rCandidate.mp3DObj->SetTransform(rCandidate.maTransform);
            }
            else
            {
@@ -505,7 +504,7 @@ void E3dDragMove::MoveSdrDrag(const Point& rPnt)
            for(sal_uInt32 nOb(0); nOb < nCnt; nOb++)
            {
                E3dDragMethodUnit& rCandidate = maGrp[nOb];
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mr3DObj.GetScene()->GetViewContact());
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mp3DObj->GetScene()->GetViewContact());
                const drawinglayer::geometry::ViewInformation3D& aViewInfo3D(rVCScene.getViewInformation3D());

                // move coor from 2d world to 3d Eye
@@ -555,8 +554,8 @@ void E3dDragMove::MoveSdrDrag(const Point& rPnt)

                if(mbMoveFull)
                {
                    E3DModifySceneSnapRectUpdater aUpdater(&rCandidate.mr3DObj);
                    rCandidate.mr3DObj.SetTransform(rCandidate.maTransform);
                    E3DModifySceneSnapRectUpdater aUpdater(rCandidate.mp3DObj);
                    rCandidate.mp3DObj->SetTransform(rCandidate.maTransform);
                }
                else
                {
@@ -576,10 +575,10 @@ void E3dDragMove::MoveSdrDrag(const Point& rPnt)
            for(sal_uInt32 nOb(0); nOb < nCnt; nOb++)
            {
                E3dDragMethodUnit& rCandidate = maGrp[nOb];
                const basegfx::B3DPoint aObjectCenter(rCandidate.mr3DObj.GetBoundVolume().getCenter());
                const basegfx::B3DPoint aObjectCenter(rCandidate.mp3DObj->GetBoundVolume().getCenter());

                // transform from 2D world view to 3D eye
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mr3DObj.GetScene()->GetViewContact());
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(rCandidate.mp3DObj->GetScene()->GetViewContact());
                const drawinglayer::geometry::ViewInformation3D& aViewInfo3D(rVCScene.getViewInformation3D());

                basegfx::B2DPoint aGlobalScaleStart2D(static_cast<double>(aStartPos.X()), static_cast<double>(aStartPos.Y()));
@@ -674,14 +673,14 @@ void E3dDragMove::MoveSdrDrag(const Point& rPnt)

                if(mbMoveFull)
                {
                    E3DModifySceneSnapRectUpdater aUpdater(&rCandidate.mr3DObj);
                    rCandidate.mr3DObj.SetTransform(rCandidate.maTransform);
                    E3DModifySceneSnapRectUpdater aUpdater(rCandidate.mp3DObj);
                    rCandidate.mp3DObj->SetTransform(rCandidate.maTransform);
                }
                else
                {
                    Hide();
                    rCandidate.maWireframePoly.clear();
                    rCandidate.maWireframePoly = rCandidate.mr3DObj.CreateWireframe();
                    rCandidate.maWireframePoly = rCandidate.mp3DObj->CreateWireframe();
                    rCandidate.maWireframePoly.transform(rCandidate.maTransform);
                    Show();
                }
diff --git a/svx/source/engine3d/e3dsceneupdater.cxx b/svx/source/engine3d/e3dsceneupdater.cxx
index 28c4727..bc696da 100644
--- a/svx/source/engine3d/e3dsceneupdater.cxx
+++ b/svx/source/engine3d/e3dsceneupdater.cxx
@@ -29,27 +29,30 @@ E3DModifySceneSnapRectUpdater::E3DModifySceneSnapRectUpdater(const SdrObject* pO
    mpViewInformation3D(nullptr)
{
    // Secure old 3D transformation stack before modification
    if(const E3dObject* pE3dObject = dynamic_cast< const E3dObject* >(pObject))
    if(pObject)
    {
        mpScene = pE3dObject->GetScene();
        const E3dObject* pE3dObject = dynamic_cast< const E3dObject* >(pObject);

        if(mpScene && mpScene->GetScene() == mpScene)
        if(pE3dObject)
        {
            // if there is a scene and it's the outmost scene, get current 3D range
            const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(mpScene->GetViewContact());
            const basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D());
            mpScene = pE3dObject->GetScene();

            if(aAllContentRange.isEmpty())
            if(mpScene && mpScene->GetScene() == mpScene)
            {
                // no content, nothing to do
                mpScene = nullptr;
            }
            else
            {
                // secure current 3D transformation stack
                mpViewInformation3D.reset(
                    new drawinglayer::geometry::ViewInformation3D(
                        rVCScene.getViewInformation3D(aAllContentRange)));
                // if there is a scene and it's the outmost scene, get current 3D range
                const sdr::contact::ViewContactOfE3dScene& rVCScene = static_cast< sdr::contact::ViewContactOfE3dScene& >(mpScene->GetViewContact());
                const basegfx::B3DRange aAllContentRange(rVCScene.getAllContentRange3D());

                if(aAllContentRange.isEmpty())
                {
                    // no content, nothing to do
                    mpScene = nullptr;
                }
                else
                {
                    // secure current 3D transformation stack
                    mpViewInformation3D.reset( new drawinglayer::geometry::ViewInformation3D(rVCScene.getViewInformation3D(aAllContentRange)) );
                }
            }
        }
    }
diff --git a/svx/source/engine3d/e3dundo.cxx b/svx/source/engine3d/e3dundo.cxx
index 47268fc..e194dd6 100644
--- a/svx/source/engine3d/e3dundo.cxx
+++ b/svx/source/engine3d/e3dundo.cxx
@@ -38,32 +38,36 @@ bool E3dUndoAction::CanRepeat(SfxRepeatTarget&) const


// Undo destructor for 3D-Rotation
E3dRotateUndoAction::~E3dRotateUndoAction()

E3dRotateUndoAction::~E3dRotateUndoAction ()
{
}

// Undo for 3D-Rotation on the Rotation matrix
void E3dRotateUndoAction::Undo()

void E3dRotateUndoAction::Undo ()
{
    E3DModifySceneSnapRectUpdater aUpdater(&mrMy3DObj);
    mrMy3DObj.SetTransform(maMyOldRotation);
    E3DModifySceneSnapRectUpdater aUpdater(pMy3DObj);
    pMy3DObj->SetTransform(aMyOldRotation);
}

// Redo for 3D-Rotation on the Rotation matrix
void E3dRotateUndoAction::Redo()

void E3dRotateUndoAction::Redo ()
{
    E3DModifySceneSnapRectUpdater aUpdater(&mrMy3DObj);
    mrMy3DObj.SetTransform(maMyNewRotation);
    E3DModifySceneSnapRectUpdater aUpdater(pMy3DObj);
    pMy3DObj->SetTransform(aMyNewRotation);
}

E3dAttributesUndoAction::E3dAttributesUndoAction(
    E3dObject& rInObject,
    const SfxItemSet& rNewSet,
    const SfxItemSet& rOldSet)
:   SdrUndoAction(rInObject.getSdrModelFromSdrObject())
    ,mrObject(rInObject)
    ,maNewSet(rNewSet)
    ,maOldSet(rOldSet)

E3dAttributesUndoAction::E3dAttributesUndoAction( SdrModel &rModel,
                                                  E3dObject*  pInObject,
                                                  const SfxItemSet& rNewSet,
                                                  const SfxItemSet& rOldSet)
    : SdrUndoAction( rModel )
    , pObject      ( pInObject )
    , aNewSet      ( rNewSet )
    , aOldSet      ( rOldSet )
{
}

@@ -76,17 +80,18 @@ E3dAttributesUndoAction::~E3dAttributesUndoAction()

void E3dAttributesUndoAction::Undo()
{
    E3DModifySceneSnapRectUpdater aUpdater(&mrObject);
    mrObject.SetMergedItemSetAndBroadcast(maOldSet);
    E3DModifySceneSnapRectUpdater aUpdater(pObject);
    pObject->SetMergedItemSetAndBroadcast(aOldSet);
}

void E3dAttributesUndoAction::Redo()
{
    E3DModifySceneSnapRectUpdater aUpdater(&mrObject);
    mrObject.SetMergedItemSetAndBroadcast(maNewSet);
    E3DModifySceneSnapRectUpdater aUpdater(pObject);
    pObject->SetMergedItemSetAndBroadcast(aNewSet);
}

// Multiple Undo is not possible

bool E3dAttributesUndoAction::CanRepeat(SfxRepeatTarget& /*rView*/) const
{
    return false;
diff --git a/svx/source/engine3d/extrud3d.cxx b/svx/source/engine3d/extrud3d.cxx
index 0a92997..3b3bb93 100644
--- a/svx/source/engine3d/extrud3d.cxx
+++ b/svx/source/engine3d/extrud3d.cxx
@@ -39,24 +39,24 @@


// DrawContact section

sdr::contact::ViewContact* E3dExtrudeObj::CreateObjectSpecificViewContact()
{
    return new sdr::contact::ViewContactOfE3dExtrude(*this);
}


sdr::properties::BaseProperties* E3dExtrudeObj::CreateObjectSpecificProperties()
{
    return new sdr::properties::E3dExtrudeProperties(*this);
}


// Constructor creates a two cover surface tools::PolyPolygon and (point-count 1) side
// surfaces rectangles from the passed PolyPolygon
E3dExtrudeObj::E3dExtrudeObj(
    SdrModel& rSdrModel,
    const E3dDefaultAttributes& rDefault,
    const basegfx::B2DPolyPolygon& rPP,
    double fDepth)
:   E3dCompoundObject(rSdrModel),

E3dExtrudeObj::E3dExtrudeObj(E3dDefaultAttributes const & rDefault, const basegfx::B2DPolyPolygon& rPP, double fDepth)
:   E3dCompoundObject(),
    maExtrudePolygon(rPP)
{
    // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
@@ -71,16 +71,15 @@ E3dExtrudeObj::E3dExtrudeObj(
    GetProperties().SetObjectItemDirect(makeSvx3DDepthItem(static_cast<sal_uInt32>(fDepth + 0.5)));
}

E3dExtrudeObj::E3dExtrudeObj(SdrModel& rSdrModel)
:   E3dCompoundObject(rSdrModel)
E3dExtrudeObj::E3dExtrudeObj()
:   E3dCompoundObject()
{
    // Set Defaults
    const E3dDefaultAttributes aDefault;

    E3dDefaultAttributes aDefault;
    SetDefaultAttributes(aDefault);
}

void E3dExtrudeObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
void E3dExtrudeObj::SetDefaultAttributes(E3dDefaultAttributes const & rDefault)
{
    GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultExtrudeSmoothed()));
    GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultExtrudeSmoothFrontBack()));
@@ -98,21 +97,11 @@ sal_uInt16 E3dExtrudeObj::GetObjIdentifier() const
    return E3D_EXTRUDEOBJ_ID;
}

E3dExtrudeObj* E3dExtrudeObj::Clone(SdrModel* pTargetModel) const
E3dExtrudeObj* E3dExtrudeObj::Clone() const
{
    return CloneHelper< E3dExtrudeObj >(pTargetModel);
    return CloneHelper< E3dExtrudeObj >();
}

E3dExtrudeObj& E3dExtrudeObj::operator=(const E3dExtrudeObj& rObj)
{
    if( this == &rObj )
        return *this;
    E3dCompoundObject::operator=(rObj);

    maExtrudePolygon = rObj.maExtrudePolygon;

    return *this;
}

// Set local parameters with geometry re-creating

@@ -205,7 +194,7 @@ SdrAttrObj* E3dExtrudeObj::GetBreakObj()
    {
    // create PathObj
        basegfx::B2DPolyPolygon aPoly = TransformToScreenCoor(aBackSide);
        SdrPathObj* pPathObj = new SdrPathObj(getSdrModelFromSdrObject(), OBJ_PLIN, aPoly);
        SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aPoly);

        SfxItemSet aSet(GetObjectItemSet());
        aSet.Put(XLineStyleItem(css::drawing::LineStyle_SOLID));
diff --git a/svx/source/engine3d/lathe3d.cxx b/svx/source/engine3d/lathe3d.cxx
index 74097eb..99268c6 100644
--- a/svx/source/engine3d/lathe3d.cxx
+++ b/svx/source/engine3d/lathe3d.cxx
@@ -37,22 +37,23 @@


// DrawContact section

sdr::contact::ViewContact* E3dLatheObj::CreateObjectSpecificViewContact()
{
    return new sdr::contact::ViewContactOfE3dLathe(*this);
}


sdr::properties::BaseProperties* E3dLatheObj::CreateObjectSpecificProperties()
{
    return new sdr::properties::E3dLatheProperties(*this);
}


// Constructor from 3D polygon, scale is the conversion factor for the coordinates
E3dLatheObj::E3dLatheObj(
    SdrModel& rSdrModel,
    const E3dDefaultAttributes& rDefault,
    const basegfx::B2DPolyPolygon& rPoly2D)
:   E3dCompoundObject(rSdrModel),

E3dLatheObj::E3dLatheObj(E3dDefaultAttributes const & rDefault, const basegfx::B2DPolyPolygon& rPoly2D)
:   E3dCompoundObject(),
    maPolyPoly2D(rPoly2D)
{
    // since the old class PolyPolygon3D did mirror the given PolyPolygons in Y, do the same here
@@ -81,16 +82,15 @@ E3dLatheObj::E3dLatheObj(
    }
}

E3dLatheObj::E3dLatheObj(SdrModel& rSdrModel)
:    E3dCompoundObject(rSdrModel)
E3dLatheObj::E3dLatheObj()
:    E3dCompoundObject()
{
    // Set Defaults
    const E3dDefaultAttributes aDefault;

    E3dDefaultAttributes aDefault;
    SetDefaultAttributes(aDefault);
}

void E3dLatheObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
void E3dLatheObj::SetDefaultAttributes(E3dDefaultAttributes const & rDefault)
{
    GetProperties().SetObjectItemDirect(Svx3DSmoothNormalsItem(rDefault.GetDefaultLatheSmoothed()));
    GetProperties().SetObjectItemDirect(Svx3DSmoothLidsItem(rDefault.GetDefaultLatheSmoothFrontBack()));
@@ -104,20 +104,9 @@ sal_uInt16 E3dLatheObj::GetObjIdentifier() const
    return E3D_LATHEOBJ_ID;
}

E3dLatheObj* E3dLatheObj::Clone(SdrModel* pTargetModel) const
E3dLatheObj* E3dLatheObj::Clone() const
{
    return CloneHelper< E3dLatheObj >(pTargetModel);
}

E3dLatheObj& E3dLatheObj::operator=(const E3dLatheObj& rObj)
{
    if( this == &rObj )
        return *this;
    E3dCompoundObject::operator=(rObj);

    maPolyPoly2D = rObj.maPolyPoly2D;

    return *this;
    return CloneHelper< E3dLatheObj >();
}

// Convert the object to group object consisting of n polygons
@@ -187,7 +176,7 @@ SdrAttrObj* E3dLatheObj::GetBreakObj()
    // create PathObj
    basegfx::B3DPolyPolygon aLathePoly3D(basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(maPolyPoly2D));
    basegfx::B2DPolyPolygon aTransPoly(TransformToScreenCoor(aLathePoly3D));
    SdrPathObj* pPathObj = new SdrPathObj(getSdrModelFromSdrObject(), OBJ_PLIN, aTransPoly);
    SdrPathObj* pPathObj = new SdrPathObj(OBJ_PLIN, aTransPoly);

    // Set Attribute
    SfxItemSet aSet(GetObjectItemSet());
diff --git a/svx/source/engine3d/obj3d.cxx b/svx/source/engine3d/obj3d.cxx
index 959ecf1..73a0675 100644
--- a/svx/source/engine3d/obj3d.cxx
+++ b/svx/source/engine3d/obj3d.cxx
@@ -81,16 +81,16 @@ using namespace com::sun::star;


// List for 3D-Objects


E3dObjList::E3dObjList()
:   SdrObjList(nullptr)
:   SdrObjList(nullptr, nullptr)
{
}

E3dObjList* E3dObjList::CloneSdrObjList(SdrModel* pNewModel) const
E3dObjList::E3dObjList(const E3dObjList&)
:   SdrObjList()
{
    E3dObjList* pObjList = new E3dObjList();
    pObjList->lateInitSdrObjList(*this, pNewModel);
    return pObjList;
}

E3dObjList::~E3dObjList()
@@ -169,9 +169,8 @@ sdr::properties::BaseProperties* E3dObject::CreateObjectSpecificProperties()
}


E3dObject::E3dObject(SdrModel& rSdrModel)
:   SdrAttrObj(rSdrModel),
    maSubList(),
E3dObject::E3dObject()
:   maSubList(),
    maLocalBoundVol(),
    maTransformation(),
    maFullTransform(),
@@ -304,7 +303,14 @@ void E3dObject::SetPage(SdrPage* pNewPage)
    maSubList.SetPage(pNewPage);
}

void E3dObject::SetModel(SdrModel* pNewModel)
{
    SdrAttrObj::SetModel(pNewModel);
    maSubList.SetModel(pNewModel);
}

// resize object, used from old 2d interfaces, e.g. in Move/Scale dialog (F4)

void E3dObject::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
    // Movement in X, Y in the eye coordinate system
@@ -650,9 +656,9 @@ OUString E3dObject::TakeObjNamePlural() const
    return ImpGetResStr(STR_ObjNamePluralObj3d);
}

E3dObject* E3dObject::Clone(SdrModel* pTargetModel) const
E3dObject* E3dObject::Clone() const
{
    return CloneHelper< E3dObject >(pTargetModel);
    return CloneHelper< E3dObject >();
}

E3dObject& E3dObject::operator=(const E3dObject& rObj)
@@ -730,8 +736,9 @@ sdr::properties::BaseProperties* E3dCompoundObject::CreateObjectSpecificProperti
    return new sdr::properties::E3dCompoundProperties(*this);
}

E3dCompoundObject::E3dCompoundObject(SdrModel& rSdrModel)
:   E3dObject(rSdrModel),

E3dCompoundObject::E3dCompoundObject()
:   E3dObject(),
    aMaterialAmbientColor()
{
    // Set defaults
@@ -874,20 +881,9 @@ void E3dCompoundObject::RecalcSnapRect()
    }
}

E3dCompoundObject* E3dCompoundObject::Clone(SdrModel* pTargetModel) const
E3dCompoundObject* E3dCompoundObject::Clone() const
{
    return CloneHelper< E3dCompoundObject >(pTargetModel);
}

E3dCompoundObject& E3dCompoundObject::operator=(const E3dCompoundObject& rObj)
{
    if( this == &rObj )
        return *this;
    E3dObject::operator=(rObj);

    aMaterialAmbientColor = rObj.aMaterialAmbientColor;

    return *this;
    return CloneHelper< E3dCompoundObject >();
}

// convert given basegfx::B3DPolyPolygon to screen coor
diff --git a/svx/source/engine3d/objfac3d.cxx b/svx/source/engine3d/objfac3d.cxx
index 58e1479..b704cf2 100644
--- a/svx/source/engine3d/objfac3d.cxx
+++ b/svx/source/engine3d/objfac3d.cxx
@@ -52,19 +52,24 @@ IMPL_STATIC_LINK( E3dObjFactory, MakeObject, SdrObjCreatorParams, aParams, SdrOb
        switch ( aParams.nObjIdentifier )
        {
            case E3D_SCENE_ID:
                return new E3dScene(aParams.rSdrModel);
                return new E3dScene();
            case E3D_POLYGONOBJ_ID  :
                return new E3dPolygonObj(aParams.rSdrModel);
                return new E3dPolygonObj();
            case E3D_CUBEOBJ_ID :
                return new E3dCubeObj(aParams.rSdrModel);
                return new E3dCubeObj();
            case E3D_SPHEREOBJ_ID:
                return new E3dSphereObj(aParams.rSdrModel);
                // Gets the dummy constructor, as this is only called when
                // loading documents. The actual number of segments is however
                // determined only after loading the members. This will result
                // in that the first sphere will be immediately destroyed,
                // although it was never used.
                return new E3dSphereObj(E3dSphereObj::DUMMY);
            case E3D_EXTRUDEOBJ_ID:
                return new E3dExtrudeObj(aParams.rSdrModel);
                return new E3dExtrudeObj();
            case E3D_LATHEOBJ_ID:
                return new E3dLatheObj(aParams.rSdrModel);
                return new E3dLatheObj();
            case E3D_COMPOUNDOBJ_ID:
                return new E3dCompoundObject(aParams.rSdrModel);
                return new E3dCompoundObject();
        }
    }
    return nullptr;
diff --git a/svx/source/engine3d/polygn3d.cxx b/svx/source/engine3d/polygn3d.cxx
index bcb9ba8..190c0ca 100644
--- a/svx/source/engine3d/polygn3d.cxx
+++ b/svx/source/engine3d/polygn3d.cxx
@@ -25,16 +25,17 @@
#include <basegfx/polygon/b3dpolygon.hxx>
#include <basegfx/polygon/b3dpolygontools.hxx>


// DrawContact section

sdr::contact::ViewContact* E3dPolygonObj::CreateObjectSpecificViewContact()
{
    return new sdr::contact::ViewContactOfE3dPolygon(*this);
}

E3dPolygonObj::E3dPolygonObj(
    SdrModel& rSdrModel,
    const basegfx::B3DPolyPolygon& rPolyPoly3D)
:   E3dCompoundObject(rSdrModel),
:   E3dCompoundObject(),
    bLineOnly(true)
{
    // Set geometry
@@ -47,9 +48,9 @@ E3dPolygonObj::E3dPolygonObj(
    CreateDefaultTexture();
}

E3dPolygonObj::E3dPolygonObj(SdrModel& rSdrModel)
:   E3dCompoundObject(rSdrModel),
    bLineOnly(false)
E3dPolygonObj::E3dPolygonObj()
:   E3dCompoundObject(),
    bLineOnly(false) // added missing initialisation
{
    // Create no geometry
}
@@ -218,23 +219,9 @@ SdrObject *E3dPolygonObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/
    return nullptr;
}

E3dPolygonObj* E3dPolygonObj::Clone(SdrModel* pTargetModel) const
E3dPolygonObj* E3dPolygonObj::Clone() const
{
    return CloneHelper< E3dPolygonObj >(pTargetModel);
}

E3dPolygonObj& E3dPolygonObj::operator=(const E3dPolygonObj& rObj)
{
    if( this == &rObj )
        return *this;
    E3dCompoundObject::operator=(rObj);

    aPolyPoly3D = rObj.aPolyPoly3D;
    aPolyNormals3D = rObj.aPolyNormals3D;
    aPolyTexture2D = rObj.aPolyTexture2D;
    bLineOnly = rObj.bLineOnly;

    return *this;
    return CloneHelper< E3dPolygonObj >();
}

void E3dPolygonObj::SetLineOnly(bool bNew)
diff --git a/svx/source/engine3d/scene3d.cxx b/svx/source/engine3d/scene3d.cxx
index 38961d3..444331d 100644
--- a/svx/source/engine3d/scene3d.cxx
+++ b/svx/source/engine3d/scene3d.cxx
@@ -170,8 +170,8 @@ sdr::contact::ViewContact* E3dScene::CreateObjectSpecificViewContact()
}


E3dScene::E3dScene(SdrModel& rSdrModel)
:   E3dObject(rSdrModel),
E3dScene::E3dScene()
:   E3dObject(),
    aCamera(basegfx::B3DPoint(0.0, 0.0, 4.0), basegfx::B3DPoint()),
    mp3DDepthRemapper(nullptr),
    bDrawOnlySelected(false),
@@ -411,9 +411,24 @@ void E3dScene::removeAllNonSelectedObjects()
    }
}

E3dScene* E3dScene::Clone(SdrModel* pTargetModel) const
E3dScene* E3dScene::Clone() const
{
    return CloneHelper< E3dScene >(pTargetModel);
    return CloneHelper< E3dScene >();
}

void E3dScene::SuspendReportingDirtyRects()
{
    GetScene()->mbSkipSettingDirty = true;
}

void E3dScene::ResumeReportingDirtyRects()
{
    GetScene()->mbSkipSettingDirty = false;
}

void E3dScene::SetAllSceneRectsDirty()
{
    GetScene()->SetRectsDirty();
}

E3dScene& E3dScene::operator=(const E3dScene& rObj)
@@ -448,21 +463,6 @@ E3dScene& E3dScene::operator=(const E3dScene& rObj)
    return *this;
}

void E3dScene::SuspendReportingDirtyRects()
{
    GetScene()->mbSkipSettingDirty = true;
}

void E3dScene::ResumeReportingDirtyRects()
{
    GetScene()->mbSkipSettingDirty = false;
}

void E3dScene::SetAllSceneRectsDirty()
{
    GetScene()->SetRectsDirty();
}

// Rebuild Light- and label- object lists rebuild (after loading, allocation)

void E3dScene::RebuildLists()
diff --git a/svx/source/engine3d/sphere3d.cxx b/svx/source/engine3d/sphere3d.cxx
index 75670c2..ecac051 100644
--- a/svx/source/engine3d/sphere3d.cxx
+++ b/svx/source/engine3d/sphere3d.cxx
@@ -33,24 +33,25 @@
#include <sdr/contact/viewcontactofe3dsphere.hxx>
#include <basegfx/polygon/b3dpolygon.hxx>


// DrawContact section

sdr::contact::ViewContact* E3dSphereObj::CreateObjectSpecificViewContact()
{
    return new sdr::contact::ViewContactOfE3dSphere(*this);
}


sdr::properties::BaseProperties* E3dSphereObj::CreateObjectSpecificProperties()
{
    return new sdr::properties::E3dSphereProperties(*this);
}


// Build Sphere from polygon facets in latitude and longitude
E3dSphereObj::E3dSphereObj(
    SdrModel& rSdrModel,
    const E3dDefaultAttributes& rDefault,
    const basegfx::B3DPoint& rCenter,
    const basegfx::B3DVector& r3DSize)
:   E3dCompoundObject(rSdrModel)

E3dSphereObj::E3dSphereObj(E3dDefaultAttributes& rDefault, const basegfx::B3DPoint& rCenter, const basegfx::B3DVector& r3DSize)
:   E3dCompoundObject()
{
    // Set defaults
    SetDefaultAttributes(rDefault);
@@ -59,16 +60,23 @@ E3dSphereObj::E3dSphereObj(
    aSize = r3DSize;
}

E3dSphereObj::E3dSphereObj(SdrModel& rSdrModel)
:   E3dCompoundObject(rSdrModel)
// Create Sphere without creating the Polygons within

// This call is from the 3D Object Factory (objfac3d.cxx) and only when loading
// of documents. Here you do not need CreateSphere call, since the real number
// of segments is not even known yet. This was until 10.02.1997 a (small)
// memory leak.

E3dSphereObj::E3dSphereObj(Dummy /*dummy*/)
// the parameters it needs to be able to distinguish which
// constructors of the two is meant. The above is the default.
{
    // Set defaults
    const E3dDefaultAttributes aDefault;

    E3dDefaultAttributes aDefault;
    SetDefaultAttributes(aDefault);
}

void E3dSphereObj::SetDefaultAttributes(const E3dDefaultAttributes& rDefault)
void E3dSphereObj::SetDefaultAttributes(E3dDefaultAttributes& rDefault)
{
    // Set defaults
    aCenter = rDefault.GetDefaultSphereCenter();
@@ -87,21 +95,9 @@ SdrObject *E3dSphereObj::DoConvertToPolyObj(bool /*bBezier*/, bool /*bAddText*/)
    return nullptr;
}

E3dSphereObj* E3dSphereObj::Clone(SdrModel* pTargetModel) const
E3dSphereObj* E3dSphereObj::Clone() const
{
    return CloneHelper< E3dSphereObj >(pTargetModel);
}

E3dSphereObj& E3dSphereObj::operator=(const E3dSphereObj& rObj)
{
    if( this == &rObj )
        return *this;
    E3dCompoundObject::operator=(rObj);

    aCenter = rObj.aCenter;
    aSize = rObj.aSize;

    return *this;
    return CloneHelper< E3dSphereObj >();
}

// Set local parameters with geometry re-creating
diff --git a/svx/source/engine3d/view3d.cxx b/svx/source/engine3d/view3d.cxx
index 31d6c36..33d051f 100644
--- a/svx/source/engine3d/view3d.cxx
+++ b/svx/source/engine3d/view3d.cxx
@@ -224,12 +224,10 @@ void Impl3DMirrorConstructOverlay::SetMirrorAxis(Point aMirrorAxisA, Point aMirr
    }
}

E3dView::E3dView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrView(rSdrModel, pOut)
E3dView::E3dView(SdrModel* pModel, OutputDevice* pOut) :
    SdrView(pModel, pOut)
{
    InitView();
    InitView ();
}

// DrawMarkedObj override, since possibly only a single 3D object is to be
@@ -581,6 +579,7 @@ bool E3dView::ImpCloneAll3DObjectsToDestScene(E3dScene const * pSrcScene, E3dSce
                    pNewCompoundObj->SetTransform(aModifyingTransform * aNewObjectTrans);

                    // fill and insert new object
                    pNewCompoundObj->SetModel(pDstScene->GetModel());
                    pNewCompoundObj->SetPage(pDstScene->GetPage());
                    pNewCompoundObj->NbcSetLayer(pCompoundObj->GetLayer());
                    pNewCompoundObj->NbcSetStyleSheet(pCompoundObj->GetStyleSheet(), true);
@@ -701,15 +700,10 @@ void E3dView::ImpCreateSingle3DObjectFlat(E3dScene* pScene, SdrObject* pObj, boo
    if(pPath)
    {
        E3dDefaultAttributes aDefault = Get3DDefaultAttributes();

        if(bExtrude)
        {
            aDefault.SetDefaultExtrudeCharacterMode(true);
        }
        else
        {
            aDefault.SetDefaultLatheCharacterMode(true);
        }

        // Get Itemset of the original object
        SfxItemSet aSet(pObj->GetMergedItemSet());
@@ -742,13 +736,13 @@ void E3dView::ImpCreateSingle3DObjectFlat(E3dScene* pScene, SdrObject* pObj, boo
        E3dObject* p3DObj = nullptr;
        if(bExtrude)
        {
            p3DObj = new E3dExtrudeObj(pObj->getSdrModelFromSdrObject(), aDefault, pPath->GetPathPoly(), fDepth);
            p3DObj = new E3dExtrudeObj(aDefault, pPath->GetPathPoly(), fDepth);
        }
        else
        {
            basegfx::B2DPolyPolygon aPolyPoly2D(pPath->GetPathPoly());
            aPolyPoly2D.transform(rLatheMat);
            p3DObj = new E3dLatheObj(pObj->getSdrModelFromSdrObject(), aDefault, aPolyPoly2D);
            p3DObj = new E3dLatheObj(aDefault, aPolyPoly2D);
        }

        // Set attribute
@@ -842,10 +836,8 @@ void E3dView::ConvertMarkedObjTo3D(bool bExtrude, const basegfx::B2DPoint& rPnt1
    else
        BegUndo(SvxResId(RID_SVX_3D_UNDO_LATHE));

    SdrModel& rSdrModel(GetSdrMarkByIndex(0)->GetMarkedSdrObj()->getSdrModelFromSdrObject());

    // Create a new scene for the created 3D object
    E3dScene* pScene = new E3dScene(rSdrModel);
    E3dScene* pScene = new E3dScene;

    // Determine rectangle and possibly correct it
    tools::Rectangle aRect = GetAllMarkedRect();
@@ -1270,6 +1262,7 @@ bool E3dView::BegDragObj(const Point& rPnt, OutputDevice* pOut,
}

// Set current 3D drawing object, create the scene for this

E3dScene* E3dView::SetCurrent3DObj(E3dObject* p3DObj)
{
    DBG_ASSERT(p3DObj != nullptr, "Who puts in a NULL-pointer here");
@@ -1282,7 +1275,7 @@ E3dScene* E3dView::SetCurrent3DObj(E3dObject* p3DObj)

    tools::Rectangle aRect(0,0, static_cast<long>(fW), static_cast<long>(fH));

    E3dScene* pScene = new E3dScene(p3DObj->getSdrModelFromSdrObject());
    E3dScene* pScene = new E3dScene;

    InitScene(pScene, fW, fH, aVolume.getMaxZ() + ((fW + fH) / 4.0));

diff --git a/svx/source/form/fmdmod.cxx b/svx/source/form/fmdmod.cxx
index ac197b2..d487399 100644
--- a/svx/source/form/fmdmod.cxx
+++ b/svx/source/form/fmdmod.cxx
@@ -31,7 +31,6 @@ using namespace ::svxform;
::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  SAL_CALL SvxFmMSFactory::createInstance(const OUString& rServiceSpecifier)
{
    ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >  xRet;

    if ( rServiceSpecifier.startsWith( "com.sun.star.form.component." ) )
    {
        css::uno::Reference<css::uno::XComponentContext> xContext = comphelper::getProcessComponentContext();
@@ -39,17 +38,11 @@ using namespace ::svxform;
    }
    else if ( rServiceSpecifier == "com.sun.star.drawing.ControlShape" )
    {
        SdrModel* pTargetModel = getSdrModelFromUnoModel();
        OSL_ENSURE(pTargetModel, "Got no SdrModel for SdrShape construction (!)");
        SdrObject* pObj = new FmFormObj(*pTargetModel);
        SdrObject* pObj = new FmFormObj();
        xRet = static_cast<cppu::OWeakObject*>(static_cast<SvxShape_UnoImplHelper*>(new SvxShapeControl(pObj)));
    }

    if (!xRet.is())
    {
        xRet = SvxUnoDrawMSFactory::createInstance(rServiceSpecifier);
    }

    return xRet;
}

diff --git a/svx/source/form/fmdpage.cxx b/svx/source/form/fmdpage.cxx
index 45ac667..1e81e8f 100644
--- a/svx/source/form/fmdpage.cxx
+++ b/svx/source/form/fmdpage.cxx
@@ -73,13 +73,10 @@ SdrObject *SvxFmDrawPage::CreateSdrObject_( const css::uno::Reference< css::draw
    if  (   aShapeType == "com.sun.star.drawing.ShapeControl"   // compatibility
        ||  aShapeType == "com.sun.star.drawing.ControlShape"
        )
    {
        return new FmFormObj(GetSdrPage()->getSdrModelFromSdrPage());
    }
        return new FmFormObj();
    else
    {
        return SvxDrawPage::CreateSdrObject_( xDescr );
    }

}

css::uno::Reference< css::drawing::XShape >  SvxFmDrawPage::CreateShape( SdrObject *pObj ) const
diff --git a/svx/source/form/fmobj.cxx b/svx/source/form/fmobj.cxx
index 44431b8..5863ec9 100644
--- a/svx/source/form/fmobj.cxx
+++ b/svx/source/form/fmobj.cxx
@@ -55,27 +55,26 @@ using namespace ::com::sun::star::container;
using namespace ::svxform;


FmFormObj::FmFormObj(
    SdrModel& rSdrModel,
    const OUString& rModelName)
:   SdrUnoObj(rSdrModel, rModelName)
    ,m_nPos(-1)
    ,m_pLastKnownRefDevice(nullptr)
FmFormObj::FmFormObj(const OUString& rModelName)
          :SdrUnoObj                ( rModelName    )
          ,m_nPos                   ( -1            )
          ,m_pLastKnownRefDevice    ( nullptr          )
{

    // normally, this is done in SetUnoControlModel, but if the call happened in the base class ctor,
    // then our incarnation of it was not called (since we were not constructed at this time).
    impl_checkRefDevice_nothrow( true );
}

FmFormObj::FmFormObj(SdrModel& rSdrModel)
:   SdrUnoObj(rSdrModel, "")
    ,m_nPos(-1)
    ,m_pLastKnownRefDevice(nullptr)

FmFormObj::FmFormObj()
          :SdrUnoObj                ( ""  )
          ,m_nPos                   ( -1        )
          ,m_pLastKnownRefDevice    ( nullptr      )
{
    // Stuff that old SetModel also did:
    impl_checkRefDevice_nothrow();
}


FmFormObj::~FmFormObj()
{

@@ -106,7 +105,7 @@ void FmFormObj::ClearObjEnv()

void FmFormObj::impl_checkRefDevice_nothrow( bool _force )
{
    const FmFormModel* pFormModel = dynamic_cast<FmFormModel*>(&getSdrModelFromSdrObject());
    const FmFormModel* pFormModel = dynamic_cast<FmFormModel*>( GetModel()  );
    if ( !pFormModel || !pFormModel->ControlsUseRefDevice() )
        return;

@@ -358,9 +357,9 @@ void FmFormObj::clonedFrom(const FmFormObj* _pSource)
}


FmFormObj* FmFormObj::Clone(SdrModel* pTargetModel) const
FmFormObj* FmFormObj::Clone() const
{
    FmFormObj* pFormObject = CloneHelper< FmFormObj >(pTargetModel);
    FmFormObj* pFormObject = CloneHelper< FmFormObj >();
    DBG_ASSERT(pFormObject != nullptr, "FmFormObj::Clone : invalid clone !");
    if (pFormObject)
        pFormObject->clonedFrom(this);
@@ -369,6 +368,13 @@ FmFormObj* FmFormObj::Clone(SdrModel* pTargetModel) const
}


void FmFormObj::NbcReformatText()
{
    impl_checkRefDevice_nothrow();
    SdrUnoObj::NbcReformatText();
}


FmFormObj& FmFormObj::operator= (const FmFormObj& rObj)
{
    if( this == &rObj )
@@ -395,13 +401,6 @@ FmFormObj& FmFormObj::operator= (const FmFormObj& rObj)
}


void FmFormObj::NbcReformatText()
{
    impl_checkRefDevice_nothrow();
    SdrUnoObj::NbcReformatText();
}


namespace
{
    OUString lcl_getFormComponentAccessPath(const Reference< XInterface >& _xElement, Reference< XInterface >& _rTopLevelElement)
@@ -585,6 +584,14 @@ Reference< XInterface >  FmFormObj::ensureModelEnv(const Reference< XInterface >
    return Reference<XInterface>( xDestContainer, UNO_QUERY );
}


void FmFormObj::SetModel( SdrModel* _pNewModel )
{
    SdrUnoObj::SetModel( _pNewModel );
    impl_checkRefDevice_nothrow();
}


FmFormObj* FmFormObj::GetFormObject( SdrObject* _pSdrObject )
{
    FmFormObj* pFormObject = dynamic_cast< FmFormObj* >( _pSdrObject );
diff --git a/svx/source/form/fmobjfac.cxx b/svx/source/form/fmobjfac.cxx
index a640caa..bfc834e 100644
--- a/svx/source/form/fmobjfac.cxx
+++ b/svx/source/form/fmobjfac.cxx
@@ -106,10 +106,10 @@ namespace
    }
}

IMPL_STATIC_LINK(FmFormObjFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject*)
IMPL_STATIC_LINK(
    FmFormObjFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject*)
{
    SdrObject* pNewObj = nullptr;

    if (aParams.nInventor == SdrInventor::FmForm)
    {
        OUString sServiceSpecifier;
@@ -213,9 +213,9 @@ IMPL_STATIC_LINK(FmFormObjFactory, MakeObject, SdrObjCreatorParams, aParams, Sdr

        // create the actual object
        if ( !sServiceSpecifier.isEmpty() )
            pNewObj = new FmFormObj(aParams.rSdrModel, sServiceSpecifier);
            pNewObj = new FmFormObj(sServiceSpecifier);
        else
            pNewObj = new FmFormObj(aParams.rSdrModel);
            pNewObj = new FmFormObj();

        // initialize some properties which we want to differ from the defaults
        for (   PropertyValueArray::const_iterator aInitProp = aInitialProperties.begin();
diff --git a/svx/source/form/fmpage.cxx b/svx/source/form/fmpage.cxx
index ca79aba..7f267cb 100644
--- a/svx/source/form/fmpage.cxx
+++ b/svx/source/form/fmpage.cxx
@@ -49,17 +49,22 @@ using com::sun::star::uno::UNO_QUERY;


FmFormPage::FmFormPage(FmFormModel& rModel, bool bMasterPage)
:   SdrPage(rModel, bMasterPage)
    ,m_pImpl( new FmFormPageImpl( *this ) )
           :SdrPage(rModel, bMasterPage)
           ,m_pImpl( new FmFormPageImpl( *this ) )
{
}

void FmFormPage::lateInit(const FmFormPage& rPage)
{
    // call parent
    SdrPage::lateInit( rPage );

    // copy local variables (former stuff from copy constructor)
FmFormPage::FmFormPage(const FmFormPage& rPage)
           :SdrPage(rPage)
           ,m_pImpl(new FmFormPageImpl( *this ) )
{
}

void FmFormPage::lateInit(const FmFormPage& rPage, FmFormModel* const pNewModel)
{
    SdrPage::lateInit( rPage, pNewModel );

    m_pImpl->initFrom( rPage.GetImpl() );
    m_sPageName = rPage.m_sPageName;
}
@@ -69,22 +74,65 @@ FmFormPage::~FmFormPage()
{
}

SdrPage* FmFormPage::Clone(SdrModel* pNewModel) const

void FmFormPage::SetModel(SdrModel* pNewModel)
{
    FmFormModel& rFmFormModel(static_cast< FmFormModel& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    FmFormPage* pClonedFmFormPage(
        new FmFormPage(
            rFmFormModel,
            IsMasterPage()));
    pClonedFmFormPage->lateInit(*this);
    return pClonedFmFormPage;
    /* #35055# */
    // we want to call the super's "SetModel" method even if the model is the
    // same, in case code somewhere in the system depends on it.  But our code
    // doesn't, so get the old model to do a check.
    SdrModel *pOldModel = GetModel();

    SdrPage::SetModel( pNewModel );

    /* #35055# */
    if ( ( pOldModel != pNewModel ) && m_pImpl )
    {
        try
        {
            Reference< css::form::XForms > xForms( m_pImpl->getForms( false ) );
            if ( xForms.is() )
            {
                // we want to keep the current collection, just reset the model
                // with which it's associated.
                FmFormModel* pDrawModel = static_cast<FmFormModel*>( GetModel() );
                SfxObjectShell* pObjShell = pDrawModel->GetObjectShell();
                if ( pObjShell )
                    xForms->setParent( pObjShell->GetModel() );
            }
        }
        catch( css::uno::Exception const& )
        {
            OSL_FAIL( "UNO Exception caught resetting model for m_pImpl (FmFormPageImpl) in FmFormPage::SetModel" );
        }
    }
}


SdrPage* FmFormPage::Clone() const
{
    return Clone(nullptr);
}

SdrPage* FmFormPage::Clone(SdrModel* const pNewModel) const
{
    FmFormPage* const pNewPage = new FmFormPage(*this);
    FmFormModel* pFormModel = nullptr;
    if (pNewModel)
    {
        pFormModel = dynamic_cast<FmFormModel*>(pNewModel);
        assert(pFormModel);
    }
    pNewPage->lateInit(*this, pFormModel);
    return pNewPage;
}


void FmFormPage::InsertObject(SdrObject* pObj, size_t nPos)
{
    SdrPage::InsertObject( pObj, nPos );
    static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Inserted(pObj);
    if (GetModel())
        static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Inserted(pObj);
}


@@ -169,8 +217,8 @@ bool FmFormPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView,
SdrObject* FmFormPage::RemoveObject(size_t nObjNum)
{
    SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
    if (pObj)
        static_cast< FmFormModel& >(getSdrModelFromSdrPage()).GetUndoEnv().Removed(pObj);
    if (pObj && GetModel())
        static_cast<FmFormModel*>(GetModel())->GetUndoEnv().Removed(pObj);
    return pObj;
}

diff --git a/svx/source/form/fmpgeimp.cxx b/svx/source/form/fmpgeimp.cxx
index 417f84a..3d974c0 100644
--- a/svx/source/form/fmpgeimp.cxx
+++ b/svx/source/form/fmpgeimp.cxx
@@ -315,15 +315,16 @@ const Reference< css::form::XForms >& FmFormPageImpl::getForms( bool _bForceCrea
            m_aFormsCreationHdl.Call( *this );
        }

        FmFormModel& rFmFormModel(dynamic_cast< FmFormModel& >(m_rPage.getSdrModelFromSdrPage()));
        FmFormModel* pFormsModel = dynamic_cast<FmFormModel*>( m_rPage.GetModel()  );

        // give the newly created collection a place in the universe
        SfxObjectShell* pObjShell(rFmFormModel.GetObjectShell());
        SfxObjectShell* pObjShell = pFormsModel ? pFormsModel->GetObjectShell() : nullptr;
        if ( pObjShell )
            m_xForms->setParent( pObjShell->GetModel() );

        // tell the UNDO environment that we have a new forms collection
        rFmFormModel.GetUndoEnv().AddForms( Reference<XNameContainer>(m_xForms,UNO_QUERY_THROW) );
        if ( pFormsModel )
            pFormsModel->GetUndoEnv().AddForms( Reference<XNameContainer>(m_xForms,UNO_QUERY_THROW) );
    }
    return m_xForms;
}
@@ -395,13 +396,13 @@ Reference< XForm >  FmFormPageImpl::getDefaultForm()
    // did not find an existing suitable form -> create a new one
    if ( !xForm.is() )
    {
        SdrModel& rModel(m_rPage.getSdrModelFromSdrPage());
        SdrModel* pModel = m_rPage.GetModel();

        if( rModel.IsUndoEnabled() )
        if( pModel->IsUndoEnabled() )
        {
            OUString aStr(SvxResId(RID_STR_FORM));
            OUString aUndoStr(SvxResId(RID_STR_UNDO_CONTAINER_INSERT));
            rModel.BegUndo(aUndoStr.replaceFirst("'#'", aStr));
            pModel->BegUndo(aUndoStr.replaceFirst("'#'", aStr));
        }

        try
@@ -416,15 +417,13 @@ Reference< XForm >  FmFormPageImpl::getDefaultForm()
            OUString sName = SvxResId(RID_STR_STDFORMNAME);
            xFormProps->setPropertyValue( FM_PROP_NAME, makeAny( sName ) );

            if( rModel.IsUndoEnabled() )
            if( pModel->IsUndoEnabled() )
            {
                rModel.AddUndo(
                    new FmUndoContainerAction(
                        static_cast< FmFormModel& >(rModel),
                        FmUndoContainerAction::Inserted,
                        xForms,
                        xForm,
                        xForms->getCount()));
                pModel->AddUndo(new FmUndoContainerAction(*static_cast<FmFormModel*>(pModel),
                                                           FmUndoContainerAction::Inserted,
                                                           xForms,
                                                           xForm,
                                                           xForms->getCount()));
            }
            xForms->insertByName( sName, makeAny( xForm ) );
            xCurrentForm = xForm;
@@ -435,8 +434,8 @@ Reference< XForm >  FmFormPageImpl::getDefaultForm()
            xForm.clear();
        }

        if( rModel.IsUndoEnabled() )
            rModel.EndUndo();
        if( pModel->IsUndoEnabled() )
            pModel->EndUndo();
    }

    return xForm;
@@ -475,15 +474,16 @@ Reference< css::form::XForm >  FmFormPageImpl::findPlaceInFormComponentHierarchy
        // If no css::form found, then create a new one
        if (!xForm.is())
        {
            SdrModel& rModel(m_rPage.getSdrModelFromSdrPage());
            const bool bUndo(rModel.IsUndoEnabled());
            SdrModel* pModel = m_rPage.GetModel();

            const bool bUndo = pModel->IsUndoEnabled();

            if( bUndo )
            {
                OUString aStr(SvxResId(RID_STR_FORM));
                OUString aUndoStr(SvxResId(RID_STR_UNDO_CONTAINER_INSERT));
                aUndoStr = aUndoStr.replaceFirst("#", aStr);
                rModel.BegUndo(aUndoStr);
                pModel->BegUndo(aUndoStr);
            }

            xForm.set(::comphelper::getProcessServiceFactory()->createInstance(FM_SUN_COMPONENT_FORM), UNO_QUERY);
@@ -515,19 +515,17 @@ Reference< css::form::XForm >  FmFormPageImpl::findPlaceInFormComponentHierarchy
            if( bUndo )
            {
                Reference< css::container::XIndexContainer >  xContainer( getForms(), UNO_QUERY );
                rModel.AddUndo(
                    new FmUndoContainerAction(
                        static_cast< FmFormModel& >(rModel),
                        FmUndoContainerAction::Inserted,
                        xContainer,
                        xForm,
                        xContainer->getCount()));
                pModel->AddUndo(new FmUndoContainerAction(*static_cast<FmFormModel*>(pModel),
                                                         FmUndoContainerAction::Inserted,
                                                         xContainer,
                                                         xForm,
                                                         xContainer->getCount()));
            }

            getForms()->insertByName( sName, makeAny( xForm ) );

            if( bUndo )
                rModel.EndUndo();
                pModel->EndUndo();
        }
        xCurrentForm = xForm;
    }
diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx
index 560b2fa..a21e904 100644
--- a/svx/source/form/fmshimp.cxx
+++ b/svx/source/form/fmshimp.cxx
@@ -3845,8 +3845,10 @@ void FmXFormShell::loadForms_Lock(FmFormPage* _pPage, const LoadFormsFlags _nBeh
    {
        // lock the undo env so the forms can change non-transient properties while loading
        // (without this my doc's modified flag would be set)
        FmFormModel& rFmFormModel(dynamic_cast< FmFormModel& >(_pPage->getSdrModelFromSdrPage()));
        rFmFormModel.GetUndoEnv().Lock();
        FmFormModel* pModel = dynamic_cast<FmFormModel*>( _pPage->GetModel()  );
        DBG_ASSERT( pModel, "FmXFormShell::loadForms: invalid model!" );
        if ( pModel )
            pModel->GetUndoEnv().Lock();

        // load all forms
        Reference< XIndexAccess >  xForms;
@@ -3892,8 +3894,9 @@ void FmXFormShell::loadForms_Lock(FmFormPage* _pPage, const LoadFormsFlags _nBeh
            }
        }

        // unlock the environment
        rFmFormModel.GetUndoEnv().UnLock();
        if ( pModel )
            // unlock the environment
            pModel->GetUndoEnv().UnLock();
    }
}

diff --git a/svx/source/form/fmview.cxx b/svx/source/form/fmview.cxx
index 6acd8b8..2adad0d 100644
--- a/svx/source/form/fmview.cxx
+++ b/svx/source/form/fmview.cxx
@@ -77,14 +77,14 @@ using namespace ::com::sun::star::util;
using namespace ::svxform;
using namespace ::svx;

FmFormView::FmFormView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   E3dView(rSdrModel, pOut)

FmFormView::FmFormView( FmFormModel* pModel, OutputDevice* pOut )
    :E3dView(pModel,pOut)
{
    Init();
}


void FmFormView::Init()
{
    pFormShell = nullptr;
diff --git a/svx/source/form/fmvwimp.cxx b/svx/source/form/fmvwimp.cxx
index 30dd8ad..cbf975f 100644
--- a/svx/source/form/fmvwimp.cxx
+++ b/svx/source/form/fmvwimp.cxx
@@ -1350,7 +1350,7 @@ SdrObject* FmXFormView::implCreateFieldControl( const svx::ODataAccessDescriptor
        if ( bCheckbox )
            return pControl;

        SdrObjGroup* pGroup  = new SdrObjGroup(getView()->getSdrModelFromSdrView());
        SdrObjGroup* pGroup  = new SdrObjGroup();
        SdrObjList* pObjList = pGroup->GetSubList();
        pObjList->InsertObject( pLabel );
        pObjList->InsertObject( pControl );
@@ -1462,7 +1462,7 @@ SdrObject* FmXFormView::implCreateXFormsControl( const svx::OXFormsDescriptor &_


            // group objects
            SdrObjGroup* pGroup  = new SdrObjGroup(getView()->getSdrModelFromSdrView());
            SdrObjGroup* pGroup  = new SdrObjGroup();
            SdrObjList* pObjList = pGroup->GetSubList();
            pObjList->InsertObject(pLabel);
            pObjList->InsertObject(pControl);
@@ -1476,11 +1476,7 @@ SdrObject* FmXFormView::implCreateXFormsControl( const svx::OXFormsDescriptor &_
            const MapMode eSourceMode(MapUnit::Map100thMM);
            const sal_uInt16 nObjID = OBJ_FM_BUTTON;
            ::Size controlSize(4000, 500);
            FmFormObj *pControl = static_cast<FmFormObj*>(
                SdrObjFactory::MakeNewObject(
                    getView()->getSdrModelFromSdrView(),
                    SdrInventor::FmForm,
                    nObjID));
            FmFormObj *pControl = static_cast<FmFormObj*>(SdrObjFactory::MakeNewObject( SdrInventor::FmForm, nObjID, nullptr ));
            controlSize.setWidth( long(controlSize.Width() * eTargetMode.GetScaleX()) );
            controlSize.setHeight( long(controlSize.Height() * eTargetMode.GetScaleY()) );
            ::Point controlPos( OutputDevice::LogicToLogic( ::Point( controlSize.Width(), 0 ), eSourceMode, eTargetMode ) );
@@ -1580,18 +1576,11 @@ bool FmXFormView::createControlLabelPair( OutputDevice const & _rOutDev, sal_Int
    // the label
    ::std::unique_ptr< SdrUnoObj > pLabel;
    Reference< XPropertySet > xLabelModel;

    if ( bNeedLabel )
    {
        pLabel.reset( dynamic_cast< SdrUnoObj* >(
            SdrObjFactory::MakeNewObject(
                *_pModel,
                _nInventor,
                _nLabelObjectID,
                _pLabelPage)));

            SdrObjFactory::MakeNewObject( _nInventor, _nLabelObjectID, _pLabelPage, _pModel ) ) );
        OSL_ENSURE( pLabel.get(), "FmXFormView::createControlLabelPair: could not create the label!" );

        if ( !pLabel.get() )
            return false;

@@ -1617,14 +1606,8 @@ bool FmXFormView::createControlLabelPair( OutputDevice const & _rOutDev, sal_Int

    // the control
    ::std::unique_ptr< SdrUnoObj > pControl( dynamic_cast< SdrUnoObj* >(
        SdrObjFactory::MakeNewObject(
            *_pModel,
             _nInventor,
             _nControlObjectID,
             _pControlPage)));

        SdrObjFactory::MakeNewObject( _nInventor, _nControlObjectID, _pControlPage, _pModel ) ) );
    OSL_ENSURE( pControl.get(), "FmXFormView::createControlLabelPair: could not create the control!" );

    if ( !pControl.get() )
        return false;

diff --git a/svx/source/gallery2/galobj.cxx b/svx/source/gallery2/galobj.cxx
index a91fabd..d9e6a20 100644
--- a/svx/source/gallery2/galobj.cxx
+++ b/svx/source/gallery2/galobj.cxx
@@ -458,7 +458,7 @@ bool SgaObjectSvDraw::CreateThumb( const FmFormModel& rModel )
            if(aObjRect.GetWidth() && aObjRect.GetHeight())
            {
                ScopedVclPtrInstance< VirtualDevice > pVDev;
                FmFormView aView(const_cast< FmFormModel& >(rModel), pVDev);
                FmFormView aView(const_cast< FmFormModel* >(&rModel), pVDev);

                aView.ShowSdrPage(const_cast< FmFormPage* >(pPage));
                aView.MarkAllObj();
diff --git a/svx/source/gallery2/galtheme.cxx b/svx/source/gallery2/galtheme.cxx
index 9c8b27b..de21ba0 100644
--- a/svx/source/gallery2/galtheme.cxx
+++ b/svx/source/gallery2/galtheme.cxx
@@ -801,7 +801,7 @@ bool GalleryTheme::GetGraphic(sal_uInt32 nPos, Graphic& rGraphic)
                        {
                            ScopedVclPtrInstance< VirtualDevice > pVDev;
                            pVDev->SetMapMode( MapMode( MapUnit::Map100thMM ) );
                            FmFormView aView(*aModel.GetModel(), pVDev);
                            FmFormView aView( aModel.GetModel(), pVDev );

                            aView.hideMarkHandles();
                            aView.ShowSdrPage(aView.GetModel()->GetPage(0));
@@ -1244,7 +1244,7 @@ bool GalleryTheme::InsertTransferable(const uno::Reference< datatransfer::XTrans
                    if( aModel.GetModel() )
                    {
                        SdrPage*    pPage = aModel.GetModel()->GetPage(0);
                        SdrGrafObj* pGrafObj = new SdrGrafObj(*aModel.GetModel(), *pGraphic );
                        SdrGrafObj* pGrafObj = new SdrGrafObj( *pGraphic );

                        pGrafObj->AppendUserData( new SgaIMapInfo( aImageMap ) );
                        pPage->InsertObject( pGrafObj );
diff --git a/svx/source/inc/cell.hxx b/svx/source/inc/cell.hxx
index 86c7579..5b7f71b0 100644
--- a/svx/source/inc/cell.hxx
+++ b/svx/source/inc/cell.hxx
@@ -91,6 +91,8 @@ public:
    SVX_DLLPRIVATE SdrTextVertAdjust GetTextVerticalAdjust() const;
    SdrTextHorzAdjust GetTextHorizontalAdjust() const;

    SVX_DLLPRIVATE virtual void SetModel(SdrModel* pNewModel) override;

    SVX_DLLPRIVATE void merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan );
    SVX_DLLPRIVATE void mergeContent( const CellRef& xSourceCell );
    SVX_DLLPRIVATE void replaceContentAndFormating( const CellRef& xSourceCell );
diff --git a/svx/source/inc/fmobj.hxx b/svx/source/inc/fmobj.hxx
index da9f7c6..6b9adf6 100644
--- a/svx/source/inc/fmobj.hxx
+++ b/svx/source/inc/fmobj.hxx
@@ -27,7 +27,7 @@

// FmFormObj

class SVX_DLLPUBLIC FmFormObj : public SdrUnoObj
class SVX_DLLPUBLIC FmFormObj: public SdrUnoObj
{
    FmFormObj( const FmFormObj& ) = delete;

@@ -47,10 +47,9 @@ class SVX_DLLPUBLIC FmFormObj : public SdrUnoObj
                            // only to be used for comparison with the current ref device!

public:
    FmFormObj(
        SdrModel& rSdrModel,
        const OUString& rModelName);
    FmFormObj(SdrModel& rSdrModel);
    FmFormObj(const OUString& rModelName);
    FmFormObj();


    SAL_DLLPRIVATE const css::uno::Reference< css::container::XIndexContainer>&
        GetOriginalParent() const { return m_xParent; }
@@ -73,10 +72,12 @@ public:
    SAL_DLLPRIVATE virtual sal_uInt16 GetObjIdentifier() const override;
    SAL_DLLPRIVATE virtual void NbcReformatText() override;

    SAL_DLLPRIVATE virtual FmFormObj* Clone(SdrModel* pTargetModel = nullptr) const override;
    SAL_DLLPRIVATE virtual FmFormObj* Clone() const override;
    // #116235# virtual SdrObject*  Clone(SdrPage* pPage, SdrModel* pModel) const;
    SAL_DLLPRIVATE FmFormObj& operator= (const FmFormObj& rObj);

    SAL_DLLPRIVATE virtual void SetModel(SdrModel* pNewModel) override;

    SAL_DLLPRIVATE void clonedFrom(const FmFormObj* _pSource);

    SAL_DLLPRIVATE static css::uno::Reference< css::uno::XInterface> ensureModelEnv(
diff --git a/svx/source/inc/tablemodel.hxx b/svx/source/inc/tablemodel.hxx
index 791a431..e59626d 100644
--- a/svx/source/inc/tablemodel.hxx
+++ b/svx/source/inc/tablemodel.hxx
@@ -176,7 +176,7 @@ private:
    rtl::Reference< TableColumns > mxTableColumns;
    rtl::Reference< TableRows >    mxTableRows;

    SdrTableObj* mpTableObj; // TTTT should be reference
    SdrTableObj* mpTableObj;

    bool mbModified;
    bool mbNotifyPending;
diff --git a/svx/source/sdr/contact/viewcontactofgraphic.cxx b/svx/source/sdr/contact/viewcontactofgraphic.cxx
index 3c0622b..b7c3086 100644
--- a/svx/source/sdr/contact/viewcontactofgraphic.cxx
+++ b/svx/source/sdr/contact/viewcontactofgraphic.cxx
@@ -241,7 +241,7 @@ namespace sdr
                aDraftText += " ...";
            }

            if (!aDraftText.isEmpty())
            if (!aDraftText.isEmpty() && GetGrafObject().GetModel())
            {
                // #i103255# Goal is to produce TextPrimitives which hold the given text as
                // BlockText in the available space. It would be very tricky to do
@@ -253,7 +253,8 @@ namespace sdr
                // needed and can be deleted.

                // create temp RectObj as TextObj and set needed attributes
                SdrRectObj aRectObj(GetGrafObject().getSdrModelFromSdrObject(), OBJ_TEXT);
                SdrRectObj aRectObj(OBJ_TEXT);
                aRectObj.SetModel(GetGrafObject().GetModel());
                aRectObj.NbcSetText(aDraftText);
                aRectObj.SetMergedItem(SvxColorItem(COL_LIGHTRED, EE_CHAR_COLOR));

diff --git a/svx/source/sdr/contact/viewcontactofsdrrectobj.cxx b/svx/source/sdr/contact/viewcontactofsdrrectobj.cxx
index f02ba91..c0ab639 100644
--- a/svx/source/sdr/contact/viewcontactofsdrrectobj.cxx
+++ b/svx/source/sdr/contact/viewcontactofsdrrectobj.cxx
@@ -72,7 +72,8 @@ drawinglayer::primitive2d::Primitive2DContainer ViewContactOfSdrRectObj::createV
    drawinglayer::primitive2d::calculateRelativeCornerRadius(nCornerRadius, aObjectRange, fCornerRadiusX, fCornerRadiusY);

    // #i105856# use knowledge about pickthrough from the model
    const bool bPickThroughTransparentTextFrames(GetRectObj().getSdrModelFromSdrObject().IsPickThroughTransparentTextFrames());
    const bool bPickThroughTransparentTextFrames(
        GetRectObj().GetModel() && GetRectObj().GetModel()->IsPickThroughTransparentTextFrames());

    // create primitive. Always create primitives to allow the decomposition of
    // SdrRectanglePrimitive2D to create needed invisible elements for HitTest and/or BoundRect
diff --git a/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx b/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx
index f6e425f..95ed93a 100644
--- a/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx
+++ b/svx/source/sdr/contact/viewobjectcontactofgraphic.cxx
@@ -242,7 +242,7 @@ namespace sdr
        {
            // prepare primitive generation with evtl. loading the graphic when it's swapped out
            SdrGrafObj& rGrafObj = const_cast< ViewObjectContactOfGraphic* >(this)->getSdrGrafObj();
            bool bDoAsynchronGraphicLoading(rGrafObj.getSdrModelFromSdrObject().IsSwapGraphics());
            bool bDoAsynchronGraphicLoading(rGrafObj.GetModel() && rGrafObj.GetModel()->IsSwapGraphics());

            if( bDoAsynchronGraphicLoading && rGrafObj.IsSwappedOut() )
            {
diff --git a/svx/source/sdr/primitive2d/sdrattributecreator.cxx b/svx/source/sdr/primitive2d/sdrattributecreator.cxx
index 4529717..60e130c8 100644
--- a/svx/source/sdr/primitive2d/sdrattributecreator.cxx
+++ b/svx/source/sdr/primitive2d/sdrattributecreator.cxx
@@ -527,7 +527,7 @@ namespace drawinglayer
            bool bChainable = rTextObj.IsChainable();


            if(rText.GetOutlinerParaObject())
            if(rText.GetOutlinerParaObject() && rText.GetModel())
            {
                // added TextEdit text suppression
                bool bInEditMode(false);
@@ -564,7 +564,7 @@ namespace drawinglayer
                const SdrTextAniKind eAniKind(rTextObj.GetTextAniKind());

                // #i107346#
                const SdrOutliner& rDrawTextOutliner(rText.GetObject().getSdrModelFromSdrObject().GetDrawOutliner(&rTextObj));
                const SdrOutliner& rDrawTextOutliner = rText.GetModel()->GetDrawOutliner(&rTextObj);
                const bool bWrongSpell(rDrawTextOutliner.GetControlWord() & EEControlBits::ONLINESPELLING);

                return attribute::SdrTextAttribute(
diff --git a/svx/source/sdr/primitive2d/sdrtextprimitive2d.cxx b/svx/source/sdr/primitive2d/sdrtextprimitive2d.cxx
index e3d7aba..0cdd5d0 100644
--- a/svx/source/sdr/primitive2d/sdrtextprimitive2d.cxx
+++ b/svx/source/sdr/primitive2d/sdrtextprimitive2d.cxx
@@ -64,16 +64,16 @@ namespace
        sal_Int16 nRetval(0);
        SdrPage* pPage = GetSdrPageFromXDrawPage(rxDrawPage);

        if(pPage)
        if(pPage && pPage->GetModel())
        {
            if( (pPage->GetPageNum() == 0) && !pPage->IsMasterPage() )
            {
                // handout page!
                return pPage->getSdrModelFromSdrPage().getHandoutPageCount();
                return pPage->GetModel()->getHandoutPageCount();
            }
            else
            {
                const sal_uInt16 nPageCount(pPage->getSdrModelFromSdrPage().GetPageCount());
                const sal_uInt16 nPageCount(pPage->GetModel()->GetPageCount());
                nRetval = (static_cast<sal_Int16>(nPageCount) - 1) / 2;
            }
        }
@@ -188,9 +188,9 @@ namespace drawinglayer
                }

                // #i101443#  check change of TextBackgroundolor
                if(!bDoDelete && getSdrText())
                if(!bDoDelete && getSdrText() && getSdrText()->GetModel())
                {
                    SdrOutliner& rDrawOutliner = getSdrText()->GetObject().getSdrModelFromSdrObject().GetDrawOutliner();
                    SdrOutliner& rDrawOutliner = getSdrText()->GetModel()->GetDrawOutliner();
                    aNewTextBackgroundColor = rDrawOutliner.GetBackgroundColor();
                    bNewTextBackgroundColorIsSet = true;

@@ -223,9 +223,9 @@ namespace drawinglayer
                    nCurrentlyValidPageCount = getPageCount(xCurrentlyVisualizingPage);
                }

                if(!bNewTextBackgroundColorIsSet && getSdrText())
                if(!bNewTextBackgroundColorIsSet && getSdrText() && getSdrText()->GetModel())
                {
                    SdrOutliner& rDrawOutliner = getSdrText()->GetObject().getSdrModelFromSdrObject().GetDrawOutliner();
                    SdrOutliner& rDrawOutliner = getSdrText()->GetModel()->GetDrawOutliner();
                    aNewTextBackgroundColor = rDrawOutliner.GetBackgroundColor();
                }

diff --git a/svx/source/sdr/properties/attributeproperties.cxx b/svx/source/sdr/properties/attributeproperties.cxx
index d14b7ff..b4038ea 100644
--- a/svx/source/sdr/properties/attributeproperties.cxx
+++ b/svx/source/sdr/properties/attributeproperties.cxx
@@ -44,40 +44,33 @@
#include <svx/svdmodel.hxx>
#include <svx/svdtrans.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdograf.hxx>
#include <svx/svdoole2.hxx>


namespace sdr
{
    namespace properties
    {
        SfxStyleSheet* AttributeProperties::ImpGetDefaultStyleSheet() const
        void AttributeProperties::ImpAddStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
        {
            // use correct default stylesheet #119287#
            const SdrGrafObj* pIsSdrGrafObj(dynamic_cast< const SdrGrafObj* >(&GetSdrObject()));
            const SdrOle2Obj* pIsSdrOle2Obj(dynamic_cast< const SdrOle2Obj* >(&GetSdrObject()));
            SfxStyleSheet* pRetval(nullptr);
            // test if old StyleSheet is cleared, else it would be lost
            // after this method -> memory leak (!)
            DBG_ASSERT(!mpStyleSheet, "Old style sheet not deleted before setting new one (!)");

            if(pIsSdrGrafObj || pIsSdrOle2Obj)
            if(pNewStyleSheet)
            {
                pRetval = GetSdrObject().getSdrModelFromSdrObject().GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
            }
            else
            {
                pRetval = GetSdrObject().getSdrModelFromSdrObject().GetDefaultStyleSheet();
            }
                mpStyleSheet = pNewStyleSheet;

            return pRetval;
        }
                // local ItemSet is needed here, force it
                GetObjectItemSet();

        void AttributeProperties::ImpSetParentAtSfxItemSet(bool bDontRemoveHardAttr)
        {
            if(HasSfxItemSet() && mpStyleSheet)
            {
                // register as listener
                StartListening(pNewStyleSheet->GetPool());
                StartListening(*pNewStyleSheet);

                // Delete hard attributes where items are set in the style sheet
                if(!bDontRemoveHardAttr)
                {
                    const SfxItemSet& rStyle = mpStyleSheet->GetItemSet();
                    const SfxItemSet& rStyle = pNewStyleSheet->GetItemSet();
                    SfxWhichIter aIter(rStyle);
                    sal_uInt16 nWhich = aIter.FirstWhich();

@@ -93,37 +86,7 @@ namespace sdr
                }

                // set new stylesheet as parent
                mpItemSet->SetParent(&mpStyleSheet->GetItemSet());
            }
            else
            {
                OSL_ENSURE(false, "ImpSetParentAtSfxItemSet called without SfxItemSet/SfxStyleSheet (!)");
            }
        }

        void AttributeProperties::ImpAddStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
        {
            // test if old StyleSheet is cleared, else it would be lost
            // after this method -> memory leak (!)
            DBG_ASSERT(!mpStyleSheet, "Old style sheet not deleted before setting new one (!)");

            if(pNewStyleSheet)
            {
                // local remember
                mpStyleSheet = pNewStyleSheet;

                if(HasSfxItemSet())
                {
                    // register as listener
                    StartListening(pNewStyleSheet->GetPool());
                    StartListening(*pNewStyleSheet);

                    // only apply the following when we have an SfxItemSet already, else
                    if(GetStyleSheet())
                    {
                        ImpSetParentAtSfxItemSet(bDontRemoveHardAttr);
                    }
                }
                mpItemSet->SetParent(&pNewStyleSheet->GetItemSet());
            }
        }

@@ -136,7 +99,7 @@ namespace sdr
                EndListening(mpStyleSheet->GetPool());

                // reset parent of ItemSet
                if(HasSfxItemSet())
                if(mpItemSet)
                {
                    mpItemSet->SetParent(nullptr);
                }
@@ -164,59 +127,15 @@ namespace sdr
        :   DefaultProperties(rObj),
            mpStyleSheet(nullptr)
        {
            // Do nothing else, esp. do *not* try to get and set
            // a default SfxStyle sheet. Nothing is allowed to be done
            // that may lead to calls to virtual functions like
            // CreateObjectSpecificItemSet - these would go *wrong*.
            // Thus the rest is lazy-init from here.
        }

        AttributeProperties::AttributeProperties(const AttributeProperties& rProps, SdrObject& rObj)
        :   DefaultProperties(rProps, rObj),
            mpStyleSheet(nullptr)
        {
            SfxStyleSheet* pTargetStyleSheet(rProps.GetStyleSheet());

            if(pTargetStyleSheet && &rObj.getSdrModelFromSdrObject() != &GetSdrObject().getSdrModelFromSdrObject())
            if(rProps.GetStyleSheet())
            {
                // TTTT It is a clone to another model, thus the TargetStyleSheet
                // is probably also from another SdrModel, so do *not* simply use it.
                //
                // The DefaultProperties::Clone already has cloned the ::SET items
                // to a new SfxItemSet in the new SfxItemPool. There are quite some
                // possibilities to continue:
                // - Do not use StyleSheet (will do this for now)
                // - Search for same StyleSheet in Target-SdrModel and use if found
                //   (use e.g. Name)
                // - Clone used StyleSheet(s) to Target-SdrModel and use
                // - Set all Attributes from the StyleSheet as hard attributes at the
                //   SfxItemSet
                // The original AW080 uses 'ImpModelChange' (see there) which Clones
                // and uses the used StyleSheets if there is a Target-SfxItemPool
                // and sets to hard attributes if not. This may be used later if needed,
                // but for now only a single UnitTest uses this Clone-scenario and works
                // well with not using the TargetStyleSheet. The logic Cloning
                // StyleSheets *should* - if needed - be on a higher level where it is
                // potentially better known what would be the correct thing to do.
                pTargetStyleSheet = nullptr;
            }

            if(pTargetStyleSheet)
            {
                if(HasSfxItemSet())
                {
                    // The SfxItemSet has been cloned and exists,
                    // we can directly set the SfxStyleSheet at it
                    ImpAddStyleSheet(pTargetStyleSheet, true);
                }
                else
                {
                    // No SfxItemSet exists yet (there is none in
                    // the source, so none was cloned). Remember the
                    // SfxStyleSheet to set it when the SfxItemSet
                    // got constructed on-demand
                    mpStyleSheet = pTargetStyleSheet;
                }
                ImpAddStyleSheet(rProps.GetStyleSheet(), true);
            }
        }

@@ -230,42 +149,6 @@ namespace sdr
            return *(new AttributeProperties(*this, rObj));
        }

        const SfxItemSet& AttributeProperties::GetObjectItemSet() const
        {
            // remember if we had a SfxItemSet already
            const bool bHadSfxItemSet(HasSfxItemSet());

            // call parent - this will then guarantee
            // SfxItemSet existance
            DefaultProperties::GetObjectItemSet();

            if(!bHadSfxItemSet)
            {
                if(GetStyleSheet())
                {
                    // Late-Init of setting parent to SfxStyleSheet after
                    // it's creation. See copy-constructor and how it remembers
                    // the SfxStyleSheet there.
                    // It is necessary to reset mpStyleSheet to nullptr to
                    // not trigger alarm insde ImpAddStyleSheet (!)
                    SfxStyleSheet* pNew(mpStyleSheet);
                    const_cast< AttributeProperties* >(this)->mpStyleSheet = nullptr;
                    const_cast< AttributeProperties* >(this)->ImpAddStyleSheet(
                        pNew,
                        true);
                }
                else
                {
                    // Set missing defaults and do not RemoveHardAttributes
                    const_cast< AttributeProperties* >(this)->ImpAddStyleSheet(
                        ImpGetDefaultStyleSheet(),
                        true);
                }
            }

            return *mpItemSet;
        }

        void AttributeProperties::ItemSetChanged(const SfxItemSet& /*rSet*/)
        {
            // own modifications
@@ -281,72 +164,64 @@ namespace sdr
            if(pNewItem)
            {
                const SfxPoolItem* pResultItem = nullptr;
                SdrModel& rModel(GetSdrObject().getSdrModelFromSdrObject());
                SdrModel* pModel = GetSdrObject().GetModel();

                switch( nWhich )
                {
                    case XATTR_FILLBITMAP:
                    {
                        // TTTT checkForUniqueItem should use SdrModel&
                        pResultItem = static_cast<const XFillBitmapItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XFillBitmapItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                    case XATTR_LINEDASH:
                    {
                        pResultItem = static_cast<const XLineDashItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XLineDashItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                    case XATTR_LINESTART:
                    {
                        pResultItem = static_cast<const XLineStartItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XLineStartItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                    case XATTR_LINEEND:
                    {
                        pResultItem = static_cast<const XLineEndItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XLineEndItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                    case XATTR_FILLGRADIENT:
                    {
                        pResultItem = static_cast<const XFillGradientItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XFillGradientItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                    case XATTR_FILLFLOATTRANSPARENCE:
                    {
                        // #85953# allow all kinds of XFillFloatTransparenceItem to be set
                        pResultItem = static_cast<const XFillFloatTransparenceItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XFillFloatTransparenceItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                    case XATTR_FILLHATCH:
                    {
                        pResultItem = static_cast<const XFillHatchItem*>(pNewItem)->checkForUniqueItem( &rModel );
                        pResultItem = static_cast<const XFillHatchItem*>(pNewItem)->checkForUniqueItem( pModel );
                        break;
                    }
                }

                // set item
                if(!HasSfxItemSet())
                {
                    GetObjectItemSet();
                }

                GetObjectItemSet();
                if(pResultItem)
                {
                    // force ItemSet
                    mpItemSet->Put(*pResultItem);

                    // delete item if it was a generated one
                    delete pResultItem;
                }
                else
                {
                    mpItemSet->Put(*pNewItem);
                }
            }
            else
            {
                // clear item if ItemSet exists
                if(HasSfxItemSet())
                if(mpItemSet)
                {
                    mpItemSet->ClearItem(nWhich);
                }
@@ -355,12 +230,6 @@ namespace sdr

        void AttributeProperties::SetStyleSheet(SfxStyleSheet* pNewStyleSheet, bool bDontRemoveHardAttr)
        {
            // guarantee SfxItemSet existance here
            if(!HasSfxItemSet())
            {
                GetObjectItemSet();
            }

            ImpRemoveStyleSheet();
            ImpAddStyleSheet(pNewStyleSheet, bDontRemoveHardAttr);

@@ -374,18 +243,237 @@ namespace sdr
            return mpStyleSheet;
        }

        void AttributeProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
        {
            OSL_ASSERT(pNewModel!=nullptr);

            if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
            {
                if(mpItemSet)
                {
                    // migrate ItemSet to new pool. Scaling is NOT necessary
                    // because this functionality is used by UNDO only. Thus
                    // objects and ItemSets would be moved back to their original
                    // pool before usage.
                    SfxStyleSheet* pStySheet = GetStyleSheet();

                    if(pStySheet)
                    {
                        ImpRemoveStyleSheet();
                    }

                    auto pOldSet = std::move(mpItemSet);
                    mpItemSet.reset(pOldSet->Clone(false, pDestPool));
                    SdrModel::MigrateItemSet(pOldSet.get(), mpItemSet.get(), pNewModel);

                    // set stylesheet (if used)
                    if(pStySheet)
                    {
                        // #i109515#
                        SfxItemPool* pStyleSheetPool = &pStySheet->GetPool().GetPool();

                        if(pStyleSheetPool == pDestPool)
                        {
                            // just re-set stylesheet
                            ImpAddStyleSheet(pStySheet, true);
                        }
                        else
                        {
                            // StyleSheet is NOT from the correct pool.
                            // Look one up in the right pool with the same
                            // name or use the default.

                            // Look up the style in the new document.
                            OSL_ASSERT(pNewModel->GetStyleSheetPool() != nullptr);
                            SfxStyleSheet* pNewStyleSheet = dynamic_cast<SfxStyleSheet*>(
                                pNewModel->GetStyleSheetPool()->Find(
                                    pStySheet->GetName(),
                                    SfxStyleFamily::All));
                            if (pNewStyleSheet == nullptr
                                || &pNewStyleSheet->GetPool().GetPool() != pDestPool)
                            {
                                // There is no copy of the style in the new
                                // document.  Use the default as a fallback.
                                pNewStyleSheet = pNewModel->GetDefaultStyleSheet();
                            }
                            ImpAddStyleSheet(pNewStyleSheet, true);
                        }
                    }
                }
            }
        }

        void AttributeProperties::SetModel(SdrModel* pOldModel, SdrModel* pNewModel)
        {
            if(pOldModel != pNewModel && pNewModel)
            {
                // For a living model move the items from one pool to the other
                if(pOldModel)
                {
                    // If metric has changed, scale items.
                    MapUnit aOldUnit(pOldModel->GetScaleUnit());
                    MapUnit aNewUnit(pNewModel->GetScaleUnit());
                    bool bScaleUnitChanged(aNewUnit != aOldUnit);
                    Fraction aMetricFactor;

                    if(bScaleUnitChanged)
                    {
                        aMetricFactor = GetMapFactor(aOldUnit, aNewUnit).X();
                        Scale(aMetricFactor);
                    }

                    // Move all styles which are used by the object to the new
                    // StyleSheet pool
                    SfxStyleSheet* pOldStyleSheet = GetStyleSheet();

                    if(pOldStyleSheet)
                    {
                        SfxStyleSheetBase* pSheet = pOldStyleSheet;
                        SfxStyleSheetBasePool* pOldPool = pOldModel->GetStyleSheetPool();
                        SfxStyleSheetBasePool* pNewPool = pNewModel->GetStyleSheetPool();
                        DBG_ASSERT(pOldPool, "Properties::SetModel(): Object has StyleSheet but no StyleSheetPool (!)");

                        if(pOldPool && pNewPool)
                        {
                            // build a list of to-be-copied Styles
                            std::vector<SfxStyleSheetBase*> aStyleList;
                            SfxStyleSheetBase* pAnchor = nullptr;

                            while(pSheet)
                            {
                                pAnchor = pNewPool->Find(pSheet->GetName(), pSheet->GetFamily());

                                if(!pAnchor)
                                {
                                    aStyleList.push_back(pSheet);
                                    pSheet = pOldPool->Find(pSheet->GetParent(), pSheet->GetFamily());
                                }
                                else
                                {
                                    // the style does exist
                                    pSheet = nullptr;
                                }
                            }

                            // copy and set the parents
                            SfxStyleSheetBase* pNewSheet = nullptr;
                            SfxStyleSheetBase* pLastSheet = nullptr;
                            SfxStyleSheetBase* pForThisObject = nullptr;

                            for (std::vector<SfxStyleSheetBase*>::const_iterator iter = aStyleList.begin(), aEnd = aStyleList.end()
                                ; iter != aEnd; ++iter)
                            {
                                pNewSheet = &pNewPool->Make((*iter)->GetName(), (*iter)->GetFamily(), (*iter)->GetMask());
                                pNewSheet->GetItemSet().Put((*iter)->GetItemSet(), false);

                                if(bScaleUnitChanged)
                                {
                                    sdr::properties::ScaleItemSet(pNewSheet->GetItemSet(), aMetricFactor);
                                }

                                if(pLastSheet)
                                {
                                    pLastSheet->SetParent(pNewSheet->GetName());
                                }

                                if(!pForThisObject)
                                {
                                    pForThisObject = pNewSheet;
                                }

                                pLastSheet = pNewSheet;
                            }

                            // Set link to the Style found in the Pool
                            if(pAnchor && pLastSheet)
                            {
                                pLastSheet->SetParent(pAnchor->GetName());
                            }

                            // if list was empty (all Styles exist in destination pool)
                            // pForThisObject is not yet set
                            if(!pForThisObject && pAnchor)
                            {
                                pForThisObject = pAnchor;
                            }

                            // De-register at old and register at new Style
                            if(GetStyleSheet() != pForThisObject)
                            {
                                ImpRemoveStyleSheet();
                                ImpAddStyleSheet(static_cast<SfxStyleSheet*>(pForThisObject), true);
                            }
                        }
                        else
                        {
                            // there is no StyleSheetPool in the new model, thus set
                            // all items as hard items in the object
                            std::vector<const SfxItemSet*> aSetList;
                            const SfxItemSet* pItemSet = &pOldStyleSheet->GetItemSet();

                            while(pItemSet)
                            {
                                aSetList.push_back(pItemSet);
                                pItemSet = pItemSet->GetParent();
                            }

                            auto pNewSet = CreateObjectSpecificItemSet(pNewModel->GetItemPool());

                            std::vector<const SfxItemSet*>::reverse_iterator riter;
                            for (riter = aSetList.rbegin(); riter != aSetList.rend(); ++riter)
                                pNewSet->Put(*(*riter));

                            // Items which were hard attributes before need to stay
                            if(mpItemSet)
                            {
                                SfxWhichIter aIter(*mpItemSet);
                                sal_uInt16 nWhich = aIter.FirstWhich();

                                while(nWhich)
                                {
                                    if(mpItemSet->GetItemState(nWhich, false) == SfxItemState::SET)
                                    {
                                        pNewSet->Put(mpItemSet->Get(nWhich));
                                    }

                                    nWhich = aIter.NextWhich();
                                }
                            }

                            if(bScaleUnitChanged)
                            {
                                ScaleItemSet(*pNewSet, aMetricFactor);
                            }

                            if(mpItemSet)
                            {
                                if(GetStyleSheet())
                                {
                                    ImpRemoveStyleSheet();
                                }
                            }

                            mpItemSet = std::move(pNewSet);
                        }
                    }
                }

                // each object gets the default Style if there is none set yet.
                if(!GetStyleSheet() && pNewModel)
                {
                    GetObjectItemSet(); // #118414 force ItemSet to allow style to be set
                    SetStyleSheet(pNewModel->GetDefaultStyleSheet(), true);
                }
            }
        }

        void AttributeProperties::ForceStyleToHardAttributes()
        {
            if(!GetStyleSheet() || dynamic_cast<const SfxStyleSheet *>(mpStyleSheet) == nullptr)
                return;

            // force SfxItemSet existence
            if(!HasSfxItemSet())
            {
                GetObjectItemSet();
            }

            // prepare copied, new itemset, but WITHOUT parent
            GetObjectItemSet();
            SfxItemSet* pDestItemSet = new SfxItemSet(*mpItemSet);
            pDestItemSet->SetParent(nullptr);

@@ -451,22 +539,22 @@ namespace sdr
                    {
                        // Style needs to be exchanged
                        SfxStyleSheet* pNewStSh = nullptr;
                        SdrModel& rModel(rObj.getSdrModelFromSdrObject());
                        SdrModel* pModel = rObj.GetModel();

                        // Do nothing if object is in destruction, else a StyleSheet may be found from
                        // a StyleSheetPool which is just being deleted itself. and thus it would be fatal
                        // to register as listener to that new StyleSheet.
                        if(!rObj.IsInDestruction())
                        if(pModel && !rObj.IsInDestruction())
                        {
                            if(dynamic_cast<const SfxStyleSheet *>(GetStyleSheet()) != nullptr)
                            {
                                pNewStSh = static_cast<SfxStyleSheet*>(rModel.GetStyleSheetPool()->Find(
                                pNewStSh = static_cast<SfxStyleSheet*>(pModel->GetStyleSheetPool()->Find(
                                    GetStyleSheet()->GetParent(), GetStyleSheet()->GetFamily()));
                            }

                            if(!pNewStSh)
                            {
                                pNewStSh = rModel.GetDefaultStyleSheet();
                                pNewStSh = pModel->GetDefaultStyleSheet();
                            }
                        }

diff --git a/svx/source/sdr/properties/defaultproperties.cxx b/svx/source/sdr/properties/defaultproperties.cxx
index 56d23b6..167e368 100644
--- a/svx/source/sdr/properties/defaultproperties.cxx
+++ b/svx/source/sdr/properties/defaultproperties.cxx
@@ -25,14 +25,14 @@
#include <svl/itemset.hxx>
#include <svl/whiter.hxx>
#include <vcl/outdev.hxx>

#include <vector>
#include <svx/svdobj.hxx>
#include <svx/svddef.hxx>
#include <svx/svdpool.hxx>
#include <editeng/eeitem.hxx>
#include <libxml/xmlwriter.h>
#include <svx/svdmodel.hxx>
#include <svx/svdtrans.hxx>


namespace sdr
{
@@ -56,29 +56,7 @@ namespace sdr
        {
            if(rProps.mpItemSet)
            {
                // Clone may be to another model and thus another ItemPool.
                // SfxItemSet supports that thus we are able to Clone all
                // SfxItemState::SET items to the target pool.
                mpItemSet.reset(
                    rProps.mpItemSet->Clone(
                        true,
                        &rObj.getSdrModelFromSdrObject().GetItemPool()));

                // React on ModelChange: If metric has changed, scale items.
                // As seen above, clone is supported, but scale is not included,
                // thus: TTTT maybe add scale to SfxItemSet::Clone() (?)
                if(&rObj.getSdrModelFromSdrObject() != &GetSdrObject().getSdrModelFromSdrObject())
                {
                    const MapUnit aOldUnit(GetSdrObject().getSdrModelFromSdrObject().GetScaleUnit());
                    const MapUnit aNewUnit(rObj.getSdrModelFromSdrObject().GetScaleUnit());
                    const bool bScaleUnitChanged(aNewUnit != aOldUnit);

                    if(bScaleUnitChanged)
                    {
                        const Fraction aMetricFactor(GetMapFactor(aOldUnit, aNewUnit).X());
                        Scale(aMetricFactor);
                    }
                }
                mpItemSet.reset(rProps.mpItemSet->Clone());

                // do not keep parent info, this may be changed by later constructors.
                // This class just copies the ItemSet, ignore parent.
diff --git a/svx/source/sdr/properties/e3dsceneproperties.cxx b/svx/source/sdr/properties/e3dsceneproperties.cxx
index a5f5994..1b3bdbf 100644
--- a/svx/source/sdr/properties/e3dsceneproperties.cxx
+++ b/svx/source/sdr/properties/e3dsceneproperties.cxx
@@ -267,6 +267,31 @@ namespace sdr
            return pRetval;
        }

        void E3dSceneProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
        {
            if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
            {
                // call parent
                E3dProperties::MoveToItemPool(pSrcPool, pDestPool, pNewModel);

                // own reaction, but only with outmost scene
                E3dScene& rObj = static_cast<E3dScene&>(GetSdrObject());
                const SdrObjList* pSubList = rObj.GetSubList();

                if(pSubList && rObj.GetScene() == &rObj)
                {
                    SdrObjListIter a3DIterator(*pSubList, SdrIterMode::DeepWithGroups);

                    while(a3DIterator.IsMore())
                    {
                        E3dObject* pObj = static_cast<E3dObject*>(a3DIterator.Next());
                        DBG_ASSERT(dynamic_cast<const E3dObject* >(pObj) !=  nullptr, "In scenes there are only 3D objects allowed (!)");
                        pObj->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
                    }
                }
            }
        }

        void E3dSceneProperties::SetSceneItemsFromCamera()
        {
            // force ItemSet
diff --git a/svx/source/sdr/properties/groupproperties.cxx b/svx/source/sdr/properties/groupproperties.cxx
index a79f7cc..7b46704 100644
--- a/svx/source/sdr/properties/groupproperties.cxx
+++ b/svx/source/sdr/properties/groupproperties.cxx
@@ -246,6 +246,31 @@ namespace sdr
            // nothing to do here, groups have no items and thus no default items, too.
        }

        void GroupProperties::MoveToItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
        {
            if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
            {
                const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
                const size_t nCount(pSub->GetObjCount());

                for(size_t a = 0; a < nCount; ++a)
                {
                    pSub->GetObj(a)->GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
                }

                // also clear local ItemSet, it's only temporary for group objects anyways.
                if(mpItemSet)
                {
                    // copy/paste is still using clone operators and MoveToItemPool functionality.
                    // Since SfxItemSet contains a pool pointer, ClearItem is not enough here.
                    // The ItemSet for merge is constructed on demand, so it's enough here to
                    // just delete it and set to 0L.
                    // mpItemSet->ClearItem();
                    mpItemSet.reset();
                }
            }
        }

        void GroupProperties::ForceStyleToHardAttributes()
        {
            const SdrObjList* pSub = static_cast<const SdrObjGroup&>(GetSdrObject()).GetSubList();
diff --git a/svx/source/sdr/properties/properties.cxx b/svx/source/sdr/properties/properties.cxx
index 256e6ea..c8082ab 100644
--- a/svx/source/sdr/properties/properties.cxx
+++ b/svx/source/sdr/properties/properties.cxx
@@ -80,6 +80,18 @@ namespace sdr
            ClearObjectItem(nWhich);
        }

        void BaseProperties::MoveToItemPool(SfxItemPool* /*pSrcPool*/, SfxItemPool* /*pDestPool*/, SdrModel* /*pNewModel*/)
        {
            // Move properties to a new ItemPool. Default implementation does nothing.
            // Override where an ItemSet is implemented.
        }

        void BaseProperties::SetModel(SdrModel* /*pOldModel*/, SdrModel* /*pNewModel*/)
        {
            // Set new model. Default implementation does nothing.
            // Override where an ItemSet is implemented.
        }

        void BaseProperties::ForceStyleToHardAttributes()
        {
            // force all attributes which come from styles to hard attributes
diff --git a/svx/source/sdr/properties/textproperties.cxx b/svx/source/sdr/properties/textproperties.cxx
index f6e1aba0..0d57e93 100644
--- a/svx/source/sdr/properties/textproperties.cxx
+++ b/svx/source/sdr/properties/textproperties.cxx
@@ -240,7 +240,7 @@ namespace sdr
            // #i101556# StyleSheet has changed -> new version
            maVersion++;

            if(!rObj.IsLinkedText() )
            if( rObj.GetModel() /*&& !rObj.IsTextEditActive()*/ && !rObj.IsLinkedText() )
            {
                SdrOutliner& rOutliner = rObj.ImpGetDrawOutliner();

@@ -279,7 +279,9 @@ namespace sdr
                                    aNewStyleSheetName = aNewStyleSheetName.copy(0, aNewStyleSheetName.getLength() - 1);
                                    sal_Int16 nDepth = rOutliner.GetDepth(nPara);
                                    aNewStyleSheetName += OUString::number( nDepth <= 0 ? 1 : nDepth + 1);
                                    SfxStyleSheetBasePool* pStylePool(rObj.getSdrModelFromSdrObject().GetStyleSheetPool());

                                    SdrModel* pModel = rObj.GetModel();
                                    SfxStyleSheetBasePool* pStylePool = (pModel != nullptr) ? pModel->GetStyleSheetPool() : nullptr;
                                    SfxStyleSheet* pNewStyle = nullptr;
                                    if(pStylePool)
                                        pNewStyle = static_cast<SfxStyleSheet*>(pStylePool->Find(aNewStyleSheetName, GetStyleSheet()->GetFamily()));
@@ -395,9 +397,11 @@ namespace sdr
            // now the standard TextProperties stuff
            SdrTextObj& rObj = static_cast<SdrTextObj&>(GetSdrObject());

            if(!rObj.IsTextEditActive() && !rObj.IsLinkedText())
            if(rObj.GetModel()
                && !rObj.IsTextEditActive()
                && !rObj.IsLinkedText())
            {
                Outliner* pOutliner = SdrMakeOutliner(OutlinerMode::OutlineObject, rObj.getSdrModelFromSdrObject());
                Outliner* pOutliner = SdrMakeOutliner(OutlinerMode::OutlineObject, *rObj.GetModel());
                const svx::ITextProvider& rTextProvider(getTextProvider());
                sal_Int32 nText = rTextProvider.getTextCount();
                while (nText--)
diff --git a/svx/source/svdraw/svdcrtv.cxx b/svx/source/svdraw/svdcrtv.cxx
index f2d739e..33cf4eb 100644
--- a/svx/source/svdraw/svdcrtv.cxx
+++ b/svx/source/svdraw/svdcrtv.cxx
@@ -197,10 +197,8 @@ void SdrCreateView::ImpClearVars()
    ImpClearConnectMarker();
}

SdrCreateView::SdrCreateView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrDragView(rSdrModel, pOut),
SdrCreateView::SdrCreateView(SdrModel* pModel1, OutputDevice* pOut)
:   SdrDragView(pModel1,pOut),
    mpCoMaOverlay(nullptr),
    mpCreateViewExtraData(new ImpSdrCreateViewExtraData())
{
@@ -350,10 +348,7 @@ void SdrCreateView::SetCurrentObj(sal_uInt16 nIdent, SdrInventor nInvent)
        nCurrentInvent=nInvent;
        nCurrentIdent=nIdent;
        SdrObject * pObj = (nIdent == OBJ_NONE) ? nullptr :
            SdrObjFactory::MakeNewObject(
                *GetModel(),
                nInvent,
                nIdent);
            SdrObjFactory::MakeNewObject(nInvent, nIdent, nullptr);

        if(pObj)
        {
@@ -412,14 +407,14 @@ bool SdrCreateView::ImpBegCreateObj(SdrInventor nInvent, sal_uInt16 nIdent, cons
                {
                    pCurrentCreate->SetPage(pCreatePV->GetPage());
                }
                else if (mpModel)
                {
                    pCurrentCreate->SetModel(mpModel);
                }
            }
            else
            {
                pCurrentCreate = SdrObjFactory::MakeNewObject(
                    *mpModel,
                    nInvent,
                    nIdent,
                    pCreatePV->GetPage());
                pCurrentCreate = SdrObjFactory::MakeNewObject(nInvent, nIdent, pCreatePV->GetPage(), mpModel);
            }

            Point aPnt(rPnt);
diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx
index 5d18d68..b13383b 100644
--- a/svx/source/svdraw/svddrgv.cxx
+++ b/svx/source/svdraw/svddrgv.cxx
@@ -71,10 +71,8 @@ void SdrDragView::ImpClearVars()
    mbSolidDragging = getOptionsDrawinglayer().IsSolidDragCreate();
}

SdrDragView::SdrDragView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrExchangeView(rSdrModel, pOut)
SdrDragView::SdrDragView(SdrModel* pModel1, OutputDevice* pOut)
:   SdrExchangeView(pModel1,pOut)
{
    ImpClearVars();
}
diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx
index ce620ae..c373caa 100644
--- a/svx/source/svdraw/svdedtv.cxx
+++ b/svx/source/svdraw/svdedtv.cxx
@@ -88,10 +88,8 @@ void SdrEditView::ImpClearVars()
    bPossibilitiesDirty=true;   // << Purify didn't like this
}

SdrEditView::SdrEditView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrMarkView(rSdrModel, pOut)
SdrEditView::SdrEditView(SdrModel* pModel1, OutputDevice* pOut):
    SdrMarkView(pModel1,pOut)
{
    ImpClearVars();
}
@@ -100,6 +98,7 @@ SdrEditView::~SdrEditView()
{
}


void SdrEditView::InsertNewLayer(const OUString& rName, sal_uInt16 nPos)
{
    SdrLayerAdmin& rLA=mpModel->GetLayerAdmin();
diff --git a/svx/source/svdraw/svdedtv2.cxx b/svx/source/svdraw/svdedtv2.cxx
index ef63499..01820c6 100644
--- a/svx/source/svdraw/svdedtv2.cxx
+++ b/svx/source/svdraw/svdedtv2.cxx
@@ -1126,7 +1126,7 @@ void SdrEditView::MergeMarkedObjects(SdrMergeMode eMode)
    // #i73441# check insert list before taking actions
    if(pInsOL)
    {
        SdrPathObj* pPath = new SdrPathObj(pAttrObj->getSdrModelFromSdrObject(), OBJ_PATHFILL, aMergePolyPolygonA);
        SdrPathObj* pPath = new SdrPathObj(OBJ_PATHFILL, aMergePolyPolygonA);
        ImpCopyAttributes(pAttrObj, pPath);
        pInsOL->InsertObject(pPath, nInsPos);
        if( bUndo )
@@ -1134,7 +1134,7 @@ void SdrEditView::MergeMarkedObjects(SdrMergeMode eMode)

        // #i124760# To have a correct selection with only the new object it is necessary to
        // unmark all objects first. If not doing so, there may remain invalid pointers to objects
        // TTTT:Not needed for aw080 (!)
        //TTTT:Not needed for aw080 (!)
        UnmarkAllObj(pInsPV);

        MarkObj(pPath, pInsPV, false, true);
@@ -1355,7 +1355,7 @@ void SdrEditView::CombineMarkedObjects(bool bNoPolyPoly)
            }
        }

        SdrPathObj* pPath = new SdrPathObj(pAttrObj->getSdrModelFromSdrObject(), eKind, aPolyPolygon);
        SdrPathObj* pPath = new SdrPathObj(eKind,aPolyPolygon);

        // attributes of the lowest object
        ImpCopyAttributes(pAttrObj, pPath);
@@ -1522,10 +1522,7 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, 

            if(!bMakeLines || nPointCount < 2)
            {
                SdrPathObj* pPath = new SdrPathObj(
                    pSrcPath->getSdrModelFromSdrObject(),
                    static_cast<SdrObjKind>(pSrcPath->GetObjIdentifier()),
                    basegfx::B2DPolyPolygon(rCandidate));
                SdrPathObj* pPath = new SdrPathObj(static_cast<SdrObjKind>(pSrcPath->GetObjIdentifier()), basegfx::B2DPolyPolygon(rCandidate));
                ImpCopyAttributes(pSrcPath, pPath);
                pLast = pPath;
                rOL.InsertObject(pPath, rPos);
@@ -1559,10 +1556,7 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, 
                        aNewPolygon.append(rCandidate.getB2DPoint(nNextIndex));
                    }

                    SdrPathObj* pPath = new SdrPathObj(
                        pSrcPath->getSdrModelFromSdrObject(),
                        eKind,
                        basegfx::B2DPolyPolygon(aNewPolygon));
                    SdrPathObj* pPath = new SdrPathObj(eKind, basegfx::B2DPolyPolygon(aNewPolygon));
                    ImpCopyAttributes(pSrcPath, pPath);
                    pLast = pPath;
                    rOL.InsertObject(pPath, rPos);
@@ -1590,6 +1584,7 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, 
            {
                SdrObject* pCandidate = pReplacement->Clone();
                DBG_ASSERT(pCandidate, "SdrEditView::ImpDismantleOneObject: Could not clone SdrObject (!)");
                pCandidate->SetModel(pCustomShape->GetModel());

                if(pCustomShape->GetMergedItem(SDRATTR_SHADOW).GetValue())
                {
@@ -1608,9 +1603,7 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, 
                {
                    // #i37011# also create a text object and add at rPos + 1
                    SdrObject* pTextObj = SdrObjFactory::MakeNewObject(
                        pCustomShape->getSdrModelFromSdrObject(),
                        pCustomShape->GetObjInventor(),
                        OBJ_TEXT);
                        pCustomShape->GetObjInventor(), OBJ_TEXT, nullptr, pCustomShape->GetModel());

                    // Copy text content
                    OutlinerParaObject* pParaObj = pCustomShape->GetOutlinerParaObject();
@@ -1761,13 +1754,14 @@ void SdrEditView::GroupMarked()
                SdrMark* pM=GetSdrMarkByIndex(nm);
                if (pM->GetPageView()==pPV)
                {
                    SdrObject* pObj=pM->GetMarkedSdrObj();
                    if (nullptr==pGrp)
                    if (pGrp==nullptr)
                    {
                        pGrp = new SdrObjGroup(pObj->getSdrModelFromSdrObject());
                        if (pGrp==nullptr)
                            pGrp=new SdrObjGroup;
                        pDstLst=pGrp->GetSubList();
                        DBG_ASSERT(pDstLst!=nullptr,"Alleged group object doesn't return object list.");
                    }
                    SdrObject* pObj=pM->GetMarkedSdrObj();
                    pSrcLst=pObj->GetObjList();
                    if (pSrcLst!=pSrcLst0)
                    {
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index d03a55f..51ef80f 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -88,10 +88,8 @@ void SdrObjEditView::ImpClearVars()
    bTextEditOnlyOneView=false;
}

SdrObjEditView::SdrObjEditView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrGlueEditView(rSdrModel, pOut),
SdrObjEditView::SdrObjEditView(SdrModel* pModel1, OutputDevice* pOut):
    SdrGlueEditView(pModel1,pOut),
    mpOldTextEditUndoManager(nullptr)
{
    ImpClearVars();
@@ -1091,7 +1089,7 @@ bool SdrObjEditView::SdrBeginTextEdit(
        mxTextEditObj.reset( pObj );
        pTextEditOutliner=pGivenOutliner;
        if (pTextEditOutliner==nullptr)
            pTextEditOutliner = SdrMakeOutliner( OutlinerMode::TextObject, mxTextEditObj->getSdrModelFromSdrObject() );
            pTextEditOutliner = SdrMakeOutliner( OutlinerMode::TextObject, *mxTextEditObj->GetModel() );

        {
            SvtAccessibilityOptions aOptions;
@@ -1590,7 +1588,8 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally)
    }

    if( pTEObj &&
        !pTEObj->getSdrModelFromSdrObject().isLocked() &&
        pTEObj->GetModel() &&
        !pTEObj->GetModel()->isLocked() &&
        pTEObj->GetBroadcaster())
    {
        SdrHint aHint(SdrHintKind::EndEdit, *pTEObj);
@@ -2409,17 +2408,11 @@ void SdrObjEditView::MarkListHasChanged()
    const SdrMarkList& rMarkList=GetMarkedObjectList();
    if( rMarkList.GetMarkCount() == 1 )
    {
        const SdrObject* pObj(rMarkList.GetMark(0)->GetMarkedSdrObj());
        SdrView* pView(dynamic_cast< SdrView* >(this));

        const SdrObject* pObj= rMarkList.GetMark(0)->GetMarkedSdrObj();
        // check for table
        if(pObj && pView && (pObj->GetObjInventor() == SdrInventor::Default ) && (pObj->GetObjIdentifier() == OBJ_TABLE))
        if( pObj && (pObj->GetObjInventor() == SdrInventor::Default ) && (pObj->GetObjIdentifier() == OBJ_TABLE) )
        {
            mxSelectionController = sdr::table::CreateTableController(
                *pView,
                static_cast<const sdr::table::SdrTableObj&>(*pObj),
                mxLastSelectionController);

            mxSelectionController = sdr::table::CreateTableController( this, static_cast<sdr::table::SdrTableObj const *>(pObj), mxLastSelectionController );
            if( mxSelectionController.is() )
            {
                mxLastSelectionController.clear();
diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx
index 24479d6..4b29e2c 100644
--- a/svx/source/svdraw/svdetc.cxx
+++ b/svx/source/svdraw/svdetc.cxx
@@ -531,6 +531,9 @@ namespace
        const SdrLayerIDSet& rVisLayers,
        Color& rCol)
    {
        if(!rList.GetModel())
            return false;

        bool bRet(false);
        bool bMaster(rList.GetPage() && rList.GetPage()->IsMasterPage());

@@ -573,6 +576,9 @@ namespace
        Color& rCol,
        bool bSkipBackgroundShape)
    {
        if(!rPage.GetModel())
            return false;

        bool bRet(impGetSdrObjListFillColor(rPage, rPnt, rTextEditPV, rVisLayers, rCol));

        if(!bRet && !rPage.IsMasterPage())
diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx
index 3f3a935..f3806362 100644
--- a/svx/source/svdraw/svdfmtf.cxx
+++ b/svx/source/svdraw/svdfmtf.cxx
@@ -557,7 +557,6 @@ void ImpSdrGDIMetaFileImport::InsertObj(SdrObject* pObj, bool bScale)
                if(!aNewRange.isEmpty())
                {
                    pObj = new SdrPathObj(
                        *mpModel,
                        aNewPoly.isClosed() ? OBJ_POLY : OBJ_PLIN,
                        aNewPoly);

@@ -687,10 +686,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction const & rAct)

        if(bCreateLineObject)
        {
            SdrPathObj* pPath = new SdrPathObj(
                *mpModel,
                OBJ_LINE,
                basegfx::B2DPolyPolygon(aLine));
            SdrPathObj* pPath = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aLine));
            mnLineWidth = nNewLineWidth;
            maLineJoin = rLineInfo.GetLineJoin();
            maLineCap = rLineInfo.GetLineCap();
@@ -709,18 +705,14 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction const & rAct)

void ImpSdrGDIMetaFileImport::DoAction(MetaRectAction const & rAct)
{
    SdrRectObj* pRect = new SdrRectObj(
        *mpModel,
        rAct.GetRect());
    SdrRectObj* pRect=new SdrRectObj(rAct.GetRect());
    SetAttributes(pRect);
    InsertObj(pRect);
}

void ImpSdrGDIMetaFileImport::DoAction(MetaRoundRectAction const & rAct)
{
    SdrRectObj* pRect = new SdrRectObj(
        *mpModel,
        rAct.GetRect());
    SdrRectObj* pRect=new SdrRectObj(rAct.GetRect());
    SetAttributes(pRect);
    long nRad=(rAct.GetHorzRound()+rAct.GetVertRound())/2;
    if (nRad!=0) {
@@ -733,10 +725,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaRoundRectAction const & rAct)

void ImpSdrGDIMetaFileImport::DoAction(MetaEllipseAction const & rAct)
{
    SdrCircObj* pCirc=new SdrCircObj(
        *mpModel,
        OBJ_CIRC,
        rAct.GetRect());
    SdrCircObj* pCirc=new SdrCircObj(OBJ_CIRC,rAct.GetRect());
    SetAttributes(pCirc);
    InsertObj(pCirc);
}
@@ -746,10 +735,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaArcAction const & rAct)
    Point aCenter(rAct.GetRect().Center());
    long nStart=GetAngle(rAct.GetStartPoint()-aCenter);
    long nEnd=GetAngle(rAct.GetEndPoint()-aCenter);
    SdrCircObj* pCirc = new SdrCircObj(
        *mpModel,
        OBJ_CARC,
        rAct.GetRect(),nStart,nEnd);
    SdrCircObj* pCirc=new SdrCircObj(OBJ_CARC,rAct.GetRect(),nStart,nEnd);
    SetAttributes(pCirc);
    InsertObj(pCirc);
}
@@ -759,12 +745,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaPieAction const & rAct)
    Point aCenter(rAct.GetRect().Center());
    long nStart=GetAngle(rAct.GetStartPoint()-aCenter);
    long nEnd=GetAngle(rAct.GetEndPoint()-aCenter);
    SdrCircObj* pCirc = new SdrCircObj(
        *mpModel,
        OBJ_SECT,
        rAct.GetRect(),
        nStart,
        nEnd);
    SdrCircObj* pCirc=new SdrCircObj(OBJ_SECT,rAct.GetRect(),nStart,nEnd);
    SetAttributes(pCirc);
    InsertObj(pCirc);
}
@@ -774,12 +755,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaChordAction const & rAct)
    Point aCenter(rAct.GetRect().Center());
    long nStart=GetAngle(rAct.GetStartPoint()-aCenter);
    long nEnd=GetAngle(rAct.GetEndPoint()-aCenter);
    SdrCircObj* pCirc = new SdrCircObj(
        *mpModel,
        OBJ_CCUT,
        rAct.GetRect(),
        nStart,
        nEnd);
    SdrCircObj* pCirc=new SdrCircObj(OBJ_CCUT,rAct.GetRect(),nStart,nEnd);
    SetAttributes(pCirc);
    InsertObj(pCirc);
}
@@ -935,7 +911,6 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaPolyLineAction const & rAct )
    if(bCreateLineObject)
    {
        SdrPathObj* pPath = new SdrPathObj(
            *mpModel,
            aSource.isClosed() ? OBJ_POLY : OBJ_PLIN,
            basegfx::B2DPolyPolygon(aSource));
        mnLineWidth = nNewLineWidth;
@@ -967,10 +942,7 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaPolygonAction const & rAct )
        {
            // #i73407# make sure polygon is closed, it's a filled primitive
            aSource.setClosed(true);
            SdrPathObj* pPath = new SdrPathObj(
                *mpModel,
                OBJ_POLY,
                basegfx::B2DPolyPolygon(aSource));
            SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aSource));
            SetAttributes(pPath);
            InsertObj(pPath, false);
        }
@@ -991,10 +963,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaPolyPolygonAction const & rAct)
        {
            // #i73407# make sure polygon is closed, it's a filled primitive
            aSource.setClosed(true);
            SdrPathObj* pPath = new SdrPathObj(
                *mpModel,
                OBJ_POLY,
                aSource);
            SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
            SetAttributes(pPath);
            InsertObj(pPath, false);
        }
@@ -1021,10 +990,7 @@ void ImpSdrGDIMetaFileImport::ImportText( const Point& rPos, const OUString& rSt
        aPos.AdjustY( -nTextHeight );

    tools::Rectangle aTextRect( aPos, aSize );
    SdrRectObj* pText = new SdrRectObj(
        *mpModel,
        OBJ_TEXT,
        aTextRect);
    SdrRectObj* pText =new SdrRectObj( OBJ_TEXT, aTextRect );

    pText->SetMergedItem ( makeSdrTextUpperDistItem (0));
    pText->SetMergedItem ( makeSdrTextLowerDistItem (0));
@@ -1043,6 +1009,7 @@ void ImpSdrGDIMetaFileImport::ImportText( const Point& rPos, const OUString& rSt
        pText->SetMergedItem( makeSdrTextAutoGrowWidthItem( true ) );
    }

    pText->SetModel(mpModel);
    pText->SetLayer(mnLayer);
    pText->NbcSetText( rStr );
    SetAttributes( pText, true );
@@ -1092,10 +1059,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpAction const & rAct)
{
    tools::Rectangle aRect(rAct.GetPoint(),rAct.GetBitmap().GetSizePixel());
    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        Graphic(rAct.GetBitmap()),
        aRect);
    SdrGrafObj* pGraf=new SdrGrafObj(Graphic(rAct.GetBitmap()),aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1107,10 +1071,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScaleAction const & rAct)
{
    tools::Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        Graphic(rAct.GetBitmap()),
        aRect);
    SdrGrafObj* pGraf=new SdrGrafObj(Graphic(rAct.GetBitmap()),aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1122,10 +1083,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExAction const & rAct)
{
    tools::Rectangle aRect(rAct.GetPoint(),rAct.GetBitmapEx().GetSizePixel());
    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        rAct.GetBitmapEx(),
        aRect);
    SdrGrafObj* pGraf=new SdrGrafObj( rAct.GetBitmapEx(), aRect );

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1137,10 +1095,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScaleAction const & rAct)
{
    tools::Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        rAct.GetBitmapEx(),
        aRect);
    SdrGrafObj* pGraf=new SdrGrafObj( rAct.GetBitmapEx(), aRect );

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1162,10 +1117,7 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaHatchAction const & rAct )
        if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
        {
            const Hatch& rHatch = rAct.GetHatch();
            SdrPathObj* pPath = new SdrPathObj(
                *mpModel,
                OBJ_POLY,
                aSource);
            SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
            // #i125211# Use the ranges from the SdrObject to create a new empty SfxItemSet
            SfxItemSet aHatchAttr(mpModel->GetItemPool(), pPath->GetMergedItemSet().GetRanges());
            css::drawing::HatchStyle eStyle;
@@ -1255,10 +1207,7 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaCommentAction const & rAct, GDIMetaF
                if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
                {
                    const Gradient& rGrad = pAct->GetGradient();
                    SdrPathObj* pPath = new SdrPathObj(
                        *mpModel,
                        OBJ_POLY,
                        aSource);
                    SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
                    // #i125211# Use the ranges from the SdrObject to create a new empty SfxItemSet
                    SfxItemSet aGradAttr(mpModel->GetItemPool(), pPath->GetMergedItemSet().GetRanges());
                    XGradient aXGradient;
@@ -1326,10 +1275,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScalePartAction const & rAct)
    aRect.AdjustRight( 1 );
    aRect.AdjustBottom( 1 );
    aBitmap.Crop(tools::Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize()));
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        aBitmap,
        aRect);
    SdrGrafObj* pGraf = new SdrGrafObj(aBitmap, aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1345,10 +1291,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScalePartAction const & rAct)
    aRect.AdjustRight( 1 );
    aRect.AdjustBottom( 1 );
    aBitmapEx.Crop(tools::Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize()));
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        aBitmapEx,
        aRect);
    SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1362,10 +1305,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaMaskAction const & rAct)
    BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor());

    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        aBitmapEx,
        aRect);
    SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1379,10 +1319,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaMaskScaleAction const & rAct)
    BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor());

    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        aBitmapEx,
        aRect);
    SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1397,10 +1334,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaMaskScalePartAction const & rAct)

    aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 );
    aBitmapEx.Crop(tools::Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize()));
    SdrGrafObj* pGraf = new SdrGrafObj(
        *mpModel,
        aBitmapEx,
        aRect);
    SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);

    // This action is not creating line and fill, set directly, do not use SetAttributes(..)
    pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
@@ -1447,7 +1381,6 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientAction const & rAct)
    aRange.transform(aTransform);
    const Gradient& rGradient = rAct.GetGradient();
    SdrRectObj* pRect = new SdrRectObj(
        *mpModel,
        tools::Rectangle(
            floor(aRange.getMinX()),
            floor(aRange.getMinY()),
@@ -1487,10 +1420,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaTransparentAction const & rAct)
        aSource.transform(aTransform);
        aSource.setClosed(true);

        SdrPathObj* pPath = new SdrPathObj(
            *mpModel,
            OBJ_POLY,
            aSource);
        SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
        SetAttributes(pPath);
        pPath->SetMergedItem(XFillTransparenceItem(rAct.GetTransparence()));
        InsertObj(pPath, false);
@@ -1509,10 +1439,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientExAction const & rAct)
        if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource))
        {
            const Gradient& rGradient = rAct.GetGradient();
            SdrPathObj* pPath = new SdrPathObj(
                *mpModel,
                OBJ_POLY,
                aSource);
            SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource);
            // #i125211# Use the ranges from the SdrObject to create a new empty SfxItemSet
            SfxItemSet aGradientAttr(mpModel->GetItemPool(), pPath->GetMergedItemSet().GetRanges());
            const css::awt::GradientStyle aXGradientStyle(getXGradientStyleFromGradientStyle(rGradient.GetStyle()));
@@ -1636,10 +1563,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct)
        }

        // create and add object
        SdrGrafObj* pGraf = new SdrGrafObj(
            *mpModel,
            aBitmapEx,
            aRect);
        SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect);

        // for MetaFloatTransparentAction, do not use SetAttributes(...)
        // since these metafile content is not used to draw line/fill
diff --git a/svx/source/svdraw/svdglev.cxx b/svx/source/svdraw/svdglev.cxx
index 3bbd461..64da87b 100644
--- a/svx/source/svdraw/svdglev.cxx
+++ b/svx/source/svdraw/svdglev.cxx
@@ -29,10 +29,9 @@
#include <svx/svdtrans.hxx>
#include <svx/svdobj.hxx>

SdrGlueEditView::SdrGlueEditView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrPolyEditView(rSdrModel, pOut)

SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut):
    SdrPolyEditView(pModel1,pOut)
{
}

@@ -40,6 +39,7 @@ SdrGlueEditView::~SdrGlueEditView()
{
}


void SdrGlueEditView::ImpDoMarkedGluePoints(PGlueDoFunc pDoFunc, bool bConst, const void* p1, const void* p2, const void* p3, const void* p4)
{
    const size_t nMarkCount=GetMarkedObjectCount();
diff --git a/svx/source/svdraw/svdhdl.cxx b/svx/source/svdraw/svdhdl.cxx
index b00b967..711a96e 100644
--- a/svx/source/svdraw/svdhdl.cxx
+++ b/svx/source/svdraw/svdhdl.cxx
@@ -1351,8 +1351,8 @@ void SdrHdlGradient::FromIAOToItem(SdrObject* _pObj, bool bSetItemOnObject, bool

    if(bSetItemOnObject)
    {
        SdrModel& rModel(_pObj->getSdrModelFromSdrObject());
        SfxItemSet aNewSet(rModel.GetItemPool());
        SdrModel* pModel = _pObj->GetModel();
        SfxItemSet aNewSet(pModel->GetItemPool());

        if(IsGradient())
        {
@@ -1367,11 +1367,11 @@ void SdrHdlGradient::FromIAOToItem(SdrObject* _pObj, bool bSetItemOnObject, bool
            aNewSet.Put(aNewTransItem);
        }

        if(bUndo && rModel.IsUndoEnabled())
        if(bUndo && pModel->IsUndoEnabled())
        {
            rModel.BegUndo(SvxResId(IsGradient() ? SIP_XA_FILLGRADIENT : SIP_XA_FILLTRANSPARENCE));
            rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoAttrObject(*_pObj));
            rModel.EndUndo();
            pModel->BegUndo(SvxResId(IsGradient() ? SIP_XA_FILLGRADIENT : SIP_XA_FILLTRANSPARENCE));
            pModel->AddUndo(pModel->GetSdrUndoFactory().CreateUndoAttrObject(*_pObj));
            pModel->EndUndo();
        }

        pObj->SetMergedItemSetAndBroadcast(aNewSet);
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index bb237ba..04d0f70 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -1323,7 +1323,7 @@ void SdrModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
    PageListChanged();
    pPage->SetInserted();
    pPage->SetPageNum(nPos);

    pPage->SetModel(this);
    if (nPos<nCount) bPagNumsDirty=true;
    SetChanged();
    SdrHint aHint(SdrHintKind::PageOrderChange, pPage);
@@ -1372,11 +1372,10 @@ void SdrModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
    MasterPageListChanged();
    pPage->SetInserted();
    pPage->SetPageNum(nPos);

    pPage->SetModel(this);
    if (nPos<nCount) {
        bMPgNumsDirty=true;
    }

    SetChanged();
    SdrHint aHint(SdrHintKind::PageOrderChange, pPage);
    Broadcast(aHint);
@@ -1477,10 +1476,7 @@ void SdrModel::CopyPages(sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
        if (!bMoveNoCopy)
        {
            const SdrPage* pPg1=GetPage(nPageNum2);

            // Clone to local model
            pPg=pPg1->Clone();

            InsertPage(pPg,nDestNum);
            if (bUndo)
                AddUndo(GetSdrUndoFactory().CreateUndoCopyPage(*pPg));
@@ -1581,18 +1577,14 @@ void SdrModel::Merge(SdrModel& rSourceModel,
    if (pMasterMap && pMasterNeed && nMasterNeed!=0) {
        for (sal_uInt16 i=nSrcMasterPageCnt; i>0;) {
            i--;
            if (pMasterNeed[i])
            {
                // Always Clone to new model
                const SdrPage* pPg1(rSourceModel.GetMasterPage(i));
                SdrPage* pPg(pPg1->Clone(this));

                if(!bTreadSourceAsConst)
                {
                    // if requested, delete original/modify original model
                    delete rSourceModel.RemoveMasterPage(i);
            if (pMasterNeed[i]) {
                SdrPage* pPg=nullptr;
                if (bTreadSourceAsConst) {
                    const SdrPage* pPg1=rSourceModel.GetMasterPage(i);
                    pPg=pPg1->Clone();
                } else {
                    pPg=rSourceModel.RemoveMasterPage(i);
                }

                if (pPg!=nullptr) {
                    // Now append all of them to the end of the DstModel.
                    // Don't use InsertMasterPage(), because everything is
@@ -1600,6 +1592,7 @@ void SdrModel::Merge(SdrModel& rSourceModel,
                    maMaPag.insert(maMaPag.begin()+nDstMasterPageCnt, pPg);
                    MasterPageListChanged();
                    pPg->SetInserted();
                    pPg->SetModel(this);
                    bMPgNumsDirty=true;
                    if (bUndo) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg));
                } else {
@@ -1614,18 +1607,14 @@ void SdrModel::Merge(SdrModel& rSourceModel,
        sal_uInt16 nSourcePos=nFirstPageNum;
        sal_uInt16 nMergeCount=sal_uInt16(std::abs(static_cast<long>(static_cast<long>(nFirstPageNum)-nLastPageNum))+1);
        if (nDestPos>GetPageCount()) nDestPos=GetPageCount();
        while (nMergeCount>0)
        {
            // Always Clone to new model
            const SdrPage* pPg1(rSourceModel.GetPage(nSourcePos));
            SdrPage* pPg(pPg1->Clone(this));

            if(!bTreadSourceAsConst)
            {
                // if requested, delete original/modify original model
                delete rSourceModel.RemovePage(nSourcePos);
        while (nMergeCount>0) {
            SdrPage* pPg=nullptr;
            if (bTreadSourceAsConst) {
                const SdrPage* pPg1=rSourceModel.GetPage(nSourcePos);
                pPg=pPg1->Clone();
            } else {
                pPg=rSourceModel.RemovePage(nSourcePos);
            }

            if (pPg!=nullptr) {
                InsertPage(pPg,nDestPos);
                if (bUndo) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg));
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 07a5b28..985b415 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -144,17 +144,15 @@ void SdrMarkView::ImpClearVars()
    BrkMarkGluePoints();
}

SdrMarkView::SdrMarkView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrSnapView(rSdrModel, pOut),
SdrMarkView::SdrMarkView(SdrModel* pModel1, OutputDevice* pOut)
:   SdrSnapView(pModel1,pOut),
    mpMarkObjOverlay(nullptr),
    mpMarkPointsOverlay(nullptr),
    mpMarkGluePointsOverlay(nullptr),
    maHdlList(this)
{
    ImpClearVars();
    StartListening(rSdrModel);
    StartListening(*pModel1);
}

SdrMarkView::~SdrMarkView()
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index 783c5e9..70c9faf7 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -810,8 +810,8 @@ sdr::properties::BaseProperties* SdrObjCustomShape::CreateObjectSpecificProperti
    return new sdr::properties::CustomShapeProperties(*this);
}

SdrObjCustomShape::SdrObjCustomShape(SdrModel& rSdrModel)
:   SdrTextObj(rSdrModel)
SdrObjCustomShape::SdrObjCustomShape()
    : SdrTextObj()
    , fObjectRotation(0.0)
    , mbAdjustingTextFrameWidthAndHeight(false)
    , mpLastShadowGeometry(nullptr)
@@ -1346,16 +1346,23 @@ void SdrObjCustomShape::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
    }
}

void SdrObjCustomShape::SetModel(SdrModel* pNewModel)
{
    SdrTextObj::SetModel(pNewModel);
    mXRenderedCustomShape.clear();
}

sal_uInt16 SdrObjCustomShape::GetObjIdentifier() const
{
    return sal_uInt16(OBJ_CUSTOMSHAPE);
}


// #115391# This implementation is based on the TextFrame size of the CustomShape and the
// state of the ResizeShapeToFitText flag to correctly set TextMinFrameWidth/Height
void SdrObjCustomShape::AdaptTextMinSize()
{
    if (!getSdrModelFromSdrObject().IsCreatingDataObj() && !getSdrModelFromSdrObject().IsPasteResize())
    if (!pModel || (!pModel->IsCreatingDataObj() && !pModel->IsPasteResize()))
    {
        const bool bResizeShapeToFitText(GetObjectItem(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue());
        SfxItemSet aSet(
@@ -2225,7 +2232,7 @@ bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool
{
    // Either we have text or the application has native text and suggested its size to us.
    bool bHasText = HasText() || (m_aSuggestedTextFrameSize.Width() != 0 && m_aSuggestedTextFrameSize.Height() != 0);
    if ( bHasText && !rR.IsEmpty() )
    if ( pModel && bHasText && !rR.IsEmpty() )
    {
        bool bWdtGrow=bWdt && IsAutoGrowWidth();
        bool bHgtGrow=bHgt && IsAutoGrowHeight();
@@ -2236,7 +2243,7 @@ bool SdrObjCustomShape::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool
            long nWdt=0,nMinWdt=0,nMaxWdt=0;
            Size aSiz(rR.GetSize()); aSiz.AdjustWidth( -1 ); aSiz.AdjustHeight( -1 );
            Size aMaxSiz(100000,100000);
            Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize());
            Size aTmpSiz(pModel->GetMaxObjSize());
            if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() );
            if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() );
            if (bWdtGrow)
@@ -2492,8 +2499,8 @@ void SdrObjCustomShape::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, tools
    Size aAnkSiz(aViewInit.GetSize());
    aAnkSiz.AdjustWidth( -1 ); aAnkSiz.AdjustHeight( -1 ); // because GetSize() adds 1
    Size aMaxSiz(1000000,1000000);
    {
        Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize());
    if (pModel!=nullptr) {
        Size aTmpSiz(pModel->GetMaxObjSize());
        if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() );
        if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() );
    }
@@ -2639,9 +2646,11 @@ void SdrObjCustomShape::TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& 

    if (pPara)
    {
        bool bHitTest(&getSdrModelFromSdrObject().GetHitTestOutliner() == &rOutliner);
        const SdrTextObj* pTestObj = rOutliner.GetTextObj();
        bool bHitTest = false;
        if( pModel )
            bHitTest = &pModel->GetHitTestOutliner() == &rOutliner;

        const SdrTextObj* pTestObj = rOutliner.GetTextObj();
        if( !pTestObj || !bHitTest || pTestObj != this ||
            pTestObj->GetOutlinerParaObject() != GetOutlinerParaObject() )
        {
@@ -2737,9 +2746,9 @@ void SdrObjCustomShape::NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject
    InvalidateRenderGeometry();
}

SdrObjCustomShape* SdrObjCustomShape::Clone(SdrModel* pTargetModel) const
SdrObjCustomShape* SdrObjCustomShape::Clone() const
{
    return CloneHelper< SdrObjCustomShape >(pTargetModel);
    return CloneHelper< SdrObjCustomShape >();
}

SdrObjCustomShape& SdrObjCustomShape::operator=(const SdrObjCustomShape& rObj)
@@ -2806,9 +2815,9 @@ SdrObject* SdrObjCustomShape::DoConvertToPolyObj(bool bBezier, bool bAddText) co

    if ( pRenderedCustomShape )
    {
        // Clone to same SdrModel
        SdrObject* pCandidate = pRenderedCustomShape->Clone();
        DBG_ASSERT(pCandidate, "SdrObjCustomShape::DoConvertToPolyObj: Could not clone SdrObject (!)");
        pCandidate->SetModel(GetModel());
        pRetval = pCandidate->DoConvertToPolyObj(bBezier, bAddText);
        SdrObject::Free( pCandidate );

@@ -2939,7 +2948,7 @@ void SdrObjCustomShape::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, 
    }

    // if anchor is used, make position relative to it
    if(getSdrModelFromSdrObject().IsWriter())
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
@@ -3056,7 +3065,7 @@ bool SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegf
    basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top());

    // position may be relative to anchorpos, convert
    if(getSdrModelFromSdrObject().IsWriter())
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
diff --git a/svx/source/svdraw/svdoattr.cxx b/svx/source/svdraw/svdoattr.cxx
index f33a47e..1f118f8 100644
--- a/svx/source/svdraw/svdoattr.cxx
+++ b/svx/source/svdraw/svdoattr.cxx
@@ -80,8 +80,7 @@ sdr::properties::BaseProperties* SdrAttrObj::CreateObjectSpecificProperties()
}


SdrAttrObj::SdrAttrObj(SdrModel& rSdrModel)
:   SdrObject(rSdrModel)
SdrAttrObj::SdrAttrObj()
{
}

@@ -100,7 +99,26 @@ const tools::Rectangle& SdrAttrObj::GetSnapRect() const
    return maSnapRect;
}

void SdrAttrObj::SetModel(SdrModel* pNewModel)
{
    SdrModel* pOldModel = pModel;

    // test for correct pool in ItemSet; move to new pool if necessary
    if(pNewModel && &GetObjectItemPool() != &pNewModel->GetItemPool())
    {
        MigrateItemPool(&GetObjectItemPool(), &pNewModel->GetItemPool(), pNewModel);
    }

    // call parent
    SdrObject::SetModel(pNewModel);

    // modify properties
    GetProperties().SetModel(pOldModel, pNewModel);
}


// syntactical sugar for ItemSet accesses

void SdrAttrObj::Notify(SfxBroadcaster& /*rBC*/, const SfxHint& rHint)
{
    bool bDataChg(SfxHintId::DataChanged == rHint.GetId());
diff --git a/svx/source/svdraw/svdobj.cxx b/svx/source/svdraw/svdobj.cxx
index 29b66b5..6726c2e 100644
--- a/svx/source/svdraw/svdobj.cxx
+++ b/svx/source/svdraw/svdobj.cxx
@@ -226,10 +226,6 @@ sdr::properties::BaseProperties& SdrObject::GetProperties() const
{
    if(!mpProperties)
    {
        // CAUTION(!) Do *not* call this during SdrObject construction,
        // that will lead to wrong type-casts (dependent on costructor-level)
        // and thus eventually create the wrong sdr::properties (!). Is there
        // a way to check if on the stack is a SdrObject-constructor (?)
        const_cast< SdrObject* >(this)->mpProperties.reset(
            const_cast< SdrObject* >(this)->CreateObjectSpecificProperties() );
    }
@@ -288,10 +284,10 @@ void SdrObject::SetBoundRectDirty()
}


SdrObject::SdrObject(SdrModel& rSdrModel)
:   mpFillGeometryDefiningShape(nullptr)
    ,mrSdrModelFromSdrObject(rSdrModel)
SdrObject::SdrObject() :
    mpFillGeometryDefiningShape(nullptr)
    ,pPage(nullptr)
    ,pModel(nullptr)
    ,pUserCall(nullptr)
    ,pPlusData(nullptr)
    ,mpImpl(new Impl)
@@ -347,7 +343,22 @@ SdrObject::~SdrObject()
    // when they get called from ObjectInDestruction().
    mpImpl->maObjectUsers.clear();

    // UserCall
    try
    {
        SvxShape* pSvxShape = getSvxShape();
        if ( pSvxShape )
        {
            OSL_ENSURE(!pSvxShape->HasSdrObjectOwnership(),"Please check where this call come from and replace it with SdrObject::Free");
            pSvxShape->InvalidateSdrObject();
            uno::Reference< lang::XComponent > xShapeComp( getWeakUnoShape(), uno::UNO_QUERY_THROW );
            xShapeComp->dispose();
        }
    }
    catch( const uno::Exception& )
    {
        DBG_UNHANDLED_EXCEPTION("svx");
    }

    SendUserCall(SdrUserCallType::Delete, GetLastBoundRect());
    o3tl::reset_preserve_ptr_during(pPlusData);

@@ -359,38 +370,14 @@ SdrObject::~SdrObject()
void SdrObject::Free( SdrObject*& _rpObject )
{
    SdrObject* pObject = _rpObject; _rpObject = nullptr;

    if(nullptr == pObject)
    {
    if ( pObject == nullptr )
        // nothing to do
        return;
    }

    SvxShape* pShape(pObject->getSvxShape());

    if(pShape)
    {
        if(pShape->HasSdrObjectOwnership())
        {
            // only the SvxShape is allowed to delete me, and will reset
            // the ownership before doing so
            return;
        }
        else
        {
            // not only delete pObject, but also need to dispose uno shape
            try
            {
                pShape->InvalidateSdrObject();
                uno::Reference< lang::XComponent > xShapeComp( pObject->getWeakUnoShape(), uno::UNO_QUERY_THROW );
                xShapeComp->dispose();
            }
            catch( const uno::Exception& )
            {
                DBG_UNHANDLED_EXCEPTION("svx");
            }
        }
    }
    SvxShape* pShape = pObject->getSvxShape();
    if ( pShape && pShape->HasSdrObjectOwnership() )
        // only the shape is allowed to delete me, and will reset the ownership before doing so
        return;

    delete pObject;
}
@@ -406,6 +393,28 @@ void SdrObject::SetRectsDirty(bool bNotMyself)
    }
}

void SdrObject::SetModel(SdrModel* pNewModel)
{
    if(pNewModel && pPage)
    {
        if(pPage->GetModel() != pNewModel)
        {
            pPage = nullptr;
        }
    }

    // update listeners at possible API wrapper object
    if( pModel != pNewModel )
    {
        SvxShape* pShape = getSvxShape();
        if( pShape )
            pShape->ChangeModel( pNewModel );
    }

    pModel = pNewModel;
}


void SdrObject::SetObjList(SdrObjList* pNewObjList)
{
    pObjList=pNewObjList;
@@ -414,23 +423,16 @@ void SdrObject::SetObjList(SdrObjList* pNewObjList)

void SdrObject::SetPage(SdrPage* pNewPage)
{
    SdrModel* pOldModel(&getSdrModelFromSdrObject());
    SdrPage* pOldPage(pPage);
    SdrModel* pOldModel = pModel;
    SdrPage* pOldPage = pPage;

    pPage = pNewPage;

    // TTTT Possibility here to add a warning for the future -> SdrModel
    // of SdrObject (this) and SdrPage it it added to *have* to have the
    // same SdrModel
    // if(nullptr != pPage)
    // {
    //     SdrModel* pMod(&pPage->getSdrModelFromSdrPage());
    //
    //     if(pMod != &getSdrModelFromSdrObject())
    //     {
    //         SetModel(pMod);
    //     }
    // }
    pPage=pNewPage;
    if (pPage!=nullptr)
    {
        SdrModel* pMod=pPage->GetModel();
        if (pMod!=pModel && pMod!=nullptr)
            SetModel(pMod);
    }

    // The creation of the UNO shape in SdrObject::getUnoShape is influenced
    // by pPage, so when the page changes we need to discard the cached UNO
@@ -438,14 +440,7 @@ void SdrObject::SetPage(SdrPage* pNewPage)
    // If the page is changing to another page with the same model, we
    // assume they create compatible UNO shape objects so we shouldn't have
    // to invalidate.
    // TTTT: This causes quite some problems in SvxDrawPage::add when used
    // e.g. from Writer - the SdrObject may be cloned to target model, and
    // the xShape was added to it by purpose (see there). Thus it will be
    // good to think about if this is really needed - it *seems* to be intended
    // for a xShape being a on-demand-creatable resource - wit hthe argument that
    // the SdrPage/UnoPage used influences the SvxShape creation. This uses
    // ressources and would be nice to get rid of anyways.
    if (pOldPage != pPage && !(pOldPage && pPage && pOldModel == &getSdrModelFromSdrObject()))
    if (pOldPage != pPage && !(pOldPage && pPage && pOldModel == pModel))
    {
        SvxShape* const pShape(getSvxShape());
        if (pShape && !pShape->HasSdrObjectOwnership())
@@ -517,9 +512,13 @@ sal_Int16 SdrObject::GetRelativeHeightRelation() const
    return mpImpl->meRelativeHeightRelation;
}

SfxItemPool& SdrObject::GetObjectItemPool() const
SfxItemPool & SdrObject::GetObjectItemPool() const
{
    return getSdrModelFromSdrObject().GetItemPool();
    if(pModel)
        return pModel->GetItemPool();

    // use a static global default pool
    return SdrObject::GetGlobalDrawObjectItemPool();
}

SdrInventor SdrObject::GetObjInventor()   const
@@ -637,7 +636,7 @@ void SdrObject::SetName(const OUString& rStr)
    {
        // Undo/Redo for setting object's name (#i73249#)
        bool bUndo( false );
        if ( getSdrModelFromSdrObject().IsUndoEnabled() )
        if ( GetModel() && GetModel()->IsUndoEnabled() )
        {
            bUndo = true;
            SdrUndoAction* pUndoAction =
@@ -646,14 +645,14 @@ void SdrObject::SetName(const OUString& rStr)
                                                    SdrUndoObjStrAttr::ObjStrAttrType::Name,
                                                    GetName(),
                                                    rStr );
            getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() );
            getSdrModelFromSdrObject().AddUndo( pUndoAction );
            GetModel()->BegUndo( pUndoAction->GetComment() );
            GetModel()->AddUndo( pUndoAction );
        }
        pPlusData->aObjName = rStr;
        // Undo/Redo for setting object's name (#i73249#)
        if ( bUndo )
        {
            getSdrModelFromSdrObject().EndUndo();
            GetModel()->EndUndo();
        }
        SetChanged();
        BroadcastObjectChange();
@@ -681,7 +680,7 @@ void SdrObject::SetTitle(const OUString& rStr)
    {
        // Undo/Redo for setting object's title (#i73249#)
        bool bUndo( false );
        if ( getSdrModelFromSdrObject().IsUndoEnabled() )
        if ( GetModel() && GetModel()->IsUndoEnabled() )
        {
            bUndo = true;
            SdrUndoAction* pUndoAction =
@@ -690,14 +689,14 @@ void SdrObject::SetTitle(const OUString& rStr)
                                                    SdrUndoObjStrAttr::ObjStrAttrType::Title,
                                                    GetTitle(),
                                                    rStr );
            getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() );
            getSdrModelFromSdrObject().AddUndo( pUndoAction );
            GetModel()->BegUndo( pUndoAction->GetComment() );
            GetModel()->AddUndo( pUndoAction );
        }
        pPlusData->aObjTitle = rStr;
        // Undo/Redo for setting object's title (#i73249#)
        if ( bUndo )
        {
            getSdrModelFromSdrObject().EndUndo();
            GetModel()->EndUndo();
        }
        SetChanged();
        BroadcastObjectChange();
@@ -725,7 +724,7 @@ void SdrObject::SetDescription(const OUString& rStr)
    {
        // Undo/Redo for setting object's description (#i73249#)
        bool bUndo( false );
        if ( getSdrModelFromSdrObject().IsUndoEnabled() )
        if ( GetModel() && GetModel()->IsUndoEnabled() )
        {
            bUndo = true;
            SdrUndoAction* pUndoAction =
@@ -734,14 +733,14 @@ void SdrObject::SetDescription(const OUString& rStr)
                                                    SdrUndoObjStrAttr::ObjStrAttrType::Description,
                                                    GetDescription(),
                                                    rStr );
            getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() );
            getSdrModelFromSdrObject().AddUndo( pUndoAction );
            GetModel()->BegUndo( pUndoAction->GetComment() );
            GetModel()->AddUndo( pUndoAction );
        }
        pPlusData->aObjDescription = rStr;
        // Undo/Redo for setting object's description (#i73249#)
        if ( bUndo )
        {
            getSdrModelFromSdrObject().EndUndo();
            GetModel()->EndUndo();
        }
        SetChanged();
        BroadcastObjectChange();
@@ -836,7 +835,7 @@ const tools::Rectangle& SdrObject::GetLastBoundRect() const
void SdrObject::RecalcBoundRect()
{
    // #i101680# suppress BoundRect calculations on import(s)
    if ((getSdrModelFromSdrObject().isLocked()) || utl::ConfigManager::IsFuzzing())
    if ((pModel && pModel->isLocked()) || utl::ConfigManager::IsFuzzing())
        return;

    // central new method which will calculate the BoundRect using primitive geometry
@@ -866,7 +865,7 @@ void SdrObject::RecalcBoundRect()

void SdrObject::BroadcastObjectChange() const
{
    if ((getSdrModelFromSdrObject().isLocked()) || utl::ConfigManager::IsFuzzing())
    if ((pModel && pModel->isLocked()) || utl::ConfigManager::IsFuzzing())
        return;

    if (mbDelayBroadcastObjectChange)
@@ -876,7 +875,7 @@ void SdrObject::BroadcastObjectChange() const
    }

    bool bPlusDataBroadcast(pPlusData && pPlusData->pBroadcast);
    bool bObjectChange(IsInserted());
    bool bObjectChange(IsInserted() && pModel);

    if(bPlusDataBroadcast || bObjectChange)
    {
@@ -889,7 +888,7 @@ void SdrObject::BroadcastObjectChange() const

        if(bObjectChange)
        {
            getSdrModelFromSdrObject().Broadcast(aHint);
            pModel->Broadcast(aHint);
        }
    }
}
@@ -900,13 +899,9 @@ void SdrObject::SetChanged()
    // notification now.
    ActionChanged();

    // TTTT Need to check meaning/usage of IsInserted in one
    // of the next changes. It should not mean to have a SdrModel
    // set (this is guaranteed now), but should be connected to
    // being added to a SdrPage (?)
    if(IsInserted())
    if(IsInserted() && pModel)
    {
        getSdrModelFromSdrObject().SetChanged();
        pModel->SetChanged();
    }
}

@@ -934,9 +929,9 @@ bool SdrObject::HasLimitedRotation() const
    return false;
}

SdrObject* SdrObject::Clone(SdrModel* pTargetModel) const
SdrObject* SdrObject::Clone() const
{
    return CloneHelper< SdrObject >(pTargetModel);
    return CloneHelper< SdrObject >();
}

SdrObject& SdrObject::operator=(const SdrObject& rObj)
@@ -952,6 +947,7 @@ SdrObject& SdrObject::operator=(const SdrObject& rObj)
    // draw object, an SdrObject needs to be provided, as in the normal constructor.
    mpProperties.reset( &rObj.GetProperties().Clone(*this) );

    pModel  =rObj.pModel;
    pPage = rObj.pPage;
    aOutRect=rObj.aOutRect;
    mnLayerID = rObj.mnLayerID;
@@ -1025,9 +1021,19 @@ void SdrObject::ImpForcePlusData()
        pPlusData.reset( new SdrObjPlusData );
}

OUString SdrObject::GetAngleStr(long nAngle) const
{
    if (pModel!=nullptr)
        return SdrModel::GetAngleString(nAngle);

    return OUString();
}

OUString SdrObject::GetMetrStr(long nVal) const
{
    return getSdrModelFromSdrObject().GetMetricString(nVal);
    if (pModel!=nullptr)
        return pModel->GetMetricString(nVal);
    return OUString();
}

basegfx::B2DPolyPolygon SdrObject::TakeXorPoly() const
@@ -2048,16 +2054,16 @@ void SdrObject::NbcApplyNotPersistAttr(const SfxItemSet& rAttr)
    if (rAttr.GetItemState(SDRATTR_LAYERID,true,&pPoolItem)==SfxItemState::SET) {
        nLayer=static_cast<const SdrLayerIdItem*>(pPoolItem)->GetValue();
    }
    if (rAttr.GetItemState(SDRATTR_LAYERNAME,true,&pPoolItem)==SfxItemState::SET)
    {
        OUString aLayerName = static_cast<const SdrLayerNameItem*>(pPoolItem)->GetValue();
        const SdrLayerAdmin& rLayAd(nullptr != pPage ? pPage->GetLayerAdmin() : getSdrModelFromSdrObject().GetLayerAdmin());
        const SdrLayer* pLayer = rLayAd.GetLayer(aLayerName);

        if(nullptr != pLayer)
        {
            nLayer=pLayer->GetID();
    if (rAttr.GetItemState(SDRATTR_LAYERNAME,true,&pPoolItem)==SfxItemState::SET && pModel!=nullptr) {
        OUString aLayerName=static_cast<const SdrLayerNameItem*>(pPoolItem)->GetValue();
        const SdrLayerAdmin* pLayAd=pPage!=nullptr ? &pPage->GetLayerAdmin() : pModel!=nullptr ? &pModel->GetLayerAdmin() : nullptr;
        if (pLayAd!=nullptr) {
            const SdrLayer* pLayer=pLayAd->GetLayer(aLayerName);
            if (pLayer!=nullptr) {
                nLayer=pLayer->GetID();
            }
        }

    }
    if (nLayer!=SDRLAYER_NOTFOUND) {
        NbcSetLayer(nLayer);
@@ -2120,11 +2126,12 @@ void SdrObject::TakeNotPersistAttr(SfxItemSet& rAttr) const
    }

    rAttr.Put(SdrLayerIdItem(GetLayer()));
    const SdrLayerAdmin& rLayAd(nullptr != pPage ? pPage->GetLayerAdmin() : getSdrModelFromSdrObject().GetLayerAdmin());
    const SdrLayer* pLayer = rLayAd.GetLayerPerID(GetLayer());
    if(nullptr != pLayer)
    {
        rAttr.Put(SdrLayerNameItem(pLayer->GetName()));
    const SdrLayerAdmin* pLayAd=pPage!=nullptr ? &pPage->GetLayerAdmin() : pModel!=nullptr ? &pModel->GetLayerAdmin() : nullptr;
    if (pLayAd!=nullptr) {
        const SdrLayer* pLayer=pLayAd->GetLayerPerID(GetLayer());
        if (pLayer!=nullptr) {
            rAttr.Put(SdrLayerNameItem(pLayer->GetName()));
        }
    }
    Point aRef1(rSnap.Center());
    Point aRef2(aRef1); aRef2.AdjustY( 1 );
@@ -2302,15 +2309,15 @@ void extractLineContourFromPrimitive2DSequence(
}


SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)
SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDash)
{
    SdrObject* pRetval(nullptr);
    bool bNoChange(true);

    if(LineGeometryUsageIsNecessary())
    if(pRet->LineGeometryUsageIsNecessary())
    {
        basegfx::B2DPolyPolygon aMergedLineFillPolyPolygon;
        basegfx::B2DPolyPolygon aMergedHairlinePolyPolygon;
        const drawinglayer::primitive2d::Primitive2DContainer xSequence(GetViewContact().getViewIndependentPrimitive2DContainer());
        const drawinglayer::primitive2d::Primitive2DContainer xSequence(pRet->GetViewContact().getViewIndependentPrimitive2DContainer());

        if(!xSequence.empty())
        {
@@ -2338,7 +2345,7 @@ SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)

        if(aMergedLineFillPolyPolygon.count() || (bForceLineDash && aMergedHairlinePolyPolygon.count()))
        {
            SfxItemSet aSet(GetMergedItemSet());
            SfxItemSet aSet(pRet->GetMergedItemSet());
            drawing::FillStyle eOldFillStyle = aSet.Get(XATTR_FILLSTYLE).GetValue();
            SdrPathObj* aLinePolygonPart = nullptr;
            SdrPathObj* aLineHairlinePart = nullptr;
@@ -2347,10 +2354,8 @@ SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)
            if(aMergedLineFillPolyPolygon.count())
            {
                // create SdrObject for filled line geometry
                aLinePolygonPart = new SdrPathObj(
                    getSdrModelFromSdrObject(),
                    OBJ_PATHFILL,
                    aMergedLineFillPolyPolygon);
                aLinePolygonPart = new SdrPathObj(OBJ_PATHFILL, aMergedLineFillPolyPolygon);
                aLinePolygonPart->SetModel(pRet->GetModel());

                // correct item properties
                aSet.Put(XLineWidthItem(0));
@@ -2370,10 +2375,8 @@ SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)
                // OBJ_PATHLINE is necessary here, not OBJ_PATHFILL. This is intended
                // to get a non-filled object. If the poly is closed, the PathObj takes care for
                // the correct closed state.
                aLineHairlinePart = new SdrPathObj(
                    getSdrModelFromSdrObject(),
                    OBJ_PATHLINE,
                    aMergedHairlinePolyPolygon);
                aLineHairlinePart = new SdrPathObj(OBJ_PATHLINE, aMergedHairlinePolyPolygon);
                aLineHairlinePart->SetModel(pRet->GetModel());

                aSet.Put(XLineWidthItem(0));
                aSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
@@ -2393,7 +2396,7 @@ SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)

            // check if original geometry should be added (e.g. filled and closed)
            bool bAddOriginalGeometry(false);
            SdrPathObj* pPath = dynamic_cast<SdrPathObj*>(this);
            SdrPathObj* pPath = dynamic_cast<SdrPathObj*>( pRet );

            if(pPath && pPath->IsClosed())
            {
@@ -2406,17 +2409,20 @@ SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)
            // do we need a group?
            if(bBuildGroup || bAddOriginalGeometry)
            {
                SdrObject* pGroup = new SdrObjGroup(getSdrModelFromSdrObject());
                SdrObject* pGroup = new SdrObjGroup;
                pGroup->SetModel(pRet->GetModel());

                if(bAddOriginalGeometry)
                {
                    // Add a clone of the original geometry.
                    aSet.ClearItem();
                    aSet.Put(GetMergedItemSet());
                    aSet.Put(pRet->GetMergedItemSet());
                    aSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
                    aSet.Put(XLineWidthItem(0));

                    SdrObject* pClone = Clone();
                    SdrObject* pClone = pRet->Clone();

                    pClone->SetModel(pRet->GetModel());
                    pClone->SetMergedItemSet(aSet);

                    pGroup->GetSubList()->NbcInsertObject(pClone);
@@ -2432,30 +2438,38 @@ SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash)
                    pGroup->GetSubList()->NbcInsertObject(aLineHairlinePart);
                }

                pRetval = pGroup;
                pRet = pGroup;

                // be more careful with the state describing bool
                bNoChange = false;
            }
            else
            {
                if(aLinePolygonPart)
                {
                    pRetval = aLinePolygonPart;
                    pRet = aLinePolygonPart;
                    // be more careful with the state describing bool
                    bNoChange = false;
                }
                else if(aLineHairlinePart)
                {
                    pRetval = aLineHairlinePart;
                    pRet = aLineHairlinePart;
                    // be more careful with the state describing bool
                    bNoChange = false;
                }
            }
        }
    }

    if(nullptr == pRetval)
    if(bNoChange)
    {
        // due to current method usage, create and return a clone when nothing has changed
        SdrObject* pClone = Clone();
        pRetval = pClone;
        SdrObject* pClone = pRet->Clone();
        pClone->SetModel(pRet->GetModel());
        pRet = pClone;
    }

    return pRetval;
    return pRet;
}


@@ -2483,7 +2497,8 @@ SdrObject* SdrObject::ConvertToContourObj(SdrObject* pRet, bool bForceLineDash) 
    if(dynamic_cast<const SdrObjGroup*>( pRet) !=  nullptr)
    {
        SdrObjList* pObjList2 = pRet->GetSubList();
        SdrObject* pGroup = new SdrObjGroup(getSdrModelFromSdrObject());
        SdrObject* pGroup = new SdrObjGroup;
        pGroup->SetModel(pRet->GetModel());

        for(size_t a=0; a<pObjList2->GetObjCount(); ++a)
        {
@@ -2503,7 +2518,7 @@ SdrObject* SdrObject::ConvertToContourObj(SdrObject* pRet, bool bForceLineDash) 
            pPathObj->SetPathPoly(basegfx::utils::simplifyCurveSegments(pPathObj->GetPathPoly()));
        }

        pRet = pRet->ImpConvertToContourObj(bForceLineDash);
        pRet = ImpConvertToContourObj(pRet, bForceLineDash);
    }

    // #i73441# preserve LayerID
@@ -2586,10 +2601,10 @@ void SdrObject::SetPrintable(bool bPrn)
    {
        bNoPrint=!bPrn;
        SetChanged();
        if (IsInserted())
        if (IsInserted() && pModel!=nullptr)
        {
            SdrHint aHint(SdrHintKind::ObjectChange, *this);
            getSdrModelFromSdrObject().Broadcast(aHint);
            pModel->Broadcast(aHint);
        }
    }
}
@@ -2600,10 +2615,10 @@ void SdrObject::SetVisible(bool bVisible)
    {
        mbVisible = bVisible;
        SetChanged();
        if (IsInserted())
        if (IsInserted() && pModel!=nullptr)
        {
            SdrHint aHint(SdrHintKind::ObjectChange, *this);
            getSdrModelFromSdrObject().Broadcast(aHint);
            pModel->Broadcast(aHint);
        }
    }
}
@@ -2729,6 +2744,15 @@ void SdrObject::SendUserCall(SdrUserCallType eUserCall, const tools::Rectangle& 
    }
}

// change ItemPool for this object
void SdrObject::MigrateItemPool(SfxItemPool* pSrcPool, SfxItemPool* pDestPool, SdrModel* pNewModel)
{
    if(pSrcPool && pDestPool && (pSrcPool != pDestPool))
    {
        GetProperties().MoveToItemPool(pSrcPool, pDestPool, pNewModel);
    }
}

void SdrObject::impl_setUnoShape( const uno::Reference< uno::XInterface >& _rxUnoShape )
{
    const uno::Reference< uno::XInterface>& xOldUnoShape( maWeakUnoShape );
@@ -2858,7 +2882,7 @@ bool SdrObject::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPo
    basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top());

    // position maybe relative to anchorpos, convert
    if(getSdrModelFromSdrObject().IsWriter())
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
@@ -2942,7 +2966,7 @@ void SdrObject::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const ba
    }

    // if anchor is used, make position relative to it
    if(getSdrModelFromSdrObject().IsWriter())
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
@@ -2961,7 +2985,9 @@ void SdrObject::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const ba
// Give info if object is in destruction
bool SdrObject::IsInDestruction() const
{
    return getSdrModelFromSdrObject().IsInDestruction();
    if(pModel)
        return pModel->IsInDestruction();
    return false;
}

// return if fill is != drawing::FillStyle_NONE
@@ -3030,9 +3056,9 @@ SdrDelayBroadcastObjectChange::~SdrDelayBroadcastObjectChange()
}


SdrObject* SdrObjFactory::CreateObjectFromFactory(SdrModel& rSdrModel, SdrInventor nInventor, sal_uInt16 nObjIdentifier)
SdrObject* SdrObjFactory::CreateObjectFromFactory( SdrInventor nInventor, sal_uInt16 nObjIdentifier  )
{
    SdrObjCreatorParams aParams { nInventor, nObjIdentifier, rSdrModel };
    SdrObjCreatorParams aParams { nInventor, nObjIdentifier };
    for (const auto & i : ImpGetUserMakeObjHdl()) {
        SdrObject* pObj = i.Call(aParams);
        if (pObj) {
@@ -3042,134 +3068,55 @@ SdrObject* SdrObjFactory::CreateObjectFromFactory(SdrModel& rSdrModel, SdrInvent
    return nullptr;
}

SdrObject* SdrObjFactory::MakeNewObject(
    SdrModel& rSdrModel,
    SdrInventor nInventor,
    sal_uInt16 nIdentifier,
    SdrPage* pPage,
    const tools::Rectangle* pSnapRect)
SdrObject* SdrObjFactory::MakeNewObject(SdrInventor nInvent, sal_uInt16 nIdent, SdrPage* pPage, SdrModel* pModel)
{
    SdrObject* pObj(nullptr);
    bool bSetSnapRect(nullptr != pSnapRect);
    if (!pModel && pPage)
        pModel = pPage->GetModel();

    if (nInventor == SdrInventor::Default)
    SdrObject* pObj = nullptr;

    if (nInvent == SdrInventor::Default)
    {
        switch (nIdentifier)
        switch (nIdent)
        {
            case OBJ_MEASURE:
            {
                if(nullptr != pSnapRect)
                {
                    pObj = new SdrMeasureObj(
                        rSdrModel,
                        pSnapRect->TopLeft(),
                        pSnapRect->BottomRight());
                }
                else
                {
                    pObj = new SdrMeasureObj(rSdrModel);
                }
            }
            break;
            case OBJ_LINE:
            {
                if(nullptr != pSnapRect)
                {
                    basegfx::B2DPolygon aPoly;

                    aPoly.append(
                        basegfx::B2DPoint(
                            pSnapRect->Left(),
                            pSnapRect->Top()));
                    aPoly.append(
                        basegfx::B2DPoint(
                            pSnapRect->Right(),
                            pSnapRect->Bottom()));
                    pObj = new SdrPathObj(
                        rSdrModel,
                        OBJ_LINE,
                        basegfx::B2DPolyPolygon(aPoly));
                }
                else
                {
                    pObj = new SdrPathObj(
                        rSdrModel,
                        OBJ_LINE);
                }
            }
            break;
            case OBJ_TEXT:
            case OBJ_TEXTEXT:
            case OBJ_TITLETEXT:
            case OBJ_OUTLINETEXT:
            {
                if(nullptr != pSnapRect)
                {
                    pObj = new SdrRectObj(
                        rSdrModel,
                        static_cast<SdrObjKind>(nIdentifier),
                        *pSnapRect);
                    bSetSnapRect = false;
                }
                else
                {
                    pObj = new SdrRectObj(
                        rSdrModel,
                        static_cast<SdrObjKind>(nIdentifier));
                }
            }
            break;
            case OBJ_CIRC:
            case OBJ_SECT:
            case OBJ_CARC:
            case OBJ_CCUT:
            {
                if(nullptr != pSnapRect)
                {
                    pObj = new SdrCircObj(
                        rSdrModel,
                        static_cast<SdrObjKind>(nIdentifier),
                        *pSnapRect);
                    bSetSnapRect = false;
                }
                else
                {
                    pObj = new SdrCircObj(
                        rSdrModel,
                        static_cast<SdrObjKind>(nIdentifier));
                }
            }
            break;
            case sal_uInt16(OBJ_NONE       ): pObj=new SdrObject(rSdrModel);                   break;
            case sal_uInt16(OBJ_GRUP       ): pObj=new SdrObjGroup(rSdrModel);                 break;
            case sal_uInt16(OBJ_POLY       ): pObj=new SdrPathObj(rSdrModel, OBJ_POLY       ); break;
            case sal_uInt16(OBJ_PLIN       ): pObj=new SdrPathObj(rSdrModel, OBJ_PLIN       ); break;
            case sal_uInt16(OBJ_PATHLINE   ): pObj=new SdrPathObj(rSdrModel, OBJ_PATHLINE   ); break;
            case sal_uInt16(OBJ_PATHFILL   ): pObj=new SdrPathObj(rSdrModel, OBJ_PATHFILL   ); break;
            case sal_uInt16(OBJ_FREELINE   ): pObj=new SdrPathObj(rSdrModel, OBJ_FREELINE   ); break;
            case sal_uInt16(OBJ_FREEFILL   ): pObj=new SdrPathObj(rSdrModel, OBJ_FREEFILL   ); break;
            case sal_uInt16(OBJ_PATHPOLY   ): pObj=new SdrPathObj(rSdrModel, OBJ_POLY       ); break;
            case sal_uInt16(OBJ_PATHPLIN   ): pObj=new SdrPathObj(rSdrModel, OBJ_PLIN       ); break;
            case sal_uInt16(OBJ_EDGE       ): pObj=new SdrEdgeObj(rSdrModel);                  break;
            case sal_uInt16(OBJ_RECT       ): pObj=new SdrRectObj(rSdrModel);                  break;
            case sal_uInt16(OBJ_GRAF       ): pObj=new SdrGrafObj(rSdrModel);                  break;
            case sal_uInt16(OBJ_OLE2       ): pObj=new SdrOle2Obj(rSdrModel);                  break;
            case sal_uInt16(OBJ_FRAME      ): pObj=new SdrOle2Obj(rSdrModel, true);            break;
            case sal_uInt16(OBJ_CAPTION    ): pObj=new SdrCaptionObj(rSdrModel);               break;
            case sal_uInt16(OBJ_PAGE       ): pObj=new SdrPageObj(rSdrModel);                  break;
            case sal_uInt16(OBJ_UNO        ): pObj=new SdrUnoObj(rSdrModel, OUString());       break;
            case sal_uInt16(OBJ_CUSTOMSHAPE  ): pObj=new SdrObjCustomShape(rSdrModel);       break;
            case sal_uInt16(OBJ_NONE       ): pObj=new SdrObject;                   break;
            case sal_uInt16(OBJ_GRUP       ): pObj=new SdrObjGroup;                 break;
            case sal_uInt16(OBJ_LINE       ): pObj=new SdrPathObj(OBJ_LINE       ); break;
            case sal_uInt16(OBJ_POLY       ): pObj=new SdrPathObj(OBJ_POLY       ); break;
            case sal_uInt16(OBJ_PLIN       ): pObj=new SdrPathObj(OBJ_PLIN       ); break;
            case sal_uInt16(OBJ_PATHLINE   ): pObj=new SdrPathObj(OBJ_PATHLINE   ); break;
            case sal_uInt16(OBJ_PATHFILL   ): pObj=new SdrPathObj(OBJ_PATHFILL   ); break;
            case sal_uInt16(OBJ_FREELINE   ): pObj=new SdrPathObj(OBJ_FREELINE   ); break;
            case sal_uInt16(OBJ_FREEFILL   ): pObj=new SdrPathObj(OBJ_FREEFILL   ); break;
            case sal_uInt16(OBJ_PATHPOLY   ): pObj=new SdrPathObj(OBJ_POLY       ); break;
            case sal_uInt16(OBJ_PATHPLIN   ): pObj=new SdrPathObj(OBJ_PLIN       ); break;
            case sal_uInt16(OBJ_EDGE       ): pObj=new SdrEdgeObj;                  break;
            case sal_uInt16(OBJ_RECT       ): pObj=new SdrRectObj;                  break;
            case sal_uInt16(OBJ_CIRC       ): pObj=new SdrCircObj(OBJ_CIRC       ); break;
            case sal_uInt16(OBJ_SECT       ): pObj=new SdrCircObj(OBJ_SECT       ); break;
            case sal_uInt16(OBJ_CARC       ): pObj=new SdrCircObj(OBJ_CARC       ); break;
            case sal_uInt16(OBJ_CCUT       ): pObj=new SdrCircObj(OBJ_CCUT       ); break;
            case sal_uInt16(OBJ_TEXT       ): pObj=new SdrRectObj(OBJ_TEXT       ); break;
            case sal_uInt16(OBJ_TEXTEXT    ): pObj=new SdrRectObj(OBJ_TEXTEXT    ); break;
            case sal_uInt16(OBJ_TITLETEXT  ): pObj=new SdrRectObj(OBJ_TITLETEXT  ); break;
            case sal_uInt16(OBJ_OUTLINETEXT): pObj=new SdrRectObj(OBJ_OUTLINETEXT); break;
            case sal_uInt16(OBJ_MEASURE    ): pObj=new SdrMeasureObj;               break;
            case sal_uInt16(OBJ_GRAF       ): pObj=new SdrGrafObj;                  break;
            case sal_uInt16(OBJ_OLE2       ): pObj=new SdrOle2Obj;                  break;
            case sal_uInt16(OBJ_FRAME      ): pObj=new SdrOle2Obj(true);            break;
            case sal_uInt16(OBJ_CAPTION    ): pObj=new SdrCaptionObj;               break;
            case sal_uInt16(OBJ_PAGE       ): pObj=new SdrPageObj;                  break;
            case sal_uInt16(OBJ_UNO        ): pObj=new SdrUnoObj(OUString());       break;
            case sal_uInt16(OBJ_CUSTOMSHAPE  ): pObj=new SdrObjCustomShape();       break;
#if HAVE_FEATURE_AVMEDIA
            case sal_uInt16(OBJ_MEDIA      ): pObj=new SdrMediaObj(rSdrModel);               break;
            case sal_uInt16(OBJ_MEDIA      ): pObj=new SdrMediaObj();               break;
#endif
            case sal_uInt16(OBJ_TABLE      ): pObj=new sdr::table::SdrTableObj(rSdrModel);   break;
            case sal_uInt16(OBJ_TABLE      ): pObj=new sdr::table::SdrTableObj(pModel);   break;
        }
    }

    if (!pObj)
    {
        pObj = CreateObjectFromFactory(rSdrModel, nInventor, nIdentifier);
    }
        pObj = CreateObjectFromFactory(nInvent, nIdent);

    if (!pObj)
    {
@@ -3177,16 +3124,99 @@ SdrObject* SdrObjFactory::MakeNewObject(
        return nullptr;
    }

    if(nullptr != pPage)
    {
    if (pPage)
        pObj->SetPage(pPage);
    else if (pModel)
        pObj->SetModel(pModel);

    return pObj;
}

SdrObject* SdrObjFactory::MakeNewObject(
    SdrInventor nInventor, sal_uInt16 nIdentifier, const tools::Rectangle& rSnapRect, SdrPage* pPage )
{
    SdrModel* pModel = pPage ? pPage->GetModel() : nullptr;

    SdrObject* pObj = nullptr;

    bool bSetSnapRect = true;

    if (nInventor == SdrInventor::Default)
    {
        switch (nIdentifier)
        {
            case OBJ_MEASURE:
            {
                pObj = new SdrMeasureObj(rSnapRect.TopLeft(), rSnapRect.BottomRight());
            }
            break;
            case OBJ_LINE:
            {
                basegfx::B2DPolygon aPoly;
                aPoly.append(basegfx::B2DPoint(rSnapRect.Left(), rSnapRect.Top()));
                aPoly.append(basegfx::B2DPoint(rSnapRect.Right(), rSnapRect.Bottom()));
                pObj = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
            }
            break;
            case OBJ_TEXT:
            case OBJ_TEXTEXT:
            case OBJ_TITLETEXT:
            case OBJ_OUTLINETEXT:
            {
                pObj = new SdrRectObj(static_cast<SdrObjKind>(nIdentifier), rSnapRect);
                bSetSnapRect = false;
            }
            break;
            case OBJ_CIRC:
            case OBJ_SECT:
            case OBJ_CARC:
            case OBJ_CCUT:
            {
                pObj = new SdrCircObj(static_cast<SdrObjKind>(nIdentifier), rSnapRect);
                bSetSnapRect = false;
            }
            break;
            case sal_uInt16(OBJ_NONE       ): pObj=new SdrObject;                   break;
            case sal_uInt16(OBJ_GRUP       ): pObj=new SdrObjGroup;                 break;
            case sal_uInt16(OBJ_POLY       ): pObj=new SdrPathObj(OBJ_POLY       ); break;
            case sal_uInt16(OBJ_PLIN       ): pObj=new SdrPathObj(OBJ_PLIN       ); break;
            case sal_uInt16(OBJ_PATHLINE   ): pObj=new SdrPathObj(OBJ_PATHLINE   ); break;
            case sal_uInt16(OBJ_PATHFILL   ): pObj=new SdrPathObj(OBJ_PATHFILL   ); break;
            case sal_uInt16(OBJ_FREELINE   ): pObj=new SdrPathObj(OBJ_FREELINE   ); break;
            case sal_uInt16(OBJ_FREEFILL   ): pObj=new SdrPathObj(OBJ_FREEFILL   ); break;
            case sal_uInt16(OBJ_PATHPOLY   ): pObj=new SdrPathObj(OBJ_POLY       ); break;
            case sal_uInt16(OBJ_PATHPLIN   ): pObj=new SdrPathObj(OBJ_PLIN       ); break;
            case sal_uInt16(OBJ_EDGE       ): pObj=new SdrEdgeObj;                  break;
            case sal_uInt16(OBJ_RECT       ): pObj=new SdrRectObj;                  break;
            case sal_uInt16(OBJ_GRAF       ): pObj=new SdrGrafObj;                  break;
            case sal_uInt16(OBJ_OLE2       ): pObj=new SdrOle2Obj;                  break;
            case sal_uInt16(OBJ_FRAME      ): pObj=new SdrOle2Obj(true);            break;
            case sal_uInt16(OBJ_CAPTION    ): pObj=new SdrCaptionObj;               break;
            case sal_uInt16(OBJ_PAGE       ): pObj=new SdrPageObj;                  break;
            case sal_uInt16(OBJ_UNO        ): pObj=new SdrUnoObj(OUString());       break;
            case sal_uInt16(OBJ_CUSTOMSHAPE  ): pObj=new SdrObjCustomShape();       break;
#if HAVE_FEATURE_AVMEDIA
            case sal_uInt16(OBJ_MEDIA      ): pObj=new SdrMediaObj();               break;
#endif
            case sal_uInt16(OBJ_TABLE      ): pObj=new sdr::table::SdrTableObj(pModel);   break;
        }
    }

    if(bSetSnapRect && nullptr != pSnapRect)
    if (!pObj)
        pObj = CreateObjectFromFactory(nInventor, nIdentifier);

    if (!pObj)
    {
        pObj->SetSnapRect(*pSnapRect);
        // Well, if no one wants it...
        return nullptr;
    }

    if (pPage)
        pObj->SetPage(pPage);

    if (bSetSnapRect)
        pObj->SetSnapRect(rSnapRect);

    return pObj;
}

diff --git a/svx/source/svdraw/svdocapt.cxx b/svx/source/svdraw/svdocapt.cxx
index cd688f3..00cb7de 100644
--- a/svx/source/svdraw/svdocapt.cxx
+++ b/svx/source/svdraw/svdocapt.cxx
@@ -189,19 +189,16 @@ sdr::contact::ViewContact* SdrCaptionObj::CreateObjectSpecificViewContact()
}


SdrCaptionObj::SdrCaptionObj(SdrModel& rSdrModel)
:   SdrRectObj(rSdrModel, OBJ_TEXT),
SdrCaptionObj::SdrCaptionObj():
    SdrRectObj(OBJ_TEXT),
    aTailPoly(3),  // default size: 3 points = 2 lines
    mbSpecialTextBoxShadow(false),
    mbFixedTail(false)
{
}

SdrCaptionObj::SdrCaptionObj(
    SdrModel& rSdrModel,
    const tools::Rectangle& rRect,
    const Point& rTail)
:   SdrRectObj(rSdrModel, OBJ_TEXT,rRect),
SdrCaptionObj::SdrCaptionObj(const tools::Rectangle& rRect, const Point& rTail):
    SdrRectObj(OBJ_TEXT,rRect),
    aTailPoly(3),  // default size: 3 points = 2 lines
    mbSpecialTextBoxShadow(false),
    mbFixedTail(false)
@@ -235,23 +232,9 @@ sal_uInt16 SdrCaptionObj::GetObjIdentifier() const
    return sal_uInt16(OBJ_CAPTION);
}

SdrCaptionObj* SdrCaptionObj::Clone(SdrModel* pTargetModel) const
SdrCaptionObj* SdrCaptionObj::Clone() const
{
    return CloneHelper< SdrCaptionObj >(pTargetModel);
}

SdrCaptionObj& SdrCaptionObj::operator=(const SdrCaptionObj& rObj)
{
    if( this == &rObj )
        return *this;
    SdrRectObj::operator=(rObj);

    aTailPoly = rObj.aTailPoly;
    mbSpecialTextBoxShadow = rObj.mbSpecialTextBoxShadow;
    mbFixedTail = rObj.mbFixedTail;
    maFixedTailPos = rObj.maFixedTailPos;

    return *this;
    return CloneHelper< SdrCaptionObj >();
}

OUString SdrCaptionObj::TakeObjNameSingul() const
@@ -680,6 +663,12 @@ Point SdrCaptionObj::GetSnapPoint(sal_uInt32 /*i*/) const
    return Point(0,0);
}

void SdrCaptionObj::SetModel(SdrModel* pNewModel)
{
    SdrRectObj::SetModel(pNewModel);
    ImpRecalcTail();
}

void SdrCaptionObj::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
{
    SdrRectObj::Notify(rBC,rHint);
@@ -717,9 +706,8 @@ SdrObject* SdrCaptionObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
        if (pOL!=nullptr) { pRet=pRect; bInsTail = false; }
        if (pOL==nullptr) pOL=pRect->GetSubList();
        if (pOL!=nullptr) { pRet=pRect; bInsRect = false; }
        if (pOL==nullptr)
        {
            SdrObjGroup* pGrp = new SdrObjGroup(getSdrModelFromSdrObject());
        if (pOL==nullptr) {
            SdrObjGroup* pGrp=new SdrObjGroup;
            pOL=pGrp->GetSubList();
            pRet=pGrp;
        }
@@ -759,8 +747,7 @@ void SdrCaptionObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons
    handleNegativeScale(aScale, &fRotate);

    // force metric to pool metric
    MapUnit eMapUnit(getSdrModelFromSdrObject().GetItemPool().GetMetric(0));

    MapUnit eMapUnit = pModel->GetItemPool().GetMetric(0);
    if(eMapUnit != MapUnit::Map100thMM)
    {
        switch(eMapUnit)
@@ -785,7 +772,7 @@ void SdrCaptionObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons
    }

    // if anchor is used, make position relative to it
    if(getSdrModelFromSdrObject().IsWriter())
    if( pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
diff --git a/svx/source/svdraw/svdocirc.cxx b/svx/source/svdraw/svdocirc.cxx
index 1dc049f..dc87f9a 100644
--- a/svx/source/svdraw/svdocirc.cxx
+++ b/svx/source/svdraw/svdocirc.cxx
@@ -104,10 +104,8 @@ sdr::contact::ViewContact* SdrCircObj::CreateObjectSpecificViewContact()
    return new sdr::contact::ViewContactOfSdrCircObj(*this);
}

SdrCircObj::SdrCircObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewKind)
:   SdrRectObj(rSdrModel)

SdrCircObj::SdrCircObj(SdrObjKind eNewKind)
{
    nStartAngle=0;
    nEndAngle=36000;
@@ -115,11 +113,8 @@ SdrCircObj::SdrCircObj(
    bClosedObj=eNewKind!=OBJ_CARC;
}

SdrCircObj::SdrCircObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewKind,
    const tools::Rectangle& rRect)
:   SdrRectObj(rSdrModel, rRect)
SdrCircObj::SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect):
    SdrRectObj(rRect)
{
    nStartAngle=0;
    nEndAngle=36000;
@@ -127,13 +122,8 @@ SdrCircObj::SdrCircObj(
    bClosedObj=eNewKind!=OBJ_CARC;
}

SdrCircObj::SdrCircObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewKind,
    const tools::Rectangle& rRect,
    long nNewStartWink,
    long nNewEndWink)
:   SdrRectObj(rSdrModel, rRect)
SdrCircObj::SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect, long nNewStartWink, long nNewEndWink):
    SdrRectObj(rRect)
{
    long nAngleDif=nNewEndWink-nNewStartWink;
    nStartAngle=NormAngle360(nNewStartWink);
@@ -348,22 +338,9 @@ OUString SdrCircObj::TakeObjNamePlural() const
    return ImpGetResStr(pID);
}

SdrCircObj* SdrCircObj::Clone(SdrModel* pTargetModel) const
SdrCircObj* SdrCircObj::Clone() const
{
    return CloneHelper< SdrCircObj >(pTargetModel);
}

SdrCircObj& SdrCircObj::operator=(const SdrCircObj& rObj)
{
    if( this == &rObj )
        return *this;
    SdrRectObj::operator=(rObj);

    meCircleKind = rObj.meCircleKind;
    nStartAngle = rObj.nStartAngle;
    nEndAngle = rObj.nEndAngle;

    return *this;
    return CloneHelper< SdrCircObj >();
}

basegfx::B2DPolyPolygon SdrCircObj::TakeXorPoly() const
@@ -599,7 +576,7 @@ OUString SdrCircObj::getSpecialDragComment(const SdrDragStat& rDrag) const
                nAngle = pU->nEnd;
            }

            aBuf.append(SdrModel::GetAngleString(nAngle));
            aBuf.append(GetAngleStr(nAngle));
            aBuf.append(')');
        }

@@ -617,7 +594,7 @@ OUString SdrCircObj::getSpecialDragComment(const SdrDragStat& rDrag) const
            ImpTakeDescriptionStr(STR_DragCircAngle, aStr);
            OUStringBuffer aBuf(aStr);
            aBuf.append(" (");
            aBuf.append(SdrModel::GetAngleString(nAngle));
            aBuf.append(GetAngleStr(nAngle));
            aBuf.append(')');

            return aBuf.makeStringAndClear();
diff --git a/svx/source/svdraw/svdoedge.cxx b/svx/source/svdraw/svdoedge.cxx
index ce5a636..45203c3 100644
--- a/svx/source/svdraw/svdoedge.cxx
+++ b/svx/source/svdraw/svdoedge.cxx
@@ -161,8 +161,8 @@ sdr::contact::ViewContact* SdrEdgeObj::CreateObjectSpecificViewContact()
}


SdrEdgeObj::SdrEdgeObj(SdrModel& rSdrModel)
:   SdrTextObj(rSdrModel),
SdrEdgeObj::SdrEdgeObj()
:   SdrTextObj(),
    nNotifyingCount(0),
    bEdgeTrackDirty(false),
    bEdgeTrackUserDefined(false),
@@ -520,14 +520,13 @@ void SdrEdgeObj::ImpSetTailPoint(bool bTail1, const Point& rPt)

void SdrEdgeObj::ImpDirtyEdgeTrack()
{
    if ( !bEdgeTrackUserDefined || !getSdrModelFromSdrObject().isLocked() )
    if ( !bEdgeTrackUserDefined || !(GetModel() && GetModel()->isLocked()) )
        bEdgeTrackDirty = true;
}

void SdrEdgeObj::ImpUndirtyEdgeTrack()
{
    if (bEdgeTrackDirty && getSdrModelFromSdrObject().isLocked())
    {
    if (bEdgeTrackDirty && (GetModel() && GetModel()->isLocked()) ) {
        ImpRecalcEdgeTrack();
    }
}
@@ -541,7 +540,7 @@ void SdrEdgeObj::ImpRecalcEdgeTrack()
    }

    // #i120437# also not when model locked during import, but remember
    if(getSdrModelFromSdrObject().isLocked())
    if(!GetModel() || GetModel()->isLocked())
    {
        mbSuppressed = true;
        return;
@@ -1616,9 +1615,9 @@ void SdrEdgeObj::Reformat()
    }
}

SdrEdgeObj* SdrEdgeObj::Clone(SdrModel* pTargetModel) const
SdrEdgeObj* SdrEdgeObj::Clone() const
{
    return CloneHelper< SdrEdgeObj >(pTargetModel);
    return CloneHelper< SdrEdgeObj >();
}

SdrEdgeObj& SdrEdgeObj::operator=(const SdrEdgeObj& rObj)
@@ -2248,7 +2247,7 @@ void SdrEdgeObj::NbcResize(const Point& rRefPnt, const Fraction& aXFact, const F
    ResizeXPoly(*pEdgeTrack,rRefPnt,aXFact,aYFact);

    // if resize is not from paste, forget user distances
    if (!getSdrModelFromSdrObject().IsPasteResize())
    if (!GetModel() || !GetModel()->IsPasteResize())
    {
        aEdgeInfo.aObj1Line2 = Point();
        aEdgeInfo.aObj1Line3 = Point();
diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx
index e61a09d..1a00716 100644
--- a/svx/source/svdraw/svdograf.cxx
+++ b/svx/source/svdraw/svdograf.cxx
@@ -216,8 +216,8 @@ void SdrGraphicLink::RemoveGraphicUpdater()
::sfx2::SvBaseLink::UpdateResult SdrGraphicLink::DataChanged(
    const OUString& rMimeType, const css::uno::Any & rValue )
{
    SdrModel& rModel(rGrafObj.getSdrModelFromSdrObject());
    sfx2::LinkManager* pLinkManager(rModel.GetLinkManager());
    SdrModel*       pModel      = rGrafObj.GetModel();
    sfx2::LinkManager* pLinkManager= pModel  ? pModel->GetLinkManager() : nullptr;

    if( pLinkManager && rValue.hasValue() )
    {
@@ -325,14 +325,15 @@ void SdrGrafObj::onGraphicChanged()
    }
}

SdrGrafObj::SdrGrafObj(SdrModel& rSdrModel)
:   SdrRectObj(rSdrModel)
    ,mpGraphicObject(new GraphicObject)
    ,pGraphicLink(nullptr)
    ,bMirrored(false)
    ,mbIsSignatureLine(false)
    ,mbIsSignatureLineShowSignDate(true)
    ,mbIsSignatureLineCanAddComment(false)

SdrGrafObj::SdrGrafObj()
    : SdrRectObj()
    , mpGraphicObject(new GraphicObject)
    , pGraphicLink(nullptr)
    , bMirrored(false)
    , mbIsSignatureLine(false)
    , mbIsSignatureLineShowSignDate(true)
    , mbIsSignatureLineCanAddComment(false)
{
    mpGraphicObject->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
    onGraphicChanged();
@@ -351,17 +352,14 @@ SdrGrafObj::SdrGrafObj(SdrModel& rSdrModel)
    mbSupportTextIndentingOnLineWidthChange = false;
}

SdrGrafObj::SdrGrafObj(
    SdrModel& rSdrModel,
    const Graphic& rGraphic,
    const tools::Rectangle& rRect)
:   SdrRectObj(rSdrModel, rRect)
    ,mpGraphicObject(new GraphicObject(rGraphic))
    ,pGraphicLink(nullptr)
    ,bMirrored(false)
    ,mbIsSignatureLine(false)
    ,mbIsSignatureLineShowSignDate(true)
    ,mbIsSignatureLineCanAddComment(false)
SdrGrafObj::SdrGrafObj(const Graphic& rGraphic, const tools::Rectangle& rRect)
    : SdrRectObj(rRect)
    , mpGraphicObject(new GraphicObject(rGraphic))
    , pGraphicLink(nullptr)
    , bMirrored(false)
    , mbIsSignatureLine(false)
    , mbIsSignatureLineShowSignDate(true)
    , mbIsSignatureLineCanAddComment(false)
{
    mpGraphicObject->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
    onGraphicChanged();
@@ -380,16 +378,14 @@ SdrGrafObj::SdrGrafObj(
    mbSupportTextIndentingOnLineWidthChange = false;
}

SdrGrafObj::SdrGrafObj(
    SdrModel& rSdrModel,
    const Graphic& rGraphic)
:   SdrRectObj(rSdrModel)
    ,mpGraphicObject(new GraphicObject(rGraphic))
    ,pGraphicLink(nullptr)
    ,bMirrored(false)
    ,mbIsSignatureLine(false)
    ,mbIsSignatureLineShowSignDate(true)
    ,mbIsSignatureLineCanAddComment(false)
SdrGrafObj::SdrGrafObj(const Graphic& rGraphic)
    : SdrRectObj()
    , mpGraphicObject(new GraphicObject(rGraphic))
    , pGraphicLink(nullptr)
    , bMirrored(false)
    , mbIsSignatureLine(false)
    , mbIsSignatureLineShowSignDate(true)
    , mbIsSignatureLineCanAddComment(false)
{
    mpGraphicObject->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) );
    onGraphicChanged();
@@ -485,12 +481,10 @@ Graphic SdrGrafObj::GetTransformedGraphic( SdrGrafObjTransformsAttrs nTransformF
{
    // Refactored most of the code to GraphicObject, where
    // everybody can use e.g. the cropping functionality
    MapMode aDestMap(
        getSdrModelFromSdrObject().GetScaleUnit(),
        Point(),
        getSdrModelFromSdrObject().GetScaleFraction(),
        getSdrModelFromSdrObject().GetScaleFraction());
    const Size aDestSize( GetLogicRect().GetSize() );

    MapMode         aDestMap( pModel->GetScaleUnit(), Point(), pModel->GetScaleFraction(), pModel->GetScaleFraction() );
    const Size      aDestSize( GetLogicRect().GetSize() );

    GraphicAttr aActAttr = GetGraphicAttr(nTransformFlags);

    // Delegate to moved code in GraphicObject
@@ -565,12 +559,11 @@ const Size& SdrGrafObj::GetGrafPrefSize() const
void SdrGrafObj::SetGrafStreamURL( const OUString& rGraphicStreamURL )
{
    mbIsPreview = false;

    if( rGraphicStreamURL.isEmpty() )
    {
        mpGraphicObject->SetUserData();
    }
    else if(getSdrModelFromSdrObject().IsSwapGraphics() )
    else if( pModel->IsSwapGraphics() )
    {
        mpGraphicObject->SetUserData( rGraphicStreamURL );
    }
@@ -587,20 +580,21 @@ Size SdrGrafObj::getOriginalSize() const

    if (aGrafInfo.IsCropped())
    {
        const long aCroppedTop(OutputDevice::LogicToLogic(aGrafInfo.GetTopCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit()));
        const long aCroppedBottom(OutputDevice::LogicToLogic(aGrafInfo.GetBottomCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit()));
        const long aCroppedLeft(OutputDevice::LogicToLogic(aGrafInfo.GetLeftCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit()));
        const long aCroppedRight(OutputDevice::LogicToLogic(aGrafInfo.GetRightCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit()));
        const long aCroppedWidth(aSize.getWidth() - aCroppedLeft + aCroppedRight);
        const long aCroppedHeight(aSize.getHeight() - aCroppedTop + aCroppedBottom);
        long aCroppedTop = OutputDevice::LogicToLogic( aGrafInfo.GetTopCrop(), GetModel()->GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit());
        long aCroppedBottom = OutputDevice::LogicToLogic( aGrafInfo.GetBottomCrop(), GetModel()->GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit());
        long aCroppedLeft = OutputDevice::LogicToLogic( aGrafInfo.GetLeftCrop(), GetModel()->GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit());
        long aCroppedRight = OutputDevice::LogicToLogic( aGrafInfo.GetRightCrop(), GetModel()->GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit());

        long aCroppedWidth = aSize.getWidth() - aCroppedLeft + aCroppedRight;
        long aCroppedHeight = aSize.getHeight() - aCroppedTop + aCroppedBottom;

        aSize = Size ( aCroppedWidth, aCroppedHeight);
    }

    if ( GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel )
        aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapMode(getSdrModelFromSdrObject().GetScaleUnit()));
        aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapMode(GetModel()->GetScaleUnit()));
    else
        aSize = OutputDevice::LogicToLogic(aSize, GetGrafPrefMapMode(), MapMode(getSdrModelFromSdrObject().GetScaleUnit()));
        aSize = OutputDevice::LogicToLogic(aSize, GetGrafPrefMapMode(), MapMode(GetModel()->GetScaleUnit()));

    return aSize;
}
@@ -635,7 +629,7 @@ void SdrGrafObj::ForceSwapIn() const

void SdrGrafObj::ImpRegisterLink()
{
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
    sfx2::LinkManager* pLinkManager = pModel != nullptr ? pModel->GetLinkManager() : nullptr;

    if( pLinkManager != nullptr && pGraphicLink == nullptr )
    {
@@ -651,7 +645,7 @@ void SdrGrafObj::ImpRegisterLink()

void SdrGrafObj::ImpDeregisterLink()
{
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
    sfx2::LinkManager* pLinkManager = pModel != nullptr ? pModel->GetLinkManager() : nullptr;

    if( pLinkManager != nullptr && pGraphicLink!=nullptr)
    {
@@ -736,11 +730,11 @@ bool SdrGrafObj::ImpUpdateGraphicLink( bool bAsynchron ) const

void SdrGrafObj::ImpSetLinkedGraphic( const Graphic& rGraphic )
{
    const bool bIsChanged(getSdrModelFromSdrObject().IsChanged());
    const bool bIsChanged = GetModel()->IsChanged();
    NbcSetGraphic( rGraphic );
    ActionChanged();
    BroadcastObjectChange();
    getSdrModelFromSdrObject().SetChanged(bIsChanged);
    GetModel()->SetChanged( bIsChanged );
}

OUString SdrGrafObj::TakeObjNameSingul() const
@@ -900,9 +894,9 @@ SdrObject* SdrGrafObj::getFullDragClone() const
    return pRetval;
}

SdrGrafObj* SdrGrafObj::Clone(SdrModel* pTargetModel) const
SdrGrafObj* SdrGrafObj::Clone() const
{
    return CloneHelper< SdrGrafObj >(pTargetModel);
    return CloneHelper< SdrGrafObj >();
}

SdrGrafObj& SdrGrafObj::operator=( const SdrGrafObj& rObj )
@@ -1022,14 +1016,14 @@ void SdrGrafObj::SetPage( SdrPage* pNewPage )
            ImpDeregisterLink();
    }

    if(!GetStyleSheet() && pNewPage)
    if(!pModel && !GetStyleSheet() && pNewPage && pNewPage->GetModel())
    {
        // #i119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
        // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
        // from the following :SetPage().
        // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
        // place for convenience currently (works in both versions, is not in the way)
        SfxStyleSheet* pSheet(pNewPage->getSdrModelFromSdrPage().GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj());
        SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();

        if(pSheet)
        {
@@ -1048,6 +1042,28 @@ void SdrGrafObj::SetPage( SdrPage* pNewPage )
        ImpRegisterLink();
}

void SdrGrafObj::SetModel( SdrModel* pNewModel )
{
    bool bChg = pNewModel != pModel;

    if( bChg )
    {
        if( mpGraphicObject->HasUserData() )
        {
            ForceSwapIn();
        }

        if( pGraphicLink != nullptr )
            ImpDeregisterLink();
    }

    // realize model
    SdrRectObj::SetModel(pNewModel);

    if (bChg && !aFileName.isEmpty())
        ImpRegisterLink();
}

void SdrGrafObj::StartAnimation()
{
    SetGrafAnimationAllowed(true);
@@ -1067,15 +1083,11 @@ GDIMetaFile SdrGrafObj::getMetafileFromEmbeddedVectorGraphicData() const
{
    GDIMetaFile aRetval;

    if(isEmbeddedVectorGraphicData())
    if(isEmbeddedVectorGraphicData() && GetModel())
    {
        ScopedVclPtrInstance< VirtualDevice > pOut;
        const tools::Rectangle aBoundRect(GetCurrentBoundRect());
        const MapMode aMap(
            getSdrModelFromSdrObject().GetScaleUnit(),
            Point(),
            getSdrModelFromSdrObject().GetScaleFraction(),
            getSdrModelFromSdrObject().GetScaleFraction());
        const MapMode aMap(GetModel()->GetScaleUnit(), Point(), GetModel()->GetScaleFraction(), GetModel()->GetScaleFraction());

        pOut->EnableOutput(false);
        pOut->SetMapMode(aMap);
@@ -1120,11 +1132,8 @@ SdrObject* SdrGrafObj::DoConvertToPolyObj(bool bBezier, bool bAddText ) const
        case GraphicType::GdiMetafile:
        {
            // Sort into group and return ONLY those objects that can be created from the MetaFile.
            ImpSdrGDIMetaFileImport aFilter(
                getSdrModelFromSdrObject(),
                GetLayer(),
                maRect);
            SdrObjGroup* pGrp = new SdrObjGroup(getSdrModelFromSdrObject());
            ImpSdrGDIMetaFileImport aFilter(*GetModel(), GetLayer(), maRect);
            SdrObjGroup* pGrp = new SdrObjGroup();

            if(aFilter.DoImport(aMtf, *pGrp->GetSubList(), 0))
            {
@@ -1147,6 +1156,7 @@ SdrObject* SdrGrafObj::DoConvertToPolyObj(bool bBezier, bool bAddText ) const

                pRetval = pGrp;
                pGrp->NbcSetLayer(GetLayer());
                pGrp->SetModel(GetModel());

                if(bAddText)
                {
@@ -1188,8 +1198,10 @@ SdrObject* SdrGrafObj::DoConvertToPolyObj(bool bBezier, bool bAddText ) const

                    if(!pGrp)
                    {
                        pGrp = new SdrObjGroup(getSdrModelFromSdrObject());
                        pGrp = new SdrObjGroup();

                        pGrp->NbcSetLayer(GetLayer());
                        pGrp->SetModel(GetModel());
                        pGrp->GetSubList()->NbcInsertObject(pRetval);
                    }

@@ -1323,7 +1335,7 @@ IMPL_LINK(SdrGrafObj, ReplacementSwapHdl, const GraphicObject*, pO, SvStream*)
    // replacement image is always swapped
    if (pO->IsInSwapOut())
    {
        SdrSwapGraphicsMode const nSwapMode(getSdrModelFromSdrObject().GetSwapGraphicsMode());
        SdrSwapGraphicsMode const nSwapMode(pModel->GetSwapGraphicsMode());
        if (nSwapMode & SdrSwapGraphicsMode::TEMP)
        {
            return GRFMGR_AUTOSWAPSTREAM_TEMP;
@@ -1347,13 +1359,13 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, const GraphicObject*, pO, SvStream* )

    if( pO->IsInSwapOut() )
    {
        if( !mbIsPreview && getSdrModelFromSdrObject().IsSwapGraphics() && mpGraphicObject->GetSizeBytes() > 20480 )
        if( pModel && !mbIsPreview && pModel->IsSwapGraphics() && mpGraphicObject->GetSizeBytes() > 20480 )
        {
            // test if this object is visualized from someone
            // ## test only if there are VOCs other than the preview renderer
            if(!GetViewContact().HasViewObjectContacts())
            {
                const SdrSwapGraphicsMode nSwapMode = getSdrModelFromSdrObject().GetSwapGraphicsMode();
                const SdrSwapGraphicsMode nSwapMode = pModel->GetSwapGraphicsMode();

                if( ( pGraphicLink ) &&
                    ( nSwapMode & SdrSwapGraphicsMode::PURGE ) )
@@ -1379,73 +1391,78 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, const GraphicObject*, pO, SvStream* )
    else if( pO->IsInSwapIn() )
    {
        // can be loaded from the original document stream later
        if(mpGraphicObject->HasUserData())
        if( pModel != nullptr )
        {
            ::comphelper::LifecycleProxy proxy;
            OUString aUserData = mpGraphicObject->GetUserData();
            uno::Reference<io::XInputStream> const xStream(
                getSdrModelFromSdrObject().GetDocumentStream(aUserData, proxy));

            std::unique_ptr<SvStream> const pStream( (xStream.is())
                    ? ::utl::UcbStreamHelper::CreateStream(xStream)
                    : nullptr );

            if( pStream != nullptr )
            if(mpGraphicObject->HasUserData())
            {
                Graphic aGraphic;
                ::comphelper::LifecycleProxy proxy;
                OUString aUserData = mpGraphicObject->GetUserData();
                uno::Reference<io::XInputStream> const xStream(
                    pModel->GetDocumentStream(aUserData, proxy));

                std::unique_ptr<css::uno::Sequence< css::beans::PropertyValue > > pFilterData;
                std::unique_ptr<SvStream> const pStream( (xStream.is())
                        ? ::utl::UcbStreamHelper::CreateStream(xStream)
                        : nullptr );

                if(mbInsidePaint && !GetViewContact().HasViewObjectContacts())
                if( pStream != nullptr )
                {
                    pFilterData.reset(new css::uno::Sequence< css::beans::PropertyValue >( 3 ));
                    Graphic aGraphic;

                    const css::awt::Size aPreviewSizeHint( 64, 64 );
                    const bool bAllowPartialStreamRead = true;
                    // create <GfxLink> instance also for previews in order to avoid that its corresponding
                    // data is cleared in the graphic cache entry in case that the preview data equals the complete graphic data
                    const bool bCreateNativeLink = true;
                    (*pFilterData)[ 0 ].Name = "PreviewSizeHint";
                    (*pFilterData)[ 0 ].Value <<= aPreviewSizeHint;
                    (*pFilterData)[ 1 ].Name = "AllowPartialStreamRead";
                    (*pFilterData)[ 1 ].Value <<= bAllowPartialStreamRead;
                    (*pFilterData)[ 2 ].Name = "CreateNativeLink";
                    (*pFilterData)[ 2 ].Value <<= bCreateNativeLink;
                    std::unique_ptr<css::uno::Sequence< css::beans::PropertyValue > > pFilterData;

                    mbIsPreview = true;
                }

                if(!GraphicFilter::GetGraphicFilter().ImportGraphic(
                    aGraphic, aUserData, *pStream,
                    GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::NONE, pFilterData.get()))
                {
                    const OUString aNewUserData( mpGraphicObject->GetUserData() );
                    mpGraphicObject->SetGraphic( aGraphic );
                    if( mbIsPreview )
                    if(mbInsidePaint && !GetViewContact().HasViewObjectContacts())
                    {
                        mpGraphicObject->SetUserData(aNewUserData);
                    }
                    else
                    {
                        mpGraphicObject->SetUserData();
                        pFilterData.reset(new css::uno::Sequence< css::beans::PropertyValue >( 3 ));

                        const css::awt::Size aPreviewSizeHint( 64, 64 );
                        const bool bAllowPartialStreamRead = true;
                        // create <GfxLink> instance also for previews in order to avoid that its corresponding
                        // data is cleared in the graphic cache entry in case that the preview data equals the complete graphic data
                        const bool bCreateNativeLink = true;
                        (*pFilterData)[ 0 ].Name = "PreviewSizeHint";
                        (*pFilterData)[ 0 ].Value <<= aPreviewSizeHint;
                        (*pFilterData)[ 1 ].Name = "AllowPartialStreamRead";
                        (*pFilterData)[ 1 ].Value <<= bAllowPartialStreamRead;
                        (*pFilterData)[ 2 ].Name = "CreateNativeLink";
                        (*pFilterData)[ 2 ].Value <<= bCreateNativeLink;

                        mbIsPreview = true;
                    }

                    // Graphic successfully swapped in.
                    pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
                }
                pFilterData.reset();
                    if(!GraphicFilter::GetGraphicFilter().ImportGraphic(
                        aGraphic, aUserData, *pStream,
                        GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::NONE, pFilterData.get()))
                    {
                        const OUString aNewUserData( mpGraphicObject->GetUserData() );
                        mpGraphicObject->SetGraphic( aGraphic );
                        if( mbIsPreview )
                        {
                            mpGraphicObject->SetUserData(aNewUserData);
                        }
                        else
                        {
                            mpGraphicObject->SetUserData();
                        }

                pStream->ResetError();
                        // Graphic successfully swapped in.
                        pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
                    }
                    pFilterData.reset();

                    pStream->ResetError();
                }
            }
            else if( !ImpUpdateGraphicLink( false ) )
            {
                pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
            }
            else
            {
                pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
            }
        }
        else if( !ImpUpdateGraphicLink( false ) )
        {
            pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
        }
        else
        {
            pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
        }
            pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
    }

    return pRet;
@@ -1464,27 +1481,30 @@ Reference< XInputStream > SdrGrafObj::getInputStream()
{
    Reference< XInputStream > xStream;

    if (mpGraphicObject && GetGraphic().IsLink())
    if( pModel )
    {
        Graphic aGraphic( GetGraphic() );
        GfxLink aLink( aGraphic.GetLink() );
        sal_uInt32 nSize = aLink.GetDataSize();
        const void* pSourceData = static_cast<const void*>(aLink.GetData());
        if( nSize && pSourceData )
        if (mpGraphicObject && GetGraphic().IsLink())
        {
            sal_uInt8 * pBuffer = new sal_uInt8[ nSize ];
            memcpy( pBuffer, pSourceData, nSize );
            Graphic aGraphic( GetGraphic() );
            GfxLink aLink( aGraphic.GetLink() );
            sal_uInt32 nSize = aLink.GetDataSize();
            const void* pSourceData = static_cast<const void*>(aLink.GetData());
            if( nSize && pSourceData )
            {
                sal_uInt8 * pBuffer = new sal_uInt8[ nSize ];
                memcpy( pBuffer, pSourceData, nSize );

            SvMemoryStream* pStream = new SvMemoryStream( static_cast<void*>(pBuffer), static_cast<std::size_t>(nSize), StreamMode::READ );
            pStream->ObjectOwnsMemory( true );
            xStream.set( new utl::OInputStreamWrapper( pStream, true ) );
                SvMemoryStream* pStream = new SvMemoryStream( static_cast<void*>(pBuffer), static_cast<std::size_t>(nSize), StreamMode::READ );
                pStream->ObjectOwnsMemory( true );
                xStream.set( new utl::OInputStreamWrapper( pStream, true ) );
            }
        }
    }

    if (!xStream.is() && !aFileName.isEmpty())
    {
        SvFileStream* pStream = new SvFileStream( aFileName, StreamMode::READ );
        xStream.set( new utl::OInputStreamWrapper( pStream ) );
        if (!xStream.is() && !aFileName.isEmpty())
        {
            SvFileStream* pStream = new SvFileStream( aFileName, StreamMode::READ );
            xStream.set( new utl::OInputStreamWrapper( pStream ) );
        }
    }

    return xStream;
diff --git a/svx/source/svdraw/svdogrp.cxx b/svx/source/svdraw/svdogrp.cxx
index 6311106..d2151f1 100644
--- a/svx/source/svdraw/svdogrp.cxx
+++ b/svx/source/svdraw/svdogrp.cxx
@@ -50,28 +50,32 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <libxml/xmlwriter.h>


// BaseProperties section

sdr::properties::BaseProperties* SdrObjGroup::CreateObjectSpecificProperties()
{
    return new sdr::properties::GroupProperties(*this);
}


// DrawContact section

sdr::contact::ViewContact* SdrObjGroup::CreateObjectSpecificViewContact()
{
    return new sdr::contact::ViewContactOfGroup(*this);
}

SdrObjGroup::SdrObjGroup(SdrModel& rSdrModel)
:   SdrObject(rSdrModel),
    maSdrObjList(),
    aRefPoint(0, 0)

SdrObjGroup::SdrObjGroup()
{
    maSdrObjList.SetOwnerObj(this);
    maSdrObjList.SetListKind(SdrObjListKind::GroupObj);
    pSub.reset( new SdrObjList(nullptr,nullptr) );
    pSub->SetOwnerObj(this);
    pSub->SetListKind(SdrObjListKind::GroupObj);
    bClosedObj=false;
}


SdrObjGroup::~SdrObjGroup()
{
}
@@ -79,9 +83,10 @@ SdrObjGroup::~SdrObjGroup()
void SdrObjGroup::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
{
    rInfo.bNoContortion=false;
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        SdrObjTransformInfoRec aInfo;
        pObj->TakeObjInfo(aInfo);
        if (!aInfo.bMoveAllowed            ) rInfo.bMoveAllowed            =false;
@@ -140,9 +145,10 @@ SdrLayerID SdrObjGroup::GetLayer() const
{
    bool b1st = true;
    SdrLayerID nLay = SdrObject::GetLayer();
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrLayerID nLay1=maSdrObjList.GetObj(i)->GetLayer();
        SdrLayerID nLay1=pOL->GetObj(i)->GetLayer();
        if (b1st) { nLay=nLay1; b1st = false; }
        else if (nLay1!=nLay) return SdrLayerID(0);
    }
@@ -153,9 +159,10 @@ SdrLayerID SdrObjGroup::GetLayer() const
void SdrObjGroup::NbcSetLayer(SdrLayerID nLayer)
{
    SdrObject::NbcSetLayer(nLayer);
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        maSdrObjList.GetObj(i)->NbcSetLayer(nLayer);
        pOL->GetObj(i)->NbcSetLayer(nLayer);
    }
}

@@ -163,27 +170,58 @@ void SdrObjGroup::NbcSetLayer(SdrLayerID nLayer)
void SdrObjGroup::SetObjList(SdrObjList* pNewObjList)
{
    SdrObject::SetObjList(pNewObjList);
    maSdrObjList.SetUpList(pNewObjList);
    pSub->SetUpList(pNewObjList);
}


void SdrObjGroup::SetPage(SdrPage* pNewPage)
{
    SdrObject::SetPage(pNewPage);
    maSdrObjList.SetPage(pNewPage);
    pSub->SetPage(pNewPage);
}


void SdrObjGroup::SetModel(SdrModel* pNewModel)
{
    if(pNewModel!=pModel)
    {
        // #i30648#
        // This method also needs to migrate the used ItemSet
        // when the destination model uses a different pool
        // than the current one. Else it is possible to create
        // SdrObjGroups which reference the old pool which might
        // be destroyed (as the bug shows).
        SdrModel* pOldModel = pModel;

        // test for correct pool in ItemSet; move to new pool if necessary
        if(pNewModel && &GetObjectItemPool() != &pNewModel->GetItemPool())
        {
            MigrateItemPool(&GetObjectItemPool(), &pNewModel->GetItemPool(), pNewModel);
        }

        // call parent
        SdrObject::SetModel(pNewModel);

        // set new model at content
        pSub->SetModel(pNewModel);

        // modify properties
        GetProperties().SetModel(pOldModel, pNewModel);
    }
}


SdrObjList* SdrObjGroup::GetSubList() const
{
    return const_cast< SdrObjList* >(&maSdrObjList);
    return pSub.get();
}

const tools::Rectangle& SdrObjGroup::GetCurrentBoundRect() const
{
    // <aOutRect> has to contain the bounding rectangle
    if ( maSdrObjList.GetObjCount()!=0 )
    if ( pSub->GetObjCount()!=0 )
    {
        const_cast<SdrObjGroup*>(this)->aOutRect = maSdrObjList.GetAllObjBoundRect();
        const_cast<SdrObjGroup*>(this)->aOutRect = pSub->GetAllObjBoundRect();
    }

    return aOutRect;
@@ -192,9 +230,9 @@ const tools::Rectangle& SdrObjGroup::GetCurrentBoundRect() const
const tools::Rectangle& SdrObjGroup::GetSnapRect() const
{
    // <aOutRect> has to contain the bounding rectangle
    if ( maSdrObjList.GetObjCount()!=0 )
    if ( pSub->GetObjCount()!=0 )
    {
        return maSdrObjList.GetAllObjSnapRect();
        return pSub->GetAllObjSnapRect();
    }
    else
    {
@@ -202,24 +240,24 @@ const tools::Rectangle& SdrObjGroup::GetSnapRect() const
    }
}

SdrObjGroup* SdrObjGroup::Clone(SdrModel* pTargetModel) const
SdrObjGroup* SdrObjGroup::Clone() const
{
    return CloneHelper< SdrObjGroup >(pTargetModel);
    return CloneHelper< SdrObjGroup >();
}

SdrObjGroup& SdrObjGroup::operator=(const SdrObjGroup& rObj)
{
    if( this == &rObj )
        return *this;

    // copy SdrObject stuff
    SdrObject::operator=(rObj);

    // #i36404#
    // copy SubList, init model and page first
    SdrObjList& rSourceSubList = *rObj.GetSubList();
    maSdrObjList.SetPage(rSourceSubList.GetPage());
    maSdrObjList.CopyObjects(*rObj.GetSubList());
    pSub->SetPage(rSourceSubList.GetPage());
    pSub->SetModel(rSourceSubList.GetModel());
    pSub->CopyObjects(*rObj.GetSubList());

    // copy local parameters
    aRefPoint  = rObj.aRefPoint;
@@ -231,7 +269,7 @@ OUString SdrObjGroup::TakeObjNameSingul() const
{
    OUStringBuffer sName;

    if(!maSdrObjList.GetObjCount())
    if(!pSub->GetObjCount())
    {
        sName.append(ImpGetResStr(STR_ObjNameSingulGRUPEMPTY));
    }
@@ -256,7 +294,7 @@ OUString SdrObjGroup::TakeObjNameSingul() const

OUString SdrObjGroup::TakeObjNamePlural() const
{
    if (maSdrObjList.GetObjCount()==0)
    if (pSub->GetObjCount()==0)
        return ImpGetResStr(STR_ObjNamePluralGRUPEMPTY);
    return ImpGetResStr(STR_ObjNamePluralGRUP);
}
@@ -270,11 +308,11 @@ void SdrObjGroup::RecalcSnapRect()
basegfx::B2DPolyPolygon SdrObjGroup::TakeXorPoly() const
{
    basegfx::B2DPolyPolygon aRetval;
    const size_t nObjCount(maSdrObjList.GetObjCount());
    const size_t nObjCount(pSub->GetObjCount());

    for(size_t a = 0; a < nObjCount; ++a)
    {
        SdrObject* pObj = maSdrObjList.GetObj(a);
        SdrObject* pObj = pSub->GetObj(a);
        aRetval.append(pObj->TakeXorPoly());
    }

@@ -303,9 +341,9 @@ long SdrObjGroup::GetRotateAngle() const
{
    long nRetval(0);

    if(maSdrObjList.GetObjCount())
    if(pSub->GetObjCount())
    {
        SdrObject* pObj = maSdrObjList.GetObj(0);
        SdrObject* pObj = pSub->GetObj(0);

        nRetval = pObj->GetRotateAngle();
    }
@@ -318,9 +356,9 @@ long SdrObjGroup::GetShearAngle(bool /*bVertical*/) const
{
    long nRetval(0);

    if(maSdrObjList.GetObjCount())
    if(pSub->GetObjCount())
    {
        SdrObject* pObj = maSdrObjList.GetObj(0);
        SdrObject* pObj = pSub->GetObj(0);

        nRetval = pObj->GetShearAngle();
    }
@@ -358,10 +396,11 @@ void SdrObjGroup::NbcSetLogicRect(const tools::Rectangle& rRect)
void SdrObjGroup::NbcMove(const Size& rSiz)
{
    aRefPoint.Move(rSiz);
    if (maSdrObjList.GetObjCount()!=0) {
        const size_t nObjCount = maSdrObjList.GetObjCount();
    if (pSub->GetObjCount()!=0) {
        SdrObjList* pOL=pSub.get();
        const size_t nObjCount = pOL->GetObjCount();
        for (size_t i=0; i<nObjCount; ++i) {
            SdrObject* pObj=maSdrObjList.GetObj(i);
            SdrObject* pObj=pOL->GetObj(i);
            pObj->NbcMove(rSiz);
        }
    } else {
@@ -389,10 +428,11 @@ void SdrObjGroup::NbcResize(const Point& rRef, const Fraction& xFact, const Frac
        }
    }
    ResizePoint(aRefPoint,rRef,xFact,yFact);
    if (maSdrObjList.GetObjCount()!=0) {
        const size_t nObjCount = maSdrObjList.GetObjCount();
    if (pSub->GetObjCount()!=0) {
        SdrObjList* pOL=pSub.get();
        const size_t nObjCount = pOL->GetObjCount();
        for (size_t i=0; i<nObjCount; ++i) {
            SdrObject* pObj=maSdrObjList.GetObj(i);
            SdrObject* pObj=pOL->GetObj(i);
            pObj->NbcResize(rRef,xFact,yFact);
        }
    } else {
@@ -406,9 +446,10 @@ void SdrObjGroup::NbcRotate(const Point& rRef, long nAngle, double sn, double cs
{
    SetGlueReallyAbsolute(true);
    RotatePoint(aRefPoint,rRef,sn,cs);
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        pObj->NbcRotate(rRef,nAngle,sn,cs);
    }
    NbcRotateGluePoints(rRef,nAngle,sn,cs);
@@ -420,9 +461,10 @@ void SdrObjGroup::NbcMirror(const Point& rRef1, const Point& rRef2)
{
    SetGlueReallyAbsolute(true);
    MirrorPoint(aRefPoint,rRef1,rRef2); // implementation missing in SvdEtc!
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        pObj->NbcMirror(rRef1,rRef2);
    }
    NbcMirrorGluePoints(rRef1,rRef2);
@@ -434,9 +476,10 @@ void SdrObjGroup::NbcShear(const Point& rRef, long nAngle, double tn, bool bVShe
{
    SetGlueReallyAbsolute(true);
    ShearPoint(aRefPoint,rRef,tn);
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        pObj->NbcShear(rRef,nAngle,tn,bVShear);
    }
    NbcShearGluePoints(rRef,tn,bVShear);
@@ -449,9 +492,10 @@ void SdrObjGroup::NbcSetAnchorPos(const Point& rPnt)
    aAnchor=rPnt;
    Size aSiz(rPnt.X()-aAnchor.X(),rPnt.Y()-aAnchor.Y());
    aRefPoint.Move(aSiz);
    const size_t nObjCount=maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount=pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        pObj->NbcSetAnchorPos(rPnt);
    }
}
@@ -493,15 +537,16 @@ void SdrObjGroup::Move(const Size& rSiz)
    if (rSiz.Width()!=0 || rSiz.Height()!=0) {
        tools::Rectangle aBoundRect0; if (pUserCall!=nullptr) aBoundRect0=GetLastBoundRect();
        aRefPoint.Move(rSiz);
        if (maSdrObjList.GetObjCount()!=0) {
        if (pSub->GetObjCount()!=0) {
            // first move the connectors, then everything else
            const size_t nObjCount = maSdrObjList.GetObjCount();
            SdrObjList* pOL=pSub.get();
            const size_t nObjCount = pOL->GetObjCount();
            for (size_t i=0; i<nObjCount; ++i) {
                SdrObject* pObj=maSdrObjList.GetObj(i);
                SdrObject* pObj=pOL->GetObj(i);
                if (pObj->IsEdgeObj()) pObj->Move(rSiz);
            }
            for (size_t i=0; i<nObjCount; ++i) {
                SdrObject* pObj=maSdrObjList.GetObj(i);
                SdrObject* pObj=pOL->GetObj(i);
                if (!pObj->IsEdgeObj()) pObj->Move(rSiz);
            }
        } else {
@@ -536,15 +581,16 @@ void SdrObjGroup::Resize(const Point& rRef, const Fraction& xFact, const Fractio
        }
        tools::Rectangle aBoundRect0; if (pUserCall!=nullptr) aBoundRect0=GetLastBoundRect();
        ResizePoint(aRefPoint,rRef,xFact,yFact);
        if (maSdrObjList.GetObjCount()!=0) {
        if (pSub->GetObjCount()!=0) {
            // move the connectors first, everything else afterwards
            const size_t nObjCount = maSdrObjList.GetObjCount();
            SdrObjList* pOL=pSub.get();
            const size_t nObjCount = pOL->GetObjCount();
            for (size_t i=0; i<nObjCount; ++i) {
                SdrObject* pObj=maSdrObjList.GetObj(i);
                SdrObject* pObj=pOL->GetObj(i);
                if (pObj->IsEdgeObj()) pObj->Resize(rRef,xFact,yFact,bUnsetRelative);
            }
            for (size_t i=0; i<nObjCount; ++i) {
                SdrObject* pObj=maSdrObjList.GetObj(i);
                SdrObject* pObj=pOL->GetObj(i);
                if (!pObj->IsEdgeObj()) pObj->Resize(rRef,xFact,yFact,bUnsetRelative);
            }
        } else {
@@ -568,13 +614,14 @@ void SdrObjGroup::Rotate(const Point& rRef, long nAngle, double sn, double cs)
    tools::Rectangle aBoundRect0; if (pUserCall!=nullptr) aBoundRect0=GetLastBoundRect();
    RotatePoint(aRefPoint,rRef,sn,cs);
    // move the connectors first, everything else afterwards
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (pObj->IsEdgeObj()) pObj->Rotate(rRef,nAngle,sn,cs);
    }
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (!pObj->IsEdgeObj()) pObj->Rotate(rRef,nAngle,sn,cs);
    }
    NbcRotateGluePoints(rRef,nAngle,sn,cs);
@@ -591,13 +638,14 @@ void SdrObjGroup::Mirror(const Point& rRef1, const Point& rRef2)
    tools::Rectangle aBoundRect0; if (pUserCall!=nullptr) aBoundRect0=GetLastBoundRect();
    MirrorPoint(aRefPoint,rRef1,rRef2); // implementation missing in SvdEtc!
    // move the connectors first, everything else afterwards
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (pObj->IsEdgeObj()) pObj->Mirror(rRef1,rRef2);
    }
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (!pObj->IsEdgeObj()) pObj->Mirror(rRef1,rRef2);
    }
    NbcMirrorGluePoints(rRef1,rRef2);
@@ -617,13 +665,14 @@ void SdrObjGroup::Shear(const Point& rRef, long nAngle, double tn, bool bVShear)
    tools::Rectangle aBoundRect0; if (pUserCall!=nullptr) aBoundRect0=GetLastBoundRect();
    ShearPoint(aRefPoint,rRef,tn);
    // move the connectors first, everything else afterwards
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (pObj->IsEdgeObj()) pObj->Shear(rRef,nAngle,tn,bVShear);
    }
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (!pObj->IsEdgeObj()) pObj->Shear(rRef,nAngle,tn,bVShear);
    }
    NbcShearGluePoints(rRef,tn,bVShear);
@@ -643,13 +692,14 @@ void SdrObjGroup::SetAnchorPos(const Point& rPnt)
    Size aSiz(rPnt.X()-aAnchor.X(),rPnt.Y()-aAnchor.Y());
    aRefPoint.Move(aSiz);
    // move the connectors first, everything else afterwards
    const size_t nObjCount = maSdrObjList.GetObjCount();
    SdrObjList* pOL=pSub.get();
    const size_t nObjCount = pOL->GetObjCount();
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj=maSdrObjList.GetObj(i);
        SdrObject* pObj=pOL->GetObj(i);
        if (pObj->IsEdgeObj()) pObj->SetAnchorPos(rPnt);
    }
    for (size_t i=0; i<nObjCount; ++i) {
        SdrObject* pObj = maSdrObjList.GetObj(i);
        SdrObject* pObj = pOL->GetObj(i);
        if (!pObj->IsEdgeObj()) pObj->SetAnchorPos(rPnt);
    }
    if (bChg) {
@@ -676,21 +726,22 @@ void SdrObjGroup::SetRelativePos(const Point& rPnt)

void SdrObjGroup::NbcReformatText()
{
    maSdrObjList.NbcReformatAllTextObjects();
    pSub->NbcReformatAllTextObjects();
}

void SdrObjGroup::ReformatText()
{
    maSdrObjList.ReformatAllTextObjects();
    pSub->ReformatAllTextObjects();
}

SdrObject* SdrObjGroup::DoConvertToPolyObj(bool bBezier, bool bAddText) const
{
    SdrObject* pGroup = new SdrObjGroup(getSdrModelFromSdrObject());
    SdrObject* pGroup = new SdrObjGroup;
    pGroup->SetModel(GetModel());

    for(size_t a=0; a<maSdrObjList.GetObjCount(); ++a)
    for(size_t a=0; a<pSub->GetObjCount(); ++a)
    {
        SdrObject* pIterObj = maSdrObjList.GetObj(a);
        SdrObject* pIterObj = pSub->GetObj(a);
        SdrObject* pResult = pIterObj->DoConvertToPolyObj(bBezier, bAddText);

        // pResult can be NULL e.g. for empty objects
@@ -708,7 +759,7 @@ void SdrObjGroup::dumpAsXml(xmlTextWriterPtr pWriter) const

    SdrObject::dumpAsXml(pWriter);

    maSdrObjList.dumpAsXml(pWriter);
    pSub->dumpAsXml(pWriter);
    xmlTextWriterEndElement(pWriter);
}

diff --git a/svx/source/svdraw/svdomeas.cxx b/svx/source/svdraw/svdomeas.cxx
index 9c1f655..63f33c6 100644
--- a/svx/source/svdraw/svdomeas.cxx
+++ b/svx/source/svdraw/svdomeas.cxx
@@ -94,63 +94,71 @@ OUString SdrMeasureObj::TakeRepresentation(SdrMeasureFieldKind eMeasureFieldKind
    {
        case SdrMeasureFieldKind::Value:
        {
            eModUIUnit = getSdrModelFromSdrObject().GetUIUnit();

            if(eMeasureUnit == FUNIT_NONE)
                eMeasureUnit = eModUIUnit;

            sal_Int32 nLen(GetLen(aPt2 - aPt1));
            Fraction aFact(1,1);

            if(eMeasureUnit != eModUIUnit)
            if(pModel)
            {
                // for the unit conversion
                aFact *= GetMapFactor(eModUIUnit, eMeasureUnit).X();
            }
                eModUIUnit = pModel->GetUIUnit();

            if(aMeasureScale.GetNumerator() != aMeasureScale.GetDenominator())
            {
                aFact *= aMeasureScale;
            }
                if(eMeasureUnit == FUNIT_NONE)
                    eMeasureUnit = eModUIUnit;

            if(aFact.GetNumerator() != aFact.GetDenominator())
            {
                // scale via BigInt, to avoid overruns
                nLen = BigMulDiv(nLen, aFact.GetNumerator(), aFact.GetDenominator());
            }
                sal_Int32 nLen(GetLen(aPt2 - aPt1));
                Fraction aFact(1,1);

            if(!aFact.IsValid())
            {
                aStr = "?";
                if(eMeasureUnit != eModUIUnit)
                {
                    // for the unit conversion
                    aFact *= GetMapFactor(eModUIUnit, eMeasureUnit).X();
                }

                if(aMeasureScale.GetNumerator() != aMeasureScale.GetDenominator())
                {
                    aFact *= aMeasureScale;
                }

                if(aFact.GetNumerator() != aFact.GetDenominator())
                {
                    // scale via BigInt, to avoid overruns
                    nLen = BigMulDiv(nLen, aFact.GetNumerator(), aFact.GetDenominator());
                }

                if(!aFact.IsValid())
                {
                    aStr = "?";
                }
                else
                {
                    aStr = pModel->GetMetricString(nLen, true, nNumDigits);
                }

                SvtSysLocale aSysLocale;
                const LocaleDataWrapper& rLocaleDataWrapper = aSysLocale.GetLocaleData();
                sal_Unicode cDec(rLocaleDataWrapper.getNumDecimalSep()[0]);
                sal_Unicode cDecAlt(rLocaleDataWrapper.getNumDecimalSepAlt().toChar());

                if(aStr.indexOf(cDec) != -1 || (cDecAlt && aStr.indexOf(cDecAlt) != -1))
                {
                    sal_Int32 nLen2(aStr.getLength() - 1);

                    while(aStr[nLen2] == '0')
                    {
                        aStr = aStr.copy(0, nLen2);
                        nLen2--;
                    }

                    if(aStr[nLen2] == cDec || (cDecAlt && aStr[nLen2] == cDecAlt))
                    {
                        aStr = aStr.copy(0, nLen2);
                        nLen2--;
                    }

                    if(aStr.isEmpty())
                        aStr += "0";
                }
            }
            else
            {
                aStr = getSdrModelFromSdrObject().GetMetricString(nLen, true, nNumDigits);
            }

            SvtSysLocale aSysLocale;
            const LocaleDataWrapper& rLocaleDataWrapper = aSysLocale.GetLocaleData();
            sal_Unicode cDec(rLocaleDataWrapper.getNumDecimalSep()[0]);
            sal_Unicode cDecAlt(rLocaleDataWrapper.getNumDecimalSepAlt().toChar());

            if(aStr.indexOf(cDec) != -1 || (cDecAlt && aStr.indexOf(cDecAlt) != -1))
            {
                sal_Int32 nLen2(aStr.getLength() - 1);

                while(aStr[nLen2] == '0')
                {
                    aStr = aStr.copy(0, nLen2);
                    nLen2--;
                }

                if(aStr[nLen2] == cDec || (cDecAlt && aStr[nLen2] == cDecAlt))
                {
                    aStr = aStr.copy(0, nLen2);
                    nLen2--;
                }

                if(aStr.isEmpty())
                    aStr += "0";
                // if there's no Model ... (e. g. preview in dialog)
                aStr = "4711";
            }

            break;
@@ -159,13 +167,16 @@ OUString SdrMeasureObj::TakeRepresentation(SdrMeasureFieldKind eMeasureFieldKind
        {
            if(bShowUnit)
            {
                eModUIUnit = getSdrModelFromSdrObject().GetUIUnit();
                if(pModel)
                {
                    eModUIUnit = pModel->GetUIUnit();

                if(eMeasureUnit == FUNIT_NONE)
                    eMeasureUnit = eModUIUnit;
                    if(eMeasureUnit == FUNIT_NONE)
                        eMeasureUnit = eModUIUnit;

                if(bShowUnit)
                    aStr = SdrModel::GetUnitString(eMeasureUnit);
                    if(bShowUnit)
                        aStr = SdrModel::GetUnitString(eMeasureUnit);
                }
            }

            break;
@@ -200,19 +211,14 @@ sdr::contact::ViewContact* SdrMeasureObj::CreateObjectSpecificViewContact()
}


SdrMeasureObj::SdrMeasureObj(SdrModel& rSdrModel)
:   SdrTextObj(rSdrModel),
SdrMeasureObj::SdrMeasureObj():
    bTextDirty(false)
{
    // #i25616#
    mbSupportTextIndentingOnLineWidthChange = false;
}

SdrMeasureObj::SdrMeasureObj(
    SdrModel& rSdrModel,
    const Point& rPt1,
    const Point& rPt2)
:   SdrTextObj(rSdrModel),
SdrMeasureObj::SdrMeasureObj(const Point& rPt1, const Point& rPt2):
    aPt1(rPt1),
    aPt2(rPt2),
    bTextDirty(false)
@@ -702,22 +708,9 @@ void SdrMeasureObj::TakeUnrotatedSnapRect(tools::Rectangle& rRect) const
    }
}

SdrMeasureObj* SdrMeasureObj::Clone(SdrModel* pTargetModel) const
SdrMeasureObj* SdrMeasureObj::Clone() const
{
    return CloneHelper< SdrMeasureObj >(pTargetModel);
}

SdrMeasureObj& SdrMeasureObj::operator=(const SdrMeasureObj& rObj)
{
    if( this == &rObj )
        return *this;
    SdrTextObj::operator=(rObj);

    aPt1 = rObj.aPt1;
    aPt2 = rObj.aPt2;
    bTextDirty = rObj.bTextDirty;

    return *this;
    return CloneHelper< SdrMeasureObj >();
}

OUString SdrMeasureObj::TakeObjNameSingul() const
@@ -1145,7 +1138,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
    SfxStyleSheet* pStyleSheet = GetStyleSheet();

    // prepare group
    SdrObjGroup* pGroup = new SdrObjGroup(getSdrModelFromSdrObject());
    SdrObjGroup* pGroup = new SdrObjGroup;
    pGroup->SetModel(GetModel());

    // prepare parameters
    basegfx::B2DPolyPolygon aPolyPoly;
@@ -1159,11 +1153,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
        aPolyPoly.clear();
        aPolyPoly.append(aTmpPolyPolygon[0].getB2DPolygon());

        pPath = new SdrPathObj(
            getSdrModelFromSdrObject(),
            OBJ_PATHLINE,
            aPolyPoly);

        pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly);
        pPath->SetModel(GetModel());
        pPath->SetMergedItemSet(aSet);
        pPath->SetStyleSheet(pStyleSheet, true);
        pGroup->GetSubList()->NbcInsertObject(pPath);
@@ -1180,11 +1171,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const

        aPolyPoly.clear();
        aPolyPoly.append(aTmpPolyPolygon[0].getB2DPolygon());
        pPath = new SdrPathObj(
            getSdrModelFromSdrObject(),
            OBJ_PATHLINE,
            aPolyPoly);

        pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly);
        pPath->SetModel(GetModel());
        pPath->SetMergedItemSet(aSet);
        pPath->SetStyleSheet(pStyleSheet, true);

@@ -1195,11 +1183,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const

        aPolyPoly.clear();
        aPolyPoly.append(aTmpPolyPolygon[1].getB2DPolygon());
        pPath = new SdrPathObj(
            getSdrModelFromSdrObject(),
            OBJ_PATHLINE,
            aPolyPoly);

        pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly);
        pPath->SetModel(GetModel());
        pPath->SetMergedItemSet(aSet);
        pPath->SetStyleSheet(pStyleSheet, true);

@@ -1217,11 +1202,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const

        aPolyPoly.clear();
        aPolyPoly.append(aTmpPolyPolygon[0].getB2DPolygon());
        pPath = new SdrPathObj(
            getSdrModelFromSdrObject(),
            OBJ_PATHLINE,
            aPolyPoly);

        pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly);
        pPath->SetModel(GetModel());
        pPath->SetMergedItemSet(aSet);
        pPath->SetStyleSheet(pStyleSheet, true);

@@ -1232,11 +1214,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const

        aPolyPoly.clear();
        aPolyPoly.append(aTmpPolyPolygon[1].getB2DPolygon());
        pPath = new SdrPathObj(
            getSdrModelFromSdrObject(),
            OBJ_PATHLINE,
            aPolyPoly);

        pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly);
        pPath->SetModel(GetModel());
        pPath->SetMergedItemSet(aSet);
        pPath->SetStyleSheet(pStyleSheet, true);

@@ -1250,11 +1229,8 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
    {
        aPolyPoly.clear();
        aPolyPoly.append(aTmpPolyPolygon[nLoopStart].getB2DPolygon());
        pPath = new SdrPathObj(
            getSdrModelFromSdrObject(),
            OBJ_PATHLINE,
            aPolyPoly);

        pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly);
        pPath->SetModel(GetModel());
        pPath->SetMergedItemSet(aSet);
        pPath->SetStyleSheet(pStyleSheet, true);

@@ -1385,7 +1361,7 @@ bool SdrMeasureObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B
    basegfx::B2DTuple aTranslate(aRange.getMinimum());

    // position maybe relative to anchor position, convert
    if( getSdrModelFromSdrObject().IsWriter() )
    if( pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
@@ -1394,7 +1370,7 @@ bool SdrMeasureObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B
    }

    // force MapUnit to 100th mm
    MapUnit eMapUnit = getSdrModelFromSdrObject().GetItemPool().GetMetric(0);
    MapUnit eMapUnit = pModel->GetItemPool().GetMetric(0);
    if(eMapUnit != MapUnit::Map100thMM)
    {
        switch(eMapUnit)
@@ -1431,7 +1407,7 @@ void SdrMeasureObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons
    basegfx::B2DPoint aPosB(rMatrix * basegfx::B2DPoint(1.0, 0.0));

    // force metric to pool metric
    MapUnit eMapUnit = getSdrModelFromSdrObject().GetItemPool().GetMetric(0);
    MapUnit eMapUnit = pModel->GetItemPool().GetMetric(0);
    if(eMapUnit != MapUnit::Map100thMM)
    {
        switch(eMapUnit)
@@ -1453,7 +1429,7 @@ void SdrMeasureObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons
        }
    }

    if( getSdrModelFromSdrObject().IsWriter() )
    if( pModel->IsWriter() )
    {
        // if anchor is used, make position relative to it
        if(GetAnchorPos().X() || GetAnchorPos().Y())
diff --git a/svx/source/svdraw/svdomedia.cxx b/svx/source/svdraw/svdomedia.cxx
index 012dc1d..4c41e76 100644
--- a/svx/source/svdraw/svdomedia.cxx
+++ b/svx/source/svdraw/svdomedia.cxx
@@ -65,17 +65,16 @@ struct SdrMediaObj::Impl
    OUString m_LastFailedPkgURL;
};

SdrMediaObj::SdrMediaObj(SdrModel& rSdrModel)
:   SdrRectObj(rSdrModel)
    ,m_xImpl( new Impl )

SdrMediaObj::SdrMediaObj()
    : SdrRectObj()
    , m_xImpl( new Impl )
{
}

SdrMediaObj::SdrMediaObj(
    SdrModel& rSdrModel,
    const tools::Rectangle& rRect)
:   SdrRectObj(rSdrModel, rRect)
    ,m_xImpl( new Impl )
SdrMediaObj::SdrMediaObj( const tools::Rectangle& rRect )
    : SdrRectObj( rRect )
    , m_xImpl( new Impl )
{
}

@@ -142,9 +141,9 @@ OUString SdrMediaObj::TakeObjNamePlural() const
    return ImpGetResStr(STR_ObjNamePluralMEDIA);
}

SdrMediaObj* SdrMediaObj::Clone(SdrModel* pTargetModel) const
SdrMediaObj* SdrMediaObj::Clone() const
{
    return CloneHelper< SdrMediaObj >(pTargetModel);
    return CloneHelper< SdrMediaObj >();
}

SdrMediaObj& SdrMediaObj::operator=(const SdrMediaObj& rObj)
@@ -316,14 +315,8 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream
        SAL_WARN("svx", "this is only intended for embedded media");
        return;
    }

    OUString tempFileURL;
    const bool bSuccess(
        lcl_CopyToTempFile(
            xStream,
            tempFileURL,
            ""));

    bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL, "");
    if (bSuccess)
    {
        m_xImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL));
@@ -338,14 +331,19 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream
/// copy a stream from XStorage to temp file
#if HAVE_FEATURE_AVMEDIA
static bool lcl_HandlePackageURL(
    OUString const & rURL,
    const SdrModel& rModel,
    OUString & o_rTempFileURL)
        OUString const & rURL,
        SdrModel const *const pModel,
        OUString & o_rTempFileURL)
{
    if (!pModel)
    {
        SAL_WARN("svx", "no model");
        return false;
    }
    ::comphelper::LifecycleProxy sourceProxy;
    uno::Reference<io::XInputStream> xInStream;
    try {
        xInStream = rModel.GetDocumentStream(rURL, sourceProxy);
        xInStream = pModel->GetDocumentStream(rURL, sourceProxy);
    }
    catch (container::NoSuchElementException const&)
    {
@@ -396,12 +394,8 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper
                                rNewProperties.getTempURL()))
            {
                OUString tempFileURL;
                const bool bSuccess(
                    lcl_HandlePackageURL(
                        url,
                        getSdrModelFromSdrObject(),
                        tempFileURL));

                bool bSuccess;
                    bSuccess = lcl_HandlePackageURL(url, GetModel(), tempFileURL);
                if (bSuccess)
                {
                    m_xImpl->m_pTempFile.reset(
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index 50595c5..8a26427 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -663,42 +663,13 @@ sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
    return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
}

void SdrOle2Obj::Init()
{
    // Stuff that was done from old SetModel:
    // #i43086# #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
    // so maybe the ImpSetVisAreaSize call can be removed here completely
    // Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
    if(!getSdrModelFromSdrObject().isLocked() && !IsChart())
    {
        ImpSetVisAreaSize();
    }

    ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist());
    if(pDestPers && !IsEmptyPresObj())
    {
        // object wasn't connected, now it should be
        Connect_Impl();
    }

    AddListeners_Impl();
}

SdrOle2Obj::SdrOle2Obj(
    SdrModel& rSdrModel,
    bool bFrame_)
:   SdrRectObj(rSdrModel),
SdrOle2Obj::SdrOle2Obj( bool bFrame_ ) :
    mpImpl(new SdrOle2ObjImpl(bFrame_))
{
    Init();
}

SdrOle2Obj::SdrOle2Obj(
    SdrModel& rSdrModel,
    const svt::EmbeddedObjectRef& rNewObjRef,
    const OUString& rNewObjName,
    const tools::Rectangle& rNewRect)
:   SdrRectObj(rSdrModel, rNewRect),
SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef&  rNewObjRef, const OUString& rNewObjName, const tools::Rectangle& rNewRect) :
    SdrRectObj(rNewRect),
    mpImpl(new SdrOle2ObjImpl(false/*bFrame_*/, rNewObjRef))
{
    mpImpl->aPersistName = rNewObjName;
@@ -708,8 +679,6 @@ SdrOle2Obj::SdrOle2Obj(

    // For math objects, set closed state to transparent
    SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() ));

    Init();
}

OUString SdrOle2Obj::GetStyleString()
@@ -812,8 +781,7 @@ bool SdrOle2Obj::UpdateLinkURL_Impl()

    if ( mpImpl->mpObjectLink )
    {
        sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());

        sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : nullptr;
        if ( pLinkManager )
        {
            OUString aNewLinkURL;
@@ -863,7 +831,9 @@ bool SdrOle2Obj::UpdateLinkURL_Impl()

void SdrOle2Obj::BreakFileLink_Impl()
{
    uno::Reference<document::XStorageBasedDocument> xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
    uno::Reference<document::XStorageBasedDocument> xDoc;
    if ( pModel )
        xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);

    if ( xDoc.is() )
    {
@@ -888,8 +858,7 @@ void SdrOle2Obj::BreakFileLink_Impl()

void SdrOle2Obj::DisconnectFileLink_Impl()
{
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());

    sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : nullptr;
    if ( pLinkManager && mpImpl->mpObjectLink )
    {
        pLinkManager->Remove( mpImpl->mpObjectLink );
@@ -899,21 +868,18 @@ void SdrOle2Obj::DisconnectFileLink_Impl()

void SdrOle2Obj::CheckFileLink_Impl()
{
    if (mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink)
    if (pModel && mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink)
    {
        try
        {
            uno::Reference< embed::XLinkageSupport > xLinkSupport( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );

            if ( xLinkSupport.is() && xLinkSupport->isLink() )
            {
                OUString aLinkURL = xLinkSupport->getLinkURL();

                if ( !aLinkURL.isEmpty() )
                {
                    // this is a file link so the model link manager should handle it
                    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());

                    sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
                    if ( pLinkManager )
                    {
                        mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
@@ -939,16 +905,14 @@ void SdrOle2Obj::Reconnect_Impl()

void SdrOle2Obj::Connect_Impl()
{
    if(!mpImpl->aPersistName.isEmpty() )
    if( pModel && !mpImpl->aPersistName.isEmpty() )
    {
        try
        {
            ::comphelper::IEmbeddedHelper* pPers(getSdrModelFromSdrObject().GetPersist());

            ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
            if ( pPers )
            {
                comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();

                if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
                  || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( mpImpl->mxObjRef.GetObject() ) ) )
                {
@@ -993,9 +957,9 @@ void SdrOle2Obj::Connect_Impl()
                uno::Reference< container::XChild > xChild( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
                if( xChild.is() )
                {
                    uno::Reference< uno::XInterface > xParent( getSdrModelFromSdrObject().getUnoModel());
                    uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
                    if( xParent.is())
                        xChild->setParent( getSdrModelFromSdrObject().getUnoModel() );
                        xChild->setParent( pModel->getUnoModel() );
                }

            }
@@ -1076,9 +1040,9 @@ void SdrOle2Obj::Disconnect_Impl()
{
    try
    {
        if ( !mpImpl->aPersistName.isEmpty() )
        if ( pModel && !mpImpl->aPersistName.isEmpty() )
        {
            if( getSdrModelFromSdrObject().IsInDestruction() )
            if( pModel->IsInDestruction() )
            {
                // TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
                // remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
@@ -1114,7 +1078,7 @@ void SdrOle2Obj::Disconnect_Impl()
            }
            else if ( mpImpl->mxObjRef.is() )
            {
                if ( getSdrModelFromSdrObject().getUnoModel().is() )
                if ( pModel->getUnoModel().is() )
                {
                    // remove object, but don't close it (that's up to someone else)
                    comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer();
@@ -1158,9 +1122,8 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const
    if(pOLEGraphic)
    {
        // #i118485# allow creating a SdrGrafObj representation
        SdrGrafObj* pClone = new SdrGrafObj(
            getSdrModelFromSdrObject(),
            *pOLEGraphic);
        SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
        pClone->SetModel(GetModel());

        // copy transformation
        basegfx::B2DHomMatrix aMatrix;
@@ -1178,7 +1141,7 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const
            // #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
            OutlinerParaObject* pOPO = GetOutlinerParaObject();

            if(pOPO)
            if(pOPO && GetModel())
            {
                pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
            }
@@ -1190,9 +1153,8 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const
    {
        // #i100710# pOLEGraphic may be zero (no visualisation available),
        // so we need to use the OLE replacement graphic
        SdrRectObj* pClone = new SdrRectObj(
            getSdrModelFromSdrObject(),
            GetSnapRect());
        SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
        pClone->SetModel(GetModel());

        // gray outline
        pClone->SetMergedItem(XLineStyleItem(css::drawing::LineStyle_SOLID));
@@ -1213,19 +1175,92 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const
SdrObject* SdrOle2Obj::DoConvertToPolyObj(bool bBezier, bool bAddText) const
{
    // #i118485# missing converter added
    SdrObject* pRetval = createSdrGrafObjReplacement(true);

    if(pRetval)
    if(GetModel())
    {
        SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
        SdrObject::Free(pRetval);
        SdrObject* pRetval = createSdrGrafObjReplacement(true);

        return pRetval2;
        if(pRetval)
        {
            SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
            SdrObject::Free(pRetval);

            return pRetval2;
        }
    }

    return nullptr;
}

void SdrOle2Obj::SetModel(SdrModel* pNewModel)
{
    ::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : nullptr;
    ::comphelper::IEmbeddedHelper* pSrcPers  = pModel ? pModel->GetPersist() : nullptr;

    if ( pNewModel == pModel )
    {
        // don't know if this is necessary or if it will ever happen, but who knows?!
        SdrRectObj::SetModel( pNewModel );
        return;
    }

    // assignment to model has changed
    DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );

    DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
    DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );

    // this is a bug if the target model has no persistence
    // no error handling is possible so just do nothing in this method
    if ( !pDestPers )
        return;

    RemoveListeners_Impl();

    if( pDestPers && pSrcPers && !IsEmptyPresObj() )
    {
        try
        {
            // move the object's storage; ObjectRef remains the same, but PersistName may change
            OUString aTmp;
            comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
            uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
            DBG_ASSERT( !mpImpl->mxObjRef.is() || mpImpl->mxObjRef.GetObject() == xObj, "Wrong object identity!" );
            if ( xObj.is() )
            {
                pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
                mpImpl->aPersistName = aTmp;
                mpImpl->mxObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
            }
            DBG_ASSERT( !aTmp.isEmpty(), "Copying embedded object failed!" );
        }
        catch( css::uno::Exception& )
        {
            SAL_WARN( "svx",  "SdrOle2Obj::SetModel(), exception caught: "
                    << comphelper::anyToString( cppu::getCaughtException() ) );
        }
    }

    SdrRectObj::SetModel( pNewModel );

    // #i43086#
    // #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
    //so maybe the ImpSetVisAreaSize call can be removed here completely
    //Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
    if( pModel && !pModel->isLocked() && !IsChart() )
        ImpSetVisAreaSize();

    if( pDestPers && !IsEmptyPresObj() )
    {
        if ( !pSrcPers || IsEmptyPresObj() )
            // object wasn't connected, now it should be
            Connect_Impl();
        else
            Reconnect_Impl();
    }

    AddListeners_Impl();
}

void SdrOle2Obj::SetPage(SdrPage* pNewPage)
{
    bool bRemove=pNewPage==nullptr && pPage!=nullptr;
@@ -1234,14 +1269,14 @@ void SdrOle2Obj::SetPage(SdrPage* pNewPage)
    if (bRemove && mpImpl->mbConnected )
        Disconnect();

    if(!GetStyleSheet() && pNewPage)
    if(!pModel && !GetStyleSheet() && pNewPage && pNewPage->GetModel())
    {
        // #i119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
        // needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
        // from the following :SetPage().
        // TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
        // place for convenience currently (works in both versions, is not in the way)
        SfxStyleSheet* pSheet = pNewPage->getSdrModelFromSdrPage().GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
        SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();

        if(pSheet)
        {
@@ -1379,70 +1414,67 @@ OUString SdrOle2Obj::TakeObjNamePlural() const
    return ImpGetResStr(mpImpl->mbFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
}

SdrOle2Obj* SdrOle2Obj::Clone(SdrModel* pTargetModel) const
SdrOle2Obj* SdrOle2Obj::Clone() const
{
    return CloneHelper< SdrOle2Obj >(pTargetModel);
}

SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj)
{
    return assignFrom(rObj);
    return CloneHelper< SdrOle2Obj >();
}

SdrOle2Obj& SdrOle2Obj::assignFrom(const SdrOle2Obj& rObj)
{
    //TODO/LATER: who takes over control of my old object?!
    if( &rObj == this )
    if( &rObj != this )
    {
        return *this;
    }
        // ImpAssign( rObj );
        const SdrOle2Obj& rOle2Obj = rObj;

    // ImpAssign( rObj );
    const SdrOle2Obj& rOle2Obj = rObj;
        if( pModel && mpImpl->mbConnected )
            Disconnect();

    if( mpImpl->mbConnected )
        Disconnect();
        SdrRectObj::operator=( rObj );

    SdrRectObj::operator=( rObj );
        // Manually copying bClosedObj attribute
        SetClosedObj( rObj.IsClosedObj() );

    // Manually copying bClosedObj attribute
    SetClosedObj( rObj.IsClosedObj() );
        mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
        mpImpl->maProgName = rOle2Obj.mpImpl->maProgName;
        mpImpl->mbFrame = rOle2Obj.mpImpl->mbFrame;

    mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
    mpImpl->maProgName = rOle2Obj.mpImpl->maProgName;
    mpImpl->mbFrame = rOle2Obj.mpImpl->mbFrame;

    if (rOle2Obj.mpImpl->mxGraphic)
    {
        mpImpl->mxGraphic.reset(new Graphic(*rOle2Obj.mpImpl->mxGraphic));
    }

    if( !IsEmptyPresObj() )
    {
        ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist());
        ::comphelper::IEmbeddedHelper* pSrcPers(rObj.getSdrModelFromSdrObject().GetPersist());
        if( pDestPers && pSrcPers )
        if (rOle2Obj.mpImpl->mxGraphic)
        {
            DBG_ASSERT( !mpImpl->mxObjRef.is(), "Object already existing!" );
            comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
            uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
            if ( xObj.is() )
            {
                OUString aTmp;
                mpImpl->mxObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
                    rContainer, xObj, aTmp, pSrcPers->getDocumentBaseURL(), pDestPers->getDocumentBaseURL()), rOle2Obj.GetAspect());
                mpImpl->mbTypeAsked = false;
                mpImpl->aPersistName = aTmp;
                CheckFileLink_Impl();
            }
            mpImpl->mxGraphic.reset(new Graphic(*rOle2Obj.mpImpl->mxGraphic));
        }

            Connect();
        if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
        {
            ::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
            ::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
            if( pDestPers && pSrcPers )
            {
                DBG_ASSERT( !mpImpl->mxObjRef.is(), "Object already existing!" );
                comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
                uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
                if ( xObj.is() )
                {
                    OUString aTmp;
                    mpImpl->mxObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
                        rContainer, xObj, aTmp, pSrcPers->getDocumentBaseURL(), pDestPers->getDocumentBaseURL()), rOle2Obj.GetAspect());
                    mpImpl->mbTypeAsked = false;
                    mpImpl->aPersistName = aTmp;
                    CheckFileLink_Impl();
                }

                Connect();
            }
        }
    }

    return *this;
}

SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj)
{
    return assignFrom(rObj);
}

void SdrOle2Obj::ImpSetVisAreaSize()
{
    // #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
@@ -1458,17 +1490,14 @@ void SdrOle2Obj::ImpSetVisAreaSize()
    GetObjRef();
    if (mpImpl->mxObjRef.is())
    {
        OSL_ASSERT( pModel );
        sal_Int64 nMiscStatus = mpImpl->mxObjRef->getStatus( GetAspect() );

        // the client is required to get access to scaling
        SfxInPlaceClient* pClient(
            SfxInPlaceClient::GetClient(
                dynamic_cast<SfxObjectShell*>(
                    getSdrModelFromSdrObject().GetPersist()),
                    mpImpl->mxObjRef.GetObject()));
        const bool bHasOwnClient(
            mpImpl->mxLightClient.is() &&
            mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) );
        SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), mpImpl->mxObjRef.GetObject() );
        bool bHasOwnClient =
                        ( mpImpl->mxLightClient.is()
                        && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) );

        if ( pClient || bHasOwnClient )
        {
@@ -1500,10 +1529,7 @@ void SdrOle2Obj::ImpSetVisAreaSize()
                Size aVisSize( static_cast<long>( Fraction( maRect.GetWidth() ) / aScaleWidth ),
                                static_cast<long>( Fraction( maRect.GetHeight() ) / aScaleHeight ) );

                aVisSize = OutputDevice::LogicToLogic(
                    aVisSize,
                    MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
                    MapMode(aMapUnit));
                aVisSize = OutputDevice::LogicToLogic(aVisSize, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit));
                awt::Size aSz;
                aSz.Width = aVisSize.Width();
                aSz.Height = aVisSize.Height();
@@ -1524,11 +1550,7 @@ void SdrOle2Obj::ImpSetVisAreaSize()
                    // server changed VisArea to its liking and the VisArea is different than the suggested one
                    // store the new value as given by the object
                    MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
                    maRect.SetSize(
                        OutputDevice::LogicToLogic(
                            aAcceptedVisArea.GetSize(),
                            MapMode(aNewMapUnit),
                            MapMode(getSdrModelFromSdrObject().GetScaleUnit())));
                    maRect.SetSize(OutputDevice::LogicToLogic(aAcceptedVisArea.GetSize(), MapMode(aNewMapUnit), MapMode(pModel->GetScaleUnit())));
                }

                // make the new object area known to the client
@@ -1574,30 +1596,13 @@ void SdrOle2Obj::ImpSetVisAreaSize()
            uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), uno::UNO_QUERY );
            if( xVisualObject.is() )
            {
                const MapUnit aMapUnit(
                    VCLUnoHelper::UnoEmbed2VCLMapUnit(
                        mpImpl->mxObjRef->getMapUnit(GetAspect())));
                const Point aTL( maRect.TopLeft() );
                const Point aBR( maRect.BottomRight() );
                const Point aTL2(
                    OutputDevice::LogicToLogic(
                        aTL,
                        MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
                        MapMode(aMapUnit)));
                const Point aBR2(
                    OutputDevice::LogicToLogic(
                        aBR,
                        MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
                        MapMode(aMapUnit)));
                const tools::Rectangle aNewRect(
                    aTL2,
                    aBR2);

                xVisualObject->setVisualAreaSize(
                    GetAspect(),
                    awt::Size(
                        aNewRect.GetWidth(),
                        aNewRect.GetHeight()));
                MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
                Point aTL( maRect.TopLeft() );
                Point aBR( maRect.BottomRight() );
                Point aTL2(OutputDevice::LogicToLogic(aTL, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit)));
                Point aBR2(OutputDevice::LogicToLogic(aBR, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit)));
                tools::Rectangle aNewRect( aTL2, aBR2 );
                xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
            }
        }
    }
@@ -1605,10 +1610,9 @@ void SdrOle2Obj::ImpSetVisAreaSize()

void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
    if(!getSdrModelFromSdrObject().isLocked())
    if( pModel && !pModel->isLocked() )
    {
        GetObjRef();

        if ( mpImpl->mxObjRef.is() && ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
        {
            // if the object needs recompose on resize
@@ -1619,8 +1623,7 @@ void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract
    }

    SdrRectObj::NbcResize(rRef,xFact,yFact);

    if( !getSdrModelFromSdrObject().isLocked() )
    if( pModel && !pModel->isLocked() )
        ImpSetVisAreaSize();
}

@@ -1628,7 +1631,7 @@ void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
{
    SdrRectObj::SetGeoData(rGeo);

    if( !getSdrModelFromSdrObject().isLocked() )
    if( pModel && !pModel->isLocked() )
        ImpSetVisAreaSize();
}

@@ -1636,7 +1639,7 @@ void SdrOle2Obj::NbcSetSnapRect(const tools::Rectangle& rRect)
{
    SdrRectObj::NbcSetSnapRect(rRect);

    if( !getSdrModelFromSdrObject().isLocked() )
    if( pModel && !pModel->isLocked() )
        ImpSetVisAreaSize();

    if ( mpImpl->mxObjRef.is() && IsChart() )
@@ -1652,7 +1655,7 @@ void SdrOle2Obj::NbcSetLogicRect(const tools::Rectangle& rRect)
{
    SdrRectObj::NbcSetLogicRect(rRect);

    if( !getSdrModelFromSdrObject().isLocked() )
    if( pModel && !pModel->isLocked() )
        ImpSetVisAreaSize();
}

@@ -1683,7 +1686,7 @@ void SdrOle2Obj::NbcMove(const Size& rSize)
{
    SdrRectObj::NbcMove(rSize);

    if( !getSdrModelFromSdrObject().isLocked() )
    if( pModel && !pModel->isLocked() )
        ImpSetVisAreaSize();
}

@@ -1755,8 +1758,7 @@ bool SdrOle2Obj::Unload()
        return true;

    bool bUnloaded = false;

    if ( mpImpl->mxObjRef.is() )
    if ( pModel && mpImpl->mxObjRef.is() )
    {
        bUnloaded = Unload( mpImpl->mxObjRef.GetObject(), GetAspect() );
    }
@@ -1766,14 +1768,12 @@ bool SdrOle2Obj::Unload()

void SdrOle2Obj::GetObjRef_Impl()
{
    if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && getSdrModelFromSdrObject().GetPersist() )
    if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && pModel && pModel->GetPersist() )
    {
        // Only try loading if it did not went wrong up to now
        if(!mpImpl->mbLoadingOLEObjectFailed)
        {
            mpImpl->mxObjRef.Assign(
                getSdrModelFromSdrObject().GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject(mpImpl->aPersistName),
                GetAspect());
            mpImpl->mxObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
            mpImpl->mbTypeAsked = false;
            CheckFileLink_Impl();

@@ -1793,7 +1793,7 @@ void SdrOle2Obj::GetObjRef_Impl()
            if( !IsEmptyPresObj() )
            {
                // remember modified status of model
                const bool bWasChanged(getSdrModelFromSdrObject().IsChanged());
                const bool bWasChanged = pModel && pModel->IsChanged();

                // perhaps preview not valid anymore
                // This line changes the modified state of the model
@@ -1802,9 +1802,9 @@ void SdrOle2Obj::GetObjRef_Impl()
                // if status was not set before, force it back
                // to not set, so that SetGraphic(0) above does not
                // set the modified state of the model.
                if(!bWasChanged && getSdrModelFromSdrObject().IsChanged())
                if(!bWasChanged && pModel && pModel->IsChanged())
                {
                    getSdrModelFromSdrObject().SetChanged( false );
                    pModel->SetChanged( false );
                }
            }
        }
@@ -1889,7 +1889,9 @@ bool SdrOle2Obj::IsCalc() const

uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
{
    uno::Reference< frame::XModel > xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
    uno::Reference< frame::XModel > xDoc;
    if ( pModel )
        xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
    return xDoc;
}

@@ -1897,10 +1899,10 @@ bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHei
{
    // TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
    // If we don't cache it for own objects also we must load the object here
    if (!mpImpl->mxObjRef.is())
    if ( !mpImpl->mxObjRef.is() || !pModel )
        return false;

    MapMode aMapMode(getSdrModelFromSdrObject().GetScaleUnit());
    MapMode aMapMode( pModel->GetScaleUnit() );
    aObjAreaSize = mpImpl->mxObjRef.GetSize( &aMapMode );

    Size aSize = maRect.GetSize();
@@ -1917,7 +1919,7 @@ bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHei
bool SdrOle2Obj::AddOwnLightClient()
{
    // The Own Light Client must be registered in object only using this method!
    if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(getSdrModelFromSdrObject().GetPersist()), mpImpl->mxObjRef.GetObject() )
    if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), mpImpl->mxObjRef.GetObject() )
      && !( mpImpl->mxLightClient.is() && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) ) )
    {
        Connect();
diff --git a/svx/source/svdraw/svdopage.cxx b/svx/source/svdraw/svdopage.cxx
index af38237..a2a6592 100644
--- a/svx/source/svdraw/svdopage.cxx
+++ b/svx/source/svdraw/svdopage.cxx
@@ -64,11 +64,9 @@ void SdrPageObj::PageInDestruction(const SdrPage& rPage)
    }
}

SdrPageObj::SdrPageObj(
    SdrModel& rSdrModel,
    SdrPage* pNewPage)
:   SdrObject(rSdrModel),
    mpShownPage(pNewPage)

SdrPageObj::SdrPageObj(SdrPage* pNewPage)
:   mpShownPage(pNewPage)
{
    if(mpShownPage)
    {
@@ -76,12 +74,8 @@ SdrPageObj::SdrPageObj(
    }
}

SdrPageObj::SdrPageObj(
    SdrModel& rSdrModel,
    const tools::Rectangle& rRect,
    SdrPage* pNewPage)
:   SdrObject(rSdrModel),
    mpShownPage(pNewPage)
SdrPageObj::SdrPageObj(const tools::Rectangle& rRect, SdrPage* pNewPage)
:   mpShownPage(pNewPage)
{
    if(mpShownPage)
    {
@@ -150,9 +144,9 @@ void SdrPageObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
    rInfo.bCanConvToPolyLineToArea=false;
}

SdrPageObj* SdrPageObj::Clone(SdrModel* pTargetModel) const
SdrPageObj* SdrPageObj::Clone() const
{
    return CloneHelper< SdrPageObj >(pTargetModel);
    return CloneHelper< SdrPageObj >();
}

SdrPageObj& SdrPageObj::operator=(const SdrPageObj& rObj)
diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx
index fc991ab..5cf8dd5 100644
--- a/svx/source/svdraw/svdopath.cxx
+++ b/svx/source/svdraw/svdopath.cxx
@@ -941,27 +941,27 @@ OUString ImpPathForDragAndCreate::getSpecialDragComment(const SdrDragStat& rDrag
        {
            aStr += SdrModel::GetAngleString(std::abs(pU->nCircRelAngle))
                    + " r="
                    + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(pU->nCircRadius, true);
                    + mrSdrPathObject.GetModel()->GetMetricString(pU->nCircRadius, true);
        }

        aStr += "dx="
                + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.X(), true)
                + mrSdrPathObject.GetModel()->GetMetricString(aNow.X(), true)
                + " dy="
                + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.Y(), true);
                + mrSdrPathObject.GetModel()->GetMetricString(aNow.Y(), true);

        if(!IsFreeHand(meObjectKind))
        {
            sal_Int32 nLen(GetLen(aNow));
            sal_Int32 nAngle(GetAngle(aNow));
            aStr += "  l="
                    + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(nLen, true)
                    + mrSdrPathObject.GetModel()->GetMetricString(nLen, true)
                    + " "
                    + SdrModel::GetAngleString(nAngle);
        }

        aStr += ")";
    }
    else if(!pHdl)
    else if(!mrSdrPathObject.GetModel() || !pHdl)
    {
        // #i103058# fallback when no model and/or Handle, both needed
        // for else-path
@@ -1011,9 +1011,9 @@ OUString ImpPathForDragAndCreate::getSpecialDragComment(const SdrDragStat& rDrag

        aStr.clear();
        aStr += "dx="
                + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.X() - aBeg.X(), true)
                + mrSdrPathObject.GetModel()->GetMetricString(aNow.X() - aBeg.X(), true)
                + " dy="
                + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.Y() - aBeg.Y(), true);
                + mrSdrPathObject.GetModel()->GetMetricString(aNow.Y() - aBeg.Y(), true);

        if(!pDragData->IsMultiPointDrag())
        {
@@ -1040,7 +1040,7 @@ OUString ImpPathForDragAndCreate::getSpecialDragComment(const SdrDragStat& rDrag
                sal_Int32 nLen(GetLen(aNow));
                sal_Int32 nAngle(GetAngle(aNow));
                aStr += "  l="
                        + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(nLen, true)
                        + mrSdrPathObject.GetModel()->GetMetricString(nLen, true)
                        + " "
                        + SdrModel::GetAngleString(nAngle);
            }
@@ -1083,7 +1083,7 @@ OUString ImpPathForDragAndCreate::getSpecialDragComment(const SdrDragStat& rDrag
                    sal_Int32 nLen(GetLen(aPt));
                    sal_Int32 nAngle(GetAngle(aPt));
                    aStr += "  l="
                            + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(nLen, true)
                            + mrSdrPathObject.GetModel()->GetMetricString(nLen, true)
                            + " "
                            + SdrModel::GetAngleString(nAngle);
                }
@@ -1101,7 +1101,7 @@ OUString ImpPathForDragAndCreate::getSpecialDragComment(const SdrDragStat& rDrag
                    sal_Int32 nLen(GetLen(aPt));
                    sal_Int32 nAngle(GetAngle(aPt));
                    aStr += "l="
                            + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(nLen, true)
                            + mrSdrPathObject.GetModel()->GetMetricString(nLen, true)
                            + " "
                            + SdrModel::GetAngleString(nAngle);
                }
@@ -1628,21 +1628,14 @@ sdr::contact::ViewContact* SdrPathObj::CreateObjectSpecificViewContact()
}


SdrPathObj::SdrPathObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewKind)
:   SdrTextObj(rSdrModel),
    meKind(eNewKind)
SdrPathObj::SdrPathObj(SdrObjKind eNewKind)
:   meKind(eNewKind)
{
    bClosedObj = IsClosed();
}

SdrPathObj::SdrPathObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewKind,
    const basegfx::B2DPolyPolygon& rPathPoly)
:   SdrTextObj(rSdrModel),
    maPathPolygon(rPathPoly),
SdrPathObj::SdrPathObj(SdrObjKind eNewKind, const basegfx::B2DPolyPolygon& rPathPoly)
:   maPathPolygon(rPathPoly),
    meKind(eNewKind)
{
    bClosedObj = IsClosed();
@@ -1828,9 +1821,9 @@ sal_uInt16 SdrPathObj::GetObjIdentifier() const
    return sal_uInt16(meKind);
}

SdrPathObj* SdrPathObj::Clone(SdrModel* pTargetModel) const
SdrPathObj* SdrPathObj::Clone() const
{
    return CloneHelper< SdrPathObj >(pTargetModel);
    return CloneHelper< SdrPathObj >();
}

SdrPathObj& SdrPathObj::operator=(const SdrPathObj& rObj)
@@ -2886,7 +2879,7 @@ bool SdrPathObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DP
    }

    // position maybe relative to anchorpos, convert
    if( getSdrModelFromSdrObject().IsWriter() )
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
@@ -2995,7 +2988,7 @@ void SdrPathObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const b
        }
    }

    if( getSdrModelFromSdrObject().IsWriter() )
    if( pModel && pModel->IsWriter() )
    {
        // if anchor is used, make position relative to it
        if(GetAnchorPos().X() || GetAnchorPos().Y())
diff --git a/svx/source/svdraw/svdorect.cxx b/svx/source/svdraw/svdorect.cxx
index e68b38c..7f85da4 100644
--- a/svx/source/svdraw/svdorect.cxx
+++ b/svx/source/svdraw/svdorect.cxx
@@ -62,26 +62,21 @@ sdr::contact::ViewContact* SdrRectObj::CreateObjectSpecificViewContact()
}


SdrRectObj::SdrRectObj(SdrModel& rSdrModel)
:   SdrTextObj(rSdrModel),
SdrRectObj::SdrRectObj()
:   mpXPoly(nullptr)
{
    bClosedObj=true;
}

SdrRectObj::SdrRectObj(const tools::Rectangle& rRect)
:   SdrTextObj(rRect),
    mpXPoly(nullptr)
{
    bClosedObj=true;
}

SdrRectObj::SdrRectObj(
    SdrModel& rSdrModel,
    const tools::Rectangle& rRect)
:   SdrTextObj(rSdrModel, rRect),
    mpXPoly(nullptr)
{
    bClosedObj=true;
}

SdrRectObj::SdrRectObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewTextKind)
:   SdrTextObj(rSdrModel, eNewTextKind),
SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind)
:   SdrTextObj(eNewTextKind),
    mpXPoly(nullptr)
{
    DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT ||
@@ -90,11 +85,8 @@ SdrRectObj::SdrRectObj(
    bClosedObj=true;
}

SdrRectObj::SdrRectObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewTextKind,
    const tools::Rectangle& rRect)
:   SdrTextObj(rSdrModel, eNewTextKind, rRect),
SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind, const tools::Rectangle& rRect)
:   SdrTextObj(eNewTextKind,rRect),
    mpXPoly(nullptr)
{
    DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT ||
@@ -107,6 +99,21 @@ SdrRectObj::~SdrRectObj()
{
}

SdrRectObj& SdrRectObj::operator=(const SdrRectObj& rCopy)
{
    if ( this == &rCopy )
        return *this;

    SdrTextObj::operator=( rCopy );

    if ( rCopy.mpXPoly )
        mpXPoly.reset( new XPolygon( *rCopy.mpXPoly ) );
    else
        mpXPoly.reset();

    return *this;
}

void SdrRectObj::SetXPolyDirty()
{
    mpXPoly.reset();
@@ -259,24 +266,9 @@ OUString SdrRectObj::TakeObjNamePlural() const
    return ImpGetResStr(pResId);
}

SdrRectObj* SdrRectObj::Clone(SdrModel* pTargetModel) const
SdrRectObj* SdrRectObj::Clone() const
{
    return CloneHelper< SdrRectObj >(pTargetModel);
}

SdrRectObj& SdrRectObj::operator=(const SdrRectObj& rCopy)
{
    if ( this == &rCopy )
        return *this;

    SdrTextObj::operator=( rCopy );

    if ( rCopy.mpXPoly )
        mpXPoly.reset( new XPolygon( *rCopy.mpXPoly ) );
    else
        mpXPoly.reset();

    return *this;
    return CloneHelper< SdrRectObj >();
}

basegfx::B2DPolyPolygon SdrRectObj::TakeXorPoly() const
diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx
index 63ca33f..cf4448f 100644
--- a/svx/source/svdraw/svdotext.cxx
+++ b/svx/source/svdraw/svdotext.cxx
@@ -64,20 +64,25 @@

using namespace com::sun::star;


// BaseProperties section

sdr::properties::BaseProperties* SdrTextObj::CreateObjectSpecificProperties()
{
    return new sdr::properties::TextProperties(*this);
}


// DrawContact section

sdr::contact::ViewContact* SdrTextObj::CreateObjectSpecificViewContact()
{
    return new sdr::contact::ViewContactOfTextObj(*this);
}

SdrTextObj::SdrTextObj(SdrModel& rSdrModel)
:   SdrAttrObj(rSdrModel),

SdrTextObj::SdrTextObj()
:   SdrAttrObj(),
    mpText(nullptr),
    pEdtOutl(nullptr),
    eTextKind(OBJ_TEXT)
@@ -97,10 +102,8 @@ SdrTextObj::SdrTextObj(SdrModel& rSdrModel)
    mbInDownScale = false;
}

SdrTextObj::SdrTextObj(
    SdrModel& rSdrModel,
    const tools::Rectangle& rNewRect)
:   SdrAttrObj(rSdrModel),
SdrTextObj::SdrTextObj(const tools::Rectangle& rNewRect)
:   SdrAttrObj(),
    maRect(rNewRect),
    mpText(nullptr),
    pEdtOutl(nullptr),
@@ -122,10 +125,8 @@ SdrTextObj::SdrTextObj(
    mbSupportTextIndentingOnLineWidthChange = true;
}

SdrTextObj::SdrTextObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewTextKind)
:   SdrAttrObj(rSdrModel),
SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind)
:   SdrAttrObj(),
    mpText(nullptr),
    pEdtOutl(nullptr),
    eTextKind(eNewTextKind)
@@ -145,11 +146,8 @@ SdrTextObj::SdrTextObj(
    mbSupportTextIndentingOnLineWidthChange = true;
}

SdrTextObj::SdrTextObj(
    SdrModel& rSdrModel,
    SdrObjKind eNewTextKind,
    const tools::Rectangle& rNewRect)
:   SdrAttrObj(rSdrModel),
SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind, const tools::Rectangle& rNewRect)
:   SdrAttrObj(),
    maRect(rNewRect),
    mpText(nullptr),
    pEdtOutl(nullptr),
@@ -173,19 +171,25 @@ SdrTextObj::SdrTextObj(

SdrTextObj::~SdrTextObj()
{
    SdrOutliner& rOutl(getSdrModelFromSdrObject().GetHitTestOutliner());
    if( rOutl.GetTextObj() == this )
        rOutl.SetTextObj( nullptr );
    if( pModel )
    {
        SdrOutliner& rOutl = pModel->GetHitTestOutliner();
        if( rOutl.GetTextObj() == this )
            rOutl.SetTextObj( nullptr );
    }

    mpText.reset();

    ImpDeregisterLink();
}

void SdrTextObj::FitFrameToTextSize()
{
    DBG_ASSERT(pModel!=nullptr,"SdrTextObj::FitFrameToTextSize(): pModel=NULL!");
    ImpJustifyRect(maRect);

    SdrText* pText = getActiveText();
    if(pText==nullptr || !pText->GetOutlinerParaObject())
    if( pText==nullptr || !pText->GetOutlinerParaObject() || pModel==nullptr)
        return;

    SdrOutliner& rOutliner=ImpGetDrawOutliner();
@@ -474,6 +478,39 @@ void SdrTextObj::SetPage(SdrPage* pNewPage)
    }
}

void SdrTextObj::SetModel(SdrModel* pNewModel)
{
    SdrModel* pOldModel=pModel;
    bool bLinked=IsLinkedText();
    bool bChg=pNewModel!=pModel;

    if (bLinked && bChg)
    {
        ImpDeregisterLink();
    }

    SdrAttrObj::SetModel(pNewModel);

    if( bChg )
    {
        if( pNewModel != nullptr && pOldModel != nullptr )
            SetTextSizeDirty();

        sal_Int32 nCount = getTextCount();
        for( sal_Int32 nText = 0; nText < nCount; nText++ )
        {
            SdrText* pText = getText( nText );
            if( pText )
                pText->SetModel( pNewModel );
        }
    }

    if (bLinked && bChg)
    {
        ImpRegisterLink();
    }
}

void SdrTextObj::NbcSetEckenradius(long nRad)
{
    SetObjectItem(makeSdrEckenradiusItem(nRad));
@@ -487,7 +524,7 @@ void SdrTextObj::AdaptTextMinSize()
        // Only do this for text frame.
        return;

    if (getSdrModelFromSdrObject().IsPasteResize())
    if (pModel && pModel->IsPasteResize())
        // Don't do this during paste resize.
        return;

@@ -717,9 +754,11 @@ void SdrTextObj::TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRe

    if (pPara)
    {
        const bool bHitTest(&getSdrModelFromSdrObject().GetHitTestOutliner() == &rOutliner);
        const SdrTextObj* pTestObj = rOutliner.GetTextObj();
        bool bHitTest = false;
        if( pModel )
            bHitTest = &pModel->GetHitTestOutliner() == &rOutliner;

        const SdrTextObj* pTestObj = rOutliner.GetTextObj();
        if( !pTestObj || !bHitTest || pTestObj != this ||
            pTestObj->GetOutlinerParaObject() != pOutlinerParaObject )
        {
@@ -1010,9 +1049,9 @@ OUString SdrTextObj::TakeObjNamePlural() const
    return sName;
}

SdrTextObj* SdrTextObj::Clone(SdrModel* pTargetModel) const
SdrTextObj* SdrTextObj::Clone() const
{
    return CloneHelper< SdrTextObj >(pTargetModel);
    return CloneHelper< SdrTextObj >();
}

SdrTextObj& SdrTextObj::operator=(const SdrTextObj& rObj)
@@ -1072,7 +1111,7 @@ basegfx::B2DPolyPolygon SdrTextObj::TakeContour() const
    basegfx::B2DPolyPolygon aRetval(SdrAttrObj::TakeContour());

    // and now add the BoundRect of the text, if necessary
    if ( GetOutlinerParaObject() && !IsFontwork() && !IsContourTextFrame() )
    if ( pModel && GetOutlinerParaObject() && !IsFontwork() && !IsContourTextFrame() )
    {
        // using Clone()-Paint() strategy inside TakeContour() leaves a destroyed
        // SdrObject as pointer in DrawOutliner. Set *this again in fetching the outliner
@@ -1174,7 +1213,7 @@ void SdrTextObj::ImpInitDrawOutliner( SdrOutliner& rOutl ) const

SdrOutliner& SdrTextObj::ImpGetDrawOutliner() const
{
    SdrOutliner& rOutl(getSdrModelFromSdrObject().GetDrawOutliner(this));
    SdrOutliner& rOutl=pModel->GetDrawOutliner(this);

    // Code extracted to ImpInitDrawOutliner()
    ImpInitDrawOutliner( rOutl );
@@ -1222,7 +1261,7 @@ void SdrTextObj::ImpSetupDrawOutlinerForPaint( bool             bContourFrame,
double SdrTextObj::GetFontScaleY() const
{
    SdrText* pText = getActiveText();
    if (pText == nullptr || !pText->GetOutlinerParaObject())
    if (pText == nullptr || !pText->GetOutlinerParaObject() || pModel == nullptr)
        return 1.0;

    SdrOutliner& rOutliner = ImpGetDrawOutliner();
@@ -1364,21 +1403,17 @@ void SdrTextObj::UpdateOutlinerFormatting( SdrOutliner& rOutl, tools::Rectangle&
    tools::Rectangle aAnchorRect;
    Fraction aFitXCorrection(1,1);

    const bool bContourFrame(IsContourTextFrame());
    const MapMode aMapMode(
        getSdrModelFromSdrObject().GetScaleUnit(),
        Point(0,0),
        getSdrModelFromSdrObject().GetScaleFraction(),
        getSdrModelFromSdrObject().GetScaleFraction());
    bool bContourFrame=IsContourTextFrame();

    rOutl.SetRefMapMode(aMapMode);
    ImpSetupDrawOutlinerForPaint(
        bContourFrame,
        rOutl,
        aTextRect,
        aAnchorRect,
        rPaintRect,
        aFitXCorrection);
    if( GetModel() )
    {
        MapMode aMapMode(GetModel()->GetScaleUnit(), Point(0,0),
                         GetModel()->GetScaleFraction(),
                         GetModel()->GetScaleFraction());
        rOutl.SetRefMapMode(aMapMode);
    }

    ImpSetupDrawOutlinerForPaint( bContourFrame, rOutl, aTextRect, aAnchorRect, rPaintRect, aFitXCorrection );
}


@@ -1526,7 +1561,7 @@ TextChain *SdrTextObj::GetTextChain() const
    //if (!IsChainable())
    //    return NULL;

    return getSdrModelFromSdrObject().GetTextChain();
    return pModel->GetTextChain();
}

bool SdrTextObj::IsVerticalWriting() const
@@ -1635,7 +1670,7 @@ bool SdrTextObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DP
    basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top());

    // position maybe relative to anchorpos, convert
    if( getSdrModelFromSdrObject().IsWriter() )
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
@@ -1734,7 +1769,7 @@ void SdrTextObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const b
    }

    // if anchor is used, make position relative to it
    if( getSdrModelFromSdrObject().IsWriter() )
    if( pModel && pModel->IsWriter() )
    {
        if(GetAnchorPos().X() || GetAnchorPos().Y())
        {
diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx
index b507369..af6977f 100644
--- a/svx/source/svdraw/svdotextdecomposition.cxx
+++ b/svx/source/svdraw/svdotextdecomposition.cxx
@@ -973,9 +973,8 @@ void SdrTextObj::impDecomposeBlockTextPrimitive(
            // Usual processing - always grow in one of directions
            bool bAllowGrowVertical = !bVerticalWriting;
            bool bAllowGrowHorizontal = bVerticalWriting;

            // Compatibility mode for tdf#99729
            if (getSdrModelFromSdrObject().IsAnchoredTextOverflowLegacy())
            if (pModel->IsAnchoredTextOverflowLegacy())
            {
                bAllowGrowVertical = bHorizontalIsBlock;
                bAllowGrowHorizontal = bVerticalIsBlock;
@@ -1467,7 +1466,7 @@ void SdrTextObj::impHandleChainingEventsDuringDecomposition(SdrOutliner &rOutlin

    if (bIsOverflow && !IsInEditMode()) {
        // Initialize Chaining Outliner
        SdrOutliner &rChainingOutl(getSdrModelFromSdrObject().GetChainingOutliner(this));
        SdrOutliner &rChainingOutl = pModel->GetChainingOutliner(this);
        ImpInitDrawOutliner( rChainingOutl );
        rChainingOutl.SetUpdateMode(true);
        // We must pass the chaining outliner otherwise we would mess up decomposition
diff --git a/svx/source/svdraw/svdotxat.cxx b/svx/source/svdraw/svdotxat.cxx
index e88e555..f4c9528 100644
--- a/svx/source/svdraw/svdotxat.cxx
+++ b/svx/source/svdraw/svdotxat.cxx
@@ -62,6 +62,10 @@ bool SdrTextObj::AdjustTextFrameWidthAndHeight( tools::Rectangle& rR, bool bHgt,
        // Not a text frame.  Bail out.
        return false;

    if (!pModel)
        // Model doesn't exist.  Bail out.
        return false;

    if (rR.IsEmpty())
        // Empty rectangle.
        return false;
@@ -91,7 +95,7 @@ bool SdrTextObj::AdjustTextFrameWidthAndHeight( tools::Rectangle& rR, bool bHgt,
    aNewSize.AdjustWidth( -1 ); aNewSize.AdjustHeight( -1 );

    Size aMaxSiz(100000, 100000);
    Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize());
    Size aTmpSiz = pModel->GetMaxObjSize();

    if (aTmpSiz.Width())
        aMaxSiz.setWidth( aTmpSiz.Width() );
@@ -308,7 +312,7 @@ bool SdrTextObj::AdjustTextFrameWidthAndHeight()

void SdrTextObj::ImpSetTextStyleSheetListeners()
{
    SfxStyleSheetBasePool* pStylePool(getSdrModelFromSdrObject().GetStyleSheetPool());
    SfxStyleSheetBasePool* pStylePool=pModel!=nullptr ? pModel->GetStyleSheetPool() : nullptr;
    if (pStylePool!=nullptr)
    {
        std::vector<OUString> aStyleNames;
diff --git a/svx/source/svdraw/svdotxed.cxx b/svx/source/svdraw/svdotxed.cxx
index bb3e60d..3290435 100644
--- a/svx/source/svdraw/svdotxed.cxx
+++ b/svx/source/svdraw/svdotxed.cxx
@@ -49,7 +49,7 @@ bool SdrTextObj::BegTextEdit(SdrOutliner& rOutl)
    if ( !IsOutlText() )
        nOutlinerMode = OutlinerMode::TextObject;
    rOutl.Init( nOutlinerMode );
    rOutl.SetRefDevice(getSdrModelFromSdrObject().GetRefDevice());
    rOutl.SetRefDevice( pModel->GetRefDevice() );

    bool bFitToSize(IsFitToSize());
    bool bContourFrame=IsContourTextFrame();
@@ -146,9 +146,11 @@ void SdrTextObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, tools::Recta
    Size aAnkSiz(aViewInit.GetSize());
    aAnkSiz.AdjustWidth( -1 ); aAnkSiz.AdjustHeight( -1 ); // because GetSize() adds 1
    Size aMaxSiz(1000000,1000000);
    Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize());
    if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() );
    if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() );
    if (pModel!=nullptr) {
        Size aTmpSiz(pModel->GetMaxObjSize());
        if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() );
        if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() );
    }

    // Done earlier since used in else tree below
    SdrTextHorzAdjust eHAdj(GetTextHorizontalAdjust());
diff --git a/svx/source/svdraw/svdotxln.cxx b/svx/source/svdraw/svdotxln.cxx
index 27d4b96..75964d9 100644
--- a/svx/source/svdraw/svdotxln.cxx
+++ b/svx/source/svdraw/svdotxln.cxx
@@ -67,9 +67,8 @@ void ImpSdrObjTextLink::Closed()
    const OUString& /*rMimeType*/, const css::uno::Any & /*rValue */)
{
    bool bForceReload = false;
    SdrModel* pModel(pSdrObj ? &pSdrObj->getSdrModelFromSdrObject() : nullptr);
    sfx2::LinkManager* pLinkManager(pModel ? pModel->GetLinkManager() : nullptr);

    SdrModel* pModel = pSdrObj ? pSdrObj->GetModel() : nullptr;
    sfx2::LinkManager* pLinkManager= pModel ? pModel->GetLinkManager() : nullptr;
    if( pLinkManager )
    {
        ImpSdrObjTextLinkUserData* pData=pSdrObj->GetLinkUserData();
@@ -255,7 +254,7 @@ ImpSdrObjTextLinkUserData* SdrTextObj::GetLinkUserData() const
void SdrTextObj::ImpRegisterLink()
{
    ImpSdrObjTextLinkUserData* pData=GetLinkUserData();
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
    sfx2::LinkManager* pLinkManager=pModel!=nullptr ? pModel->GetLinkManager() : nullptr;
    if (pLinkManager!=nullptr && pData!=nullptr && pData->pLink==nullptr) { // don't register twice
        pData->pLink = new ImpSdrObjTextLink(this);
        pLinkManager->InsertFileLink(*pData->pLink,OBJECT_CLIENT_FILE,pData->aFileName,
@@ -267,7 +266,7 @@ void SdrTextObj::ImpRegisterLink()
void SdrTextObj::ImpDeregisterLink()
{
    ImpSdrObjTextLinkUserData* pData=GetLinkUserData();
    sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
    sfx2::LinkManager* pLinkManager=pModel!=nullptr ? pModel->GetLinkManager() : nullptr;
    if (pLinkManager!=nullptr && pData!=nullptr && pData->pLink!=nullptr) { // don't register twice
        // when doing Remove, *pLink is deleted implicitly
        pLinkManager->Remove( pData->pLink.get() );
diff --git a/svx/source/svdraw/svdotxtr.cxx b/svx/source/svdraw/svdotxtr.cxx
index 1a6d4a5..40eca10 100644
--- a/svx/source/svdraw/svdotxtr.cxx
+++ b/svx/source/svdraw/svdotxtr.cxx
@@ -175,7 +175,7 @@ void SdrTextObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract

    AdaptTextMinSize();

    if(bTextFrame && !getSdrModelFromSdrObject().IsPasteResize())
    if(bTextFrame && (!pModel || !pModel->IsPasteResize()))
    {
        NbcAdjustTextFrameWidthAndHeight();
    }
@@ -313,7 +313,7 @@ SdrObject* SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const
        if(nResultCount)
        {
            // prepare own target
            SdrObjGroup* pGroup = new SdrObjGroup(getSdrModelFromSdrObject());
            SdrObjGroup* pGroup = new SdrObjGroup();
            SdrObjList* pObjectList = pGroup->GetSubList();

            // process results
@@ -355,10 +355,7 @@ SdrObject* SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const
                        aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_SOLID));

                        // create filled SdrPathObj
                        pPathObj = new SdrPathObj(
                            getSdrModelFromSdrObject(),
                            OBJ_PATHFILL,
                            aPolyPolygon);
                        pPathObj = new SdrPathObj(OBJ_PATHFILL, aPolyPolygon);
                    }
                    else
                    {
@@ -369,16 +366,18 @@ SdrObject* SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const
                        aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_NONE));

                        // create line SdrPathObj
                        pPathObj = new SdrPathObj(
                            getSdrModelFromSdrObject(),
                            OBJ_PATHLINE,
                            aPolyPolygon);
                        pPathObj = new SdrPathObj(OBJ_PATHLINE, aPolyPolygon);
                    }

                    // copy basic information from original
                    pPathObj->ImpSetAnchorPos(GetAnchorPos());
                    pPathObj->NbcSetLayer(GetLayer());
                    pPathObj->NbcSetStyleSheet(GetStyleSheet(), true);

                    if(GetModel())
                    {
                        pPathObj->SetModel(GetModel());
                        pPathObj->NbcSetStyleSheet(GetStyleSheet(), true);
                    }

                    // apply prepared ItemSet and add to target
                    pPathObj->SetMergedItemSet(aAttributeSet);
@@ -434,10 +433,7 @@ SdrObject* SdrTextObj::ImpConvertMakeObj(const basegfx::B2DPolyPolygon& rPolyPol
        ePathKind = bClosed ? OBJ_POLY : OBJ_PLIN;
    }

    SdrPathObj* pPathObj = new SdrPathObj(
        getSdrModelFromSdrObject(),
        ePathKind,
        aB2DPolyPolygon);
    SdrPathObj* pPathObj = new SdrPathObj(ePathKind, aB2DPolyPolygon);

    if(bBezier)
    {
@@ -447,11 +443,18 @@ SdrObject* SdrTextObj::ImpConvertMakeObj(const basegfx::B2DPolyPolygon& rPolyPol

    pPathObj->ImpSetAnchorPos(aAnchor);
    pPathObj->NbcSetLayer(GetLayer());
    sdr::properties::ItemChangeBroadcaster aC(*pPathObj);
    pPathObj->ClearMergedItem();
    pPathObj->SetMergedItemSet(GetObjectItemSet());
    pPathObj->GetProperties().BroadcastItemChange(aC);
    pPathObj->NbcSetStyleSheet(GetStyleSheet(), true);

    if(pModel)
    {
        pPathObj->SetModel(pModel);

        sdr::properties::ItemChangeBroadcaster aC(*pPathObj);

        pPathObj->ClearMergedItem();
        pPathObj->SetMergedItemSet(GetObjectItemSet());
        pPathObj->GetProperties().BroadcastItemChange(aC);
        pPathObj->NbcSetStyleSheet(GetStyleSheet(), true);
    }

    return pPathObj;
}
@@ -486,7 +489,7 @@ SdrObject* SdrTextObj::ImpConvertAddText(SdrObject* pObj, bool bBezier) const
    else
    {
        // not yet a group, create one and add partial and new shapes
        SdrObjGroup* pGrp=new SdrObjGroup(getSdrModelFromSdrObject());
        SdrObjGroup* pGrp=new SdrObjGroup;
        SdrObjList* pOL=pGrp->GetSubList();
        pOL->InsertObject(pObj);
        pOL->InsertObject(pText);
diff --git a/svx/source/svdraw/svdouno.cxx b/svx/source/svdraw/svdouno.cxx
index 4a0e071..6e364c3 100644
--- a/svx/source/svdraw/svdouno.cxx
+++ b/svx/source/svdraw/svdouno.cxx
@@ -145,11 +145,9 @@ namespace
    }
}

SdrUnoObj::SdrUnoObj(
    SdrModel& rSdrModel,
    const OUString& rModelName)
:   SdrRectObj(rSdrModel),
    m_pImpl( new SdrUnoObjDataHolder )

SdrUnoObj::SdrUnoObj(const OUString& rModelName)
:   m_pImpl( new SdrUnoObjDataHolder )
{
    bIsUnoObj = true;

@@ -160,12 +158,9 @@ SdrUnoObj::SdrUnoObj(
        CreateUnoControlModel(rModelName);
}

SdrUnoObj::SdrUnoObj(
    SdrModel& rSdrModel,
    const OUString& rModelName,
    const uno::Reference< lang::XMultiServiceFactory >& rxSFac)
:   SdrRectObj(rSdrModel),
    m_pImpl( new SdrUnoObjDataHolder )
SdrUnoObj::SdrUnoObj(const OUString& rModelName,
                     const uno::Reference< lang::XMultiServiceFactory >& rxSFac)
:   m_pImpl( new SdrUnoObjDataHolder )
{
    bIsUnoObj = true;

@@ -255,9 +250,9 @@ OUString SdrUnoObj::TakeObjNamePlural() const
    return ImpGetResStr(STR_ObjNamePluralUno);
}

SdrUnoObj* SdrUnoObj::Clone(SdrModel* pTargetModel) const
SdrUnoObj* SdrUnoObj::Clone() const
{
    return CloneHelper< SdrUnoObj >(pTargetModel);
    return CloneHelper< SdrUnoObj >();
}

SdrUnoObj& SdrUnoObj::operator= (const SdrUnoObj& rObj)
@@ -333,6 +328,38 @@ bool SdrUnoObj::hasSpecialDrag() const
    return false;
}

bool SdrUnoObj::supportsFullDrag() const
{
    // override to have the possibility to enable/disable in debug and
    // to check some things out. Current solution is working, so default is
    // enabled
    static bool bDoSupportFullDrag(true);

    return bDoSupportFullDrag;
}

SdrObject* SdrUnoObj::getFullDragClone() const
{
    SdrObject* pRetval = nullptr;
    static bool bHandleSpecial(false);

    if(bHandleSpecial)
    {
        // special handling for SdrUnoObj (FormControl). Create a SdrGrafObj
        // for drag containing the graphical representation. This does not work too
        // well, so the default is to simply clone
        pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
    }
    else
    {
        // call parent (simply clone)
        pRetval = SdrRectObj::getFullDragClone();
    }

    return pRetval;
}


void SdrUnoObj::NbcSetLayer( SdrLayerID _nLayer )
{
    if ( GetLayer() == _nLayer )
diff --git a/svx/source/svdraw/svdovirt.cxx b/svx/source/svdraw/svdovirt.cxx
index 4306ecd5..2ffcdc3 100644
--- a/svx/source/svdraw/svdovirt.cxx
+++ b/svx/source/svdraw/svdovirt.cxx
@@ -42,10 +42,8 @@ sdr::contact::ViewContact* SdrVirtObj::CreateObjectSpecificViewContact()
    return new sdr::contact::ViewContactOfVirtObj(*this);
}

SdrVirtObj::SdrVirtObj(
    SdrModel& rSdrModel,
    SdrObject& rNewObj)
:   SdrObject(rSdrModel),

SdrVirtObj::SdrVirtObj(SdrObject& rNewObj):
    rRefObj(rNewObj)
{
    bVirtObj=true; // this is only a virtual object
@@ -58,6 +56,7 @@ SdrVirtObj::~SdrVirtObj()
    rRefObj.DelReference(*this);
}


const SdrObject& SdrVirtObj::GetReferencedObj() const
{
    return rRefObj;
@@ -82,6 +81,13 @@ void SdrVirtObj::NbcSetAnchorPos(const Point& rAnchorPos)
    aAnchor=rAnchorPos;
}


void SdrVirtObj::SetModel(SdrModel* pNewModel)
{
    SdrObject::SetModel(pNewModel);
    rRefObj.SetModel(pNewModel);
}

void SdrVirtObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
{
    rRefObj.TakeObjInfo(rInfo);
@@ -122,29 +128,15 @@ void SdrVirtObj::RecalcBoundRect()
    aOutRect+=aAnchor;
}

SdrVirtObj* SdrVirtObj::Clone(SdrModel* pTargetModel) const
SdrVirtObj* SdrVirtObj::Clone() const
{
    return CloneHelper< SdrVirtObj >(pTargetModel);
    // TTTT not sure if the above works - how could SdrObjFactory::MakeNewObject
    // create an object wit correct rRefObj (?) OTOH VirtObj probably needs not
    // to be cloned ever - only used in Writer for multiple instances e.g. Header/Footer
    // return new SdrVirtObj(
    //     getSdrModelFromSdrObject(),
    //     rRefObj); // only a further reference
    return new SdrVirtObj(rRefObj); // only a further reference
}

SdrVirtObj& SdrVirtObj::operator=(const SdrVirtObj& rObj)
{
{   // reference different object??
    SdrObject::operator=(rObj);

    // reference different object?? TTTT -> yes!
    rRefObj.DelReference(*this);
    rRefObj = rObj.rRefObj;
    rRefObj.AddReference(*this);

    aSnapRect = rObj.aSnapRect;
    aAnchor = rObj.aAnchor;

    aAnchor=rObj.aAnchor;
    return *this;
}

@@ -274,11 +266,24 @@ bool SdrVirtObj::supportsFullDrag() const

SdrObject* SdrVirtObj::getFullDragClone() const
{
    SdrObject& rReferencedObject = const_cast<SdrVirtObj*>(this)->ReferencedObj();
    return new SdrGrafObj(
        getSdrModelFromSdrObject(),
        SdrDragView::GetObjGraphic(rReferencedObject),
        GetLogicRect());
    static bool bSpecialHandling(false);
    SdrObject* pRetval = nullptr;

    if(bSpecialHandling)
    {
        // special handling for VirtObj. Do not create another
        // reference to rRefObj, this would allow to change that
        // one on drag. Instead, create a SdrGrafObj for drag containing
        // the graphical representation
        pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), this), GetLogicRect());
    }
    else
    {
        SdrObject& rReferencedObject = const_cast<SdrVirtObj*>(this)->ReferencedObj();
        pRetval = new SdrGrafObj(SdrDragView::GetObjGraphic(GetModel(), &rReferencedObject), GetLogicRect());
    }

    return pRetval;
}

bool SdrVirtObj::beginSpecialDrag(SdrDragStat& rDrag) const
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 2dff0a9..7ff4129 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -70,12 +70,13 @@ public:
static const sal_Int32 InitialObjectContainerCapacity (64);


SdrObjList::SdrObjList(SdrPage* pNewPage)
:   maList(),
SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage):
    maList(),
    mxNavigationOrder(),
    mbIsNavigationOrderDirty(false)
{
    maList.reserve(InitialObjectContainerCapacity);
    pModel=pNewModel;
    pPage=pNewPage;
    pUpList=nullptr;
    bObjOrdNumsDirty=false;
@@ -84,46 +85,58 @@ SdrObjList::SdrObjList(SdrPage* pNewPage)
    eListKind=SdrObjListKind::Unknown;
}

SdrObjList::SdrObjList():
    maList(),
    mxNavigationOrder(),
    mbIsNavigationOrderDirty(false)
{
    maList.reserve(InitialObjectContainerCapacity);
    pModel=nullptr;
    pPage=nullptr;
    pUpList=nullptr;
    bObjOrdNumsDirty=false;
    bRectsDirty=false;
    pOwnerObj=nullptr;
    eListKind=SdrObjListKind::Unknown;
}

SdrObjList::~SdrObjList()
{

    // To avoid that the Clear() method will broadcast changes when in destruction
    // which would call virtual method (not allowed in destructor), the model is set
    // to NULL here.
    pModel = nullptr;

    Clear(); // delete contents of container
}

SdrObjList* SdrObjList::CloneSdrObjList(SdrModel* pNewModel) const
{
    SdrObjList* pObjList = new SdrObjList();
    pObjList->lateInitSdrObjList(*this, pNewModel);
    return pObjList;
}

void SdrObjList::lateInitSdrObjList(const SdrObjList& rSrcList, SdrModel* pNewModel)
void SdrObjList::lateInit(const SdrObjList& rSrcList)
{
    // this function is only supposed to be called once, right after construction
    assert(maList.empty());

    eListKind=rSrcList.eListKind;
    CopyObjects(rSrcList, pNewModel);
    CopyObjects(rSrcList);
}

void SdrObjList::CopyObjects(const SdrObjList& rSrcList, SdrModel* pNewModel)
void SdrObjList::CopyObjects(const SdrObjList& rSrcList)
{
    Clear();
    bObjOrdNumsDirty = false;
    bRectsDirty = false;
    size_t nCloneErrCnt(0);
    const size_t nCount(rSrcList.GetObjCount());
    bObjOrdNumsDirty=false;
    bRectsDirty     =false;
    size_t nCloneErrCnt = 0;
    const size_t nCount = rSrcList.GetObjCount();
    for (size_t no=0; no<nCount; ++no) {
        SdrObject* pSO=rSrcList.GetObj(no);

    for (size_t no(0); no < nCount; ++no)
    {
        SdrObject* pSO(rSrcList.GetObj(no));
        SdrObject* pDO(pSO->Clone(pNewModel));
        SdrObject* pDO = pSO->Clone();

        if(nullptr != pDO)
        {
        if (pDO!=nullptr) {
            pDO->SetModel(pModel);
            pDO->SetPage(pPage);
            NbcInsertObject(pDO, SAL_MAX_SIZE);
        }
        else
        {
        } else {
            nCloneErrCnt++;
        }
    }
@@ -196,9 +209,9 @@ void SdrObjList::CopyObjects(const SdrObjList& rSrcList, SdrModel* pNewModel)

void SdrObjList::Clear()
{
    SdrModel* pSdrModelFromRemovedSdrObject(nullptr);
    bool bObjectsRemoved(false);

    while(!maList.empty())
    while( ! maList.empty())
    {
        // remove last object from list
        SdrObject* pObj = maList.back();
@@ -208,22 +221,22 @@ void SdrObjList::Clear()
        // to delete the object and thus refresh visualisations
        pObj->GetViewContact().flushViewObjectContacts();

        if(nullptr == pSdrModelFromRemovedSdrObject)
        {
            pSdrModelFromRemovedSdrObject = &pObj->getSdrModelFromSdrObject();
        }
        bObjectsRemoved = true;

        // sent remove hint (after removal, see RemoveObject())
        SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj, pPage);
        pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        if(pModel)
        {
            SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj, pPage);
            pModel->Broadcast(aHint);
        }

        // delete the object itself
        SdrObject::Free( pObj );
    }

    if(nullptr != pSdrModelFromRemovedSdrObject)
    if(pModel && bObjectsRemoved)
    {
        pSdrModelFromRemovedSdrObject->SetChanged();
        pModel->SetChanged();
    }
}

@@ -244,6 +257,23 @@ void SdrObjList::SetPage(SdrPage* pNewPage)
    }
}

SdrModel* SdrObjList::GetModel() const
{
    return pModel;
}

void SdrObjList::SetModel(SdrModel* pNewModel)
{
    if (pModel!=pNewModel) {
        pModel=pNewModel;
        const size_t nCount = GetObjCount();
        for (size_t i=0; i<nCount; ++i) {
            SdrObject* pObj=GetObj(i);
            pObj->SetModel(pModel);
        }
    }
}

void SdrObjList::RecalcObjOrdNums()
{
    const size_t nCount = GetObjCount();
@@ -339,15 +369,18 @@ void SdrObjList::InsertObject(SdrObject* pObj, size_t nPos)
            pOwnerObj->ActionChanged();
        }

        // TODO: We need a different broadcast here!
        // Repaint from object number ... (heads-up: GroupObj)
        if(pObj->GetPage())
        if(pModel)
        {
            SdrHint aHint(SdrHintKind::ObjectInserted, *pObj);
            pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        }
            // TODO: We need a different broadcast here!
            // Repaint from object number ... (heads-up: GroupObj)
            if(pObj->GetPage())
            {
                SdrHint aHint(SdrHintKind::ObjectInserted, *pObj);
                pModel->Broadcast(aHint);
            }

        pObj->getSdrModelFromSdrObject().SetChanged();
            pModel->SetChanged();
        }
    }
}

@@ -399,17 +432,16 @@ SdrObject* SdrObjList::RemoveObject(size_t nObjNum)
    {
        // flushViewObjectContacts() clears the VOC's and those invalidate
        pObj->GetViewContact().flushViewObjectContacts();

        DBG_ASSERT(pObj->IsInserted(),"The object does not have the status Inserted.");

        // TODO: We need a different broadcast here.
        if (pObj->GetPage()!=nullptr)
        {
            SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj);
            pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        if (pModel!=nullptr) {
            // TODO: We need a different broadcast here.
            if (pObj->GetPage()!=nullptr) {
                SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj);
                pModel->Broadcast(aHint);
            }
            pModel->SetChanged();
        }

        pObj->getSdrModelFromSdrObject().SetChanged();

        pObj->SetInserted(false); // calls, among other things, the UserCall
        pObj->SetObjList(nullptr);
        pObj->SetPage(nullptr);
@@ -482,14 +514,13 @@ SdrObject* SdrObjList::ReplaceObject(SdrObject* pNewObj, size_t nObjNum)
    DBG_ASSERT(pObj!=nullptr,"SdrObjList::ReplaceObject: Could not find object to remove.");
    if (pObj!=nullptr) {
        DBG_ASSERT(pObj->IsInserted(),"SdrObjList::ReplaceObject: the object does not have status Inserted.");

        // TODO: We need a different broadcast here.
        if (pObj->GetPage()!=nullptr)
        {
            SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj);
            pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        if (pModel!=nullptr) {
            // TODO: We need a different broadcast here.
            if (pObj->GetPage()!=nullptr) {
                SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj);
                pModel->Broadcast(aHint);
            }
        }

        pObj->SetInserted(false);
        pObj->SetObjList(nullptr);
        pObj->SetPage(nullptr);
@@ -507,15 +538,14 @@ SdrObject* SdrObjList::ReplaceObject(SdrObject* pNewObj, size_t nObjNum)
        impChildInserted(*pNewObj);

        pNewObj->SetInserted(true);

        // TODO: We need a different broadcast here.
        if (pNewObj->GetPage()!=nullptr) {
            SdrHint aHint(SdrHintKind::ObjectInserted, *pNewObj);
            pNewObj->getSdrModelFromSdrObject().Broadcast(aHint);
        if (pModel!=nullptr) {
            // TODO: We need a different broadcast here.
            if (pNewObj->GetPage()!=nullptr) {
                SdrHint aHint(SdrHintKind::ObjectInserted, *pNewObj);
                pModel->Broadcast(aHint);
            }
            pModel->SetChanged();
        }

        pNewObj->getSdrModelFromSdrObject().SetChanged();

        SetRectsDirty();
    }
    return pObj;
@@ -544,11 +574,13 @@ SdrObject* SdrObjList::SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum)

        pObj->SetOrdNum(nNewObjNum);
        bObjOrdNumsDirty=true;

        // TODO: We need a different broadcast here.
        if (pObj->GetPage()!=nullptr)
            pObj->getSdrModelFromSdrObject().Broadcast(SdrHint(SdrHintKind::ObjectChange, *pObj));
        pObj->getSdrModelFromSdrObject().SetChanged();
        if (pModel!=nullptr)
        {
            // TODO: We need a different broadcast here.
            if (pObj->GetPage()!=nullptr)
                pModel->Broadcast(SdrHint(SdrHintKind::ObjectChange, *pObj));
            pModel->SetChanged();
        }
    }
    return pObj;
}
@@ -749,7 +781,8 @@ void SdrObjList::SetObjectNavigationPosition (
        mbIsNavigationOrderDirty = true;

        // The navigation order is written out to file so mark the model as modified.
        rObject.getSdrModelFromSdrObject().SetChanged();
        if (pModel != nullptr)
            pModel->SetChanged();
    }
}

@@ -1015,18 +1048,20 @@ void SdrPageProperties::ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet)
void ImpPageChange(SdrPage& rSdrPage)
{
    rSdrPage.ActionChanged();
    rSdrPage.getSdrModelFromSdrPage().SetChanged();
    SdrHint aHint(SdrHintKind::PageOrderChange, &rSdrPage);
    rSdrPage.getSdrModelFromSdrPage().Broadcast(aHint);

    if(rSdrPage.GetModel())
    {
        rSdrPage.GetModel()->SetChanged();
        SdrHint aHint(SdrHintKind::PageOrderChange, &rSdrPage);
        rSdrPage.GetModel()->Broadcast(aHint);
    }
}

SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage)
:   SfxListener(),
    mpSdrPage(&rSdrPage),
    mpStyleSheet(nullptr),
    maProperties(
        mpSdrPage->getSdrModelFromSdrPage().GetItemPool(),
        svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{})
    maProperties(mpSdrPage->GetModel()->GetItemPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{})
{
    if(!rSdrPage.IsMasterPage())
    {
@@ -1101,23 +1136,18 @@ void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet)
}


SdrPage::SdrPage(SdrModel& rModel, bool bMasterPage)
:   tools::WeakBase(),
    SdrObjList(this),
    maPageUsers(),
SdrPage::SdrPage(SdrModel& rNewModel, bool bMasterPage)
:   SdrObjList(&rNewModel, this),
    mpViewContact(nullptr),
    mrSdrModelFromSdrPage(rModel),
    mnWidth(10),
    mnHeight(10),
    mnBorderLeft(0),
    mnBorderUpper(0),
    mnBorderRight(0),
    mnBorderLower(0),
    mpLayerAdmin(new SdrLayerAdmin(&rModel.GetLayerAdmin())),
    mpLayerAdmin(new SdrLayerAdmin(&rNewModel.GetLayerAdmin())),
    mpSdrPageProperties(nullptr),
    mxUnoPage(),
    mpMasterPageDescriptor(nullptr),
    aPrefVisiLayers(),
    nPageNum(0),
    mbMaster(bMasterPage),
    mbInserted(false),
@@ -1130,6 +1160,27 @@ SdrPage::SdrPage(SdrModel& rModel, bool bMasterPage)
    mpSdrPageProperties.reset(new SdrPageProperties(*this));
}

SdrPage::SdrPage(const SdrPage& rSrcPage)
:   SdrObjList(rSrcPage.pModel, this),
    mpViewContact(nullptr),
    mnWidth(rSrcPage.mnWidth),
    mnHeight(rSrcPage.mnHeight),
    mnBorderLeft(rSrcPage.mnBorderLeft),
    mnBorderUpper(rSrcPage.mnBorderUpper),
    mnBorderRight(rSrcPage.mnBorderRight),
    mnBorderLower(rSrcPage.mnBorderLower),
    mpLayerAdmin(new SdrLayerAdmin(rSrcPage.pModel->GetLayerAdmin())),
    mpSdrPageProperties(nullptr),
    mpMasterPageDescriptor(nullptr),
    nPageNum(rSrcPage.nPageNum),
    mbMaster(rSrcPage.mbMaster),
    mbInserted(false),
    mbObjectsNotPersistent(rSrcPage.mbObjectsNotPersistent),
    mbPageBorderOnlyLeftRight(rSrcPage.mbPageBorderOnlyLeftRight)
{
    aPrefVisiLayers.SetAll();
}

SdrPage::~SdrPage()
{
    if( mxUnoPage.is() ) try
@@ -1167,13 +1218,18 @@ SdrPage::~SdrPage()
    mpSdrPageProperties.reset();
}

void SdrPage::lateInit(const SdrPage& rSrcPage)
void SdrPage::lateInit(const SdrPage& rSrcPage, SdrModel* const pNewModel)
{
    assert(!mpViewContact);
    // SdrPageProperties get set by SdrPage::SdrPage already, so do not assert anymore
    // assert(!mpSdrPageProperties);
    assert(!mpSdrPageProperties);
    assert(!mxUnoPage.is());

    if (pNewModel && (pNewModel != pModel))
    {
        pModel = pNewModel;
        impl_setModelForLayerAdmin(pNewModel);
    }

    // copy all the local parameters to make this instance
    // a valid copy of source page before copying and inserting
    // the contained objects
@@ -1212,18 +1268,24 @@ void SdrPage::lateInit(const SdrPage& rSrcPage)
    }

    // Now copy the contained objects
    SdrObjList::lateInitSdrObjList(rSrcPage, &getSdrModelFromSdrPage());
    SdrObjList::lateInit(rSrcPage);

    // be careful and correct eListKind, a member of SdrObjList which
    // will be changed by the SdrObjList::lateInit before...
    eListKind = (mbMaster) ? SdrObjListKind::MasterPage : SdrObjListKind::DrawPage;
}

SdrPage* SdrPage::Clone() const
{
    return Clone(nullptr);
}

SdrPage* SdrPage::Clone(SdrModel* pNewModel) const
{
    SdrPage* pClonedPage(new SdrPage(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    pClonedPage->lateInit(*this);
    return pClonedPage;
    if (pNewModel==nullptr) pNewModel=pModel;
    SdrPage* pPage2=new SdrPage(*pNewModel);
    pPage2->lateInit(*this);
    return pPage2;
}

void SdrPage::SetSize(const Size& aSiz)
@@ -1373,6 +1435,59 @@ sal_Int32 SdrPage::GetLowerBorder() const
    return mnBorderLower;
}

void SdrPage::impl_setModelForLayerAdmin(SdrModel* const pNewModel)
{
    if (pNewModel!=nullptr) {
        mpLayerAdmin->SetParent(&pNewModel->GetLayerAdmin());
    } else {
        mpLayerAdmin->SetParent(nullptr);
    }
    mpLayerAdmin->SetModel(pNewModel);
}

void SdrPage::SetModel(SdrModel* pNewModel)
{
    SdrModel* pOldModel=pModel;
    SdrObjList::SetModel(pNewModel);

    if (pNewModel!=pOldModel)
    {
        impl_setModelForLayerAdmin( pNewModel );

        // create new SdrPageProperties with new model (due to SfxItemSet there)
        // and copy ItemSet and StyleSheet
        std::unique_ptr<SdrPageProperties> pNew(new SdrPageProperties(*this));

        if(!IsMasterPage())
        {
            const SfxItemSet& rOldSet = getSdrPageProperties().GetItemSet();
            SfxItemSet* pNewSet = rOldSet.Clone(false, &pNewModel->GetItemPool());
            //ensure checkForUniqueItem is called so new pages which have e.g.
            //XFillBitmapItem set, do not conflict with an existing XFillBitmapItem
            //with the same name but different properties
            SdrModel::MigrateItemSet(&rOldSet, pNewSet, pNewModel);
            pNew->PutItemSet(*pNewSet);
            delete pNewSet;
        }

        pNew->SetStyleSheet(getSdrPageProperties().GetStyleSheet());

        mpSdrPageProperties = std::move(pNew);
    }

    // update listeners at possible API wrapper object
    if( pOldModel != pNewModel )
    {
        if( mxUnoPage.is() )
        {
            SvxDrawPage* pPage2 = SvxDrawPage::getImplementation( mxUnoPage );
            if( pPage2 )
                pPage2->ChangeModel( pNewModel );
        }
    }
}


// #i68775# React on PageNum changes (from Model in most cases)
void SdrPage::SetPageNum(sal_uInt16 nNew)
{
@@ -1392,11 +1507,11 @@ sal_uInt16 SdrPage::GetPageNum() const
        return 0;

    if (mbMaster) {
        if (getSdrModelFromSdrPage().IsMPgNumsDirty())
            getSdrModelFromSdrPage().RecalcPageNums(true);
        if (pModel && pModel->IsMPgNumsDirty())
            pModel->RecalcPageNums(true);
    } else {
        if (getSdrModelFromSdrPage().IsPagNumsDirty())
            getSdrModelFromSdrPage().RecalcPageNums(false);
        if (pModel && pModel->IsPagNumsDirty())
            pModel->RecalcPageNums(false);
    }
    return nPageNum;
}
@@ -1406,7 +1521,11 @@ void SdrPage::SetChanged()
    // For test purposes, use the new ViewContact for change
    // notification now.
    ActionChanged();
    getSdrModelFromSdrPage().SetChanged();

    if( pModel )
    {
        pModel->SetChanged();
    }
}


diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx
index ff63498..da88ec5 100644
--- a/svx/source/svdraw/svdpagv.cxx
+++ b/svx/source/svdraw/svdpagv.cxx
@@ -898,25 +898,15 @@ sal_uInt16 SdrPageView::GetEnteredLevel() const

void SdrPageView::CheckAktGroup()
{
    SdrObject* pGrp(GetAktGroup());

    while(nullptr != pGrp &&
        (!pGrp->IsInserted() || nullptr == pGrp->GetObjList() || nullptr == pGrp->GetPage()))
    {
        // anything outside of the borders?
        pGrp = pGrp->GetUpGroup();
    SdrObject* pGrp=GetAktGroup();
    while (pGrp!=nullptr &&
           (!pGrp->IsInserted() || pGrp->GetObjList()==nullptr ||
            pGrp->GetPage()==nullptr || pGrp->GetModel()==nullptr)) { // anything outside of the borders?
        pGrp=pGrp->GetUpGroup();
    }

    if(pGrp != GetAktGroup())
    {
        if(nullptr != pGrp)
        {
            EnterGroup(pGrp);
        }
        else
        {
            LeaveAllGroup();
        }
    if (pGrp!=GetAktGroup()) {
        if (pGrp!=nullptr) EnterGroup(pGrp);
        else LeaveAllGroup();
    }
}

diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx
index ba0e252..48c971d 100644
--- a/svx/source/svdraw/svdpntv.cxx
+++ b/svx/source/svdraw/svdpntv.cxx
@@ -181,12 +181,9 @@ void SdrPaintView::ImpClearVars()
    maGridColor = COL_BLACK;
}

SdrPaintView::SdrPaintView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   mrSdrModelFromSdrView(rSdrModel),
    mpPageView(nullptr),
    maDefaultAttr(rSdrModel.GetItemPool()),
SdrPaintView::SdrPaintView(SdrModel* pModel, OutputDevice* pOut)
:   mpPageView(nullptr),
    maDefaultAttr(pModel->GetItemPool()),
    mbBufferedOutputAllowed(false),
    mbBufferedOverlayAllowed(false),
    mbPagePaintingAllowed(true),
@@ -195,7 +192,7 @@ SdrPaintView::SdrPaintView(
    mbHideDraw(false),
    mbHideFormControl(false)
{
    mpModel=&rSdrModel;
    mpModel=pModel;
    ImpClearVars();

    if(pOut)
diff --git a/svx/source/svdraw/svdpoev.cxx b/svx/source/svdraw/svdpoev.cxx
index 56e3286..509eb11 100644
--- a/svx/source/svdraw/svdpoev.cxx
+++ b/svx/source/svdraw/svdpoev.cxx
@@ -44,10 +44,8 @@ void SdrPolyEditView::ImpResetPolyPossibilityFlags()
    bSetMarkedSegmentsKindPossible=false;
}

SdrPolyEditView::SdrPolyEditView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrEditView(rSdrModel, pOut)
SdrPolyEditView::SdrPolyEditView(SdrModel* pModel1, OutputDevice* pOut):
    SdrEditView(pModel1,pOut)
{
    ImpResetPolyPossibilityFlags();
}
diff --git a/svx/source/svdraw/svdsnpv.cxx b/svx/source/svdraw/svdsnpv.cxx
index 10aacc3..94f1f5a 100644
--- a/svx/source/svdraw/svdsnpv.cxx
+++ b/svx/source/svdraw/svdsnpv.cxx
@@ -165,31 +165,30 @@ void ImplHelpLineOverlay::SetPosition(const basegfx::B2DPoint& rNewPosition)
    }
}

SdrSnapView::SdrSnapView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrPaintView(rSdrModel, pOut)
    ,mpPageOriginOverlay(nullptr)
    ,mpHelpLineOverlay(nullptr)
    ,nMagnSizPix(4)
    ,nSnapAngle(1500)
    ,nEliminatePolyPointLimitAngle(0)
    ,eCrookMode(SdrCrookMode::Rotate)
    ,bSnapEnab(true)
    ,bGridSnap(true)
    ,bBordSnap(true)
    ,bHlplSnap(true)
    ,bOFrmSnap(true)
    ,bOPntSnap(false)
    ,bOConSnap(true)
    ,bMoveSnapOnlyTopLeft(false)
    ,bOrtho(false)
    ,bBigOrtho(true)
    ,bAngleSnapEnab(false)
    ,bMoveOnlyDragging(false)
    ,bSlantButShear(false)
    ,bCrookNoContortion(false)
    ,bEliminatePolyPoints(false)

SdrSnapView::SdrSnapView(SdrModel* pModel1, OutputDevice* pOut)
    : SdrPaintView(pModel1,pOut)
    , mpPageOriginOverlay(nullptr)
    , mpHelpLineOverlay(nullptr)
    , nMagnSizPix(4)
    , nSnapAngle(1500)
    , nEliminatePolyPointLimitAngle(0)
    , eCrookMode(SdrCrookMode::Rotate)
    , bSnapEnab(true)
    , bGridSnap(true)
    , bBordSnap(true)
    , bHlplSnap(true)
    , bOFrmSnap(true)
    , bOPntSnap(false)
    , bOConSnap(true)
    , bMoveSnapOnlyTopLeft(false)
    , bOrtho(false)
    , bBigOrtho(true)
    , bAngleSnapEnab(false)
    , bMoveOnlyDragging(false)
    , bSlantButShear(false)
    , bCrookNoContortion(false)
    , bEliminatePolyPoints(false)
{
}

diff --git a/svx/source/svdraw/svdtext.cxx b/svx/source/svdraw/svdtext.cxx
index 5495788..159f863 100644
--- a/svx/source/svdraw/svdtext.cxx
+++ b/svx/source/svdraw/svdtext.cxx
@@ -31,6 +31,7 @@
SdrText::SdrText( SdrTextObj& rObject )
: mpOutlinerParaObject( nullptr )
, mrObject( rObject )
, mpModel( rObject.GetModel() )
, mbPortionInfoChecked( false )
{
    OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)");
@@ -47,12 +48,11 @@ void SdrText::CheckPortionInfo( SdrOutliner& rOutliner )
    {
        // #i102062# no action when the Outliner is the HitTestOutliner,
        // this will remove WrongList info at the OPO
        if(&rOutliner == &mrObject.getSdrModelFromSdrObject().GetHitTestOutliner())
        if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner())
            return;

        // TODO: optimization: we could create a BigTextObject
        mbPortionInfoChecked=true;

        if(mpOutlinerParaObject!=nullptr && rOutliner.ShouldCreateBigTextObject())
        {
            // #i102062# MemoryLeak closed
@@ -76,15 +76,16 @@ void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
{
    if( mpOutlinerParaObject.get() != pTextObject )
    {
        // Update HitTestOutliner
        const SdrTextObj* pTestObj(mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().GetTextObj());

        if(pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get())
        if( mpModel )
        {
            mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().SetTextObj(nullptr);
            // Update HitTestOutliner
            const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
            if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get() )
                mpModel->GetHitTestOutliner().SetTextObj( nullptr );
        }

        mpOutlinerParaObject.reset(pTextObject);

        mbPortionInfoChecked = false;
    }
}
@@ -97,33 +98,82 @@ OutlinerParaObject* SdrText::GetOutlinerParaObject() const
/** returns the current OutlinerParaObject and removes it from this instance */
OutlinerParaObject* SdrText::RemoveOutlinerParaObject()
{
    // Update HitTestOutliner
    const SdrTextObj* pTestObj(mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().GetTextObj());

    if(pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get())
    if( mpModel )
    {
        mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().SetTextObj(nullptr);
        // Update HitTestOutliner
        const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj();
        if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get() )
            mpModel->GetHitTestOutliner().SetTextObj( nullptr );
    }

    OutlinerParaObject* pOPO = mpOutlinerParaObject.release();

    mbPortionInfoChecked = false;

    return pOPO;
}

void SdrText::SetModel( SdrModel* pNewModel )
{
    if( pNewModel == mpModel )
        return;

    SdrModel* pOldModel = mpModel;
    mpModel = pNewModel;

    if( !mpOutlinerParaObject || pOldModel==nullptr || pNewModel==nullptr)
        return;

    bool bHgtSet = GetObjectItemSet().GetItemState(EE_CHAR_FONTHEIGHT) == SfxItemState::SET;

    MapUnit aOldUnit(pOldModel->GetScaleUnit());
    MapUnit aNewUnit(pNewModel->GetScaleUnit());
    bool bScaleUnitChanged=aNewUnit!=aOldUnit;
    // Now move the OutlinerParaObject into a new Pool.
    // TODO: We should compare the DefTab and RefDevice of both Models to
    // see whether we need to use AutoGrow!
    sal_Int32 nOldFontHgt=pOldModel->GetDefaultFontHeight();
    sal_Int32 nNewFontHgt=pNewModel->GetDefaultFontHeight();
    bool bDefHgtChanged=nNewFontHgt!=nOldFontHgt;
    bool bSetHgtItem=bDefHgtChanged && !bHgtSet;
    if (bSetHgtItem)
    {
        // fix the value of HeightItem, so
        // 1. it remains and
        // 2. DoStretchChars gets the right value
        SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
    }
    // now use the Outliner, etc. so the above SetAttr can work at all
    SdrOutliner& rOutliner = mrObject.ImpGetDrawOutliner();
    rOutliner.SetText(*mpOutlinerParaObject);
    mpOutlinerParaObject.reset();
    if (bScaleUnitChanged)
    {
        Fraction aMetricFactor=GetMapFactor(aOldUnit,aNewUnit).X();

        if (bSetHgtItem)
        {
            // Now correct the frame attribute
            nOldFontHgt=BigMulDiv(nOldFontHgt,aMetricFactor.GetNumerator(),aMetricFactor.GetDenominator());
            SetObjectItem(SvxFontHeightItem(nOldFontHgt, 100, EE_CHAR_FONTHEIGHT));
        }
    }
    SetOutlinerParaObject(rOutliner.CreateParaObject());
    mpOutlinerParaObject->ClearPortionInfo();
    mbPortionInfoChecked=false;
    rOutliner.Clear();
}

void SdrText::ForceOutlinerParaObject( OutlinerMode nOutlMode )
{
    if(!mpOutlinerParaObject)
    if( mpModel && !mpOutlinerParaObject )
    {
        std::unique_ptr<Outliner> pOutliner(
            SdrMakeOutliner(
                nOutlMode,
                mrObject.getSdrModelFromSdrObject()));

        if(pOutliner)
        std::unique_ptr<Outliner> pOutliner(SdrMakeOutliner(nOutlMode, *mpModel));
        if( pOutliner )
        {
            Outliner& aDrawOutliner(mrObject.getSdrModelFromSdrObject().GetDrawOutliner());
            Outliner& aDrawOutliner = mpModel->GetDrawOutliner();
            pOutliner->SetCalcFieldValueHdl( aDrawOutliner.GetCalcFieldValueHdl() );

            pOutliner->SetStyleSheet( 0, GetStyleSheet());
            OutlinerParaObject* pOutlinerParaObject = pOutliner->CreateParaObject();
            SetOutlinerParaObject( pOutlinerParaObject );
diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx
index 22720cf..1c6ec23 100644
--- a/svx/source/svdraw/svdundo.cxx
+++ b/svx/source/svdraw/svdundo.cxx
@@ -209,8 +209,8 @@ OUString SdrUndoGroup::GetSdrRepeatComment(SdrView& /*rView*/) const
}

SdrUndoObj::SdrUndoObj(SdrObject& rNewObj)
:   SdrUndoAction(rNewObj.getSdrModelFromSdrObject())
    ,pObj(&rNewObj)
    : SdrUndoAction(*rNewObj.GetModel())
    , pObj(&rNewObj)
{
}

@@ -237,10 +237,10 @@ void SdrUndoObj::ImpTakeDescriptionStr(const char* pStrCacheID, OUString& rStr, 
// common call method for possible change of the page when UNDO/REDO is triggered
void SdrUndoObj::ImpShowPageOfThisObject()
{
    if(pObj && pObj->IsInserted() && pObj->GetPage())
    if(pObj && pObj->IsInserted() && pObj->GetPage() && pObj->GetModel())
    {
        SdrHint aHint(SdrHintKind::SwitchToPage, *pObj, pObj->GetPage());
        pObj->getSdrModelFromSdrObject().Broadcast(aHint);
        pObj->GetModel()->Broadcast(aHint);
    }
}

@@ -275,7 +275,7 @@ SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSave
    if(bIsGroup)
    {
        // it's a group object!
        pUndoGroup.reset(new SdrUndoGroup(pObj->getSdrModelFromSdrObject()));
        pUndoGroup.reset( new SdrUndoGroup(*pObj->GetModel()) );
        const size_t nObjCount(pOL->GetObjCount());

        for(size_t nObjNum = 0; nObjNum < nObjCount; ++nObjNum)
@@ -343,9 +343,9 @@ void SdrUndoAttrObj::Undo()
            mxRedoStyleSheet = pObj->GetStyleSheet();
            SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxUndoStyleSheet.get());

            if(pSheet && pObj->getSdrModelFromSdrObject().GetStyleSheetPool())
            if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
            {
                ensureStyleSheetInStyleSheetPool(*pObj->getSdrModelFromSdrObject().GetStyleSheetPool(), *pSheet);
                ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
                pObj->SetStyleSheet(pSheet, true);
            }
            else
@@ -426,9 +426,9 @@ void SdrUndoAttrObj::Redo()
            mxUndoStyleSheet = pObj->GetStyleSheet();
            SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxRedoStyleSheet.get());

            if(pSheet && pObj->getSdrModelFromSdrObject().GetStyleSheetPool())
            if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
            {
                ensureStyleSheetInStyleSheetPool(*pObj->getSdrModelFromSdrObject().GetStyleSheetPool(), *pSheet);
                ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
                pObj->SetStyleSheet(pSheet, true);
            }
            else
@@ -581,7 +581,7 @@ SdrUndoGeoObj::SdrUndoGeoObj(SdrObject& rNewObj)
        // this is a group object!
        // If this were 3D scene, we'd only add an Undo for the scene itself
        // (which we do elsewhere).
        pUndoGroup.reset(new SdrUndoGroup(pObj->getSdrModelFromSdrObject()));
        pUndoGroup.reset(new SdrUndoGroup(*pObj->GetModel()));
        const size_t nObjCount = pOL->GetObjCount();
        for (size_t nObjNum = 0; nObjNum<nObjCount; ++nObjNum) {
            pUndoGroup->AddAction(new SdrUndoGeoObj(*pOL->GetObj(nObjNum)));
@@ -1335,8 +1335,8 @@ OUString SdrUndoMoveLayer::GetComment() const


SdrUndoPage::SdrUndoPage(SdrPage& rNewPg)
:   SdrUndoAction(rNewPg.getSdrModelFromSdrPage())
    ,mrPage(rNewPg)
    : SdrUndoAction(*rNewPg.GetModel())
    , mrPage(rNewPg)
{
}

@@ -1657,7 +1657,7 @@ void SdrUndoPageRemoveMasterPage::Undo()
{
    if(mbOldHadMasterPage)
    {
        mrPage.TRG_SetMasterPage(*mrPage.getSdrModelFromSdrPage().GetMasterPage(maOldMasterPageNumber));
        mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
        mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
    }
}
@@ -1695,7 +1695,7 @@ void SdrUndoPageChangeMasterPage::Undo()
    if(mbOldHadMasterPage)
    {
        mrPage.TRG_ClearMasterPage();
        mrPage.TRG_SetMasterPage(*mrPage.getSdrModelFromSdrPage().GetMasterPage(maOldMasterPageNumber));
        mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
        mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
    }
}
@@ -1706,7 +1706,7 @@ void SdrUndoPageChangeMasterPage::Redo()
    if(mbNewHadMasterPage)
    {
        mrPage.TRG_ClearMasterPage();
        mrPage.TRG_SetMasterPage(*mrPage.getSdrModelFromSdrPage().GetMasterPage(maNewMasterPageNumber));
        mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maNewMasterPageNumber));
        mrPage.TRG_SetMasterPageVisibleLayers(maNewSet);
    }
}
diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx
index d9eb524..db460ea 100644
--- a/svx/source/svdraw/svdview.cxx
+++ b/svx/source/svdraw/svdview.cxx
@@ -146,15 +146,15 @@ SdrDropMarkerOverlay::~SdrDropMarkerOverlay()
    // OverlayManager and deletes them.
}

SdrView::SdrView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrCreateView(rSdrModel, pOut),

SdrView::SdrView(SdrModel* pModel1, OutputDevice* pOut)
:   SdrCreateView(pModel1,pOut),
    bNoExtendedMouseDispatcher(false),
    bNoExtendedKeyDispatcher(false),
    mbMasterPagePaintCaching(false)
{
    maAccessibilityOptions.AddListener(this);

    onAccessibilityOptionsChanged();
}

diff --git a/svx/source/svdraw/svdviter.cxx b/svx/source/svdraw/svdviter.cxx
index 044526e..2dbd8b5 100644
--- a/svx/source/svdraw/svdviter.cxx
+++ b/svx/source/svdraw/svdviter.cxx
@@ -38,7 +38,7 @@ void SdrViewIter::ImpInitVars()
SdrViewIter::SdrViewIter(const SdrPage* pPage)
{
    mpPage = pPage;
    mpModel = pPage ? &pPage->getSdrModelFromSdrPage() : nullptr;
    mpModel = pPage ? pPage->GetModel() : nullptr;
    mpObject = nullptr;
    mbNoMasterPage = false;
    ImpInitVars();
@@ -48,7 +48,7 @@ SdrViewIter::SdrViewIter(const SdrPage* pPage)
SdrViewIter::SdrViewIter(const SdrObject* pObject)
{
    mpObject = pObject;
    mpModel = pObject ? &pObject->getSdrModelFromSdrObject() : nullptr;
    mpModel = pObject ? pObject->GetModel() : nullptr;
    mpPage = pObject ? pObject->GetPage() : nullptr;
    mbNoMasterPage = false;

diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx
index 58fc733..1011c8a 100644
--- a/svx/source/svdraw/svdxcgv.cxx
+++ b/svx/source/svdraw/svdxcgv.cxx
@@ -57,10 +57,8 @@

using namespace com::sun::star;

SdrExchangeView::SdrExchangeView(
    SdrModel& rSdrModel,
    OutputDevice* pOut)
:   SdrObjEditView(rSdrModel, pOut)
SdrExchangeView::SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut):
    SdrObjEditView(pModel1,pOut)
{
}

@@ -145,11 +143,8 @@ bool SdrExchangeView::Paste(const OUString& rStr, const Point& rPos, SdrObjList*
    if (pPage!=nullptr) {
        aTextRect.SetSize(pPage->GetSize());
    }
    SdrRectObj* pObj = new SdrRectObj(
        getSdrModelFromSdrView(),
        OBJ_TEXT,
        aTextRect);

    SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
    pObj->SetModel(mpModel);
    pObj->SetLayer(nLayer);
    pObj->NbcSetText(rStr); // SetText before SetAttr, else SetAttr doesn't work!
    if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);
@@ -185,11 +180,8 @@ bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat eFormat, const Point&
    if (pPage!=nullptr) {
        aTextRect.SetSize(pPage->GetSize());
    }
    SdrRectObj* pObj = new SdrRectObj(
        getSdrModelFromSdrView(),
        OBJ_TEXT,
        aTextRect);

    SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect);
    pObj->SetModel(mpModel);
    pObj->SetLayer(nLayer);
    if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false);

@@ -209,9 +201,9 @@ bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat eFormat, const Point&
    ImpPasteObject(pObj,*pLst,aPos,aSiz,MapMode(eMap,Point(0,0),aMap,aMap),nOptions);

    // b4967543
    if(pObj->GetOutlinerParaObject())
    if(pObj->GetModel() && pObj->GetOutlinerParaObject())
    {
        SdrOutliner& rOutliner = pObj->getSdrModelFromSdrObject().GetHitTestOutliner();
        SdrOutliner& rOutliner = pObj->GetModel()->GetHitTestOutliner();
        rOutliner.SetText(*pObj->GetOutlinerParaObject());

        if(1 == rOutliner.GetParagraphCount())
@@ -220,7 +212,7 @@ bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat eFormat, const Point&

            if(pCandidate)
            {
                if(pObj->getSdrModelFromSdrObject().GetStyleSheetPool() == &pCandidate->GetPool())
                if(pObj->GetModel()->GetStyleSheetPool() == &pCandidate->GetPool())
                {
                    pObj->NbcSetStyleSheet(pCandidate, true);
                }
@@ -313,13 +305,15 @@ bool SdrExchangeView::Paste(
            {
                if(bResize)
                {
                    pNewObj->getSdrModelFromSdrObject().SetPasteResize(true);
                    pNewObj->GetModel()->SetPasteResize(true);
                    pNewObj->NbcResize(aPt0,aXResize,aYResize);
                    pNewObj->getSdrModelFromSdrObject().SetPasteResize(false);
                    pNewObj->GetModel()->SetPasteResize(false);
                }

                // #i39861#
                pNewObj->SetModel(pDstLst->GetModel());
                pNewObj->SetPage(pDstLst->GetPage());

                pNewObj->NbcMove(aSiz);

                const SdrPage* pPg = pDstLst->GetPage();
@@ -351,7 +345,7 @@ bool SdrExchangeView::Paste(
                pDstLst->InsertObject(pNewObj, SAL_MAX_SIZE);

                if( bUndo )
                    AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));
                    AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));

                if (bMark) {
                    // Don't already set Markhandles!
@@ -420,7 +414,7 @@ void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Po
    rLst.InsertObject(pObj, SAL_MAX_SIZE);

    if( IsUndoEnabled() )
        AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pObj));
        AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj));

    SdrPageView* pMarkPV=nullptr;
    SdrPageView* pPV = GetSdrPageView();
@@ -585,7 +579,7 @@ Graphic SdrExchangeView::GetAllMarkedGraphic() const
    if( AreObjectsMarked() )
    {
        if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) )
            aRet = SdrExchangeView::GetObjGraphic(*GetMarkedObjectByIndex(0));
            aRet = SdrExchangeView::GetObjGraphic( mpModel, GetMarkedObjectByIndex( 0 ) );
        else
            aRet = GetMarkedObjMetaFile();
    }
@@ -594,68 +588,68 @@ Graphic SdrExchangeView::GetAllMarkedGraphic() const
}


Graphic SdrExchangeView::GetObjGraphic(const SdrObject& rSdrObject)
Graphic SdrExchangeView::GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj )
{
    Graphic aRet;

    // try to get a graphic from the object first
    const SdrGrafObj* pSdrGrafObj(dynamic_cast< const SdrGrafObj* >(&rSdrObject));
    const SdrOle2Obj* pSdrOle2Obj(dynamic_cast< const SdrOle2Obj* >(&rSdrObject));

    if(pSdrGrafObj)
    if( pModel && pObj )
    {
        if(pSdrGrafObj->isEmbeddedVectorGraphicData())
        {
            // get Metafile for Svg content
            aRet = pSdrGrafObj->getMetafileFromEmbeddedVectorGraphicData();
        }
        else
        {
            // Make behaviour coherent with metafile
            // recording below (which of course also takes
            // view-transformed objects)
            aRet = pSdrGrafObj->GetTransformedGraphic();
        }
    }
    else if(pSdrOle2Obj)
    {
        if(pSdrOle2Obj->GetGraphic())
        {
            aRet = *pSdrOle2Obj->GetGraphic();
        }
    }
        // try to get a graphic from the object first
        const SdrGrafObj* pSdrGrafObj = dynamic_cast< const SdrGrafObj* >(pObj);
        const SdrOle2Obj* pSdrOle2Obj = dynamic_cast< const SdrOle2Obj* >(pObj);

    // if graphic could not be retrieved => go the hard way and create a MetaFile
    if((GraphicType::NONE == aRet.GetType()) || (GraphicType::Default == aRet.GetType()))
    {
        ScopedVclPtrInstance< VirtualDevice > pOut;
        GDIMetaFile aMtf;
        const tools::Rectangle aBoundRect(rSdrObject.GetCurrentBoundRect());
        const MapMode aMap(rSdrObject.getSdrModelFromSdrObject().GetScaleUnit(),
            Point(),
            rSdrObject.getSdrModelFromSdrObject().GetScaleFraction(),
            rSdrObject.getSdrModelFromSdrObject().GetScaleFraction());

        pOut->EnableOutput(false);
        pOut->SetMapMode(aMap);
        aMtf.Record(pOut);
        rSdrObject.SingleObjectPainter(*pOut.get());
        aMtf.Stop();
        aMtf.WindStart();

        // #i99268# replace the original offset from using XOutDev's SetOffset
        // NOT (as tried with #i92760#) with another MapMode which gets recorded
        // by the Metafile itself (what always leads to problems), but by
        // moving the result directly
        aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());
        aMtf.SetPrefMapMode(aMap);
        aMtf.SetPrefSize(aBoundRect.GetSize());

        if(aMtf.GetActionSize())
        if(pSdrGrafObj)
        {
            aRet = aMtf;
            if(pSdrGrafObj->isEmbeddedVectorGraphicData())
            {
                // get Metafile for Svg content
                aRet = pSdrGrafObj->getMetafileFromEmbeddedVectorGraphicData();
            }
            else
            {
                // Make behaviour coherent with metafile
                // recording below (which of course also takes
                // view-transformed objects)
                aRet = pSdrGrafObj->GetTransformedGraphic();
            }
        }
    }
        else if(pSdrOle2Obj)
        {
            if ( pSdrOle2Obj->GetGraphic() )
                aRet = *pSdrOle2Obj->GetGraphic();
        }

        // if graphic could not be retrieved => go the hard way and create a MetaFile
        if( ( GraphicType::NONE == aRet.GetType() ) || ( GraphicType::Default == aRet.GetType() ) )
        {
            ScopedVclPtrInstance< VirtualDevice > pOut;
            GDIMetaFile     aMtf;
            const tools::Rectangle aBoundRect( pObj->GetCurrentBoundRect() );
            const MapMode   aMap( pModel->GetScaleUnit(),
                                  Point(),
                                  pModel->GetScaleFraction(),
                                  pModel->GetScaleFraction() );

            pOut->EnableOutput( false );
            pOut->SetMapMode( aMap );
            aMtf.Record( pOut );
            pObj->SingleObjectPainter( *pOut.get() );
            aMtf.Stop();
            aMtf.WindStart();

            // #i99268# replace the original offset from using XOutDev's SetOffset
            // NOT (as tried with #i92760#) with another MapMode which gets recorded
            // by the Metafile itself (what always leads to problems), but by
            // moving the result directly
            aMtf.Move(-aBoundRect.Left(), -aBoundRect.Top());

            aMtf.SetPrefMapMode( aMap );
            aMtf.SetPrefSize( aBoundRect.GetSize() );

            if( aMtf.GetActionSize() )
                aRet = aMtf;
        }
     }

     return aRet;
}
@@ -709,6 +703,7 @@ void SdrExchangeView::DrawMarkedObj(OutputDevice& rOut) const
    }
}


SdrModel* SdrExchangeView::GetMarkedObjModel() const
{
    // Sorting the MarkList here might be problematic in the future, so
@@ -734,16 +729,15 @@ SdrModel* SdrExchangeView::GetMarkedObjModel() const
            {
                // convert SdrPageObj's to a graphic representation, because
                // virtual connection to referenced page gets lost in new model
                pNewObj = new SdrGrafObj(
                    *pNeuMod,
                    GetObjGraphic(*pObj),
                    pObj->GetLogicRect());
                pNewObj = new SdrGrafObj( GetObjGraphic( mpModel, pObj ), pObj->GetLogicRect() );
                pNewObj->SetPage( pNeuPag );
                pNewObj->SetModel( pNeuMod );
            }
            else
            {
                pNewObj = pObj->Clone();
                pNewObj->SetPage( pNeuPag );
                pNewObj->SetModel( pNeuMod );
            }

            pNeuPag->InsertObject(pNewObj, SAL_MAX_SIZE);
@@ -756,8 +750,8 @@ SdrModel* SdrExchangeView::GetMarkedObjModel() const
        // New mechanism to re-create the connections of cloned connectors
        aCloneList.CopyConnections();
    }

    return pNeuMod;
}


/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx
index 0f733d0..cd19738 100644
--- a/svx/source/table/cell.cxx
+++ b/svx/source/table/cell.cxx
@@ -392,31 +392,21 @@ rtl::Reference< Cell > Cell::create( SdrTableObj& rTableObj )
}


Cell::Cell(
    SdrTableObj& rTableObj)
:   SdrText(rTableObj)
    ,SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
    ,mpPropSet( ImplGetSvxCellPropertySet() )
    ,mpProperties( new sdr::properties::CellProperties( rTableObj, this ) )
    ,mnCellContentType( CellContentType_EMPTY )
    ,mfValue( 0.0 )
    ,mnError( 0 )
    ,mbMerged( false )
    ,mnRowSpan( 1 )
    ,mnColSpan( 1 )
    ,mxTable( rTableObj.getTable() )
Cell::Cell( SdrTableObj& rTableObj )
: SdrText( rTableObj )
, SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
, mpPropSet( ImplGetSvxCellPropertySet() )
, mpProperties( new sdr::properties::CellProperties( rTableObj, this ) )
, mnCellContentType( CellContentType_EMPTY )
, mfValue( 0.0 )
, mnError( 0 )
, mbMerged( false )
, mnRowSpan( 1 )
, mnColSpan( 1 )
, mxTable( rTableObj.getTable() )
{
    // Caution: Old SetModel() indirectly did a very necessary thing here,
    // it created a valid SvxTextEditSource which is needed to bind contained
    // Text to the UNO API and thus to save/load and more. Added version without
    // model change.
    // Also done was (not needed, for reference):
    //         SetStyleSheet( nullptr, true );
    //         ForceOutlinerParaObject( OutlinerMode::TextObject );
    if(nullptr == GetEditSource())
    {
        SetEditSource(new SvxTextEditSource(&GetObject(), this));
    }
    if( rTableObj.GetModel() )
        SetModel( rTableObj.GetModel() );
}


@@ -450,6 +440,37 @@ void Cell::dispose()
    SetOutlinerParaObject( nullptr );
}


void Cell::SetModel(SdrModel* pNewModel)
{
    SvxTextEditSource* pTextEditSource = dynamic_cast< SvxTextEditSource* >( GetEditSource() );
    if( (GetModel() != pNewModel) || ( pNewModel && !pTextEditSource) )
    {
        if( mpProperties )
        {
            SfxItemPool* pItemPool = mpProperties->GetObjectItemSet().GetPool();

            // test for correct pool in ItemSet; move to new pool if necessary
            if( pNewModel && pItemPool && pItemPool != &pNewModel->GetItemPool())
                mpProperties->MoveToItemPool(pItemPool, &pNewModel->GetItemPool(), pNewModel);
        }

        if( pTextEditSource )
        {
            pTextEditSource->ChangeModel( pNewModel );
        }
        else
        {
            SetEditSource( new SvxTextEditSource( &GetObject(), this ) );
        }

        SetStyleSheet( nullptr, true );
        SdrText::SetModel( pNewModel );
        ForceOutlinerParaObject( OutlinerMode::TextObject );
    }
}


void Cell::merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan )
{
    if ((mnColSpan != nColumnSpan) || (mnRowSpan != nRowSpan) || mbMerged)
@@ -516,13 +537,12 @@ void Cell::replaceContentAndFormating( const CellRef& xSourceCell )
    {
        mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() );
        SetOutlinerParaObject( new OutlinerParaObject(*xSourceCell->GetOutlinerParaObject()) );

        SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
        SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() );

        if(&rSourceTableObj.getSdrModelFromSdrObject() != &rTableObj.getSdrModelFromSdrObject())
        if(rSourceTableObj.GetModel() != rTableObj.GetModel())
        {
            // TTTT should not happen - if, then a clone may be needed
            // Maybe add a assertion here later
            SetStyleSheet( nullptr, true );
        }
    }
@@ -544,13 +564,12 @@ void Cell::copyFormatFrom( const CellRef& xSourceCell )
    if( xSourceCell.is() && mpProperties )
    {
        mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() );

        SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() );
        SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() );

        if(&rSourceTableObj.getSdrModelFromSdrObject() != &rTableObj.getSdrModelFromSdrObject())
        if(rSourceTableObj.GetModel() != rTableObj.GetModel())
        {
            // TTTT should not happen - if, then a clone may be needed
            // Maybe add a assertion here later
            SetStyleSheet( nullptr, true );
        }

@@ -793,11 +812,10 @@ void Cell::SetOutlinerParaObject( OutlinerParaObject* pTextObject )
void Cell::AddUndo()
{
    SdrObject& rObj = GetObject();

    if( rObj.IsInserted() && rObj.getSdrModelFromSdrObject().IsUndoEnabled() )
    if( rObj.IsInserted() && GetModel() && GetModel()->IsUndoEnabled() )
    {
        CellRef xCell( this );
        rObj.getSdrModelFromSdrObject().AddUndo( new CellUndo( &rObj, xCell ) );
        GetModel()->AddUndo( new CellUndo( &rObj, xCell ) );

        // Undo action for the after-text-edit-ended stack.
        SdrTableObj* pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(&rObj);
@@ -1001,7 +1019,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& 
{
    ::SolarMutexGuard aGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName);
@@ -1093,7 +1111,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& 
        }
        default:
        {
            SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}});
            SfxItemSet aSet( GetModel()->GetItemPool(), {{pMap->nWID, pMap->nWID}});
            aSet.Put(mpProperties->GetItem(pMap->nWID));

            bool bSpecial = false;
@@ -1113,7 +1131,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& 
                        OUString aApiName;
                        if( rValue >>= aApiName )
                        {
                            if(SvxShape::SetFillAttribute(pMap->nWID, aApiName, aSet, &GetObject().getSdrModelFromSdrObject()))
                            if( SvxShape::SetFillAttribute( pMap->nWID, aApiName, aSet, GetModel() ) )
                                bSpecial = true;
                        }
                    }
@@ -1130,7 +1148,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& 
                    {
                        // fetch the default from ItemPool
                        if(SfxItemPool::IsWhich(pMap->nWID))
                            aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID));
                            aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
                    }

                    if( aSet.GetItemState( pMap->nWID ) == SfxItemState::SET )
@@ -1140,7 +1158,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& 
                }
            }

            GetObject().getSdrModelFromSdrObject().SetChanged();
            GetModel()->SetChanged();
            mpProperties->SetMergedItemSetAndBroadcast( aSet );
            return;
        }
@@ -1154,7 +1172,7 @@ Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName )
{
    ::SolarMutexGuard aGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
@@ -1213,7 +1231,7 @@ Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName )
        }
        default:
        {
            SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}});
            SfxItemSet aSet( GetModel()->GetItemPool(), {{pMap->nWID, pMap->nWID}});
            aSet.Put(mpProperties->GetItem(pMap->nWID));

            Any aAny;
@@ -1223,7 +1241,7 @@ Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName )
                {
                    // fetch the default from ItemPool
                    if(SfxItemPool::IsWhich(pMap->nWID))
                        aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID));
                        aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
                }

                if( aSet.Count() )
@@ -1265,7 +1283,7 @@ void SAL_CALL Cell::setPropertyValues( const Sequence< OUString >& aPropertyName
{
    ::SolarMutexGuard aSolarGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const sal_Int32 nCount = aPropertyNames.getLength();
@@ -1295,7 +1313,7 @@ Sequence< Any > SAL_CALL Cell::getPropertyValues( const Sequence< OUString >& aP
{
    ::SolarMutexGuard aSolarGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const sal_Int32 nCount = aPropertyNames.getLength();
@@ -1346,7 +1364,7 @@ PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName )
{
    ::SolarMutexGuard aGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
@@ -1449,7 +1467,7 @@ Sequence< PropertyState > SAL_CALL Cell::getPropertyStates( const Sequence< OUSt
{
    ::SolarMutexGuard aGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const sal_Int32 nCount = aPropertyName.getLength();
@@ -1479,7 +1497,7 @@ void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName )
{
    ::SolarMutexGuard aGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);
@@ -1509,7 +1527,7 @@ void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName )
        }
        }

        GetObject().getSdrModelFromSdrObject().SetChanged();
        GetModel()->SetChanged();
        return;
    }
    throw UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
@@ -1520,7 +1538,7 @@ Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName )
{
    ::SolarMutexGuard aGuard;

    if(mpProperties == nullptr)
    if( (mpProperties == nullptr) || (GetModel() == nullptr) )
        throw DisposedException();

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName);
@@ -1547,8 +1565,8 @@ Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName )
        {
            if( SfxItemPool::IsWhich(pMap->nWID) )
            {
                SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}});
                aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID));
                SfxItemSet aSet( GetModel()->GetItemPool(), {{pMap->nWID, pMap->nWID}});
                aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID));
                return GetAnyForItem( aSet, pMap );
            }
        }
diff --git a/svx/source/table/cellcursor.cxx b/svx/source/table/cellcursor.cxx
index b636883..db68fdb 100644
--- a/svx/source/table/cellcursor.cxx
+++ b/svx/source/table/cellcursor.cxx
@@ -242,11 +242,11 @@ void SAL_CALL CellCursor::merge(  )
    if( !mxTable.is() || (mxTable->getSdrTableObj() == nullptr) )
        throw DisposedException();

    SdrModel& rModel(mxTable->getSdrTableObj()->getSdrModelFromSdrObject());
    const bool bUndo(mxTable->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled());
    SdrModel* pModel = mxTable->getSdrTableObj()->GetModel();
    const bool bUndo = pModel && mxTable->getSdrTableObj()->IsInserted() && pModel->IsUndoEnabled();

    if( bUndo )
        rModel.BegUndo( ImpGetResStr(STR_TABLE_MERGE) );
        pModel->BegUndo( ImpGetResStr(STR_TABLE_MERGE) );

    try
    {
@@ -260,9 +260,10 @@ void SAL_CALL CellCursor::merge(  )
    }

    if( bUndo )
        rModel.EndUndo();
        pModel->EndUndo();

    rModel.SetChanged();
    if( pModel )
        pModel->SetChanged();
}


@@ -502,11 +503,10 @@ void SAL_CALL CellCursor::split( sal_Int32 nColumns, sal_Int32 nRows )
    if( !mxTable.is() || (mxTable->getSdrTableObj() == nullptr) )
        throw DisposedException();

    SdrModel& rModel(mxTable->getSdrTableObj()->getSdrModelFromSdrObject());
    const bool bUndo(mxTable->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled());

    SdrModel* pModel = mxTable->getSdrTableObj()->GetModel();
    const bool bUndo = pModel && mxTable->getSdrTableObj()->IsInserted() && pModel->IsUndoEnabled();
    if( bUndo )
        rModel.BegUndo( ImpGetResStr(STR_TABLE_SPLIT) );
        pModel->BegUndo( ImpGetResStr(STR_TABLE_SPLIT) );

    try
    {
@@ -526,9 +526,10 @@ void SAL_CALL CellCursor::split( sal_Int32 nColumns, sal_Int32 nRows )
    }

    if( bUndo )
        rModel.EndUndo();
        pModel->EndUndo();

    rModel.SetChanged();
    if( pModel )
        pModel->SetChanged();
}


diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx
index f8b2362..dab61a9 100644
--- a/svx/source/table/svdotable.cxx
+++ b/svx/source/table/svdotable.cxx
@@ -684,7 +684,7 @@ sal_Int32 SdrTableObjImpl::getRowCount() const

void SdrTableObjImpl::LayoutTable( tools::Rectangle& rArea, bool bFitWidth, bool bFitHeight )
{
    if(mpLayouter)
    if( mpLayouter && mpTableObj->GetModel() )
    {
        // Optimization: SdrTableObj::SetChanged() can call this very often, repeatedly
        // with the same settings, noticeably increasing load time. Skip if already done.
@@ -749,20 +749,20 @@ sdr::contact::ViewContact* SdrTableObj::CreateObjectSpecificViewContact()
    return new sdr::contact::ViewContactOfTableObj(*this);
}

SdrTableObj::SdrTableObj(SdrModel& rSdrModel)
:   SdrTextObj(rSdrModel)

SdrTableObj::SdrTableObj(SdrModel* _pModel)
{
    pModel = _pModel;
    init( 1, 1 );
}

SdrTableObj::SdrTableObj(
    SdrModel& rSdrModel,
    const ::tools::Rectangle& rNewRect,
    sal_Int32 nColumns,
    sal_Int32 nRows)
:   SdrTextObj(rSdrModel, rNewRect)
    ,maLogicRect(rNewRect)

SdrTableObj::SdrTableObj(SdrModel* _pModel, const ::tools::Rectangle& rNewRect, sal_Int32 nColumns, sal_Int32 nRows)
: SdrTextObj( rNewRect )
, maLogicRect( rNewRect )
{
    pModel = _pModel;

    if( nColumns <= 0 )
        nColumns = 1;

@@ -779,16 +779,6 @@ void SdrTableObj::init( sal_Int32 nColumns, sal_Int32 nRows )

    mpImpl = new SdrTableObjImpl;
    mpImpl->init( this, nColumns, nRows );

    // Stuff done from old SetModel:
    if( !maLogicRect.IsEmpty() )
    {
        maRect = maLogicRect;
        mpImpl->LayoutTable( maRect, false, false );
    }

    // Also init from old SetModel:
    mpImpl->SetModel(&getSdrModelFromSdrObject());
}


@@ -1359,6 +1349,28 @@ sal_uInt16 SdrTableObj::GetObjIdentifier() const
    return static_cast<sal_uInt16>(OBJ_TABLE);
}


void SdrTableObj::SetModel(SdrModel* pNewModel)
{
    SdrModel* pOldModel = GetModel();
    if( pNewModel != pOldModel )
    {
        SdrTextObj::SetModel(pNewModel);

        if( mpImpl.is() )
        {
            mpImpl->SetModel( pNewModel );

            if( !maLogicRect.IsEmpty() )
            {
                maRect = maLogicRect;
                mpImpl->LayoutTable( maRect, false, false );
            }
        }
    }
}


void SdrTableObj::TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRect, bool bNoEditText, tools::Rectangle* pAnchorRect, bool /*bLineWidth*/ ) const
{
    if( mpImpl.is() )
@@ -1406,9 +1418,9 @@ void SdrTableObj::TakeTextRect( const CellPos& rPos, SdrOutliner& rOutliner, too

    if (pPara)
    {
        const bool bHitTest(&getSdrModelFromSdrObject().GetHitTestOutliner() == &rOutliner);
        const SdrTextObj* pTestObj(rOutliner.GetTextObj());
        const bool bHitTest = pModel && (&pModel->GetHitTestOutliner() == &rOutliner);

        const SdrTextObj* pTestObj = rOutliner.GetTextObj();
        if( !pTestObj || !bHitTest || (pTestObj != this) || (pTestObj->GetOutlinerParaObject() != xCell->GetOutlinerParaObject()) )
        {
            if( bHitTest ) // #i33696# take back fix #i27510#
@@ -1553,9 +1565,12 @@ void SdrTableObj::TakeTextEditArea( const CellPos& rPos, Size* pPaperMin, Size* 
    aAnkSiz.AdjustWidth( -1 ); aAnkSiz.AdjustHeight( -1 ); // because GetSize() increments by one

    Size aMaxSiz(aAnkSiz.Width(),1000000);
    Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize());
    if (aTmpSiz.Height()!=0)
        aMaxSiz.setHeight(aTmpSiz.Height() );
    if (pModel!=nullptr)
    {
        Size aTmpSiz(pModel->GetMaxObjSize());
        if (aTmpSiz.Height()!=0)
            aMaxSiz.setHeight(aTmpSiz.Height() );
    }

    CellRef xCell( mpImpl->getCell( rPos ) );
    SdrTextVertAdjust eVAdj = xCell.is() ? xCell->GetTextVerticalAdjust() : SDRTEXTVERTADJUST_TOP;
@@ -1646,9 +1661,9 @@ OUString SdrTableObj::TakeObjNamePlural() const
}


SdrTableObj* SdrTableObj::Clone(SdrModel* pTargetModel) const
SdrTableObj* SdrTableObj::Clone() const
{
    return CloneHelper< SdrTableObj >(pTargetModel);
    return CloneHelper< SdrTableObj >();
}

SdrTableObj& SdrTableObj::operator=(const SdrTableObj& rObj)
@@ -1709,20 +1724,20 @@ bool SdrTableObj::BegTextEdit(SdrOutliner& rOutl)
    mbInEditMode = true;

    rOutl.Init( OutlinerMode::TextObject );
    rOutl.SetRefDevice(getSdrModelFromSdrObject().GetRefDevice());
    rOutl.SetRefDevice( pModel->GetRefDevice() );

    bool bUpdMerk=rOutl.GetUpdateMode();
    if (bUpdMerk) rOutl.SetUpdateMode(false);
    Size aPaperMin;
    Size aPaperMax;
    tools::Rectangle aEditArea;
    TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,nullptr);
        bool bUpdMerk=rOutl.GetUpdateMode();
        if (bUpdMerk) rOutl.SetUpdateMode(false);
        Size aPaperMin;
        Size aPaperMax;
        tools::Rectangle aEditArea;
        TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,nullptr);

    rOutl.SetMinAutoPaperSize(aPaperMin);
    rOutl.SetMaxAutoPaperSize(aPaperMax);
    rOutl.SetPaperSize(aPaperMax);
        rOutl.SetMinAutoPaperSize(aPaperMin);
        rOutl.SetMaxAutoPaperSize(aPaperMax);
        rOutl.SetPaperSize(aPaperMax);

    if (bUpdMerk) rOutl.SetUpdateMode(true);
        if (bUpdMerk) rOutl.SetUpdateMode(true);

    EEControlBits nStat=rOutl.GetControlWord();
    nStat   |= EEControlBits::AUTOPAGESIZE;
@@ -1743,14 +1758,14 @@ bool SdrTableObj::BegTextEdit(SdrOutliner& rOutl)
void SdrTableObj::EndTextEdit(SdrOutliner& rOutl)
{

    if (getSdrModelFromSdrObject().IsUndoEnabled() && !mpImpl->maUndos.empty())
    if (GetModel() && GetModel()->IsUndoEnabled() && !mpImpl->maUndos.empty())
    {
        // These actions should be on the undo stack after text edit.
        for (std::unique_ptr<SdrUndoAction>& pAction : mpImpl->maUndos)
            getSdrModelFromSdrObject().AddUndo(pAction.release());
            GetModel()->AddUndo(pAction.release());
        mpImpl->maUndos.clear();

        getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoGeoObject(*this));
        GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*this));
    }

    if(rOutl.IsModified())
@@ -1795,15 +1810,16 @@ void SdrTableObj::NbcSetOutlinerParaObject( OutlinerParaObject* pTextObject)
    CellRef xCell( getActiveCell() );
    if( xCell.is() )
    {
        // Update HitTestOutliner
        const SdrTextObj* pTestObj(getSdrModelFromSdrObject().GetHitTestOutliner().GetTextObj());

        if(pTestObj && pTestObj->GetOutlinerParaObject() == xCell->GetOutlinerParaObject())
        if( pModel )
        {
            getSdrModelFromSdrObject().GetHitTestOutliner().SetTextObj(nullptr);
            // Update HitTestOutliner
            const SdrTextObj* pTestObj = pModel->GetHitTestOutliner().GetTextObj();
            if( pTestObj && pTestObj->GetOutlinerParaObject() == xCell->GetOutlinerParaObject() )
                pModel->GetHitTestOutliner().SetTextObj( nullptr );
        }

        xCell->SetOutlinerParaObject( pTextObject );

        SetTextSizeDirty();
        NbcAdjustTextFrameWidthAndHeight();
    }
@@ -1875,7 +1891,7 @@ bool SdrTableObj::AdjustTextFrameWidthAndHeight()

bool SdrTableObj::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool bHeight, bool bWidth) const
{
    if(rR.IsEmpty() || !mpImpl.is() || !mpImpl->mxTable.is())
    if((pModel == nullptr) || rR.IsEmpty() || !mpImpl.is() || !mpImpl->mxTable.is() )
        return false;

    tools::Rectangle aRectangle( rR );
@@ -2187,7 +2203,7 @@ bool SdrTableObj::applySpecialDrag(SdrDragStat& rDrag)

            if( pEdgeHdl )
            {
                if( IsInserted() )
                if( GetModel() && IsInserted() )
                {
                    rDrag.SetEndDragChangesAttributes(true);
                    rDrag.SetEndDragChangesLayout(true);
@@ -2325,21 +2341,12 @@ void SdrTableObj::RestGeoData(const SdrObjGeoData& rGeo)
}


SdrTableObj* SdrTableObj::CloneRange(
    const CellPos& rStart,
    const CellPos& rEnd,
    SdrModel& rTargetModel)
SdrTableObj* SdrTableObj::CloneRange( const CellPos& rStart, const CellPos& rEnd )
{
    const sal_Int32 nColumns = rEnd.mnCol - rStart.mnCol + 1;
    const sal_Int32 nRows = rEnd.mnRow - rStart.mnRow + 1;

    SdrTableObj* pNewTableObj(
        new SdrTableObj(
            rTargetModel,
            GetCurrentBoundRect(),
            nColumns,
            nRows));

    SdrTableObj* pNewTableObj = new SdrTableObj( GetModel(), GetCurrentBoundRect(), nColumns, nRows);
    pNewTableObj->setTableStyleSettings( getTableStyleSettings() );
    pNewTableObj->setTableStyle( getTableStyle() );

diff --git a/svx/source/table/tablecolumn.cxx b/svx/source/table/tablecolumn.cxx
index e4007b3..e6f1c4a 100644
--- a/svx/source/table/tablecolumn.cxx
+++ b/svx/source/table/tablecolumn.cxx
@@ -141,10 +141,10 @@ void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& a
    bool bOk = false;
    bool bChange = false;

    SdrModel& rModel(mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject());
    TableColumnUndo* pUndo = nullptr;
    SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();

    if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled() )
    TableColumnUndo* pUndo = nullptr;
    if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() )
    {
        TableColumnRef xThis( this );
        pUndo = new TableColumnUndo( xThis );
@@ -214,7 +214,7 @@ void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& a
    {
        if( pUndo )
        {
            rModel.AddUndo( pUndo );
            pModel->AddUndo( pUndo );
            pUndo = nullptr;
        }
        mxTableModel->setModified(true);
diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index aaf4af7..cc0b6de 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -140,44 +140,35 @@ void SAL_CALL SvxTableControllerModifyListener::disposing( const css::lang::Even
// class SvxTableController


rtl::Reference< sdr::SelectionController > CreateTableController(
    SdrView& rView,
    const SdrTableObj& rObj,
    const rtl::Reference< sdr::SelectionController >& xRefController )
rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
{
    return SvxTableController::create(rView, rObj, xRefController);
    return SvxTableController::create( pView, pObj, xRefController );
}


rtl::Reference< sdr::SelectionController > SvxTableController::create(
    SdrView& rView,
    const SdrTableObj& rObj,
    const rtl::Reference< sdr::SelectionController >& xRefController )
rtl::Reference< sdr::SelectionController > SvxTableController::create( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController )
{
    if( xRefController.is() )
    {
        SvxTableController* pController = dynamic_cast< SvxTableController* >( xRefController.get() );

        if(pController && (pController->mxTableObj.get() == &rObj) && (&pController->mrView == &rView))
        {
        if( pController && (pController->mxTableObj.get() == pObj) && (pController->mpView == pView)  )
            return xRefController;
        }
    }

    return new SvxTableController(rView, rObj);
    return new SvxTableController( pView, pObj );
}


SvxTableController::SvxTableController(
    SdrView& rView,
    const SdrTableObj& rObj)
:   mbCellSelectionMode(false)
    ,mbLeftButtonDown(false)
    ,mpSelectionOverlay(nullptr)
    ,mrView(rView)
    ,mxTableObj(const_cast< SdrTableObj* >(&rObj))
    ,mnUpdateEvent( nullptr )
SvxTableController::SvxTableController( SdrObjEditView* pView, const SdrTableObj* pObj )
: mbCellSelectionMode(false)
, mbLeftButtonDown(false)
, mpSelectionOverlay(nullptr)
, mpView( dynamic_cast< SdrView* >( pView ) )
, mxTableObj( const_cast< SdrTableObj* >( pObj ) )
, mpModel( nullptr )
, mnUpdateEvent( nullptr )
{
    mpModel = mxTableObj->GetModel();

    mxTableObj->getActiveCellPos( maCursorFirstPos );
    maCursorLastPos = maCursorFirstPos;

@@ -211,14 +202,11 @@ SvxTableController::~SvxTableController()

bool SvxTableController::onKeyInput(const KeyEvent& rKEvt, vcl::Window* pWindow )
{
    if(!checkTableObject())
    if( !checkTableObject() )
        return false;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());

    // check if we are read only
    if( rModel.IsReadOnly())
    if( mpModel && mpModel->IsReadOnly())
    {
        switch( rKEvt.GetKeyCode().GetCode() )
        {
@@ -264,7 +252,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window*
    if (comphelper::LibreOfficeKit::isActive() && !pWindow)
    {
        // Tiled rendering: get the window that has the disabled map mode.
        if (OutputDevice* pOutputDevice = mrView.GetFirstOutputDevice())
        if (OutputDevice* pOutputDevice = mpView->GetFirstOutputDevice())
        {
            if (pOutputDevice->GetOutDevType() == OUTDEV_WINDOW)
                pWindow = static_cast<vcl::Window*>(pOutputDevice);
@@ -275,7 +263,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window*
        return false;

    SdrViewEvent aVEvt;
    if( !rMEvt.IsRight() && mrView.PickAnything(rMEvt,SdrMouseEventKind::BUTTONDOWN, aVEvt) == SdrHitKind::Handle )
    if( !rMEvt.IsRight() && mpView->PickAnything(rMEvt,SdrMouseEventKind::BUTTONDOWN, aVEvt) == SdrHitKind::Handle )
        return false;

    TableHitKind eHit = mxTableObj->CheckTableHit(pixelToLogic(rMEvt.GetPosPixel(), pWindow), maMouseDownPos.mnCol, maMouseDownPos.mnRow);
@@ -296,7 +284,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window*
    {
        RemoveSelection();

        SdrHdl* pHdl = mrView.PickHandle(pixelToLogic(rMEvt.GetPosPixel(), pWindow));
        SdrHdl* pHdl = mpView->PickHandle(pixelToLogic(rMEvt.GetPosPixel(), pWindow));

        if( pHdl )
        {
@@ -316,7 +304,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window*
    if (comphelper::LibreOfficeKit::isActive() && rMEvt.GetClicks() == 2 && rMEvt.IsLeft() && eHit == TableHitKind::CellTextArea)
    {
        bool bEmptyOutliner = false;
        if (Outliner* pOutliner = mrView.GetTextEditOutliner())
        if (Outliner* pOutliner = mpView->GetTextEditOutliner())
        {
            if (pOutliner->GetParagraphCount() == 1)
            {
@@ -330,7 +318,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window*
            StartSelection(maMouseDownPos);
            setSelectedCells(maMouseDownPos, maMouseDownPos);
            // Update graphic selection, should be hidden now.
            mrView.AdjustMarkHdl();
            mpView->AdjustMarkHdl();
            return true;
        }
    }
@@ -394,7 +382,7 @@ void SvxTableController::onSelectionHasChanged()
    }
    else
    {
        const SdrMarkList& rMarkList= mrView.GetMarkedObjectList();
        const SdrMarkList& rMarkList= mpView->GetMarkedObjectList();
        if( rMarkList.GetMarkCount() == 1 )
            bSelected = mxTableObj.get() == rMarkList.GetMark(0)->GetMarkedSdrObj();
        /* fdo#46186 Selecting the table means selecting the entire cells */
@@ -419,13 +407,12 @@ void SvxTableController::onSelectionHasChanged()

void SvxTableController::GetState( SfxItemSet& rSet )
{
    if(!mxTable.is() || !mxTableObj.is())
    if( !mxTable.is() || !mxTableObj.is() || !mxTableObj->GetModel() )
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    std::unique_ptr<SfxItemSet> xSet;
    bool bVertDone(false);

    bool bVertDone = false;

    // Iterate over all requested items in the set.
    SfxWhichIter aIter( rSet );
@@ -438,11 +425,15 @@ void SvxTableController::GetState( SfxItemSet& rSet )
            case SID_TABLE_VERT_CENTER:
            case SID_TABLE_VERT_NONE:
                {
                    if(!bVertDone)
                    if( !mxTable.is() || !mxTableObj->GetModel() )
                    {
                        rSet.DisableItem(nWhich);
                    }
                    else if(!bVertDone)
                    {
                        if (!xSet)
                        {
                            xSet.reset(new SfxItemSet(rModel.GetItemPool()));
                            xSet.reset(new SfxItemSet( mxTableObj->GetModel()->GetItemPool() ));
                            MergeAttrFromSelectedCells(*xSet, false);
                        }

@@ -514,270 +505,277 @@ void SvxTableController::GetState( SfxItemSet& rSet )

void SvxTableController::onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs )
{
    if(!checkTableObject())
    sdr::table::SdrTableObj* pTableObj = mxTableObj.get();
    if( !pTableObj )
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    bool bInsertAfter = true;
    sal_uInt16 nCount = 0;

    if( pArgs )
    if( mxTable.is() ) try
    {
        const SfxPoolItem* pItem = nullptr;
        pArgs->GetItemState(nSId, false, &pItem);
        if (pItem)

        bool bInsertAfter = true;
        sal_uInt16 nCount = 0;
        if( pArgs )
        {
            nCount = static_cast<const SfxInt16Item*>(pItem)->GetValue();
            if(SfxItemState::SET == pArgs->GetItemState(SID_TABLE_PARAM_INSERT_AFTER, true, &pItem))
                bInsertAfter = static_cast<const SfxBoolItem*>(pItem)->GetValue();
        }
    }

    CellPos aStart, aEnd;
    if( hasSelectedCells() )
    {
        getSelectedCells( aStart, aEnd );
    }
    else
    {
        if( bInsertAfter )
        {
            aStart.mnCol = mxTable->getColumnCount() - 1;
            aStart.mnRow = mxTable->getRowCount() - 1;
            aEnd = aStart;
        }
    }

    if( rTableObj.IsTextEditActive() )
        mrView.SdrEndTextEdit(true);

    RemoveSelection();

    const OUString sSize( "Size" );
    const bool bUndo(rModel.IsUndoEnabled());

    switch( nSId )
    {
    case SID_TABLE_INSERT_COL:
    {
        TableModelNotifyGuard aGuard( mxTable.get() );

        if( bUndo )
        {
            rModel.BegUndo( ImpGetResStr(STR_TABLE_INSCOL) );
            rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
        }

        Reference< XTableColumns > xCols( mxTable->getColumns() );
        const sal_Int32 nNewColumns = (nCount == 0) ? (aEnd.mnCol - aStart.mnCol + 1) : nCount;
        const sal_Int32 nNewStartColumn = aEnd.mnCol + (bInsertAfter ? 1 : 0);
        xCols->insertByIndex( nNewStartColumn, nNewColumns );

        for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ )
        {
            // Resolves fdo#61540
            // On Insert before, the reference column whose size is going to be
            // used for newly created column(s) is wrong. As the new columns are
            // inserted before the reference column, the reference column moved
            // to the new position by no., of new columns i.e (earlier+newcolumns).
            Reference< XPropertySet >(xCols->getByIndex(nNewStartColumn+nOffset), UNO_QUERY_THROW )->
                setPropertyValue( sSize,
                    Reference< XPropertySet >(xCols->getByIndex( bInsertAfter?nNewStartColumn-1:nNewStartColumn+nNewColumns ), UNO_QUERY_THROW )->
                        getPropertyValue( sSize ) );
        }

        // Copy cell properties
        sal_Int32 nPropSrcCol = (bInsertAfter ? aEnd.mnCol : aStart.mnCol + nNewColumns);
        sal_Int32 nRowSpan = 0;
        bool bNewSpan = false;

        for( sal_Int32 nRow = 0; nRow < mxTable->getRowCount(); ++nRow )
        {
            CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nPropSrcCol, nRow ).get() ) );

            // When we insert new COLUMNs, we want to copy ROW spans.
            if (xSourceCell.is() && nRowSpan == 0)
            const SfxPoolItem* pItem = nullptr;
            pArgs->GetItemState(nSId, false, &pItem);
            if (pItem)
            {
                // we are not in a span yet. Let's find out if the current cell is in a span.
                sal_Int32 nColSpan = sal_Int32();
                sal_Int32 nSpanInfoCol = sal_Int32();
                nCount = static_cast<const SfxInt16Item*>(pItem)->GetValue();
                if(SfxItemState::SET == pArgs->GetItemState(SID_TABLE_PARAM_INSERT_AFTER, true, &pItem))
                    bInsertAfter = static_cast<const SfxBoolItem*>(pItem)->GetValue();
            }
        }

                if( xSourceCell->getRowSpan() > 1 )
                {
                    // The current cell is the top-left cell in a span.
                    // Get the span info and propagate it to the target.
                    nRowSpan = xSourceCell->getRowSpan();
                    nColSpan = xSourceCell->getColumnSpan();
                    nSpanInfoCol = nPropSrcCol;
                }
                else if( xSourceCell->isMerged() )
                {
                    // The current cell is a middle cell in a 2D span.
                    // Look for the top-left cell in the span.
                    for( nSpanInfoCol = nPropSrcCol - 1; nSpanInfoCol >= 0; --nSpanInfoCol )
                    {
                        CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nSpanInfoCol, nRow ).get() ) );
                        if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged())
                        {
                            nRowSpan = xMergeInfoCell->getRowSpan();
                            nColSpan = xMergeInfoCell->getColumnSpan();
                            break;
                        }
                    }
                    if( nRowSpan == 1 )
                        nRowSpan = 0;
                }
        CellPos aStart, aEnd;
        if( hasSelectedCells() )
        {
            getSelectedCells( aStart, aEnd );
        }
        else
        {
            if( bInsertAfter )
            {
                aStart.mnCol = mxTable->getColumnCount() - 1;
                aStart.mnRow = mxTable->getRowCount() - 1;
                aEnd = aStart;
            }
        }

                // The target columns are outside the span; Start a new span.
                if( nRowSpan > 0 && ( nNewStartColumn < nSpanInfoCol || nSpanInfoCol + nColSpan <= nNewStartColumn ) )
                    bNewSpan = true;
        if( pTableObj->IsTextEditActive() )
            mpView->SdrEndTextEdit(true);

        RemoveSelection();

        const OUString sSize( "Size" );

        const bool bUndo = mpModel && mpModel->IsUndoEnabled();

        switch( nSId )
        {
        case SID_TABLE_INSERT_COL:
        {
            TableModelNotifyGuard aGuard( mxTable.get() );

            if( bUndo )
            {
                mpModel->BegUndo( ImpGetResStr(STR_TABLE_INSCOL) );
                mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
            }

            // Now copy the properties from the source to the targets
            Reference< XTableColumns > xCols( mxTable->getColumns() );
            const sal_Int32 nNewColumns = (nCount == 0) ? (aEnd.mnCol - aStart.mnCol + 1) : nCount;
            const sal_Int32 nNewStartColumn = aEnd.mnCol + (bInsertAfter ? 1 : 0);
            xCols->insertByIndex( nNewStartColumn, nNewColumns );

            for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ )
            {
                CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nNewStartColumn + nOffset, nRow ).get() ) );
                if( xTargetCell.is() )
                // Resolves fdo#61540
                // On Insert before, the reference column whose size is going to be
                // used for newly created column(s) is wrong. As the new columns are
                // inserted before the reference column, the reference column moved
                // to the new position by no., of new columns i.e (earlier+newcolumns).
                Reference< XPropertySet >(xCols->getByIndex(nNewStartColumn+nOffset), UNO_QUERY_THROW )->
                    setPropertyValue( sSize,
                        Reference< XPropertySet >(xCols->getByIndex( bInsertAfter?nNewStartColumn-1:nNewStartColumn+nNewColumns ), UNO_QUERY_THROW )->
                            getPropertyValue( sSize ) );
            }

            // Copy cell properties
            sal_Int32 nPropSrcCol = (bInsertAfter ? aEnd.mnCol : aStart.mnCol + nNewColumns);
            sal_Int32 nRowSpan = 0;
            bool bNewSpan = false;

            for( sal_Int32 nRow = 0; nRow < mxTable->getRowCount(); ++nRow )
            {
                CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nPropSrcCol, nRow ).get() ) );

                // When we insert new COLUMNs, we want to copy ROW spans.
                if (xSourceCell.is() && nRowSpan == 0)
                {
                    if( nRowSpan > 0 )
                    // we are not in a span yet. Let's find out if the current cell is in a span.
                    sal_Int32 nColSpan = sal_Int32();
                    sal_Int32 nSpanInfoCol = sal_Int32();

                    if( xSourceCell->getRowSpan() > 1 )
                    {
                        if( bNewSpan )
                            xTargetCell->merge( 1, nRowSpan );
                        else
                            xTargetCell->setMerged();
                        // The current cell is the top-left cell in a span.
                        // Get the span info and propagate it to the target.
                        nRowSpan = xSourceCell->getRowSpan();
                        nColSpan = xSourceCell->getColumnSpan();
                        nSpanInfoCol = nPropSrcCol;
                    }
                    xTargetCell->copyFormatFrom( xSourceCell );
                }
            }

            if( nRowSpan > 0 )
            {
                --nRowSpan;
                bNewSpan = false;
            }
        }

        if( bUndo )
            rModel.EndUndo();

        aStart.mnCol = nNewStartColumn;
        aStart.mnRow = 0;
        aEnd.mnCol = aStart.mnCol + nNewColumns - 1;
        aEnd.mnRow = mxTable->getRowCount() - 1;
        break;
    }

    case SID_TABLE_INSERT_ROW:
    {
        TableModelNotifyGuard aGuard( mxTable.get() );

        if( bUndo )
        {
            rModel.BegUndo( ImpGetResStr(STR_TABLE_INSROW ) );
            rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
        }

        Reference< XTableRows > xRows( mxTable->getRows() );
        const sal_Int32 nNewRows = (nCount == 0) ? (aEnd.mnRow - aStart.mnRow + 1) : nCount;
        const sal_Int32 nNewRowStart = aEnd.mnRow + (bInsertAfter ? 1 : 0);
        xRows->insertByIndex( nNewRowStart, nNewRows );

        for( sal_Int32 nOffset = 0; nOffset < nNewRows; nOffset++ )
        {
            Reference< XPropertySet >( xRows->getByIndex( aEnd.mnRow + nOffset + 1 ), UNO_QUERY_THROW )->
                setPropertyValue( sSize,
                    Reference< XPropertySet >( xRows->getByIndex( aStart.mnRow + nOffset ), UNO_QUERY_THROW )->
                        getPropertyValue( sSize ) );
        }

        // Copy the cell properties
        sal_Int32 nPropSrcRow = (bInsertAfter ? aEnd.mnRow : aStart.mnRow + nNewRows);
        sal_Int32 nColSpan = 0;
        bool bNewSpan = false;

        for( sal_Int32 nCol = 0; nCol < mxTable->getColumnCount(); ++nCol )
        {
            CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nPropSrcRow ).get() ) );

            if (!xSourceCell.is())
                continue;

            // When we insert new ROWs, we want to copy COLUMN spans.
            if( nColSpan == 0 )
            {
                // we are not in a span yet. Let's find out if the current cell is in a span.
                sal_Int32 nRowSpan = sal_Int32();
                sal_Int32 nSpanInfoRow = sal_Int32();

                if( xSourceCell->getColumnSpan() > 1 )
                {
                    // The current cell is the top-left cell in a span.
                    // Get the span info and propagate it to the target.
                    nColSpan = xSourceCell->getColumnSpan();
                    nRowSpan = xSourceCell->getRowSpan();
                    nSpanInfoRow = nPropSrcRow;
                }
                else if( xSourceCell->isMerged() )
                {
                    // The current cell is a middle cell in a 2D span.
                    // Look for the top-left cell in the span.
                    for( nSpanInfoRow = nPropSrcRow - 1; nSpanInfoRow >= 0; --nSpanInfoRow )
                    else if( xSourceCell->isMerged() )
                    {
                        CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nSpanInfoRow ).get() ) );
                        if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged())
                        // The current cell is a middle cell in a 2D span.
                        // Look for the top-left cell in the span.
                        for( nSpanInfoCol = nPropSrcCol - 1; nSpanInfoCol >= 0; --nSpanInfoCol )
                        {
                            nColSpan = xMergeInfoCell->getColumnSpan();
                            nRowSpan = xMergeInfoCell->getRowSpan();
                            break;
                            CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nSpanInfoCol, nRow ).get() ) );
                            if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged())
                            {
                                nRowSpan = xMergeInfoCell->getRowSpan();
                                nColSpan = xMergeInfoCell->getColumnSpan();
                                break;
                            }
                        }
                        if( nRowSpan == 1 )
                            nRowSpan = 0;
                    }
                    if( nColSpan == 1 )
                        nColSpan = 0;

                    // The target columns are outside the span; Start a new span.
                    if( nRowSpan > 0 && ( nNewStartColumn < nSpanInfoCol || nSpanInfoCol + nColSpan <= nNewStartColumn ) )
                        bNewSpan = true;
                }

                // Inserted rows are outside the span; Start a new span.
                if( nColSpan > 0 && ( nNewRowStart < nSpanInfoRow || nSpanInfoRow + nRowSpan <= nNewRowStart ) )
                    bNewSpan = true;
            }

            // Now copy the properties from the source to the targets
            for( sal_Int32 nOffset = 0; nOffset < nNewRows; ++nOffset )
            {
                CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nNewRowStart + nOffset ).get() ) );
                if( xTargetCell.is() )
                // Now copy the properties from the source to the targets
                for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ )
                {
                    if( nColSpan > 0 )
                    CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nNewStartColumn + nOffset, nRow ).get() ) );
                    if( xTargetCell.is() )
                    {
                        if( bNewSpan )
                            xTargetCell->merge( nColSpan, 1 );
                        else
                            xTargetCell->setMerged();
                        if( nRowSpan > 0 )
                        {
                            if( bNewSpan )
                                xTargetCell->merge( 1, nRowSpan );
                            else
                                xTargetCell->setMerged();
                        }
                        xTargetCell->copyFormatFrom( xSourceCell );
                    }
                    xTargetCell->copyFormatFrom( xSourceCell );
                }

                if( nRowSpan > 0 )
                {
                    --nRowSpan;
                    bNewSpan = false;
                }
            }

            if( nColSpan > 0 )
            {
                --nColSpan;
                bNewSpan = false;
            }
            if( bUndo )
                mpModel->EndUndo();

            aStart.mnCol = nNewStartColumn;
            aStart.mnRow = 0;
            aEnd.mnCol = aStart.mnCol + nNewColumns - 1;
            aEnd.mnRow = mxTable->getRowCount() - 1;
            break;
        }

        if( bUndo )
            rModel.EndUndo();
        case SID_TABLE_INSERT_ROW:
        {
            TableModelNotifyGuard aGuard( mxTable.get() );

        aStart.mnCol = 0;
        aStart.mnRow = nNewRowStart;
        aEnd.mnCol = mxTable->getColumnCount() - 1;
        aEnd.mnRow = aStart.mnRow + nNewRows - 1;
        break;
    }
    }
            if( bUndo )
            {
                mpModel->BegUndo( ImpGetResStr(STR_TABLE_INSROW ) );
                mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
            }

    StartSelection( aStart );
    UpdateSelection( aEnd );
            Reference< XTableRows > xRows( mxTable->getRows() );
            const sal_Int32 nNewRows = (nCount == 0) ? (aEnd.mnRow - aStart.mnRow + 1) : nCount;
            const sal_Int32 nNewRowStart = aEnd.mnRow + (bInsertAfter ? 1 : 0);
            xRows->insertByIndex( nNewRowStart, nNewRows );

            for( sal_Int32 nOffset = 0; nOffset < nNewRows; nOffset++ )
            {
                Reference< XPropertySet >( xRows->getByIndex( aEnd.mnRow + nOffset + 1 ), UNO_QUERY_THROW )->
                    setPropertyValue( sSize,
                        Reference< XPropertySet >( xRows->getByIndex( aStart.mnRow + nOffset ), UNO_QUERY_THROW )->
                            getPropertyValue( sSize ) );
            }

            // Copy the cell properties
            sal_Int32 nPropSrcRow = (bInsertAfter ? aEnd.mnRow : aStart.mnRow + nNewRows);
            sal_Int32 nColSpan = 0;
            bool bNewSpan = false;

            for( sal_Int32 nCol = 0; nCol < mxTable->getColumnCount(); ++nCol )
            {
                CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nPropSrcRow ).get() ) );

                if (!xSourceCell.is())
                    continue;

                // When we insert new ROWs, we want to copy COLUMN spans.
                if( nColSpan == 0 )
                {
                    // we are not in a span yet. Let's find out if the current cell is in a span.
                    sal_Int32 nRowSpan = sal_Int32();
                    sal_Int32 nSpanInfoRow = sal_Int32();

                    if( xSourceCell->getColumnSpan() > 1 )
                    {
                        // The current cell is the top-left cell in a span.
                        // Get the span info and propagate it to the target.
                        nColSpan = xSourceCell->getColumnSpan();
                        nRowSpan = xSourceCell->getRowSpan();
                        nSpanInfoRow = nPropSrcRow;
                    }
                    else if( xSourceCell->isMerged() )
                    {
                        // The current cell is a middle cell in a 2D span.
                        // Look for the top-left cell in the span.
                        for( nSpanInfoRow = nPropSrcRow - 1; nSpanInfoRow >= 0; --nSpanInfoRow )
                        {
                            CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nSpanInfoRow ).get() ) );
                            if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged())
                            {
                                nColSpan = xMergeInfoCell->getColumnSpan();
                                nRowSpan = xMergeInfoCell->getRowSpan();
                                break;
                            }
                        }
                        if( nColSpan == 1 )
                            nColSpan = 0;
                    }

                    // Inserted rows are outside the span; Start a new span.
                    if( nColSpan > 0 && ( nNewRowStart < nSpanInfoRow || nSpanInfoRow + nRowSpan <= nNewRowStart ) )
                        bNewSpan = true;
                }

                // Now copy the properties from the source to the targets
                for( sal_Int32 nOffset = 0; nOffset < nNewRows; ++nOffset )
                {
                    CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nNewRowStart + nOffset ).get() ) );
                    if( xTargetCell.is() )
                    {
                        if( nColSpan > 0 )
                        {
                            if( bNewSpan )
                                xTargetCell->merge( nColSpan, 1 );
                            else
                                xTargetCell->setMerged();
                        }
                        xTargetCell->copyFormatFrom( xSourceCell );
                    }
                }

                if( nColSpan > 0 )
                {
                    --nColSpan;
                    bNewSpan = false;
                }
            }

            if( bUndo )
                mpModel->EndUndo();

            aStart.mnCol = 0;
            aStart.mnRow = nNewRowStart;
            aEnd.mnCol = mxTable->getColumnCount() - 1;
            aEnd.mnRow = aStart.mnRow + nNewRows - 1;
            break;
        }
        }

        StartSelection( aStart );
        UpdateSelection( aEnd );
    }
    catch( Exception& )
    {
        OSL_FAIL("svx::SvxTableController::onInsert(), exception caught!");
    }
}


@@ -793,7 +791,7 @@ void SvxTableController::onDelete( sal_uInt16 nSId )
        getSelectedCells( aStart, aEnd );

        if( pTableObj->IsTextEditActive() )
            mrView.SdrEndTextEdit(true);
            mpView->SdrEndTextEdit(true);

        RemoveSelection();

@@ -832,7 +830,7 @@ void SvxTableController::onDelete( sal_uInt16 nSId )
        }

        if( bDeleteTable )
            mrView.DeleteMarkedObj();
            mpView->DeleteMarkedObj();
        else
            UpdateTableShape();
    }
@@ -888,16 +886,15 @@ namespace

void SvxTableController::onFormatTable( SfxRequest const & rReq )
{
    if(!mxTableObj.is())
    sdr::table::SdrTableObj* pTableObj = mxTableObj.get();
    if( !pTableObj )
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    const SfxItemSet* pArgs = rReq.GetArgs();

    if(!pArgs)
    if( !pArgs && pTableObj->GetModel() )
    {
        SfxItemSet aNewAttr(rModel.GetItemPool());
        SfxItemSet aNewAttr( pTableObj->GetModel()->GetItemPool() );

        // merge drawing layer text distance items into SvxBoxItem used by the dialog
        SvxBoxItem aBoxItem(mergeDrawinglayerTextDistancesAndSvxBoxItem(aNewAttr));
@@ -910,11 +907,7 @@ void SvxTableController::onFormatTable( SfxRequest const & rReq )
        aNewAttr.Put( aBoxInfoItem );

        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
        ScopedVclPtr<SfxAbstractTabDialog> xDlg( pFact ? pFact->CreateSvxFormatCellsDialog(
            &aNewAttr,
            rModel,
            &rTableObj) : nullptr );

        ScopedVclPtr<SfxAbstractTabDialog> xDlg( pFact ? pFact->CreateSvxFormatCellsDialog( &aNewAttr, pTableObj->GetModel(), pTableObj) : nullptr );
        // Even Cancel Button is returning positive(101) value,
        if (xDlg.get() && xDlg->Execute() == RET_OK)
        {
@@ -1033,19 +1026,16 @@ void SvxTableController::Execute( SfxRequest& rReq )

void SvxTableController::SetTableStyle( const SfxItemSet* pArgs )
{
    if(!checkTableObject())
        return;
    SdrTableObj* pTableObj = mxTableObj.get();
    SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());

    if(!pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_TABLE_STYLE, false)))
    if( !pTableObj || !pModel || !pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_TABLE_STYLE, false)) )
        return;

    const SfxStringItem* pArg = dynamic_cast< const SfxStringItem* >( &pArgs->Get( SID_TABLE_STYLE ) );
    if( pArg && mxTable.is() ) try
    {
        Reference< XStyleFamiliesSupplier > xSFS( rModel.getUnoModel(), UNO_QUERY_THROW );
        Reference< XStyleFamiliesSupplier > xSFS( pModel->getUnoModel(), UNO_QUERY_THROW );
        Reference< XNameAccess > xFamilyNameAccess( xSFS->getStyleFamilies(), UNO_QUERY_THROW );
        const OUString sFamilyName( "table" );
        Reference< XNameAccess > xTableFamilyAccess( xFamilyNameAccess->getByName( sFamilyName ), UNO_QUERY_THROW );
@@ -1055,15 +1045,15 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs )
            // found table style with the same name
            Reference< XIndexAccess > xNewTableStyle( xTableFamilyAccess->getByName( pArg->GetValue() ), UNO_QUERY_THROW );

            const bool bUndo = rModel.IsUndoEnabled();
            const bool bUndo = pModel->IsUndoEnabled();

            if( bUndo )
            {
                rModel.BegUndo(ImpGetResStr(STR_TABLE_STYLE));
                rModel.AddUndo(new TableStyleUndo(rTableObj));
                pModel->BegUndo( ImpGetResStr(STR_TABLE_STYLE) );
                pModel->AddUndo( new TableStyleUndo( *pTableObj ) );
            }

            rTableObj.setTableStyle( xNewTableStyle );
            pTableObj->setTableStyle( xNewTableStyle );

            const sal_Int32 nRowCount = mxTable->getRowCount();
            const sal_Int32 nColCount = mxTable->getColumnCount();
@@ -1108,7 +1098,7 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs )
            }

            if( bUndo )
                rModel.EndUndo();
                pModel->EndUndo();
        }
    }
    catch( Exception& )
@@ -1119,13 +1109,14 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs )

void SvxTableController::SetTableStyleSettings( const SfxItemSet* pArgs )
{
    if(!checkTableObject())
    SdrTableObj* pTableObj = mxTableObj.get();
    SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr;

    if( !pTableObj || !pModel )
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    TableStyleSettings aSettings( pTableObj->getTableStyleSettings() );

    TableStyleSettings aSettings(rTableObj.getTableStyleSettings() );
    const SfxPoolItem *pPoolItem=nullptr;

    if( SfxItemState::SET == pArgs->GetItemState(ID_VAL_USEFIRSTROWSTYLE, false,&pPoolItem) )
@@ -1146,38 +1137,36 @@ void SvxTableController::SetTableStyleSettings( const SfxItemSet* pArgs )
    if( SfxItemState::SET == pArgs->GetItemState(ID_VAL_USEBANDINGCOLUMNSTYLE, false,&pPoolItem) )
        aSettings.mbUseColumnBanding = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue();

    if( aSettings == rTableObj.getTableStyleSettings() )
    if( aSettings == pTableObj->getTableStyleSettings() )
        return;

    const bool bUndo(rModel.IsUndoEnabled());
    const bool bUndo = pModel->IsUndoEnabled();

    if( bUndo )
    {
        rModel.BegUndo( ImpGetResStr(STR_TABLE_STYLE_SETTINGS) );
        rModel.AddUndo(new TableStyleUndo(rTableObj));
        pModel->BegUndo( ImpGetResStr(STR_TABLE_STYLE_SETTINGS) );
        pModel->AddUndo( new TableStyleUndo( *pTableObj ) );
    }

    rTableObj.setTableStyleSettings( aSettings );
    pTableObj->setTableStyleSettings( aSettings );

    if( bUndo )
        rModel.EndUndo();
        pModel->EndUndo();
}

void SvxTableController::SetVertical( sal_uInt16 nSId )
{
    if(!checkTableObject())
    SdrTableObj* pTableObj = mxTableObj.get();
    if( !mxTable.is() || !pTableObj )
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());

    TableModelNotifyGuard aGuard( mxTable.get() );
    const bool bUndo(rModel.IsUndoEnabled());

    bool bUndo = mpModel && mpModel->IsUndoEnabled();
    if (bUndo)
    {
        rModel.BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT));
        rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoAttrObject(rTableObj));
        mpModel->BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT));
        mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoAttrObject(*pTableObj));
    }

    CellPos aStart, aEnd;
@@ -1219,7 +1208,7 @@ void SvxTableController::SetVertical( sal_uInt16 nSId )
    UpdateTableShape();

    if (bUndo)
        rModel.EndUndo();
        mpModel->EndUndo();
}

void SvxTableController::MergeMarkedCells()
@@ -1230,7 +1219,7 @@ void SvxTableController::MergeMarkedCells()
    if( pTableObj )
    {
        if( pTableObj->IsTextEditActive() )
            mrView.SdrEndTextEdit(true);
            mpView->SdrEndTextEdit(true);

        TableModelNotifyGuard aGuard( mxTable.get() );
        MergeRange( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow );
@@ -1239,102 +1228,102 @@ void SvxTableController::MergeMarkedCells()

void SvxTableController::SplitMarkedCells()
{
    if(!checkTableObject() || !mxTable.is())
        return;

    SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
    ScopedVclPtr< SvxAbstractSplitTableDialog > xDlg( pFact ? pFact->CreateSvxSplitTableDialog( nullptr, false, 99 ) : nullptr );

    if( xDlg.get() && xDlg->Execute() )
    if( mxTable.is() )
    {
        const sal_Int32 nCount = xDlg->GetCount() - 1;

        if( nCount < 1 )
            return;

        CellPos aStart, aEnd;
        getSelectedCells( aStart, aEnd );
        Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow ) ), UNO_QUERY_THROW );
        const sal_Int32 nRowCount = mxTable->getRowCount();
        const sal_Int32 nColCount = mxTable->getColumnCount();
        SdrTableObj& rTableObj(*mxTableObj.get());

        if( rTableObj.IsTextEditActive() )
            mrView.SdrEndTextEdit(true);

        TableModelNotifyGuard aGuard( mxTable.get() );
        SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
        const bool bUndo(rModel.IsUndoEnabled());

        if( bUndo )
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
        ScopedVclPtr< SvxAbstractSplitTableDialog > xDlg( pFact ? pFact->CreateSvxSplitTableDialog( nullptr, false, 99 ) : nullptr );
        if( xDlg.get() && xDlg->Execute() )
        {
            rModel.BegUndo( ImpGetResStr(STR_TABLE_SPLIT) );
            rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
            const sal_Int32 nCount = xDlg->GetCount() - 1;
            if( nCount < 1 )
                return;

            getSelectedCells( aStart, aEnd );

            Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow ) ), UNO_QUERY_THROW );

            const sal_Int32 nRowCount = mxTable->getRowCount();
            const sal_Int32 nColCount = mxTable->getColumnCount();


            SdrTableObj* pTableObj = mxTableObj.get();
            if( pTableObj )
            {
                if( pTableObj->IsTextEditActive() )
                    mpView->SdrEndTextEdit(true);

                TableModelNotifyGuard aGuard( mxTable.get() );

                const bool bUndo = mpModel && mpModel->IsUndoEnabled();
                if( bUndo )
                {
                    mpModel->BegUndo( ImpGetResStr(STR_TABLE_SPLIT) );
                    mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
                }

                if( xDlg->IsHorizontal() )
                {
                    xRange->split( 0, nCount );
                }
                else
                {
                    xRange->split( nCount, 0 );
                }

                if( bUndo )
                    mpModel->EndUndo();
            }
            aEnd.mnRow += mxTable->getRowCount() - nRowCount;
            aEnd.mnCol += mxTable->getColumnCount() - nColCount;

            setSelectedCells( aStart, aEnd );
        }

        if( xDlg->IsHorizontal() )
        {
            xRange->split( 0, nCount );
        }
        else
        {
            xRange->split( nCount, 0 );
        }

        if( bUndo )
            rModel.EndUndo();

        aEnd.mnRow += mxTable->getRowCount() - nRowCount;
        aEnd.mnCol += mxTable->getColumnCount() - nColCount;

        setSelectedCells( aStart, aEnd );
    }
}

void SvxTableController::DistributeColumns()
{
    if(!checkTableObject())
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    const bool bUndo(rModel.IsUndoEnabled());

    if( bUndo )
    SdrTableObj* pTableObj = mxTableObj.get();
    if( pTableObj )
    {
        rModel.BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_COLUMNS) );
        rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
        const bool bUndo = mpModel && mpModel->IsUndoEnabled();
        if( bUndo )
        {
            mpModel->BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_COLUMNS) );
            mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
        }

        CellPos aStart, aEnd;
        getSelectedCells( aStart, aEnd );
        pTableObj->DistributeColumns( aStart.mnCol, aEnd.mnCol );

        if( bUndo )
            mpModel->EndUndo();
    }

    CellPos aStart, aEnd;
    getSelectedCells( aStart, aEnd );
    rTableObj.DistributeColumns( aStart.mnCol, aEnd.mnCol );

    if( bUndo )
        rModel.EndUndo();
}

void SvxTableController::DistributeRows()
{
    if(!checkTableObject())
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    const bool bUndo(rModel.IsUndoEnabled());

    if( bUndo )
    SdrTableObj* pTableObj = mxTableObj.get();
    if( pTableObj )
    {
        rModel.BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_ROWS) );
        rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
        const bool bUndo = mpModel && mpModel->IsUndoEnabled();
        if( bUndo )
        {
            mpModel->BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_ROWS) );
            mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) );
        }

        CellPos aStart, aEnd;
        getSelectedCells( aStart, aEnd );
        pTableObj->DistributeRows( aStart.mnRow, aEnd.mnRow );

        if( bUndo )
            mpModel->EndUndo();
    }

    CellPos aStart, aEnd;
    getSelectedCells( aStart, aEnd );
    rTableObj.DistributeRows( aStart.mnRow, aEnd.mnRow );

    if( bUndo )
        rModel.EndUndo();
}

bool SvxTableController::HasMarked()
@@ -1344,15 +1333,12 @@ bool SvxTableController::HasMarked()

bool SvxTableController::DeleteMarked()
{
    if(!checkTableObject() || !HasMarked())
    if (!HasMarked())
        return false;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    const bool bUndo(rModel.IsUndoEnabled());

    const bool bUndo = mpModel && mpModel->IsUndoEnabled();
    if (bUndo)
        rModel.BegUndo(ImpGetResStr(STR_TABLE_DELETE_CELL_CONTENTS));
        mpModel->BegUndo(ImpGetResStr(STR_TABLE_DELETE_CELL_CONTENTS));

    CellPos aStart, aEnd;
    getSelectedCells( aStart, aEnd );
@@ -1371,7 +1357,7 @@ bool SvxTableController::DeleteMarked()
    }

    if (bUndo)
        rModel.EndUndo();
        mpModel->EndUndo();

    UpdateTableShape();
    return true;
@@ -1458,7 +1444,8 @@ SvxTableController::TblAction SvxTableController::getKeyboardAction(const KeyEve
{
    const bool bMod1 = rKEvt.GetKeyCode().IsMod1(); // ctrl
    const bool bMod2 = rKEvt.GetKeyCode().IsMod2(); // Alt
    const bool bTextEdit = mrView.IsTextEdit();

    const bool bTextEdit = mpView->IsTextEdit();

    TblAction nAction = TblAction::HandledByView;

@@ -1589,7 +1576,7 @@ SvxTableController::TblAction SvxTableController::getKeyboardAction(const KeyEve
        }

        bool bTextMove = false;
        OutlinerView* pOLV = mrView.GetTextEditOutlinerView();
        OutlinerView* pOLV = mpView->GetTextEditOutlinerView();
        if( pOLV )
        {
            RemoveSelection();
@@ -1753,7 +1740,7 @@ bool SvxTableController::executeAction(TblAction nAction, bool bSelect, vcl::Win
void SvxTableController::gotoCell(const CellPos& rPos, bool bSelect, vcl::Window* pWindow, TblAction nAction /*= TblAction::NONE */)
{
    if( mxTableObj.is() && mxTableObj->IsTextEditActive() )
        mrView.SdrEndTextEdit(true);
        mpView->SdrEndTextEdit(true);

    if( bSelect )
    {
@@ -1800,29 +1787,22 @@ const CellPos& SvxTableController::getSelectionEnd()

void SvxTableController::MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow )
{
    if(!checkTableObject() || !mxTable.is())
        return;

    try
    if( mxTable.is() ) try
    {
        Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( nFirstCol, nFirstRow,nLastCol, nLastRow ) ), UNO_QUERY_THROW );

        if( xRange->isMergeable() )
        {
            SdrTableObj& rTableObj(*mxTableObj.get());
            SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
            const bool bUndo(rModel.IsUndoEnabled());

            const bool bUndo = mpModel && mpModel->IsUndoEnabled();
            if( bUndo )
            {
                rModel.BegUndo( ImpGetResStr(STR_TABLE_MERGE) );
                rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj));
                mpModel->BegUndo( ImpGetResStr(STR_TABLE_MERGE) );
                mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*mxTableObj.get()) );
            }

            xRange->merge();

            if( bUndo )
                rModel.EndUndo();
                mpModel->EndUndo();
        }
    }
    catch( Exception& )
@@ -1868,20 +1848,16 @@ void SvxTableController::findMergeOrigin( CellPos& rPos )

void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, TblAction nAction /*= TblAction::NONE */)
{
    SdrPageView* pPV(mrView.GetSdrPageView());
    SdrPageView* pPV = mpView->GetSdrPageView();

    if(nullptr == pPV || !checkTableObject())
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());

    if(rTableObj.GetPage() == pPV->GetPage())
    sdr::table::SdrTableObj* pTableObj = mxTableObj.get();
    if( pTableObj && pTableObj->GetPage() == pPV->GetPage() )
    {
        bool bEmptyOutliner = false;

        if(!rTableObj.GetOutlinerParaObject() && mrView.GetTextEditOutliner())
        if(!pTableObj->GetOutlinerParaObject() && mpView->GetTextEditOutliner())
        {
            ::Outliner* pOutl = mrView.GetTextEditOutliner();
            ::Outliner* pOutl = mpView->GetTextEditOutliner();
            sal_Int32 nParaCnt = pOutl->GetParagraphCount();
            Paragraph* p1stPara = pOutl->GetParagraph( 0 );

@@ -1898,30 +1874,28 @@ void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, Tbl
        CellPos aPos( rPos );
        findMergeOrigin( aPos );

        if( &rTableObj != mrView.GetTextEditObject() || bEmptyOutliner || !rTableObj.IsTextEditActive( aPos ) )
        if( pTableObj != mpView->GetTextEditObject() || bEmptyOutliner || !pTableObj->IsTextEditActive( aPos ) )
        {
            if( rTableObj.IsTextEditActive() )
                mrView.SdrEndTextEdit(true);
            if( pTableObj->IsTextEditActive() )
                mpView->SdrEndTextEdit(true);

            rTableObj.setActiveCell( aPos );
            pTableObj->setActiveCell( aPos );

            // create new outliner, owner will be the SdrObjEditView
            SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
            SdrOutliner* pOutl(SdrMakeOutliner(OutlinerMode::OutlineObject, rModel));

            if (pOutl && rTableObj.IsVerticalWriting())
            SdrOutliner* pOutl = mpModel ? SdrMakeOutliner(OutlinerMode::OutlineObject, *mpModel) : nullptr;
            if (pOutl && pTableObj->IsVerticalWriting())
                pOutl->SetVertical( true );

            if (mrView.SdrBeginTextEdit(&rTableObj, pPV, pWindow, true, pOutl))
            if (mpView->SdrBeginTextEdit(pTableObj, pPV, pWindow, true, pOutl))
            {
                maCursorLastPos = maCursorFirstPos = rPos;

                OutlinerView* pOLV = mrView.GetTextEditOutlinerView();
                OutlinerView* pOLV = mpView->GetTextEditOutlinerView();

                // Move cursor to end of text
                ESelection aNewSelection;

                const WritingMode eMode = rTableObj.GetWritingMode();
                const WritingMode eMode = pTableObj->GetWritingMode();
                if (((nAction == TblAction::GotoLeftCell) || (nAction == TblAction::GotoRightCell)) && (eMode != WritingMode_TB_RL))
                {
                    const bool bLast = ((nAction == TblAction::GotoLeftCell) && (eMode == WritingMode_LR_TB)) ||
@@ -1939,11 +1913,11 @@ void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, Tbl

void SvxTableController::StopTextEdit()
{
    if(mrView.IsTextEdit())
    if(mpView->IsTextEdit())
    {
        mrView.SdrEndTextEdit();
        mrView.SetCurrentObj(OBJ_TABLE);
        mrView.SetEditMode(SdrViewEditMode::Edit);
        mpView->SdrEndTextEdit();
        mpView->SetCurrentObj(OBJ_TABLE);
        mpView->SetEditMode(SdrViewEditMode::Edit);
    }
}

@@ -1997,7 +1971,7 @@ void SvxTableController::getSelectedCells( CellPos& rFirst, CellPos& rLast )
        }
        while(bExt);
    }
    else if(mrView.IsTextEdit())
    else if( mpView && mpView->IsTextEdit() )
    {
        rFirst = getSelectionStart();
        findMergeOrigin( rFirst );
@@ -2036,7 +2010,7 @@ void SvxTableController::StartSelection( const CellPos& rPos )
    StopTextEdit();
    mbCellSelectionMode = true;
    maCursorLastPos = maCursorFirstPos = rPos;
    mrView.MarkListHasChanged();
    mpView->MarkListHasChanged();
}


@@ -2051,58 +2025,53 @@ void SvxTableController::setSelectedCells( const CellPos& rStart, const CellPos&

bool SvxTableController::ChangeFontSize(bool bGrow, const FontList* pFontList)
{
    if(!checkTableObject() || !mxTable.is())
        return false;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());

    if (mrView.IsTextEdit())
        return true;

    CellPos aStart, aEnd;

    if(hasSelectedCells())
    if (mxTable.is())
    {
        getSelectedCells(aStart, aEnd);
    }
    else
    {
        aStart.mnRow = 0;
        aStart.mnCol = 0;
        aEnd.mnRow = mxTable->getRowCount() - 1;
        aEnd.mnCol = mxTable->getColumnCount() - 1;
    }
        if (mpView->IsTextEdit())
            return true;

    for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++)
    {
        for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++)
        CellPos aStart, aEnd;
        if(hasSelectedCells())
        {
            CellRef xCell(dynamic_cast< Cell* >(mxTable->getCellByPosition(nCol, nRow).get()));
            if (xCell.is())
            {
                if (rModel.IsUndoEnabled())
                    xCell->AddUndo();
            getSelectedCells(aStart, aEnd);
        }
        else
        {
            aStart.mnRow = 0;
            aStart.mnCol = 0;
            aEnd.mnRow = mxTable->getRowCount() - 1;
            aEnd.mnCol = mxTable->getColumnCount() - 1;
        }

                SfxItemSet aCellSet(xCell->GetItemSet());
                if (EditView::ChangeFontSize(bGrow, aCellSet, pFontList))
        for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++)
        {
            for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++)
            {
                CellRef xCell(dynamic_cast< Cell* >(mxTable->getCellByPosition(nCol, nRow).get()));
                if (xCell.is())
                {
                    xCell->SetMergedItemSetAndBroadcast(aCellSet, false);
                    if (mpModel && mpModel->IsUndoEnabled())
                        xCell->AddUndo();

                    SfxItemSet aCellSet(xCell->GetItemSet());
                    if (EditView::ChangeFontSize(bGrow, aCellSet, pFontList))
                    {
                        xCell->SetMergedItemSetAndBroadcast(aCellSet, false);
                    }
                }
            }
        }
        UpdateTableShape();
        return true;
    }

    UpdateTableShape();

    return true;
    return false;
}


void SvxTableController::UpdateSelection( const CellPos& rPos )
{
    maCursorLastPos = rPos;
    mrView.MarkListHasChanged();
    mpView->MarkListHasChanged();
}


@@ -2130,7 +2099,7 @@ void SvxTableController::RemoveSelection()
    if( mbCellSelectionMode )
    {
        mbCellSelectionMode = false;
        mrView.MarkListHasChanged();
        mpView->MarkListHasChanged();
    }
}

@@ -2167,14 +2136,14 @@ void SvxTableController::updateSelectionOverlay()
            aRanges.push_back( a2DRange );

            ::Color aHighlight( COL_BLUE );
            OutputDevice* pOutDev = mrView.GetFirstOutputDevice();
            OutputDevice* pOutDev = mpView->GetFirstOutputDevice();
            if( pOutDev )
                aHighlight = pOutDev->GetSettings().GetStyleSettings().GetHighlightColor();

            const sal_uInt32 nCount = mrView.PaintWindowCount();
            const sal_uInt32 nCount = mpView->PaintWindowCount();
            for( sal_uInt32 nIndex = 0; nIndex < nCount; nIndex++ )
            {
                SdrPaintWindow* pPaintWindow = mrView.GetPaintWindow(nIndex);
                SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(nIndex);
                if( pPaintWindow )
                {
                    rtl::Reference < sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
@@ -2531,15 +2500,13 @@ void SvxTableController::UpdateTableShape()

void SvxTableController::SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll)
{
    if(!checkTableObject() || !mxTable.is())
    if( !mxTable.is() )
        return;

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    const bool bUndo(rModel.IsUndoEnabled());
    const bool bUndo = mpModel && mpModel->IsUndoEnabled();

    if( bUndo )
        rModel.BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) );
        mpModel->BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) );

    CellPos aStart, aEnd;
    getSelectedCells( aStart, aEnd );
@@ -2577,7 +2544,7 @@ void SvxTableController::SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bR
    UpdateTableShape();

    if( bUndo )
        rModel.EndUndo();
        mpModel->EndUndo();
}


@@ -2587,9 +2554,9 @@ bool SvxTableController::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAtt
    {
        MergeAttrFromSelectedCells( rTargetSet, bOnlyHardAttr );

        if( mrView.IsTextEdit() )
        if( mpView->IsTextEdit() )
        {
            OutlinerView* pTextEditOutlinerView = mrView.GetTextEditOutlinerView();
            OutlinerView* pTextEditOutlinerView = mpView->GetTextEditOutlinerView();
            if(pTextEditOutlinerView)
            {
                // FALSE= consider InvalidItems not as the default, but as "holes"
@@ -2608,7 +2575,7 @@ bool SvxTableController::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAtt

bool SvxTableController::SetAttributes(const SfxItemSet& rSet, bool bReplaceAll)
{
    if( mbCellSelectionMode || mrView.IsTextEdit()  )
    if( mbCellSelectionMode || mpView->IsTextEdit()  )
    {
        SetAttrToSelectedCells( rSet, bReplaceAll );
        return true;
@@ -2621,17 +2588,16 @@ bool SvxTableController::GetMarkedObjModel( SdrPage* pNewPage )
{
    if( mxTableObj.is() && mbCellSelectionMode && pNewPage ) try
    {
        sdr::table::SdrTableObj& rTableObj(*mxTableObj.get());
        CellPos aStart, aEnd;
        getSelectedCells(aStart, aEnd);
        sdr::table::SdrTableObj& rTableObj = *mxTableObj.get();

        // Clone to new SdrModel
        SdrTableObj* pNewTableObj(
            rTableObj.CloneRange(
                aStart,
                aEnd,
                pNewPage->getSdrModelFromSdrPage()));
        pNewTableObj->SetPage(pNewPage);
        CellPos aStart, aEnd;
        getSelectedCells( aStart, aEnd );

        SdrTableObj* pNewTableObj = rTableObj.CloneRange( aStart, aEnd );

        pNewTableObj->SetPage( pNewPage );
        pNewTableObj->SetModel( pNewPage->GetModel() );

        pNewPage->InsertObject(pNewTableObj, SAL_MAX_SIZE);

        return true;
@@ -2640,14 +2606,13 @@ bool SvxTableController::GetMarkedObjModel( SdrPage* pNewPage )
    {
        OSL_FAIL( "svx::SvxTableController::GetMarkedObjModel(), exception caught!" );
    }

    return false;
}


bool SvxTableController::PasteObjModel( const SdrModel& rModel )
{
    if( mxTableObj.is() && (rModel.GetPageCount() >= 1) )
    if( mxTableObj.is() && mpView && (rModel.GetPageCount() >= 1) )
    {
        const SdrPage* pPastePage = rModel.GetPage(0);
        if( pPastePage && pPastePage->GetObjCount() == 1 )
@@ -2682,8 +2647,8 @@ bool SvxTableController::PasteObject( SdrTableObj const * pPasteTableObj )
    CellPos aStart, aEnd;
    getSelectedCells( aStart, aEnd );

    if( mrView.IsTextEdit() )
        mrView.SdrEndTextEdit(true);
    if( mpView->IsTextEdit() )
        mpView->SdrEndTextEdit(true);

    sal_Int32 nColumns = mxTable->getColumnCount();
    sal_Int32 nRows = mxTable->getRowCount();
@@ -2727,51 +2692,51 @@ bool SvxTableController::TakeFormatPaintBrush( std::shared_ptr< SfxItemSet >& /*

bool SvxTableController::ApplyFormatPaintBrush( SfxItemSet& rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats )
{
    if(!mbCellSelectionMode)
    if( mbCellSelectionMode )
    {
        return false;
    }
        SdrTextObj* pTableObj = dynamic_cast<SdrTextObj*>( mxTableObj.get() );
        if( !pTableObj )
            return false;

    if(!checkTableObject())
        return false;
        const bool bUndo = mpModel && mpModel->IsUndoEnabled();

    SdrTableObj& rTableObj(*mxTableObj.get());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    const bool bUndo(rModel.IsUndoEnabled());
        if( bUndo )
            mpModel->BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) );

    if( bUndo )
        rModel.BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT));
        CellPos aStart, aEnd;
        getSelectedCells( aStart, aEnd );

    CellPos aStart, aEnd;
    getSelectedCells( aStart, aEnd );
    const bool bFrame = (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER ) == SfxItemState::SET) || (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER_INNER ) == SfxItemState::SET);
        const bool bFrame = (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER ) == SfxItemState::SET) || (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER_INNER ) == SfxItemState::SET);

    for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
    {
        for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
        for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ )
        {
            CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
            if( xCell.is() )
            for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ )
            {
                if (bUndo)
                    xCell->AddUndo();
                SdrText* pText = static_cast< SdrText* >( xCell.get() );
                SdrObjEditView::ApplyFormatPaintBrushToText( rFormatSet, rTableObj, pText, bNoCharacterFormats, bNoParagraphFormats );
                CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
                if( xCell.is() )
                {
                    if (bUndo)
                        xCell->AddUndo();
                    SdrText* pText = static_cast< SdrText* >( xCell.get() );
                    SdrObjEditView::ApplyFormatPaintBrushToText( rFormatSet, *pTableObj, pText, bNoCharacterFormats, bNoParagraphFormats );
                }
            }
        }

        if( bFrame )
        {
            ApplyBorderAttr( rFormatSet );
        }

        UpdateTableShape();

        if( bUndo )
            mpModel->EndUndo();

        return true;

    }

    if( bFrame )
    {
        ApplyBorderAttr( rFormatSet );
    }

    UpdateTableShape();

    if( bUndo )
        rModel.EndUndo();

    return true;
    return false;
}


@@ -3112,22 +3077,26 @@ bool SvxTableController::isColumnSelected( sal_Int32 nColumn )

bool SvxTableController::isRowHeader()
{
    if(!checkTableObject())
    SdrTableObj* pTableObj = mxTableObj.get();
    SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr;

    if( !pTableObj || !pModel )
        return false;

    SdrTableObj& rTableObj(*mxTableObj.get());
    TableStyleSettings aSettings(rTableObj.getTableStyleSettings());
    TableStyleSettings aSettings( pTableObj->getTableStyleSettings() );

    return aSettings.mbUseFirstRow;
}

bool SvxTableController::isColumnHeader()
{
    if(!checkTableObject())
    SdrTableObj* pTableObj = mxTableObj.get();
    SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr;

    if( !pTableObj || !pModel )
        return false;

    SdrTableObj& rTableObj(*mxTableObj.get());
    TableStyleSettings aSettings(rTableObj.getTableStyleSettings());
    TableStyleSettings aSettings( pTableObj->getTableStyleSettings() );

    return aSettings.mbUseFirstColumn;
}
@@ -3156,7 +3125,7 @@ bool SvxTableController::setCursorLogicPosition(const Point& rPosition, bool bPo
            // No selection, but rPosition is at an other cell: start table selection.
            StartSelection(maMouseDownPos);
            // Update graphic selection, should be hidden now.
            mrView.AdjustMarkHdl();
            mpView->AdjustMarkHdl();
        }
    }

diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx
index 812e3de7..033af24 100644
--- a/svx/source/table/tablemodel.cxx
+++ b/svx/source/table/tablemodel.cxx
@@ -554,7 +554,7 @@ void TableModel::unlockBroadcasts()
void TableModel::notifyModification()
{
    ::osl::MutexGuard guard( m_aMutex );
    if( (mnNotifyLock == 0) && mpTableObj )
    if( (mnNotifyLock == 0) && mpTableObj && mpTableObj->GetModel() )
    {
        mbNotifyPending = false;

@@ -602,7 +602,8 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount )
    {
        try
        {
            SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject());
            SdrModel* pModel = mpTableObj->GetModel();

            TableModelNotifyGuard aGuard( this );
            nIndex = insert_range<ColumnVector,ColumnVector::iterator,TableColumnRef>( maColumns, nIndex, nCount );

@@ -618,12 +619,11 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount )
                aNewColumns[nOffset] = xNewCol;
            }

            const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled());

            const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled();
            if( bUndo )
            {
                rModel.BegUndo( ImpGetResStr(STR_TABLE_INSCOL) );
                rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
                pModel->BegUndo( ImpGetResStr(STR_TABLE_INSCOL) );
                pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );

                TableModelRef xThis( this );

@@ -638,7 +638,7 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount )
                        (*aCellIter++) = getCell( nIndex + nOffset, nRow );
                }

                rModel.AddUndo( new InsertColUndo( xThis, nIndex, aNewColumns, aNewCells ) );
                pModel->AddUndo( new InsertColUndo( xThis, nIndex, aNewColumns, aNewCells ) );
            }

            const sal_Int32 nRowCount = getRowCountImpl();
@@ -660,9 +660,11 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount )
            }

            if( bUndo )
                rModel.EndUndo();
                pModel->EndUndo();

            rModel.SetChanged();
            if( pModel )
                pModel->SetChanged();

        }
        catch( Exception& )
        {
@@ -689,13 +691,14 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
                nCount = nColCount - nIndex;

            sal_Int32 nRows = getRowCountImpl();
            SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject());
            const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled());

            SdrModel* pModel = mpTableObj->GetModel();

            const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled();
            if( bUndo  )
            {
                rModel.BegUndo( ImpGetResStr(STR_UNDO_COL_DELETE) );
                rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
                pModel->BegUndo( ImpGetResStr(STR_UNDO_COL_DELETE) );
                pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );

                TableModelRef xThis( this );
                ColumnVector aRemovedCols( nCount );
@@ -713,7 +716,7 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
                        (*aCellIter++) = getCell( nIndex + nOffset, nRow );
                }

                rModel.AddUndo( new RemoveColUndo( xThis, nIndex, aRemovedCols, aRemovedCells ) );
                pModel->AddUndo( new RemoveColUndo( xThis, nIndex, aRemovedCols, aRemovedCells ) );
            }

            // only rows before and inside the removed rows are considered
@@ -766,9 +769,10 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount )
                maRows[nRows]->removeColumns( nIndex, nCount );

            if( bUndo )
                rModel.EndUndo();
                pModel->EndUndo();

            rModel.SetChanged();
            if( pModel )
                pModel->SetChanged();
        }
        catch( Exception& )
        {
@@ -785,9 +789,8 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount )
{
    if( nCount && mpTableObj )
    {
        SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject());
        const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled());

        SdrModel* pModel = mpTableObj->GetModel();
        const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled();
        try
        {
            TableModelNotifyGuard aGuard( this );
@@ -805,10 +808,10 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount )

            if( bUndo )
            {
                rModel.BegUndo( ImpGetResStr(STR_TABLE_INSROW) );
                rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
                pModel->BegUndo( ImpGetResStr(STR_TABLE_INSROW) );
                pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
                TableModelRef xThis( this );
                rModel.AddUndo( new InsertRowUndo( xThis, nIndex, aNewRows ) );
                pModel->AddUndo( new InsertRowUndo( xThis, nIndex, aNewRows ) );
            }

            // check if cells merge over new columns
@@ -833,9 +836,10 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount )
            OSL_FAIL("sdr::table::TableModel::insertRows(), exception caught!");
        }
        if( bUndo )
            rModel.EndUndo();
            pModel->EndUndo();

        rModel.SetChanged();
        if( pModel )
            pModel->SetChanged();

        updateRows();
        setModified(true);
@@ -849,8 +853,8 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount )

    if( mpTableObj && nCount && (nIndex >= 0) && (nIndex < nRowCount) )
    {
        SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject());
        const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled());
        SdrModel* pModel = mpTableObj->GetModel();
        const bool bUndo = pModel && mpTableObj->IsInserted()&& pModel->IsUndoEnabled();

        try
        {
@@ -862,8 +866,8 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount )

            if( bUndo )
            {
                rModel.BegUndo( ImpGetResStr(STR_UNDO_ROW_DELETE) );
                rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );
                pModel->BegUndo( ImpGetResStr(STR_UNDO_ROW_DELETE) );
                pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) );

                TableModelRef xThis( this );

@@ -871,7 +875,7 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount )
                for( sal_Int32 nOffset = 0; nOffset < nCount; ++nOffset )
                    aRemovedRows[nOffset] = maRows[nIndex+nOffset];

                rModel.AddUndo( new RemoveRowUndo( xThis, nIndex, aRemovedRows ) );
                pModel->AddUndo( new RemoveRowUndo( xThis, nIndex, aRemovedRows ) );
            }

            // only rows before and inside the removed rows are considered
@@ -922,9 +926,10 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount )
            remove_range<RowVector,RowVector::iterator>( maRows, nIndex, nCount );

            if( bUndo )
                rModel.EndUndo();
                pModel->EndUndo();

            rModel.SetChanged();
            if( pModel )
                pModel->SetChanged();
        }
        catch( Exception& )
        {
@@ -1045,11 +1050,10 @@ void TableModel::optimize()

void TableModel::merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan )
{
    if(nullptr == mpTableObj)
        return;
    SdrModel* pModel = mpTableObj->GetModel();

    SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject());
    const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled());
    const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled();

    const sal_Int32 nLastRow = nRow + nRowSpan;
    const sal_Int32 nLastCol = nCol + nColSpan;

diff --git a/svx/source/table/tablerow.cxx b/svx/source/table/tablerow.cxx
index cf765b4..43010ad 100644
--- a/svx/source/table/tablerow.cxx
+++ b/svx/source/table/tablerow.cxx
@@ -206,15 +206,14 @@ void SAL_CALL TableRow::setName( const OUString& aName )

void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
{
    if(!mxTableModel.is() || nullptr == mxTableModel->getSdrTableObj())
        return;
    bool bOk = false;
    bool bChange = false;

    SdrTableObj& rTableObj(*mxTableModel->getSdrTableObj());
    SdrModel& rModel(rTableObj.getSdrModelFromSdrObject());
    bool bOk(false);
    bool bChange(false);
    TableRowUndo* pUndo(nullptr);
    const bool bUndo(rTableObj.IsInserted() && rModel.IsUndoEnabled());
    TableRowUndo* pUndo = nullptr;

    SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel();

    const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled();

    if( bUndo )
    {
@@ -277,7 +276,6 @@ void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aVal
        delete pUndo;
        throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
    }

    if( !bOk )
    {
        delete pUndo;
@@ -288,7 +286,7 @@ void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aVal
    {
        if( pUndo )
        {
            rModel.AddUndo( pUndo );
            pModel->AddUndo( pUndo );
            pUndo = nullptr;
        }
        mxTableModel->setModified(true);
diff --git a/svx/source/table/tablertfimporter.cxx b/svx/source/table/tablertfimporter.cxx
index b50efb3..714e0c6 100644
--- a/svx/source/table/tablertfimporter.cxx
+++ b/svx/source/table/tablertfimporter.cxx
@@ -132,8 +132,8 @@ private:

SdrTableRTFParser::SdrTableRTFParser( SdrTableObj& rTableObj )
: mrTableObj( rTableObj )
, mpOutliner( SdrMakeOutliner( OutlinerMode::TextObject, rTableObj.getSdrModelFromSdrObject() ) )
, mrItemPool( rTableObj.getSdrModelFromSdrObject().GetItemPool() )
, mpOutliner( SdrMakeOutliner( OutlinerMode::TextObject, *rTableObj.GetModel() ) )
, mrItemPool( rTableObj.GetModel()->GetItemPool() )
, mnLastToken( 0 )
, mbNewDef( false )
, mnStartPara( 0 )
diff --git a/svx/source/table/tableundo.cxx b/svx/source/table/tableundo.cxx
index 493c895..9a14948 100644
--- a/svx/source/table/tableundo.cxx
+++ b/svx/source/table/tableundo.cxx
@@ -35,10 +35,10 @@ using namespace ::com::sun::star::table;
namespace sdr { namespace table {

CellUndo::CellUndo( const tools::WeakReference<SdrObject>& xObjRef, const CellRef& xCell )
:   SdrUndoAction(xCell->GetObject().getSdrModelFromSdrObject())
    ,mxObjRef( xObjRef )
    ,mxCell( xCell )
    ,mbUndo( true )
    : SdrUndoAction( *xCell->GetModel() )
    , mxObjRef( xObjRef )
    , mxCell( xCell )
    , mbUndo( true )
{
    if( mxCell.is() && mxObjRef.is() )
    {
@@ -162,10 +162,10 @@ static void Dispose( RowVector& rRows )


InsertRowUndo::InsertRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aNewRows )
:   SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
    ,mxTable( xTable )
    ,mnIndex( nIndex )
    ,mbUndo( true )
    : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() )
    , mxTable( xTable )
    , mnIndex( nIndex )
    , mbUndo( true )
{
    maRows.swap( aNewRows );
}
@@ -202,10 +202,10 @@ void InsertRowUndo::Redo()


RemoveRowUndo::RemoveRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aRemovedRows )
:   SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
    ,mxTable( xTable )
    ,mnIndex( nIndex )
    ,mbUndo( true )
    : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() )
    , mxTable( xTable )
    , mnIndex( nIndex )
    , mbUndo( true )
{
    maRows.swap( aRemovedRows );
}
@@ -258,10 +258,10 @@ static void Dispose( CellVector& rCells )


InsertColUndo::InsertColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells  )
:   SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
    ,mxTable( xTable )
    ,mnIndex( nIndex )
    ,mbUndo( true )
    : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() )
    , mxTable( xTable )
    , mnIndex( nIndex )
    , mbUndo( true )
{
    maColumns.swap( aNewCols );
    maCells.swap( aCells );
@@ -302,10 +302,10 @@ void InsertColUndo::Redo()


RemoveColUndo::RemoveColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells )
:   SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject())
    ,mxTable( xTable )
    ,mnIndex( nIndex )
    ,mbUndo( true )
    : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() )
    , mxTable( xTable )
    , mnIndex( nIndex )
    , mbUndo( true )
{
    maColumns.swap( aNewCols );
    maCells.swap( aCells );
@@ -346,9 +346,9 @@ void RemoveColUndo::Redo()


TableColumnUndo::TableColumnUndo( const TableColumnRef& xCol )
:   SdrUndoAction(xCol->mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject())
    ,mxCol( xCol )
    ,mbHasRedoData( false )
    : SdrUndoAction( *xCol->mxTableModel->getSdrTableObj()->GetModel() )
    , mxCol( xCol )
    , mbHasRedoData( false )
{
    getData( maUndoData );
}
@@ -412,7 +412,7 @@ void TableColumnUndo::getData( Data& rData )


TableRowUndo::TableRowUndo( const TableRowRef& xRow )
:   SdrUndoAction(xRow->mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject())
    : SdrUndoAction( *xRow->mxTableModel->getSdrTableObj()->GetModel() )
    , mxRow( xRow )
    , mbHasRedoData( false )
{
@@ -475,9 +475,9 @@ void TableRowUndo::getData( Data& rData )


TableStyleUndo::TableStyleUndo( const SdrTableObj& rTableObj )
:   SdrUndoAction(rTableObj.getSdrModelFromSdrObject())
    ,mxObjRef( const_cast< sdr::table::SdrTableObj*>( &rTableObj ) )
    ,mbHasRedoData(false)
    : SdrUndoAction( *rTableObj.GetModel() )
    , mxObjRef( const_cast< sdr::table::SdrTableObj*>( &rTableObj ) )
    , mbHasRedoData(false)
{
    getData( maUndoData );
}
diff --git a/svx/source/tbxctrls/fontworkgallery.cxx b/svx/source/tbxctrls/fontworkgallery.cxx
index 1dadd49..cca40d2 100644
--- a/svx/source/tbxctrls/fontworkgallery.cxx
+++ b/svx/source/tbxctrls/fontworkgallery.cxx
@@ -197,8 +197,7 @@ void FontWorkGalleryDialog::insertSelectedFontwork()
            SdrPage* pPage = pModel->GetPage(0);
            if( pPage && pPage->GetObjCount() )
            {
                // Clone directly to target SdrModel
                SdrObject* pNewObject(pPage->GetObj(0)->Clone(mpDestModel));
                SdrObject* pNewObject = pPage->GetObj(0)->Clone();

                // center shape on current view
                OutputDevice* pOutDev = mpSdrView->GetFirstOutputDevice();
@@ -211,15 +210,16 @@ void FontWorkGalleryDialog::insertSelectedFontwork()
                    aPagePos.AdjustY( -(aObjRect.GetHeight() / 2) );
                    tools::Rectangle aNewObjectRectangle(aPagePos, aObjRect.GetSize());
                    SdrPageView* pPV = mpSdrView->GetSdrPageView();
                    pNewObject->SetLogicRect(aNewObjectRectangle);

                    pNewObject->SetLogicRect(aNewObjectRectangle);
                    if ( mppSdrObject )
                    {
                        *mppSdrObject = pNewObject;
                        (*mppSdrObject)->SetModel( mpDestModel );
                    }
                    else if( pPV )
                    {
                        mpSdrView->InsertObjectAtView( pNewObject, *pPV );
                            mpSdrView->InsertObjectAtView( pNewObject, *pPV );
                    }
                }
            }
diff --git a/svx/source/unodraw/UnoGraphicExporter.cxx b/svx/source/unodraw/UnoGraphicExporter.cxx
index a70c99a..9fb0d02 100644
--- a/svx/source/unodraw/UnoGraphicExporter.cxx
+++ b/svx/source/unodraw/UnoGraphicExporter.cxx
@@ -108,21 +108,24 @@ namespace {
        Fraction    maScaleX;
        Fraction    maScaleY;

        explicit ExportSettings(const SdrModel& rSdrModel);
        explicit ExportSettings( SdrModel const * pDoc );
    };

    ExportSettings::ExportSettings(const SdrModel& rSdrModel)
    :   mnWidth( 0 )
        ,mnHeight( 0 )
        ,mbExportOnlyBackground( false )
        ,mbScrollText( false )
        ,mbUseHighContrast( false )
        ,mbTranslucent( false )
        ,maScaleX( 1, 1 )
        ,maScaleY( 1, 1 )
    ExportSettings::ExportSettings( SdrModel const * pDoc )
    : mnWidth( 0 )
    , mnHeight( 0 )
    , mbExportOnlyBackground( false )
    , mbScrollText( false )
    , mbUseHighContrast( false )
    , mbTranslucent( false )
    , maScaleX( 1, 1 )
    , maScaleY( 1, 1 )
    {
        maScaleX = rSdrModel.GetScaleFraction();
        maScaleY = rSdrModel.GetScaleFraction();
        if( pDoc )
        {
            maScaleX = pDoc->GetScaleFraction();
            maScaleY = pDoc->GetScaleFraction();
        }
    }

    /** implements a component to export shapes or pages to external graphic formats.
@@ -418,15 +421,13 @@ VclPtr<VirtualDevice> GraphicExporter::CreatePageVDev( SdrPage* pPage, sal_uIntP

    if(bSuccess)
    {
        std::unique_ptr<SdrView> pView(new SdrView(*mpDoc, pVDev));

        std::unique_ptr<SdrView> pView(new SdrView(mpDoc, pVDev));
        pView->SetPageVisible( false );
        pView->SetBordVisible( false );
        pView->SetGridVisible( false );
        pView->SetHlplVisible( false );
        pView->SetGlueVisible( false );
        pView->ShowSdrPage(pPage);

        vcl::Region aRegion (tools::Rectangle( aPoint, aPageSize ) );

        ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage );
@@ -630,9 +631,7 @@ bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGr

            if(pCorrectProperties)
            {
                pTempBackgroundShape = new SdrRectObj(
                    *mpDoc,
                    tools::Rectangle(Point(0,0), pPage->GetSize()));
                pTempBackgroundShape = new SdrRectObj(tools::Rectangle(Point(0,0), pPage->GetSize()));
                pTempBackgroundShape->SetMergedItemSet(pCorrectProperties->GetItemSet());
                pTempBackgroundShape->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE));
                pTempBackgroundShape->NbcSetStyleSheet(pCorrectProperties->GetStyleSheet(), true);
@@ -684,14 +683,13 @@ bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGr
                }

                std::unique_ptr<SdrView> xLocalView;

                if (FmFormModel* pFormModel = dynamic_cast<FmFormModel*>(mpDoc))
                {
                    xLocalView.reset(new FmFormView(*pFormModel, aVDev));
                    xLocalView.reset(new FmFormView(pFormModel, aVDev) );
                }
                else
                {
                    xLocalView.reset(new SdrView(*mpDoc, aVDev));
                    xLocalView.reset(new SdrView(mpDoc, aVDev));
                }

                ScopedVclPtr<VirtualDevice> pVDev(CreatePageVDev( pPage, nWidthPix, nHeightPix ));
@@ -717,14 +715,13 @@ bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGr

                // create a view
                std::unique_ptr< SdrView > pView;

                if (FmFormModel *pFormModel = dynamic_cast<FmFormModel*>(mpDoc))
                {
                    pView.reset(new FmFormView(*pFormModel, aVDev));
                    pView.reset(new FmFormView(pFormModel, aVDev));
                }
                else
                {
                    pView.reset(new SdrView(*mpDoc, aVDev));
                    pView.reset(new SdrView( mpDoc, aVDev ));
                }

                pView->SetBordVisible( false );
@@ -1000,8 +997,8 @@ sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDes
    GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();

    // get the arguments from the descriptor
    ExportSettings aSettings(*mpDoc);
    ParseSettings(aDescriptor, aSettings);
    ExportSettings aSettings( mpDoc );
    ParseSettings( aDescriptor, aSettings );

    const sal_uInt16    nFilter = !aSettings.maMediaType.isEmpty()
                            ? rFilter.GetExportFormatNumberForMediaType( aSettings.maMediaType )
@@ -1139,7 +1136,7 @@ void SAL_CALL GraphicExporter::setSourceDocument( const Reference< lang::XCompon
        if( nullptr == mpUnoPage || nullptr == mpUnoPage->GetSdrPage() )
            break;

        mpDoc = &mpUnoPage->GetSdrPage()->getSdrModelFromSdrPage();
        mpDoc = mpUnoPage->GetSdrPage()->GetModel();

        // Step 4:  If we got a generic XShapes test all contained shapes
        //          if they belong to the same XDrawPage
@@ -1249,7 +1246,7 @@ Graphic SvxGetGraphicForShape( SdrObject& rShape )
        rtl::Reference< GraphicExporter > xExporter( new GraphicExporter() );
        Reference< XComponent > xComp( rShape.getUnoShape(), UNO_QUERY_THROW );
        xExporter->setSourceDocument( xComp );
        ExportSettings aSettings(rShape.getSdrModelFromSdrObject());
        ExportSettings aSettings( rShape.GetModel() );
        xExporter->GetGraphic( aSettings, aGraphic, true/*bVector*/ );
    }
    catch( Exception& )
diff --git a/svx/source/unodraw/tableshape.cxx b/svx/source/unodraw/tableshape.cxx
index 281dfa2..a348156 100644
--- a/svx/source/unodraw/tableshape.cxx
+++ b/svx/source/unodraw/tableshape.cxx
@@ -59,8 +59,8 @@ bool SvxTableShape::setPropertyValueImpl(
        if( !(rValue >>= xTemplate) )
            throw IllegalArgumentException();

        if( HasSdrObject() )
            static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->setTableStyle(xTemplate);
        if( mpObj.is() )
            static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->setTableStyle(xTemplate);

        return true;
    }
@@ -71,9 +71,9 @@ bool SvxTableShape::setPropertyValueImpl(
    case OWN_ATTR_TABLETEMPLATE_BANDINGROWS:
    case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:
    {
        if( HasSdrObject() )
        if( mpObj.is() )
        {
            TableStyleSettings aSettings( static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->getTableStyleSettings() );
            TableStyleSettings aSettings( static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTableStyleSettings() );

            switch( pProperty->nWID )
            {
@@ -85,7 +85,7 @@ bool SvxTableShape::setPropertyValueImpl(
            case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:    rValue >>= aSettings.mbUseColumnBanding; break;
            }

            static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->setTableStyleSettings(aSettings);
            static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->setTableStyleSettings(aSettings);
        }

        return true;
@@ -106,25 +106,25 @@ bool SvxTableShape::getPropertyValueImpl(
    {
    case OWN_ATTR_OLEMODEL:
    {
        if( HasSdrObject() )
        if( mpObj.is() )
        {
            rValue <<= static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->getTable();
            rValue <<= static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTable();
        }
        return true;
    }
    case OWN_ATTR_TABLETEMPLATE:
    {
        if( HasSdrObject() )
        if( mpObj.is() )
        {
            rValue <<= static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->getTableStyle();
            rValue <<= static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTableStyle();
        }
        return true;
    }
    case OWN_ATTR_BITMAP:
    {
        if( HasSdrObject() )
        if( mpObj.is() )
        {
            Graphic aGraphic( SvxGetGraphicForShape( *GetSdrObject() ) );
            Graphic aGraphic( SvxGetGraphicForShape( *mpObj.get() ) );
            rValue <<= aGraphic.GetXGraphic();
        }
        return true;
@@ -136,9 +136,9 @@ bool SvxTableShape::getPropertyValueImpl(
    case OWN_ATTR_TABLETEMPLATE_BANDINGROWS:
    case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:
    {
        if( HasSdrObject() )
        if( mpObj.is() )
        {
            TableStyleSettings aSettings( static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->getTableStyleSettings() );
            TableStyleSettings aSettings( static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTableStyleSettings() );

            switch( pProperty->nWID )
            {
@@ -163,14 +163,14 @@ bool SvxTableShape::getPropertyValueImpl(
void SvxTableShape::lock()
{
    SvxShape::lock();
    if( HasSdrObject() )
        static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->uno_lock();
    if( mpObj.is() )
        static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->uno_lock();
}

void SvxTableShape::unlock()
{
    if( HasSdrObject() )
        static_cast< sdr::table::SdrTableObj* >( GetSdrObject() )->uno_unlock();
    if( mpObj.is() )
        static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->uno_unlock();
    SvxShape::unlock();
}

diff --git a/svx/source/unodraw/unomod.cxx b/svx/source/unodraw/unomod.cxx
index dd1d131..4f0ea1f 100644
--- a/svx/source/unodraw/unomod.cxx
+++ b/svx/source/unodraw/unomod.cxx
@@ -246,26 +246,8 @@ uno::Sequence< OUString > SvxUnoDrawMSFactory::concatServiceNames( uno::Sequence
    return aSeq;
}

SdrModel* SvxUnoDrawingModel::getSdrModelFromUnoModel() const
{
    return mpDoc;
}

SvxUnoDrawingModel::SvxUnoDrawingModel(SdrModel* pDoc) throw()
:   SfxBaseModel(nullptr),
    SvxFmMSFactory(),
    css::drawing::XDrawPagesSupplier(),
    css::lang::XServiceInfo(),
    css::ucb::XAnyCompareFactory(),
    mpDoc(pDoc),
    mxDrawPagesAccess(),
    mxDashTable(),
    mxGradientTable(),
    mxHatchTable(),
    mxBitmapTable(),
    mxTransGradientTable(),
    mxMarkerTable(),
    maTypeSequence()
SvxUnoDrawingModel::SvxUnoDrawingModel( SdrModel* pDoc ) throw()
: SfxBaseModel(nullptr), mpDoc( pDoc )
{
}

diff --git a/svx/source/unodraw/unopage.cxx b/svx/source/unodraw/unopage.cxx
index 3dc69e8..d7f14d3 100644
--- a/svx/source/unodraw/unopage.cxx
+++ b/svx/source/unodraw/unopage.cxx
@@ -61,11 +61,12 @@ using namespace ::com::sun::star::drawing;

UNO3_GETIMPLEMENTATION_IMPL( SvxDrawPage );

SvxDrawPage::SvxDrawPage(SdrPage* pInPage) // TTTT should be reference
:   mrBHelper(getMutex())
    ,mpPage(pInPage)
    ,mpModel(&pInPage->getSdrModelFromSdrPage())  // register at broadcaster
    ,mpView(new SdrView(pInPage->getSdrModelFromSdrPage())) // create (hidden) view
SvxDrawPage::SvxDrawPage(SdrPage* pInPage)
    : mrBHelper(getMutex())
    , mpPage(pInPage)
    , mpModel(mpPage->GetModel())  // register at broadcaster
    , mpView(new SdrView(mpModel)) // create (hidden) view

{
    mpView->SetDesignMode();
}
@@ -191,24 +192,6 @@ void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape 
        return;

    SdrObject *pObj = pShape->GetSdrObject();
    bool bNeededToClone(false);

    if(nullptr != pObj && &pObj->getSdrModelFromSdrObject() != &mpPage->getSdrModelFromSdrPage())
    {
        // TTTT UNO API tries to add an existing SvxShape to this SvxDrawPage,
        // but these use different SdrModels. It was possible before to completely
        // 'change' a SdrObject to another SdrModel (including dangerous MigrateItemPool
        // stuff), but is no longer. We need to Clone the SdrObject to the target model
        // and ::Create a new SvxShape (set SdrObject there, take obver values, ...)
        SdrObject* pClonedSdrShape(pObj->Clone(&mpPage->getSdrModelFromSdrPage()));
        pObj->setUnoShape(nullptr);
        pClonedSdrShape->setUnoShape(xShape);
        // pShape->InvalidateSdrObject();
        // pShape->Create(pClonedSdrShape, this);
        SdrObject::Free(pObj);
        pObj = pClonedSdrShape;
        bNeededToClone = true;
    }

    if(!pObj)
    {
@@ -217,20 +200,8 @@ void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape 
    }
    else if ( !pObj->IsInserted() )
    {
        pObj->SetModel(mpModel);
        mpPage->InsertObject( pObj );

        if(bNeededToClone)
        {
            // TTTT Unfortunately in SdrObject::SetPage (see there) the
            // xShape/UnoShape at the newly cloned SDrObject is *removed* again,
            // so re-set it here, the caller *may need it* (e.g. Writer)
            uno::Reference< uno::XInterface > xShapeCheck(pObj->getWeakUnoShape());

            if( !xShapeCheck.is() )
            {
                pObj->setUnoShape(xShape);
            }
        }
    }

    pShape->Create( pObj, this );
@@ -238,6 +209,7 @@ void SAL_CALL SvxDrawPage::add( const uno::Reference< drawing::XShape >& xShape 

    if ( !pObj->IsInserted() )
    {
        pObj->SetModel(mpModel);
        mpPage->InsertObject( pObj );
    }

@@ -270,6 +242,7 @@ void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& x
    }
    else if ( !pObj->IsInserted() )
    {
        pObj->SetModel(mpModel);
        mpPage->InsertObject( pObj, 0 );
    }

@@ -278,6 +251,7 @@ void SAL_CALL SvxDrawPage::addBottom( const uno::Reference< drawing::XShape >& x

    if ( !pObj->IsInserted() )
    {
        pObj->SetModel(mpModel);
        mpPage->InsertObject( pObj, 0 );
    }

@@ -491,7 +465,7 @@ void SAL_CALL SvxDrawPage::ungroup( const Reference< drawing::XShapeGroup >& aGr
        mpModel->SetChanged();
}

SdrObject* SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
SdrObject *SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xShape)
{
    sal_uInt16 nType = 0;
    SdrInventor nInventor;
@@ -506,13 +480,7 @@ SdrObject* SvxDrawPage::CreateSdrObject_(const Reference< drawing::XShape > & xS
    awt::Point aPos = xShape->getPosition();
    tools::Rectangle aRect( Point( aPos.X, aPos.Y ), Size( aSize.Width, aSize.Height ) );

    SdrObject* pNewObj = SdrObjFactory::MakeNewObject(
        *mpModel,
        nInventor,
        nType,
        mpPage,
        &aRect);

    SdrObject* pNewObj = SdrObjFactory::MakeNewObject(nInventor, nType, aRect, mpPage);
    if (!pNewObj)
        return nullptr;

@@ -712,37 +680,39 @@ SvxShape* SvxDrawPage::CreateShapeByTypeAndInventor( sal_uInt16 nType, SdrInvent
                            SdrPage* pSdrPage = mpPage->GetSdrPage();
                            if( pSdrPage )
                            {
                                SdrModel& rSdrModel(pSdrPage->getSdrModelFromSdrPage());
                                ::comphelper::IEmbeddedHelper *pPersist = rSdrModel.GetPersist();

                                if( pPersist )
                                SdrModel* pSdrModel = pSdrPage->GetModel();
                                if( pSdrModel )
                                {
                                    uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
                                            GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );

                                    // TODO CL->KA: Why is this not working anymore?
                                    if( xObject.is() )
                                    ::comphelper::IEmbeddedHelper *pPersist = pSdrModel->GetPersist();
                                    if( pPersist )
                                    {
                                        SvGlobalName aClassId( xObject->getClassID() );
                                        uno::Reference < embed::XEmbeddedObject > xObject = pPersist->getEmbeddedObjectContainer().
                                                GetEmbeddedObject( static_cast< SdrOle2Obj* >( pObj )->GetPersistName() );

                                        const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
                                        const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
                                        const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
                                        // TODO CL->KA: Why is this not working anymore?
                                        if( xObject.is() )
                                        {
                                            SvGlobalName aClassId( xObject->getClassID() );

                                        if( aPluginClassId == aClassId )
                                        {
                                            pRet = new SvxPluginShape( pObj );
                                            nType = OBJ_OLE2_PLUGIN;
                                        }
                                        else if( aAppletClassId == aClassId )
                                        {
                                            pRet = new SvxAppletShape( pObj );
                                            nType = OBJ_OLE2_APPLET;
                                        }
                                        else if( aIFrameClassId == aClassId )
                                        {
                                            pRet = new SvxFrameShape( pObj );
                                            nType = OBJ_FRAME;
                                            const SvGlobalName aAppletClassId( SO3_APPLET_CLASSID );
                                            const SvGlobalName aPluginClassId( SO3_PLUGIN_CLASSID );
                                            const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );

                                            if( aPluginClassId == aClassId )
                                            {
                                                pRet = new SvxPluginShape( pObj );
                                                nType = OBJ_OLE2_PLUGIN;
                                            }
                                            else if( aAppletClassId == aClassId )
                                            {
                                                pRet = new SvxAppletShape( pObj );
                                                nType = OBJ_OLE2_APPLET;
                                            }
                                            else if( aIFrameClassId == aClassId )
                                            {
                                                pRet = new SvxFrameShape( pObj );
                                                nType = OBJ_FRAME;
                                            }
                                        }
                                    }
                                }
@@ -842,6 +812,7 @@ SdrObject *SvxDrawPage::CreateSdrObject( const Reference< drawing::XShape > & xS
    SdrObject* pObj = CreateSdrObject_( xShape );
    if( pObj)
    {
        pObj->SetModel(mpModel);
        if ( !pObj->IsInserted() && !pObj->IsDoNotInsertIntoPageAutomatically() )
        {
            if(bBeginning)
@@ -876,6 +847,21 @@ SvxShape* CreateSvxShapeByTypeAndInventor(sal_uInt16 nType, SdrInventor nInvento
    return SvxDrawPage::CreateShapeByTypeAndInventor( nType, nInventor, nullptr, nullptr, referer );
}

void SvxDrawPage::ChangeModel( SdrModel* pNewModel )
{
    if( pNewModel != mpModel )
    {
        mpModel = pNewModel;

        if( mpView )
        {
            delete mpView;
            mpView = new SdrView( mpModel );
            mpView->SetDesignMode();
        }
    }
}

/** returns a StarOffice API wrapper for the given SdrPage */
uno::Reference< drawing::XDrawPage > GetXDrawPageForSdrPage( SdrPage* pPage ) throw ()
{
diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx
index 3410663..8c5fc28 100644
--- a/svx/source/unodraw/unoshap2.cxx
+++ b/svx/source/unodraw/unoshap2.cxx
@@ -181,7 +181,7 @@ void SAL_CALL SvxShapeGroup::leaveGroup(  )

void SvxShapeGroup::addUnoShape( const uno::Reference< drawing::XShape >& xShape, size_t nPos )
{
    if (!HasSdrObject() || !mxPage.is())
    if (!mpObj.is() || !mxPage.is())
    {
        OSL_FAIL("could not add XShape to group shape!");
        return;
@@ -201,10 +201,8 @@ void SvxShapeGroup::addUnoShape( const uno::Reference< drawing::XShape >& xShape
    if( pSdrShape->IsInserted() )
        pSdrShape->GetObjList()->RemoveObject( pSdrShape->GetOrdNum() );

    GetSdrObject()->GetSubList()->InsertObject(pSdrShape, nPos);
    // TTTT Was created using mpModel in CreateSdrObject_ above
    // TTTT may be good to add a assertion here for the future
    // pSdrShape->SetModel(GetSdrObject()->GetModel());
    mpObj->GetSubList()->InsertObject(pSdrShape, nPos);
    pSdrShape->SetModel(mpObj->GetModel());

    // #85922# It makes no sense to set the layer asked
    // from the group object since these is an iteration
@@ -219,7 +217,8 @@ void SvxShapeGroup::addUnoShape( const uno::Reference< drawing::XShape >& xShape
    // would be created when this connection would not already exist.
    pShape->Create( pSdrShape, mxPage.get() );

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}

// XShapes
@@ -242,7 +241,7 @@ void SAL_CALL SvxShapeGroup::remove( const uno::Reference< drawing::XShape >& xS
    if( pShape )
        pSdrShape = pShape->GetSdrObject();

    if( !HasSdrObject() || pSdrShape == nullptr || pSdrShape->GetObjList()->GetOwnerObj() != GetSdrObject() )
    if( !mpObj.is() || pSdrShape == nullptr || pSdrShape->GetObjList()->GetOwnerObj() != mpObj.get() )
        throw uno::RuntimeException();

    SdrObjList& rList = *pSdrShape->GetObjList();
@@ -279,7 +278,8 @@ void SAL_CALL SvxShapeGroup::remove( const uno::Reference< drawing::XShape >& xS
        SAL_WARN( "svx", "Fatality! SdrObject is not belonging to its SdrObjList! [CL]" );
    }

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}

void SAL_CALL SvxShapeGroup::addTop( const uno::Reference< drawing::XShape >& xShape )
@@ -305,10 +305,10 @@ sal_Int32 SAL_CALL SvxShapeGroup::getCount()
{
    ::SolarMutexGuard aGuard;

    if(!HasSdrObject() || !GetSdrObject()->GetSubList())
    if(!mpObj.is() || !mpObj->GetSubList())
        throw uno::RuntimeException();

    sal_Int32 nRetval = GetSdrObject()->GetSubList()->GetObjCount();
    sal_Int32 nRetval = mpObj->GetSubList()->GetObjCount();
    return nRetval;
}

@@ -317,13 +317,13 @@ uno::Any SAL_CALL SvxShapeGroup::getByIndex( sal_Int32 Index )
{
    ::SolarMutexGuard aGuard;

    if( !HasSdrObject() || GetSdrObject()->GetSubList() == nullptr )
    if( !mpObj.is() || mpObj->GetSubList() == nullptr )
        throw uno::RuntimeException();

    if( Index<0 || GetSdrObject()->GetSubList()->GetObjCount() <= static_cast<size_t>(Index) )
    if( Index<0 || mpObj->GetSubList()->GetObjCount() <= static_cast<size_t>(Index) )
        throw lang::IndexOutOfBoundsException();

    SdrObject* pDestObj = GetSdrObject()->GetSubList()->GetObj( Index );
    SdrObject* pDestObj = mpObj->GetSubList()->GetObj( Index );

    if(pDestObj == nullptr)
        throw lang::IndexOutOfBoundsException();
@@ -345,7 +345,7 @@ sal_Bool SAL_CALL SvxShapeGroup::hasElements()
{
    ::SolarMutexGuard aGuard;

    return HasSdrObject() && GetSdrObject()->GetSubList() && (GetSdrObject()->GetSubList()->GetObjCount() > 0);
    return mpObj.is() && mpObj->GetSubList() && (mpObj->GetSubList()->GetObjCount() > 0);
}

SvxShapeConnector::SvxShapeConnector(SdrObject* pObj)
@@ -438,9 +438,10 @@ void SAL_CALL SvxShapeConnector::connectStart( const uno::Reference< drawing::XC
    SvxShape* pShape = SvxShape::getImplementation( xRef );

    if( pShape )
        GetSdrObject()->ConnectToNode( true, pShape->GetSdrObject() );
        mpObj->ConnectToNode( true, pShape->mpObj.get() );

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}


@@ -451,10 +452,11 @@ void SAL_CALL SvxShapeConnector::connectEnd( const uno::Reference< drawing::XCon
    Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
    SvxShape* pShape = SvxShape::getImplementation( xRef );

    if( HasSdrObject() && pShape )
        GetSdrObject()->ConnectToNode( false, pShape->GetSdrObject() );
    if( mpObj.is() && pShape )
        mpObj->ConnectToNode( false, pShape->mpObj.get() );

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}


@@ -462,10 +464,11 @@ void SAL_CALL SvxShapeConnector::disconnectBegin( const uno::Reference< drawing:
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
        GetSdrObject()->DisconnectFromNode( true );
    if(mpObj.is())
        mpObj->DisconnectFromNode( true );

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}


@@ -473,10 +476,11 @@ void SAL_CALL SvxShapeConnector::disconnectEnd( const uno::Reference< drawing::X
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
        GetSdrObject()->DisconnectFromNode( false );
    if(mpObj.is())
        mpObj->DisconnectFromNode( false );

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}

SvxShapeControl::SvxShapeControl(SdrObject* pObj)
@@ -568,7 +572,7 @@ Reference< awt::XControlModel > SAL_CALL SvxShapeControl::getControl()

    Reference< awt::XControlModel > xModel;

    SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(GetSdrObject());
    SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(mpObj.get());
    if( pUnoObj )
        xModel = pUnoObj->GetUnoControlModel();

@@ -580,11 +584,12 @@ void SAL_CALL SvxShapeControl::setControl( const Reference< awt::XControlModel >
{
    ::SolarMutexGuard aGuard;

    SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(GetSdrObject());
    SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(mpObj.get());
    if( pUnoObj )
        pUnoObj->SetUnoControlModel( xControl );

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}

static struct
@@ -978,14 +983,14 @@ bool SvxShapePolyPolygon::setPropertyValueImpl( const OUString& rName, const Sfx
    {
        if( auto s = o3tl::tryAccess<drawing::PointSequenceSequence>(rValue) )
        {
            if( HasSdrObject() )
            if( mpObj.is() )
            {
                basegfx::B2DPolyPolygon aNewPolyPolygon;
                basegfx::B2DHomMatrix aNewHomogenMatrix;

                GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
                mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
                aNewPolyPolygon = ImplSvxPointSequenceSequenceToB2DPolyPolygon(s);
                GetSdrObject()->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
                mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
            }
            return true;
        }
@@ -1088,8 +1093,8 @@ bool SvxShapePolyPolygon::getPropertyValueImpl( const OUString& rName, const Sfx
        basegfx::B2DPolyPolygon aNewPolyPolygon;
        basegfx::B2DHomMatrix aNewHomogenMatrix;

        if(HasSdrObject())
            GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
        if(mpObj.is())
            mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);

        drawing::PointSequenceSequence aRetval(aNewPolyPolygon.count());
        B2DPolyPolygonToSvxPointSequenceSequence(aNewPolyPolygon, aRetval);
@@ -1142,8 +1147,8 @@ void SvxShapePolyPolygon::SetPolygon(const basegfx::B2DPolyPolygon& rNew)
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
        static_cast<SdrPathObj*>(GetSdrObject())->SetPathPoly(rNew);
    if(mpObj.is())
        static_cast<SdrPathObj*>(mpObj.get())->SetPathPoly(rNew);
}


@@ -1151,9 +1156,9 @@ basegfx::B2DPolyPolygon SvxShapePolyPolygon::GetPolygon() const throw()
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
    if(mpObj.is())
    {
        return static_cast<SdrPathObj*>(GetSdrObject())->GetPathPoly();
        return static_cast<SdrPathObj*>(mpObj.get())->GetPathPoly();
    }
    else
    {
@@ -1190,15 +1195,15 @@ bool SvxShapePolyPolygonBezier::setPropertyValueImpl( const OUString& rName, con
    {
        if( auto s = o3tl::tryAccess<drawing::PolyPolygonBezierCoords>(rValue) )
        {
            if( HasSdrObject() )
            if( mpObj.is() )
            {
                basegfx::B2DPolyPolygon aNewPolyPolygon;
                basegfx::B2DHomMatrix aNewHomogenMatrix;

                GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
                mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
                aNewPolyPolygon = basegfx::unotools::polyPolygonBezierToB2DPolyPolygon(
                    *s);
                GetSdrObject()->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
                mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
            }
            return true;
        }
@@ -1231,7 +1236,7 @@ bool SvxShapePolyPolygonBezier::getPropertyValueImpl( const OUString& rName, con
        // pack a tools::PolyPolygon in a struct tools::PolyPolygon
        basegfx::B2DPolyPolygon aNewPolyPolygon;
        basegfx::B2DHomMatrix aNewHomogenMatrix;
        GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
        mpObj.get()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
        drawing::PolyPolygonBezierCoords aRetval;
        basegfx::unotools::b2DPolyPolygonToPolyPolygonBezier(aNewPolyPolygon, aRetval);

@@ -1254,8 +1259,8 @@ void SvxShapePolyPolygonBezier::SetPolygon(const basegfx::B2DPolyPolygon& rNew)
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
        static_cast<SdrPathObj*>(GetSdrObject())->SetPathPoly(rNew);
    if(mpObj.is())
        static_cast<SdrPathObj*>(mpObj.get())->SetPathPoly(rNew);
}


@@ -1263,9 +1268,9 @@ basegfx::B2DPolyPolygon SvxShapePolyPolygonBezier::GetPolygon() const throw()
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
    if(mpObj.is())
    {
        return static_cast<SdrPathObj*>(GetSdrObject())->GetPathPoly();
        return static_cast<SdrPathObj*>(mpObj.get())->GetPathPoly();
    }
    else
    {
@@ -1298,7 +1303,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte

            if( GraphicConverter::Import( aMemStm, aGraphic ) == ERRCODE_NONE )
            {
                static_cast<SdrGrafObj*>(GetSdrObject())->SetGraphic(aGraphic);
                static_cast<SdrGrafObj*>(mpObj.get())->SetGraphic(aGraphic);
                bOk = true;
            }
        }
@@ -1307,7 +1312,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
            auto xGraphic = rValue.get<uno::Reference<graphic::XGraphic>>();
            if (xGraphic.is())
            {
                static_cast<SdrGrafObj*>(GetSdrObject())->SetGraphic(Graphic(xGraphic));
                static_cast<SdrGrafObj*>(mpObj.get())->SetGraphic(Graphic(xGraphic));
                bOk = true;
            }
        }
@@ -1318,7 +1323,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
            {
                uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY);
                Graphic aGraphic(xGraphic);
                static_cast<SdrGrafObj*>(GetSdrObject())->SetGraphic(aGraphic);
                static_cast<SdrGrafObj*>(mpObj.get())->SetGraphic(aGraphic);
                bOk = true;
            }
        }
@@ -1334,9 +1339,9 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
            if( !aStreamURL.startsWith( UNO_NAME_GRAPHOBJ_URLPKGPREFIX ) )
                aStreamURL.clear();

            if( HasSdrObject() )
            if( mpObj.is() )
            {
                static_cast<SdrGrafObj*>(GetSdrObject())->SetGrafStreamURL( aStreamURL );
                static_cast<SdrGrafObj*>(mpObj.get())->SetGrafStreamURL( aStreamURL );
            }
            bOk = true;
        }
@@ -1348,7 +1353,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
        if( xGraphic.is() )
        {
            static_cast< SdrGrafObj*>( GetSdrObject() )->SetGraphic( xGraphic );
            static_cast< SdrGrafObj*>( mpObj.get() )->SetGraphic( xGraphic );
            bOk = true;
        }
        break;
@@ -1359,7 +1364,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        bool bIsSignatureLine;
        if (rValue >>= bIsSignatureLine)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setIsSignatureLine(bIsSignatureLine);
            static_cast<SdrGrafObj*>(mpObj.get())->setIsSignatureLine(bIsSignatureLine);
            bOk = true;
        }
        break;
@@ -1370,7 +1375,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        OUString aSignatureLineId;
        if (rValue >>= aSignatureLineId)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineId(aSignatureLineId);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineId(aSignatureLineId);
            bOk = true;
        }
        break;
@@ -1381,7 +1386,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        OUString aSuggestedSignerName;
        if (rValue >>= aSuggestedSignerName)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineSuggestedSignerName(aSuggestedSignerName);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineSuggestedSignerName(aSuggestedSignerName);
            bOk = true;
        }
        break;
@@ -1392,7 +1397,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        OUString aSuggestedSignerTitle;
        if (rValue >>= aSuggestedSignerTitle)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineSuggestedSignerTitle(aSuggestedSignerTitle);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineSuggestedSignerTitle(aSuggestedSignerTitle);
            bOk = true;
        }
        break;
@@ -1403,7 +1408,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        OUString aSuggestedSignerEmail;
        if (rValue >>= aSuggestedSignerEmail)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineSuggestedSignerEmail(aSuggestedSignerEmail);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineSuggestedSignerEmail(aSuggestedSignerEmail);
            bOk = true;
        }
        break;
@@ -1414,7 +1419,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        OUString aSigningInstructions;
        if (rValue >>= aSigningInstructions)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineSigningInstructions(aSigningInstructions);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineSigningInstructions(aSigningInstructions);
            bOk = true;
        }
        break;
@@ -1425,7 +1430,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        bool bShowSignDate;
        if (rValue >>= bShowSignDate)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineShowSignDate(bShowSignDate);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineShowSignDate(bShowSignDate);
            bOk = true;
        }
        break;
@@ -1436,7 +1441,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        bool bCanAddComment;
        if (rValue >>= bCanAddComment)
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineCanAddComment(bCanAddComment);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineCanAddComment(bCanAddComment);
            bOk = true;
        }
        break;
@@ -1447,7 +1452,7 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
        Reference<graphic::XGraphic> xGraphic(rValue, uno::UNO_QUERY);
        if (xGraphic.is())
        {
            static_cast<SdrGrafObj*>(GetSdrObject())->setSignatureLineUnsignedGraphic(xGraphic);
            static_cast<SdrGrafObj*>(mpObj.get())->setSignatureLineUnsignedGraphic(xGraphic);
            bOk = true;
        }
        break;
@@ -1460,7 +1465,8 @@ bool SvxGraphicObject::setPropertyValueImpl( const OUString& rName, const SfxIte
    if( !bOk )
        throw lang::IllegalArgumentException();

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();

    return true;
}
@@ -1471,7 +1477,7 @@ bool SvxGraphicObject::getPropertyValueImpl( const OUString& rName, const SfxIte
    {
    case OWN_ATTR_VALUE_FILLBITMAP:
    {
        const Graphic& rGraphic = static_cast<SdrGrafObj*>(GetSdrObject())->GetGraphic();
        const Graphic& rGraphic = static_cast<SdrGrafObj*>(mpObj.get())->GetGraphic();

        if (rGraphic.GetType() != GraphicType::GdiMetafile)
        {
@@ -1493,7 +1499,7 @@ bool SvxGraphicObject::getPropertyValueImpl( const OUString& rName, const SfxIte

    case OWN_ATTR_REPLACEMENT_GRAPHIC:
    {
        const GraphicObject* pGrafObj = static_cast< SdrGrafObj* >(GetSdrObject())->GetReplacementGraphicObject();
        const GraphicObject* pGrafObj = static_cast< SdrGrafObj* >(mpObj.get())->GetReplacementGraphicObject();

        if (pGrafObj)
        {
@@ -1505,7 +1511,7 @@ bool SvxGraphicObject::getPropertyValueImpl( const OUString& rName, const SfxIte

    case OWN_ATTR_GRAFSTREAMURL:
    {
        const OUString  aStreamURL( static_cast<SdrGrafObj*>( GetSdrObject() )->GetGrafStreamURL() );
        const OUString  aStreamURL( static_cast<SdrGrafObj*>( mpObj.get() )->GetGrafStreamURL() );
        if( !aStreamURL.isEmpty() )
            rValue <<= aStreamURL;
        break;
@@ -1514,7 +1520,7 @@ bool SvxGraphicObject::getPropertyValueImpl( const OUString& rName, const SfxIte
    case OWN_ATTR_VALUE_GRAPHIC:
    {
        Reference<graphic::XGraphic> xGraphic;
        auto pSdrGraphicObject = static_cast<SdrGrafObj*>(GetSdrObject());
        auto pSdrGraphicObject = static_cast<SdrGrafObj*>(mpObj.get());
        if (pSdrGraphicObject->GetGraphicObject().GetType() != GraphicType::NONE)
            xGraphic = pSdrGraphicObject->GetGraphic().GetXGraphic();
        rValue <<= xGraphic;
@@ -1523,62 +1529,62 @@ bool SvxGraphicObject::getPropertyValueImpl( const OUString& rName, const SfxIte

    case OWN_ATTR_GRAPHIC_STREAM:
    {
        rValue <<= static_cast< SdrGrafObj* >( GetSdrObject() )->getInputStream();
        rValue <<= static_cast< SdrGrafObj* >( mpObj.get() )->getInputStream();
        break;
    }

    case OWN_ATTR_IS_SIGNATURELINE:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->isSignatureLine();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->isSignatureLine();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_ID:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->getSignatureLineId();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->getSignatureLineId();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_SUGGESTED_SIGNER_NAME:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->getSignatureLineSuggestedSignerName();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->getSignatureLineSuggestedSignerName();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_SUGGESTED_SIGNER_TITLE:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->getSignatureLineSuggestedSignerTitle();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->getSignatureLineSuggestedSignerTitle();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_SUGGESTED_SIGNER_EMAIL:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->getSignatureLineSuggestedSignerEmail();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->getSignatureLineSuggestedSignerEmail();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_SIGNING_INSTRUCTIONS:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->getSignatureLineSigningInstructions();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->getSignatureLineSigningInstructions();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_SHOW_SIGN_DATE:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->isSignatureLineShowSignDate();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->isSignatureLineShowSignDate();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_CAN_ADD_COMMENT:
    {
        rValue <<= static_cast<SdrGrafObj*>(GetSdrObject())->isSignatureLineCanAddComment();
        rValue <<= static_cast<SdrGrafObj*>(mpObj.get())->isSignatureLineCanAddComment();
        break;
    }

    case OWN_ATTR_SIGNATURELINE_UNSIGNED_IMAGE:
    {
        Reference<graphic::XGraphic> xGraphic(
            static_cast<SdrGrafObj*>(GetSdrObject())->getSignatureLineUnsignedGraphic());
            static_cast<SdrGrafObj*>(mpObj.get())->getSignatureLineUnsignedGraphic());
        rValue <<= xGraphic;
        break;
    }
@@ -1649,21 +1655,21 @@ uno::Sequence< sal_Int8 > SAL_CALL SvxCustomShape::getImplementationId()
awt::Point SAL_CALL SvxCustomShape::getPosition()
{
    ::SolarMutexGuard aGuard;
    if ( HasSdrObject() )
    if ( mpModel && mpObj.is() )
    {
        SdrAShapeObjGeoData aCustomShapeGeoData;
        static_cast<SdrObjCustomShape*>(GetSdrObject())->SaveGeoData( aCustomShapeGeoData );
        static_cast<SdrObjCustomShape*>(mpObj.get())->SaveGeoData( aCustomShapeGeoData );

        bool bMirroredX = false;
        bool bMirroredY = false;

        if ( HasSdrObject() )
        if ( mpObj.is() )
        {
            bMirroredX = static_cast<SdrObjCustomShape*>(GetSdrObject())->IsMirroredX();
            bMirroredY = static_cast<SdrObjCustomShape*>(GetSdrObject())->IsMirroredY();
            bMirroredX = static_cast<SdrObjCustomShape*>(mpObj.get())->IsMirroredX();
            bMirroredY = static_cast<SdrObjCustomShape*>(mpObj.get())->IsMirroredY();
        }
        // get aRect, this is the unrotated snaprect
        tools::Rectangle aRect(static_cast<SdrObjCustomShape*>(GetSdrObject())->GetLogicRect());
        tools::Rectangle aRect(static_cast<SdrObjCustomShape*>(mpObj.get())->GetLogicRect());
        tools::Rectangle aRectangle( aRect );

        if ( bMirroredX || bMirroredY )
@@ -1717,8 +1723,8 @@ awt::Point SAL_CALL SvxCustomShape::getPosition()
        }
        Point aPt( aRectangle.TopLeft() );

        if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
            aPt -= GetSdrObject()->GetAnchorPos();
        if( mpModel->IsWriter() )
            aPt -= mpObj->GetAnchorPos();

        ForceMetricTo100th_mm(aPt);
        return css::awt::Point( aPt.X(), aPt.Y() );
@@ -1732,7 +1738,7 @@ void SAL_CALL SvxCustomShape::setPropertyValue( const OUString& aPropertyName, c
{
    ::SolarMutexGuard aGuard;

    SdrObject* pObject = GetSdrObject();
    SdrObject* pObject = mpObj.get();

    // tdf#98163 Use a custom slot to have filter code flush the UNO
    // API implementations of SdrObjCustomShape. Used e.g. by
@@ -1818,7 +1824,7 @@ bool SvxCustomShape::getPropertyValueImpl( const OUString& rName, const SfxItemP
    {
    case SDRATTR_ROTATEANGLE:
    {
        double fAngle = static_cast<SdrObjCustomShape*>(GetSdrObject())->GetObjectRotation();
        double fAngle = static_cast<SdrObjCustomShape*>(mpObj.get())->GetObjectRotation();
        fAngle *= 100;
        rValue <<= static_cast<sal_Int32>(fAngle);
        return true;
@@ -1830,13 +1836,13 @@ bool SvxCustomShape::getPropertyValueImpl( const OUString& rName, const SfxItemP

void SvxCustomShape::createCustomShapeDefaults( const OUString& rValueType )
{
    if (!HasSdrObject())
    if (!mpObj.is())
    {
        OSL_FAIL("could not create Custom Shape Defaults!");
        return;
    }

    static_cast<SdrObjCustomShape*>(GetSdrObject())->MergeDefaultAttributes( &rValueType );
    static_cast<SdrObjCustomShape*>(mpObj.get())->MergeDefaultAttributes( &rValueType );
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/unodraw/unoshap3.cxx b/svx/source/unodraw/unoshap3.cxx
index 663dcc9..66ac52b 100644
--- a/svx/source/unodraw/unoshap3.cxx
+++ b/svx/source/unodraw/unoshap3.cxx
@@ -45,7 +45,6 @@
#include <basegfx/polygon/b3dpolygontools.hxx>
#include <com/sun/star/drawing/PolyPolygonShape3D.hpp>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/matrix/b3dhommatrixtools.hxx>
#include "shapeimpl.hxx"

using namespace ::cppu;
@@ -119,13 +118,13 @@ void SAL_CALL Svx3DSceneObject::add( const Reference< drawing::XShape >& xShape 

    SvxShape* pShape = SvxShape::getImplementation( xShape );

    if(!HasSdrObject() || !mxPage.is() || pShape == nullptr || nullptr != pShape->GetSdrObject() )
    if(!mpObj.is() || !mxPage.is() || pShape == nullptr || nullptr != pShape->GetSdrObject() )
        throw uno::RuntimeException();

    SdrObject* pSdrShape = mxPage->CreateSdrObject_( xShape );
    if( dynamic_cast<const E3dObject* >(pSdrShape) !=  nullptr )
    {
        GetSdrObject()->GetSubList()->NbcInsertObject( pSdrShape );
        mpObj->GetSubList()->NbcInsertObject( pSdrShape );

        if(pShape)
            pShape->Create( pSdrShape, mxPage.get()  );
@@ -136,7 +135,8 @@ void SAL_CALL Svx3DSceneObject::add( const Reference< drawing::XShape >& xShape 
        throw uno::RuntimeException();
    }

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if( mpModel )
        mpModel->SetChanged();
}


@@ -146,11 +146,11 @@ void SAL_CALL Svx3DSceneObject::remove( const Reference< drawing::XShape >& xSha

    SvxShape* pShape = SvxShape::getImplementation( xShape );

    if(!HasSdrObject() || pShape == nullptr)
    if(!mpObj.is() || pShape == nullptr)
        throw uno::RuntimeException();

    SdrObject* pSdrShape = pShape->GetSdrObject();
    if(pSdrShape == nullptr || pSdrShape->GetObjList()->GetOwnerObj() != GetSdrObject())
    if(pSdrShape == nullptr || pSdrShape->GetObjList()->GetOwnerObj() != mpObj.get())
    {
        throw uno::RuntimeException();
    }
@@ -184,8 +184,8 @@ sal_Int32 SAL_CALL Svx3DSceneObject::getCount()

    sal_Int32 nRetval = 0;

    if(HasSdrObject() && dynamic_cast<const E3dScene* >(GetSdrObject()) != nullptr && GetSdrObject()->GetSubList())
        nRetval = GetSdrObject()->GetSubList()->GetObjCount();
    if(mpObj.is() && dynamic_cast<const E3dScene* >(mpObj.get()) != nullptr && mpObj->GetSubList())
        nRetval = mpObj->GetSubList()->GetObjCount();
    return nRetval;
}

@@ -194,13 +194,13 @@ uno::Any SAL_CALL Svx3DSceneObject::getByIndex( sal_Int32 Index )
{
    SolarMutexGuard aGuard;

    if( !HasSdrObject() || GetSdrObject()->GetSubList() == nullptr )
    if( !mpObj.is() || mpObj->GetSubList() == nullptr )
        throw uno::RuntimeException();

    if( Index<0 || GetSdrObject()->GetSubList()->GetObjCount() <= static_cast<size_t>(Index) )
    if( Index<0 || mpObj->GetSubList()->GetObjCount() <= static_cast<size_t>(Index) )
        throw lang::IndexOutOfBoundsException();

    SdrObject* pDestObj = GetSdrObject()->GetSubList()->GetObj( Index );
    SdrObject* pDestObj = mpObj->GetSubList()->GetObj( Index );
    if(pDestObj == nullptr)
        throw lang::IndexOutOfBoundsException();

@@ -221,16 +221,33 @@ sal_Bool SAL_CALL Svx3DSceneObject::hasElements()
{
    SolarMutexGuard aGuard;

    return HasSdrObject() && GetSdrObject()->GetSubList() && (GetSdrObject()->GetSubList()->GetObjCount() > 0);
    return mpObj.is() && mpObj->GetSubList() && (mpObj->GetSubList()->GetObjCount() > 0);
}


static bool ConvertHomogenMatrixToObject( E3dObject* pObject, const Any& rValue )
{
    drawing::HomogenMatrix aMat;
    if( rValue >>= aMat )
    drawing::HomogenMatrix m;
    if( rValue >>= m )
    {
        pObject->SetTransform(basegfx::utils::UnoHomogenMatrixToB3DHomMatrix(aMat));
        basegfx::B3DHomMatrix aMat;
        aMat.set(0, 0, m.Line1.Column1);
        aMat.set(0, 1, m.Line1.Column2);
        aMat.set(0, 2, m.Line1.Column3);
        aMat.set(0, 3, m.Line1.Column4);
        aMat.set(1, 0, m.Line2.Column1);
        aMat.set(1, 1, m.Line2.Column2);
        aMat.set(1, 2, m.Line2.Column3);
        aMat.set(1, 3, m.Line2.Column4);
        aMat.set(2, 0, m.Line3.Column1);
        aMat.set(2, 1, m.Line3.Column2);
        aMat.set(2, 2, m.Line3.Column3);
        aMat.set(2, 3, m.Line3.Column4);
        aMat.set(3, 0, m.Line4.Column1);
        aMat.set(3, 1, m.Line4.Column2);
        aMat.set(3, 2, m.Line4.Column3);
        aMat.set(3, 3, m.Line4.Column4);
        pObject->SetTransform(aMat);
        return true;
    }
    return false;
@@ -240,7 +257,22 @@ static void ConvertObjectToHomogenMatric( E3dObject const * pObject, Any& rValue
{
    drawing::HomogenMatrix aHomMat;
    const basegfx::B3DHomMatrix& rMat = pObject->GetTransform();
    basegfx::utils::B3DHomMatrixToUnoHomogenMatrix(rMat, aHomMat);
    aHomMat.Line1.Column1 = rMat.get(0, 0);
    aHomMat.Line1.Column2 = rMat.get(0, 1);
    aHomMat.Line1.Column3 = rMat.get(0, 2);
    aHomMat.Line1.Column4 = rMat.get(0, 3);
    aHomMat.Line2.Column1 = rMat.get(1, 0);
    aHomMat.Line2.Column2 = rMat.get(1, 1);
    aHomMat.Line2.Column3 = rMat.get(1, 2);
    aHomMat.Line2.Column4 = rMat.get(1, 3);
    aHomMat.Line3.Column1 = rMat.get(2, 0);
    aHomMat.Line3.Column2 = rMat.get(2, 1);
    aHomMat.Line3.Column3 = rMat.get(2, 2);
    aHomMat.Line3.Column4 = rMat.get(2, 3);
    aHomMat.Line4.Column1 = rMat.get(3, 0);
    aHomMat.Line4.Column2 = rMat.get(3, 1);
    aHomMat.Line4.Column3 = rMat.get(3, 2);
    aHomMat.Line4.Column4 = rMat.get(3, 3);
    rValue <<= aHomMat;
}

@@ -258,14 +290,14 @@ bool Svx3DSceneObject::setPropertyValueImpl( const OUString& rName, const SfxIte
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // patch transformation matrix to the object
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( GetSdrObject() ), rValue ) )
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( mpObj.get() ), rValue ) )
            return true;
        break;
    }
    case OWN_ATTR_3D_VALUE_CAMERA_GEOMETRY:
    {
        // set CameraGeometry at scene
        E3dScene* pScene = static_cast< E3dScene* >( GetSdrObject() );
        E3dScene* pScene = static_cast< E3dScene* >( mpObj.get() );
        drawing::CameraGeometry aCamGeo;

        if(rValue >>= aCamGeo)
@@ -370,13 +402,13 @@ bool Svx3DSceneObject::getPropertyValueImpl(const OUString& rName, const SfxItem
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // patch object to a homogeneous 4x4 matrix
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( GetSdrObject() ), rValue );
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( mpObj.get() ), rValue );
        break;
    }
    case OWN_ATTR_3D_VALUE_CAMERA_GEOMETRY:
    {
        // get CameraGeometry from scene
        E3dScene* pScene = static_cast< E3dScene* >( GetSdrObject() );
        E3dScene* pScene = static_cast< E3dScene* >( mpObj.get() );
        drawing::CameraGeometry aCamGeo;

        // fill Vectors from scene camera
@@ -432,7 +464,7 @@ bool Svx3DCubeObject::setPropertyValueImpl( const OUString& rName, const SfxItem
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformationmatrix to the object
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( GetSdrObject() ), rValue ) )
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( mpObj.get() ), rValue ) )
            return true;
        break;
    }
@@ -443,7 +475,7 @@ bool Svx3DCubeObject::setPropertyValueImpl( const OUString& rName, const SfxItem
        if( rValue >>= aUnoPos )
        {
            basegfx::B3DPoint aPos(aUnoPos.PositionX, aUnoPos.PositionY, aUnoPos.PositionZ);
            static_cast< E3dCubeObj* >( GetSdrObject() )->SetCubePos(aPos);
            static_cast< E3dCubeObj* >( mpObj.get() )->SetCubePos(aPos);
            return true;
        }
        break;
@@ -455,7 +487,7 @@ bool Svx3DCubeObject::setPropertyValueImpl( const OUString& rName, const SfxItem
        if( rValue >>= aDirection )
        {
            basegfx::B3DVector aSize(aDirection.DirectionX, aDirection.DirectionY, aDirection.DirectionZ);
            static_cast< E3dCubeObj* >( GetSdrObject() )->SetCubeSize(aSize);
            static_cast< E3dCubeObj* >( mpObj.get() )->SetCubeSize(aSize);
            return true;
        }
        break;
@@ -466,7 +498,7 @@ bool Svx3DCubeObject::setPropertyValueImpl( const OUString& rName, const SfxItem
        // pack sal_Bool bPosIsCenter to the object
        if( rValue >>= bNew )
        {
            static_cast< E3dCubeObj* >( GetSdrObject() )->SetPosIsCenter(bNew);
            static_cast< E3dCubeObj* >( mpObj.get() )->SetPosIsCenter(bNew);
            return true;
        }
        break;
@@ -485,13 +517,13 @@ bool Svx3DCubeObject::getPropertyValueImpl( const OUString& rName, const SfxItem
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformation to a homogeneous matrix
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( GetSdrObject() ), rValue );
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( mpObj.get() ), rValue );
        break;
    }
    case OWN_ATTR_3D_VALUE_POSITION:
    {
        // pack position
        const basegfx::B3DPoint& rPos = static_cast<E3dCubeObj*>(GetSdrObject())->GetCubePos();
        const basegfx::B3DPoint& rPos = static_cast<E3dCubeObj*>(mpObj.get())->GetCubePos();
        drawing::Position3D aPos;

        aPos.PositionX = rPos.getX();
@@ -504,7 +536,7 @@ bool Svx3DCubeObject::getPropertyValueImpl( const OUString& rName, const SfxItem
    case OWN_ATTR_3D_VALUE_SIZE:
    {
        // pack size
        const basegfx::B3DVector& rSize = static_cast<E3dCubeObj*>(GetSdrObject())->GetCubeSize();
        const basegfx::B3DVector& rSize = static_cast<E3dCubeObj*>(mpObj.get())->GetCubeSize();
        drawing::Direction3D aDir;

        aDir.DirectionX = rSize.getX();
@@ -516,7 +548,7 @@ bool Svx3DCubeObject::getPropertyValueImpl( const OUString& rName, const SfxItem
    }
    case OWN_ATTR_3D_VALUE_POS_IS_CENTER:
    {
        rValue <<= static_cast<E3dCubeObj*>(GetSdrObject())->GetPosIsCenter();
        rValue <<= static_cast<E3dCubeObj*>(mpObj.get())->GetPosIsCenter();
        break;
    }
    default:
@@ -551,7 +583,7 @@ bool Svx3DSphereObject::setPropertyValueImpl( const OUString& rName, const SfxIt
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformation matrix to the object
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( GetSdrObject() ), rValue ) )
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( mpObj.get() ), rValue ) )
            return true;
        break;
    }
@@ -563,7 +595,7 @@ bool Svx3DSphereObject::setPropertyValueImpl( const OUString& rName, const SfxIt
        if( rValue >>= aUnoPos )
        {
            basegfx::B3DPoint aPos(aUnoPos.PositionX, aUnoPos.PositionY, aUnoPos.PositionZ);
            static_cast<E3dSphereObj*>(GetSdrObject())->SetCenter(aPos);
            static_cast<E3dSphereObj*>(mpObj.get())->SetCenter(aPos);
            return true;
        }
        break;
@@ -576,7 +608,7 @@ bool Svx3DSphereObject::setPropertyValueImpl( const OUString& rName, const SfxIt
        if( rValue >>= aDir )
        {
            basegfx::B3DVector aPos(aDir.DirectionX, aDir.DirectionY, aDir.DirectionZ);
            static_cast<E3dSphereObj*>(GetSdrObject())->SetSize(aPos);
            static_cast<E3dSphereObj*>(mpObj.get())->SetSize(aPos);
            return true;
        }
        break;
@@ -595,13 +627,13 @@ bool Svx3DSphereObject::getPropertyValueImpl( const OUString& rName, const SfxIt
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformation to a homogeneous matrix
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( GetSdrObject() ), rValue );
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( mpObj.get() ), rValue );
        break;
    }
    case OWN_ATTR_3D_VALUE_POSITION:
    {
        // pack position
        const basegfx::B3DPoint& rPos = static_cast<E3dSphereObj*>(GetSdrObject())->Center();
        const basegfx::B3DPoint& rPos = static_cast<E3dSphereObj*>(mpObj.get())->Center();
        drawing::Position3D aPos;

        aPos.PositionX = rPos.getX();
@@ -614,7 +646,7 @@ bool Svx3DSphereObject::getPropertyValueImpl( const OUString& rName, const SfxIt
    case OWN_ATTR_3D_VALUE_SIZE:
    {
        // pack size
        const basegfx::B3DVector& rSize = static_cast<E3dSphereObj*>(GetSdrObject())->Size();
        const basegfx::B3DVector& rSize = static_cast<E3dSphereObj*>(mpObj.get())->Size();
        drawing::Direction3D aDir;

        aDir.DirectionX = rSize.getX();
@@ -744,7 +776,7 @@ bool Svx3DLatheObject::setPropertyValueImpl( const OUString& rName, const SfxIte
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformation matrix to the object
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( GetSdrObject() ), rValue ) )
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( mpObj.get() ), rValue ) )
            return true;
        break;
    }
@@ -759,18 +791,18 @@ bool Svx3DLatheObject::setPropertyValueImpl( const OUString& rName, const SfxIte
            // #105127# SetPolyPoly3D sets the Svx3DVerticalSegmentsItem to the number
            // of points of the polygon. Thus, value gets lost. To avoid this, rescue
            // item here and re-set after setting the polygon.
            const sal_uInt32 nPrevVerticalSegs(static_cast<E3dLatheObj*>(GetSdrObject())->GetVerticalSegments());
            const sal_uInt32 nPrevVerticalSegs(static_cast<E3dLatheObj*>(mpObj.get())->GetVerticalSegments());

            // set polygon
            const basegfx::B3DHomMatrix aIdentity;
            const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(aNewB3DPolyPolygon, aIdentity));
            static_cast<E3dLatheObj*>(GetSdrObject())->SetPolyPoly2D(aB2DPolyPolygon);
            const sal_uInt32 nPostVerticalSegs(static_cast<E3dLatheObj*>(GetSdrObject())->GetVerticalSegments());
            static_cast<E3dLatheObj*>(mpObj.get())->SetPolyPoly2D(aB2DPolyPolygon);
            const sal_uInt32 nPostVerticalSegs(static_cast<E3dLatheObj*>(mpObj.get())->GetVerticalSegments());

            if(nPrevVerticalSegs != nPostVerticalSegs)
            {
                // restore the vertical segment count
                static_cast<E3dLatheObj*>(GetSdrObject())->SetMergedItem(makeSvx3DVerticalSegmentsItem(nPrevVerticalSegs));
                static_cast<E3dLatheObj*>(mpObj.get())->SetMergedItem(makeSvx3DVerticalSegmentsItem(nPrevVerticalSegs));
            }
            return true;
        }
@@ -791,14 +823,32 @@ bool Svx3DLatheObject::getPropertyValueImpl( const OUString& rName, const SfxIte
    {
        // pack transformation to a homogeneous matrix
        drawing::HomogenMatrix aHomMat;
        basegfx::B3DHomMatrix aMat = static_cast<E3dObject*>(GetSdrObject())->GetTransform();
        basegfx::utils::B3DHomMatrixToUnoHomogenMatrix(aMat, aHomMat);
        basegfx::B3DHomMatrix aMat = static_cast<E3dObject*>(mpObj.get())->GetTransform();

        // pack evtl. transformed matrix to output
        aHomMat.Line1.Column1 = aMat.get(0, 0);
        aHomMat.Line1.Column2 = aMat.get(0, 1);
        aHomMat.Line1.Column3 = aMat.get(0, 2);
        aHomMat.Line1.Column4 = aMat.get(0, 3);
        aHomMat.Line2.Column1 = aMat.get(1, 0);
        aHomMat.Line2.Column2 = aMat.get(1, 1);
        aHomMat.Line2.Column3 = aMat.get(1, 2);
        aHomMat.Line2.Column4 = aMat.get(1, 3);
        aHomMat.Line3.Column1 = aMat.get(2, 0);
        aHomMat.Line3.Column2 = aMat.get(2, 1);
        aHomMat.Line3.Column3 = aMat.get(2, 2);
        aHomMat.Line3.Column4 = aMat.get(2, 3);
        aHomMat.Line4.Column1 = aMat.get(3, 0);
        aHomMat.Line4.Column2 = aMat.get(3, 1);
        aHomMat.Line4.Column3 = aMat.get(3, 2);
        aHomMat.Line4.Column4 = aMat.get(3, 3);

        rValue <<= aHomMat;
        break;
    }
    case OWN_ATTR_3D_VALUE_POLYPOLYGON3D:
    {
        const basegfx::B2DPolyPolygon& rPolyPoly = static_cast<E3dLatheObj*>(GetSdrObject())->GetPolyPoly2D();
        const basegfx::B2DPolyPolygon& rPolyPoly = static_cast<E3dLatheObj*>(mpObj.get())->GetPolyPoly2D();
        const basegfx::B3DPolyPolygon aB3DPolyPolygon(basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(rPolyPoly));

        B3dPolyPolygon_to_PolyPolygonShape3D(aB3DPolyPolygon, rValue);
@@ -836,7 +886,7 @@ bool Svx3DExtrudeObject::setPropertyValueImpl( const OUString& rName, const SfxI
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformation matrix to the object
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( GetSdrObject() ), rValue ) )
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( mpObj.get() ), rValue ) )
            return true;
        break;
    }
@@ -852,7 +902,7 @@ bool Svx3DExtrudeObject::setPropertyValueImpl( const OUString& rName, const SfxI
            // set polygon
            const basegfx::B3DHomMatrix aIdentity;
            const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(aNewB3DPolyPolygon, aIdentity));
            static_cast<E3dExtrudeObj*>(GetSdrObject())->SetExtrudePolygon(aB2DPolyPolygon);
            static_cast<E3dExtrudeObj*>(mpObj.get())->SetExtrudePolygon(aB2DPolyPolygon);
            return true;
        }
        break;
@@ -872,8 +922,26 @@ bool Svx3DExtrudeObject::getPropertyValueImpl( const OUString& rName, const SfxI
    {
        // pack transformation to a homogeneous matrix
        drawing::HomogenMatrix aHomMat;
        basegfx::B3DHomMatrix aMat = static_cast<E3dObject*>(GetSdrObject())->GetTransform();
        basegfx::utils::B3DHomMatrixToUnoHomogenMatrix(aMat, aHomMat);
        basegfx::B3DHomMatrix aMat = static_cast<E3dObject*>(mpObj.get())->GetTransform();

        // pack evtl. transformed matrix to output
        aHomMat.Line1.Column1 = aMat.get(0, 0);
        aHomMat.Line1.Column2 = aMat.get(0, 1);
        aHomMat.Line1.Column3 = aMat.get(0, 2);
        aHomMat.Line1.Column4 = aMat.get(0, 3);
        aHomMat.Line2.Column1 = aMat.get(1, 0);
        aHomMat.Line2.Column2 = aMat.get(1, 1);
        aHomMat.Line2.Column3 = aMat.get(1, 2);
        aHomMat.Line2.Column4 = aMat.get(1, 3);
        aHomMat.Line3.Column1 = aMat.get(2, 0);
        aHomMat.Line3.Column2 = aMat.get(2, 1);
        aHomMat.Line3.Column3 = aMat.get(2, 2);
        aHomMat.Line3.Column4 = aMat.get(2, 3);
        aHomMat.Line4.Column1 = aMat.get(3, 0);
        aHomMat.Line4.Column2 = aMat.get(3, 1);
        aHomMat.Line4.Column3 = aMat.get(3, 2);
        aHomMat.Line4.Column4 = aMat.get(3, 3);

        rValue <<= aHomMat;
        break;
    }
@@ -881,7 +949,7 @@ bool Svx3DExtrudeObject::getPropertyValueImpl( const OUString& rName, const SfxI
    case OWN_ATTR_3D_VALUE_POLYPOLYGON3D:
    {
        // pack polygon definition
        const basegfx::B2DPolyPolygon& rPolyPoly = static_cast<E3dExtrudeObj*>(GetSdrObject())->GetExtrudePolygon();
        const basegfx::B2DPolyPolygon& rPolyPoly = static_cast<E3dExtrudeObj*>(mpObj.get())->GetExtrudePolygon();
        const basegfx::B3DPolyPolygon aB3DPolyPolygon(basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(rPolyPoly));

        B3dPolyPolygon_to_PolyPolygonShape3D(aB3DPolyPolygon, rValue);
@@ -919,7 +987,7 @@ bool Svx3DPolygonObject::setPropertyValueImpl( const OUString& rName, const SfxI
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        // pack transformation matrix to the object
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( GetSdrObject() ), rValue ) )
        if( ConvertHomogenMatrixToObject( static_cast< E3dObject* >( mpObj.get() ), rValue ) )
            return true;
        break;
    }
@@ -933,7 +1001,7 @@ bool Svx3DPolygonObject::setPropertyValueImpl( const OUString& rName, const SfxI
        if( PolyPolygonShape3D_to_B3dPolyPolygon( rValue, aNewB3DPolyPolygon, false ) )
        {
            // set polygon
            static_cast<E3dPolygonObj*>(GetSdrObject())->SetPolyPolygon3D(aNewB3DPolyPolygon);
            static_cast<E3dPolygonObj*>(mpObj.get())->SetPolyPolygon3D(aNewB3DPolyPolygon);
            return true;
        }
        break;
@@ -947,7 +1015,7 @@ bool Svx3DPolygonObject::setPropertyValueImpl( const OUString& rName, const SfxI
        if( PolyPolygonShape3D_to_B3dPolyPolygon( rValue, aNewB3DPolyPolygon, false ) )
        {
            // set polygon
            static_cast<E3dPolygonObj*>(GetSdrObject())->SetPolyNormals3D(aNewB3DPolyPolygon);
            static_cast<E3dPolygonObj*>(mpObj.get())->SetPolyNormals3D(aNewB3DPolyPolygon);
            return true;
        }
        break;
@@ -963,7 +1031,7 @@ bool Svx3DPolygonObject::setPropertyValueImpl( const OUString& rName, const SfxI
            // set polygon
            const basegfx::B3DHomMatrix aIdentity;
            const basegfx::B2DPolyPolygon aB2DPolyPolygon(basegfx::utils::createB2DPolyPolygonFromB3DPolyPolygon(aNewB3DPolyPolygon, aIdentity));
            static_cast<E3dPolygonObj*>(GetSdrObject())->SetPolyTexture2D(aB2DPolyPolygon);
            static_cast<E3dPolygonObj*>(mpObj.get())->SetPolyTexture2D(aB2DPolyPolygon);
            return true;
        }
        break;
@@ -973,7 +1041,7 @@ bool Svx3DPolygonObject::setPropertyValueImpl( const OUString& rName, const SfxI
        bool bNew = false;
        if( rValue >>= bNew )
        {
            static_cast<E3dPolygonObj*>(GetSdrObject())->SetLineOnly(bNew);
            static_cast<E3dPolygonObj*>(mpObj.get())->SetLineOnly(bNew);
            return true;
        }
        break;
@@ -991,26 +1059,26 @@ bool Svx3DPolygonObject::getPropertyValueImpl( const OUString& rName, const SfxI
    {
    case OWN_ATTR_3D_VALUE_TRANSFORM_MATRIX:
    {
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( GetSdrObject() ), rValue );
        ConvertObjectToHomogenMatric( static_cast< E3dObject* >( mpObj.get() ), rValue );
        break;
    }

    case OWN_ATTR_3D_VALUE_POLYPOLYGON3D:
    {
        B3dPolyPolygon_to_PolyPolygonShape3D(static_cast<E3dPolygonObj*>(GetSdrObject())->GetPolyPolygon3D(),rValue);
        B3dPolyPolygon_to_PolyPolygonShape3D(static_cast<E3dPolygonObj*>(mpObj.get())->GetPolyPolygon3D(),rValue);
        break;
    }

    case OWN_ATTR_3D_VALUE_NORMALSPOLYGON3D:
    {
        B3dPolyPolygon_to_PolyPolygonShape3D(static_cast<E3dPolygonObj*>(GetSdrObject())->GetPolyNormals3D(),rValue);
        B3dPolyPolygon_to_PolyPolygonShape3D(static_cast<E3dPolygonObj*>(mpObj.get())->GetPolyNormals3D(),rValue);
        break;
    }

    case OWN_ATTR_3D_VALUE_TEXTUREPOLYGON3D:
    {
        // pack texture definition
        const basegfx::B2DPolyPolygon& rPolyPoly = static_cast<E3dPolygonObj*>(GetSdrObject())->GetPolyTexture2D();
        const basegfx::B2DPolyPolygon& rPolyPoly = static_cast<E3dPolygonObj*>(mpObj.get())->GetPolyTexture2D();
        const basegfx::B3DPolyPolygon aB3DPolyPolygon(basegfx::utils::createB3DPolyPolygonFromB2DPolyPolygon(rPolyPoly));

        B3dPolyPolygon_to_PolyPolygonShape3D(aB3DPolyPolygon,rValue);
@@ -1019,7 +1087,7 @@ bool Svx3DPolygonObject::getPropertyValueImpl( const OUString& rName, const SfxI

    case OWN_ATTR_3D_VALUE_LINEONLY:
    {
        rValue <<= static_cast<E3dPolygonObj*>(GetSdrObject())->GetLineOnly();
        rValue <<= static_cast<E3dPolygonObj*>(mpObj.get())->GetLineOnly();
        break;
    }

diff --git a/svx/source/unodraw/unoshap4.cxx b/svx/source/unodraw/unoshap4.cxx
index c9e4065..a5ef378 100644
--- a/svx/source/unodraw/unoshap4.cxx
+++ b/svx/source/unodraw/unoshap4.cxx
@@ -90,10 +90,10 @@ bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPro
        // TODO/LATER: seems to make no sense for iconified object

        awt::Rectangle aVisArea;
        if( (rValue >>= aVisArea) && dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr)
        if( (rValue >>= aVisArea) && dynamic_cast<const SdrOle2Obj* >(mpObj.get()) != nullptr)
        {
            Size aTmp( aVisArea.X + aVisArea.Width, aVisArea.Y + aVisArea.Height );
            uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef();
            uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef();
            if( xObj.is() )
            {
                try
@@ -118,7 +118,7 @@ bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPro
        sal_Int64 nAspect = 0;
        if( rValue >>= nAspect )
        {
            static_cast<SdrOle2Obj*>(GetSdrObject())->SetAspect( nAspect );
            static_cast<SdrOle2Obj*>(mpObj.get())->SetAspect( nAspect );
            return true;
        }
        break;
@@ -144,7 +144,7 @@ bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPro
        if( xGraphic.is() )
        {
            const Graphic aGraphic(xGraphic);
            static_cast<SdrOle2Obj*>(GetSdrObject())->SetGraphic(aGraphic);
            static_cast<SdrOle2Obj*>(mpObj.get())->SetGraphic(aGraphic);
            return true;
        }
        break;
@@ -154,7 +154,7 @@ bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPro
        uno::Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
        if( xGraphic.is() )
        {
            SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
            SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
            if( pOle )
            {
                GraphicObject aGrafObj( xGraphic );
@@ -172,10 +172,10 @@ bool SvxOle2Shape::setPropertyValueImpl( const OUString& rName, const SfxItemPro
        {
            SdrOle2Obj *pOle;
#if OSL_DEBUG_LEVEL > 0
            pOle = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
            pOle = dynamic_cast<SdrOle2Obj*>(mpObj.get());
            assert(pOle);
#else
            pOle = static_cast<SdrOle2Obj*>(GetSdrObject());
            pOle = static_cast<SdrOle2Obj*>(mpObj.get());
#endif
            pOle->SetPersistName( aPersistName );
            return true;
@@ -220,7 +220,7 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro

    case OWN_ATTR_METAFILE:
    {
        SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
        SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(mpObj.get());
        if( pObj )
        {
            const Graphic* pGraphic = pObj->GetGraphic();
@@ -260,10 +260,10 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro
    case OWN_ATTR_OLE_VISAREA:
    {
        awt::Rectangle aVisArea;
        if( dynamic_cast<const SdrOle2Obj* >(GetSdrObject()) != nullptr)
        if( dynamic_cast<const SdrOle2Obj* >(mpObj.get()) != nullptr)
        {
            MapMode aMapMode( MapUnit::Map100thMM ); // the API uses this map mode
            Size aTmp = static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
            Size aTmp = static_cast<SdrOle2Obj*>(mpObj.get())->GetOrigObjSize( &aMapMode ); // get the size in the requested map mode
            aVisArea = awt::Rectangle( 0, 0, aTmp.Width(), aTmp.Height() );
        }

@@ -273,14 +273,14 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro

    case OWN_ATTR_OLESIZE:
    {
        Size aTmp( static_cast<SdrOle2Obj*>(GetSdrObject())->GetOrigObjSize() );
        Size aTmp( static_cast<SdrOle2Obj*>(mpObj.get())->GetOrigObjSize() );
        rValue <<= awt::Size( aTmp.Width(), aTmp.Height() );
        break;
    }

    case OWN_ATTR_OLE_ASPECT:
    {
        rValue <<= static_cast<SdrOle2Obj*>(GetSdrObject())->GetAspect();
        rValue <<= static_cast<SdrOle2Obj*>(mpObj.get())->GetAspect();
        break;
    }

@@ -288,7 +288,7 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro
    case OWN_ATTR_OLE_EMBEDDED_OBJECT:
    case OWN_ATTR_OLE_EMBEDDED_OBJECT_NONEWCLIENT:
    {
        SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( GetSdrObject() );
        SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>( mpObj.get() );
        if( pObj )
        {
            uno::Reference < embed::XEmbeddedObject > xObj( pObj->GetObjRef() );
@@ -315,7 +315,7 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro
    case OWN_ATTR_VALUE_GRAPHIC:
    {
        uno::Reference< graphic::XGraphic > xGraphic;
        const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic();
        const Graphic* pGraphic = static_cast<SdrOle2Obj*>( mpObj.get() )->GetGraphic();
        if( pGraphic )
            xGraphic = pGraphic->GetXGraphic();
        rValue <<= xGraphic;
@@ -325,7 +325,7 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro
    case OWN_ATTR_THUMBNAIL:
    {
        uno::Reference< graphic::XGraphic > xGraphic;
        const Graphic* pGraphic = static_cast<SdrOle2Obj*>( GetSdrObject() )->GetGraphic();
        const Graphic* pGraphic = static_cast<SdrOle2Obj*>( mpObj.get() )->GetGraphic();
        if( pGraphic )
            xGraphic = pGraphic->GetXGraphic();
        rValue <<= xGraphic;
@@ -334,14 +334,14 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro
    case OWN_ATTR_PERSISTNAME:
    {
        OUString    aPersistName;
        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );

        if( pOle )
        {
            aPersistName = pOle->GetPersistName();
            if( !aPersistName.isEmpty() )
            {
                ::comphelper::IEmbeddedHelper* pPersist(GetSdrObject()->getSdrModelFromSdrObject().GetPersist());
                ::comphelper::IEmbeddedHelper *pPersist = mpObj->GetModel()->GetPersist();
                if( (nullptr == pPersist) || !pPersist->getEmbeddedObjectContainer().HasEmbeddedObject( pOle->GetPersistName() ) )
                    aPersistName.clear();
            }
@@ -353,7 +353,7 @@ bool SvxOle2Shape::getPropertyValueImpl( const OUString& rName, const SfxItemPro
    case OWN_ATTR_OLE_LINKURL:
    {
        OUString    aLinkURL;
        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );

        if( pOle )
        {
@@ -376,12 +376,12 @@ bool SvxOle2Shape::createObject( const SvGlobalName &aClassName )
{
    DBG_TESTSOLARMUTEX();

    SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
    SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
    if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
        return false;

    // create storage and inplace object
    ::comphelper::IEmbeddedHelper*     pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
    ::comphelper::IEmbeddedHelper*     pPersist = mpModel->GetPersist();
    OUString              aPersistName;
    OUString            aTmpStr;
    if( SvxShape::getPropertyValue( UNO_NAME_OLE2_PERSISTNAME ) >>= aTmpStr )
@@ -438,13 +438,13 @@ void SvxOle2Shape::createLink( const OUString& aLinkURL )
{
    DBG_TESTSOLARMUTEX();

    SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
    SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
    if ( !pOle2Obj || !pOle2Obj->IsEmpty() )
        return;

    OUString aPersistName;

    ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
    ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();

    uno::Sequence< beans::PropertyValue > aMediaDescr( 1 );
    aMediaDescr[0].Name = "URL";
@@ -497,10 +497,10 @@ void SvxOle2Shape::createLink( const OUString& aLinkURL )

void SvxOle2Shape::resetModifiedState()
{
    ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
    ::comphelper::IEmbeddedHelper* pPersist = mpModel ? mpModel->GetPersist() : nullptr;
    if( pPersist && !pPersist->isEnableSetModified() )
    {
        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( mpObj.get() );
        if( pOle && !pOle->IsEmpty() )
        {
            uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), uno::UNO_QUERY );
@@ -515,7 +515,7 @@ const SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& rHexCLSID)
{
    DBG_TESTSOLARMUTEX();
    SvGlobalName aClassName;
    SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
    SdrOle2Obj* pOle2Obj = dynamic_cast< SdrOle2Obj* >( mpObj.get() );

    if( pOle2Obj )
    {
@@ -523,7 +523,7 @@ const SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& rHexCLSID)

        if( pOle2Obj->IsEmpty() )
        {
            ::comphelper::IEmbeddedHelper* pPersist = GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
            ::comphelper::IEmbeddedHelper* pPersist = mpModel->GetPersist();
            if( pPersist )
            {
                uno::Reference < embed::XEmbeddedObject > xObj =
@@ -584,9 +584,9 @@ bool SvxAppletShape::setPropertyValueImpl( const OUString& rName, const SfxItemP
{
    if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
    {
        if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
        if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
        {
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            if( xSet.is() )
            {
                // allow exceptions to pass through
@@ -605,9 +605,9 @@ bool SvxAppletShape::getPropertyValueImpl( const OUString& rName, const SfxItemP
{
    if( (pProperty->nWID >= OWN_ATTR_APPLET_DOCBASE) && (pProperty->nWID <= OWN_ATTR_APPLET_ISSCRIPT) )
    {
        if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
        if ( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
        {
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            if( xSet.is() )
            {
                rValue = xSet->getPropertyValue( rName );
@@ -655,9 +655,9 @@ bool SvxPluginShape::setPropertyValueImpl( const OUString& rName, const SfxItemP
{
    if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
    {
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
        {
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            if( xSet.is() )
            {
                // allow exceptions to pass through
@@ -676,9 +676,9 @@ bool SvxPluginShape::getPropertyValueImpl( const OUString& rName, const SfxItemP
{
    if( (pProperty->nWID >= OWN_ATTR_PLUGIN_MIMETYPE) && (pProperty->nWID <= OWN_ATTR_PLUGIN_COMMANDS) )
    {
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
        {
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            if( xSet.is() )
            {
                rValue = xSet->getPropertyValue( rName );
@@ -727,9 +727,9 @@ bool SvxFrameShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr
{
    if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
    {
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
        {
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            if( xSet.is() )
            {
                // allow exceptions to pass through
@@ -749,9 +749,9 @@ bool SvxFrameShape::getPropertyValueImpl(const OUString& rName, const SfxItemPro
{
    if( (pProperty->nWID >= OWN_ATTR_FRAME_URL) && (pProperty->nWID <= OWN_ATTR_FRAME_MARGIN_HEIGHT) )
    {
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef() ) )
        if( svt::EmbeddedObjectRef::TryRunningState( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef() ) )
        {
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(GetSdrObject())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            uno::Reference < beans::XPropertySet > xSet( static_cast<SdrOle2Obj*>(mpObj.get())->GetObjRef()->getComponent(), uno::UNO_QUERY );
            if( xSet.is() )
            {
                rValue = xSet->getPropertyValue( rName );
@@ -783,7 +783,7 @@ bool SvxMediaShape::setPropertyValueImpl( const OUString& rName, const SfxItemPr
        || (pProperty->nWID == OWN_ATTR_MEDIA_STREAM)
        || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE) )
    {
        SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
        SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
        ::avmedia::MediaItem aItem;
        bool bOk = false;

@@ -926,7 +926,7 @@ bool SvxMediaShape::getPropertyValueImpl( const OUString& rName, const SfxItemPr
        || (pProperty->nWID == OWN_ATTR_MEDIA_MIMETYPE)
        || (pProperty->nWID == OWN_ATTR_FALLBACK_GRAPHIC))
    {
        SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( GetSdrObject() );
        SdrMediaObj* pMedia = static_cast< SdrMediaObj* >( mpObj.get() );
        const ::avmedia::MediaItem aItem( pMedia->getMediaProperties() );

        switch( pProperty->nWID )
diff --git a/svx/source/unodraw/unoshape.cxx b/svx/source/unodraw/unoshape.cxx
index c726444..572b31c 100644
--- a/svx/source/unodraw/unoshape.cxx
+++ b/svx/source/unodraw/unoshape.cxx
@@ -180,7 +180,8 @@ SvxShape::SvxShape( SdrObject* pObject )
,   mbIsMultiPropertyCall(false)
,   mpPropSet(getSvxMapProvider().GetPropertySet(SVXMAP_SHAPE, SdrObject::GetGlobalDrawObjectItemPool()))
,   maPropMapEntries(getSvxMapProvider().GetMap(SVXMAP_SHAPE))
,   mpSdrObjectWeakReference(pObject)
,   mpObj(pObject)
,   mpModel(nullptr)
,   mnLockCount(0)
{
    impl_construct();
@@ -193,7 +194,8 @@ SvxShape::SvxShape( SdrObject* pObject, const SfxItemPropertyMapEntry* pEntries,
,   mbIsMultiPropertyCall(false)
,   mpPropSet(pPropertySet)
,   maPropMapEntries(pEntries)
,   mpSdrObjectWeakReference(pObject)
,   mpObj(pObject)
,   mpModel(nullptr)
,   mnLockCount(0)
{
    impl_construct();
@@ -206,7 +208,8 @@ SvxShape::SvxShape()
,   mbIsMultiPropertyCall(false)
,   mpPropSet(getSvxMapProvider().GetPropertySet(SVXMAP_SHAPE, SdrObject::GetGlobalDrawObjectItemPool()))
,   maPropMapEntries(getSvxMapProvider().GetMap(SVXMAP_SHAPE))
,   mpSdrObjectWeakReference(nullptr)
,   mpObj(nullptr)
,   mpModel(nullptr)
,   mnLockCount(0)
{
    impl_construct();
@@ -219,19 +222,19 @@ SvxShape::~SvxShape() throw()

    DBG_ASSERT( mnLockCount == 0, "Locked shape was disposed!" );

    if ( mpModel )
        EndListening( *mpModel );

    if ( mpImpl->mpMaster )
        mpImpl->mpMaster->dispose();

    if ( HasSdrObject() )
    {
        EndListening(GetSdrObject()->getSdrModelFromSdrObject());
        GetSdrObject()->setUnoShape(nullptr);
    }
    if ( mpObj.is() )
        mpObj->setUnoShape(nullptr);

    if( HasSdrObjectOwnership() && HasSdrObject() )
    if( HasSdrObjectOwnership() && mpObj.is() )
    {
        mpImpl->mbHasSdrObjectOwnership = false;
        SdrObject* pObject = GetSdrObject();
        SdrObject* pObject = mpObj.get();
        SdrObject::Free( pObject );
    }

@@ -245,23 +248,13 @@ void SvxShape::TakeSdrObjectOwnership()
}


void SvxShape::InvalidateSdrObject()
{
    if(HasSdrObject())
    {
        EndListening(GetSdrObject()->getSdrModelFromSdrObject());
    }

    mpSdrObjectWeakReference.reset( nullptr );
};

bool SvxShape::HasSdrObjectOwnership() const
{
    if ( !mpImpl->mbHasSdrObjectOwnership )
        return false;

    OSL_ENSURE( HasSdrObject(), "SvxShape::HasSdrObjectOwnership: have the ownership of an object which I don't know!" );
    return HasSdrObject();
    OSL_ENSURE( mpObj.is(), "SvxShape::HasSdrObjectOwnership: have the ownership of an object which I don't know!" );
    return mpObj.is();
}


@@ -342,31 +335,40 @@ void SvxShape::impl_construct()
    mpImpl->maPropertyNotifier.registerProvider( svx::ShapeProperty::Size,
        std::shared_ptr<svx::IPropertyValueProvider>( new ShapeSizeProvider( *mpImpl ) ) );

    if ( HasSdrObject() )
    {
        StartListening(GetSdrObject()->getSdrModelFromSdrObject());
    if ( mpObj.is() )
        impl_initFromSdrObject();
    }
}


void SvxShape::impl_initFromSdrObject()
{
    DBG_TESTSOLARMUTEX();
    OSL_PRECOND( HasSdrObject(), "SvxShape::impl_initFromSdrObject: not to be called without SdrObject!" );
    if ( !HasSdrObject() )
    OSL_PRECOND( mpObj.is(), "SvxShape::impl_initFromSdrObject: not to be called without SdrObject!" );
    if ( !mpObj.is() )
        return;

    osl_atomic_increment( &m_refCount );
    {
        GetSdrObject()->setUnoShape(*this);
        mpObj->setUnoShape(*this);
    }
    osl_atomic_decrement( &m_refCount );

    auto pNewModel = mpObj->GetModel();

    if (pNewModel != mpModel)
    {
        if (mpModel)
            EndListening( *mpModel );
        if (pNewModel)
            StartListening( *pNewModel );
        mpModel = pNewModel;
    }

    // #i40944#
    // Do not simply return when no model but do the type corrections
    // following below.
    const SdrInventor nInventor = GetSdrObject()->GetObjInventor();

    const SdrInventor nInventor = mpObj->GetObjInventor();

    // is it one of ours (svx) ?
    if( nInventor == SdrInventor::Default || nInventor == SdrInventor::E3d || nInventor == SdrInventor::FmForm )
@@ -377,7 +379,7 @@ void SvxShape::impl_initFromSdrObject()
        }
        else
        {
            mpImpl->mnObjId = GetSdrObject()->GetObjIdentifier();
            mpImpl->mnObjId = mpObj->GetObjIdentifier();
            if( nInventor == SdrInventor::E3d )
                mpImpl->mnObjId |= E3D_INVENTOR_FLAG;
        }
@@ -410,20 +412,16 @@ void SvxShape::Create( SdrObject* pNewObj, SvxDrawPage* /*pNewPage*/ )
    if ( pCreatedObj == pNewObj )
        return;

    DBG_ASSERT( pNewObj->GetModel(), "no model for SdrObject?" );
    // Correct condition (#i52126#)
    mpImpl->mpCreatedObj = pNewObj;

    if( HasSdrObject() )
    if( mpObj.is() && mpObj->GetModel() )
    {
        EndListening( GetSdrObject()->getSdrModelFromSdrObject() );
        EndListening( *mpObj->GetModel() );
    }

    mpSdrObjectWeakReference.reset( pNewObj );

    if( HasSdrObject() )
    {
        StartListening( GetSdrObject()->getSdrModelFromSdrObject() );
    }
    mpObj.reset( pNewObj );

    OSL_ENSURE( !mbIsMultiPropertyCall, "SvxShape::Create: hmm?" );
        // this was previously set in impl_initFromSdrObject, but I think it was superfluous
@@ -434,29 +432,63 @@ void SvxShape::Create( SdrObject* pNewObj, SvxDrawPage* /*pNewPage*/ )
    ObtainSettingsFromPropertySet( *mpPropSet );

    // save user call
    SdrObjUserCall* pUser = GetSdrObject()->GetUserCall();
    GetSdrObject()->SetUserCall(nullptr);
    SdrObjUserCall* pUser = mpObj->GetUserCall();
    mpObj->SetUserCall(nullptr);

    setPosition( maPosition );
    setSize( maSize );

    // restore user call after we set the initial size
    GetSdrObject()->SetUserCall( pUser );
    mpObj->SetUserCall( pUser );

    // if this shape was already named, use this name
    if( !maShapeName.isEmpty() )
    {
        GetSdrObject()->SetName( maShapeName );
        mpObj->SetName( maShapeName );
        maShapeName.clear();
    }
}


void SvxShape::ChangeModel( SdrModel* pNewModel )
{
    DBG_TESTSOLARMUTEX();
    if( mpObj.is() && mpObj->GetModel() )
    {
        if( mpObj->GetModel() != pNewModel )
        {
            EndListening( *mpObj->GetModel() );
        }
    }

    // Always listen to new model (#i52126#)
    if( pNewModel )
    {
        StartListening( *pNewModel );
    }

    // HACK #i53696# ChangeModel should be virtual, but it isn't. can't change that for 2.0.1
    SvxShapeText* pShapeText = dynamic_cast< SvxShapeText* >( this );
    if( pShapeText )
    {
        SvxTextEditSource* pTextEditSource = dynamic_cast< SvxTextEditSource* >( pShapeText->GetEditSource() );
        if( pTextEditSource )
            pTextEditSource->ChangeModel( pNewModel );
    }

    mpModel = pNewModel;

    if( mpImpl->mpMaster )
        mpImpl->mpMaster->modelChanged( pNewModel );
}


void SvxShape::ForceMetricToItemPoolMetric(Pair& rPoint) const throw()
{
    DBG_TESTSOLARMUTEX();
    if(HasSdrObject())
    if(mpModel)
    {
        MapUnit eMapUnit(GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0));
        MapUnit eMapUnit = mpModel->GetItemPool().GetMetric(0);
        if(eMapUnit != MapUnit::Map100thMM)
        {
            switch(eMapUnit)
@@ -480,9 +512,9 @@ void SvxShape::ForceMetricToItemPoolMetric(Pair& rPoint) const throw()
void SvxShape::ForceMetricToItemPoolMetric(basegfx::B2DPolyPolygon& rPolyPolygon) const throw()
{
    DBG_TESTSOLARMUTEX();
    if(HasSdrObject())
    if(mpModel)
    {
        MapUnit eMapUnit(GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0));
        MapUnit eMapUnit = mpModel->GetItemPool().GetMetric(0);
        if(eMapUnit != MapUnit::Map100thMM)
        {
            switch(eMapUnit)
@@ -510,9 +542,9 @@ void SvxShape::ForceMetricTo100th_mm(Pair& rPoint) const throw()
{
    DBG_TESTSOLARMUTEX();
    MapUnit eMapUnit = MapUnit::Map100thMM;
    if(HasSdrObject())
    if(mpModel)
    {
        eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0);
        eMapUnit = mpModel->GetItemPool().GetMetric(0);
        if(eMapUnit != MapUnit::Map100thMM)
        {
            switch(eMapUnit)
@@ -537,9 +569,9 @@ void SvxShape::ForceMetricTo100th_mm(basegfx::B2DPolyPolygon& rPolyPolygon) cons
{
    DBG_TESTSOLARMUTEX();
    MapUnit eMapUnit = MapUnit::Map100thMM;
    if(HasSdrObject())
    if(mpModel)
    {
        eMapUnit = GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetMetric(0);
        eMapUnit = mpModel->GetItemPool().GetMetric(0);
        if(eMapUnit != MapUnit::Map100thMM)
        {
            switch(eMapUnit)
@@ -619,15 +651,15 @@ void SvxItemPropertySet_ObtainSettingsFromPropertySet(const SvxItemPropertySet& 
void SvxShape::ObtainSettingsFromPropertySet(const SvxItemPropertySet& rPropSet)
{
    DBG_TESTSOLARMUTEX();
    if(HasSdrObject() && rPropSet.AreThereOwnUsrAnys())
    if(mpObj.is() && rPropSet.AreThereOwnUsrAnys() && mpModel)
    {
        SfxItemSet aSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(), svl::Items<SDRATTR_START, SDRATTR_END>{});
        SfxItemSet aSet( mpModel->GetItemPool(), svl::Items<SDRATTR_START, SDRATTR_END>{});
        Reference< beans::XPropertySet > xShape( static_cast<OWeakObject*>(this), UNO_QUERY );
        SvxItemPropertySet_ObtainSettingsFromPropertySet(rPropSet, aSet, xShape, &mpPropSet->getPropertyMap() );

        GetSdrObject()->SetMergedItemSetAndBroadcast(aSet);
        mpObj->SetMergedItemSetAndBroadcast(aSet);

        GetSdrObject()->ApplyNotPersistAttr( aSet );
        mpObj->ApplyNotPersistAttr( aSet );
    }
}

@@ -636,21 +668,20 @@ uno::Any SvxShape::GetBitmap( bool bMetaFile /* = false */ ) const
    DBG_TESTSOLARMUTEX();
    uno::Any aAny;

    if( !HasSdrObject() || !GetSdrObject()->IsInserted() || nullptr == GetSdrObject()->GetPage() )
    if( !mpObj.is() || mpModel == nullptr || !mpObj->IsInserted() || nullptr == mpObj->GetPage() )
        return aAny;

    ScopedVclPtrInstance< VirtualDevice > pVDev;
    pVDev->SetMapMode(MapMode(MapUnit::Map100thMM));
    SdrPage* pPage = GetSdrObject()->GetPage();

    std::unique_ptr<E3dView> pView(
        new E3dView(
            GetSdrObject()->getSdrModelFromSdrObject(),
            pVDev.get()));
    SdrModel* pModel = mpObj->GetModel();
    SdrPage* pPage = mpObj->GetPage();

    std::unique_ptr<E3dView> pView(new E3dView( pModel, pVDev.get() ));
    pView->hideMarkHandles();
    SdrPageView* pPageView = pView->ShowSdrPage(pPage);

    SdrObject *pTempObj = GetSdrObject();
    SdrObject *pTempObj = mpObj.get();
    pView->MarkObj(pTempObj,pPageView);

    tools::Rectangle aRect(pTempObj->GetCurrentBoundRect());
@@ -980,7 +1011,7 @@ uno::Sequence< sal_Int8 > SAL_CALL SvxShape::getImplementationId()
void SvxShape::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()
{
    DBG_TESTSOLARMUTEX();
    if( !HasSdrObject() )
    if( !mpObj.is() )
        return;

    // #i55919# SdrHintKind::ObjectChange is only interesting if it's for this object
@@ -988,14 +1019,13 @@ void SvxShape::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()
    const SdrHint* pSdrHint = dynamic_cast<const SdrHint*>(&rHint);
    if (!pSdrHint ||
        ((pSdrHint->GetKind() != SdrHintKind::ModelCleared) &&
         (pSdrHint->GetKind() != SdrHintKind::ObjectChange || pSdrHint->GetObject() != GetSdrObject() )))
         (pSdrHint->GetKind() != SdrHintKind::ObjectChange || pSdrHint->GetObject() != mpObj.get() )))
        return;

    uno::Reference< uno::XInterface > xSelf( GetSdrObject()->getWeakUnoShape() );
    uno::Reference< uno::XInterface > xSelf( mpObj->getWeakUnoShape() );
    if( !xSelf.is() )
    {
        EndListening(GetSdrObject()->getSdrModelFromSdrObject());
        mpSdrObjectWeakReference.reset( nullptr );
        mpObj.reset( nullptr );
        return;
    }

@@ -1011,6 +1041,7 @@ void SvxShape::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()
        case SdrHintKind::ModelCleared:
        {
            bClearMe = true;
            mpModel = nullptr;
            break;
        }
        default:
@@ -1019,30 +1050,13 @@ void SvxShape::Notify( SfxBroadcaster&, const SfxHint& rHint ) throw()

    if( bClearMe )
    {
        SdrObject* pSdrObject(GetSdrObject());

        if(!HasSdrObjectOwnership())
        {
            if(nullptr != pSdrObject)
            {
                EndListening(pSdrObject->getSdrModelFromSdrObject());
                pSdrObject->setUnoShape(nullptr);
            }

            mpSdrObjectWeakReference.reset(nullptr);

            // SdrModel *is* going down, try to Free SdrObject even
            // when !HasSdrObjectOwnership
            if(nullptr != pSdrObject && !pSdrObject->IsInserted())
            {
                SdrObject::Free(pSdrObject);
            }
        if( !HasSdrObjectOwnership() ) {
            if( mpObj.is() )
                mpObj->setUnoShape( nullptr );
            mpObj.reset( nullptr );
        }

        if(!mpImpl->mbDisposing)
        {
        if ( !mpImpl->mbDisposing )
            dispose();
        }
    }
}

@@ -1111,14 +1125,14 @@ awt::Point SAL_CALL SvxShape::getPosition()
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
    if( mpObj.is() && mpModel)
    {
        tools::Rectangle aRect( svx_getLogicRectHack(GetSdrObject()) );
        tools::Rectangle aRect( svx_getLogicRectHack(mpObj.get()) );
        Point aPt( aRect.Left(), aRect.Top() );

        // Position is relative to anchor, so recalc to absolute position
        if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
            aPt -= GetSdrObject()->GetAnchorPos();
        if( mpModel->IsWriter() )
            aPt -= mpObj->GetAnchorPos();

        ForceMetricTo100th_mm(aPt);
        return css::awt::Point( aPt.X(), aPt.Y() );
@@ -1134,25 +1148,25 @@ void SAL_CALL SvxShape::setPosition( const awt::Point& Position )
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
    if( mpObj.is() && mpModel )
    {
        // do NOT move 3D objects, this would change the homogen
        // transformation matrix
        if(dynamic_cast<const E3dCompoundObject* >(GetSdrObject()) == nullptr)
        if(dynamic_cast<const E3dCompoundObject* >(mpObj.get()) == nullptr)
        {
            tools::Rectangle aRect( svx_getLogicRectHack(GetSdrObject()) );
            tools::Rectangle aRect( svx_getLogicRectHack(mpObj.get()) );
            Point aLocalPos( Position.X, Position.Y );
            ForceMetricToItemPoolMetric(aLocalPos);

            // Position is absolute, so recalc to position relative to anchor
            if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                aLocalPos += GetSdrObject()->GetAnchorPos();
            if( mpModel->IsWriter() )
                aLocalPos += mpObj->GetAnchorPos();

            long nDX = aLocalPos.X() - aRect.Left();
            long nDY = aLocalPos.Y() - aRect.Top();

            GetSdrObject()->Move( Size( nDX, nDY ) );
            GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
            mpObj->Move( Size( nDX, nDY ) );
            mpModel->SetChanged();
        }
    }

@@ -1164,9 +1178,9 @@ awt::Size SAL_CALL SvxShape::getSize()
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
    if( mpObj.is() && mpModel)
    {
        tools::Rectangle aRect( svx_getLogicRectHack(GetSdrObject()) );
        tools::Rectangle aRect( svx_getLogicRectHack(mpObj.get()) );
        Size aObjSize( aRect.getWidth(), aRect.getHeight() );
        ForceMetricTo100th_mm(aObjSize);
        return css::awt::Size( aObjSize.getWidth(), aObjSize.getHeight() );
@@ -1180,26 +1194,26 @@ void SAL_CALL SvxShape::setSize( const awt::Size& rSize )
{
    ::SolarMutexGuard aGuard;

    if(HasSdrObject())
    if( mpObj.is() && mpModel)
    {
        // #i123539# optimization for 3D chart object generation: do not use UNO
        // API commands to get the range, this is too expensive since for 3D
        // scenes it may recalculate the whole scene since in AOO this depends
        // on the contained geometry (layouted to show all content)
        const bool b3DConstruction(dynamic_cast< E3dObject* >(GetSdrObject()) && GetSdrObject()->getSdrModelFromSdrObject().isLocked());
        const bool b3DConstruction(dynamic_cast< E3dObject* >(mpObj.get()) && mpModel->isLocked());
        tools::Rectangle aRect(
            b3DConstruction ?
                tools::Rectangle(maPosition.X, maPosition.Y, maSize.Width, maSize.Height) :
                svx_getLogicRectHack(GetSdrObject()) );
                svx_getLogicRectHack(mpObj.get()) );
        Size aLocalSize( rSize.Width, rSize.Height );
        ForceMetricToItemPoolMetric(aLocalSize);

        if(GetSdrObject()->GetObjInventor() == SdrInventor::Default && GetSdrObject()->GetObjIdentifier() == OBJ_MEASURE )
        if(mpObj->GetObjInventor() == SdrInventor::Default && mpObj->GetObjIdentifier() == OBJ_MEASURE )
        {
            Fraction aWdt(aLocalSize.Width(),aRect.Right()-aRect.Left());
            Fraction aHgt(aLocalSize.Height(),aRect.Bottom()-aRect.Top());
            Point aPt = GetSdrObject()->GetSnapRect().TopLeft();
            GetSdrObject()->Resize(aPt,aWdt,aHgt);
            Point aPt = mpObj->GetSnapRect().TopLeft();
            mpObj->Resize(aPt,aWdt,aHgt);
        }
        else
        {
@@ -1217,10 +1231,10 @@ void SAL_CALL SvxShape::setSize( const awt::Size& rSize )
            else
                aRect.setHeight(aLocalSize.Height());

            svx_setLogicRectHack( GetSdrObject(), aRect );
            svx_setLogicRectHack( mpObj.get(), aRect );
        }

        GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
        mpModel->SetChanged();
    }
    maSize = rSize;
}
@@ -1230,9 +1244,9 @@ void SAL_CALL SvxShape::setSize( const awt::Size& rSize )
OUString SAL_CALL SvxShape::getName(  )
{
    ::SolarMutexGuard aGuard;
    if( HasSdrObject() )
    if( mpObj.is() )
    {
        return GetSdrObject()->GetName();
        return mpObj->GetName();
    }
    else
    {
@@ -1244,9 +1258,9 @@ OUString SAL_CALL SvxShape::getName(  )
void SAL_CALL SvxShape::setName( const OUString& aName )
{
    ::SolarMutexGuard aGuard;
    if( HasSdrObject() )
    if( mpObj.is() )
    {
        GetSdrObject()->SetName( aName );
        mpObj->SetName( aName );
    }
    else
    {
@@ -1282,42 +1296,47 @@ void SAL_CALL SvxShape::dispose()
    mpImpl->maDisposeListeners.disposeAndClear(aEvt);
    mpImpl->maPropertyNotifier.disposing();

    if ( HasSdrObject() )
    if ( mpObj.is() )
    {
        EndListening( GetSdrObject()->getSdrModelFromSdrObject() );
        bool bFreeSdrObject = false;

        if ( GetSdrObject()->IsInserted() && GetSdrObject()->GetPage() )
        if ( mpObj->IsInserted() && mpObj->GetPage() )
        {
            OSL_ENSURE( HasSdrObjectOwnership(), "SvxShape::dispose: is the below code correct?" );
                // normally, we are allowed to free the SdrObject only if we have its ownership.
                // Why isn't this checked here?

            SdrPage* pPage = GetSdrObject()->GetPage();
            SdrPage* pPage = mpObj->GetPage();
            // delete the SdrObject from the page
            const size_t nCount = pPage->GetObjCount();
            for ( size_t nNum = 0; nNum < nCount; ++nNum )
            {
                if ( pPage->GetObj( nNum ) == GetSdrObject() )
                if ( pPage->GetObj( nNum ) == mpObj.get() )
                {
                    OSL_VERIFY( pPage->RemoveObject( nNum ) == GetSdrObject() );
                    OSL_VERIFY( pPage->RemoveObject( nNum ) == mpObj.get() );
                    bFreeSdrObject = true;
                    break;
                }
            }
        }

        GetSdrObject()->setUnoShape(nullptr);
        mpObj->setUnoShape(nullptr);

        if ( bFreeSdrObject )
        {
            // in case we have the ownership of the SdrObject, a Free
            // would do nothing. So ensure the ownership is reset.
            mpImpl->mbHasSdrObjectOwnership = false;
            SdrObject* pObject = GetSdrObject();
            SdrObject* pObject = mpObj.get();
            SdrObject::Free( pObject );
        }
    }

    if( mpModel )
    {
        EndListening( *mpModel );
        mpModel = nullptr;
    }
}


@@ -1383,20 +1402,19 @@ void SAL_CALL SvxShape::removeVetoableChangeListener( const OUString& , const Re

bool SvxShape::SetFillAttribute( sal_uInt16 nWID, const OUString& rName )
{
    if(HasSdrObject())
    SfxItemSet aSet( mpModel->GetItemPool(),    {{nWID, nWID}} );

    if( SetFillAttribute( nWID, rName, aSet, mpModel ) )
    {
        SfxItemSet aSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(), {{nWID, nWID}} );
        //mpObj->SetItemSetAndBroadcast(aSet);
        mpObj->SetMergedItemSetAndBroadcast(aSet);

        if( SetFillAttribute( nWID, rName, aSet, &GetSdrObject()->getSdrModelFromSdrObject() ) )
        {
            //GetSdrObject()->SetItemSetAndBroadcast(aSet);
            GetSdrObject()->SetMergedItemSetAndBroadcast(aSet);

            return true;
        }
        return true;
    }

    return false;
    else
    {
        return false;
    }
}


@@ -1579,7 +1597,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName);

    if (!HasSdrObject())
    if (!mpObj.is() || !mpModel)
    {
        // Since we have no actual sdr object right now, remember all
        // properties in a list. These properties will be set when the sdr
@@ -1594,7 +1612,6 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
            //        supported after creation.
            mpPropSet->setPropertyValue( pMap, rVal );
        }

        return;
    }

@@ -1609,7 +1626,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
            "Readonly property can't be set: " + rPropertyName,
            uno::Reference<drawing::XShape>(this));

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    mpModel->SetChanged();

    if (setPropertyValueImpl(rPropertyName, pMap, rVal))
        return;
@@ -1631,7 +1648,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
    {
        if( mpImpl->mpItemSet == nullptr )
        {
            pSet = mpImpl->mpItemSet = GetSdrObject()->GetMergedItemSet().Clone();
            pSet = mpImpl->mpItemSet = mpObj->GetMergedItemSet().Clone();
        }
        else
        {
@@ -1640,11 +1657,11 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
    }
    else
    {
        pSet = new SfxItemSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(),  {{pMap->nWID, pMap->nWID}});
        pSet = new SfxItemSet( mpModel->GetItemPool(),  {{pMap->nWID, pMap->nWID}});
    }

    if( pSet->GetItemState( pMap->nWID ) != SfxItemState::SET )
        pSet->Put(GetSdrObject()->GetMergedItem(pMap->nWID));
        pSet->Put(mpObj->GetMergedItem(pMap->nWID));

    if( !SvxUnoTextRangeBase::SetPropertyValueHelper( pMap, rVal, *pSet ))
    {
@@ -1653,7 +1670,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
            if(bIsNotPersist)
            {
                // not-persistent attribute, get those extra
                GetSdrObject()->TakeNotPersistAttr(*pSet);
                mpObj->TakeNotPersistAttr(*pSet);
            }
        }

@@ -1661,7 +1678,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
        {
            // get default from ItemPool
            if(SfxItemPool::IsWhich(pMap->nWID))
                pSet->Put(GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID));
                pSet->Put(mpModel->GetItemPool().GetDefaultItem(pMap->nWID));
        }

        if( pSet->GetItemState( pMap->nWID ) == SfxItemState::SET )
@@ -1673,7 +1690,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
    if(bIsNotPersist)
    {
        // set not-persistent attribute extra
        GetSdrObject()->ApplyNotPersistAttr( *pSet );
        mpObj->ApplyNotPersistAttr( *pSet );
        delete pSet;
    }
    else
@@ -1682,7 +1699,7 @@ void SvxShape::_setPropertyValue( const OUString& rPropertyName, const uno::Any&
        // will be set in setPropertyValues later
        if( !mbIsMultiPropertyCall )
        {
            GetSdrObject()->SetMergedItemSetAndBroadcast( *pSet );
            mpObj->SetMergedItemSetAndBroadcast( *pSet );

            delete pSet;
        }
@@ -1706,7 +1723,7 @@ uno::Any SvxShape::_getPropertyValue( const OUString& PropertyName )
    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);

    uno::Any aAny;
    if(HasSdrObject())
    if( mpObj.is() && mpModel )
    {
        if(pMap == nullptr )
            throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));
@@ -1716,8 +1733,8 @@ uno::Any SvxShape::_getPropertyValue( const OUString& PropertyName )
            DBG_ASSERT( pMap->nWID == SDRATTR_TEXTDIRECTION || (pMap->nWID < SDRATTR_NOTPERSIST_FIRST || pMap->nWID > SDRATTR_NOTPERSIST_LAST), "Not persist item not handled!" );
            DBG_ASSERT( pMap->nWID < OWN_ATTR_VALUE_START || pMap->nWID > OWN_ATTR_VALUE_END, "Not item property not handled!" );

            SfxItemSet aSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(),    {{pMap->nWID, pMap->nWID}});
            aSet.Put(GetSdrObject()->GetMergedItem(pMap->nWID));
            SfxItemSet aSet( mpModel->GetItemPool(),    {{pMap->nWID, pMap->nWID}});
            aSet.Put(mpObj->GetMergedItem(pMap->nWID));

            if(SvxUnoTextRangeBase::GetPropertyValueHelper(  aSet, pMap, aAny ))
                return aAny;
@@ -1727,7 +1744,7 @@ uno::Any SvxShape::_getPropertyValue( const OUString& PropertyName )
                if(pMap->nWID >= SDRATTR_NOTPERSIST_FIRST && pMap->nWID <= SDRATTR_NOTPERSIST_LAST)
                {
                    // not-persistent attribute, get those extra
                    GetSdrObject()->TakeNotPersistAttr(aSet);
                    mpObj->TakeNotPersistAttr(aSet);
                }
            }

@@ -1735,7 +1752,7 @@ uno::Any SvxShape::_getPropertyValue( const OUString& PropertyName )
            {
                // get default from ItemPool
                if(SfxItemPool::IsWhich(pMap->nWID))
                    aSet.Put(GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID));
                    aSet.Put(mpModel->GetItemPool().GetDefaultItem(pMap->nWID));
            }

            if(aSet.Count())
@@ -1800,8 +1817,8 @@ void SAL_CALL SvxShape::setPropertyValues( const css::uno::Sequence< OUString >&
        }
    }

    if( mpImpl->mpItemSet && HasSdrObject() )
        GetSdrObject()->SetMergedItemSetAndBroadcast( *mpImpl->mpItemSet );
    if( mpImpl->mpItemSet && mpObj.is() )
        mpObj->SetMergedItemSetAndBroadcast( *mpImpl->mpItemSet );
}


@@ -1903,10 +1920,10 @@ uno::Any SvxShape::GetAnyForItem( SfxItemSet const & aSet, const SfxItemProperty

    case SDRATTR_CIRCKIND:
    {
        if( GetSdrObject()->GetObjInventor() == SdrInventor::Default)
        if( mpObj->GetObjInventor() == SdrInventor::Default)
        {
            drawing::CircleKind eKind;
            switch(GetSdrObject()->GetObjIdentifier())
            switch(mpObj->GetObjIdentifier())
            {
            case OBJ_CIRC:          // circle, ellipse
                eKind = drawing::CircleKind_FULL;
@@ -1971,13 +1988,13 @@ beans::PropertyState SvxShape::_getPropertyState( const OUString& PropertyName )

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName);

    if( !HasSdrObject() || pMap == nullptr )
    if( !mpObj.is() || pMap == nullptr )
        throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));

    beans::PropertyState eState;
    if( !getPropertyStateImpl( pMap, eState ) )
    {
        const SfxItemSet& rSet = GetSdrObject()->GetMergedItemSet();
        const SfxItemSet& rSet = mpObj->GetMergedItemSet();

        switch( rSet.GetItemState( pMap->nWID, false ) )
        {
@@ -2046,7 +2063,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            // #90763# position is relative to top left, make it absolute
            basegfx::B2DPolyPolygon aNewPolyPolygon;
            basegfx::B2DHomMatrix aNewHomogenMatrix;
            GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
            mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);

            aVclPoint.AdjustX(basegfx::fround(aNewHomogenMatrix.get(0, 2)) );
            aVclPoint.AdjustY(basegfx::fround(aNewHomogenMatrix.get(1, 2)) );
@@ -2055,12 +2072,12 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            ForceMetricToItemPoolMetric(aVclPoint);

            // #88491# position relative to anchor
            if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
            if( mpModel->IsWriter() )
            {
                aVclPoint += GetSdrObject()->GetAnchorPos();
                aVclPoint += mpObj->GetAnchorPos();
            }

            static_cast<SdrCaptionObj*>(GetSdrObject())->SetTailPos(aVclPoint);
            static_cast<SdrCaptionObj*>(mpObj.get())->SetTailPos(aVclPoint);

            return true;
        }
@@ -2074,7 +2091,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            basegfx::B2DPolyPolygon aNewPolyPolygon;
            basegfx::B2DHomMatrix aNewHomogenMatrix;

            GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
            mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);

            aNewHomogenMatrix.set(0, 0, aMatrix.Line1.Column1);
            aNewHomogenMatrix.set(0, 1, aMatrix.Line1.Column2);
@@ -2086,7 +2103,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            aNewHomogenMatrix.set(2, 1, aMatrix.Line3.Column2);
            aNewHomogenMatrix.set(2, 2, aMatrix.Line3.Column3);

            GetSdrObject()->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
            mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
            return true;
        }
        break;
@@ -2097,12 +2114,12 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        sal_Int32 nNewOrdNum = 0;
        if(rValue >>= nNewOrdNum)
        {
            SdrObjList* pObjList = GetSdrObject()->GetObjList();
            SdrObjList* pObjList = mpObj->GetObjList();
            if( pObjList )
            {
                SdrObject* pCheck =
                            pObjList->SetObjectOrdNum( GetSdrObject()->GetOrdNum(), static_cast<size_t>(nNewOrdNum) );
                DBG_ASSERT( pCheck == GetSdrObject(), "GetOrdNum() failed!" );
                            pObjList->SetObjectOrdNum( mpObj->GetOrdNum(), static_cast<size_t>(nNewOrdNum) );
                DBG_ASSERT( pCheck == mpObj.get(), "GetOrdNum() failed!" );
            }
            return true;
        }
@@ -2120,7 +2137,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            tools::Rectangle aRect;
            aRect.SetPos(aTopLeft);
            aRect.SetSize(aObjSize);
            GetSdrObject()->SetSnapRect(aRect);
            mpObj->SetSnapRect(aRect);
            return true;
        }
        break;
@@ -2130,7 +2147,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        bool bMirror;
        if(rValue >>= bMirror )
        {
            SdrGrafObj* pObj = dynamic_cast< SdrGrafObj* >( GetSdrObject() );
            SdrGrafObj* pObj = dynamic_cast< SdrGrafObj* >( mpObj.get() );
            if( pObj )
                pObj->SetMirrored(bMirror);
            return true;
@@ -2145,7 +2162,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    case OWN_ATTR_EDGE_END_POS:
    case OWN_ATTR_EDGE_POLYPOLYGONBEZIER:
    {
        SdrEdgeObj* pEdgeObj = dynamic_cast< SdrEdgeObj* >(GetSdrObject());
        SdrEdgeObj* pEdgeObj = dynamic_cast< SdrEdgeObj* >(mpObj.get());
        if(pEdgeObj)
        {
            switch(pProperty->nWID)
@@ -2179,8 +2196,8 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
                        // perform metric change before applying anchor position,
                        // because the anchor position is in pool metric.
                        ForceMetricToItemPoolMetric( aPoint );
                        if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                            aPoint += GetSdrObject()->GetAnchorPos();
                        if( mpModel->IsWriter() )
                            aPoint += mpObj->GetAnchorPos();

                        pEdgeObj->SetTailPoint( pProperty->nWID == OWN_ATTR_EDGE_START_POS, aPoint );
                        return true;
@@ -2221,9 +2238,9 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
                    {
                        // Reintroduction of fix for issue i59051 (#i108851#)
                        ForceMetricToItemPoolMetric( aNewPolyPolygon );
                        if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                        if( mpModel->IsWriter() )
                        {
                            Point aPoint( GetSdrObject()->GetAnchorPos() );
                            Point aPoint( mpObj->GetAnchorPos() );
                            aNewPolyPolygon.transform(basegfx::utils::createTranslateB2DHomMatrix(aPoint.X(), aPoint.Y()));
                        }
                        pEdgeObj->SetEdgeTrackPath( aNewPolyPolygon );
@@ -2237,7 +2254,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    case OWN_ATTR_MEASURE_START_POS:
    case OWN_ATTR_MEASURE_END_POS:
    {
        SdrMeasureObj* pMeasureObj = dynamic_cast< SdrMeasureObj* >(GetSdrObject());
        SdrMeasureObj* pMeasureObj = dynamic_cast< SdrMeasureObj* >(mpObj.get());
        awt::Point aUnoPoint;
        if(pMeasureObj && ( rValue >>= aUnoPoint ) )
        {
@@ -2245,8 +2262,8 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

            // Reintroduction of fix for issue #i59051# (#i108851#)
            ForceMetricToItemPoolMetric( aPoint );
            if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                aPoint += GetSdrObject()->GetAnchorPos();
            if( mpModel->IsWriter() )
                aPoint += mpObj->GetAnchorPos();

            pMeasureObj->NbcSetPoint( aPoint, pProperty->nWID == OWN_ATTR_MEASURE_START_POS ? 0 : 1 );
            pMeasureObj->SetChanged();
@@ -2266,8 +2283,8 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

                eMode = static_cast<drawing::BitmapMode>(nMode);
            }
            GetSdrObject()->SetMergedItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
            GetSdrObject()->SetMergedItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
            mpObj->SetMergedItem( XFillBmpStretchItem( eMode == drawing::BitmapMode_STRETCH ) );
            mpObj->SetMergedItem( XFillBmpTileItem( eMode == drawing::BitmapMode_REPEAT ) );
            return true;
        }

@@ -2276,10 +2293,10 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        sal_Int16 nLayerId = sal_Int16();
        if( rValue >>= nLayerId )
        {
            SdrLayer* pLayer = GetSdrObject()->getSdrModelFromSdrObject().GetLayerAdmin().GetLayerPerID(SdrLayerID(nLayerId));
            SdrLayer* pLayer = mpModel->GetLayerAdmin().GetLayerPerID(SdrLayerID(nLayerId));
            if( pLayer )
            {
                GetSdrObject()->SetLayer(SdrLayerID(nLayerId));
                mpObj->SetLayer(SdrLayerID(nLayerId));
                return true;
            }
        }
@@ -2291,10 +2308,10 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        OUString aLayerName;
        if( rValue >>= aLayerName )
        {
            const SdrLayer* pLayer = GetSdrObject()->getSdrModelFromSdrObject().GetLayerAdmin().GetLayer(aLayerName);
            const SdrLayer* pLayer=mpModel->GetLayerAdmin().GetLayer(aLayerName);
            if( pLayer != nullptr )
            {
                GetSdrObject()->SetLayer( pLayer->GetID() );
                mpObj->SetLayer( pLayer->GetID() );
                return true;
            }
        }
@@ -2305,13 +2322,13 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        sal_Int32 nAngle = 0;
        if( rValue >>= nAngle )
        {
            Point aRef1(GetSdrObject()->GetSnapRect().Center());
            nAngle -= GetSdrObject()->GetRotateAngle();
            Point aRef1(mpObj->GetSnapRect().Center());
            nAngle -= mpObj->GetRotateAngle();
            if (nAngle!=0)
            {
                double nSin=sin(nAngle*nPi180);
                double nCos=cos(nAngle*nPi180);
                GetSdrObject()->Rotate(aRef1,nAngle,nSin,nCos);
                mpObj->Rotate(aRef1,nAngle,nSin,nCos);
            }
            return true;
        }
@@ -2324,12 +2341,12 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        sal_Int32 nShear = 0;
        if( rValue >>= nShear )
        {
            nShear -= GetSdrObject()->GetShearAngle();
            nShear -= mpObj->GetShearAngle();
            if(nShear != 0 )
            {
                Point aRef1(GetSdrObject()->GetSnapRect().Center());
                Point aRef1(mpObj->GetSnapRect().Center());
                double nTan=tan(nShear*nPi180);
                GetSdrObject()->Shear(aRef1,nShear,nTan,false);
                mpObj->Shear(aRef1,nShear,nTan,false);
                return true;
            }
        }
@@ -2339,7 +2356,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_INTEROPGRABBAG:
    {
        GetSdrObject()->SetGrabBagItem(rValue);
        mpObj->SetGrabBagItem(rValue);
        return true;
    }

@@ -2348,7 +2365,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        bool bMoveProtect;
        if( rValue >>= bMoveProtect )
        {
            GetSdrObject()->SetMoveProtect(bMoveProtect);
            mpObj->SetMoveProtect(bMoveProtect);
            return true;
        }
        break;
@@ -2358,7 +2375,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        OUString aName;
        if( rValue >>= aName )
        {
            GetSdrObject()->SetName( aName );
            mpObj->SetName( aName );
            return true;
        }
        break;
@@ -2370,7 +2387,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        OUString aTitle;
        if( rValue >>= aTitle )
        {
            GetSdrObject()->SetTitle( aTitle );
            mpObj->SetTitle( aTitle );
            return true;
        }
        break;
@@ -2380,7 +2397,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        OUString aDescription;
        if( rValue >>= aDescription )
        {
            GetSdrObject()->SetDescription( aDescription );
            mpObj->SetDescription( aDescription );
            return true;
        }
        break;
@@ -2391,7 +2408,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        bool bPrintable;
        if( rValue >>= bPrintable )
        {
            GetSdrObject()->SetPrintable(bPrintable);
            mpObj->SetPrintable(bPrintable);
            return true;
        }
        break;
@@ -2401,7 +2418,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        bool bVisible;
        if( rValue >>= bVisible )
        {
            GetSdrObject()->SetVisible(bVisible);
            mpObj->SetVisible(bVisible);
            return true;
        }
        break;
@@ -2411,7 +2428,7 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        bool bResizeProtect;
        if( rValue >>= bResizeProtect )
        {
            GetSdrObject()->SetResizeProtect(bResizeProtect);
            mpObj->SetResizeProtect(bResizeProtect);
            return true;
        }
        break;
@@ -2421,16 +2438,19 @@ bool SvxShape::setPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        sal_Int32 nPageNum = 0;
        if( (rValue >>= nPageNum) && ( nPageNum >= 0 ) && ( nPageNum <= 0xffff ) )
        {
            SdrPageObj* pPageObj = dynamic_cast< SdrPageObj* >(GetSdrObject());
            SdrPageObj* pPageObj = dynamic_cast< SdrPageObj* >(mpObj.get());
            if( pPageObj )
            {
                SdrModel& rModel(pPageObj->getSdrModelFromSdrObject());
                SdrModel* pModel = pPageObj->GetModel();
                SdrPage* pNewPage = nullptr;
                const sal_uInt16 nDestinationPageNum(static_cast<sal_uInt16>((nPageNum << 1) - 1));

                if(nDestinationPageNum < rModel.GetPageCount())
                if(pModel)
                {
                    pNewPage = rModel.GetPage(nDestinationPageNum);
                    if(nDestinationPageNum < pModel->GetPageCount())
                    {
                        pNewPage = pModel->GetPage(nDestinationPageNum);
                    }
                }

                pPageObj->SetReferencedPage(pNewPage);
@@ -2478,12 +2498,12 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    {
    case OWN_ATTR_CAPTION_POINT:
    {
        Point aVclPoint = static_cast<SdrCaptionObj*>(GetSdrObject())->GetTailPos();
        Point aVclPoint = static_cast<SdrCaptionObj*>(mpObj.get())->GetTailPos();

        // #88491# make pos relative to anchor
        if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
        if( mpModel->IsWriter() )
        {
            aVclPoint -= GetSdrObject()->GetAnchorPos();
            aVclPoint -= mpObj->GetAnchorPos();
        }

        // #88657# metric of pool maybe twips (writer)
@@ -2492,7 +2512,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        // #90763# pos is absolute, make it relative to top left
        basegfx::B2DPolyPolygon aNewPolyPolygon;
        basegfx::B2DHomMatrix aNewHomogenMatrix;
        GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
        mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);

        aVclPoint.AdjustX( -(basegfx::fround(aNewHomogenMatrix.get(0, 2))) );
        aVclPoint.AdjustY( -(basegfx::fround(aNewHomogenMatrix.get(1, 2))) );
@@ -2506,7 +2526,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    {
        basegfx::B2DPolyPolygon aNewPolyPolygon;
        basegfx::B2DHomMatrix aNewHomogenMatrix;
        GetSdrObject()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
        mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
        drawing::HomogenMatrix3 aMatrix;

        aMatrix.Line1.Column1 = aNewHomogenMatrix.get(0, 0);
@@ -2526,7 +2546,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_ZORDER:
    {
        rValue <<= static_cast<sal_Int32>(GetSdrObject()->GetOrdNum());
        rValue <<= static_cast<sal_Int32>(mpObj->GetOrdNum());
        break;
    }

@@ -2541,13 +2561,13 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_ISFONTWORK:
    {
        rValue <<= dynamic_cast<const SdrTextObj*>(GetSdrObject()) != nullptr && static_cast<SdrTextObj*>(GetSdrObject())->IsFontwork();
        rValue <<= dynamic_cast<const SdrTextObj*>(mpObj.get()) != nullptr && static_cast<SdrTextObj*>(mpObj.get())->IsFontwork();
        break;
    }

    case OWN_ATTR_FRAMERECT:
    {
        tools::Rectangle aRect( GetSdrObject()->GetSnapRect() );
        tools::Rectangle aRect( mpObj->GetSnapRect() );
        Point aTopLeft( aRect.TopLeft() );
        Size aObjSize( aRect.GetWidth(), aRect.GetHeight() );
        ForceMetricTo100th_mm(aTopLeft);
@@ -2561,7 +2581,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_BOUNDRECT:
    {
        tools::Rectangle aRect( GetSdrObject()->GetCurrentBoundRect() );
        tools::Rectangle aRect( mpObj->GetCurrentBoundRect() );
        Point aTopLeft( aRect.TopLeft() );
        Size aObjSize( aRect.GetWidth(), aRect.GetHeight() );
        ForceMetricTo100th_mm(aTopLeft);
@@ -2575,7 +2595,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_LDNAME:
    {
        OUString aName( GetSdrObject()->GetName() );
        OUString aName( mpObj->GetName() );
        rValue <<= aName;
        break;
    }
@@ -2583,11 +2603,11 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    case OWN_ATTR_LDBITMAP:
    {
        OUString sId;
        if( GetSdrObject()->GetObjInventor() == SdrInventor::Default && GetSdrObject()->GetObjIdentifier() == OBJ_OLE2 )
        if( mpObj->GetObjInventor() == SdrInventor::Default && mpObj->GetObjIdentifier() == OBJ_OLE2 )
        {
            sId = RID_UNODRAW_OLE2;
        }
        else if( GetSdrObject()->GetObjInventor() == SdrInventor::Default && GetSdrObject()->GetObjIdentifier() == OBJ_GRAF )
        else if( mpObj->GetObjInventor() == SdrInventor::Default && mpObj->GetObjIdentifier() == OBJ_GRAF )
        {
            sId = RID_UNODRAW_GRAPHICS;
        }
@@ -2606,8 +2626,8 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    case OWN_ATTR_MIRRORED:
    {
        bool bMirror = false;
        if( HasSdrObject() && dynamic_cast<const SdrGrafObj*>(GetSdrObject()) != nullptr )
            bMirror = static_cast<SdrGrafObj*>(GetSdrObject())->IsMirrored();
        if( mpObj.is() && dynamic_cast<const SdrGrafObj*>(mpObj.get()) != nullptr )
            bMirror = static_cast<SdrGrafObj*>(mpObj.get())->IsMirrored();

        rValue <<= bMirror;
        break;
@@ -2621,7 +2641,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    case OWN_ATTR_GLUEID_TAIL:
    case OWN_ATTR_EDGE_POLYPOLYGONBEZIER:
    {
        SdrEdgeObj* pEdgeObj = dynamic_cast<SdrEdgeObj*>(GetSdrObject());
        SdrEdgeObj* pEdgeObj = dynamic_cast<SdrEdgeObj*>(mpObj.get());
        if(pEdgeObj)
        {
            switch(pProperty->nWID)
@@ -2644,8 +2664,8 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            case OWN_ATTR_EDGE_END_POS:
                {
                    Point aPoint( pEdgeObj->GetTailPoint( pProperty->nWID == OWN_ATTR_EDGE_START_POS ) );
                    if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                        aPoint -= GetSdrObject()->GetAnchorPos();
                    if( mpModel->IsWriter() )
                        aPoint -= mpObj->GetAnchorPos();

                    ForceMetricTo100th_mm( aPoint );
                    awt::Point aUnoPoint( aPoint.X(), aPoint.Y() );
@@ -2662,9 +2682,9 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
            case OWN_ATTR_EDGE_POLYPOLYGONBEZIER:
                {
                    basegfx::B2DPolyPolygon aPolyPoly( pEdgeObj->GetEdgeTrackPath() );
                    if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                    if( mpModel->IsWriter() )
                    {
                        Point aPoint( GetSdrObject()->GetAnchorPos() );
                        Point aPoint( mpObj->GetAnchorPos() );
                        aPolyPoly.transform(basegfx::utils::createTranslateB2DHomMatrix(-aPoint.X(), -aPoint.Y()));
                    }
                    // Reintroduction of fix for issue #i59051# (#i108851#)
@@ -2682,12 +2702,12 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    case OWN_ATTR_MEASURE_START_POS:
    case OWN_ATTR_MEASURE_END_POS:
    {
        SdrMeasureObj* pMeasureObj = dynamic_cast<SdrMeasureObj*>(GetSdrObject());
        SdrMeasureObj* pMeasureObj = dynamic_cast<SdrMeasureObj*>(mpObj.get());
        if(pMeasureObj)
        {
            Point aPoint( pMeasureObj->GetPoint( pProperty->nWID == OWN_ATTR_MEASURE_START_POS ? 0 : 1 ) );
            if( GetSdrObject()->getSdrModelFromSdrObject().IsWriter() )
                aPoint -= GetSdrObject()->GetAnchorPos();
            if( mpModel->IsWriter() )
                aPoint -= mpObj->GetAnchorPos();

            // Reintroduction of fix for issue #i59051# (#i108851#)
            ForceMetricTo100th_mm( aPoint );
@@ -2701,7 +2721,7 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_FILLBMP_MODE:
    {
        const SfxItemSet& rObjItemSet = GetSdrObject()->GetMergedItemSet();
        const SfxItemSet& rObjItemSet = mpObj->GetMergedItemSet();

        const XFillBmpStretchItem* pStretchItem = &rObjItemSet.Get(XATTR_FILLBMP_STRETCH);
        const XFillBmpTileItem* pTileItem = &rObjItemSet.Get(XATTR_FILLBMP_TILE);
@@ -2721,12 +2741,12 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
        break;
    }
    case SDRATTR_LAYERID:
        rValue <<= sal_uInt16(sal_uInt8(GetSdrObject()->GetLayer()));
        rValue <<= sal_uInt16(sal_uInt8(mpObj->GetLayer()));
        break;

    case SDRATTR_LAYERNAME:
    {
        SdrLayer* pLayer = GetSdrObject()->getSdrModelFromSdrObject().GetLayerAdmin().GetLayerPerID(GetSdrObject()->GetLayer());
        SdrLayer* pLayer = mpModel->GetLayerAdmin().GetLayerPerID(mpObj->GetLayer());
        if( pLayer )
        {
            OUString aName( pLayer->GetName() );
@@ -2736,26 +2756,26 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    }

    case SDRATTR_ROTATEANGLE:
        rValue <<= static_cast<sal_Int32>(GetSdrObject()->GetRotateAngle());
        rValue <<= static_cast<sal_Int32>(mpObj->GetRotateAngle());
        break;

    case SDRATTR_SHEARANGLE:
        rValue <<= static_cast<sal_Int32>(GetSdrObject()->GetShearAngle());
        rValue <<= static_cast<sal_Int32>(mpObj->GetShearAngle());
        break;

    case OWN_ATTR_INTEROPGRABBAG:
    {
        GetSdrObject()->GetGrabBagItem(rValue);
        mpObj->GetGrabBagItem(rValue);
        break;
    }

    case SDRATTR_OBJMOVEPROTECT:
        rValue <<= GetSdrObject()->IsMoveProtect();
        rValue <<= mpObj->IsMoveProtect();
        break;

    case SDRATTR_OBJECTNAME:
    {
        OUString aName( GetSdrObject()->GetName() );
        OUString aName( mpObj->GetName() );
        rValue <<= aName;
        break;
    }
@@ -2763,33 +2783,33 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl
    // #i68101#
    case OWN_ATTR_MISC_OBJ_TITLE:
    {
        OUString aTitle( GetSdrObject()->GetTitle() );
        OUString aTitle( mpObj->GetTitle() );
        rValue <<= aTitle;
        break;
    }

    case OWN_ATTR_MISC_OBJ_DESCRIPTION:
    {
        OUString aDescription( GetSdrObject()->GetDescription() );
        OUString aDescription( mpObj->GetDescription() );
        rValue <<= aDescription;
        break;
    }

    case SDRATTR_OBJPRINTABLE:
        rValue <<= GetSdrObject()->IsPrintable();
        rValue <<= mpObj->IsPrintable();
        break;

    case SDRATTR_OBJVISIBLE:
        rValue <<= GetSdrObject()->IsVisible();
        rValue <<= mpObj->IsVisible();
        break;

    case SDRATTR_OBJSIZEPROTECT:
        rValue <<= GetSdrObject()->IsResizeProtect();
        rValue <<= mpObj->IsResizeProtect();
        break;

    case OWN_ATTR_PAGE_NUMBER:
    {
        SdrPageObj* pPageObj = dynamic_cast<SdrPageObj*>(GetSdrObject());
        SdrPageObj* pPageObj = dynamic_cast<SdrPageObj*>(mpObj.get());
        if(pPageObj)
        {
            SdrPage* pPage = pPageObj->GetReferencedPage();
@@ -2803,18 +2823,18 @@ bool SvxShape::getPropertyValueImpl( const OUString&, const SfxItemPropertySimpl

    case OWN_ATTR_UINAME_SINGULAR:
    {
        rValue <<= GetSdrObject()->TakeObjNameSingul();
        rValue <<= mpObj->TakeObjNameSingul();
        break;
    }

    case OWN_ATTR_UINAME_PLURAL:
    {
        rValue <<= GetSdrObject()->TakeObjNamePlural();
        rValue <<= mpObj->TakeObjNamePlural();
        break;
    }
    case OWN_ATTR_METAFILE:
    {
        SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(GetSdrObject());
        SdrOle2Obj* pObj = dynamic_cast<SdrOle2Obj*>(mpObj.get());
        if( pObj )
        {
            const Graphic* pGraphic = pObj->GetGraphic();
@@ -2863,7 +2883,7 @@ bool SvxShape::getPropertyStateImpl( const SfxItemPropertySimpleEntry* pProperty
{
    if( pProperty->nWID == OWN_ATTR_FILLBMP_MODE )
    {
        const SfxItemSet& rSet = GetSdrObject()->GetMergedItemSet();
        const SfxItemSet& rSet = mpObj->GetMergedItemSet();

        if( rSet.GetItemState( XATTR_FILLBMP_STRETCH, false ) == SfxItemState::SET ||
            rSet.GetItemState( XATTR_FILLBMP_TILE, false ) == SfxItemState::SET )
@@ -2893,8 +2913,8 @@ bool SvxShape::setPropertyToDefaultImpl( const SfxItemPropertySimpleEntry* pProp
{
    if( pProperty->nWID == OWN_ATTR_FILLBMP_MODE )
    {
        GetSdrObject()->ClearMergedItem( XATTR_FILLBMP_STRETCH );
        GetSdrObject()->ClearMergedItem( XATTR_FILLBMP_TILE );
        mpObj->ClearMergedItem( XATTR_FILLBMP_STRETCH );
        mpObj->ClearMergedItem( XATTR_FILLBMP_TILE );
        return true;
    }
    else if((pProperty->nWID >= OWN_ATTR_VALUE_START && pProperty->nWID <= OWN_ATTR_VALUE_END ) ||
@@ -2942,15 +2962,15 @@ void SvxShape::_setPropertyToDefault( const OUString& PropertyName )

    const SfxItemPropertySimpleEntry* pProperty = mpPropSet->getPropertyMapEntry(PropertyName);

    if( !HasSdrObject() || pProperty == nullptr )
    if( !mpObj.is() || mpModel == nullptr || pProperty == nullptr )
        throw beans::UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this));

    if( !setPropertyToDefaultImpl( pProperty ) )
    {
        GetSdrObject()->ClearMergedItem( pProperty->nWID );
        mpObj->ClearMergedItem( pProperty->nWID );
    }

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    mpModel->SetChanged();
}


@@ -2972,7 +2992,7 @@ uno::Any SvxShape::_getPropertyDefault( const OUString& aPropertyName )

    const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName);

    if( !HasSdrObject() || pMap == nullptr )
    if( !mpObj.is() || pMap == nullptr || mpModel == nullptr )
        throw beans::UnknownPropertyException( aPropertyName, static_cast<cppu::OWeakObject*>(this));

    if(( pMap->nWID >= OWN_ATTR_VALUE_START && pMap->nWID <= OWN_ATTR_VALUE_END ) ||
@@ -2985,8 +3005,8 @@ uno::Any SvxShape::_getPropertyDefault( const OUString& aPropertyName )
    if(!SfxItemPool::IsWhich(pMap->nWID))
        throw beans::UnknownPropertyException( "No WhichID " + OUString::number(pMap->nWID) + " for " + aPropertyName, static_cast<cppu::OWeakObject*>(this));

    SfxItemSet aSet( GetSdrObject()->getSdrModelFromSdrObject().GetItemPool(),    {{pMap->nWID, pMap->nWID}});
    aSet.Put(GetSdrObject()->getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID));
    SfxItemSet aSet( mpModel->GetItemPool(),    {{pMap->nWID, pMap->nWID}});
    aSet.Put(mpModel->GetItemPool().GetDefaultItem(pMap->nWID));

    return GetAnyForItem( aSet, pMap );
}
@@ -2996,15 +3016,15 @@ void SvxShape::setAllPropertiesToDefault()
{
    ::SolarMutexGuard aGuard;

    if( !HasSdrObject() )
    if( !mpObj.is() )
        throw lang::DisposedException();
    GetSdrObject()->ClearMergedItem(); // nWhich == 0 => all
    mpObj->ClearMergedItem(); // nWhich == 0 => all

    if(dynamic_cast<const SdrGrafObj*>(GetSdrObject()) != nullptr)
    if(dynamic_cast<const SdrGrafObj*>(mpObj.get()) != nullptr)
    {
        // defaults for graphic objects have changed:
        GetSdrObject()->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
        GetSdrObject()->SetMergedItem( XLineStyleItem( drawing::LineStyle_NONE ) );
        mpObj->SetMergedItem( XFillStyleItem( drawing::FillStyle_NONE ) );
        mpObj->SetMergedItem( XLineStyleItem( drawing::LineStyle_NONE ) );
    }

    // #i68523# special handling for Svx3DCharacterModeItem, this is not saved
@@ -3012,12 +3032,13 @@ void SvxShape::setAllPropertiesToDefault()
    // does not load lathe or extrude objects, it is possible to set the items
    // here.
    // For other solution possibilities, see task description.
    if( dynamic_cast<const E3dLatheObj* >(GetSdrObject())  != nullptr|| dynamic_cast<const E3dExtrudeObj* >(GetSdrObject()) != nullptr)
    if( dynamic_cast<const E3dLatheObj* >(mpObj.get())  != nullptr|| dynamic_cast<const E3dExtrudeObj* >(mpObj.get()) != nullptr)
    {
        GetSdrObject()->SetMergedItem(Svx3DCharacterModeItem(true));
        mpObj->SetMergedItem(Svx3DCharacterModeItem(true));
    }

    GetSdrObject()->getSdrModelFromSdrObject().SetChanged();
    if (mpModel)
        mpModel->SetChanged();
}

void SvxShape::setPropertiesToDefault(
@@ -3105,9 +3126,9 @@ uno::Sequence< OUString > SvxShape::_getSupportedServiceNames()
{
    ::SolarMutexGuard aGuard;

    if( HasSdrObject() && GetSdrObject()->GetObjInventor() == SdrInventor::Default)
    if( mpObj.is() && mpObj->GetObjInventor() == SdrInventor::Default)
    {
        const sal_uInt16 nIdent = GetSdrObject()->GetObjIdentifier();
        const sal_uInt16 nIdent = mpObj->GetObjIdentifier();

        switch(nIdent)
        {
@@ -3632,10 +3653,10 @@ uno::Sequence< OUString > SvxShape::_getSupportedServiceNames()
            }
        }
    }
    else if( HasSdrObject() && GetSdrObject()->GetObjInventor() == SdrInventor::FmForm)
    else if( mpObj.is() && mpObj->GetObjInventor() == SdrInventor::FmForm)
    {
#if OSL_DEBUG_LEVEL > 0
        const sal_uInt16 nIdent = GetSdrObject()->GetObjIdentifier();
        const sal_uInt16 nIdent = mpObj->GetObjIdentifier();
        OSL_ENSURE( nIdent == OBJ_UNO, "SvxShape::_getSupportedServiceNames: SdrInventor::FmForm, but no UNO object?" );
#endif
        static uno::Sequence< OUString > *pSeq = nullptr;
@@ -3666,9 +3687,9 @@ uno::Reference< container::XIndexContainer > SAL_CALL SvxShape::getGluePoints()
    ::SolarMutexGuard aGuard;
    uno::Reference< container::XIndexContainer > xGluePoints( mxGluePoints );

    if( HasSdrObject() && !xGluePoints.is() )
    if( mpObj.is() && !xGluePoints.is() )
    {
        uno::Reference< container::XIndexContainer > xNew( SvxUnoGluePointAccess_createInstance( GetSdrObject() ), uno::UNO_QUERY );
        uno::Reference< container::XIndexContainer > xNew( SvxUnoGluePointAccess_createInstance( mpObj.get() ), uno::UNO_QUERY );
        mxGluePoints = xGluePoints = xNew;
    }

@@ -3680,9 +3701,9 @@ uno::Reference<uno::XInterface> SAL_CALL SvxShape::getParent()
{
    ::SolarMutexGuard aGuard;

    if( HasSdrObject() && GetSdrObject()->GetObjList() )
    if( mpObj.is() && mpObj->GetObjList() )
    {
        SdrObjList* pObjList = GetSdrObject()->GetObjList();
        SdrObjList* pObjList = mpObj->GetObjList();

        switch (pObjList->GetListKind())
        {
@@ -3802,7 +3823,7 @@ void SvxShape::updateShapeKind()
        case OBJ_PATHPOLY:
        case OBJ_PATHPLIN:
        {
            const sal_uInt32 nId = GetSdrObject()->GetObjIdentifier();
            const sal_uInt32 nId = mpObj->GetObjIdentifier();

            if( nId != mpImpl->mnObjId )
            {
@@ -3817,7 +3838,7 @@ void SvxShape::updateShapeKind()
SvxShapeText::SvxShapeText(SdrObject* pObject)
: SvxShape( pObject, getSvxMapProvider().GetMap(SVXMAP_TEXT), getSvxMapProvider().GetPropertySet(SVXMAP_TEXT, SdrObject::GetGlobalDrawObjectItemPool()) ), SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
{
    if( pObject )
    if( pObject && pObject->GetModel() )
        SetEditSource( new SvxTextEditSource( pObject, nullptr ) );
}

@@ -3825,7 +3846,7 @@ SvxShapeText::SvxShapeText(SdrObject* pObject)
SvxShapeText::SvxShapeText(SdrObject* pObject, const SfxItemPropertyMapEntry* pPropertyMap, const SvxItemPropertySet* pPropertySet)
: SvxShape( pObject, pPropertyMap, pPropertySet ), SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() )
{
    if( pObject )
    if( pObject && pObject->GetModel() )
        SetEditSource( new SvxTextEditSource( pObject, nullptr ) );
}

@@ -3981,7 +4002,7 @@ bool SvxShapeText::setPropertyValueImpl( const OUString& rName, const SfxItemPro

    if( pProperty->nWID == SDRATTR_TEXTDIRECTION )
    {
        SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( GetSdrObject() );
        SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mpObj.get() );
        if( pTextObj )
        {
            css::text::WritingMode eMode;
@@ -3999,7 +4020,7 @@ bool SvxShapeText::getPropertyValueImpl( const OUString& rName, const SfxItemPro
{
    if( pProperty->nWID == SDRATTR_TEXTDIRECTION )
    {
        SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( GetSdrObject() );
        SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( mpObj.get() );
        if( pTextObj && pTextObj->IsVerticalWriting() )
            rValue <<= css::text::WritingMode_TB_RL;
        else
diff --git a/svx/source/unodraw/unoshtxt.cxx b/svx/source/unodraw/unoshtxt.cxx
index f09305d..4cb601c 100644
--- a/svx/source/unodraw/unoshtxt.cxx
+++ b/svx/source/unodraw/unoshtxt.cxx
@@ -80,11 +80,11 @@ class SvxTextEditSourceImpl : public SfxListener, public SfxBroadcaster, public 
private:
    oslInterlockedCount maRefCount;

    SdrObject*                      mpObject;           // TTTT could be reference (?)
    SdrObject*                      mpObject;
    SdrText*                        mpText;
    SdrView*                        mpView;
    VclPtr<const vcl::Window>       mpWindow;
    SdrModel*                       mpModel;            // TTTT probably not needed -> use SdrModel from SdrObject (?)
    SdrModel*                       mpModel;
    SdrOutliner*                    mpOutliner;
    SvxOutlinerForwarder*           mpTextForwarder;
    SvxDrawOutlinerViewForwarder*   mpViewForwarder;    // if non-NULL, use GetViewModeTextForwarder text forwarder
@@ -147,6 +147,8 @@ public:

    virtual void ObjectInDestruction(const SdrObject& rObject) override;

    void ChangeModel( SdrModel* pNewModel );

    void                    UpdateOutliner();
};

@@ -157,7 +159,7 @@ SvxTextEditSourceImpl::SvxTextEditSourceImpl( SdrObject* pObject, SdrText* pText
    mpText          ( pText ),
    mpView          ( nullptr ),
    mpWindow        ( nullptr ),
    mpModel         ( pObject ? &pObject->getSdrModelFromSdrObject() : nullptr ), // TTTT should be reference
    mpModel         ( pObject ? pObject->GetModel() : nullptr ),
    mpOutliner      ( nullptr ),
    mpTextForwarder ( nullptr ),
    mpViewForwarder ( nullptr ),
@@ -193,7 +195,7 @@ SvxTextEditSourceImpl::SvxTextEditSourceImpl( SdrObject& rObject, SdrText* pText
    mpText          ( pText ),
    mpView          ( &rView ),
    mpWindow        ( &rWindow ),
    mpModel         ( &rObject.getSdrModelFromSdrObject() ), // TTTT should be reference
    mpModel         ( rObject.GetModel() ),
    mpOutliner      ( nullptr ),
    mpTextForwarder ( nullptr ),
    mpViewForwarder ( nullptr ),
@@ -262,6 +264,51 @@ void SvxTextEditSourceImpl::release()
        delete this;
}

void SvxTextEditSourceImpl::ChangeModel( SdrModel* pNewModel )
{
    if( mpModel != pNewModel )
    {
        if( mpModel )
            EndListening( *mpModel );

        if( mpOutliner )
        {
            if( mpModel )
                mpModel->disposeOutliner( mpOutliner );
            else
                delete mpOutliner;
            mpOutliner = nullptr;
        }

        if( mpView )
        {
            EndListening( *mpView );
            mpView = nullptr;
        }

        mpWindow = nullptr;
        m_xLinguServiceManager.clear();

        mpModel = pNewModel;

        if( mpTextForwarder )
        {
            delete mpTextForwarder;
            mpTextForwarder = nullptr;
        }

        if( mpViewForwarder )
        {
            delete mpViewForwarder;
            mpViewForwarder = nullptr;
        }

        if( mpModel )
            StartListening( *mpModel );
    }
}


void SvxTextEditSourceImpl::Notify(SfxBroadcaster& rBC, const SfxHint& rHint)
{
    // #i105988 keep reference to this object
@@ -591,7 +638,7 @@ SvxTextForwarder* SvxTextEditSourceImpl::GetBackgroundTextForwarder()
            bool bVertical = pOutlinerParaObject && pOutlinerParaObject->IsVertical();

            // set objects style sheet on empty outliner
            SfxStyleSheetPool* pPool = static_cast<SfxStyleSheetPool*>(mpObject->getSdrModelFromSdrObject().GetStyleSheetPool());
            SfxStyleSheetPool* pPool = static_cast<SfxStyleSheetPool*>(mpObject->GetModel()->GetStyleSheetPool());
            if( pPool )
                mpOutliner->SetStyleSheetPool( pPool );

@@ -662,7 +709,10 @@ SvxTextForwarder* SvxTextEditSourceImpl::GetTextForwarder()
        return nullptr;

    if( mpModel == nullptr )
        mpModel = &mpObject->getSdrModelFromSdrObject();
        mpModel = mpObject->GetModel();

    if( mpModel == nullptr )
        return nullptr;

    // distinguish the cases
    // a) connected to view, maybe edit mode is active, can work directly on the EditOutliner
@@ -713,7 +763,10 @@ SvxEditViewForwarder* SvxTextEditSourceImpl::GetEditViewForwarder( bool bCreate 
        return nullptr;

    if( mpModel == nullptr )
        mpModel = &mpObject->getSdrModelFromSdrObject();
        mpModel = mpObject->GetModel();

    if( mpModel == nullptr )
        return nullptr;

    // shall we delete?
    if( mpViewForwarder )
@@ -1055,6 +1108,11 @@ const SvxUnoTextRangeBaseList& SvxTextEditSource::getRanges() const
    return mpImpl->getRanges();
}

void SvxTextEditSource::ChangeModel( SdrModel* pNewModel )
{
    mpImpl->ChangeModel( pNewModel );
}

void SvxTextEditSource::UpdateOutliner()
{
    mpImpl->UpdateOutliner();
diff --git a/svx/source/unogallery/unogaltheme.cxx b/svx/source/unogallery/unogaltheme.cxx
index 1bf753b..404a9bb 100644
--- a/svx/source/unogallery/unogaltheme.cxx
+++ b/svx/source/unogallery/unogaltheme.cxx
@@ -254,14 +254,13 @@ void SAL_CALL GalleryTheme::update(  )
                uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_QUERY_THROW );
                uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
                SvxDrawPage* pUnoPage = xPage.is() ? SvxDrawPage::getImplementation( xPage ) : nullptr;
                SdrModel* pOrigModel = pUnoPage ? &pUnoPage->GetSdrPage()->getSdrModelFromSdrPage() : nullptr;
                SdrModel* pOrigModel = pUnoPage ? pUnoPage->GetSdrPage()->GetModel() : nullptr;
                SdrPage* pOrigPage = pUnoPage ? pUnoPage->GetSdrPage() : nullptr;

                if (pOrigPage && pOrigModel)
                {
                    FmFormModel* pTmpModel = new FmFormModel(&pOrigModel->GetItemPool());
                    // Clone to new target SdrModel
                    SdrPage* pNewPage = pOrigPage->Clone(pTmpModel);
                    SdrPage* pNewPage = pOrigPage->Clone();
                    pTmpModel->InsertPage(pNewPage, 0);

                    uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pTmpModel ) );
diff --git a/sw/inc/dcontact.hxx b/sw/inc/dcontact.hxx
index 2262eea..87c18ff 100644
--- a/sw/inc/dcontact.hxx
+++ b/sw/inc/dcontact.hxx
@@ -196,7 +196,7 @@ private:
public:

    /// Creates DrawObject and registers it with the Model.
    SwFlyDrawContact(SwFlyFrameFormat* pToRegisterIn, SdrModel& rTargetModel);
    SwFlyDrawContact( SwFlyFrameFormat* pToRegisterIn );
    static SwVirtFlyDrawObj* CreateNewRef(SwFlyFrame* pFly, SwFlyFrameFormat* pFormat);
    virtual ~SwFlyDrawContact() override;

@@ -240,17 +240,15 @@ class SwDrawVirtObj : public SdrVirtObj
        virtual sdr::contact::ViewContact* CreateObjectSpecificViewContact() override;

    public:
        SwDrawVirtObj(
            SdrModel& rSdrModel,
            SdrObject& _rNewObj,
            SwDrawContact& _rDrawContact);

        SwDrawVirtObj( SdrObject&       _rNewObj,
                       SwDrawContact&   _rDrawContact );
        virtual ~SwDrawVirtObj() override;

        /// access to offset
        virtual const Point GetOffset() const override;

        virtual SwDrawVirtObj* Clone(SdrModel* pTargetModel = nullptr) const override;
        virtual SwDrawVirtObj* Clone() const override;
        SwDrawVirtObj& operator= (const SwDrawVirtObj& rObj);

        /// connection to writer layout
diff --git a/sw/inc/dpage.hxx b/sw/inc/dpage.hxx
index 7b3b50e..f905f68 100644
--- a/sw/inc/dpage.hxx
+++ b/sw/inc/dpage.hxx
@@ -30,7 +30,6 @@ class SwDoc;
class SwDPage final : public FmFormPage, public SdrObjUserCall
{
    SwDPage &operator=(const SwDPage&) = delete;
    SwDPage(const SwDPage&) = delete;

    std::unique_ptr<SdrPageGridFrameList>   pGridLst;
    SwDoc*                                  pDoc;
@@ -39,7 +38,8 @@ public:
    explicit SwDPage(SwDrawModel& rNewModel, bool bMasterPage);
    virtual ~SwDPage() override;

    virtual SwDPage* Clone(SdrModel* pNewModel = nullptr) const override;
    virtual SwDPage* Clone() const override;
    virtual SwDPage* Clone(SdrModel* pNewModel) const override;

    // #i3694#
    // This GetOffset() method is not needed anymore, it even leads to errors.
@@ -54,7 +54,9 @@ public:
    virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override;

private:
    void lateInit(const SwDPage& rSrcPage);
    void lateInit(const SwDPage& rPage, SwDrawModel* pNewModel);

    SwDPage(const SwDPage& rSrcPage);
};

#endif // INCLUDED_SW_INC_DPAGE_HXX
diff --git a/sw/inc/frmfmt.hxx b/sw/inc/frmfmt.hxx
index 01cf869..e90b808 100644
--- a/sw/inc/frmfmt.hxx
+++ b/sw/inc/frmfmt.hxx
@@ -38,8 +38,6 @@ class SwContact;
class SdrObject;
class SwRootFrame;
class SwFlyDrawContact;
class SdrModel;

namespace sw
{
    class DocumentLayoutManager;
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index eb0964f9..eebd5d2 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -200,9 +200,6 @@ private:
    using SfxBaseModel::removeEventListener;

protected:
    /** abstract SdrModel provider */
    virtual SdrModel* getSdrModelFromUnoModel() const override;

    virtual ~SwXTextDocument() override;
public:
    SwXTextDocument(SwDocShell* pShell);
diff --git a/sw/source/core/doc/doclay.cxx b/sw/source/core/doc/doclay.cxx
index 4430547..3b93cd9 100644
--- a/sw/source/core/doc/doclay.cxx
+++ b/sw/source/core/doc/doclay.cxx
@@ -125,9 +125,7 @@ SdrObject* SwDoc::CloneSdrObj( const SdrObject& rObj, bool bMoveWithinDoc,
        getIDocumentDrawModelAccess().GetDrawModel()->InsertPage( pPg );
    }

    // TTTT Clone directly to target SdrModel
    SdrObject *pObj = rObj.Clone(getIDocumentDrawModelAccess().GetDrawModel());

    SdrObject *pObj = rObj.Clone();
    if( bMoveWithinDoc && SdrInventor::FmForm == pObj->GetObjInventor() )
    {
        // We need to preserve the Name for Controls
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index c690b25..2cc3235 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -460,11 +460,9 @@ void SwContact::SwClientNotify(const SwModify& rMod, const SfxHint& rHint)
}


SwFlyDrawContact::SwFlyDrawContact(
    SwFlyFrameFormat *pToRegisterIn,
    SdrModel& rTargetModel)
:   SwContact(pToRegisterIn),
    mpMasterObj(new SwFlyDrawObj(rTargetModel))
SwFlyDrawContact::SwFlyDrawContact( SwFlyFrameFormat *pToRegisterIn )
    : SwContact( pToRegisterIn )
    , mpMasterObj(new SwFlyDrawObj)
{
    // #i26791# - class <SwFlyDrawContact> contains the 'master'
    // drawing object of type <SwFlyDrawObj> on its own.
@@ -512,11 +510,8 @@ SwVirtFlyDrawObj* SwFlyDrawContact::CreateNewRef(SwFlyFrame* pFly, SwFlyFrameFor

    IDocumentDrawModelAccess& rIDDMA = pFormat->getIDocumentDrawModelAccess();
    SwFlyDrawContact* pContact = pFormat->GetOrCreateContact();
    SwVirtFlyDrawObj* pDrawObj(
        new SwVirtFlyDrawObj(
            pContact->GetMaster()->getSdrModelFromSdrObject(),
            *pContact->GetMaster(),
            pFly));
    SwVirtFlyDrawObj* pDrawObj(new SwVirtFlyDrawObj(*pContact->GetMaster(), pFly));
    pDrawObj->SetModel(pContact->GetMaster()->GetModel());
    pDrawObj->SetUserCall(pContact);

    // The Reader creates the Masters and inserts them into the Page in
@@ -812,12 +807,7 @@ SwFrame* SwDrawContact::GetAnchorFrame(SdrObject const *const pDrawObj)
 */
SwDrawVirtObj* SwDrawContact::AddVirtObj()
{
    maDrawVirtObjs.push_back(
        std::unique_ptr<SwDrawVirtObj>(
            new SwDrawVirtObj(
                GetMaster()->getSdrModelFromSdrObject(),
                *GetMaster(),
                *this)));
    maDrawVirtObjs.push_back(std::unique_ptr<SwDrawVirtObj>(new SwDrawVirtObj(*GetMaster(), *this)));
    maDrawVirtObjs.back()->AddToDrawingPage();
    return maDrawVirtObjs.back().get();
}
@@ -2148,29 +2138,27 @@ namespace sdr
} // end of namespace sdr

/// implementation of class <SwDrawVirtObj>

sdr::contact::ViewContact* SwDrawVirtObj::CreateObjectSpecificViewContact()
{
    return new sdr::contact::VCOfDrawVirtObj(*this);
}

SwDrawVirtObj::SwDrawVirtObj(
    SdrModel& rSdrModel,
    SdrObject& _rNewObj,
    SwDrawContact& _rDrawContact)
:   SdrVirtObj(rSdrModel, _rNewObj ),
    maAnchoredDrawObj(),
    mrDrawContact(_rDrawContact)
SwDrawVirtObj::SwDrawVirtObj( SdrObject&        _rNewObj,
                              SwDrawContact&    _rDrawContact )
    : SdrVirtObj( _rNewObj ),
      // #i26791# - init new member <maAnchoredDrawObj>
      maAnchoredDrawObj(),
      mrDrawContact( _rDrawContact )
{
    // #i26791#
    maAnchoredDrawObj.SetDrawObj( *this );

    // #i35635# - set initial position out of sight
    NbcMove( Size( -16000, -16000 ) );
}

SwDrawVirtObj::~SwDrawVirtObj()
{
}
{}

SwDrawVirtObj& SwDrawVirtObj::operator=( const SwDrawVirtObj& rObj )
{
@@ -2180,12 +2168,9 @@ SwDrawVirtObj& SwDrawVirtObj::operator=( const SwDrawVirtObj& rObj )
    return *this;
}

SwDrawVirtObj* SwDrawVirtObj::Clone(SdrModel* pTargetModel) const
SwDrawVirtObj* SwDrawVirtObj::Clone() const
{
    SwDrawVirtObj* pObj = new SwDrawVirtObj(
        nullptr == pTargetModel ? getSdrModelFromSdrObject() : *pTargetModel,
        rRefObj,
        mrDrawContact);
    SwDrawVirtObj* pObj = new SwDrawVirtObj( rRefObj, mrDrawContact );

    pObj->operator=( *this );
    // Note: Member <maAnchoredDrawObj> hasn't to be considered.
diff --git a/sw/source/core/draw/dflyobj.cxx b/sw/source/core/draw/dflyobj.cxx
index cd74e92..93a58d2 100644
--- a/sw/source/core/draw/dflyobj.cxx
+++ b/sw/source/core/draw/dflyobj.cxx
@@ -121,8 +121,7 @@ sdr::contact::ViewContact* SwFlyDrawObj::CreateObjectSpecificViewContact()
    return new sdr::contact::VCOfSwFlyDrawObj(*this);
}

SwFlyDrawObj::SwFlyDrawObj(SdrModel& rSdrModel)
:   SdrObject(rSdrModel)
SwFlyDrawObj::SwFlyDrawObj()
{
}

@@ -131,6 +130,7 @@ SwFlyDrawObj::~SwFlyDrawObj()
}

// SwFlyDrawObj - Factory-Methods

SdrInventor SwFlyDrawObj::GetObjInventor() const
{
    return SdrInventor::Swg;
@@ -142,6 +142,7 @@ sal_uInt16 SwFlyDrawObj::GetObjIdentifier() const
}

// TODO: Need own primitive to get the FlyFrame paint working

namespace drawinglayer
{
    namespace primitive2d
@@ -420,12 +421,9 @@ sdr::contact::ViewContact* SwVirtFlyDrawObj::CreateObjectSpecificViewContact()
    return new sdr::contact::VCOfSwVirtFlyDrawObj(*this);
}

SwVirtFlyDrawObj::SwVirtFlyDrawObj(
    SdrModel& rSdrModel,
    SdrObject& rNew,
    SwFlyFrame* pFly)
:   SdrVirtObj(rSdrModel, rNew),
    m_pFlyFrame(pFly)
SwVirtFlyDrawObj::SwVirtFlyDrawObj(SdrObject& rNew, SwFlyFrame* pFly) :
    SdrVirtObj( rNew ),
    m_pFlyFrame( pFly )
{
    const SvxProtectItem &rP = m_pFlyFrame->GetFormat()->GetProtect();
    bMovProt = rP.IsPosProtected();
diff --git a/sw/source/core/draw/dobjfac.cxx b/sw/source/core/draw/dobjfac.cxx
index e11e375..e358764 100644
--- a/sw/source/core/draw/dobjfac.cxx
+++ b/sw/source/core/draw/dobjfac.cxx
@@ -31,7 +31,7 @@ IMPL_STATIC_LINK(
        // No switch, there's only one at the moment
        OSL_ENSURE( aParams.nObjIdentifier == SwFlyDrawObjIdentifier,
                                        "Wrong inventor or identifier" );
        return new SwFlyDrawObj(aParams.rSdrModel);
        return new SwFlyDrawObj;
    }
    return nullptr;
}
diff --git a/sw/source/core/draw/dpage.cxx b/sw/source/core/draw/dpage.cxx
index d50a7f5..716e41c 100644
--- a/sw/source/core/draw/dpage.cxx
+++ b/sw/source/core/draw/dpage.cxx
@@ -49,21 +49,17 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::frame;

SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage)
:   FmFormPage(rNewModel, bMasterPage),
SwDPage::SwDPage(SwDrawModel& rNewModel, bool bMasterPage) :
    FmFormPage(rNewModel, bMasterPage),
    pGridLst( nullptr ),
    pDoc(&rNewModel.GetDoc())
{
}

SwDPage::~SwDPage()
SwDPage::SwDPage(const SwDPage& rSrcPage) :
    FmFormPage( rSrcPage ),
    pDoc( nullptr )
{
}

void SwDPage::lateInit(const SwDPage& rSrcPage)
{
    FmFormPage::lateInit( rSrcPage );

    if ( rSrcPage.pGridLst )
    {
        pGridLst.reset( new SdrPageGridFrameList );
@@ -72,15 +68,39 @@ void SwDPage::lateInit(const SwDPage& rSrcPage)
    }
}

SwDPage::~SwDPage()
{
}

void SwDPage::lateInit(const SwDPage& rPage, SwDrawModel* const pNewModel)
{
    FmFormPage::lateInit( rPage, pNewModel );

    SwDrawModel* pSwDrawModel = pNewModel;
    if (!pSwDrawModel)
    {
        pSwDrawModel = &dynamic_cast<SwDrawModel&>(*GetModel());
        assert( pSwDrawModel );
    }
    pDoc = &pSwDrawModel->GetDoc();
}

SwDPage* SwDPage::Clone() const
{
    return Clone( nullptr );
}

SwDPage* SwDPage::Clone(SdrModel* const pNewModel) const
{
    SwDrawModel& rSwDrawModel(static_cast< SwDrawModel& >(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel));
    SwDPage* pClonedSwDPage(
        new SwDPage(
            rSwDrawModel,
            IsMasterPage()));
    pClonedSwDPage->lateInit(*this);
    return pClonedSwDPage;
    SwDPage* const pNewPage = new SwDPage( *this );
    SwDrawModel* pSwDrawModel = nullptr;
    if ( pNewModel )
    {
        pSwDrawModel = &dynamic_cast<SwDrawModel&>(*pNewModel);
        assert( pSwDrawModel );
    }
    pNewPage->lateInit( *this, pSwDrawModel );
    return pNewPage;
}

SdrObject*  SwDPage::ReplaceObject( SdrObject* pNewObj, size_t nObjNum )
@@ -106,7 +126,7 @@ void InsertGridFrame( SdrPageGridFrameList *pLst, const SwFrame *pPg )
const SdrPageGridFrameList*  SwDPage::GetGridFrameList(
                        const SdrPageView* pPV, const tools::Rectangle *pRect ) const
{
    SwViewShell* pSh = static_cast< SwDrawModel& >(getSdrModelFromSdrPage()).GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
    SwViewShell* pSh = static_cast< SwDrawModel* >(GetModel())->GetDoc().getIDocumentLayoutAccess().GetCurrentViewShell();
    if(pSh)
    {
        for(SwViewShell& rShell : pSh->GetRingContainer())
diff --git a/sw/source/core/draw/dview.cxx b/sw/source/core/draw/dview.cxx
index 2551634..ef557e8 100644
--- a/sw/source/core/draw/dview.cxx
+++ b/sw/source/core/draw/dview.cxx
@@ -94,11 +94,8 @@ static const SwFrame *lcl_FindAnchor( const SdrObject *pObj, bool bAll )
    return nullptr;
}

SwDrawView::SwDrawView(
    SwViewShellImp& rI,
    FmFormModel& rFmFormModel,
    OutputDevice* pOutDev)
:   FmFormView(rFmFormModel, pOutDev),
SwDrawView::SwDrawView( SwViewShellImp &rI, SdrModel *pMd, OutputDevice *pOutDev) :
    FmFormView( static_cast<FmFormModel*>(pMd), pOutDev ),
    m_rImp( rI )
{
    SetPageVisible( false );
diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 385f8da..fd44d6e 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -1287,10 +1287,7 @@ static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs( SdrModel* _pModel )
                pOle2Obj->Disconnect();

                // create new graphic shape with the ole graphic and shape size
                SdrGrafObj* pGraphicObj = new SdrGrafObj(
                    *_pModel, // TTTT should be reference
                    aGraphic,
                    pOle2Obj->GetCurrentBoundRect());
                SdrGrafObj* pGraphicObj = new SdrGrafObj( aGraphic, pOle2Obj->GetCurrentBoundRect() );
                // apply layer of ole2 shape at graphic shape
                pGraphicObj->SetLayer( pOle2Obj->GetLayer() );

diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 250fec8..a47aa96 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -111,10 +111,10 @@ using namespace com::sun::star;

namespace {

::basegfx::B2DPolyPolygon getPolygon(const char* pResId, const SdrModel& rModel)
::basegfx::B2DPolyPolygon getPolygon(const char* pResId, SdrModel const * pDoc)
{
    ::basegfx::B2DPolyPolygon aRetval;
    XLineEndListRef pLineEndList(rModel.GetLineEndList());
    XLineEndListRef pLineEndList = pDoc->GetLineEndList();

    if( pLineEndList.is() )
    {
@@ -894,7 +894,7 @@ static void lcl_NotifyNeighbours( const SdrMarkList *pLst )

void SwFEShell::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj, sal_uInt16 nSlotId)
{
    SdrModel& rModel(pObj->getSdrModelFromSdrObject());
    SdrModel *pDoc = pObj->GetModel();

    if ( !(nSlotId == SID_LINE_ARROW_START      ||
          nSlotId == SID_LINE_ARROW_END        ||
@@ -908,7 +908,7 @@ void SwFEShell::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj, sal_uInt1
    // set attributes of line start and ends

    // arrowhead
    ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, rModel ) );
    ::basegfx::B2DPolyPolygon aArrow( getPolygon( RID_SVXSTR_ARROW, pDoc ) );
    if( !aArrow.count() )
    {
        ::basegfx::B2DPolygon aNewArrow;
@@ -920,7 +920,7 @@ void SwFEShell::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj, sal_uInt1
    }

    // Circles
    ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, rModel ) );
    ::basegfx::B2DPolyPolygon aCircle( getPolygon( RID_SVXSTR_CIRCLE, pDoc ) );
    if( !aCircle.count() )
    {
        ::basegfx::B2DPolygon aNewCircle;
@@ -930,7 +930,7 @@ void SwFEShell::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj, sal_uInt1
    }

    // Square
    ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, rModel ) );
    ::basegfx::B2DPolyPolygon aSquare( getPolygon( RID_SVXSTR_SQUARE, pDoc ) );
    if( !aSquare.count() )
    {
        ::basegfx::B2DPolygon aNewSquare;
@@ -942,7 +942,7 @@ void SwFEShell::SetLineEnds(SfxItemSet& rAttr, SdrObject const * pObj, sal_uInt1
        aSquare.append(aNewSquare);
    }

    SfxItemSet aSet( rModel.GetItemPool() );
    SfxItemSet aSet( pDoc->GetItemPool() );
    long nWidth = 100; // (1/100th mm)

    // determine line width and calculate with it the line end width
@@ -2919,9 +2919,8 @@ long SwFEShell::GetSectionWidth( SwFormat const & rFormat ) const
    SdrView* pDrawView = GetDrawView();
    SdrModel* pDrawModel = pDrawView->GetModel();
    SdrObject* pObj = SdrObjFactory::MakeNewObject(
        *pDrawModel,
        SdrInventor::Default,
        eSdrObjectKind);
        SdrInventor::Default, eSdrObjectKind,
        nullptr, pDrawModel);

    if(pObj)
    {
@@ -3041,7 +3040,7 @@ long SwFEShell::GetSectionWidth( SwFormat const & rFormat ) const
                    aTempPoly.append(basegfx::B2DPoint(aRect.BottomRight().getX(), nYMiddle));
                    aPoly.append(aTempPoly);

                    SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
                    SfxItemSet aAttr(pObj->GetModel()->GetItemPool());
                    SetLineEnds(aAttr, pObj, nSlotId);
                    pObj->SetMergedItemSet(aAttr);
                }
diff --git a/sw/source/core/inc/dflyobj.hxx b/sw/source/core/inc/dflyobj.hxx
index 6e157b1..a0cf7fd2 100644
--- a/sw/source/core/inc/dflyobj.hxx
+++ b/sw/source/core/inc/dflyobj.hxx
@@ -42,7 +42,7 @@ protected:

public:

    SwFlyDrawObj(SdrModel& rSdrModel);
    SwFlyDrawObj();
    virtual ~SwFlyDrawObj() override;

    // for instantiation of this class while loading (via factory)
@@ -80,10 +80,7 @@ public:
    // RotGrfFlyFrame: Check if this is a SwGrfNode
    bool ContainsSwGrfNode() const;

    SwVirtFlyDrawObj(
        SdrModel& rSdrModel,
        SdrObject& rNew,
        SwFlyFrame* pFly);
    SwVirtFlyDrawObj(SdrObject& rNew, SwFlyFrame* pFly);
    virtual ~SwVirtFlyDrawObj() override;

    // override method of base class SdrVirtObj
diff --git a/sw/source/core/inc/dview.hxx b/sw/source/core/inc/dview.hxx
index 66b51fd4..aeb1e86 100644
--- a/sw/source/core/inc/dview.hxx
+++ b/sw/source/core/inc/dview.hxx
@@ -79,10 +79,7 @@ protected:
    virtual SdrUndoManager* getSdrUndoManagerForEnhancedTextEdit() const override;

public:
    SwDrawView(
        SwViewShellImp &rI,
        FmFormModel& rFmFormModel,
        OutputDevice* pOutDev);
    SwDrawView( SwViewShellImp &rI, SdrModel *pMd, OutputDevice* pOutDev );

    // from base class
    virtual SdrObject*   GetMaxToTopObj(SdrObject* pObj) const override;
diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx
index d7b8421..91d8e15 100644
--- a/sw/source/core/layout/atrfrm.cxx
+++ b/sw/source/core/layout/atrfrm.cxx
@@ -2886,11 +2886,7 @@ SwFlyFrameFormat::~SwFlyFrameFormat()
SwFlyDrawContact* SwFlyFrameFormat::GetOrCreateContact()
{
    if(!m_pContact)
    {
        SwDrawModel* pDrawModel(GetDoc()->getIDocumentDrawModelAccess().GetOrCreateDrawModel());
        m_pContact.reset(new SwFlyDrawContact(this, *pDrawModel));
    }

        m_pContact.reset(new SwFlyDrawContact(this));
    return m_pContact.get();
}

diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 592a8a7..ffc0940 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -7384,7 +7384,7 @@ Graphic SwDrawFrameFormat::MakeGraphic( ImageMap* )
    if ( pMod )
    {
        SdrObject *pObj = FindSdrObject();
        std::unique_ptr<SdrView> pView( new SdrView( *pMod ) );
        std::unique_ptr<SdrView> pView( new SdrView( pMod ) );
        SdrPageView *pPgView = pView->ShowSdrPage(pView->GetModel()->GetPage(0));
        pView->MarkObj( pObj, pPgView );
        aRet = pView->GetMarkedObjBitmapEx();
diff --git a/sw/source/core/view/viewimp.cxx b/sw/source/core/view/viewimp.cxx
index 2146529..ee204d1 100644
--- a/sw/source/core/view/viewimp.cxx
+++ b/sw/source/core/view/viewimp.cxx
@@ -228,10 +228,7 @@ void SwViewShellImp::MakeDrawView()
                pOutDevForDrawView = GetShell()->GetOut();
            }

            m_pDrawView = new SwDrawView(
                *this,
                *rIDDMA.GetOrCreateDrawModel(),
                pOutDevForDrawView);
            m_pDrawView = new SwDrawView( *this, rIDDMA.GetDrawModel(), pOutDevForDrawView);
        }

        GetDrawView()->SetActiveLayer("Heaven");
diff --git a/sw/source/filter/html/htmldrawreader.cxx b/sw/source/filter/html/htmldrawreader.cxx
index 8b15895..7d74657 100644
--- a/sw/source/filter/html/htmldrawreader.cxx
+++ b/sw/source/filter/html/htmldrawreader.cxx
@@ -355,12 +355,8 @@ void SwHTMLParser::NewMarquee( HTMLTable *pCurTable )
    // #i52858# - method name changed
    SwDrawModel* pModel = m_xDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
    SdrPage* pPg = pModel->GetPage( 0 );
    m_pMarquee = SdrObjFactory::MakeNewObject(
        *pModel,
        SdrInventor::Default,
        OBJ_TEXT,
        pPg);

    m_pMarquee = SdrObjFactory::MakeNewObject( SdrInventor::Default,
                                             OBJ_TEXT, pPg, pModel );
    if( !m_pMarquee )
        return;

diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index c27173b..7406f15 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -2966,8 +2966,10 @@ void SwEscherEx::WriteOCXControl( const SwFrameFormat& rFormat, sal_uInt32 nShap

    // #i71538# use complete SdrViews
    // SdrExchangeView aExchange(pModel, pDevice);
    SdrView aExchange(*pModel, pDevice);
    const Graphic aGraphic(SdrExchangeView::GetObjGraphic(*pSdrObj));
    SdrView aExchange(pModel, pDevice);

    Graphic aGraphic(SdrExchangeView::GetObjGraphic(pModel, pSdrObj));

    EscherPropertyContainer aPropOpt;
    WriteOLEPicture(aPropOpt,
        ShapeFlag::HaveAnchor | ShapeFlag::HaveShapeProperty | ShapeFlag::OLEShape, aGraphic,
diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx
index ee2f929..4d9ceaa 100644
--- a/sw/source/filter/ww8/wrtww8gr.cxx
+++ b/sw/source/filter/ww8/wrtww8gr.cxx
@@ -67,8 +67,6 @@
#include <docsh.hxx>
#include <cstdio>
#include <o3tl/enumrange.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <drawdoc.hxx>

using namespace ::com::sun::star;

@@ -141,18 +139,7 @@ bool WW8Export::TestOleNeedsGraphic(const SwAttrSet& rSet,
        if ( pOLENd )
            nAspect = pOLENd->GetAspect();
        SdrOle2Obj *pRet = SvxMSDffManager::CreateSdrOLEFromStorage(
            *m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel(),
            rStorageName,
            xObjStg,
            m_pDoc->GetDocStorage(),
            aGraph,
            aRect,
            tools::Rectangle(),
            nullptr,
            nErr,
            0,
            nAspect,
            m_pWriter->GetBaseURL());
            rStorageName,xObjStg,m_pDoc->GetDocStorage(),aGraph,aRect,tools::Rectangle(),nullptr,nErr,0,nAspect, m_pWriter->GetBaseURL());

        if (pRet)
        {
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 1b165cf..ed67365 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -326,10 +326,7 @@ SdrObject* SwWW8ImplReader::ReadLine(WW8_DPHEAD const * pHd, SfxAllItemSet &rSet
    ::basegfx::B2DPolygon aPolygon;
    aPolygon.append(::basegfx::B2DPoint(aP[0].X(), aP[0].Y()));
    aPolygon.append(::basegfx::B2DPoint(aP[1].X(), aP[1].Y()));
    SdrObject* pObj = new SdrPathObj(
        *m_pDrawModel,
        OBJ_LINE,
        ::basegfx::B2DPolyPolygon(aPolygon));
    SdrObject* pObj = new SdrPathObj(OBJ_LINE, ::basegfx::B2DPolyPolygon(aPolygon));

    SetStdAttr( rSet, aLine.aLnt, aLine.aShd );
    SetLineEndAttr( rSet, aLine.aEpp, aLine.aLnt );
@@ -350,9 +347,7 @@ SdrObject* SwWW8ImplReader::ReadRect(WW8_DPHEAD const * pHd, SfxAllItemSet &rSet
    aP1.AdjustX(static_cast<sal_Int16>(SVBT16ToShort( pHd->dxa )) );
    aP1.AdjustY(static_cast<sal_Int16>(SVBT16ToShort( pHd->dya )) );

    SdrObject* pObj = new SdrRectObj(
        *m_pDrawModel,
        tools::Rectangle(aP0, aP1));
    SdrObject* pObj = new SdrRectObj( tools::Rectangle( aP0, aP1 ) );

    SetStdAttr( rSet, aRect.aLnt, aRect.aShd );
    SetFill( rSet, aRect.aFill );
@@ -373,10 +368,7 @@ SdrObject* SwWW8ImplReader::ReadElipse(WW8_DPHEAD const * pHd, SfxAllItemSet &rS
    aP1.AdjustX(static_cast<sal_Int16>(SVBT16ToShort( pHd->dxa )) );
    aP1.AdjustY(static_cast<sal_Int16>(SVBT16ToShort( pHd->dya )) );

    SdrObject* pObj = new SdrCircObj(
        *m_pDrawModel,
        OBJ_CIRC,
        tools::Rectangle(aP0, aP1));
    SdrObject* pObj = new SdrCircObj( OBJ_CIRC, tools::Rectangle( aP0, aP1 ) );

    SetStdAttr( rSet, aElipse.aLnt, aElipse.aShd );
    SetFill( rSet, aElipse.aFill );
@@ -408,12 +400,8 @@ SdrObject* SwWW8ImplReader::ReadArc(WW8_DPHEAD const * pHd, SfxAllItemSet &rSet)
        aP1.AdjustX( -static_cast<sal_Int16>(SVBT16ToShort( pHd->dxa )) );
    }

    SdrObject* pObj = new SdrCircObj(
        *m_pDrawModel,
        OBJ_SECT,
        tools::Rectangle(aP0, aP1),
        nW * 9000,
        ( ( nW + 1 ) & 3 ) * 9000);
    SdrObject* pObj = new SdrCircObj( OBJ_SECT, tools::Rectangle( aP0, aP1 ),
                               nW * 9000, ( ( nW + 1 ) & 3 ) * 9000 );

    SetStdAttr( rSet, aArc.aLnt, aArc.aShd );
    SetFill( rSet, aArc.aFill );
@@ -448,11 +436,7 @@ SdrObject* SwWW8ImplReader::ReadPolyLine(WW8_DPHEAD const * pHd, SfxAllItemSet &
    }
    xP.reset();

    SdrObject* pObj = new SdrPathObj(
        *m_pDrawModel,
        (SVBT16ToShort(aPoly.aBits1) & 0x1) ? OBJ_POLY : OBJ_PLIN,
        ::basegfx::B2DPolyPolygon(aP.getB2DPolygon()));

    SdrObject* pObj = new SdrPathObj(( SVBT16ToShort( aPoly.aBits1 ) & 0x1 ) ? OBJ_POLY : OBJ_PLIN, ::basegfx::B2DPolyPolygon(aP.getB2DPolygon()));
    SetStdAttr( rSet, aPoly.aLnt, aPoly.aShd );
    SetFill( rSet, aPoly.aFill );

@@ -1112,12 +1096,13 @@ void SwWW8ImplReader::InsertTxbxText(SdrTextObj* pTextObj,

                                if( !pNew )
                                {
                                    pNew = new SdrGrafObj(*m_pDrawModel);
                                    pNew = new SdrGrafObj;
                                    static_cast<SdrGrafObj*>(pNew)->SetGraphic(aGraph);
                                }

                                GrafikCtor();

                                pNew->SetModel( m_pDrawModel );
                                pNew->SetLogicRect( pTextObj->GetCurrentBoundRect() );
                                pNew->SetLayer( pTextObj->GetLayer() );

@@ -1240,11 +1225,8 @@ SdrObject* SwWW8ImplReader::ReadTextBox(WW8_DPHEAD const * pHd, SfxAllItemSet &r
    aP1.AdjustX(static_cast<sal_Int16>(SVBT16ToShort( pHd->dxa )) );
    aP1.AdjustY(static_cast<sal_Int16>(SVBT16ToShort( pHd->dya )) );

    SdrRectObj* pObj = new SdrRectObj(
        *m_pDrawModel,
        OBJ_TEXT,
        tools::Rectangle(aP0, aP1));

    SdrRectObj* pObj = new SdrRectObj( OBJ_TEXT, tools::Rectangle( aP0, aP1 ) );
    pObj->SetModel( m_pDrawModel );
    pObj->NbcSetSnapRect(tools::Rectangle(aP0, aP1));
    Size aSize( static_cast<sal_Int16>(SVBT16ToShort( pHd->dxa )) ,
        static_cast<sal_Int16>(SVBT16ToShort( pHd->dya )) );
@@ -1313,11 +1295,8 @@ SdrObject* SwWW8ImplReader::ReadCaptionBox(WW8_DPHEAD const * pHd, SfxAllItemSet
               + m_nDrawYOfs2 + static_cast<sal_Int16>(SVBT16ToShort( xP[1] )) );
    xP.reset();

    SdrCaptionObj* pObj = new SdrCaptionObj(
        *m_pDrawModel,
        tools::Rectangle(aP0, aP1),
        aP2);

    SdrCaptionObj* pObj = new SdrCaptionObj( tools::Rectangle( aP0, aP1 ), aP2 );
    pObj->SetModel( m_pDrawModel );
    pObj->NbcSetSnapRect(tools::Rectangle(aP0, aP1));
    Size aSize( static_cast<sal_Int16>(SVBT16ToShort( aCallB.dpheadTxbx.dxa )),
                           static_cast<sal_Int16>(SVBT16ToShort(  aCallB.dpheadTxbx.dya )) );
@@ -1349,7 +1328,7 @@ SdrObject *SwWW8ImplReader::ReadGroup(WW8_DPHEAD const * pHd, SfxAllItemSet &rSe
    m_nDrawXOfs = m_nDrawXOfs + static_cast<sal_Int16>(SVBT16ToShort( pHd->xa ));
    m_nDrawYOfs = m_nDrawYOfs + static_cast<sal_Int16>(SVBT16ToShort( pHd->ya ));

    SdrObject* pObj = new SdrObjGroup(*m_pDrawModel);
    SdrObject* pObj = new SdrObjGroup;

    short nLeft = static_cast<sal_Int16>(SVBT16ToShort( pHd->cb )) - sizeof( WW8_DPHEAD );
    for (int i = 0; i < nGrouped && nLeft >= static_cast<short>(sizeof(WW8_DPHEAD)); ++i)
@@ -2815,10 +2794,7 @@ SwFrameFormat* SwWW8ImplReader::MungeTextIntoDrawBox(SdrObject* pTrueObject,
    {
        // Group objects don't have text. Insert a text object into
        // the group for holding the text.
        pSdrTextObj = new SdrRectObj(
            *m_pDrawModel,
            OBJ_TEXT,
            pThisGroup->GetCurrentBoundRect());
        pSdrTextObj = new SdrRectObj( OBJ_TEXT, pThisGroup->GetCurrentBoundRect());

        SfxItemSet aSet(m_pDrawModel->GetItemPool());
        aSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 0990ec4..33ff69a 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -497,19 +497,9 @@ SdrObject* SwMSDffManager::ImportOLE( sal_uInt32 nOLEId,
        else
        {
            ErrCode nError = ERRCODE_NONE;
            pRet = CreateSdrOLEFromStorage(
                *pSdrModel,
                sStorageName,
                xSrcStg,
                xDstStg,
                rGrf,
                rBoundRect,
                rVisArea,
                pStData,
                nError,
                nSvxMSDffOLEConvFlags,
                css::embed::Aspects::MSOLE_CONTENT,
                rReader.GetBaseURL());
            pRet = CreateSdrOLEFromStorage( sStorageName, xSrcStg, xDstStg,
                rGrf, rBoundRect, rVisArea, pStData, nError,
                nSvxMSDffOLEConvFlags, css::embed::Aspects::MSOLE_CONTENT, rReader.GetBaseURL());
        }
    }
    return pRet;
@@ -743,10 +733,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt,
            if (bIsSimpleDrawingTextBox)
            {
                SdrObject::Free( pObj );
                pObj = new SdrRectObj(
                    *pSdrModel,
                    OBJ_TEXT,
                    rTextRect);
                pObj = new SdrRectObj(OBJ_TEXT, rTextRect);
            }

            // The vertical paragraph justification are contained within the
@@ -870,6 +857,7 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt,
            if (pObj != nullptr)
            {
                pObj->SetMergedItemSet(aSet);
                pObj->SetModel(pSdrModel);

                if (bVerticalText)
                {
@@ -935,10 +923,8 @@ SdrObject* SwMSDffManager::ProcessObj(SvStream& rSt,
            // simple rectangular objects are ignored by ImportObj()  :-(
            // this is OK for Draw but not for Calc and Writer
            // cause here these objects have a default border
            pObj = new SdrRectObj(
                *pSdrModel,
                rTextRect);

            pObj = new SdrRectObj(rTextRect);
            pObj->SetModel( pSdrModel );
            SfxItemSet aSet( pSdrModel->GetItemPool() );
            ApplyAttributes( rSt, aSet, rObjData );

diff --git a/sw/source/filter/ww8/ww8par4.cxx b/sw/source/filter/ww8/ww8par4.cxx
index d2a63a9..fd82c91 100644
--- a/sw/source/filter/ww8/ww8par4.cxx
+++ b/sw/source/filter/ww8/ww8par4.cxx
@@ -436,21 +436,9 @@ SdrObject* SwWW8ImplReader::ImportOleBase( Graphic& rGraph,
            }

            ErrCode nError = ERRCODE_NONE;
            GrafikCtor();

            pRet = SvxMSDffManager::CreateSdrOLEFromStorage(
                *m_pDrawModel,
                aSrcStgName,
                xSrc0,
                m_pDocShell->GetStorage(),
                rGraph,
                aRect,
                aVisArea,
                pTmpData,
                nError,
                SwMSDffManager::GetFilterFlags(),
                nAspect,
                GetBaseURL());
                aSrcStgName, xSrc0, m_pDocShell->GetStorage(), rGraph, aRect, aVisArea, pTmpData, nError,
                SwMSDffManager::GetFilterFlags(), nAspect, GetBaseURL());
            m_pDataStream->Seek( nOldPos );
        }
    }
diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx
index e0244ca..d64f3c2 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -458,11 +458,7 @@ static void lcl_ConvertSdrOle2ObjsToSdrGrafObjs(SwDoc& _rDoc)
                pOle2Obj->Disconnect();

                // create new graphic shape with the ole graphic and shape size
                SdrGrafObj* pGraphicObj = new SdrGrafObj(
                    pOle2Obj->getSdrModelFromSdrObject(),
                    aGraphic,
                    pOle2Obj->GetCurrentBoundRect());

                SdrGrafObj* pGraphicObj = new SdrGrafObj( aGraphic, pOle2Obj->GetCurrentBoundRect() );
                // apply layer of ole2 shape at graphic shape
                pGraphicObj->SetLayer( pOle2Obj->GetLayer() );

diff --git a/sw/source/uibase/ribbar/concustomshape.cxx b/sw/source/uibase/ribbar/concustomshape.cxx
index adbbd07..be8e19e 100644
--- a/sw/source/uibase/ribbar/concustomshape.cxx
+++ b/sw/source/uibase/ribbar/concustomshape.cxx
@@ -128,7 +128,7 @@ void ConstCustomShape::SetAttributes( SdrObject* pObj )
                        {
                            const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
                            SfxItemSet aDest(
                                pObj->getSdrModelFromSdrObject().GetItemPool(),
                                pObj->GetModel()->GetItemPool(),
                                svl::Items<
                                    // Ranges from SdrAttrObj:
                                    SDRATTR_START, SDRATTR_SHADOW_LAST,
diff --git a/sw/source/uibase/ribbar/conrect.cxx b/sw/source/uibase/ribbar/conrect.cxx
index 395bca6..36f1050 100644
--- a/sw/source/uibase/ribbar/conrect.cxx
+++ b/sw/source/uibase/ribbar/conrect.cxx
@@ -65,7 +65,7 @@ bool ConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
            SdrObject* pObj = m_pView->GetDrawView()->GetCreateObj();
            if (pObj)
            {
                SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
                SfxItemSet aAttr(pObj->GetModel()->GetItemPool());
                SwFEShell::SetLineEnds(aAttr, pObj, m_nSlotId);
                pObj->SetMergedItemSet(aAttr);
            }
diff --git a/sw/source/uibase/shells/grfshex.cxx b/sw/source/uibase/shells/grfshex.cxx
index e31d5a1..6536cf5 100644
--- a/sw/source/uibase/shells/grfshex.cxx
+++ b/sw/source/uibase/shells/grfshex.cxx
@@ -123,10 +123,9 @@ bool SwTextShell::InsertMediaDlg( SfxRequest const & rReq )
                if (!bRet) { return bRet; }
            }

            SdrMediaObj* pObj = new SdrMediaObj(
                *rSh.GetDoc()->getIDocumentDrawModelAccess().GetDrawModel(),
                tools::Rectangle(aPos, aSize));
            SdrMediaObj* pObj = new SdrMediaObj( tools::Rectangle( aPos, aSize ) );

            pObj->SetModel(rSh.GetDoc()->getIDocumentDrawModelAccess().GetDrawModel()); // set before setURL
            pObj->setURL( realURL, "" );
            rSh.EnterStdMode();
            rSh.SwFEShell::InsertDrawObj( *pObj, aPos );
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 3aa9a3c..2fd36e8 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -450,12 +450,6 @@ SwXTextDocument::SwXTextDocument(SwDocShell* pShell)
{
}

SdrModel* SwXTextDocument::getSdrModelFromUnoModel() const
{
    OSL_ENSURE(pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetOrCreateDrawModel(), "No SdrModel in SwDoc, should not happen");
    return pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel();
}

SwXTextDocument::~SwXTextDocument()
{
    InitNewDoc();
diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx
index 54f7f70..4601f35 100644
--- a/xmloff/source/draw/xexptran.cxx
+++ b/xmloff/source/draw/xexptran.cxx
@@ -33,7 +33,6 @@
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
#include <basegfx/utils/unotools.hxx>
#include <basegfx/matrix/b3dhommatrixtools.hxx>

using namespace ::com::sun::star;

@@ -601,7 +600,22 @@ void SdXMLImExTransform3D::AddMatrix(const ::basegfx::B3DHomMatrix& rNew)

void SdXMLImExTransform3D::AddHomogenMatrix(const drawing::HomogenMatrix& xHomMat)
{
    AddMatrix(basegfx::utils::UnoHomogenMatrixToB3DHomMatrix(xHomMat));
    ::basegfx::B3DHomMatrix aExportMatrix;

    aExportMatrix.set(0, 0, xHomMat.Line1.Column1);
    aExportMatrix.set(0, 1, xHomMat.Line1.Column2);
    aExportMatrix.set(0, 2, xHomMat.Line1.Column3);
    aExportMatrix.set(0, 3, xHomMat.Line1.Column4);
    aExportMatrix.set(1, 0, xHomMat.Line2.Column1);
    aExportMatrix.set(1, 1, xHomMat.Line2.Column2);
    aExportMatrix.set(1, 2, xHomMat.Line2.Column3);
    aExportMatrix.set(1, 3, xHomMat.Line2.Column4);
    aExportMatrix.set(2, 0, xHomMat.Line3.Column1);
    aExportMatrix.set(2, 1, xHomMat.Line3.Column2);
    aExportMatrix.set(2, 2, xHomMat.Line3.Column3);
    aExportMatrix.set(2, 3, xHomMat.Line3.Column4);

    AddMatrix(aExportMatrix);
}

// gen string for export
@@ -914,7 +928,26 @@ bool SdXMLImExTransform3D::GetFullHomogenTransform(css::drawing::HomogenMatrix& 

    if(!aFullTransform.isIdentity())
    {
        basegfx::utils::B3DHomMatrixToUnoHomogenMatrix(aFullTransform, xHomMat);
        xHomMat.Line1.Column1 = aFullTransform.get(0, 0);
        xHomMat.Line1.Column2 = aFullTransform.get(0, 1);
        xHomMat.Line1.Column3 = aFullTransform.get(0, 2);
        xHomMat.Line1.Column4 = aFullTransform.get(0, 3);

        xHomMat.Line2.Column1 = aFullTransform.get(1, 0);
        xHomMat.Line2.Column2 = aFullTransform.get(1, 1);
        xHomMat.Line2.Column3 = aFullTransform.get(1, 2);
        xHomMat.Line2.Column4 = aFullTransform.get(1, 3);

        xHomMat.Line3.Column1 = aFullTransform.get(2, 0);
        xHomMat.Line3.Column2 = aFullTransform.get(2, 1);
        xHomMat.Line3.Column3 = aFullTransform.get(2, 2);
        xHomMat.Line3.Column4 = aFullTransform.get(2, 3);

        xHomMat.Line4.Column1 = aFullTransform.get(3, 0);
        xHomMat.Line4.Column2 = aFullTransform.get(3, 1);
        xHomMat.Line4.Column3 = aFullTransform.get(3, 2);
        xHomMat.Line4.Column4 = aFullTransform.get(3, 3);

        return true;
    }