Bump version to 24.04.3.4
[LibreOffice.git] / svx / source / svdraw / svdundo.cxx
blob0dcfede6e0cc3dcd6a50582521b0266dd044608b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/drawing/FillStyle.hpp>
22 #include <svx/svdundo.hxx>
23 #include <svx/svdotext.hxx>
24 #include <svx/svdobj.hxx>
25 #include <svx/svdpage.hxx>
26 #include <svx/svdlayer.hxx>
27 #include <svx/svdmodel.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/xbtmpit.hxx>
30 #include <svx/xfillit0.hxx>
31 #include <svx/strings.hrc>
32 #include <svx/dialmgr.hxx>
33 #include <svx/scene3d.hxx>
34 #include <editeng/outlobj.hxx>
35 #include <svx/svdogrp.hxx>
36 #include <sdr/properties/itemsettools.hxx>
37 #include <svx/sdr/properties/properties.hxx>
38 #include <svx/svdocapt.hxx>
39 #include <svl/whiter.hxx>
40 #include <svx/e3dsceneupdater.hxx>
41 #include <svx/svdviter.hxx>
42 #include <svx/svdotable.hxx> // #i124389#
43 #include <utility>
44 #include <vcl/svapp.hxx>
45 #include <sfx2/viewsh.hxx>
46 #include <svx/svdoashp.hxx>
47 #include <sal/log.hxx>
48 #include <osl/diagnose.h>
49 #include <svx/diagram/datamodel.hxx>
50 #include <svx/diagram/IDiagramHelper.hxx>
53 // iterates over all views and unmarks this SdrObject if it is marked
54 static void ImplUnmarkObject( SdrObject* pObj )
56 SdrViewIter::ForAllViews( pObj,
57 [&pObj] (SdrView* pView)
59 pView->MarkObj( pObj, pView->GetSdrPageView(), true );
60 });
63 SdrUndoAction::SdrUndoAction(SdrModel& rNewMod)
64 : rMod(rNewMod), m_nViewShellId(-1)
66 if (SfxViewShell* pViewShell = SfxViewShell::Current())
67 m_nViewShellId = pViewShell->GetViewShellId();
70 SdrUndoAction::~SdrUndoAction() {}
72 bool SdrUndoAction::CanRepeat(SfxRepeatTarget& rView) const
74 SdrView* pV=dynamic_cast<SdrView*>( &rView );
75 if (pV!=nullptr) return CanSdrRepeat(*pV);
76 return false;
79 void SdrUndoAction::Repeat(SfxRepeatTarget& rView)
81 SdrView* pV=dynamic_cast<SdrView*>( &rView );
82 if (pV!=nullptr) SdrRepeat(*pV);
83 DBG_ASSERT(pV!=nullptr,"Repeat: SfxRepeatTarget that was handed over is not a SdrView");
86 OUString SdrUndoAction::GetRepeatComment(SfxRepeatTarget& rView) const
88 SdrView* pV=dynamic_cast<SdrView*>( &rView );
89 if (pV!=nullptr) return GetSdrRepeatComment();
90 return OUString();
93 bool SdrUndoAction::CanSdrRepeat(SdrView& /*rView*/) const
95 return false;
98 void SdrUndoAction::SdrRepeat(SdrView& /*rView*/)
102 OUString SdrUndoAction::GetSdrRepeatComment() const
104 return OUString();
107 ViewShellId SdrUndoAction::GetViewShellId() const
109 return m_nViewShellId;
112 SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod)
113 : SdrUndoAction(rNewMod),
114 eFunction(SdrRepeatFunc::NONE)
117 SdrUndoGroup::~SdrUndoGroup()
121 void SdrUndoGroup::AddAction(std::unique_ptr<SdrUndoAction> pAct)
123 maActions.push_back(std::move(pAct));
126 void SdrUndoGroup::Undo()
128 for (auto it = maActions.rbegin(); it != maActions.rend(); ++it)
129 (*it)->Undo();
132 void SdrUndoGroup::Redo()
134 for (std::unique_ptr<SdrUndoAction> & pAction : maActions)
135 pAction->Redo();
138 OUString SdrUndoGroup::GetComment() const
140 return aComment.replaceAll("%1", aObjDescription);
143 bool SdrUndoGroup::CanSdrRepeat(SdrView& rView) const
145 switch (eFunction)
147 case SdrRepeatFunc::NONE : return false;
148 case SdrRepeatFunc::Delete : return rView.AreObjectsMarked();
149 case SdrRepeatFunc::CombinePolyPoly: return rView.IsCombinePossible();
150 case SdrRepeatFunc::CombineOnePoly : return rView.IsCombinePossible(true);
151 case SdrRepeatFunc::DismantlePolys : return rView.IsDismantlePossible();
152 case SdrRepeatFunc::DismantleLines : return rView.IsDismantlePossible(true);
153 case SdrRepeatFunc::ConvertToPoly : return rView.IsConvertToPolyObjPossible();
154 case SdrRepeatFunc::ConvertToPath : return rView.IsConvertToPathObjPossible();
155 case SdrRepeatFunc::Group : return rView.IsGroupPossible();
156 case SdrRepeatFunc::Ungroup : return rView.IsUnGroupPossible();
157 case SdrRepeatFunc::PutToTop : return rView.IsToTopPossible();
158 case SdrRepeatFunc::PutToBottom : return rView.IsToBtmPossible();
159 case SdrRepeatFunc::MoveToTop : return rView.IsToTopPossible();
160 case SdrRepeatFunc::MoveToBottom : return rView.IsToBtmPossible();
161 case SdrRepeatFunc::ReverseOrder : return rView.IsReverseOrderPossible();
162 case SdrRepeatFunc::ImportMtf : return rView.IsImportMtfPossible();
163 default: break;
164 } // switch
165 return false;
168 void SdrUndoGroup::SdrRepeat(SdrView& rView)
170 switch (eFunction)
172 case SdrRepeatFunc::NONE : break;
173 case SdrRepeatFunc::Delete : rView.DeleteMarked(); break;
174 case SdrRepeatFunc::CombinePolyPoly : rView.CombineMarkedObjects(false); break;
175 case SdrRepeatFunc::CombineOnePoly : rView.CombineMarkedObjects(); break;
176 case SdrRepeatFunc::DismantlePolys : rView.DismantleMarkedObjects(); break;
177 case SdrRepeatFunc::DismantleLines : rView.DismantleMarkedObjects(true); break;
178 case SdrRepeatFunc::ConvertToPoly : rView.ConvertMarkedToPolyObj(); break;
179 case SdrRepeatFunc::ConvertToPath : rView.ConvertMarkedToPathObj(false); break;
180 case SdrRepeatFunc::Group : rView.GroupMarked(); break;
181 case SdrRepeatFunc::Ungroup : rView.UnGroupMarked(); break;
182 case SdrRepeatFunc::PutToTop : rView.PutMarkedToTop(); break;
183 case SdrRepeatFunc::PutToBottom : rView.PutMarkedToBtm(); break;
184 case SdrRepeatFunc::MoveToTop : rView.MovMarkedToTop(); break;
185 case SdrRepeatFunc::MoveToBottom : rView.MovMarkedToBtm(); break;
186 case SdrRepeatFunc::ReverseOrder : rView.ReverseOrderOfMarked(); break;
187 case SdrRepeatFunc::ImportMtf : rView.DoImportMarkedMtf(); break;
188 default: break;
189 } // switch
192 OUString SdrUndoGroup::GetSdrRepeatComment() const
194 return aComment.replaceAll("%1", SvxResId(STR_ObjNameSingulPlural));
197 SdrUndoObj::SdrUndoObj(SdrObject& rNewObj)
198 : SdrUndoAction(rNewObj.getSdrModelFromSdrObject())
199 ,mxObj(&rNewObj)
203 SdrUndoObj::~SdrUndoObj() {}
205 OUString SdrUndoObj::GetDescriptionStringForObject( const SdrObject& _rForObject, TranslateId pStrCacheID, bool bRepeat )
207 const OUString rStr {SvxResId(pStrCacheID)};
209 const sal_Int32 nPos = rStr.indexOf("%1");
210 if (nPos < 0)
211 return rStr;
213 if (bRepeat)
214 return rStr.replaceAt(nPos, 2, SvxResId(STR_ObjNameSingulPlural));
216 return rStr.replaceAt(nPos, 2, _rForObject.TakeObjNameSingul());
219 OUString SdrUndoObj::ImpGetDescriptionStr(TranslateId pStrCacheID, bool bRepeat) const
221 if ( mxObj )
222 return GetDescriptionStringForObject( *mxObj, pStrCacheID, bRepeat );
223 return OUString();
226 // common call method for possible change of the page when UNDO/REDO is triggered
227 void SdrUndoObj::ImpShowPageOfThisObject()
229 if(mxObj && mxObj->IsInserted() && mxObj->getSdrPageFromSdrObject())
231 SdrHint aHint(SdrHintKind::SwitchToPage, *mxObj, mxObj->getSdrPageFromSdrObject());
232 mxObj->getSdrModelFromSdrObject().Broadcast(aHint);
236 void SdrUndoAttrObj::ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool& rStyleSheetPool, SfxStyleSheet& rSheet)
238 SfxStyleSheetBase* pThere = rStyleSheetPool.Find(rSheet.GetName(), rSheet.GetFamily());
240 if(!pThere)
242 // re-insert remembered style which was removed in the meantime. To do this
243 // without assertion, do it without parent and set parent after insertion
244 const OUString aParent(rSheet.GetParent());
246 rSheet.SetParent(OUString());
247 rStyleSheetPool.Insert(&rSheet);
248 rSheet.SetParent(aParent);
252 SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSaveText)
253 : SdrUndoObj(rNewObj)
254 , bHaveToTakeRedoSet(true)
256 bStyleSheet = bStyleSheet1;
258 SdrObjList* pOL = rNewObj.GetSubList();
259 bool bIsGroup(pOL!=nullptr && pOL->GetObjCount());
260 bool bIs3DScene(bIsGroup && DynCastE3dScene(mxObj.get()));
262 if(bIsGroup)
264 // it's a group object!
265 pUndoGroup.reset(new SdrUndoGroup(mxObj->getSdrModelFromSdrObject()));
267 for (const rtl::Reference<SdrObject>& pObj : *pOL)
269 pUndoGroup->AddAction(
270 std::make_unique<SdrUndoAttrObj>(*pObj, bStyleSheet1));
274 if(bIsGroup && !bIs3DScene)
275 return;
277 moUndoSet.emplace( mxObj->GetMergedItemSet() );
279 if(bStyleSheet)
280 mxUndoStyleSheet = mxObj->GetStyleSheet();
282 if(bSaveText)
284 auto p = mxObj->GetOutlinerParaObject();
285 if(p)
286 pTextUndo = *p;
290 SdrUndoAttrObj::~SdrUndoAttrObj()
292 moUndoSet.reset();
293 moRedoSet.reset();
294 pUndoGroup.reset();
295 pTextUndo.reset();
296 pTextRedo.reset();
299 void SdrUndoAttrObj::Undo()
301 E3DModifySceneSnapRectUpdater aUpdater(mxObj.get());
302 bool bIs3DScene(DynCastE3dScene(mxObj.get()));
304 // Trigger PageChangeCall
305 ImpShowPageOfThisObject();
307 if(!pUndoGroup || bIs3DScene)
309 if(bHaveToTakeRedoSet)
311 bHaveToTakeRedoSet = false;
313 moRedoSet.emplace( mxObj->GetMergedItemSet() );
315 if(bStyleSheet)
316 mxRedoStyleSheet = mxObj->GetStyleSheet();
318 if(pTextUndo)
320 // #i8508#
321 auto p = mxObj->GetOutlinerParaObject();
322 if(p)
323 pTextRedo = *p;
327 if(bStyleSheet)
329 mxRedoStyleSheet = mxObj->GetStyleSheet();
330 SfxStyleSheet* pSheet = mxUndoStyleSheet.get();
332 if(pSheet && mxObj->getSdrModelFromSdrObject().GetStyleSheetPool())
334 ensureStyleSheetInStyleSheetPool(*mxObj->getSdrModelFromSdrObject().GetStyleSheetPool(), *pSheet);
335 mxObj->SetStyleSheet(pSheet, true);
337 else
339 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
343 sdr::properties::ItemChangeBroadcaster aItemChange(*mxObj);
345 // Since ClearItem sets back everything to normal
346 // it also sets fit-to-size text to non-fit-to-size text and
347 // switches on autogrowheight (the default). That may lead to
348 // losing the geometry size info for the object when it is
349 // laid out again from AdjustTextFrameWidthAndHeight(). This makes
350 // rescuing the size of the object necessary.
351 const tools::Rectangle aSnapRect = mxObj->GetSnapRect();
352 // SdrObjCustomShape::NbcSetSnapRect needs logic instead of snap rect
353 const tools::Rectangle aLogicRect = mxObj->GetLogicRect();
355 if(moUndoSet)
357 if(dynamic_cast<const SdrCaptionObj*>( mxObj.get() ) != nullptr)
359 // do a more smooth item deletion here, else the text
360 // rect will be reformatted, especially when information regarding
361 // vertical text is changed. When clearing only set items it's
362 // slower, but safer regarding such information (it's not changed
363 // usually)
364 SfxWhichIter aIter(*moUndoSet);
365 sal_uInt16 nWhich(aIter.FirstWhich());
367 while(nWhich)
369 if(SfxItemState::SET != aIter.GetItemState(false))
371 mxObj->ClearMergedItem(nWhich);
374 nWhich = aIter.NextWhich();
377 else
379 mxObj->ClearMergedItem();
382 mxObj->SetMergedItemSet(*moUndoSet);
385 // Restore previous size here when it was changed.
386 if(aSnapRect != mxObj->GetSnapRect())
388 if(dynamic_cast<const SdrObjCustomShape*>(mxObj.get()))
389 mxObj->NbcSetSnapRect(aLogicRect);
390 else
391 mxObj->NbcSetSnapRect(aSnapRect);
394 mxObj->GetProperties().BroadcastItemChange(aItemChange);
396 if(pTextUndo)
398 mxObj->SetOutlinerParaObject(*pTextUndo);
402 if(pUndoGroup)
404 pUndoGroup->Undo();
408 void SdrUndoAttrObj::Redo()
410 E3DModifySceneSnapRectUpdater aUpdater(mxObj.get());
411 bool bIs3DScene(DynCastE3dScene(mxObj.get()));
413 if(!pUndoGroup || bIs3DScene)
415 if(bStyleSheet)
417 mxUndoStyleSheet = mxObj->GetStyleSheet();
418 SfxStyleSheet* pSheet = mxRedoStyleSheet.get();
420 if(pSheet && mxObj->getSdrModelFromSdrObject().GetStyleSheetPool())
422 ensureStyleSheetInStyleSheetPool(*mxObj->getSdrModelFromSdrObject().GetStyleSheetPool(), *pSheet);
423 mxObj->SetStyleSheet(pSheet, true);
425 else
427 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
431 sdr::properties::ItemChangeBroadcaster aItemChange(*mxObj);
433 const tools::Rectangle aSnapRect = mxObj->GetSnapRect();
434 const tools::Rectangle aLogicRect = mxObj->GetLogicRect();
436 if(moRedoSet)
438 if(dynamic_cast<const SdrCaptionObj*>( mxObj.get() ) != nullptr)
440 // do a more smooth item deletion here, else the text
441 // rect will be reformatted, especially when information regarding
442 // vertical text is changed. When clearing only set items it's
443 // slower, but safer regarding such information (it's not changed
444 // usually)
445 SfxWhichIter aIter(*moRedoSet);
446 sal_uInt16 nWhich(aIter.FirstWhich());
448 while(nWhich)
450 if(SfxItemState::SET != aIter.GetItemState(false))
452 mxObj->ClearMergedItem(nWhich);
455 nWhich = aIter.NextWhich();
458 else
460 mxObj->ClearMergedItem();
463 mxObj->SetMergedItemSet(*moRedoSet);
466 // Restore previous size here when it was changed.
467 if(aSnapRect != mxObj->GetSnapRect())
469 if(dynamic_cast<const SdrObjCustomShape*>(mxObj.get()))
470 mxObj->NbcSetSnapRect(aLogicRect);
471 else
472 mxObj->NbcSetSnapRect(aSnapRect);
475 mxObj->GetProperties().BroadcastItemChange(aItemChange);
477 // #i8508#
478 if(pTextRedo)
480 mxObj->SetOutlinerParaObject(*pTextRedo);
484 if(pUndoGroup)
486 pUndoGroup->Redo();
489 // Trigger PageChangeCall
490 ImpShowPageOfThisObject();
493 OUString SdrUndoAttrObj::GetComment() const
495 if(bStyleSheet)
497 return ImpGetDescriptionStr(STR_EditSetStylesheet);
499 else
501 return ImpGetDescriptionStr(STR_EditSetAttributes);
505 OUString SdrUndoAttrObj::GetSdrRepeatComment() const
507 if(bStyleSheet)
509 return ImpGetDescriptionStr(STR_EditSetStylesheet, true);
511 else
513 return ImpGetDescriptionStr(STR_EditSetAttributes, true);
518 SdrUndoMoveObj::~SdrUndoMoveObj() {}
520 void SdrUndoMoveObj::Undo()
522 // Trigger PageChangeCall
523 ImpShowPageOfThisObject();
525 mxObj->Move(Size(-aDistance.Width(),-aDistance.Height()));
528 void SdrUndoMoveObj::Redo()
530 mxObj->Move(Size(aDistance.Width(),aDistance.Height()));
532 // Trigger PageChangeCall
533 ImpShowPageOfThisObject();
536 OUString SdrUndoMoveObj::GetComment() const
538 return ImpGetDescriptionStr(STR_EditMove);
541 void SdrUndoMoveObj::SdrRepeat(SdrView& rView)
543 rView.MoveMarkedObj(aDistance);
546 bool SdrUndoMoveObj::CanSdrRepeat(SdrView& rView) const
548 return rView.AreObjectsMarked();
551 OUString SdrUndoMoveObj::GetSdrRepeatComment() const
553 return ImpGetDescriptionStr(STR_EditMove,true);
557 SdrUndoGeoObj::SdrUndoGeoObj(SdrObject& rNewObj)
558 : SdrUndoObj(rNewObj)
559 , mbSkipChangeLayout(false)
561 SdrObjList* pOL=rNewObj.GetSubList();
562 if (pOL!=nullptr && pOL->GetObjCount() && !DynCastE3dScene(&rNewObj))
564 // this is a group object!
565 // If this were 3D scene, we'd only add an Undo for the scene itself
566 // (which we do elsewhere).
567 pUndoGroup.reset(new SdrUndoGroup(mxObj->getSdrModelFromSdrObject()));
568 for (const rtl::Reference<SdrObject>& pObj : *pOL)
569 pUndoGroup->AddAction(std::make_unique<SdrUndoGeoObj>(*pObj));
571 else
573 pUndoGeo = mxObj->GetGeoData();
577 SdrUndoGeoObj::~SdrUndoGeoObj()
579 pUndoGeo.reset();
580 pRedoGeo.reset();
581 pUndoGroup.reset();
584 void SdrUndoGeoObj::Undo()
586 // Trigger PageChangeCall
587 ImpShowPageOfThisObject();
589 if(pUndoGroup)
591 pUndoGroup->Undo();
593 // only repaint, no objectchange
594 mxObj->ActionChanged();
596 else
598 pRedoGeo = mxObj->GetGeoData();
600 auto pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(mxObj.get());
601 if (pTableObj && mbSkipChangeLayout)
602 pTableObj->SetSkipChangeLayout(true);
603 mxObj->SetGeoData(*pUndoGeo);
604 if (pTableObj && mbSkipChangeLayout)
605 pTableObj->SetSkipChangeLayout(false);
609 void SdrUndoGeoObj::Redo()
611 if(pUndoGroup)
613 pUndoGroup->Redo();
615 // only repaint, no objectchange
616 mxObj->ActionChanged();
618 else
620 pUndoGeo = mxObj->GetGeoData();
621 mxObj->SetGeoData(*pRedoGeo);
624 // Trigger PageChangeCall
625 ImpShowPageOfThisObject();
628 OUString SdrUndoGeoObj::GetComment() const
630 return ImpGetDescriptionStr(STR_DragMethObjOwn);
633 SdrUndoDiagramModelData::SdrUndoDiagramModelData(SdrObject& rNewObj, svx::diagram::DiagramDataStatePtr& rStartState)
634 : SdrUndoObj(rNewObj)
635 , m_aStartState(rStartState)
636 , m_aEndState()
638 if(rNewObj.isDiagram())
639 m_aEndState = rNewObj.getDiagramHelper()->extractDiagramDataState();
642 SdrUndoDiagramModelData::~SdrUndoDiagramModelData()
646 void SdrUndoDiagramModelData::implUndoRedo(bool bUndo)
648 if(!mxObj)
649 return;
651 if(!mxObj->isDiagram())
652 return;
654 mxObj->getDiagramHelper()->applyDiagramDataState(
655 bUndo ? m_aStartState : m_aEndState);
656 mxObj->getDiagramHelper()->reLayout(*static_cast<SdrObjGroup*>(mxObj.get()));
659 void SdrUndoDiagramModelData::Undo()
661 implUndoRedo(true);
664 void SdrUndoDiagramModelData::Redo()
666 implUndoRedo(false);
669 OUString SdrUndoDiagramModelData::GetComment() const
671 return ImpGetDescriptionStr(STR_DiagramModelDataChange);
674 SdrUndoObjList::SdrUndoObjList(SdrObject& rNewObj, bool bOrdNumDirect)
675 : SdrUndoObj(rNewObj)
677 pObjList=mxObj->getParentSdrObjListFromSdrObject();
678 if (bOrdNumDirect)
680 nOrdNum=mxObj->GetOrdNumDirect();
682 else
684 nOrdNum=mxObj->GetOrdNum();
688 SdrUndoObjList::~SdrUndoObjList()
692 void SdrUndoRemoveObj::Undo()
694 // Trigger PageChangeCall
695 ImpShowPageOfThisObject();
697 DBG_ASSERT(!mxObj->IsInserted(),"UndoRemoveObj: mxObj has already been inserted.");
698 if (mxObj->IsInserted())
699 return;
701 // #i11426#
702 // For UNDOs in Calc/Writer it is necessary to adapt the anchor
703 // position of the target object.
704 Point aOwnerAnchorPos(0, 0);
706 if (dynamic_cast< const SdrObjGroup* >(pObjList->getSdrObjectFromSdrObjList()) != nullptr)
708 aOwnerAnchorPos = pObjList->getSdrObjectFromSdrObjList()->GetAnchorPos();
711 E3DModifySceneSnapRectUpdater aUpdater(pObjList->getSdrObjectFromSdrObjList());
712 pObjList->InsertObject(mxObj.get(), nOrdNum);
714 // #i11426#
715 if(aOwnerAnchorPos.X() || aOwnerAnchorPos.Y())
717 mxObj->NbcSetAnchorPos(aOwnerAnchorPos);
721 void SdrUndoRemoveObj::Redo()
723 DBG_ASSERT(mxObj->IsInserted(),"RedoRemoveObj: mxObj is not inserted.");
724 if (mxObj->IsInserted())
726 ImplUnmarkObject( mxObj.get() );
727 E3DModifySceneSnapRectUpdater aUpdater(mxObj.get());
728 pObjList->RemoveObject(mxObj->GetOrdNum());
731 // Trigger PageChangeCall
732 ImpShowPageOfThisObject();
735 SdrUndoRemoveObj::~SdrUndoRemoveObj()
740 void SdrUndoInsertObj::Undo()
742 // Trigger PageChangeCall
743 ImpShowPageOfThisObject();
745 DBG_ASSERT(mxObj->IsInserted(),"UndoInsertObj: mxObj is not inserted.");
746 if (mxObj->IsInserted())
748 ImplUnmarkObject( mxObj.get() );
750 rtl::Reference<SdrObject> pChkObj= pObjList->RemoveObject(mxObj->GetOrdNum());
751 DBG_ASSERT(pChkObj.get()==mxObj.get(),"UndoInsertObj: RemoveObjNum!=mxObj");
755 void SdrUndoInsertObj::Redo()
757 DBG_ASSERT(!mxObj->IsInserted(),"RedoInsertObj: mxObj is already inserted");
758 if (!mxObj->IsInserted())
760 // Restore anchor position of an object,
761 // which becomes a member of a group, because its cleared in method
762 // <InsertObject(..)>. Needed for correct Redo in Writer. (#i45952#)
763 Point aAnchorPos( 0, 0 );
765 if (dynamic_cast<const SdrObjGroup*>(pObjList->getSdrObjectFromSdrObjList()) != nullptr)
767 aAnchorPos = mxObj->GetAnchorPos();
770 pObjList->InsertObject(mxObj.get(), nOrdNum);
772 // Arcs lose position when grouped (#i45952#)
773 if ( aAnchorPos.X() || aAnchorPos.Y() )
775 mxObj->NbcSetAnchorPos( aAnchorPos );
779 // Trigger PageChangeCall
780 ImpShowPageOfThisObject();
783 SdrUndoDelObj::SdrUndoDelObj(SdrObject& rNewObj, bool bOrdNumDirect)
784 : SdrUndoRemoveObj(rNewObj,bOrdNumDirect)
788 void SdrUndoDelObj::Undo()
790 SdrUndoRemoveObj::Undo();
793 void SdrUndoDelObj::Redo()
795 SdrUndoRemoveObj::Redo();
798 OUString SdrUndoDelObj::GetComment() const
800 return ImpGetDescriptionStr(STR_EditDelete);
803 void SdrUndoDelObj::SdrRepeat(SdrView& rView)
805 rView.DeleteMarked();
808 bool SdrUndoDelObj::CanSdrRepeat(SdrView& rView) const
810 return rView.AreObjectsMarked();
813 OUString SdrUndoDelObj::GetSdrRepeatComment() const
815 return ImpGetDescriptionStr(STR_EditDelete,true);
819 void SdrUndoNewObj::Undo()
821 SdrUndoInsertObj::Undo();
824 void SdrUndoNewObj::Redo()
826 SdrUndoInsertObj::Redo();
829 OUString SdrUndoNewObj::GetComment( const SdrObject& _rForObject )
831 return GetDescriptionStringForObject( _rForObject, STR_UndoInsertObj );
834 OUString SdrUndoNewObj::GetComment() const
836 return ImpGetDescriptionStr(STR_UndoInsertObj);
839 SdrUndoReplaceObj::SdrUndoReplaceObj(SdrObject& rOldObj1, SdrObject& rNewObj1)
840 : SdrUndoObj(rOldObj1)
841 , mxNewObj(&rNewObj1)
843 pObjList=mxObj->getParentSdrObjListFromSdrObject();
846 SdrUndoReplaceObj::~SdrUndoReplaceObj()
850 void SdrUndoReplaceObj::Undo()
852 // Trigger PageChangeCall
853 ImpShowPageOfThisObject();
855 DBG_ASSERT(!mxObj->IsInserted(),"SdrUndoReplaceObj::Undo(): Old object is already inserted!");
856 DBG_ASSERT(mxNewObj->IsInserted(),"SdrUndoReplaceObj::Undo(): New object is not inserted!");
858 ImplUnmarkObject( mxNewObj.get() );
859 pObjList->ReplaceObject(mxObj.get(), mxNewObj->GetOrdNum());
862 void SdrUndoReplaceObj::Redo()
864 ImplUnmarkObject( mxObj.get() );
865 pObjList->ReplaceObject(mxNewObj.get(), mxObj->GetOrdNum());
867 // Trigger PageChangeCall
868 ImpShowPageOfThisObject();
872 OUString SdrUndoCopyObj::GetComment() const
874 return ImpGetDescriptionStr(STR_UndoCopyObj);
878 // #i11702#
880 SdrUndoObjectLayerChange::SdrUndoObjectLayerChange(SdrObject& rObj, SdrLayerID aOldLayer, SdrLayerID aNewLayer)
881 : SdrUndoObj(rObj)
882 , maOldLayer(aOldLayer)
883 , maNewLayer(aNewLayer)
887 void SdrUndoObjectLayerChange::Undo()
889 ImpShowPageOfThisObject();
890 mxObj->SetLayer(maOldLayer);
893 void SdrUndoObjectLayerChange::Redo()
895 mxObj->SetLayer(maNewLayer);
896 ImpShowPageOfThisObject();
900 SdrUndoObjOrdNum::SdrUndoObjOrdNum(SdrObject& rNewObj, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
901 : SdrUndoObj(rNewObj)
902 , nOldOrdNum(nOldOrdNum1)
903 , nNewOrdNum(nNewOrdNum1)
907 void SdrUndoObjOrdNum::Undo()
909 // Trigger PageChangeCall
910 ImpShowPageOfThisObject();
912 SdrObjList* pOL=mxObj->getParentSdrObjListFromSdrObject();
913 if (pOL==nullptr)
915 OSL_FAIL("UndoObjOrdNum: mxObj does not have an ObjList.");
916 return;
918 pOL->SetObjectOrdNum(nNewOrdNum,nOldOrdNum);
921 void SdrUndoObjOrdNum::Redo()
923 SdrObjList* pOL=mxObj->getParentSdrObjListFromSdrObject();
924 if (pOL==nullptr)
926 OSL_FAIL("RedoObjOrdNum: mxObj does not have an ObjList.");
927 return;
929 pOL->SetObjectOrdNum(nOldOrdNum,nNewOrdNum);
931 // Trigger PageChangeCall
932 ImpShowPageOfThisObject();
935 OUString SdrUndoObjOrdNum::GetComment() const
937 return ImpGetDescriptionStr(STR_UndoObjOrdNum);
940 SdrUndoSort::SdrUndoSort(const SdrPage & rPage,
941 ::std::vector<sal_Int32> const& rSortOrder)
942 : SdrUndoAction(rPage.getSdrModelFromSdrPage())
943 , m_OldSortOrder(rSortOrder.size())
944 , m_NewSortOrder(rSortOrder)
945 , m_nPage(rPage.GetPageNum())
947 // invert order
948 for (size_t i = 0; i < rSortOrder.size(); ++i)
950 m_OldSortOrder[rSortOrder[i]] = i;
954 void SdrUndoSort::Do(::std::vector<sal_Int32> & rSortOrder)
956 SdrPage & rPage(*rMod.GetPage(m_nPage));
957 if (rPage.GetObjCount() != rSortOrder.size())
959 // can probably happen with sw's cursed SdrVirtObj mess - no good solution for that
960 SAL_WARN("svx", "SdrUndoSort size mismatch");
961 return;
964 // hopefully this can't throw
965 rPage.sort(rSortOrder);
968 void SdrUndoSort::Undo()
970 Do(m_OldSortOrder);
973 void SdrUndoSort::Redo()
975 Do(m_NewSortOrder);
978 OUString SdrUndoSort::GetComment() const
980 return SvxResId(STR_SortShapes);
983 SdrUndoObjSetText::SdrUndoObjSetText(SdrObject& rNewObj, sal_Int32 nText)
984 : SdrUndoObj(rNewObj)
985 , bNewTextAvailable(false)
986 , bEmptyPresObj(false)
987 , mnText(nText)
989 SdrText* pText = static_cast< SdrTextObj*>( &rNewObj )->getText(mnText);
990 if( pText && pText->GetOutlinerParaObject() )
991 pOldText = *pText->GetOutlinerParaObject();
993 bEmptyPresObj = rNewObj.IsEmptyPresObj();
996 SdrUndoObjSetText::~SdrUndoObjSetText()
998 pOldText.reset();
999 pNewText.reset();
1002 bool SdrUndoObjSetText::IsDifferent() const
1004 if (!pOldText || !pNewText)
1005 return pOldText || pNewText;
1006 return *pOldText != *pNewText;
1009 void SdrUndoObjSetText::AfterSetText()
1011 if (!bNewTextAvailable)
1013 SdrText* pText = static_cast< SdrTextObj*>( mxObj.get() )->getText(mnText);
1014 if( pText && pText->GetOutlinerParaObject() )
1015 pNewText = *pText->GetOutlinerParaObject();
1016 bNewTextAvailable=true;
1020 void SdrUndoObjSetText::Undo()
1022 // only works with SdrTextObj
1023 SdrTextObj* pTarget = DynCastSdrTextObj(mxObj.get());
1025 if(!pTarget)
1027 OSL_ENSURE(false, "SdrUndoObjSetText::Undo with SdrObject not based on SdrTextObj (!)");
1028 return;
1031 // Trigger PageChangeCall
1032 ImpShowPageOfThisObject();
1034 // save old text for Redo
1035 if(!bNewTextAvailable)
1037 AfterSetText();
1040 SdrText* pText = pTarget->getText(mnText);
1041 if (pText)
1043 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1044 pTarget->NbcSetOutlinerParaObjectForText(pOldText, pText);
1047 pTarget->SetEmptyPresObj(bEmptyPresObj);
1048 pTarget->ActionChanged();
1050 // #i124389# if it's a table, also need to relayout TextFrame
1051 if(dynamic_cast< sdr::table::SdrTableObj* >(pTarget) != nullptr)
1053 pTarget->NbcAdjustTextFrameWidthAndHeight();
1056 // #i122410# SetOutlinerParaObject at SdrText does not trigger a
1057 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1058 // update their preview.
1059 pTarget->BroadcastObjectChange();
1062 void SdrUndoObjSetText::Redo()
1064 // only works with SdrTextObj
1065 SdrTextObj* pTarget = DynCastSdrTextObj(mxObj.get());
1067 if(!pTarget)
1069 OSL_ENSURE(false, "SdrUndoObjSetText::Redo with SdrObject not based on SdrTextObj (!)");
1070 return;
1073 SdrText* pText = pTarget->getText(mnText);
1074 if (pText)
1076 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1077 pTarget->NbcSetOutlinerParaObjectForText( pNewText, pText );
1080 pTarget->ActionChanged();
1082 // #i124389# if it's a table, also need to relayout TextFrame
1083 if(dynamic_cast< sdr::table::SdrTableObj* >(pTarget) != nullptr)
1085 pTarget->NbcAdjustTextFrameWidthAndHeight();
1088 // #i122410# NbcSetOutlinerParaObjectForText at SdrTextObj does not trigger a
1089 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1090 // update their preview.
1091 pTarget->BroadcastObjectChange();
1093 // Trigger PageChangeCall
1094 ImpShowPageOfThisObject();
1097 OUString SdrUndoObjSetText::GetComment() const
1099 return ImpGetDescriptionStr(STR_UndoObjSetText);
1102 OUString SdrUndoObjSetText::GetSdrRepeatComment() const
1104 return ImpGetDescriptionStr(STR_UndoObjSetText);
1107 void SdrUndoObjSetText::SdrRepeat(SdrView& rView)
1109 if (!(bNewTextAvailable && rView.AreObjectsMarked()))
1110 return;
1112 const SdrMarkList& rML=rView.GetMarkedObjectList();
1114 const bool bUndo = rView.IsUndoEnabled();
1115 if( bUndo )
1117 OUString aStr = ImpGetDescriptionStr(STR_UndoObjSetText);
1118 rView.BegUndo(aStr);
1121 const size_t nCount=rML.GetMarkCount();
1122 for (size_t nm=0; nm<nCount; ++nm)
1124 SdrObject* pObj2=rML.GetMark(nm)->GetMarkedSdrObj();
1125 SdrTextObj* pTextObj=DynCastSdrTextObj( pObj2 );
1126 if (pTextObj!=nullptr)
1128 if( bUndo )
1129 rView.AddUndo(std::make_unique<SdrUndoObjSetText>(*pTextObj,0));
1131 pTextObj->SetOutlinerParaObject(pNewText);
1135 if( bUndo )
1136 rView.EndUndo();
1139 bool SdrUndoObjSetText::CanSdrRepeat(SdrView& rView) const
1141 bool bOk = false;
1142 if (bNewTextAvailable && rView.AreObjectsMarked()) {
1143 bOk=true;
1145 return bOk;
1148 // Undo/Redo for setting object's name (#i73249#)
1149 SdrUndoObjStrAttr::SdrUndoObjStrAttr( SdrObject& rNewObj,
1150 const ObjStrAttrType eObjStrAttr,
1151 OUString sOldStr,
1152 OUString sNewStr)
1153 : SdrUndoObj( rNewObj )
1154 , meObjStrAttr( eObjStrAttr )
1155 , msOldStr(std::move( sOldStr ))
1156 , msNewStr(std::move( sNewStr ))
1160 void SdrUndoObjStrAttr::Undo()
1162 ImpShowPageOfThisObject();
1164 switch ( meObjStrAttr )
1166 case ObjStrAttrType::Name:
1167 mxObj->SetName( msOldStr );
1168 break;
1169 case ObjStrAttrType::Title:
1170 mxObj->SetTitle( msOldStr );
1171 break;
1172 case ObjStrAttrType::Description:
1173 mxObj->SetDescription( msOldStr );
1174 break;
1178 void SdrUndoObjStrAttr::Redo()
1180 switch ( meObjStrAttr )
1182 case ObjStrAttrType::Name:
1183 mxObj->SetName( msNewStr );
1184 break;
1185 case ObjStrAttrType::Title:
1186 mxObj->SetTitle( msNewStr );
1187 break;
1188 case ObjStrAttrType::Description:
1189 mxObj->SetDescription( msNewStr );
1190 break;
1193 ImpShowPageOfThisObject();
1196 OUString SdrUndoObjStrAttr::GetComment() const
1198 OUString aStr;
1199 switch ( meObjStrAttr )
1201 case ObjStrAttrType::Name:
1202 aStr = ImpGetDescriptionStr( STR_UndoObjName) +
1203 " '" + msNewStr + "'";
1204 break;
1205 case ObjStrAttrType::Title:
1206 aStr = ImpGetDescriptionStr( STR_UndoObjTitle );
1207 break;
1208 case ObjStrAttrType::Description:
1209 aStr = ImpGetDescriptionStr( STR_UndoObjDescription );
1210 break;
1213 return aStr;
1216 SdrUndoObjDecorative::SdrUndoObjDecorative(SdrObject & rObj, bool const WasDecorative)
1217 : SdrUndoObj(rObj)
1218 , m_WasDecorative(WasDecorative)
1222 void SdrUndoObjDecorative::Undo()
1224 ImpShowPageOfThisObject();
1226 mxObj->SetDecorative(m_WasDecorative);
1229 void SdrUndoObjDecorative::Redo()
1231 mxObj->SetDecorative(!m_WasDecorative);
1233 ImpShowPageOfThisObject();
1236 OUString SdrUndoObjDecorative::GetComment() const
1238 return ImpGetDescriptionStr(STR_UndoObjDecorative);
1242 SdrUndoLayer::SdrUndoLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1243 : SdrUndoAction(rNewModel)
1244 , pLayer(rNewLayerAdmin.GetLayer(nLayerNum))
1245 , pLayerAdmin(&rNewLayerAdmin)
1246 , nNum(nLayerNum)
1247 , bItsMine(false)
1251 SdrUndoLayer::~SdrUndoLayer()
1253 if (bItsMine)
1255 delete pLayer;
1259 void SdrUndoNewLayer::Undo()
1261 DBG_ASSERT(!bItsMine,"SdrUndoNewLayer::Undo(): Layer already belongs to UndoAction.");
1262 bItsMine=true;
1263 // coverity[leaked_storage] - owned by this SdrUndoNewLayer as pLayer
1264 SdrLayer* pCmpLayer = pLayerAdmin->RemoveLayer(nNum).release();
1265 assert(pCmpLayer == pLayer && "SdrUndoNewLayer::Undo(): Removed layer is != pLayer."); (void)pCmpLayer;
1268 void SdrUndoNewLayer::Redo()
1270 DBG_ASSERT(bItsMine,"SdrUndoNewLayer::Undo(): Layer does not belong to UndoAction.");
1271 bItsMine=false;
1272 pLayerAdmin->InsertLayer(std::unique_ptr<SdrLayer>(pLayer),nNum);
1275 OUString SdrUndoNewLayer::GetComment() const
1277 return SvxResId(STR_UndoNewLayer);
1281 void SdrUndoDelLayer::Undo()
1283 DBG_ASSERT(bItsMine,"SdrUndoDelLayer::Undo(): Layer does not belong to UndoAction.");
1284 bItsMine=false;
1285 pLayerAdmin->InsertLayer(std::unique_ptr<SdrLayer>(pLayer),nNum);
1288 void SdrUndoDelLayer::Redo()
1290 DBG_ASSERT(!bItsMine,"SdrUndoDelLayer::Undo(): Layer already belongs to UndoAction.");
1291 bItsMine=true;
1292 // coverity[leaked_storage] - owned by this SdrUndoNewLayer as pLayer
1293 SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum).release();
1294 assert(pCmpLayer == pLayer && "SdrUndoDelLayer::Redo(): Removed layer is != pLayer."); (void)pCmpLayer;
1297 OUString SdrUndoDelLayer::GetComment() const
1299 return SvxResId(STR_UndoDelLayer);
1303 SdrUndoPage::SdrUndoPage(SdrPage& rNewPg)
1304 : SdrUndoAction(rNewPg.getSdrModelFromSdrPage())
1305 ,mxPage(&rNewPg)
1309 SdrUndoPage::~SdrUndoPage() {}
1311 void SdrUndoPage::ImpInsertPage(sal_uInt16 nNum)
1313 DBG_ASSERT(!mxPage->IsInserted(),"SdrUndoPage::ImpInsertPage(): mxPage is already inserted.");
1314 if (!mxPage->IsInserted())
1316 if (mxPage->IsMasterPage())
1318 rMod.InsertMasterPage(mxPage.get(), nNum);
1320 else
1322 rMod.InsertPage(mxPage.get(), nNum);
1327 void SdrUndoPage::ImpRemovePage(sal_uInt16 nNum)
1329 DBG_ASSERT(mxPage->IsInserted(),"SdrUndoPage::ImpRemovePage(): mxPage is not inserted.");
1330 if (!mxPage->IsInserted())
1331 return;
1333 rtl::Reference<SdrPage> pChkPg;
1334 if (mxPage->IsMasterPage())
1336 pChkPg = rMod.RemoveMasterPage(nNum);
1338 else
1340 pChkPg = rMod.RemovePage(nNum);
1342 DBG_ASSERT(pChkPg==mxPage,"SdrUndoPage::ImpRemovePage(): RemovePage!=mxPage");
1345 void SdrUndoPage::ImpMovePage(sal_uInt16 nOldNum, sal_uInt16 nNewNum)
1347 DBG_ASSERT(mxPage->IsInserted(),"SdrUndoPage::ImpMovePage(): mxPage is not inserted.");
1348 if (mxPage->IsInserted())
1350 if (mxPage->IsMasterPage())
1352 rMod.MoveMasterPage(nOldNum,nNewNum);
1354 else
1356 rMod.MovePage(nOldNum,nNewNum);
1361 OUString SdrUndoPage::ImpGetDescriptionStr(TranslateId pStrCacheID)
1363 return SvxResId(pStrCacheID);
1367 SdrUndoPageList::SdrUndoPageList(SdrPage& rNewPg)
1368 : SdrUndoPage(rNewPg)
1370 nPageNum=rNewPg.GetPageNum();
1373 SdrUndoPageList::~SdrUndoPageList()
1378 SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg)
1379 : SdrUndoPageList(rNewPg)
1380 , mbHasFillBitmap(false)
1382 // keep fill bitmap separately to remove it from pool if not used elsewhere
1383 if (mxPage->IsMasterPage())
1385 SfxStyleSheet* const pStyleSheet = mxPage->getSdrPageProperties().GetStyleSheet();
1386 if (pStyleSheet)
1387 queryFillBitmap(pStyleSheet->GetItemSet());
1389 else
1391 queryFillBitmap(mxPage->getSdrPageProperties().GetItemSet());
1393 if (bool(mpFillBitmapItem))
1394 clearFillBitmap();
1396 // now remember the master page relationships
1397 if(!mxPage->IsMasterPage())
1398 return;
1400 sal_uInt16 nPageCnt(rMod.GetPageCount());
1402 for(sal_uInt16 nPageNum2(0); nPageNum2 < nPageCnt; nPageNum2++)
1404 SdrPage* pDrawPage = rMod.GetPage(nPageNum2);
1406 if(pDrawPage->TRG_HasMasterPage())
1408 SdrPage& rMasterPage = pDrawPage->TRG_GetMasterPage();
1410 if(mxPage.get() == &rMasterPage)
1412 if(!pUndoGroup)
1414 pUndoGroup.reset( new SdrUndoGroup(rMod) );
1417 pUndoGroup->AddAction(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage));
1423 SdrUndoDelPage::~SdrUndoDelPage()
1427 void SdrUndoDelPage::Undo()
1429 if (bool(mpFillBitmapItem))
1430 restoreFillBitmap();
1431 ImpInsertPage(nPageNum);
1432 if (pUndoGroup!=nullptr)
1434 // recover master page relationships
1435 pUndoGroup->Undo();
1439 void SdrUndoDelPage::Redo()
1441 ImpRemovePage(nPageNum);
1442 if (bool(mpFillBitmapItem))
1443 clearFillBitmap();
1446 OUString SdrUndoDelPage::GetComment() const
1448 return ImpGetDescriptionStr(STR_UndoDelPage);
1451 OUString SdrUndoDelPage::GetSdrRepeatComment() const
1453 return ImpGetDescriptionStr(STR_UndoDelPage);
1456 void SdrUndoDelPage::SdrRepeat(SdrView& /*rView*/)
1460 bool SdrUndoDelPage::CanSdrRepeat(SdrView& /*rView*/) const
1462 return false;
1465 void SdrUndoDelPage::queryFillBitmap(const SfxItemSet& rItemSet)
1467 if (const XFillBitmapItem *pItem = rItemSet.GetItemIfSet(XATTR_FILLBITMAP, false))
1468 mpFillBitmapItem.reset(pItem->Clone());
1469 if (const XFillStyleItem *pItem = rItemSet.GetItemIfSet(XATTR_FILLSTYLE, false))
1470 mbHasFillBitmap = pItem->GetValue() == css::drawing::FillStyle_BITMAP;
1473 void SdrUndoDelPage::clearFillBitmap()
1475 if (mxPage->IsMasterPage())
1477 SfxStyleSheet* const pStyleSheet = mxPage->getSdrPageProperties().GetStyleSheet();
1478 assert(bool(pStyleSheet)); // who took away my stylesheet?
1479 if (pStyleSheet->GetListenerCount() == 1)
1481 SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
1482 rItemSet.ClearItem(XATTR_FILLBITMAP);
1483 if (mbHasFillBitmap)
1484 rItemSet.ClearItem(XATTR_FILLSTYLE);
1487 else
1489 SdrPageProperties &rPageProps = mxPage->getSdrPageProperties();
1490 rPageProps.ClearItem(XATTR_FILLBITMAP);
1491 if (mbHasFillBitmap)
1492 rPageProps.ClearItem(XATTR_FILLSTYLE);
1496 void SdrUndoDelPage::restoreFillBitmap()
1498 if (mxPage->IsMasterPage())
1500 SfxStyleSheet* const pStyleSheet = mxPage->getSdrPageProperties().GetStyleSheet();
1501 assert(bool(pStyleSheet)); // who took away my stylesheet?
1502 if (pStyleSheet->GetListenerCount() == 1)
1504 SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
1505 rItemSet.Put(*mpFillBitmapItem);
1506 if (mbHasFillBitmap)
1507 rItemSet.Put(XFillStyleItem(css::drawing::FillStyle_BITMAP));
1510 else
1512 SdrPageProperties &rPageProps = mxPage->getSdrPageProperties();
1513 rPageProps.PutItem(*mpFillBitmapItem);
1514 if (mbHasFillBitmap)
1515 rPageProps.PutItem(XFillStyleItem(css::drawing::FillStyle_BITMAP));
1520 void SdrUndoNewPage::Undo()
1522 ImpRemovePage(nPageNum);
1525 void SdrUndoNewPage::Redo()
1527 ImpInsertPage(nPageNum);
1530 OUString SdrUndoNewPage::GetComment() const
1532 return ImpGetDescriptionStr(STR_UndoNewPage);
1536 OUString SdrUndoCopyPage::GetComment() const
1538 return ImpGetDescriptionStr(STR_UndoCopPage);
1541 OUString SdrUndoCopyPage::GetSdrRepeatComment() const
1543 return ImpGetDescriptionStr(STR_UndoCopPage);
1546 void SdrUndoCopyPage::SdrRepeat(SdrView& /*rView*/)
1551 bool SdrUndoCopyPage::CanSdrRepeat(SdrView& /*rView*/) const
1553 return false;
1557 void SdrUndoSetPageNum::Undo()
1559 ImpMovePage(nNewPageNum,nOldPageNum);
1562 void SdrUndoSetPageNum::Redo()
1564 ImpMovePage(nOldPageNum,nNewPageNum);
1567 OUString SdrUndoSetPageNum::GetComment() const
1569 return ImpGetDescriptionStr(STR_UndoMovPage);
1572 SdrUndoPageMasterPage::SdrUndoPageMasterPage(SdrPage& rChangedPage)
1573 : SdrUndoPage(rChangedPage)
1574 , mbOldHadMasterPage(mxPage->TRG_HasMasterPage())
1575 , maOldMasterPageNumber(0)
1577 // get current state from page
1578 if(mbOldHadMasterPage)
1580 maOldSet = mxPage->TRG_GetMasterPageVisibleLayers();
1581 maOldMasterPageNumber = mxPage->TRG_GetMasterPage().GetPageNum();
1585 SdrUndoPageMasterPage::~SdrUndoPageMasterPage()
1589 SdrUndoPageRemoveMasterPage::SdrUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1590 : SdrUndoPageMasterPage(rChangedPage)
1594 void SdrUndoPageRemoveMasterPage::Undo()
1596 if(mbOldHadMasterPage)
1598 mxPage->TRG_SetMasterPage(*mxPage->getSdrModelFromSdrPage().GetMasterPage(maOldMasterPageNumber));
1599 mxPage->TRG_SetMasterPageVisibleLayers(maOldSet);
1603 void SdrUndoPageRemoveMasterPage::Redo()
1605 mxPage->TRG_ClearMasterPage();
1608 OUString SdrUndoPageRemoveMasterPage::GetComment() const
1610 return ImpGetDescriptionStr(STR_UndoDelPageMasterDscr);
1613 SdrUndoPageChangeMasterPage::SdrUndoPageChangeMasterPage(SdrPage& rChangedPage)
1614 : SdrUndoPageMasterPage(rChangedPage)
1615 , mbNewHadMasterPage(false)
1616 , maNewMasterPageNumber(0)
1620 void SdrUndoPageChangeMasterPage::Undo()
1622 // remember values from new page
1623 if(mxPage->TRG_HasMasterPage())
1625 mbNewHadMasterPage = true;
1626 maNewSet = mxPage->TRG_GetMasterPageVisibleLayers();
1627 maNewMasterPageNumber = mxPage->TRG_GetMasterPage().GetPageNum();
1630 // restore old values
1631 if(mbOldHadMasterPage)
1633 mxPage->TRG_ClearMasterPage();
1634 mxPage->TRG_SetMasterPage(*mxPage->getSdrModelFromSdrPage().GetMasterPage(maOldMasterPageNumber));
1635 mxPage->TRG_SetMasterPageVisibleLayers(maOldSet);
1639 void SdrUndoPageChangeMasterPage::Redo()
1641 // restore new values
1642 if(mbNewHadMasterPage)
1644 mxPage->TRG_ClearMasterPage();
1645 mxPage->TRG_SetMasterPage(*mxPage->getSdrModelFromSdrPage().GetMasterPage(maNewMasterPageNumber));
1646 mxPage->TRG_SetMasterPageVisibleLayers(maNewSet);
1650 OUString SdrUndoPageChangeMasterPage::GetComment() const
1652 return ImpGetDescriptionStr(STR_UndoChgPageMasterDscr);
1656 SdrUndoFactory::~SdrUndoFactory(){}
1658 // shapes
1660 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist )
1662 return std::make_unique<SdrUndoMoveObj>( rObject, rDist );
1665 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoGeoObject( SdrObject& rObject )
1667 return std::make_unique<SdrUndoGeoObj>( rObject );
1670 // Diagram ModelData changes
1671 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDiagramModelData( SdrObject& rObject, std::shared_ptr< svx::diagram::DiagramDataState >& rStartState )
1673 return std::make_unique<SdrUndoDiagramModelData>( rObject, rStartState );
1676 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
1678 return std::make_unique<SdrUndoAttrObj>( rObject, bStyleSheet1, bSaveText );
1681 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoRemoveObject(SdrObject& rObject)
1683 return std::make_unique<SdrUndoRemoveObj>(rObject);
1686 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect )
1688 return std::make_unique<SdrUndoInsertObj>( rObject, bOrdNumDirect );
1691 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
1693 return std::make_unique<SdrUndoDelObj>( rObject, bOrdNumDirect );
1696 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect )
1698 return std::make_unique<SdrUndoNewObj>( rObject, bOrdNumDirect );
1701 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect )
1703 return std::make_unique<SdrUndoCopyObj>( rObject, bOrdNumDirect );
1706 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
1708 return std::make_unique<SdrUndoObjOrdNum>( rObject, nOldOrdNum1, nNewOrdNum1 );
1711 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoSort(SdrPage & rPage, ::std::vector<sal_Int32> const& rSortOrder)
1713 return std::make_unique<SdrUndoSort>(rPage, rSortOrder);
1716 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject )
1718 return std::make_unique<SdrUndoReplaceObj>( rOldObject, rNewObject );
1721 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer )
1723 return std::make_unique<SdrUndoObjectLayerChange>( rObject, aOldLayer, aNewLayer );
1726 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText )
1728 return std::make_unique<SdrUndoObjSetText>( rNewObj, nText );
1731 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectStrAttr( SdrObject& rObject,
1732 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType,
1733 const OUString& sOldStr,
1734 const OUString& sNewStr )
1736 return std::make_unique<SdrUndoObjStrAttr>( rObject, eObjStrAttrType, sOldStr, sNewStr );
1739 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoObjectDecorative(
1740 SdrObject& rObject, bool const WasDecorative)
1742 return std::make_unique<SdrUndoObjDecorative>(rObject, WasDecorative);
1746 // layer
1747 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1749 return std::make_unique<SdrUndoNewLayer>( nLayerNum, rNewLayerAdmin, rNewModel );
1752 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1754 return std::make_unique<SdrUndoDelLayer>( nLayerNum, rNewLayerAdmin, rNewModel );
1757 // page
1758 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoDeletePage(SdrPage& rPage)
1760 return std::make_unique<SdrUndoDelPage>(rPage);
1763 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoNewPage(SdrPage& rPage)
1765 return std::make_unique<SdrUndoNewPage>( rPage );
1768 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoCopyPage(SdrPage& rPage)
1770 return std::make_unique<SdrUndoCopyPage>( rPage );
1773 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1)
1775 return std::make_unique<SdrUndoSetPageNum>( rNewPg, nOldPageNum1, nNewPageNum1 );
1777 // master page
1778 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1780 return std::make_unique<SdrUndoPageRemoveMasterPage>( rChangedPage );
1783 std::unique_ptr<SdrUndoAction> SdrUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage)
1785 return std::make_unique<SdrUndoPageChangeMasterPage>(rChangedPage);
1789 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */