diff options
Diffstat (limited to 'svx/source/svdraw')
43 files changed, 1498 insertions, 1657 deletions
diff --git a/svx/source/svdraw/svdcrtv.cxx b/svx/source/svdraw/svdcrtv.cxx index 33cf4eb9b3c2..f2d739e76612 100644 --- a/svx/source/svdraw/svdcrtv.cxx +++ b/svx/source/svdraw/svdcrtv.cxx @@ -197,8 +197,10 @@ void SdrCreateView::ImpClearVars() ImpClearConnectMarker(); } -SdrCreateView::SdrCreateView(SdrModel* pModel1, OutputDevice* pOut) -: SdrDragView(pModel1,pOut), +SdrCreateView::SdrCreateView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrDragView(rSdrModel, pOut), mpCoMaOverlay(nullptr), mpCreateViewExtraData(new ImpSdrCreateViewExtraData()) { @@ -348,7 +350,10 @@ void SdrCreateView::SetCurrentObj(sal_uInt16 nIdent, SdrInventor nInvent) nCurrentInvent=nInvent; nCurrentIdent=nIdent; SdrObject * pObj = (nIdent == OBJ_NONE) ? nullptr : - SdrObjFactory::MakeNewObject(nInvent, nIdent, nullptr); + SdrObjFactory::MakeNewObject( + *GetModel(), + nInvent, + nIdent); if(pObj) { @@ -407,14 +412,14 @@ bool SdrCreateView::ImpBegCreateObj(SdrInventor nInvent, sal_uInt16 nIdent, cons { pCurrentCreate->SetPage(pCreatePV->GetPage()); } - else if (mpModel) - { - pCurrentCreate->SetModel(mpModel); - } } else { - pCurrentCreate = SdrObjFactory::MakeNewObject(nInvent, nIdent, pCreatePV->GetPage(), mpModel); + pCurrentCreate = SdrObjFactory::MakeNewObject( + *mpModel, + nInvent, + nIdent, + pCreatePV->GetPage()); } Point aPnt(rPnt); diff --git a/svx/source/svdraw/svddrgv.cxx b/svx/source/svdraw/svddrgv.cxx index b13383b27a32..5d18d6840d27 100644 --- a/svx/source/svdraw/svddrgv.cxx +++ b/svx/source/svdraw/svddrgv.cxx @@ -71,8 +71,10 @@ void SdrDragView::ImpClearVars() mbSolidDragging = getOptionsDrawinglayer().IsSolidDragCreate(); } -SdrDragView::SdrDragView(SdrModel* pModel1, OutputDevice* pOut) -: SdrExchangeView(pModel1,pOut) +SdrDragView::SdrDragView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrExchangeView(rSdrModel, pOut) { ImpClearVars(); } diff --git a/svx/source/svdraw/svdedtv.cxx b/svx/source/svdraw/svdedtv.cxx index c373caac480f..ce620ae67e41 100644 --- a/svx/source/svdraw/svdedtv.cxx +++ b/svx/source/svdraw/svdedtv.cxx @@ -88,8 +88,10 @@ void SdrEditView::ImpClearVars() bPossibilitiesDirty=true; // << Purify didn't like this } -SdrEditView::SdrEditView(SdrModel* pModel1, OutputDevice* pOut): - SdrMarkView(pModel1,pOut) +SdrEditView::SdrEditView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrMarkView(rSdrModel, pOut) { ImpClearVars(); } @@ -98,7 +100,6 @@ 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 01820c63bc34..ef63499a1eb8 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(OBJ_PATHFILL, aMergePolyPolygonA); + SdrPathObj* pPath = new SdrPathObj(pAttrObj->getSdrModelFromSdrObject(), 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(eKind,aPolyPolygon); + SdrPathObj* pPath = new SdrPathObj(pAttrObj->getSdrModelFromSdrObject(), eKind, aPolyPolygon); // attributes of the lowest object ImpCopyAttributes(pAttrObj, pPath); @@ -1522,7 +1522,10 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, if(!bMakeLines || nPointCount < 2) { - SdrPathObj* pPath = new SdrPathObj(static_cast<SdrObjKind>(pSrcPath->GetObjIdentifier()), basegfx::B2DPolyPolygon(rCandidate)); + SdrPathObj* pPath = new SdrPathObj( + pSrcPath->getSdrModelFromSdrObject(), + static_cast<SdrObjKind>(pSrcPath->GetObjIdentifier()), + basegfx::B2DPolyPolygon(rCandidate)); ImpCopyAttributes(pSrcPath, pPath); pLast = pPath; rOL.InsertObject(pPath, rPos); @@ -1556,7 +1559,10 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, aNewPolygon.append(rCandidate.getB2DPoint(nNextIndex)); } - SdrPathObj* pPath = new SdrPathObj(eKind, basegfx::B2DPolyPolygon(aNewPolygon)); + SdrPathObj* pPath = new SdrPathObj( + pSrcPath->getSdrModelFromSdrObject(), + eKind, + basegfx::B2DPolyPolygon(aNewPolygon)); ImpCopyAttributes(pSrcPath, pPath); pLast = pPath; rOL.InsertObject(pPath, rPos); @@ -1584,7 +1590,6 @@ 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()) { @@ -1603,7 +1608,9 @@ void SdrEditView::ImpDismantleOneObject(const SdrObject* pObj, SdrObjList& rOL, { // #i37011# also create a text object and add at rPos + 1 SdrObject* pTextObj = SdrObjFactory::MakeNewObject( - pCustomShape->GetObjInventor(), OBJ_TEXT, nullptr, pCustomShape->GetModel()); + pCustomShape->getSdrModelFromSdrObject(), + pCustomShape->GetObjInventor(), + OBJ_TEXT); // Copy text content OutlinerParaObject* pParaObj = pCustomShape->GetOutlinerParaObject(); @@ -1754,14 +1761,13 @@ void SdrEditView::GroupMarked() SdrMark* pM=GetSdrMarkByIndex(nm); if (pM->GetPageView()==pPV) { - if (pGrp==nullptr) + SdrObject* pObj=pM->GetMarkedSdrObj(); + if (nullptr==pGrp) { - if (pGrp==nullptr) - pGrp=new SdrObjGroup; + pGrp = new SdrObjGroup(pObj->getSdrModelFromSdrObject()); 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 51ef80fb46b6..d03a55fe4b11 100644 --- a/svx/source/svdraw/svdedxv.cxx +++ b/svx/source/svdraw/svdedxv.cxx @@ -88,8 +88,10 @@ void SdrObjEditView::ImpClearVars() bTextEditOnlyOneView=false; } -SdrObjEditView::SdrObjEditView(SdrModel* pModel1, OutputDevice* pOut): - SdrGlueEditView(pModel1,pOut), +SdrObjEditView::SdrObjEditView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrGlueEditView(rSdrModel, pOut), mpOldTextEditUndoManager(nullptr) { ImpClearVars(); @@ -1089,7 +1091,7 @@ bool SdrObjEditView::SdrBeginTextEdit( mxTextEditObj.reset( pObj ); pTextEditOutliner=pGivenOutliner; if (pTextEditOutliner==nullptr) - pTextEditOutliner = SdrMakeOutliner( OutlinerMode::TextObject, *mxTextEditObj->GetModel() ); + pTextEditOutliner = SdrMakeOutliner( OutlinerMode::TextObject, mxTextEditObj->getSdrModelFromSdrObject() ); { SvtAccessibilityOptions aOptions; @@ -1588,8 +1590,7 @@ SdrEndTextEditKind SdrObjEditView::SdrEndTextEdit(bool bDontDeleteReally) } if( pTEObj && - pTEObj->GetModel() && - !pTEObj->GetModel()->isLocked() && + !pTEObj->getSdrModelFromSdrObject().isLocked() && pTEObj->GetBroadcaster()) { SdrHint aHint(SdrHintKind::EndEdit, *pTEObj); @@ -2408,11 +2409,17 @@ void SdrObjEditView::MarkListHasChanged() const SdrMarkList& rMarkList=GetMarkedObjectList(); if( rMarkList.GetMarkCount() == 1 ) { - const SdrObject* pObj= rMarkList.GetMark(0)->GetMarkedSdrObj(); + const SdrObject* pObj(rMarkList.GetMark(0)->GetMarkedSdrObj()); + SdrView* pView(dynamic_cast< SdrView* >(this)); + // check for table - if( pObj && (pObj->GetObjInventor() == SdrInventor::Default ) && (pObj->GetObjIdentifier() == OBJ_TABLE) ) + if(pObj && pView && (pObj->GetObjInventor() == SdrInventor::Default ) && (pObj->GetObjIdentifier() == OBJ_TABLE)) { - mxSelectionController = sdr::table::CreateTableController( this, static_cast<sdr::table::SdrTableObj const *>(pObj), mxLastSelectionController ); + mxSelectionController = sdr::table::CreateTableController( + *pView, + static_cast<const sdr::table::SdrTableObj&>(*pObj), + mxLastSelectionController); + if( mxSelectionController.is() ) { mxLastSelectionController.clear(); diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx index 4b29e2c53efe..24479d6e8a06 100644 --- a/svx/source/svdraw/svdetc.cxx +++ b/svx/source/svdraw/svdetc.cxx @@ -531,9 +531,6 @@ namespace const SdrLayerIDSet& rVisLayers, Color& rCol) { - if(!rList.GetModel()) - return false; - bool bRet(false); bool bMaster(rList.GetPage() && rList.GetPage()->IsMasterPage()); @@ -576,9 +573,6 @@ 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 f3806362aba6..3f3a93565979 100644 --- a/svx/source/svdraw/svdfmtf.cxx +++ b/svx/source/svdraw/svdfmtf.cxx @@ -557,6 +557,7 @@ void ImpSdrGDIMetaFileImport::InsertObj(SdrObject* pObj, bool bScale) if(!aNewRange.isEmpty()) { pObj = new SdrPathObj( + *mpModel, aNewPoly.isClosed() ? OBJ_POLY : OBJ_PLIN, aNewPoly); @@ -686,7 +687,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction const & rAct) if(bCreateLineObject) { - SdrPathObj* pPath = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aLine)); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + OBJ_LINE, + basegfx::B2DPolyPolygon(aLine)); mnLineWidth = nNewLineWidth; maLineJoin = rLineInfo.GetLineJoin(); maLineCap = rLineInfo.GetLineCap(); @@ -705,14 +709,18 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaLineAction const & rAct) void ImpSdrGDIMetaFileImport::DoAction(MetaRectAction const & rAct) { - SdrRectObj* pRect=new SdrRectObj(rAct.GetRect()); + SdrRectObj* pRect = new SdrRectObj( + *mpModel, + rAct.GetRect()); SetAttributes(pRect); InsertObj(pRect); } void ImpSdrGDIMetaFileImport::DoAction(MetaRoundRectAction const & rAct) { - SdrRectObj* pRect=new SdrRectObj(rAct.GetRect()); + SdrRectObj* pRect = new SdrRectObj( + *mpModel, + rAct.GetRect()); SetAttributes(pRect); long nRad=(rAct.GetHorzRound()+rAct.GetVertRound())/2; if (nRad!=0) { @@ -725,7 +733,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaRoundRectAction const & rAct) void ImpSdrGDIMetaFileImport::DoAction(MetaEllipseAction const & rAct) { - SdrCircObj* pCirc=new SdrCircObj(OBJ_CIRC,rAct.GetRect()); + SdrCircObj* pCirc=new SdrCircObj( + *mpModel, + OBJ_CIRC, + rAct.GetRect()); SetAttributes(pCirc); InsertObj(pCirc); } @@ -735,7 +746,10 @@ 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(OBJ_CARC,rAct.GetRect(),nStart,nEnd); + SdrCircObj* pCirc = new SdrCircObj( + *mpModel, + OBJ_CARC, + rAct.GetRect(),nStart,nEnd); SetAttributes(pCirc); InsertObj(pCirc); } @@ -745,7 +759,12 @@ 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(OBJ_SECT,rAct.GetRect(),nStart,nEnd); + SdrCircObj* pCirc = new SdrCircObj( + *mpModel, + OBJ_SECT, + rAct.GetRect(), + nStart, + nEnd); SetAttributes(pCirc); InsertObj(pCirc); } @@ -755,7 +774,12 @@ 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(OBJ_CCUT,rAct.GetRect(),nStart,nEnd); + SdrCircObj* pCirc = new SdrCircObj( + *mpModel, + OBJ_CCUT, + rAct.GetRect(), + nStart, + nEnd); SetAttributes(pCirc); InsertObj(pCirc); } @@ -911,6 +935,7 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaPolyLineAction const & rAct ) if(bCreateLineObject) { SdrPathObj* pPath = new SdrPathObj( + *mpModel, aSource.isClosed() ? OBJ_POLY : OBJ_PLIN, basegfx::B2DPolyPolygon(aSource)); mnLineWidth = nNewLineWidth; @@ -942,7 +967,10 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaPolygonAction const & rAct ) { // #i73407# make sure polygon is closed, it's a filled primitive aSource.setClosed(true); - SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, basegfx::B2DPolyPolygon(aSource)); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + OBJ_POLY, + basegfx::B2DPolyPolygon(aSource)); SetAttributes(pPath); InsertObj(pPath, false); } @@ -963,7 +991,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaPolyPolygonAction const & rAct) { // #i73407# make sure polygon is closed, it's a filled primitive aSource.setClosed(true); - SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + OBJ_POLY, + aSource); SetAttributes(pPath); InsertObj(pPath, false); } @@ -990,7 +1021,10 @@ void ImpSdrGDIMetaFileImport::ImportText( const Point& rPos, const OUString& rSt aPos.AdjustY( -nTextHeight ); tools::Rectangle aTextRect( aPos, aSize ); - SdrRectObj* pText =new SdrRectObj( OBJ_TEXT, aTextRect ); + SdrRectObj* pText = new SdrRectObj( + *mpModel, + OBJ_TEXT, + aTextRect); pText->SetMergedItem ( makeSdrTextUpperDistItem (0)); pText->SetMergedItem ( makeSdrTextLowerDistItem (0)); @@ -1009,7 +1043,6 @@ 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 ); @@ -1059,7 +1092,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpAction const & rAct) { tools::Rectangle aRect(rAct.GetPoint(),rAct.GetBitmap().GetSizePixel()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); - SdrGrafObj* pGraf=new SdrGrafObj(Graphic(rAct.GetBitmap()),aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + Graphic(rAct.GetBitmap()), + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1071,7 +1107,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScaleAction const & rAct) { tools::Rectangle aRect(rAct.GetPoint(),rAct.GetSize()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); - SdrGrafObj* pGraf=new SdrGrafObj(Graphic(rAct.GetBitmap()),aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + Graphic(rAct.GetBitmap()), + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1083,7 +1122,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExAction const & rAct) { tools::Rectangle aRect(rAct.GetPoint(),rAct.GetBitmapEx().GetSizePixel()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); - SdrGrafObj* pGraf=new SdrGrafObj( rAct.GetBitmapEx(), aRect ); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + rAct.GetBitmapEx(), + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1095,7 +1137,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScaleAction const & rAct) { tools::Rectangle aRect(rAct.GetPoint(),rAct.GetSize()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); - SdrGrafObj* pGraf=new SdrGrafObj( rAct.GetBitmapEx(), aRect ); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + rAct.GetBitmapEx(), + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1117,7 +1162,10 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaHatchAction const & rAct ) if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource)) { const Hatch& rHatch = rAct.GetHatch(); - SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + 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; @@ -1207,7 +1255,10 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaCommentAction const & rAct, GDIMetaF if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource)) { const Gradient& rGrad = pAct->GetGradient(); - SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + 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; @@ -1275,7 +1326,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpScalePartAction const & rAct) aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); aBitmap.Crop(tools::Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize())); - SdrGrafObj* pGraf = new SdrGrafObj(aBitmap, aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + aBitmap, + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1291,7 +1345,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaBmpExScalePartAction const & rAct) aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); aBitmapEx.Crop(tools::Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize())); - SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + aBitmapEx, + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1305,7 +1362,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaMaskAction const & rAct) BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); - SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + aBitmapEx, + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1319,7 +1379,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaMaskScaleAction const & rAct) BitmapEx aBitmapEx(rAct.GetBitmap(), rAct.GetColor()); aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); - SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + aBitmapEx, + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1334,7 +1397,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaMaskScalePartAction const & rAct) aRect.AdjustRight( 1 ); aRect.AdjustBottom( 1 ); aBitmapEx.Crop(tools::Rectangle(rAct.GetSrcPoint(), rAct.GetSrcSize())); - SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + aBitmapEx, + aRect); // This action is not creating line and fill, set directly, do not use SetAttributes(..) pGraf->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); @@ -1381,6 +1447,7 @@ 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()), @@ -1420,7 +1487,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaTransparentAction const & rAct) aSource.transform(aTransform); aSource.setClosed(true); - SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + OBJ_POLY, + aSource); SetAttributes(pPath); pPath->SetMergedItem(XFillTransparenceItem(rAct.GetTransparence())); InsertObj(pPath, false); @@ -1439,7 +1509,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientExAction const & rAct) if(!mbLastObjWasPolyWithoutLine || !CheckLastPolyLineAndFillMerge(aSource)) { const Gradient& rGradient = rAct.GetGradient(); - SdrPathObj* pPath = new SdrPathObj(OBJ_POLY, aSource); + SdrPathObj* pPath = new SdrPathObj( + *mpModel, + 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())); @@ -1563,7 +1636,10 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct) } // create and add object - SdrGrafObj* pGraf = new SdrGrafObj(aBitmapEx, aRect); + SdrGrafObj* pGraf = new SdrGrafObj( + *mpModel, + 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 64da87b646ab..3bbd461923fd 100644 --- a/svx/source/svdraw/svdglev.cxx +++ b/svx/source/svdraw/svdglev.cxx @@ -29,9 +29,10 @@ #include <svx/svdtrans.hxx> #include <svx/svdobj.hxx> - -SdrGlueEditView::SdrGlueEditView(SdrModel* pModel1, OutputDevice* pOut): - SdrPolyEditView(pModel1,pOut) +SdrGlueEditView::SdrGlueEditView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrPolyEditView(rSdrModel, pOut) { } @@ -39,7 +40,6 @@ 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 711a96e1dfff..b00b9671ece4 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* pModel = _pObj->GetModel(); - SfxItemSet aNewSet(pModel->GetItemPool()); + SdrModel& rModel(_pObj->getSdrModelFromSdrObject()); + SfxItemSet aNewSet(rModel.GetItemPool()); if(IsGradient()) { @@ -1367,11 +1367,11 @@ void SdrHdlGradient::FromIAOToItem(SdrObject* _pObj, bool bSetItemOnObject, bool aNewSet.Put(aNewTransItem); } - if(bUndo && pModel->IsUndoEnabled()) + if(bUndo && rModel.IsUndoEnabled()) { - pModel->BegUndo(SvxResId(IsGradient() ? SIP_XA_FILLGRADIENT : SIP_XA_FILLTRANSPARENCE)); - pModel->AddUndo(pModel->GetSdrUndoFactory().CreateUndoAttrObject(*_pObj)); - pModel->EndUndo(); + rModel.BegUndo(SvxResId(IsGradient() ? SIP_XA_FILLGRADIENT : SIP_XA_FILLTRANSPARENCE)); + rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoAttrObject(*_pObj)); + rModel.EndUndo(); } pObj->SetMergedItemSetAndBroadcast(aNewSet); diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx index 04d0f701247e..bb237ba756cf 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,10 +1372,11 @@ 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); @@ -1476,7 +1477,10 @@ 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)); @@ -1577,14 +1581,18 @@ void SdrModel::Merge(SdrModel& rSourceModel, if (pMasterMap && pMasterNeed && nMasterNeed!=0) { for (sal_uInt16 i=nSrcMasterPageCnt; i>0;) { i--; - if (pMasterNeed[i]) { - SdrPage* pPg=nullptr; - if (bTreadSourceAsConst) { - const SdrPage* pPg1=rSourceModel.GetMasterPage(i); - pPg=pPg1->Clone(); - } else { - pPg=rSourceModel.RemoveMasterPage(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 (pPg!=nullptr) { // Now append all of them to the end of the DstModel. // Don't use InsertMasterPage(), because everything is @@ -1592,7 +1600,6 @@ 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 { @@ -1607,14 +1614,18 @@ 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) { - SdrPage* pPg=nullptr; - if (bTreadSourceAsConst) { - const SdrPage* pPg1=rSourceModel.GetPage(nSourcePos); - pPg=pPg1->Clone(); - } else { - pPg=rSourceModel.RemovePage(nSourcePos); + 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); } + 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 985b415ca3b6..07a5b2876361 100644 --- a/svx/source/svdraw/svdmrkv.cxx +++ b/svx/source/svdraw/svdmrkv.cxx @@ -144,15 +144,17 @@ void SdrMarkView::ImpClearVars() BrkMarkGluePoints(); } -SdrMarkView::SdrMarkView(SdrModel* pModel1, OutputDevice* pOut) -: SdrSnapView(pModel1,pOut), +SdrMarkView::SdrMarkView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrSnapView(rSdrModel, pOut), mpMarkObjOverlay(nullptr), mpMarkPointsOverlay(nullptr), mpMarkGluePointsOverlay(nullptr), maHdlList(this) { ImpClearVars(); - StartListening(*pModel1); + StartListening(rSdrModel); } SdrMarkView::~SdrMarkView() diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx index 70c9faf7978b..783c5e9b5b58 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() - : SdrTextObj() +SdrObjCustomShape::SdrObjCustomShape(SdrModel& rSdrModel) +: SdrTextObj(rSdrModel) , fObjectRotation(0.0) , mbAdjustingTextFrameWidthAndHeight(false) , mpLastShadowGeometry(nullptr) @@ -1346,23 +1346,16 @@ 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 (!pModel || (!pModel->IsCreatingDataObj() && !pModel->IsPasteResize())) + if (!getSdrModelFromSdrObject().IsCreatingDataObj() && !getSdrModelFromSdrObject().IsPasteResize()) { const bool bResizeShapeToFitText(GetObjectItem(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue()); SfxItemSet aSet( @@ -2232,7 +2225,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 ( pModel && bHasText && !rR.IsEmpty() ) + if ( bHasText && !rR.IsEmpty() ) { bool bWdtGrow=bWdt && IsAutoGrowWidth(); bool bHgtGrow=bHgt && IsAutoGrowHeight(); @@ -2243,7 +2236,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(pModel->GetMaxObjSize()); + Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize()); if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() ); if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() ); if (bWdtGrow) @@ -2499,8 +2492,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); - if (pModel!=nullptr) { - Size aTmpSiz(pModel->GetMaxObjSize()); + { + Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize()); if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() ); if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() ); } @@ -2646,11 +2639,9 @@ void SdrObjCustomShape::TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& if (pPara) { - bool bHitTest = false; - if( pModel ) - bHitTest = &pModel->GetHitTestOutliner() == &rOutliner; - + bool bHitTest(&getSdrModelFromSdrObject().GetHitTestOutliner() == &rOutliner); const SdrTextObj* pTestObj = rOutliner.GetTextObj(); + if( !pTestObj || !bHitTest || pTestObj != this || pTestObj->GetOutlinerParaObject() != GetOutlinerParaObject() ) { @@ -2746,9 +2737,9 @@ void SdrObjCustomShape::NbcSetOutlinerParaObject(OutlinerParaObject* pTextObject InvalidateRenderGeometry(); } -SdrObjCustomShape* SdrObjCustomShape::Clone() const +SdrObjCustomShape* SdrObjCustomShape::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrObjCustomShape >(); + return CloneHelper< SdrObjCustomShape >(pTargetModel); } SdrObjCustomShape& SdrObjCustomShape::operator=(const SdrObjCustomShape& rObj) @@ -2815,9 +2806,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 ); @@ -2948,7 +2939,7 @@ void SdrObjCustomShape::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, } // if anchor is used, make position relative to it - if( pModel && pModel->IsWriter() ) + if(getSdrModelFromSdrObject().IsWriter()) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { @@ -3065,7 +3056,7 @@ bool SdrObjCustomShape::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegf basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top()); // position may be relative to anchorpos, convert - if( pModel && pModel->IsWriter() ) + if(getSdrModelFromSdrObject().IsWriter()) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { diff --git a/svx/source/svdraw/svdoattr.cxx b/svx/source/svdraw/svdoattr.cxx index 1f118f838f84..f33a47e63ee5 100644 --- a/svx/source/svdraw/svdoattr.cxx +++ b/svx/source/svdraw/svdoattr.cxx @@ -80,7 +80,8 @@ sdr::properties::BaseProperties* SdrAttrObj::CreateObjectSpecificProperties() } -SdrAttrObj::SdrAttrObj() +SdrAttrObj::SdrAttrObj(SdrModel& rSdrModel) +: SdrObject(rSdrModel) { } @@ -99,26 +100,7 @@ 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 6726c2eafda3..29b66b5cdf92 100644 --- a/svx/source/svdraw/svdobj.cxx +++ b/svx/source/svdraw/svdobj.cxx @@ -226,6 +226,10 @@ 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() ); } @@ -284,10 +288,10 @@ void SdrObject::SetBoundRectDirty() } -SdrObject::SdrObject() : - mpFillGeometryDefiningShape(nullptr) +SdrObject::SdrObject(SdrModel& rSdrModel) +: mpFillGeometryDefiningShape(nullptr) + ,mrSdrModelFromSdrObject(rSdrModel) ,pPage(nullptr) - ,pModel(nullptr) ,pUserCall(nullptr) ,pPlusData(nullptr) ,mpImpl(new Impl) @@ -343,22 +347,7 @@ SdrObject::~SdrObject() // when they get called from ObjectInDestruction(). mpImpl->maObjectUsers.clear(); - 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"); - } - + // UserCall SendUserCall(SdrUserCallType::Delete, GetLastBoundRect()); o3tl::reset_preserve_ptr_during(pPlusData); @@ -370,14 +359,38 @@ SdrObject::~SdrObject() void SdrObject::Free( SdrObject*& _rpObject ) { SdrObject* pObject = _rpObject; _rpObject = nullptr; - if ( pObject == nullptr ) + + if(nullptr == pObject) + { // nothing to do return; + } - 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; + 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"); + } + } + } delete pObject; } @@ -393,28 +406,6 @@ 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; @@ -423,16 +414,23 @@ void SdrObject::SetObjList(SdrObjList* pNewObjList) void SdrObject::SetPage(SdrPage* pNewPage) { - SdrModel* pOldModel = pModel; - SdrPage* pOldPage = pPage; + SdrModel* pOldModel(&getSdrModelFromSdrObject()); + SdrPage* pOldPage(pPage); - pPage=pNewPage; - if (pPage!=nullptr) - { - SdrModel* pMod=pPage->GetModel(); - if (pMod!=pModel && pMod!=nullptr) - SetModel(pMod); - } + 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); + // } + // } // 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 @@ -440,7 +438,14 @@ 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. - if (pOldPage != pPage && !(pOldPage && pPage && pOldModel == pModel)) + // 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())) { SvxShape* const pShape(getSvxShape()); if (pShape && !pShape->HasSdrObjectOwnership()) @@ -512,13 +517,9 @@ sal_Int16 SdrObject::GetRelativeHeightRelation() const return mpImpl->meRelativeHeightRelation; } -SfxItemPool & SdrObject::GetObjectItemPool() const +SfxItemPool& SdrObject::GetObjectItemPool() const { - if(pModel) - return pModel->GetItemPool(); - - // use a static global default pool - return SdrObject::GetGlobalDrawObjectItemPool(); + return getSdrModelFromSdrObject().GetItemPool(); } SdrInventor SdrObject::GetObjInventor() const @@ -636,7 +637,7 @@ void SdrObject::SetName(const OUString& rStr) { // Undo/Redo for setting object's name (#i73249#) bool bUndo( false ); - if ( GetModel() && GetModel()->IsUndoEnabled() ) + if ( getSdrModelFromSdrObject().IsUndoEnabled() ) { bUndo = true; SdrUndoAction* pUndoAction = @@ -645,14 +646,14 @@ void SdrObject::SetName(const OUString& rStr) SdrUndoObjStrAttr::ObjStrAttrType::Name, GetName(), rStr ); - GetModel()->BegUndo( pUndoAction->GetComment() ); - GetModel()->AddUndo( pUndoAction ); + getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() ); + getSdrModelFromSdrObject().AddUndo( pUndoAction ); } pPlusData->aObjName = rStr; // Undo/Redo for setting object's name (#i73249#) if ( bUndo ) { - GetModel()->EndUndo(); + getSdrModelFromSdrObject().EndUndo(); } SetChanged(); BroadcastObjectChange(); @@ -680,7 +681,7 @@ void SdrObject::SetTitle(const OUString& rStr) { // Undo/Redo for setting object's title (#i73249#) bool bUndo( false ); - if ( GetModel() && GetModel()->IsUndoEnabled() ) + if ( getSdrModelFromSdrObject().IsUndoEnabled() ) { bUndo = true; SdrUndoAction* pUndoAction = @@ -689,14 +690,14 @@ void SdrObject::SetTitle(const OUString& rStr) SdrUndoObjStrAttr::ObjStrAttrType::Title, GetTitle(), rStr ); - GetModel()->BegUndo( pUndoAction->GetComment() ); - GetModel()->AddUndo( pUndoAction ); + getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() ); + getSdrModelFromSdrObject().AddUndo( pUndoAction ); } pPlusData->aObjTitle = rStr; // Undo/Redo for setting object's title (#i73249#) if ( bUndo ) { - GetModel()->EndUndo(); + getSdrModelFromSdrObject().EndUndo(); } SetChanged(); BroadcastObjectChange(); @@ -724,7 +725,7 @@ void SdrObject::SetDescription(const OUString& rStr) { // Undo/Redo for setting object's description (#i73249#) bool bUndo( false ); - if ( GetModel() && GetModel()->IsUndoEnabled() ) + if ( getSdrModelFromSdrObject().IsUndoEnabled() ) { bUndo = true; SdrUndoAction* pUndoAction = @@ -733,14 +734,14 @@ void SdrObject::SetDescription(const OUString& rStr) SdrUndoObjStrAttr::ObjStrAttrType::Description, GetDescription(), rStr ); - GetModel()->BegUndo( pUndoAction->GetComment() ); - GetModel()->AddUndo( pUndoAction ); + getSdrModelFromSdrObject().BegUndo( pUndoAction->GetComment() ); + getSdrModelFromSdrObject().AddUndo( pUndoAction ); } pPlusData->aObjDescription = rStr; // Undo/Redo for setting object's description (#i73249#) if ( bUndo ) { - GetModel()->EndUndo(); + getSdrModelFromSdrObject().EndUndo(); } SetChanged(); BroadcastObjectChange(); @@ -835,7 +836,7 @@ const tools::Rectangle& SdrObject::GetLastBoundRect() const void SdrObject::RecalcBoundRect() { // #i101680# suppress BoundRect calculations on import(s) - if ((pModel && pModel->isLocked()) || utl::ConfigManager::IsFuzzing()) + if ((getSdrModelFromSdrObject().isLocked()) || utl::ConfigManager::IsFuzzing()) return; // central new method which will calculate the BoundRect using primitive geometry @@ -865,7 +866,7 @@ void SdrObject::RecalcBoundRect() void SdrObject::BroadcastObjectChange() const { - if ((pModel && pModel->isLocked()) || utl::ConfigManager::IsFuzzing()) + if ((getSdrModelFromSdrObject().isLocked()) || utl::ConfigManager::IsFuzzing()) return; if (mbDelayBroadcastObjectChange) @@ -875,7 +876,7 @@ void SdrObject::BroadcastObjectChange() const } bool bPlusDataBroadcast(pPlusData && pPlusData->pBroadcast); - bool bObjectChange(IsInserted() && pModel); + bool bObjectChange(IsInserted()); if(bPlusDataBroadcast || bObjectChange) { @@ -888,7 +889,7 @@ void SdrObject::BroadcastObjectChange() const if(bObjectChange) { - pModel->Broadcast(aHint); + getSdrModelFromSdrObject().Broadcast(aHint); } } } @@ -899,9 +900,13 @@ void SdrObject::SetChanged() // notification now. ActionChanged(); - if(IsInserted() && pModel) + // 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()) { - pModel->SetChanged(); + getSdrModelFromSdrObject().SetChanged(); } } @@ -929,9 +934,9 @@ bool SdrObject::HasLimitedRotation() const return false; } -SdrObject* SdrObject::Clone() const +SdrObject* SdrObject::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrObject >(); + return CloneHelper< SdrObject >(pTargetModel); } SdrObject& SdrObject::operator=(const SdrObject& rObj) @@ -947,7 +952,6 @@ 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; @@ -1021,19 +1025,9 @@ 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 { - if (pModel!=nullptr) - return pModel->GetMetricString(nVal); - return OUString(); + return getSdrModelFromSdrObject().GetMetricString(nVal); } basegfx::B2DPolyPolygon SdrObject::TakeXorPoly() const @@ -2054,16 +2048,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 && 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 (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 (nLayer!=SDRLAYER_NOTFOUND) { NbcSetLayer(nLayer); @@ -2126,12 +2120,11 @@ void SdrObject::TakeNotPersistAttr(SfxItemSet& rAttr) const } rAttr.Put(SdrLayerIdItem(GetLayer())); - 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())); - } + const SdrLayerAdmin& rLayAd(nullptr != pPage ? pPage->GetLayerAdmin() : getSdrModelFromSdrObject().GetLayerAdmin()); + const SdrLayer* pLayer = rLayAd.GetLayerPerID(GetLayer()); + if(nullptr != pLayer) + { + rAttr.Put(SdrLayerNameItem(pLayer->GetName())); } Point aRef1(rSnap.Center()); Point aRef2(aRef1); aRef2.AdjustY( 1 ); @@ -2309,15 +2302,15 @@ void extractLineContourFromPrimitive2DSequence( } -SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDash) +SdrObject* SdrObject::ImpConvertToContourObj(bool bForceLineDash) { - bool bNoChange(true); + SdrObject* pRetval(nullptr); - if(pRet->LineGeometryUsageIsNecessary()) + if(LineGeometryUsageIsNecessary()) { basegfx::B2DPolyPolygon aMergedLineFillPolyPolygon; basegfx::B2DPolyPolygon aMergedHairlinePolyPolygon; - const drawinglayer::primitive2d::Primitive2DContainer xSequence(pRet->GetViewContact().getViewIndependentPrimitive2DContainer()); + const drawinglayer::primitive2d::Primitive2DContainer xSequence(GetViewContact().getViewIndependentPrimitive2DContainer()); if(!xSequence.empty()) { @@ -2345,7 +2338,7 @@ SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDas if(aMergedLineFillPolyPolygon.count() || (bForceLineDash && aMergedHairlinePolyPolygon.count())) { - SfxItemSet aSet(pRet->GetMergedItemSet()); + SfxItemSet aSet(GetMergedItemSet()); drawing::FillStyle eOldFillStyle = aSet.Get(XATTR_FILLSTYLE).GetValue(); SdrPathObj* aLinePolygonPart = nullptr; SdrPathObj* aLineHairlinePart = nullptr; @@ -2354,8 +2347,10 @@ SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDas if(aMergedLineFillPolyPolygon.count()) { // create SdrObject for filled line geometry - aLinePolygonPart = new SdrPathObj(OBJ_PATHFILL, aMergedLineFillPolyPolygon); - aLinePolygonPart->SetModel(pRet->GetModel()); + aLinePolygonPart = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHFILL, + aMergedLineFillPolyPolygon); // correct item properties aSet.Put(XLineWidthItem(0)); @@ -2375,8 +2370,10 @@ SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDas // 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(OBJ_PATHLINE, aMergedHairlinePolyPolygon); - aLineHairlinePart->SetModel(pRet->GetModel()); + aLineHairlinePart = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aMergedHairlinePolyPolygon); aSet.Put(XLineWidthItem(0)); aSet.Put(XFillStyleItem(drawing::FillStyle_NONE)); @@ -2396,7 +2393,7 @@ SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDas // check if original geometry should be added (e.g. filled and closed) bool bAddOriginalGeometry(false); - SdrPathObj* pPath = dynamic_cast<SdrPathObj*>( pRet ); + SdrPathObj* pPath = dynamic_cast<SdrPathObj*>(this); if(pPath && pPath->IsClosed()) { @@ -2409,20 +2406,17 @@ SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDas // do we need a group? if(bBuildGroup || bAddOriginalGeometry) { - SdrObject* pGroup = new SdrObjGroup; - pGroup->SetModel(pRet->GetModel()); + SdrObject* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); if(bAddOriginalGeometry) { // Add a clone of the original geometry. aSet.ClearItem(); - aSet.Put(pRet->GetMergedItemSet()); + aSet.Put(GetMergedItemSet()); aSet.Put(XLineStyleItem(drawing::LineStyle_NONE)); aSet.Put(XLineWidthItem(0)); - SdrObject* pClone = pRet->Clone(); - - pClone->SetModel(pRet->GetModel()); + SdrObject* pClone = Clone(); pClone->SetMergedItemSet(aSet); pGroup->GetSubList()->NbcInsertObject(pClone); @@ -2438,38 +2432,30 @@ SdrObject* SdrObject::ImpConvertToContourObj(SdrObject* pRet, bool bForceLineDas pGroup->GetSubList()->NbcInsertObject(aLineHairlinePart); } - pRet = pGroup; - - // be more careful with the state describing bool - bNoChange = false; + pRetval = pGroup; } else { if(aLinePolygonPart) { - pRet = aLinePolygonPart; - // be more careful with the state describing bool - bNoChange = false; + pRetval = aLinePolygonPart; } else if(aLineHairlinePart) { - pRet = aLineHairlinePart; - // be more careful with the state describing bool - bNoChange = false; + pRetval = aLineHairlinePart; } } } } - if(bNoChange) + if(nullptr == pRetval) { // due to current method usage, create and return a clone when nothing has changed - SdrObject* pClone = pRet->Clone(); - pClone->SetModel(pRet->GetModel()); - pRet = pClone; + SdrObject* pClone = Clone(); + pRetval = pClone; } - return pRet; + return pRetval; } @@ -2497,8 +2483,7 @@ SdrObject* SdrObject::ConvertToContourObj(SdrObject* pRet, bool bForceLineDash) if(dynamic_cast<const SdrObjGroup*>( pRet) != nullptr) { SdrObjList* pObjList2 = pRet->GetSubList(); - SdrObject* pGroup = new SdrObjGroup; - pGroup->SetModel(pRet->GetModel()); + SdrObject* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); for(size_t a=0; a<pObjList2->GetObjCount(); ++a) { @@ -2518,7 +2503,7 @@ SdrObject* SdrObject::ConvertToContourObj(SdrObject* pRet, bool bForceLineDash) pPathObj->SetPathPoly(basegfx::utils::simplifyCurveSegments(pPathObj->GetPathPoly())); } - pRet = ImpConvertToContourObj(pRet, bForceLineDash); + pRet = pRet->ImpConvertToContourObj(bForceLineDash); } // #i73441# preserve LayerID @@ -2601,10 +2586,10 @@ void SdrObject::SetPrintable(bool bPrn) { bNoPrint=!bPrn; SetChanged(); - if (IsInserted() && pModel!=nullptr) + if (IsInserted()) { SdrHint aHint(SdrHintKind::ObjectChange, *this); - pModel->Broadcast(aHint); + getSdrModelFromSdrObject().Broadcast(aHint); } } } @@ -2615,10 +2600,10 @@ void SdrObject::SetVisible(bool bVisible) { mbVisible = bVisible; SetChanged(); - if (IsInserted() && pModel!=nullptr) + if (IsInserted()) { SdrHint aHint(SdrHintKind::ObjectChange, *this); - pModel->Broadcast(aHint); + getSdrModelFromSdrObject().Broadcast(aHint); } } } @@ -2744,15 +2729,6 @@ 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 ); @@ -2882,7 +2858,7 @@ bool SdrObject::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPo basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top()); // position maybe relative to anchorpos, convert - if( pModel && pModel->IsWriter() ) + if(getSdrModelFromSdrObject().IsWriter()) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { @@ -2966,7 +2942,7 @@ void SdrObject::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const ba } // if anchor is used, make position relative to it - if( pModel && pModel->IsWriter() ) + if(getSdrModelFromSdrObject().IsWriter()) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { @@ -2985,9 +2961,7 @@ void SdrObject::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const ba // Give info if object is in destruction bool SdrObject::IsInDestruction() const { - if(pModel) - return pModel->IsInDestruction(); - return false; + return getSdrModelFromSdrObject().IsInDestruction(); } // return if fill is != drawing::FillStyle_NONE @@ -3056,9 +3030,9 @@ SdrDelayBroadcastObjectChange::~SdrDelayBroadcastObjectChange() } -SdrObject* SdrObjFactory::CreateObjectFromFactory( SdrInventor nInventor, sal_uInt16 nObjIdentifier ) +SdrObject* SdrObjFactory::CreateObjectFromFactory(SdrModel& rSdrModel, SdrInventor nInventor, sal_uInt16 nObjIdentifier) { - SdrObjCreatorParams aParams { nInventor, nObjIdentifier }; + SdrObjCreatorParams aParams { nInventor, nObjIdentifier, rSdrModel }; for (const auto & i : ImpGetUserMakeObjHdl()) { SdrObject* pObj = i.Call(aParams); if (pObj) { @@ -3068,78 +3042,15 @@ SdrObject* SdrObjFactory::CreateObjectFromFactory( SdrInventor nInventor, sal_uI return nullptr; } -SdrObject* SdrObjFactory::MakeNewObject(SdrInventor nInvent, sal_uInt16 nIdent, SdrPage* pPage, SdrModel* pModel) -{ - if (!pModel && pPage) - pModel = pPage->GetModel(); - - SdrObject* pObj = nullptr; - - if (nInvent == SdrInventor::Default) - { - switch (nIdent) - { - 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(); break; -#endif - case sal_uInt16(OBJ_TABLE ): pObj=new sdr::table::SdrTableObj(pModel); break; - } - } - - if (!pObj) - pObj = CreateObjectFromFactory(nInvent, nIdent); - - if (!pObj) - { - // Well, if no one wants it... - return nullptr; - } - - 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& rSdrModel, + SdrInventor nInventor, + sal_uInt16 nIdentifier, + SdrPage* pPage, + const tools::Rectangle* pSnapRect) { - SdrModel* pModel = pPage ? pPage->GetModel() : nullptr; - - SdrObject* pObj = nullptr; - - bool bSetSnapRect = true; + SdrObject* pObj(nullptr); + bool bSetSnapRect(nullptr != pSnapRect); if (nInventor == SdrInventor::Default) { @@ -3147,15 +3058,44 @@ SdrObject* SdrObjFactory::MakeNewObject( { case OBJ_MEASURE: { - pObj = new SdrMeasureObj(rSnapRect.TopLeft(), rSnapRect.BottomRight()); + if(nullptr != pSnapRect) + { + pObj = new SdrMeasureObj( + rSdrModel, + pSnapRect->TopLeft(), + pSnapRect->BottomRight()); + } + else + { + pObj = new SdrMeasureObj(rSdrModel); + } } 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)); + 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: @@ -3163,8 +3103,20 @@ SdrObject* SdrObjFactory::MakeNewObject( case OBJ_TITLETEXT: case OBJ_OUTLINETEXT: { - pObj = new SdrRectObj(static_cast<SdrObjKind>(nIdentifier), rSnapRect); - bSetSnapRect = false; + 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: @@ -3172,38 +3124,52 @@ SdrObject* SdrObjFactory::MakeNewObject( case OBJ_CARC: case OBJ_CCUT: { - pObj = new SdrCircObj(static_cast<SdrObjKind>(nIdentifier), rSnapRect); - bSetSnapRect = false; + 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; 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; + 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; #if HAVE_FEATURE_AVMEDIA - case sal_uInt16(OBJ_MEDIA ): pObj=new SdrMediaObj(); break; + case sal_uInt16(OBJ_MEDIA ): pObj=new SdrMediaObj(rSdrModel); break; #endif - case sal_uInt16(OBJ_TABLE ): pObj=new sdr::table::SdrTableObj(pModel); break; + case sal_uInt16(OBJ_TABLE ): pObj=new sdr::table::SdrTableObj(rSdrModel); break; } } if (!pObj) - pObj = CreateObjectFromFactory(nInventor, nIdentifier); + { + pObj = CreateObjectFromFactory(rSdrModel, nInventor, nIdentifier); + } if (!pObj) { @@ -3211,11 +3177,15 @@ SdrObject* SdrObjFactory::MakeNewObject( return nullptr; } - if (pPage) + if(nullptr != pPage) + { pObj->SetPage(pPage); + } - if (bSetSnapRect) - pObj->SetSnapRect(rSnapRect); + if(bSetSnapRect && nullptr != pSnapRect) + { + pObj->SetSnapRect(*pSnapRect); + } return pObj; } diff --git a/svx/source/svdraw/svdocapt.cxx b/svx/source/svdraw/svdocapt.cxx index 00cb7ded37ab..cd688f348842 100644 --- a/svx/source/svdraw/svdocapt.cxx +++ b/svx/source/svdraw/svdocapt.cxx @@ -189,16 +189,19 @@ sdr::contact::ViewContact* SdrCaptionObj::CreateObjectSpecificViewContact() } -SdrCaptionObj::SdrCaptionObj(): - SdrRectObj(OBJ_TEXT), +SdrCaptionObj::SdrCaptionObj(SdrModel& rSdrModel) +: SdrRectObj(rSdrModel, OBJ_TEXT), aTailPoly(3), // default size: 3 points = 2 lines mbSpecialTextBoxShadow(false), mbFixedTail(false) { } -SdrCaptionObj::SdrCaptionObj(const tools::Rectangle& rRect, const Point& rTail): - SdrRectObj(OBJ_TEXT,rRect), +SdrCaptionObj::SdrCaptionObj( + SdrModel& rSdrModel, + const tools::Rectangle& rRect, + const Point& rTail) +: SdrRectObj(rSdrModel, OBJ_TEXT,rRect), aTailPoly(3), // default size: 3 points = 2 lines mbSpecialTextBoxShadow(false), mbFixedTail(false) @@ -232,9 +235,23 @@ sal_uInt16 SdrCaptionObj::GetObjIdentifier() const return sal_uInt16(OBJ_CAPTION); } -SdrCaptionObj* SdrCaptionObj::Clone() const +SdrCaptionObj* SdrCaptionObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrCaptionObj >(); + 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; } OUString SdrCaptionObj::TakeObjNameSingul() const @@ -663,12 +680,6 @@ 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); @@ -706,8 +717,9 @@ 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; + if (pOL==nullptr) + { + SdrObjGroup* pGrp = new SdrObjGroup(getSdrModelFromSdrObject()); pOL=pGrp->GetSubList(); pRet=pGrp; } @@ -747,7 +759,8 @@ void SdrCaptionObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons handleNegativeScale(aScale, &fRotate); // force metric to pool metric - MapUnit eMapUnit = pModel->GetItemPool().GetMetric(0); + MapUnit eMapUnit(getSdrModelFromSdrObject().GetItemPool().GetMetric(0)); + if(eMapUnit != MapUnit::Map100thMM) { switch(eMapUnit) @@ -772,7 +785,7 @@ void SdrCaptionObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons } // if anchor is used, make position relative to it - if( pModel->IsWriter() ) + if(getSdrModelFromSdrObject().IsWriter()) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { diff --git a/svx/source/svdraw/svdocirc.cxx b/svx/source/svdraw/svdocirc.cxx index dc87f9a5de9a..1dc049f07d17 100644 --- a/svx/source/svdraw/svdocirc.cxx +++ b/svx/source/svdraw/svdocirc.cxx @@ -104,8 +104,10 @@ sdr::contact::ViewContact* SdrCircObj::CreateObjectSpecificViewContact() return new sdr::contact::ViewContactOfSdrCircObj(*this); } - -SdrCircObj::SdrCircObj(SdrObjKind eNewKind) +SdrCircObj::SdrCircObj( + SdrModel& rSdrModel, + SdrObjKind eNewKind) +: SdrRectObj(rSdrModel) { nStartAngle=0; nEndAngle=36000; @@ -113,8 +115,11 @@ SdrCircObj::SdrCircObj(SdrObjKind eNewKind) bClosedObj=eNewKind!=OBJ_CARC; } -SdrCircObj::SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect): - SdrRectObj(rRect) +SdrCircObj::SdrCircObj( + SdrModel& rSdrModel, + SdrObjKind eNewKind, + const tools::Rectangle& rRect) +: SdrRectObj(rSdrModel, rRect) { nStartAngle=0; nEndAngle=36000; @@ -122,8 +127,13 @@ SdrCircObj::SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect): bClosedObj=eNewKind!=OBJ_CARC; } -SdrCircObj::SdrCircObj(SdrObjKind eNewKind, const tools::Rectangle& rRect, long nNewStartWink, long nNewEndWink): - SdrRectObj(rRect) +SdrCircObj::SdrCircObj( + SdrModel& rSdrModel, + SdrObjKind eNewKind, + const tools::Rectangle& rRect, + long nNewStartWink, + long nNewEndWink) +: SdrRectObj(rSdrModel, rRect) { long nAngleDif=nNewEndWink-nNewStartWink; nStartAngle=NormAngle360(nNewStartWink); @@ -338,9 +348,22 @@ OUString SdrCircObj::TakeObjNamePlural() const return ImpGetResStr(pID); } -SdrCircObj* SdrCircObj::Clone() const +SdrCircObj* SdrCircObj::Clone(SdrModel* pTargetModel) const +{ + return CloneHelper< SdrCircObj >(pTargetModel); +} + +SdrCircObj& SdrCircObj::operator=(const SdrCircObj& rObj) { - return CloneHelper< SdrCircObj >(); + if( this == &rObj ) + return *this; + SdrRectObj::operator=(rObj); + + meCircleKind = rObj.meCircleKind; + nStartAngle = rObj.nStartAngle; + nEndAngle = rObj.nEndAngle; + + return *this; } basegfx::B2DPolyPolygon SdrCircObj::TakeXorPoly() const @@ -576,7 +599,7 @@ OUString SdrCircObj::getSpecialDragComment(const SdrDragStat& rDrag) const nAngle = pU->nEnd; } - aBuf.append(GetAngleStr(nAngle)); + aBuf.append(SdrModel::GetAngleString(nAngle)); aBuf.append(')'); } @@ -594,7 +617,7 @@ OUString SdrCircObj::getSpecialDragComment(const SdrDragStat& rDrag) const ImpTakeDescriptionStr(STR_DragCircAngle, aStr); OUStringBuffer aBuf(aStr); aBuf.append(" ("); - aBuf.append(GetAngleStr(nAngle)); + aBuf.append(SdrModel::GetAngleString(nAngle)); aBuf.append(')'); return aBuf.makeStringAndClear(); diff --git a/svx/source/svdraw/svdoedge.cxx b/svx/source/svdraw/svdoedge.cxx index 45203c3d63cf..ce5a636a5e03 100644 --- a/svx/source/svdraw/svdoedge.cxx +++ b/svx/source/svdraw/svdoedge.cxx @@ -161,8 +161,8 @@ sdr::contact::ViewContact* SdrEdgeObj::CreateObjectSpecificViewContact() } -SdrEdgeObj::SdrEdgeObj() -: SdrTextObj(), +SdrEdgeObj::SdrEdgeObj(SdrModel& rSdrModel) +: SdrTextObj(rSdrModel), nNotifyingCount(0), bEdgeTrackDirty(false), bEdgeTrackUserDefined(false), @@ -520,13 +520,14 @@ void SdrEdgeObj::ImpSetTailPoint(bool bTail1, const Point& rPt) void SdrEdgeObj::ImpDirtyEdgeTrack() { - if ( !bEdgeTrackUserDefined || !(GetModel() && GetModel()->isLocked()) ) + if ( !bEdgeTrackUserDefined || !getSdrModelFromSdrObject().isLocked() ) bEdgeTrackDirty = true; } void SdrEdgeObj::ImpUndirtyEdgeTrack() { - if (bEdgeTrackDirty && (GetModel() && GetModel()->isLocked()) ) { + if (bEdgeTrackDirty && getSdrModelFromSdrObject().isLocked()) + { ImpRecalcEdgeTrack(); } } @@ -540,7 +541,7 @@ void SdrEdgeObj::ImpRecalcEdgeTrack() } // #i120437# also not when model locked during import, but remember - if(!GetModel() || GetModel()->isLocked()) + if(getSdrModelFromSdrObject().isLocked()) { mbSuppressed = true; return; @@ -1615,9 +1616,9 @@ void SdrEdgeObj::Reformat() } } -SdrEdgeObj* SdrEdgeObj::Clone() const +SdrEdgeObj* SdrEdgeObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrEdgeObj >(); + return CloneHelper< SdrEdgeObj >(pTargetModel); } SdrEdgeObj& SdrEdgeObj::operator=(const SdrEdgeObj& rObj) @@ -2247,7 +2248,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 (!GetModel() || !GetModel()->IsPasteResize()) + if (!getSdrModelFromSdrObject().IsPasteResize()) { aEdgeInfo.aObj1Line2 = Point(); aEdgeInfo.aObj1Line3 = Point(); diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index 1a00716fa088..e61a09da8e2b 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* pModel = rGrafObj.GetModel(); - sfx2::LinkManager* pLinkManager= pModel ? pModel->GetLinkManager() : nullptr; + SdrModel& rModel(rGrafObj.getSdrModelFromSdrObject()); + sfx2::LinkManager* pLinkManager(rModel.GetLinkManager()); if( pLinkManager && rValue.hasValue() ) { @@ -325,15 +325,14 @@ void SdrGrafObj::onGraphicChanged() } } - -SdrGrafObj::SdrGrafObj() - : SdrRectObj() - , mpGraphicObject(new GraphicObject) - , pGraphicLink(nullptr) - , bMirrored(false) - , mbIsSignatureLine(false) - , mbIsSignatureLineShowSignDate(true) - , mbIsSignatureLineCanAddComment(false) +SdrGrafObj::SdrGrafObj(SdrModel& rSdrModel) +: SdrRectObj(rSdrModel) + ,mpGraphicObject(new GraphicObject) + ,pGraphicLink(nullptr) + ,bMirrored(false) + ,mbIsSignatureLine(false) + ,mbIsSignatureLineShowSignDate(true) + ,mbIsSignatureLineCanAddComment(false) { mpGraphicObject->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) ); onGraphicChanged(); @@ -352,14 +351,17 @@ SdrGrafObj::SdrGrafObj() mbSupportTextIndentingOnLineWidthChange = 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) +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) { mpGraphicObject->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) ); onGraphicChanged(); @@ -378,14 +380,16 @@ SdrGrafObj::SdrGrafObj(const Graphic& rGraphic, const tools::Rectangle& rRect) mbSupportTextIndentingOnLineWidthChange = false; } -SdrGrafObj::SdrGrafObj(const Graphic& rGraphic) - : SdrRectObj() - , mpGraphicObject(new GraphicObject(rGraphic)) - , pGraphicLink(nullptr) - , bMirrored(false) - , mbIsSignatureLine(false) - , mbIsSignatureLineShowSignDate(true) - , mbIsSignatureLineCanAddComment(false) +SdrGrafObj::SdrGrafObj( + SdrModel& rSdrModel, + const Graphic& rGraphic) +: SdrRectObj(rSdrModel) + ,mpGraphicObject(new GraphicObject(rGraphic)) + ,pGraphicLink(nullptr) + ,bMirrored(false) + ,mbIsSignatureLine(false) + ,mbIsSignatureLineShowSignDate(true) + ,mbIsSignatureLineCanAddComment(false) { mpGraphicObject->SetSwapStreamHdl( LINK(this, SdrGrafObj, ImpSwapHdl) ); onGraphicChanged(); @@ -481,10 +485,12 @@ Graphic SdrGrafObj::GetTransformedGraphic( SdrGrafObjTransformsAttrs nTransformF { // Refactored most of the code to GraphicObject, where // everybody can use e.g. the cropping functionality - - MapMode aDestMap( pModel->GetScaleUnit(), Point(), pModel->GetScaleFraction(), pModel->GetScaleFraction() ); - const Size aDestSize( GetLogicRect().GetSize() ); - + MapMode aDestMap( + getSdrModelFromSdrObject().GetScaleUnit(), + Point(), + getSdrModelFromSdrObject().GetScaleFraction(), + getSdrModelFromSdrObject().GetScaleFraction()); + const Size aDestSize( GetLogicRect().GetSize() ); GraphicAttr aActAttr = GetGraphicAttr(nTransformFlags); // Delegate to moved code in GraphicObject @@ -559,11 +565,12 @@ const Size& SdrGrafObj::GetGrafPrefSize() const void SdrGrafObj::SetGrafStreamURL( const OUString& rGraphicStreamURL ) { mbIsPreview = false; + if( rGraphicStreamURL.isEmpty() ) { mpGraphicObject->SetUserData(); } - else if( pModel->IsSwapGraphics() ) + else if(getSdrModelFromSdrObject().IsSwapGraphics() ) { mpGraphicObject->SetUserData( rGraphicStreamURL ); } @@ -580,21 +587,20 @@ Size SdrGrafObj::getOriginalSize() const if (aGrafInfo.IsCropped()) { - 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; + 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); aSize = Size ( aCroppedWidth, aCroppedHeight); } if ( GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel ) - aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapMode(GetModel()->GetScaleUnit())); + aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapMode(getSdrModelFromSdrObject().GetScaleUnit())); else - aSize = OutputDevice::LogicToLogic(aSize, GetGrafPrefMapMode(), MapMode(GetModel()->GetScaleUnit())); + aSize = OutputDevice::LogicToLogic(aSize, GetGrafPrefMapMode(), MapMode(getSdrModelFromSdrObject().GetScaleUnit())); return aSize; } @@ -629,7 +635,7 @@ void SdrGrafObj::ForceSwapIn() const void SdrGrafObj::ImpRegisterLink() { - sfx2::LinkManager* pLinkManager = pModel != nullptr ? pModel->GetLinkManager() : nullptr; + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); if( pLinkManager != nullptr && pGraphicLink == nullptr ) { @@ -645,7 +651,7 @@ void SdrGrafObj::ImpRegisterLink() void SdrGrafObj::ImpDeregisterLink() { - sfx2::LinkManager* pLinkManager = pModel != nullptr ? pModel->GetLinkManager() : nullptr; + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); if( pLinkManager != nullptr && pGraphicLink!=nullptr) { @@ -730,11 +736,11 @@ bool SdrGrafObj::ImpUpdateGraphicLink( bool bAsynchron ) const void SdrGrafObj::ImpSetLinkedGraphic( const Graphic& rGraphic ) { - const bool bIsChanged = GetModel()->IsChanged(); + const bool bIsChanged(getSdrModelFromSdrObject().IsChanged()); NbcSetGraphic( rGraphic ); ActionChanged(); BroadcastObjectChange(); - GetModel()->SetChanged( bIsChanged ); + getSdrModelFromSdrObject().SetChanged(bIsChanged); } OUString SdrGrafObj::TakeObjNameSingul() const @@ -894,9 +900,9 @@ SdrObject* SdrGrafObj::getFullDragClone() const return pRetval; } -SdrGrafObj* SdrGrafObj::Clone() const +SdrGrafObj* SdrGrafObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrGrafObj >(); + return CloneHelper< SdrGrafObj >(pTargetModel); } SdrGrafObj& SdrGrafObj::operator=( const SdrGrafObj& rObj ) @@ -1016,14 +1022,14 @@ void SdrGrafObj::SetPage( SdrPage* pNewPage ) ImpDeregisterLink(); } - if(!pModel && !GetStyleSheet() && pNewPage && pNewPage->GetModel()) + if(!GetStyleSheet() && pNewPage) { // #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->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(); + SfxStyleSheet* pSheet(pNewPage->getSdrModelFromSdrPage().GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj()); if(pSheet) { @@ -1042,28 +1048,6 @@ 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); @@ -1083,11 +1067,15 @@ GDIMetaFile SdrGrafObj::getMetafileFromEmbeddedVectorGraphicData() const { GDIMetaFile aRetval; - if(isEmbeddedVectorGraphicData() && GetModel()) + if(isEmbeddedVectorGraphicData()) { ScopedVclPtrInstance< VirtualDevice > pOut; const tools::Rectangle aBoundRect(GetCurrentBoundRect()); - const MapMode aMap(GetModel()->GetScaleUnit(), Point(), GetModel()->GetScaleFraction(), GetModel()->GetScaleFraction()); + const MapMode aMap( + getSdrModelFromSdrObject().GetScaleUnit(), + Point(), + getSdrModelFromSdrObject().GetScaleFraction(), + getSdrModelFromSdrObject().GetScaleFraction()); pOut->EnableOutput(false); pOut->SetMapMode(aMap); @@ -1132,8 +1120,11 @@ 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(*GetModel(), GetLayer(), maRect); - SdrObjGroup* pGrp = new SdrObjGroup(); + ImpSdrGDIMetaFileImport aFilter( + getSdrModelFromSdrObject(), + GetLayer(), + maRect); + SdrObjGroup* pGrp = new SdrObjGroup(getSdrModelFromSdrObject()); if(aFilter.DoImport(aMtf, *pGrp->GetSubList(), 0)) { @@ -1156,7 +1147,6 @@ SdrObject* SdrGrafObj::DoConvertToPolyObj(bool bBezier, bool bAddText ) const pRetval = pGrp; pGrp->NbcSetLayer(GetLayer()); - pGrp->SetModel(GetModel()); if(bAddText) { @@ -1198,10 +1188,8 @@ SdrObject* SdrGrafObj::DoConvertToPolyObj(bool bBezier, bool bAddText ) const if(!pGrp) { - pGrp = new SdrObjGroup(); - + pGrp = new SdrObjGroup(getSdrModelFromSdrObject()); pGrp->NbcSetLayer(GetLayer()); - pGrp->SetModel(GetModel()); pGrp->GetSubList()->NbcInsertObject(pRetval); } @@ -1335,7 +1323,7 @@ IMPL_LINK(SdrGrafObj, ReplacementSwapHdl, const GraphicObject*, pO, SvStream*) // replacement image is always swapped if (pO->IsInSwapOut()) { - SdrSwapGraphicsMode const nSwapMode(pModel->GetSwapGraphicsMode()); + SdrSwapGraphicsMode const nSwapMode(getSdrModelFromSdrObject().GetSwapGraphicsMode()); if (nSwapMode & SdrSwapGraphicsMode::TEMP) { return GRFMGR_AUTOSWAPSTREAM_TEMP; @@ -1359,13 +1347,13 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, const GraphicObject*, pO, SvStream* ) if( pO->IsInSwapOut() ) { - if( pModel && !mbIsPreview && pModel->IsSwapGraphics() && mpGraphicObject->GetSizeBytes() > 20480 ) + if( !mbIsPreview && getSdrModelFromSdrObject().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 = pModel->GetSwapGraphicsMode(); + const SdrSwapGraphicsMode nSwapMode = getSdrModelFromSdrObject().GetSwapGraphicsMode(); if( ( pGraphicLink ) && ( nSwapMode & SdrSwapGraphicsMode::PURGE ) ) @@ -1391,78 +1379,73 @@ IMPL_LINK( SdrGrafObj, ImpSwapHdl, const GraphicObject*, pO, SvStream* ) else if( pO->IsInSwapIn() ) { // can be loaded from the original document stream later - if( pModel != nullptr ) + if(mpGraphicObject->HasUserData()) { - if(mpGraphicObject->HasUserData()) + ::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 ) { - ::comphelper::LifecycleProxy proxy; - OUString aUserData = mpGraphicObject->GetUserData(); - uno::Reference<io::XInputStream> const xStream( - pModel->GetDocumentStream(aUserData, proxy)); + Graphic aGraphic; - std::unique_ptr<SvStream> const pStream( (xStream.is()) - ? ::utl::UcbStreamHelper::CreateStream(xStream) - : nullptr ); + std::unique_ptr<css::uno::Sequence< css::beans::PropertyValue > > pFilterData; - if( pStream != nullptr ) + if(mbInsidePaint && !GetViewContact().HasViewObjectContacts()) { - Graphic aGraphic; - - std::unique_ptr<css::uno::Sequence< css::beans::PropertyValue > > pFilterData; + 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; + } - if(mbInsidePaint && !GetViewContact().HasViewObjectContacts()) + 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 ) { - 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; + mpGraphicObject->SetUserData(aNewUserData); } - - if(!GraphicFilter::GetGraphicFilter().ImportGraphic( - aGraphic, aUserData, *pStream, - GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::NONE, pFilterData.get())) + else { - const OUString aNewUserData( mpGraphicObject->GetUserData() ); - mpGraphicObject->SetGraphic( aGraphic ); - if( mbIsPreview ) - { - mpGraphicObject->SetUserData(aNewUserData); - } - else - { - mpGraphicObject->SetUserData(); - } - - // Graphic successfully swapped in. - pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; + mpGraphicObject->SetUserData(); } - pFilterData.reset(); - pStream->ResetError(); + // Graphic successfully swapped in. + pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; } - } - else if( !ImpUpdateGraphicLink( false ) ) - { - pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; - } - else - { - pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; + pFilterData.reset(); + + pStream->ResetError(); } } - else + else if( !ImpUpdateGraphicLink( false ) ) + { pRet = GRFMGR_AUTOSWAPSTREAM_TEMP; + } + else + { + pRet = GRFMGR_AUTOSWAPSTREAM_LOADED; + } } return pRet; @@ -1481,30 +1464,27 @@ Reference< XInputStream > SdrGrafObj::getInputStream() { Reference< XInputStream > xStream; - if( pModel ) + if (mpGraphicObject && GetGraphic().IsLink()) { - if (mpGraphicObject && GetGraphic().IsLink()) + Graphic aGraphic( GetGraphic() ); + GfxLink aLink( aGraphic.GetLink() ); + sal_uInt32 nSize = aLink.GetDataSize(); + const void* pSourceData = static_cast<const void*>(aLink.GetData()); + if( nSize && pSourceData ) { - 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 ); + 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 d2151f14f4e4..6311106c4e2f 100644 --- a/svx/source/svdraw/svdogrp.cxx +++ b/svx/source/svdraw/svdogrp.cxx @@ -50,32 +50,28 @@ #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() +SdrObjGroup::SdrObjGroup(SdrModel& rSdrModel) +: SdrObject(rSdrModel), + maSdrObjList(), + aRefPoint(0, 0) { - pSub.reset( new SdrObjList(nullptr,nullptr) ); - pSub->SetOwnerObj(this); - pSub->SetListKind(SdrObjListKind::GroupObj); + maSdrObjList.SetOwnerObj(this); + maSdrObjList.SetListKind(SdrObjListKind::GroupObj); bClosedObj=false; } - SdrObjGroup::~SdrObjGroup() { } @@ -83,10 +79,9 @@ SdrObjGroup::~SdrObjGroup() void SdrObjGroup::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const { rInfo.bNoContortion=false; - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); SdrObjTransformInfoRec aInfo; pObj->TakeObjInfo(aInfo); if (!aInfo.bMoveAllowed ) rInfo.bMoveAllowed =false; @@ -145,10 +140,9 @@ SdrLayerID SdrObjGroup::GetLayer() const { bool b1st = true; SdrLayerID nLay = SdrObject::GetLayer(); - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrLayerID nLay1=pOL->GetObj(i)->GetLayer(); + SdrLayerID nLay1=maSdrObjList.GetObj(i)->GetLayer(); if (b1st) { nLay=nLay1; b1st = false; } else if (nLay1!=nLay) return SdrLayerID(0); } @@ -159,10 +153,9 @@ SdrLayerID SdrObjGroup::GetLayer() const void SdrObjGroup::NbcSetLayer(SdrLayerID nLayer) { SdrObject::NbcSetLayer(nLayer); - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - pOL->GetObj(i)->NbcSetLayer(nLayer); + maSdrObjList.GetObj(i)->NbcSetLayer(nLayer); } } @@ -170,58 +163,27 @@ void SdrObjGroup::NbcSetLayer(SdrLayerID nLayer) void SdrObjGroup::SetObjList(SdrObjList* pNewObjList) { SdrObject::SetObjList(pNewObjList); - pSub->SetUpList(pNewObjList); + maSdrObjList.SetUpList(pNewObjList); } void SdrObjGroup::SetPage(SdrPage* pNewPage) { SdrObject::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); - } + maSdrObjList.SetPage(pNewPage); } - SdrObjList* SdrObjGroup::GetSubList() const { - return pSub.get(); + return const_cast< SdrObjList* >(&maSdrObjList); } const tools::Rectangle& SdrObjGroup::GetCurrentBoundRect() const { // <aOutRect> has to contain the bounding rectangle - if ( pSub->GetObjCount()!=0 ) + if ( maSdrObjList.GetObjCount()!=0 ) { - const_cast<SdrObjGroup*>(this)->aOutRect = pSub->GetAllObjBoundRect(); + const_cast<SdrObjGroup*>(this)->aOutRect = maSdrObjList.GetAllObjBoundRect(); } return aOutRect; @@ -230,9 +192,9 @@ const tools::Rectangle& SdrObjGroup::GetCurrentBoundRect() const const tools::Rectangle& SdrObjGroup::GetSnapRect() const { // <aOutRect> has to contain the bounding rectangle - if ( pSub->GetObjCount()!=0 ) + if ( maSdrObjList.GetObjCount()!=0 ) { - return pSub->GetAllObjSnapRect(); + return maSdrObjList.GetAllObjSnapRect(); } else { @@ -240,24 +202,24 @@ const tools::Rectangle& SdrObjGroup::GetSnapRect() const } } -SdrObjGroup* SdrObjGroup::Clone() const +SdrObjGroup* SdrObjGroup::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrObjGroup >(); + return CloneHelper< SdrObjGroup >(pTargetModel); } 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(); - pSub->SetPage(rSourceSubList.GetPage()); - pSub->SetModel(rSourceSubList.GetModel()); - pSub->CopyObjects(*rObj.GetSubList()); + maSdrObjList.SetPage(rSourceSubList.GetPage()); + maSdrObjList.CopyObjects(*rObj.GetSubList()); // copy local parameters aRefPoint = rObj.aRefPoint; @@ -269,7 +231,7 @@ OUString SdrObjGroup::TakeObjNameSingul() const { OUStringBuffer sName; - if(!pSub->GetObjCount()) + if(!maSdrObjList.GetObjCount()) { sName.append(ImpGetResStr(STR_ObjNameSingulGRUPEMPTY)); } @@ -294,7 +256,7 @@ OUString SdrObjGroup::TakeObjNameSingul() const OUString SdrObjGroup::TakeObjNamePlural() const { - if (pSub->GetObjCount()==0) + if (maSdrObjList.GetObjCount()==0) return ImpGetResStr(STR_ObjNamePluralGRUPEMPTY); return ImpGetResStr(STR_ObjNamePluralGRUP); } @@ -308,11 +270,11 @@ void SdrObjGroup::RecalcSnapRect() basegfx::B2DPolyPolygon SdrObjGroup::TakeXorPoly() const { basegfx::B2DPolyPolygon aRetval; - const size_t nObjCount(pSub->GetObjCount()); + const size_t nObjCount(maSdrObjList.GetObjCount()); for(size_t a = 0; a < nObjCount; ++a) { - SdrObject* pObj = pSub->GetObj(a); + SdrObject* pObj = maSdrObjList.GetObj(a); aRetval.append(pObj->TakeXorPoly()); } @@ -341,9 +303,9 @@ long SdrObjGroup::GetRotateAngle() const { long nRetval(0); - if(pSub->GetObjCount()) + if(maSdrObjList.GetObjCount()) { - SdrObject* pObj = pSub->GetObj(0); + SdrObject* pObj = maSdrObjList.GetObj(0); nRetval = pObj->GetRotateAngle(); } @@ -356,9 +318,9 @@ long SdrObjGroup::GetShearAngle(bool /*bVertical*/) const { long nRetval(0); - if(pSub->GetObjCount()) + if(maSdrObjList.GetObjCount()) { - SdrObject* pObj = pSub->GetObj(0); + SdrObject* pObj = maSdrObjList.GetObj(0); nRetval = pObj->GetShearAngle(); } @@ -396,11 +358,10 @@ void SdrObjGroup::NbcSetLogicRect(const tools::Rectangle& rRect) void SdrObjGroup::NbcMove(const Size& rSiz) { aRefPoint.Move(rSiz); - if (pSub->GetObjCount()!=0) { - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + if (maSdrObjList.GetObjCount()!=0) { + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); pObj->NbcMove(rSiz); } } else { @@ -428,11 +389,10 @@ void SdrObjGroup::NbcResize(const Point& rRef, const Fraction& xFact, const Frac } } ResizePoint(aRefPoint,rRef,xFact,yFact); - if (pSub->GetObjCount()!=0) { - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + if (maSdrObjList.GetObjCount()!=0) { + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); pObj->NbcResize(rRef,xFact,yFact); } } else { @@ -446,10 +406,9 @@ void SdrObjGroup::NbcRotate(const Point& rRef, long nAngle, double sn, double cs { SetGlueReallyAbsolute(true); RotatePoint(aRefPoint,rRef,sn,cs); - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); pObj->NbcRotate(rRef,nAngle,sn,cs); } NbcRotateGluePoints(rRef,nAngle,sn,cs); @@ -461,10 +420,9 @@ void SdrObjGroup::NbcMirror(const Point& rRef1, const Point& rRef2) { SetGlueReallyAbsolute(true); MirrorPoint(aRefPoint,rRef1,rRef2); // implementation missing in SvdEtc! - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); pObj->NbcMirror(rRef1,rRef2); } NbcMirrorGluePoints(rRef1,rRef2); @@ -476,10 +434,9 @@ void SdrObjGroup::NbcShear(const Point& rRef, long nAngle, double tn, bool bVShe { SetGlueReallyAbsolute(true); ShearPoint(aRefPoint,rRef,tn); - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); pObj->NbcShear(rRef,nAngle,tn,bVShear); } NbcShearGluePoints(rRef,tn,bVShear); @@ -492,10 +449,9 @@ void SdrObjGroup::NbcSetAnchorPos(const Point& rPnt) aAnchor=rPnt; Size aSiz(rPnt.X()-aAnchor.X(),rPnt.Y()-aAnchor.Y()); aRefPoint.Move(aSiz); - SdrObjList* pOL=pSub.get(); - const size_t nObjCount=pOL->GetObjCount(); + const size_t nObjCount=maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); pObj->NbcSetAnchorPos(rPnt); } } @@ -537,16 +493,15 @@ 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 (pSub->GetObjCount()!=0) { + if (maSdrObjList.GetObjCount()!=0) { // first move the connectors, then everything else - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (pObj->IsEdgeObj()) pObj->Move(rSiz); } for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (!pObj->IsEdgeObj()) pObj->Move(rSiz); } } else { @@ -581,16 +536,15 @@ 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 (pSub->GetObjCount()!=0) { + if (maSdrObjList.GetObjCount()!=0) { // move the connectors first, everything else afterwards - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (pObj->IsEdgeObj()) pObj->Resize(rRef,xFact,yFact,bUnsetRelative); } for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (!pObj->IsEdgeObj()) pObj->Resize(rRef,xFact,yFact,bUnsetRelative); } } else { @@ -614,14 +568,13 @@ 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 - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (pObj->IsEdgeObj()) pObj->Rotate(rRef,nAngle,sn,cs); } for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (!pObj->IsEdgeObj()) pObj->Rotate(rRef,nAngle,sn,cs); } NbcRotateGluePoints(rRef,nAngle,sn,cs); @@ -638,14 +591,13 @@ 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 - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (pObj->IsEdgeObj()) pObj->Mirror(rRef1,rRef2); } for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (!pObj->IsEdgeObj()) pObj->Mirror(rRef1,rRef2); } NbcMirrorGluePoints(rRef1,rRef2); @@ -665,14 +617,13 @@ 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 - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (pObj->IsEdgeObj()) pObj->Shear(rRef,nAngle,tn,bVShear); } for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (!pObj->IsEdgeObj()) pObj->Shear(rRef,nAngle,tn,bVShear); } NbcShearGluePoints(rRef,tn,bVShear); @@ -692,14 +643,13 @@ 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 - SdrObjList* pOL=pSub.get(); - const size_t nObjCount = pOL->GetObjCount(); + const size_t nObjCount = maSdrObjList.GetObjCount(); for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj=pOL->GetObj(i); + SdrObject* pObj=maSdrObjList.GetObj(i); if (pObj->IsEdgeObj()) pObj->SetAnchorPos(rPnt); } for (size_t i=0; i<nObjCount; ++i) { - SdrObject* pObj = pOL->GetObj(i); + SdrObject* pObj = maSdrObjList.GetObj(i); if (!pObj->IsEdgeObj()) pObj->SetAnchorPos(rPnt); } if (bChg) { @@ -726,22 +676,21 @@ void SdrObjGroup::SetRelativePos(const Point& rPnt) void SdrObjGroup::NbcReformatText() { - pSub->NbcReformatAllTextObjects(); + maSdrObjList.NbcReformatAllTextObjects(); } void SdrObjGroup::ReformatText() { - pSub->ReformatAllTextObjects(); + maSdrObjList.ReformatAllTextObjects(); } SdrObject* SdrObjGroup::DoConvertToPolyObj(bool bBezier, bool bAddText) const { - SdrObject* pGroup = new SdrObjGroup; - pGroup->SetModel(GetModel()); + SdrObject* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); - for(size_t a=0; a<pSub->GetObjCount(); ++a) + for(size_t a=0; a<maSdrObjList.GetObjCount(); ++a) { - SdrObject* pIterObj = pSub->GetObj(a); + SdrObject* pIterObj = maSdrObjList.GetObj(a); SdrObject* pResult = pIterObj->DoConvertToPolyObj(bBezier, bAddText); // pResult can be NULL e.g. for empty objects @@ -759,7 +708,7 @@ void SdrObjGroup::dumpAsXml(xmlTextWriterPtr pWriter) const SdrObject::dumpAsXml(pWriter); - pSub->dumpAsXml(pWriter); + maSdrObjList.dumpAsXml(pWriter); xmlTextWriterEndElement(pWriter); } diff --git a/svx/source/svdraw/svdomeas.cxx b/svx/source/svdraw/svdomeas.cxx index 63f33c6cbbce..9c1f6550f66d 100644 --- a/svx/source/svdraw/svdomeas.cxx +++ b/svx/source/svdraw/svdomeas.cxx @@ -94,71 +94,63 @@ OUString SdrMeasureObj::TakeRepresentation(SdrMeasureFieldKind eMeasureFieldKind { case SdrMeasureFieldKind::Value: { - if(pModel) + eModUIUnit = getSdrModelFromSdrObject().GetUIUnit(); + + if(eMeasureUnit == FUNIT_NONE) + eMeasureUnit = eModUIUnit; + + sal_Int32 nLen(GetLen(aPt2 - aPt1)); + Fraction aFact(1,1); + + if(eMeasureUnit != eModUIUnit) { - eModUIUnit = pModel->GetUIUnit(); + // for the unit conversion + aFact *= GetMapFactor(eModUIUnit, eMeasureUnit).X(); + } - if(eMeasureUnit == FUNIT_NONE) - eMeasureUnit = eModUIUnit; + if(aMeasureScale.GetNumerator() != aMeasureScale.GetDenominator()) + { + aFact *= aMeasureScale; + } - sal_Int32 nLen(GetLen(aPt2 - aPt1)); - Fraction aFact(1,1); + if(aFact.GetNumerator() != aFact.GetDenominator()) + { + // scale via BigInt, to avoid overruns + nLen = BigMulDiv(nLen, aFact.GetNumerator(), aFact.GetDenominator()); + } - if(eMeasureUnit != eModUIUnit) - { - // for the unit conversion - aFact *= GetMapFactor(eModUIUnit, eMeasureUnit).X(); - } + if(!aFact.IsValid()) + { + aStr = "?"; + } + else + { + aStr = getSdrModelFromSdrObject().GetMetricString(nLen, true, nNumDigits); + } - if(aMeasureScale.GetNumerator() != aMeasureScale.GetDenominator()) - { - aFact *= aMeasureScale; - } + SvtSysLocale aSysLocale; + const LocaleDataWrapper& rLocaleDataWrapper = aSysLocale.GetLocaleData(); + sal_Unicode cDec(rLocaleDataWrapper.getNumDecimalSep()[0]); + sal_Unicode cDecAlt(rLocaleDataWrapper.getNumDecimalSepAlt().toChar()); - if(aFact.GetNumerator() != aFact.GetDenominator()) - { - // scale via BigInt, to avoid overruns - nLen = BigMulDiv(nLen, aFact.GetNumerator(), aFact.GetDenominator()); - } + if(aStr.indexOf(cDec) != -1 || (cDecAlt && aStr.indexOf(cDecAlt) != -1)) + { + sal_Int32 nLen2(aStr.getLength() - 1); - if(!aFact.IsValid()) - { - aStr = "?"; - } - else + while(aStr[nLen2] == '0') { - aStr = pModel->GetMetricString(nLen, true, nNumDigits); + aStr = aStr.copy(0, nLen2); + nLen2--; } - 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)) + if(aStr[nLen2] == cDec || (cDecAlt && aStr[nLen2] == cDecAlt)) { - 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"; + aStr = aStr.copy(0, nLen2); + nLen2--; } - } - else - { - // if there's no Model ... (e. g. preview in dialog) - aStr = "4711"; + + if(aStr.isEmpty()) + aStr += "0"; } break; @@ -167,16 +159,13 @@ OUString SdrMeasureObj::TakeRepresentation(SdrMeasureFieldKind eMeasureFieldKind { if(bShowUnit) { - if(pModel) - { - eModUIUnit = pModel->GetUIUnit(); + eModUIUnit = getSdrModelFromSdrObject().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; @@ -211,14 +200,19 @@ sdr::contact::ViewContact* SdrMeasureObj::CreateObjectSpecificViewContact() } -SdrMeasureObj::SdrMeasureObj(): +SdrMeasureObj::SdrMeasureObj(SdrModel& rSdrModel) +: SdrTextObj(rSdrModel), bTextDirty(false) { // #i25616# mbSupportTextIndentingOnLineWidthChange = false; } -SdrMeasureObj::SdrMeasureObj(const Point& rPt1, const Point& rPt2): +SdrMeasureObj::SdrMeasureObj( + SdrModel& rSdrModel, + const Point& rPt1, + const Point& rPt2) +: SdrTextObj(rSdrModel), aPt1(rPt1), aPt2(rPt2), bTextDirty(false) @@ -708,9 +702,22 @@ void SdrMeasureObj::TakeUnrotatedSnapRect(tools::Rectangle& rRect) const } } -SdrMeasureObj* SdrMeasureObj::Clone() const +SdrMeasureObj* SdrMeasureObj::Clone(SdrModel* pTargetModel) const +{ + return CloneHelper< SdrMeasureObj >(pTargetModel); +} + +SdrMeasureObj& SdrMeasureObj::operator=(const SdrMeasureObj& rObj) { - return CloneHelper< SdrMeasureObj >(); + if( this == &rObj ) + return *this; + SdrTextObj::operator=(rObj); + + aPt1 = rObj.aPt1; + aPt2 = rObj.aPt2; + bTextDirty = rObj.bTextDirty; + + return *this; } OUString SdrMeasureObj::TakeObjNameSingul() const @@ -1138,8 +1145,7 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const SfxStyleSheet* pStyleSheet = GetStyleSheet(); // prepare group - SdrObjGroup* pGroup = new SdrObjGroup; - pGroup->SetModel(GetModel()); + SdrObjGroup* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); // prepare parameters basegfx::B2DPolyPolygon aPolyPoly; @@ -1153,8 +1159,11 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const aPolyPoly.clear(); aPolyPoly.append(aTmpPolyPolygon[0].getB2DPolygon()); - pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly); - pPath->SetModel(GetModel()); + pPath = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPoly); + pPath->SetMergedItemSet(aSet); pPath->SetStyleSheet(pStyleSheet, true); pGroup->GetSubList()->NbcInsertObject(pPath); @@ -1171,8 +1180,11 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const aPolyPoly.clear(); aPolyPoly.append(aTmpPolyPolygon[0].getB2DPolygon()); - pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly); - pPath->SetModel(GetModel()); + pPath = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPoly); + pPath->SetMergedItemSet(aSet); pPath->SetStyleSheet(pStyleSheet, true); @@ -1183,8 +1195,11 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const aPolyPoly.clear(); aPolyPoly.append(aTmpPolyPolygon[1].getB2DPolygon()); - pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly); - pPath->SetModel(GetModel()); + pPath = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPoly); + pPath->SetMergedItemSet(aSet); pPath->SetStyleSheet(pStyleSheet, true); @@ -1202,8 +1217,11 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const aPolyPoly.clear(); aPolyPoly.append(aTmpPolyPolygon[0].getB2DPolygon()); - pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly); - pPath->SetModel(GetModel()); + pPath = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPoly); + pPath->SetMergedItemSet(aSet); pPath->SetStyleSheet(pStyleSheet, true); @@ -1214,8 +1232,11 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const aPolyPoly.clear(); aPolyPoly.append(aTmpPolyPolygon[1].getB2DPolygon()); - pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly); - pPath->SetModel(GetModel()); + pPath = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPoly); + pPath->SetMergedItemSet(aSet); pPath->SetStyleSheet(pStyleSheet, true); @@ -1229,8 +1250,11 @@ SdrObject* SdrMeasureObj::DoConvertToPolyObj(bool bBezier, bool bAddText) const { aPolyPoly.clear(); aPolyPoly.append(aTmpPolyPolygon[nLoopStart].getB2DPolygon()); - pPath = new SdrPathObj(OBJ_PATHLINE, aPolyPoly); - pPath->SetModel(GetModel()); + pPath = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPoly); + pPath->SetMergedItemSet(aSet); pPath->SetStyleSheet(pStyleSheet, true); @@ -1361,7 +1385,7 @@ bool SdrMeasureObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B basegfx::B2DTuple aTranslate(aRange.getMinimum()); // position maybe relative to anchor position, convert - if( pModel->IsWriter() ) + if( getSdrModelFromSdrObject().IsWriter() ) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { @@ -1370,7 +1394,7 @@ bool SdrMeasureObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B } // force MapUnit to 100th mm - MapUnit eMapUnit = pModel->GetItemPool().GetMetric(0); + MapUnit eMapUnit = getSdrModelFromSdrObject().GetItemPool().GetMetric(0); if(eMapUnit != MapUnit::Map100thMM) { switch(eMapUnit) @@ -1407,7 +1431,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 = pModel->GetItemPool().GetMetric(0); + MapUnit eMapUnit = getSdrModelFromSdrObject().GetItemPool().GetMetric(0); if(eMapUnit != MapUnit::Map100thMM) { switch(eMapUnit) @@ -1429,7 +1453,7 @@ void SdrMeasureObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, cons } } - if( pModel->IsWriter() ) + if( getSdrModelFromSdrObject().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 4c41e76e6dc3..012dc1d35879 100644 --- a/svx/source/svdraw/svdomedia.cxx +++ b/svx/source/svdraw/svdomedia.cxx @@ -65,16 +65,17 @@ struct SdrMediaObj::Impl OUString m_LastFailedPkgURL; }; - -SdrMediaObj::SdrMediaObj() - : SdrRectObj() - , m_xImpl( new Impl ) +SdrMediaObj::SdrMediaObj(SdrModel& rSdrModel) +: SdrRectObj(rSdrModel) + ,m_xImpl( new Impl ) { } -SdrMediaObj::SdrMediaObj( const tools::Rectangle& rRect ) - : SdrRectObj( rRect ) - , m_xImpl( new Impl ) +SdrMediaObj::SdrMediaObj( + SdrModel& rSdrModel, + const tools::Rectangle& rRect) +: SdrRectObj(rSdrModel, rRect) + ,m_xImpl( new Impl ) { } @@ -141,9 +142,9 @@ OUString SdrMediaObj::TakeObjNamePlural() const return ImpGetResStr(STR_ObjNamePluralMEDIA); } -SdrMediaObj* SdrMediaObj::Clone() const +SdrMediaObj* SdrMediaObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrMediaObj >(); + return CloneHelper< SdrMediaObj >(pTargetModel); } SdrMediaObj& SdrMediaObj::operator=(const SdrMediaObj& rObj) @@ -315,8 +316,14 @@ void SdrMediaObj::SetInputStream(uno::Reference<io::XInputStream> const& xStream SAL_WARN("svx", "this is only intended for embedded media"); return; } + OUString tempFileURL; - bool const bSuccess = lcl_CopyToTempFile(xStream, tempFileURL, ""); + const bool bSuccess( + lcl_CopyToTempFile( + xStream, + tempFileURL, + "")); + if (bSuccess) { m_xImpl->m_pTempFile.reset(new MediaTempFile(tempFileURL)); @@ -331,19 +338,14 @@ 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, - SdrModel const *const pModel, - OUString & o_rTempFileURL) + OUString const & rURL, + const SdrModel& rModel, + OUString & o_rTempFileURL) { - if (!pModel) - { - SAL_WARN("svx", "no model"); - return false; - } ::comphelper::LifecycleProxy sourceProxy; uno::Reference<io::XInputStream> xInStream; try { - xInStream = pModel->GetDocumentStream(rURL, sourceProxy); + xInStream = rModel.GetDocumentStream(rURL, sourceProxy); } catch (container::NoSuchElementException const&) { @@ -394,8 +396,12 @@ void SdrMediaObj::mediaPropertiesChanged( const ::avmedia::MediaItem& rNewProper rNewProperties.getTempURL())) { OUString tempFileURL; - bool bSuccess; - bSuccess = lcl_HandlePackageURL(url, GetModel(), tempFileURL); + const bool bSuccess( + lcl_HandlePackageURL( + url, + getSdrModelFromSdrObject(), + tempFileURL)); + if (bSuccess) { m_xImpl->m_pTempFile.reset( diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx index 8a264270bddf..50595c5766df 100644 --- a/svx/source/svdraw/svdoole2.cxx +++ b/svx/source/svdraw/svdoole2.cxx @@ -663,13 +663,42 @@ sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact() return new sdr::contact::ViewContactOfSdrOle2Obj(*this); } -SdrOle2Obj::SdrOle2Obj( bool bFrame_ ) : +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), mpImpl(new SdrOle2ObjImpl(bFrame_)) { + Init(); } -SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const OUString& rNewObjName, const tools::Rectangle& rNewRect) : - SdrRectObj(rNewRect), +SdrOle2Obj::SdrOle2Obj( + SdrModel& rSdrModel, + const svt::EmbeddedObjectRef& rNewObjRef, + const OUString& rNewObjName, + const tools::Rectangle& rNewRect) +: SdrRectObj(rSdrModel, rNewRect), mpImpl(new SdrOle2ObjImpl(false/*bFrame_*/, rNewObjRef)) { mpImpl->aPersistName = rNewObjName; @@ -679,6 +708,8 @@ SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const OUStrin // For math objects, set closed state to transparent SetClosedObj(!ImplIsMathObj( mpImpl->mxObjRef.GetObject() )); + + Init(); } OUString SdrOle2Obj::GetStyleString() @@ -781,7 +812,8 @@ bool SdrOle2Obj::UpdateLinkURL_Impl() if ( mpImpl->mpObjectLink ) { - sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : nullptr; + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); + if ( pLinkManager ) { OUString aNewLinkURL; @@ -831,9 +863,7 @@ bool SdrOle2Obj::UpdateLinkURL_Impl() void SdrOle2Obj::BreakFileLink_Impl() { - uno::Reference<document::XStorageBasedDocument> xDoc; - if ( pModel ) - xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY); + uno::Reference<document::XStorageBasedDocument> xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY); if ( xDoc.is() ) { @@ -858,7 +888,8 @@ void SdrOle2Obj::BreakFileLink_Impl() void SdrOle2Obj::DisconnectFileLink_Impl() { - sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : nullptr; + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); + if ( pLinkManager && mpImpl->mpObjectLink ) { pLinkManager->Remove( mpImpl->mpObjectLink ); @@ -868,18 +899,21 @@ void SdrOle2Obj::DisconnectFileLink_Impl() void SdrOle2Obj::CheckFileLink_Impl() { - if (pModel && mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink) + if (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 = pModel->GetLinkManager(); + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); + if ( pLinkManager ) { mpImpl->mpObjectLink = new SdrEmbedObjectLink( this ); @@ -905,14 +939,16 @@ void SdrOle2Obj::Reconnect_Impl() void SdrOle2Obj::Connect_Impl() { - if( pModel && !mpImpl->aPersistName.isEmpty() ) + if(!mpImpl->aPersistName.isEmpty() ) { try { - ::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist(); + ::comphelper::IEmbeddedHelper* pPers(getSdrModelFromSdrObject().GetPersist()); + if ( pPers ) { comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer(); + if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName ) || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( mpImpl->mxObjRef.GetObject() ) ) ) { @@ -957,9 +993,9 @@ void SdrOle2Obj::Connect_Impl() uno::Reference< container::XChild > xChild( mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY ); if( xChild.is() ) { - uno::Reference< uno::XInterface > xParent( pModel->getUnoModel()); + uno::Reference< uno::XInterface > xParent( getSdrModelFromSdrObject().getUnoModel()); if( xParent.is()) - xChild->setParent( pModel->getUnoModel() ); + xChild->setParent( getSdrModelFromSdrObject().getUnoModel() ); } } @@ -1040,9 +1076,9 @@ void SdrOle2Obj::Disconnect_Impl() { try { - if ( pModel && !mpImpl->aPersistName.isEmpty() ) + if ( !mpImpl->aPersistName.isEmpty() ) { - if( pModel->IsInDestruction() ) + if( getSdrModelFromSdrObject().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 @@ -1078,7 +1114,7 @@ void SdrOle2Obj::Disconnect_Impl() } else if ( mpImpl->mxObjRef.is() ) { - if ( pModel->getUnoModel().is() ) + if ( getSdrModelFromSdrObject().getUnoModel().is() ) { // remove object, but don't close it (that's up to someone else) comphelper::EmbeddedObjectContainer* pContainer = mpImpl->mxObjRef.GetContainer(); @@ -1122,8 +1158,9 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const if(pOLEGraphic) { // #i118485# allow creating a SdrGrafObj representation - SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic); - pClone->SetModel(GetModel()); + SdrGrafObj* pClone = new SdrGrafObj( + getSdrModelFromSdrObject(), + *pOLEGraphic); // copy transformation basegfx::B2DHomMatrix aMatrix; @@ -1141,7 +1178,7 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const // #i118485# copy text (Caution! Model needed, as guaranteed in aw080) OutlinerParaObject* pOPO = GetOutlinerParaObject(); - if(pOPO && GetModel()) + if(pOPO) { pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO)); } @@ -1153,8 +1190,9 @@ 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(GetSnapRect()); - pClone->SetModel(GetModel()); + SdrRectObj* pClone = new SdrRectObj( + getSdrModelFromSdrObject(), + GetSnapRect()); // gray outline pClone->SetMergedItem(XLineStyleItem(css::drawing::LineStyle_SOLID)); @@ -1175,90 +1213,17 @@ SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText) const SdrObject* SdrOle2Obj::DoConvertToPolyObj(bool bBezier, bool bAddText) const { // #i118485# missing converter added - if(GetModel()) - { - SdrObject* pRetval = createSdrGrafObjReplacement(true); - - if(pRetval) - { - SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText); - SdrObject::Free(pRetval); - - return pRetval2; - } - } + SdrObject* pRetval = createSdrGrafObjReplacement(true); - 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() ) + if(pRetval) { - 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 ); + SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText); + SdrObject::Free(pRetval); - // #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(); + return pRetval2; } - AddListeners_Impl(); + return nullptr; } void SdrOle2Obj::SetPage(SdrPage* pNewPage) @@ -1269,14 +1234,14 @@ void SdrOle2Obj::SetPage(SdrPage* pNewPage) if (bRemove && mpImpl->mbConnected ) Disconnect(); - if(!pModel && !GetStyleSheet() && pNewPage && pNewPage->GetModel()) + if(!GetStyleSheet() && pNewPage) { // #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->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(); + SfxStyleSheet* pSheet = pNewPage->getSdrModelFromSdrPage().GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj(); if(pSheet) { @@ -1414,65 +1379,68 @@ OUString SdrOle2Obj::TakeObjNamePlural() const return ImpGetResStr(mpImpl->mbFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2); } -SdrOle2Obj* SdrOle2Obj::Clone() const +SdrOle2Obj* SdrOle2Obj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrOle2Obj >(); + return CloneHelper< SdrOle2Obj >(pTargetModel); +} + +SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj) +{ + return assignFrom(rObj); } SdrOle2Obj& SdrOle2Obj::assignFrom(const SdrOle2Obj& rObj) { //TODO/LATER: who takes over control of my old object?! - if( &rObj != this ) + if( &rObj == this ) { - // ImpAssign( rObj ); - const SdrOle2Obj& rOle2Obj = rObj; + return *this; + } + + // 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 (rOle2Obj.mpImpl->mxGraphic) + { + mpImpl->mxGraphic.reset(new Graphic(*rOle2Obj.mpImpl->mxGraphic)); + } - if( pModel && rObj.GetModel() && !IsEmptyPresObj() ) + if( !IsEmptyPresObj() ) + { + ::comphelper::IEmbeddedHelper* pDestPers(getSdrModelFromSdrObject().GetPersist()); + ::comphelper::IEmbeddedHelper* pSrcPers(rObj.getSdrModelFromSdrObject().GetPersist()); + if( pDestPers && pSrcPers ) { - ::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() ) { - 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(); + 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); + return *this; } void SdrOle2Obj::ImpSetVisAreaSize() @@ -1490,14 +1458,17 @@ 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*>(pModel->GetPersist()), mpImpl->mxObjRef.GetObject() ); - bool bHasOwnClient = - ( mpImpl->mxLightClient.is() - && mpImpl->mxObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) ); + 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() ) ); if ( pClient || bHasOwnClient ) { @@ -1529,7 +1500,10 @@ void SdrOle2Obj::ImpSetVisAreaSize() Size aVisSize( static_cast<long>( Fraction( maRect.GetWidth() ) / aScaleWidth ), static_cast<long>( Fraction( maRect.GetHeight() ) / aScaleHeight ) ); - aVisSize = OutputDevice::LogicToLogic(aVisSize, MapMode(pModel->GetScaleUnit()), MapMode(aMapUnit)); + aVisSize = OutputDevice::LogicToLogic( + aVisSize, + MapMode(getSdrModelFromSdrObject().GetScaleUnit()), + MapMode(aMapUnit)); awt::Size aSz; aSz.Width = aVisSize.Width(); aSz.Height = aVisSize.Height(); @@ -1550,7 +1524,11 @@ 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(pModel->GetScaleUnit()))); + maRect.SetSize( + OutputDevice::LogicToLogic( + aAcceptedVisArea.GetSize(), + MapMode(aNewMapUnit), + MapMode(getSdrModelFromSdrObject().GetScaleUnit()))); } // make the new object area known to the client @@ -1596,13 +1574,30 @@ void SdrOle2Obj::ImpSetVisAreaSize() uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), uno::UNO_QUERY ); if( xVisualObject.is() ) { - 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() ) ); + 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())); } } } @@ -1610,9 +1605,10 @@ void SdrOle2Obj::ImpSetVisAreaSize() void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact) { - if( pModel && !pModel->isLocked() ) + if(!getSdrModelFromSdrObject().isLocked()) { GetObjRef(); + if ( mpImpl->mxObjRef.is() && ( mpImpl->mxObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) ) { // if the object needs recompose on resize @@ -1623,7 +1619,8 @@ void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fract } SdrRectObj::NbcResize(rRef,xFact,yFact); - if( pModel && !pModel->isLocked() ) + + if( !getSdrModelFromSdrObject().isLocked() ) ImpSetVisAreaSize(); } @@ -1631,7 +1628,7 @@ void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo) { SdrRectObj::SetGeoData(rGeo); - if( pModel && !pModel->isLocked() ) + if( !getSdrModelFromSdrObject().isLocked() ) ImpSetVisAreaSize(); } @@ -1639,7 +1636,7 @@ void SdrOle2Obj::NbcSetSnapRect(const tools::Rectangle& rRect) { SdrRectObj::NbcSetSnapRect(rRect); - if( pModel && !pModel->isLocked() ) + if( !getSdrModelFromSdrObject().isLocked() ) ImpSetVisAreaSize(); if ( mpImpl->mxObjRef.is() && IsChart() ) @@ -1655,7 +1652,7 @@ void SdrOle2Obj::NbcSetLogicRect(const tools::Rectangle& rRect) { SdrRectObj::NbcSetLogicRect(rRect); - if( pModel && !pModel->isLocked() ) + if( !getSdrModelFromSdrObject().isLocked() ) ImpSetVisAreaSize(); } @@ -1686,7 +1683,7 @@ void SdrOle2Obj::NbcMove(const Size& rSize) { SdrRectObj::NbcMove(rSize); - if( pModel && !pModel->isLocked() ) + if( !getSdrModelFromSdrObject().isLocked() ) ImpSetVisAreaSize(); } @@ -1758,7 +1755,8 @@ bool SdrOle2Obj::Unload() return true; bool bUnloaded = false; - if ( pModel && mpImpl->mxObjRef.is() ) + + if ( mpImpl->mxObjRef.is() ) { bUnloaded = Unload( mpImpl->mxObjRef.GetObject(), GetAspect() ); } @@ -1768,12 +1766,14 @@ bool SdrOle2Obj::Unload() void SdrOle2Obj::GetObjRef_Impl() { - if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && pModel && pModel->GetPersist() ) + if ( !mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() && getSdrModelFromSdrObject().GetPersist() ) { // Only try loading if it did not went wrong up to now if(!mpImpl->mbLoadingOLEObjectFailed) { - mpImpl->mxObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() ); + mpImpl->mxObjRef.Assign( + getSdrModelFromSdrObject().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 = pModel && pModel->IsChanged(); + const bool bWasChanged(getSdrModelFromSdrObject().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 && pModel && pModel->IsChanged()) + if(!bWasChanged && getSdrModelFromSdrObject().IsChanged()) { - pModel->SetChanged( false ); + getSdrModelFromSdrObject().SetChanged( false ); } } } @@ -1889,9 +1889,7 @@ bool SdrOle2Obj::IsCalc() const uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const { - uno::Reference< frame::XModel > xDoc; - if ( pModel ) - xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY); + uno::Reference< frame::XModel > xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY); return xDoc; } @@ -1899,10 +1897,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() || !pModel ) + if (!mpImpl->mxObjRef.is()) return false; - MapMode aMapMode( pModel->GetScaleUnit() ); + MapMode aMapMode(getSdrModelFromSdrObject().GetScaleUnit()); aObjAreaSize = mpImpl->mxObjRef.GetSize( &aMapMode ); Size aSize = maRect.GetSize(); @@ -1919,7 +1917,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*>(pModel->GetPersist()), mpImpl->mxObjRef.GetObject() ) + if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(getSdrModelFromSdrObject().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 a2a6592037ee..af38237fa632 100644 --- a/svx/source/svdraw/svdopage.cxx +++ b/svx/source/svdraw/svdopage.cxx @@ -64,9 +64,11 @@ void SdrPageObj::PageInDestruction(const SdrPage& rPage) } } - -SdrPageObj::SdrPageObj(SdrPage* pNewPage) -: mpShownPage(pNewPage) +SdrPageObj::SdrPageObj( + SdrModel& rSdrModel, + SdrPage* pNewPage) +: SdrObject(rSdrModel), + mpShownPage(pNewPage) { if(mpShownPage) { @@ -74,8 +76,12 @@ SdrPageObj::SdrPageObj(SdrPage* pNewPage) } } -SdrPageObj::SdrPageObj(const tools::Rectangle& rRect, SdrPage* pNewPage) -: mpShownPage(pNewPage) +SdrPageObj::SdrPageObj( + SdrModel& rSdrModel, + const tools::Rectangle& rRect, + SdrPage* pNewPage) +: SdrObject(rSdrModel), + mpShownPage(pNewPage) { if(mpShownPage) { @@ -144,9 +150,9 @@ void SdrPageObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const rInfo.bCanConvToPolyLineToArea=false; } -SdrPageObj* SdrPageObj::Clone() const +SdrPageObj* SdrPageObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrPageObj >(); + return CloneHelper< SdrPageObj >(pTargetModel); } SdrPageObj& SdrPageObj::operator=(const SdrPageObj& rObj) diff --git a/svx/source/svdraw/svdopath.cxx b/svx/source/svdraw/svdopath.cxx index 5cf8dd58c115..fc991ab478c3 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.GetModel()->GetMetricString(pU->nCircRadius, true); + + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(pU->nCircRadius, true); } aStr += "dx=" - + mrSdrPathObject.GetModel()->GetMetricString(aNow.X(), true) + + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.X(), true) + " dy=" - + mrSdrPathObject.GetModel()->GetMetricString(aNow.Y(), true); + + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.Y(), true); if(!IsFreeHand(meObjectKind)) { sal_Int32 nLen(GetLen(aNow)); sal_Int32 nAngle(GetAngle(aNow)); aStr += " l=" - + mrSdrPathObject.GetModel()->GetMetricString(nLen, true) + + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(nLen, true) + " " + SdrModel::GetAngleString(nAngle); } aStr += ")"; } - else if(!mrSdrPathObject.GetModel() || !pHdl) + else if(!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.GetModel()->GetMetricString(aNow.X() - aBeg.X(), true) + + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(aNow.X() - aBeg.X(), true) + " dy=" - + mrSdrPathObject.GetModel()->GetMetricString(aNow.Y() - aBeg.Y(), true); + + mrSdrPathObject.getSdrModelFromSdrObject().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.GetModel()->GetMetricString(nLen, true) + + mrSdrPathObject.getSdrModelFromSdrObject().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.GetModel()->GetMetricString(nLen, true) + + mrSdrPathObject.getSdrModelFromSdrObject().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.GetModel()->GetMetricString(nLen, true) + + mrSdrPathObject.getSdrModelFromSdrObject().GetMetricString(nLen, true) + " " + SdrModel::GetAngleString(nAngle); } @@ -1628,14 +1628,21 @@ sdr::contact::ViewContact* SdrPathObj::CreateObjectSpecificViewContact() } -SdrPathObj::SdrPathObj(SdrObjKind eNewKind) -: meKind(eNewKind) +SdrPathObj::SdrPathObj( + SdrModel& rSdrModel, + SdrObjKind eNewKind) +: SdrTextObj(rSdrModel), + meKind(eNewKind) { bClosedObj = IsClosed(); } -SdrPathObj::SdrPathObj(SdrObjKind eNewKind, const basegfx::B2DPolyPolygon& rPathPoly) -: maPathPolygon(rPathPoly), +SdrPathObj::SdrPathObj( + SdrModel& rSdrModel, + SdrObjKind eNewKind, + const basegfx::B2DPolyPolygon& rPathPoly) +: SdrTextObj(rSdrModel), + maPathPolygon(rPathPoly), meKind(eNewKind) { bClosedObj = IsClosed(); @@ -1821,9 +1828,9 @@ sal_uInt16 SdrPathObj::GetObjIdentifier() const return sal_uInt16(meKind); } -SdrPathObj* SdrPathObj::Clone() const +SdrPathObj* SdrPathObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrPathObj >(); + return CloneHelper< SdrPathObj >(pTargetModel); } SdrPathObj& SdrPathObj::operator=(const SdrPathObj& rObj) @@ -2879,7 +2886,7 @@ bool SdrPathObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DP } // position maybe relative to anchorpos, convert - if( pModel && pModel->IsWriter() ) + if( getSdrModelFromSdrObject().IsWriter() ) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { @@ -2988,7 +2995,7 @@ void SdrPathObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const b } } - if( pModel && pModel->IsWriter() ) + if( getSdrModelFromSdrObject().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 7f85da4b71a8..e68b38ce3205 100644 --- a/svx/source/svdraw/svdorect.cxx +++ b/svx/source/svdraw/svdorect.cxx @@ -62,21 +62,26 @@ sdr::contact::ViewContact* SdrRectObj::CreateObjectSpecificViewContact() } -SdrRectObj::SdrRectObj() -: mpXPoly(nullptr) +SdrRectObj::SdrRectObj(SdrModel& rSdrModel) +: SdrTextObj(rSdrModel), + mpXPoly(nullptr) { bClosedObj=true; } -SdrRectObj::SdrRectObj(const tools::Rectangle& rRect) -: SdrTextObj(rRect), +SdrRectObj::SdrRectObj( + SdrModel& rSdrModel, + const tools::Rectangle& rRect) +: SdrTextObj(rSdrModel, rRect), mpXPoly(nullptr) { bClosedObj=true; } -SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind) -: SdrTextObj(eNewTextKind), +SdrRectObj::SdrRectObj( + SdrModel& rSdrModel, + SdrObjKind eNewTextKind) +: SdrTextObj(rSdrModel, eNewTextKind), mpXPoly(nullptr) { DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT || @@ -85,8 +90,11 @@ SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind) bClosedObj=true; } -SdrRectObj::SdrRectObj(SdrObjKind eNewTextKind, const tools::Rectangle& rRect) -: SdrTextObj(eNewTextKind,rRect), +SdrRectObj::SdrRectObj( + SdrModel& rSdrModel, + SdrObjKind eNewTextKind, + const tools::Rectangle& rRect) +: SdrTextObj(rSdrModel, eNewTextKind, rRect), mpXPoly(nullptr) { DBG_ASSERT(eTextKind==OBJ_TEXT || eTextKind==OBJ_TEXTEXT || @@ -99,21 +107,6 @@ 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(); @@ -266,9 +259,24 @@ OUString SdrRectObj::TakeObjNamePlural() const return ImpGetResStr(pResId); } -SdrRectObj* SdrRectObj::Clone() const +SdrRectObj* SdrRectObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrRectObj >(); + 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; } basegfx::B2DPolyPolygon SdrRectObj::TakeXorPoly() const diff --git a/svx/source/svdraw/svdotext.cxx b/svx/source/svdraw/svdotext.cxx index cf4448fac249..63ca33f850fc 100644 --- a/svx/source/svdraw/svdotext.cxx +++ b/svx/source/svdraw/svdotext.cxx @@ -64,25 +64,20 @@ 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() -: SdrAttrObj(), +SdrTextObj::SdrTextObj(SdrModel& rSdrModel) +: SdrAttrObj(rSdrModel), mpText(nullptr), pEdtOutl(nullptr), eTextKind(OBJ_TEXT) @@ -102,8 +97,10 @@ SdrTextObj::SdrTextObj() mbInDownScale = false; } -SdrTextObj::SdrTextObj(const tools::Rectangle& rNewRect) -: SdrAttrObj(), +SdrTextObj::SdrTextObj( + SdrModel& rSdrModel, + const tools::Rectangle& rNewRect) +: SdrAttrObj(rSdrModel), maRect(rNewRect), mpText(nullptr), pEdtOutl(nullptr), @@ -125,8 +122,10 @@ SdrTextObj::SdrTextObj(const tools::Rectangle& rNewRect) mbSupportTextIndentingOnLineWidthChange = true; } -SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind) -: SdrAttrObj(), +SdrTextObj::SdrTextObj( + SdrModel& rSdrModel, + SdrObjKind eNewTextKind) +: SdrAttrObj(rSdrModel), mpText(nullptr), pEdtOutl(nullptr), eTextKind(eNewTextKind) @@ -146,8 +145,11 @@ SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind) mbSupportTextIndentingOnLineWidthChange = true; } -SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind, const tools::Rectangle& rNewRect) -: SdrAttrObj(), +SdrTextObj::SdrTextObj( + SdrModel& rSdrModel, + SdrObjKind eNewTextKind, + const tools::Rectangle& rNewRect) +: SdrAttrObj(rSdrModel), maRect(rNewRect), mpText(nullptr), pEdtOutl(nullptr), @@ -171,25 +173,19 @@ SdrTextObj::SdrTextObj(SdrObjKind eNewTextKind, const tools::Rectangle& rNewRect SdrTextObj::~SdrTextObj() { - if( pModel ) - { - SdrOutliner& rOutl = pModel->GetHitTestOutliner(); - if( rOutl.GetTextObj() == this ) - rOutl.SetTextObj( nullptr ); - } - + SdrOutliner& rOutl(getSdrModelFromSdrObject().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() || pModel==nullptr) + if(pText==nullptr || !pText->GetOutlinerParaObject()) return; SdrOutliner& rOutliner=ImpGetDrawOutliner(); @@ -478,39 +474,6 @@ 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)); @@ -524,7 +487,7 @@ void SdrTextObj::AdaptTextMinSize() // Only do this for text frame. return; - if (pModel && pModel->IsPasteResize()) + if (getSdrModelFromSdrObject().IsPasteResize()) // Don't do this during paste resize. return; @@ -754,11 +717,9 @@ void SdrTextObj::TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRe if (pPara) { - bool bHitTest = false; - if( pModel ) - bHitTest = &pModel->GetHitTestOutliner() == &rOutliner; - + const bool bHitTest(&getSdrModelFromSdrObject().GetHitTestOutliner() == &rOutliner); const SdrTextObj* pTestObj = rOutliner.GetTextObj(); + if( !pTestObj || !bHitTest || pTestObj != this || pTestObj->GetOutlinerParaObject() != pOutlinerParaObject ) { @@ -1049,9 +1010,9 @@ OUString SdrTextObj::TakeObjNamePlural() const return sName; } -SdrTextObj* SdrTextObj::Clone() const +SdrTextObj* SdrTextObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrTextObj >(); + return CloneHelper< SdrTextObj >(pTargetModel); } SdrTextObj& SdrTextObj::operator=(const SdrTextObj& rObj) @@ -1111,7 +1072,7 @@ basegfx::B2DPolyPolygon SdrTextObj::TakeContour() const basegfx::B2DPolyPolygon aRetval(SdrAttrObj::TakeContour()); // and now add the BoundRect of the text, if necessary - if ( pModel && GetOutlinerParaObject() && !IsFontwork() && !IsContourTextFrame() ) + if ( GetOutlinerParaObject() && !IsFontwork() && !IsContourTextFrame() ) { // using Clone()-Paint() strategy inside TakeContour() leaves a destroyed // SdrObject as pointer in DrawOutliner. Set *this again in fetching the outliner @@ -1213,7 +1174,7 @@ void SdrTextObj::ImpInitDrawOutliner( SdrOutliner& rOutl ) const SdrOutliner& SdrTextObj::ImpGetDrawOutliner() const { - SdrOutliner& rOutl=pModel->GetDrawOutliner(this); + SdrOutliner& rOutl(getSdrModelFromSdrObject().GetDrawOutliner(this)); // Code extracted to ImpInitDrawOutliner() ImpInitDrawOutliner( rOutl ); @@ -1261,7 +1222,7 @@ void SdrTextObj::ImpSetupDrawOutlinerForPaint( bool bContourFrame, double SdrTextObj::GetFontScaleY() const { SdrText* pText = getActiveText(); - if (pText == nullptr || !pText->GetOutlinerParaObject() || pModel == nullptr) + if (pText == nullptr || !pText->GetOutlinerParaObject()) return 1.0; SdrOutliner& rOutliner = ImpGetDrawOutliner(); @@ -1403,17 +1364,21 @@ void SdrTextObj::UpdateOutlinerFormatting( SdrOutliner& rOutl, tools::Rectangle& tools::Rectangle aAnchorRect; Fraction aFitXCorrection(1,1); - bool bContourFrame=IsContourTextFrame(); - - if( GetModel() ) - { - MapMode aMapMode(GetModel()->GetScaleUnit(), Point(0,0), - GetModel()->GetScaleFraction(), - GetModel()->GetScaleFraction()); - rOutl.SetRefMapMode(aMapMode); - } + const bool bContourFrame(IsContourTextFrame()); + const MapMode aMapMode( + getSdrModelFromSdrObject().GetScaleUnit(), + Point(0,0), + getSdrModelFromSdrObject().GetScaleFraction(), + getSdrModelFromSdrObject().GetScaleFraction()); - ImpSetupDrawOutlinerForPaint( bContourFrame, rOutl, aTextRect, aAnchorRect, rPaintRect, aFitXCorrection ); + rOutl.SetRefMapMode(aMapMode); + ImpSetupDrawOutlinerForPaint( + bContourFrame, + rOutl, + aTextRect, + aAnchorRect, + rPaintRect, + aFitXCorrection); } @@ -1561,7 +1526,7 @@ TextChain *SdrTextObj::GetTextChain() const //if (!IsChainable()) // return NULL; - return pModel->GetTextChain(); + return getSdrModelFromSdrObject().GetTextChain(); } bool SdrTextObj::IsVerticalWriting() const @@ -1670,7 +1635,7 @@ bool SdrTextObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DP basegfx::B2DTuple aTranslate(aRectangle.Left(), aRectangle.Top()); // position maybe relative to anchorpos, convert - if( pModel && pModel->IsWriter() ) + if( getSdrModelFromSdrObject().IsWriter() ) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { @@ -1769,7 +1734,7 @@ void SdrTextObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const b } // if anchor is used, make position relative to it - if( pModel && pModel->IsWriter() ) + if( getSdrModelFromSdrObject().IsWriter() ) { if(GetAnchorPos().X() || GetAnchorPos().Y()) { diff --git a/svx/source/svdraw/svdotextdecomposition.cxx b/svx/source/svdraw/svdotextdecomposition.cxx index af6977fc3cbe..b50736972d35 100644 --- a/svx/source/svdraw/svdotextdecomposition.cxx +++ b/svx/source/svdraw/svdotextdecomposition.cxx @@ -973,8 +973,9 @@ void SdrTextObj::impDecomposeBlockTextPrimitive( // Usual processing - always grow in one of directions bool bAllowGrowVertical = !bVerticalWriting; bool bAllowGrowHorizontal = bVerticalWriting; + // Compatibility mode for tdf#99729 - if (pModel->IsAnchoredTextOverflowLegacy()) + if (getSdrModelFromSdrObject().IsAnchoredTextOverflowLegacy()) { bAllowGrowVertical = bHorizontalIsBlock; bAllowGrowHorizontal = bVerticalIsBlock; @@ -1466,7 +1467,7 @@ void SdrTextObj::impHandleChainingEventsDuringDecomposition(SdrOutliner &rOutlin if (bIsOverflow && !IsInEditMode()) { // Initialize Chaining Outliner - SdrOutliner &rChainingOutl = pModel->GetChainingOutliner(this); + SdrOutliner &rChainingOutl(getSdrModelFromSdrObject().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 f4c9528d4125..e88e55519930 100644 --- a/svx/source/svdraw/svdotxat.cxx +++ b/svx/source/svdraw/svdotxat.cxx @@ -62,10 +62,6 @@ 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; @@ -95,7 +91,7 @@ bool SdrTextObj::AdjustTextFrameWidthAndHeight( tools::Rectangle& rR, bool bHgt, aNewSize.AdjustWidth( -1 ); aNewSize.AdjustHeight( -1 ); Size aMaxSiz(100000, 100000); - Size aTmpSiz = pModel->GetMaxObjSize(); + Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize()); if (aTmpSiz.Width()) aMaxSiz.setWidth( aTmpSiz.Width() ); @@ -312,7 +308,7 @@ bool SdrTextObj::AdjustTextFrameWidthAndHeight() void SdrTextObj::ImpSetTextStyleSheetListeners() { - SfxStyleSheetBasePool* pStylePool=pModel!=nullptr ? pModel->GetStyleSheetPool() : nullptr; + SfxStyleSheetBasePool* pStylePool(getSdrModelFromSdrObject().GetStyleSheetPool()); if (pStylePool!=nullptr) { std::vector<OUString> aStyleNames; diff --git a/svx/source/svdraw/svdotxed.cxx b/svx/source/svdraw/svdotxed.cxx index 3290435144b1..bb3e60d9291b 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( pModel->GetRefDevice() ); + rOutl.SetRefDevice(getSdrModelFromSdrObject().GetRefDevice()); bool bFitToSize(IsFitToSize()); bool bContourFrame=IsContourTextFrame(); @@ -146,11 +146,9 @@ 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); - if (pModel!=nullptr) { - Size aTmpSiz(pModel->GetMaxObjSize()); - if (aTmpSiz.Width()!=0) aMaxSiz.setWidth(aTmpSiz.Width() ); - if (aTmpSiz.Height()!=0) aMaxSiz.setHeight(aTmpSiz.Height() ); - } + Size aTmpSiz(getSdrModelFromSdrObject().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 75964d95d60b..27d4b9679da8 100644 --- a/svx/source/svdraw/svdotxln.cxx +++ b/svx/source/svdraw/svdotxln.cxx @@ -67,8 +67,9 @@ void ImpSdrObjTextLink::Closed() const OUString& /*rMimeType*/, const css::uno::Any & /*rValue */) { bool bForceReload = false; - SdrModel* pModel = pSdrObj ? pSdrObj->GetModel() : nullptr; - sfx2::LinkManager* pLinkManager= pModel ? pModel->GetLinkManager() : nullptr; + SdrModel* pModel(pSdrObj ? &pSdrObj->getSdrModelFromSdrObject() : nullptr); + sfx2::LinkManager* pLinkManager(pModel ? pModel->GetLinkManager() : nullptr); + if( pLinkManager ) { ImpSdrObjTextLinkUserData* pData=pSdrObj->GetLinkUserData(); @@ -254,7 +255,7 @@ ImpSdrObjTextLinkUserData* SdrTextObj::GetLinkUserData() const void SdrTextObj::ImpRegisterLink() { ImpSdrObjTextLinkUserData* pData=GetLinkUserData(); - sfx2::LinkManager* pLinkManager=pModel!=nullptr ? pModel->GetLinkManager() : nullptr; + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); 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, @@ -266,7 +267,7 @@ void SdrTextObj::ImpRegisterLink() void SdrTextObj::ImpDeregisterLink() { ImpSdrObjTextLinkUserData* pData=GetLinkUserData(); - sfx2::LinkManager* pLinkManager=pModel!=nullptr ? pModel->GetLinkManager() : nullptr; + sfx2::LinkManager* pLinkManager(getSdrModelFromSdrObject().GetLinkManager()); 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 40eca1077e38..1a6d4a50a358 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 && (!pModel || !pModel->IsPasteResize())) + if(bTextFrame && !getSdrModelFromSdrObject().IsPasteResize()) { NbcAdjustTextFrameWidthAndHeight(); } @@ -313,7 +313,7 @@ SdrObject* SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const if(nResultCount) { // prepare own target - SdrObjGroup* pGroup = new SdrObjGroup(); + SdrObjGroup* pGroup = new SdrObjGroup(getSdrModelFromSdrObject()); SdrObjList* pObjectList = pGroup->GetSubList(); // process results @@ -355,7 +355,10 @@ SdrObject* SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_SOLID)); // create filled SdrPathObj - pPathObj = new SdrPathObj(OBJ_PATHFILL, aPolyPolygon); + pPathObj = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHFILL, + aPolyPolygon); } else { @@ -366,18 +369,16 @@ SdrObject* SdrTextObj::ImpConvertContainedTextToSdrPathObjs(bool bToPoly) const aAttributeSet.Put(XFillStyleItem(drawing::FillStyle_NONE)); // create line SdrPathObj - pPathObj = new SdrPathObj(OBJ_PATHLINE, aPolyPolygon); + pPathObj = new SdrPathObj( + getSdrModelFromSdrObject(), + OBJ_PATHLINE, + aPolyPolygon); } // copy basic information from original pPathObj->ImpSetAnchorPos(GetAnchorPos()); pPathObj->NbcSetLayer(GetLayer()); - - if(GetModel()) - { - pPathObj->SetModel(GetModel()); - pPathObj->NbcSetStyleSheet(GetStyleSheet(), true); - } + pPathObj->NbcSetStyleSheet(GetStyleSheet(), true); // apply prepared ItemSet and add to target pPathObj->SetMergedItemSet(aAttributeSet); @@ -433,7 +434,10 @@ SdrObject* SdrTextObj::ImpConvertMakeObj(const basegfx::B2DPolyPolygon& rPolyPol ePathKind = bClosed ? OBJ_POLY : OBJ_PLIN; } - SdrPathObj* pPathObj = new SdrPathObj(ePathKind, aB2DPolyPolygon); + SdrPathObj* pPathObj = new SdrPathObj( + getSdrModelFromSdrObject(), + ePathKind, + aB2DPolyPolygon); if(bBezier) { @@ -443,18 +447,11 @@ SdrObject* SdrTextObj::ImpConvertMakeObj(const basegfx::B2DPolyPolygon& rPolyPol pPathObj->ImpSetAnchorPos(aAnchor); pPathObj->NbcSetLayer(GetLayer()); - - if(pModel) - { - pPathObj->SetModel(pModel); - - sdr::properties::ItemChangeBroadcaster aC(*pPathObj); - - pPathObj->ClearMergedItem(); - pPathObj->SetMergedItemSet(GetObjectItemSet()); - pPathObj->GetProperties().BroadcastItemChange(aC); - pPathObj->NbcSetStyleSheet(GetStyleSheet(), true); - } + sdr::properties::ItemChangeBroadcaster aC(*pPathObj); + pPathObj->ClearMergedItem(); + pPathObj->SetMergedItemSet(GetObjectItemSet()); + pPathObj->GetProperties().BroadcastItemChange(aC); + pPathObj->NbcSetStyleSheet(GetStyleSheet(), true); return pPathObj; } @@ -489,7 +486,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; + SdrObjGroup* pGrp=new SdrObjGroup(getSdrModelFromSdrObject()); 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 6e364c33ade1..4a0e071ca8b9 100644 --- a/svx/source/svdraw/svdouno.cxx +++ b/svx/source/svdraw/svdouno.cxx @@ -145,9 +145,11 @@ namespace } } - -SdrUnoObj::SdrUnoObj(const OUString& rModelName) -: m_pImpl( new SdrUnoObjDataHolder ) +SdrUnoObj::SdrUnoObj( + SdrModel& rSdrModel, + const OUString& rModelName) +: SdrRectObj(rSdrModel), + m_pImpl( new SdrUnoObjDataHolder ) { bIsUnoObj = true; @@ -158,9 +160,12 @@ SdrUnoObj::SdrUnoObj(const OUString& rModelName) CreateUnoControlModel(rModelName); } -SdrUnoObj::SdrUnoObj(const OUString& rModelName, - const uno::Reference< lang::XMultiServiceFactory >& rxSFac) -: m_pImpl( new SdrUnoObjDataHolder ) +SdrUnoObj::SdrUnoObj( + SdrModel& rSdrModel, + const OUString& rModelName, + const uno::Reference< lang::XMultiServiceFactory >& rxSFac) +: SdrRectObj(rSdrModel), + m_pImpl( new SdrUnoObjDataHolder ) { bIsUnoObj = true; @@ -250,9 +255,9 @@ OUString SdrUnoObj::TakeObjNamePlural() const return ImpGetResStr(STR_ObjNamePluralUno); } -SdrUnoObj* SdrUnoObj::Clone() const +SdrUnoObj* SdrUnoObj::Clone(SdrModel* pTargetModel) const { - return CloneHelper< SdrUnoObj >(); + return CloneHelper< SdrUnoObj >(pTargetModel); } SdrUnoObj& SdrUnoObj::operator= (const SdrUnoObj& rObj) @@ -328,38 +333,6 @@ 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 2ffcdc313473..4306ecd577fa 100644 --- a/svx/source/svdraw/svdovirt.cxx +++ b/svx/source/svdraw/svdovirt.cxx @@ -42,8 +42,10 @@ sdr::contact::ViewContact* SdrVirtObj::CreateObjectSpecificViewContact() return new sdr::contact::ViewContactOfVirtObj(*this); } - -SdrVirtObj::SdrVirtObj(SdrObject& rNewObj): +SdrVirtObj::SdrVirtObj( + SdrModel& rSdrModel, + SdrObject& rNewObj) +: SdrObject(rSdrModel), rRefObj(rNewObj) { bVirtObj=true; // this is only a virtual object @@ -56,7 +58,6 @@ SdrVirtObj::~SdrVirtObj() rRefObj.DelReference(*this); } - const SdrObject& SdrVirtObj::GetReferencedObj() const { return rRefObj; @@ -81,13 +82,6 @@ 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); @@ -128,15 +122,29 @@ void SdrVirtObj::RecalcBoundRect() aOutRect+=aAnchor; } -SdrVirtObj* SdrVirtObj::Clone() const +SdrVirtObj* SdrVirtObj::Clone(SdrModel* pTargetModel) const { - return new SdrVirtObj(rRefObj); // only a further reference + 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 } SdrVirtObj& SdrVirtObj::operator=(const SdrVirtObj& rObj) -{ // reference different object?? +{ SdrObject::operator=(rObj); - aAnchor=rObj.aAnchor; + + // reference different object?? TTTT -> yes! + rRefObj.DelReference(*this); + rRefObj = rObj.rRefObj; + rRefObj.AddReference(*this); + + aSnapRect = rObj.aSnapRect; + aAnchor = rObj.aAnchor; + return *this; } @@ -266,24 +274,11 @@ bool SdrVirtObj::supportsFullDrag() const SdrObject* SdrVirtObj::getFullDragClone() const { - 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; + SdrObject& rReferencedObject = const_cast<SdrVirtObj*>(this)->ReferencedObj(); + return new SdrGrafObj( + getSdrModelFromSdrObject(), + SdrDragView::GetObjGraphic(rReferencedObject), + GetLogicRect()); } bool SdrVirtObj::beginSpecialDrag(SdrDragStat& rDrag) const diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index 7ff4129691ff..2dff0a900148 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -70,13 +70,12 @@ public: static const sal_Int32 InitialObjectContainerCapacity (64); -SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage): - maList(), +SdrObjList::SdrObjList(SdrPage* pNewPage) +: maList(), mxNavigationOrder(), mbIsNavigationOrderDirty(false) { maList.reserve(InitialObjectContainerCapacity); - pModel=pNewModel; pPage=pNewPage; pUpList=nullptr; bObjOrdNumsDirty=false; @@ -85,58 +84,46 @@ SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage): eListKind=SdrObjListKind::Unknown; } -SdrObjList::SdrObjList(): - maList(), - mxNavigationOrder(), - mbIsNavigationOrderDirty(false) +SdrObjList::~SdrObjList() { - maList.reserve(InitialObjectContainerCapacity); - pModel=nullptr; - pPage=nullptr; - pUpList=nullptr; - bObjOrdNumsDirty=false; - bRectsDirty=false; - pOwnerObj=nullptr; - eListKind=SdrObjListKind::Unknown; + Clear(); // delete contents of container } -SdrObjList::~SdrObjList() +SdrObjList* SdrObjList::CloneSdrObjList(SdrModel* pNewModel) const { - - // 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* pObjList = new SdrObjList(); + pObjList->lateInitSdrObjList(*this, pNewModel); + return pObjList; } -void SdrObjList::lateInit(const SdrObjList& rSrcList) +void SdrObjList::lateInitSdrObjList(const SdrObjList& rSrcList, SdrModel* pNewModel) { // this function is only supposed to be called once, right after construction assert(maList.empty()); - eListKind=rSrcList.eListKind; - CopyObjects(rSrcList); + CopyObjects(rSrcList, pNewModel); } -void SdrObjList::CopyObjects(const SdrObjList& rSrcList) +void SdrObjList::CopyObjects(const SdrObjList& rSrcList, SdrModel* pNewModel) { Clear(); - 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); + bObjOrdNumsDirty = false; + bRectsDirty = false; + size_t nCloneErrCnt(0); + const size_t nCount(rSrcList.GetObjCount()); - SdrObject* pDO = pSO->Clone(); + for (size_t no(0); no < nCount; ++no) + { + SdrObject* pSO(rSrcList.GetObj(no)); + SdrObject* pDO(pSO->Clone(pNewModel)); - if (pDO!=nullptr) { - pDO->SetModel(pModel); + if(nullptr != pDO) + { pDO->SetPage(pPage); NbcInsertObject(pDO, SAL_MAX_SIZE); - } else { + } + else + { nCloneErrCnt++; } } @@ -209,9 +196,9 @@ void SdrObjList::CopyObjects(const SdrObjList& rSrcList) void SdrObjList::Clear() { - bool bObjectsRemoved(false); + SdrModel* pSdrModelFromRemovedSdrObject(nullptr); - while( ! maList.empty()) + while(!maList.empty()) { // remove last object from list SdrObject* pObj = maList.back(); @@ -221,22 +208,22 @@ void SdrObjList::Clear() // to delete the object and thus refresh visualisations pObj->GetViewContact().flushViewObjectContacts(); - bObjectsRemoved = true; - - // sent remove hint (after removal, see RemoveObject()) - if(pModel) + if(nullptr == pSdrModelFromRemovedSdrObject) { - SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj, pPage); - pModel->Broadcast(aHint); + pSdrModelFromRemovedSdrObject = &pObj->getSdrModelFromSdrObject(); } + // sent remove hint (after removal, see RemoveObject()) + SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj, pPage); + pObj->getSdrModelFromSdrObject().Broadcast(aHint); + // delete the object itself SdrObject::Free( pObj ); } - if(pModel && bObjectsRemoved) + if(nullptr != pSdrModelFromRemovedSdrObject) { - pModel->SetChanged(); + pSdrModelFromRemovedSdrObject->SetChanged(); } } @@ -257,23 +244,6 @@ 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(); @@ -369,18 +339,15 @@ void SdrObjList::InsertObject(SdrObject* pObj, size_t nPos) pOwnerObj->ActionChanged(); } - if(pModel) + // TODO: We need a different broadcast here! + // Repaint from object number ... (heads-up: GroupObj) + if(pObj->GetPage()) { - // 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); - } - - pModel->SetChanged(); + SdrHint aHint(SdrHintKind::ObjectInserted, *pObj); + pObj->getSdrModelFromSdrObject().Broadcast(aHint); } + + pObj->getSdrModelFromSdrObject().SetChanged(); } } @@ -432,16 +399,17 @@ 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."); - if (pModel!=nullptr) { - // TODO: We need a different broadcast here. - if (pObj->GetPage()!=nullptr) { - SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj); - pModel->Broadcast(aHint); - } - pModel->SetChanged(); + + // TODO: We need a different broadcast here. + if (pObj->GetPage()!=nullptr) + { + SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj); + pObj->getSdrModelFromSdrObject().Broadcast(aHint); } + + pObj->getSdrModelFromSdrObject().SetChanged(); + pObj->SetInserted(false); // calls, among other things, the UserCall pObj->SetObjList(nullptr); pObj->SetPage(nullptr); @@ -514,13 +482,14 @@ 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."); - if (pModel!=nullptr) { - // TODO: We need a different broadcast here. - if (pObj->GetPage()!=nullptr) { - SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj); - pModel->Broadcast(aHint); - } + + // TODO: We need a different broadcast here. + if (pObj->GetPage()!=nullptr) + { + SdrHint aHint(SdrHintKind::ObjectRemoved, *pObj); + pObj->getSdrModelFromSdrObject().Broadcast(aHint); } + pObj->SetInserted(false); pObj->SetObjList(nullptr); pObj->SetPage(nullptr); @@ -538,14 +507,15 @@ SdrObject* SdrObjList::ReplaceObject(SdrObject* pNewObj, size_t nObjNum) impChildInserted(*pNewObj); pNewObj->SetInserted(true); - if (pModel!=nullptr) { - // TODO: We need a different broadcast here. - if (pNewObj->GetPage()!=nullptr) { - SdrHint aHint(SdrHintKind::ObjectInserted, *pNewObj); - pModel->Broadcast(aHint); - } - pModel->SetChanged(); + + // TODO: We need a different broadcast here. + if (pNewObj->GetPage()!=nullptr) { + SdrHint aHint(SdrHintKind::ObjectInserted, *pNewObj); + pNewObj->getSdrModelFromSdrObject().Broadcast(aHint); } + + pNewObj->getSdrModelFromSdrObject().SetChanged(); + SetRectsDirty(); } return pObj; @@ -574,13 +544,11 @@ SdrObject* SdrObjList::SetObjectOrdNum(size_t nOldObjNum, size_t nNewObjNum) pObj->SetOrdNum(nNewObjNum); bObjOrdNumsDirty=true; - if (pModel!=nullptr) - { - // TODO: We need a different broadcast here. - if (pObj->GetPage()!=nullptr) - pModel->Broadcast(SdrHint(SdrHintKind::ObjectChange, *pObj)); - pModel->SetChanged(); - } + + // TODO: We need a different broadcast here. + if (pObj->GetPage()!=nullptr) + pObj->getSdrModelFromSdrObject().Broadcast(SdrHint(SdrHintKind::ObjectChange, *pObj)); + pObj->getSdrModelFromSdrObject().SetChanged(); } return pObj; } @@ -781,8 +749,7 @@ void SdrObjList::SetObjectNavigationPosition ( mbIsNavigationOrderDirty = true; // The navigation order is written out to file so mark the model as modified. - if (pModel != nullptr) - pModel->SetChanged(); + rObject.getSdrModelFromSdrObject().SetChanged(); } } @@ -1048,20 +1015,18 @@ void SdrPageProperties::ImpAddStyleSheet(SfxStyleSheet& rNewStyleSheet) void ImpPageChange(SdrPage& rSdrPage) { rSdrPage.ActionChanged(); - - if(rSdrPage.GetModel()) - { - rSdrPage.GetModel()->SetChanged(); - SdrHint aHint(SdrHintKind::PageOrderChange, &rSdrPage); - rSdrPage.GetModel()->Broadcast(aHint); - } + rSdrPage.getSdrModelFromSdrPage().SetChanged(); + SdrHint aHint(SdrHintKind::PageOrderChange, &rSdrPage); + rSdrPage.getSdrModelFromSdrPage().Broadcast(aHint); } SdrPageProperties::SdrPageProperties(SdrPage& rSdrPage) : SfxListener(), mpSdrPage(&rSdrPage), mpStyleSheet(nullptr), - maProperties(mpSdrPage->GetModel()->GetItemPool(), svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}) + maProperties( + mpSdrPage->getSdrModelFromSdrPage().GetItemPool(), + svl::Items<XATTR_FILL_FIRST, XATTR_FILL_LAST>{}) { if(!rSdrPage.IsMasterPage()) { @@ -1136,18 +1101,23 @@ void SdrPageProperties::SetStyleSheet(SfxStyleSheet* pStyleSheet) } -SdrPage::SdrPage(SdrModel& rNewModel, bool bMasterPage) -: SdrObjList(&rNewModel, this), +SdrPage::SdrPage(SdrModel& rModel, bool bMasterPage) +: tools::WeakBase(), + SdrObjList(this), + maPageUsers(), mpViewContact(nullptr), + mrSdrModelFromSdrPage(rModel), mnWidth(10), mnHeight(10), mnBorderLeft(0), mnBorderUpper(0), mnBorderRight(0), mnBorderLower(0), - mpLayerAdmin(new SdrLayerAdmin(&rNewModel.GetLayerAdmin())), + mpLayerAdmin(new SdrLayerAdmin(&rModel.GetLayerAdmin())), mpSdrPageProperties(nullptr), + mxUnoPage(), mpMasterPageDescriptor(nullptr), + aPrefVisiLayers(), nPageNum(0), mbMaster(bMasterPage), mbInserted(false), @@ -1160,27 +1130,6 @@ SdrPage::SdrPage(SdrModel& rNewModel, 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 @@ -1218,18 +1167,13 @@ SdrPage::~SdrPage() mpSdrPageProperties.reset(); } -void SdrPage::lateInit(const SdrPage& rSrcPage, SdrModel* const pNewModel) +void SdrPage::lateInit(const SdrPage& rSrcPage) { assert(!mpViewContact); - assert(!mpSdrPageProperties); + // SdrPageProperties get set by SdrPage::SdrPage already, so do not assert anymore + // 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 @@ -1268,24 +1212,18 @@ void SdrPage::lateInit(const SdrPage& rSrcPage, SdrModel* const pNewModel) } // Now copy the contained objects - SdrObjList::lateInit(rSrcPage); + SdrObjList::lateInitSdrObjList(rSrcPage, &getSdrModelFromSdrPage()); // 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 { - if (pNewModel==nullptr) pNewModel=pModel; - SdrPage* pPage2=new SdrPage(*pNewModel); - pPage2->lateInit(*this); - return pPage2; + SdrPage* pClonedPage(new SdrPage(nullptr == pNewModel ? getSdrModelFromSdrPage() : *pNewModel)); + pClonedPage->lateInit(*this); + return pClonedPage; } void SdrPage::SetSize(const Size& aSiz) @@ -1435,59 +1373,6 @@ 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) { @@ -1507,11 +1392,11 @@ sal_uInt16 SdrPage::GetPageNum() const return 0; if (mbMaster) { - if (pModel && pModel->IsMPgNumsDirty()) - pModel->RecalcPageNums(true); + if (getSdrModelFromSdrPage().IsMPgNumsDirty()) + getSdrModelFromSdrPage().RecalcPageNums(true); } else { - if (pModel && pModel->IsPagNumsDirty()) - pModel->RecalcPageNums(false); + if (getSdrModelFromSdrPage().IsPagNumsDirty()) + getSdrModelFromSdrPage().RecalcPageNums(false); } return nPageNum; } @@ -1521,11 +1406,7 @@ void SdrPage::SetChanged() // For test purposes, use the new ViewContact for change // notification now. ActionChanged(); - - if( pModel ) - { - pModel->SetChanged(); - } + getSdrModelFromSdrPage().SetChanged(); } diff --git a/svx/source/svdraw/svdpagv.cxx b/svx/source/svdraw/svdpagv.cxx index da88ec5907f3..ff6349894259 100644 --- a/svx/source/svdraw/svdpagv.cxx +++ b/svx/source/svdraw/svdpagv.cxx @@ -898,15 +898,25 @@ sal_uInt16 SdrPageView::GetEnteredLevel() const void SdrPageView::CheckAktGroup() { - 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(); + SdrObject* pGrp(GetAktGroup()); + + while(nullptr != pGrp && + (!pGrp->IsInserted() || nullptr == pGrp->GetObjList() || nullptr == pGrp->GetPage())) + { + // anything outside of the borders? + pGrp = pGrp->GetUpGroup(); } - if (pGrp!=GetAktGroup()) { - if (pGrp!=nullptr) EnterGroup(pGrp); - else LeaveAllGroup(); + + if(pGrp != GetAktGroup()) + { + if(nullptr != pGrp) + { + EnterGroup(pGrp); + } + else + { + LeaveAllGroup(); + } } } diff --git a/svx/source/svdraw/svdpntv.cxx b/svx/source/svdraw/svdpntv.cxx index 48c971d61792..ba0e252da346 100644 --- a/svx/source/svdraw/svdpntv.cxx +++ b/svx/source/svdraw/svdpntv.cxx @@ -181,9 +181,12 @@ void SdrPaintView::ImpClearVars() maGridColor = COL_BLACK; } -SdrPaintView::SdrPaintView(SdrModel* pModel, OutputDevice* pOut) -: mpPageView(nullptr), - maDefaultAttr(pModel->GetItemPool()), +SdrPaintView::SdrPaintView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: mrSdrModelFromSdrView(rSdrModel), + mpPageView(nullptr), + maDefaultAttr(rSdrModel.GetItemPool()), mbBufferedOutputAllowed(false), mbBufferedOverlayAllowed(false), mbPagePaintingAllowed(true), @@ -192,7 +195,7 @@ SdrPaintView::SdrPaintView(SdrModel* pModel, OutputDevice* pOut) mbHideDraw(false), mbHideFormControl(false) { - mpModel=pModel; + mpModel=&rSdrModel; ImpClearVars(); if(pOut) diff --git a/svx/source/svdraw/svdpoev.cxx b/svx/source/svdraw/svdpoev.cxx index 509eb112dd96..56e32865e012 100644 --- a/svx/source/svdraw/svdpoev.cxx +++ b/svx/source/svdraw/svdpoev.cxx @@ -44,8 +44,10 @@ void SdrPolyEditView::ImpResetPolyPossibilityFlags() bSetMarkedSegmentsKindPossible=false; } -SdrPolyEditView::SdrPolyEditView(SdrModel* pModel1, OutputDevice* pOut): - SdrEditView(pModel1,pOut) +SdrPolyEditView::SdrPolyEditView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrEditView(rSdrModel, pOut) { ImpResetPolyPossibilityFlags(); } diff --git a/svx/source/svdraw/svdsnpv.cxx b/svx/source/svdraw/svdsnpv.cxx index 94f1f5affc00..10aacc3f87fd 100644 --- a/svx/source/svdraw/svdsnpv.cxx +++ b/svx/source/svdraw/svdsnpv.cxx @@ -165,30 +165,31 @@ void ImplHelpLineOverlay::SetPosition(const basegfx::B2DPoint& rNewPosition) } } - -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) +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) { } diff --git a/svx/source/svdraw/svdtext.cxx b/svx/source/svdraw/svdtext.cxx index 159f863cb54c..549578832885 100644 --- a/svx/source/svdraw/svdtext.cxx +++ b/svx/source/svdraw/svdtext.cxx @@ -31,7 +31,6 @@ SdrText::SdrText( SdrTextObj& rObject ) : mpOutlinerParaObject( nullptr ) , mrObject( rObject ) -, mpModel( rObject.GetModel() ) , mbPortionInfoChecked( false ) { OSL_ENSURE(&mrObject, "SdrText created without SdrTextObj (!)"); @@ -48,11 +47,12 @@ void SdrText::CheckPortionInfo( SdrOutliner& rOutliner ) { // #i102062# no action when the Outliner is the HitTestOutliner, // this will remove WrongList info at the OPO - if(mpModel && &rOutliner == &mpModel->GetHitTestOutliner()) + if(&rOutliner == &mrObject.getSdrModelFromSdrObject().GetHitTestOutliner()) return; // TODO: optimization: we could create a BigTextObject mbPortionInfoChecked=true; + if(mpOutlinerParaObject!=nullptr && rOutliner.ShouldCreateBigTextObject()) { // #i102062# MemoryLeak closed @@ -76,16 +76,15 @@ void SdrText::SetOutlinerParaObject( OutlinerParaObject* pTextObject ) { if( mpOutlinerParaObject.get() != pTextObject ) { - if( mpModel ) + // Update HitTestOutliner + const SdrTextObj* pTestObj(mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().GetTextObj()); + + if(pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get()) { - // Update HitTestOutliner - const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj(); - if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get() ) - mpModel->GetHitTestOutliner().SetTextObj( nullptr ); + mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().SetTextObj(nullptr); } mpOutlinerParaObject.reset(pTextObject); - mbPortionInfoChecked = false; } } @@ -98,82 +97,33 @@ OutlinerParaObject* SdrText::GetOutlinerParaObject() const /** returns the current OutlinerParaObject and removes it from this instance */ OutlinerParaObject* SdrText::RemoveOutlinerParaObject() { - if( mpModel ) + // Update HitTestOutliner + const SdrTextObj* pTestObj(mrObject.getSdrModelFromSdrObject().GetHitTestOutliner().GetTextObj()); + + if(pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get()) { - // Update HitTestOutliner - const SdrTextObj* pTestObj = mpModel->GetHitTestOutliner().GetTextObj(); - if( pTestObj && pTestObj->GetOutlinerParaObject() == mpOutlinerParaObject.get() ) - mpModel->GetHitTestOutliner().SetTextObj( nullptr ); + mrObject.getSdrModelFromSdrObject().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( mpModel && !mpOutlinerParaObject ) + if(!mpOutlinerParaObject) { - std::unique_ptr<Outliner> pOutliner(SdrMakeOutliner(nOutlMode, *mpModel)); - if( pOutliner ) + std::unique_ptr<Outliner> pOutliner( + SdrMakeOutliner( + nOutlMode, + mrObject.getSdrModelFromSdrObject())); + + if(pOutliner) { - Outliner& aDrawOutliner = mpModel->GetDrawOutliner(); + Outliner& aDrawOutliner(mrObject.getSdrModelFromSdrObject().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 1c6ec236f34b..22720cfb4ca4 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.GetModel()) - , pObj(&rNewObj) +: SdrUndoAction(rNewObj.getSdrModelFromSdrObject()) + ,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() && pObj->GetModel()) + if(pObj && pObj->IsInserted() && pObj->GetPage()) { SdrHint aHint(SdrHintKind::SwitchToPage, *pObj, pObj->GetPage()); - pObj->GetModel()->Broadcast(aHint); + pObj->getSdrModelFromSdrObject().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->GetModel()) ); + pUndoGroup.reset(new SdrUndoGroup(pObj->getSdrModelFromSdrObject())); 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->GetModel() && pObj->GetModel()->GetStyleSheetPool()) + if(pSheet && pObj->getSdrModelFromSdrObject().GetStyleSheetPool()) { - ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet); + ensureStyleSheetInStyleSheetPool(*pObj->getSdrModelFromSdrObject().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->GetModel() && pObj->GetModel()->GetStyleSheetPool()) + if(pSheet && pObj->getSdrModelFromSdrObject().GetStyleSheetPool()) { - ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet); + ensureStyleSheetInStyleSheetPool(*pObj->getSdrModelFromSdrObject().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->GetModel())); + pUndoGroup.reset(new SdrUndoGroup(pObj->getSdrModelFromSdrObject())); 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.GetModel()) - , mrPage(rNewPg) +: SdrUndoAction(rNewPg.getSdrModelFromSdrPage()) + ,mrPage(rNewPg) { } @@ -1657,7 +1657,7 @@ void SdrUndoPageRemoveMasterPage::Undo() { if(mbOldHadMasterPage) { - mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber)); + mrPage.TRG_SetMasterPage(*mrPage.getSdrModelFromSdrPage().GetMasterPage(maOldMasterPageNumber)); mrPage.TRG_SetMasterPageVisibleLayers(maOldSet); } } @@ -1695,7 +1695,7 @@ void SdrUndoPageChangeMasterPage::Undo() if(mbOldHadMasterPage) { mrPage.TRG_ClearMasterPage(); - mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber)); + mrPage.TRG_SetMasterPage(*mrPage.getSdrModelFromSdrPage().GetMasterPage(maOldMasterPageNumber)); mrPage.TRG_SetMasterPageVisibleLayers(maOldSet); } } @@ -1706,7 +1706,7 @@ void SdrUndoPageChangeMasterPage::Redo() if(mbNewHadMasterPage) { mrPage.TRG_ClearMasterPage(); - mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maNewMasterPageNumber)); + mrPage.TRG_SetMasterPage(*mrPage.getSdrModelFromSdrPage().GetMasterPage(maNewMasterPageNumber)); mrPage.TRG_SetMasterPageVisibleLayers(maNewSet); } } diff --git a/svx/source/svdraw/svdview.cxx b/svx/source/svdraw/svdview.cxx index db460ea89d45..d9eb52432957 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* pModel1, OutputDevice* pOut) -: SdrCreateView(pModel1,pOut), +SdrView::SdrView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrCreateView(rSdrModel, 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 2dbd8b5f3bb2..044526e6e638 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->GetModel() : nullptr; + mpModel = pPage ? &pPage->getSdrModelFromSdrPage() : 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->GetModel() : nullptr; + mpModel = pObject ? &pObject->getSdrModelFromSdrObject() : nullptr; mpPage = pObject ? pObject->GetPage() : nullptr; mbNoMasterPage = false; diff --git a/svx/source/svdraw/svdxcgv.cxx b/svx/source/svdraw/svdxcgv.cxx index 1011c8a11e87..58fc73351181 100644 --- a/svx/source/svdraw/svdxcgv.cxx +++ b/svx/source/svdraw/svdxcgv.cxx @@ -57,8 +57,10 @@ using namespace com::sun::star; -SdrExchangeView::SdrExchangeView(SdrModel* pModel1, OutputDevice* pOut): - SdrObjEditView(pModel1,pOut) +SdrExchangeView::SdrExchangeView( + SdrModel& rSdrModel, + OutputDevice* pOut) +: SdrObjEditView(rSdrModel, pOut) { } @@ -143,8 +145,11 @@ bool SdrExchangeView::Paste(const OUString& rStr, const Point& rPos, SdrObjList* if (pPage!=nullptr) { aTextRect.SetSize(pPage->GetSize()); } - SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect); - pObj->SetModel(mpModel); + SdrRectObj* pObj = new SdrRectObj( + getSdrModelFromSdrView(), + OBJ_TEXT, + aTextRect); + pObj->SetLayer(nLayer); pObj->NbcSetText(rStr); // SetText before SetAttr, else SetAttr doesn't work! if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false); @@ -180,8 +185,11 @@ bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat eFormat, const Point& if (pPage!=nullptr) { aTextRect.SetSize(pPage->GetSize()); } - SdrRectObj* pObj=new SdrRectObj(OBJ_TEXT,aTextRect); - pObj->SetModel(mpModel); + SdrRectObj* pObj = new SdrRectObj( + getSdrModelFromSdrView(), + OBJ_TEXT, + aTextRect); + pObj->SetLayer(nLayer); if (mpDefaultStyleSheet!=nullptr) pObj->NbcSetStyleSheet(mpDefaultStyleSheet, false); @@ -201,9 +209,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->GetModel() && pObj->GetOutlinerParaObject()) + if(pObj->GetOutlinerParaObject()) { - SdrOutliner& rOutliner = pObj->GetModel()->GetHitTestOutliner(); + SdrOutliner& rOutliner = pObj->getSdrModelFromSdrObject().GetHitTestOutliner(); rOutliner.SetText(*pObj->GetOutlinerParaObject()); if(1 == rOutliner.GetParagraphCount()) @@ -212,7 +220,7 @@ bool SdrExchangeView::Paste(SvStream& rInput, EETextFormat eFormat, const Point& if(pCandidate) { - if(pObj->GetModel()->GetStyleSheetPool() == &pCandidate->GetPool()) + if(pObj->getSdrModelFromSdrObject().GetStyleSheetPool() == &pCandidate->GetPool()) { pObj->NbcSetStyleSheet(pCandidate, true); } @@ -305,15 +313,13 @@ bool SdrExchangeView::Paste( { if(bResize) { - pNewObj->GetModel()->SetPasteResize(true); + pNewObj->getSdrModelFromSdrObject().SetPasteResize(true); pNewObj->NbcResize(aPt0,aXResize,aYResize); - pNewObj->GetModel()->SetPasteResize(false); + pNewObj->getSdrModelFromSdrObject().SetPasteResize(false); } // #i39861# - pNewObj->SetModel(pDstLst->GetModel()); pNewObj->SetPage(pDstLst->GetPage()); - pNewObj->NbcMove(aSiz); const SdrPage* pPg = pDstLst->GetPage(); @@ -345,7 +351,7 @@ bool SdrExchangeView::Paste( pDstLst->InsertObject(pNewObj, SAL_MAX_SIZE); if( bUndo ) - AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pNewObj)); + AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pNewObj)); if (bMark) { // Don't already set Markhandles! @@ -414,7 +420,7 @@ void SdrExchangeView::ImpPasteObject(SdrObject* pObj, SdrObjList& rLst, const Po rLst.InsertObject(pObj, SAL_MAX_SIZE); if( IsUndoEnabled() ) - AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoNewObject(*pObj)); + AddUndo(getSdrModelFromSdrView().GetSdrUndoFactory().CreateUndoNewObject(*pObj)); SdrPageView* pMarkPV=nullptr; SdrPageView* pPV = GetSdrPageView(); @@ -579,7 +585,7 @@ Graphic SdrExchangeView::GetAllMarkedGraphic() const if( AreObjectsMarked() ) { if( ( 1 == GetMarkedObjectCount() ) && GetSdrMarkByIndex( 0 ) ) - aRet = SdrExchangeView::GetObjGraphic( mpModel, GetMarkedObjectByIndex( 0 ) ); + aRet = SdrExchangeView::GetObjGraphic(*GetMarkedObjectByIndex(0)); else aRet = GetMarkedObjMetaFile(); } @@ -588,68 +594,68 @@ Graphic SdrExchangeView::GetAllMarkedGraphic() const } -Graphic SdrExchangeView::GetObjGraphic( const SdrModel* pModel, const SdrObject* pObj ) +Graphic SdrExchangeView::GetObjGraphic(const SdrObject& rSdrObject) { Graphic aRet; - if( pModel && pObj ) - { - // 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); + // 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(pSdrGrafObj) + { + if(pSdrGrafObj->isEmbeddedVectorGraphicData()) { - 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(); - } + // get Metafile for Svg content + aRet = pSdrGrafObj->getMetafileFromEmbeddedVectorGraphicData(); } - else if(pSdrOle2Obj) + else { - if ( pSdrOle2Obj->GetGraphic() ) - aRet = *pSdrOle2Obj->GetGraphic(); + // Make behaviour coherent with metafile + // recording below (which of course also takes + // view-transformed objects) + aRet = pSdrGrafObj->GetTransformedGraphic(); } - - // if graphic could not be retrieved => go the hard way and create a MetaFile - if( ( GraphicType::NONE == aRet.GetType() ) || ( GraphicType::Default == aRet.GetType() ) ) + } + else if(pSdrOle2Obj) + { + if(pSdrOle2Obj->GetGraphic()) { - 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() ); + aRet = *pSdrOle2Obj->GetGraphic(); + } + } - if( aMtf.GetActionSize() ) - aRet = aMtf; + // 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()) + { + aRet = aMtf; } - } + } return aRet; } @@ -703,7 +709,6 @@ void SdrExchangeView::DrawMarkedObj(OutputDevice& rOut) const } } - SdrModel* SdrExchangeView::GetMarkedObjModel() const { // Sorting the MarkList here might be problematic in the future, so @@ -729,15 +734,16 @@ 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( GetObjGraphic( mpModel, pObj ), pObj->GetLogicRect() ); + pNewObj = new SdrGrafObj( + *pNeuMod, + GetObjGraphic(*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); @@ -750,8 +756,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: */ |