Adjust includes
[LibreOffice.git] / svx / source / svdraw / svdundo.cxx
blob1fd2aca90d1d0cb0c10b987e1c78eeb53c376018
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 <svl/lstner.hxx>
24 #include <svx/svdundo.hxx>
25 #include <svx/svdotext.hxx>
26 #include <svx/svdobj.hxx>
27 #include <svx/svdpage.hxx>
28 #include <svx/svdlayer.hxx>
29 #include <svx/svdmodel.hxx>
30 #include <svx/svdview.hxx>
31 #include <svx/xfillit0.hxx>
32 #include <svx/strings.hrc>
33 #include <svdglob.hxx>
34 #include <svx/scene3d.hxx>
35 #include <editeng/editdata.hxx>
36 #include <editeng/outlobj.hxx>
37 #include <svx/svdogrp.hxx>
38 #include <sdr/properties/itemsettools.hxx>
39 #include <svx/sdr/properties/properties.hxx>
40 #include <svx/svdocapt.hxx>
41 #include <svl/whiter.hxx>
42 #include <svx/e3dsceneupdater.hxx>
43 #include <svx/svdviter.hxx>
44 #include <svx/svdograf.hxx>
45 #include <sdr/contact/viewcontactofgraphic.hxx>
46 #include <svx/svdotable.hxx> // #i124389#
47 #include <vcl/svapp.hxx>
48 #include <sfx2/viewsh.hxx>
51 // iterates over all views and unmarks this SdrObject if it is marked
52 static void ImplUnmarkObject( SdrObject* pObj )
54 SdrViewIter aIter( pObj );
55 for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
57 pView->MarkObj( pObj, pView->GetSdrPageView(), true );
61 SdrUndoAction::SdrUndoAction(SdrModel& rNewMod)
62 : rMod(rNewMod), m_nViewShellId(-1)
64 if (SfxViewShell* pViewShell = SfxViewShell::Current())
65 m_nViewShellId = pViewShell->GetViewShellId();
68 SdrUndoAction::~SdrUndoAction() {}
70 bool SdrUndoAction::CanRepeat(SfxRepeatTarget& rView) const
72 SdrView* pV=dynamic_cast<SdrView*>( &rView );
73 if (pV!=nullptr) return CanSdrRepeat(*pV);
74 return false;
77 void SdrUndoAction::Repeat(SfxRepeatTarget& rView)
79 SdrView* pV=dynamic_cast<SdrView*>( &rView );
80 if (pV!=nullptr) SdrRepeat(*pV);
81 DBG_ASSERT(pV!=nullptr,"Repeat: SfxRepeatTarget that was handed over is not a SdrView");
84 OUString SdrUndoAction::GetRepeatComment(SfxRepeatTarget& rView) const
86 SdrView* pV=dynamic_cast<SdrView*>( &rView );
87 if (pV!=nullptr) return GetSdrRepeatComment(*pV);
88 return OUString();
91 bool SdrUndoAction::CanSdrRepeat(SdrView& /*rView*/) const
93 return false;
96 void SdrUndoAction::SdrRepeat(SdrView& /*rView*/)
100 OUString SdrUndoAction::GetSdrRepeatComment(SdrView& /*rView*/) const
102 return OUString();
105 ViewShellId SdrUndoAction::GetViewShellId() const
107 return m_nViewShellId;
110 SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod)
111 : SdrUndoAction(rNewMod),
112 aBuf(),
113 eFunction(SdrRepeatFunc::NONE)
116 SdrUndoGroup::~SdrUndoGroup()
118 Clear();
121 void SdrUndoGroup::Clear()
123 for (sal_Int32 nu=0; nu<GetActionCount(); nu++) {
124 SdrUndoAction* pAct=GetAction(nu);
125 delete pAct;
127 aBuf.clear();
130 void SdrUndoGroup::AddAction(SdrUndoAction* pAct)
132 aBuf.push_back(pAct);
135 void SdrUndoGroup::Undo()
137 for (sal_Int32 nu=GetActionCount(); nu>0;) {
138 nu--;
139 SdrUndoAction* pAct=GetAction(nu);
140 pAct->Undo();
144 void SdrUndoGroup::Redo()
146 for (sal_Int32 nu=0; nu<GetActionCount(); nu++) {
147 SdrUndoAction* pAct=GetAction(nu);
148 pAct->Redo();
152 OUString SdrUndoGroup::GetComment() const
154 return aComment.replaceAll("%1", aObjDescription);
157 bool SdrUndoGroup::CanSdrRepeat(SdrView& rView) const
159 switch (eFunction)
161 case SdrRepeatFunc::NONE : return false;
162 case SdrRepeatFunc::Delete : return rView.AreObjectsMarked();
163 case SdrRepeatFunc::CombinePolyPoly: return rView.IsCombinePossible();
164 case SdrRepeatFunc::CombineOnePoly : return rView.IsCombinePossible(true);
165 case SdrRepeatFunc::DismantlePolys : return rView.IsDismantlePossible();
166 case SdrRepeatFunc::DismantleLines : return rView.IsDismantlePossible(true);
167 case SdrRepeatFunc::ConvertToPoly : return rView.IsConvertToPolyObjPossible();
168 case SdrRepeatFunc::ConvertToPath : return rView.IsConvertToPathObjPossible();
169 case SdrRepeatFunc::Group : return rView.IsGroupPossible();
170 case SdrRepeatFunc::Ungroup : return rView.IsUnGroupPossible();
171 case SdrRepeatFunc::PutToTop : return rView.IsToTopPossible();
172 case SdrRepeatFunc::PutToBottom : return rView.IsToBtmPossible();
173 case SdrRepeatFunc::MoveToTop : return rView.IsToTopPossible();
174 case SdrRepeatFunc::MoveToBottom : return rView.IsToBtmPossible();
175 case SdrRepeatFunc::ReverseOrder : return rView.IsReverseOrderPossible();
176 case SdrRepeatFunc::ImportMtf : return rView.IsImportMtfPossible();
177 default: break;
178 } // switch
179 return false;
182 void SdrUndoGroup::SdrRepeat(SdrView& rView)
184 switch (eFunction)
186 case SdrRepeatFunc::NONE : break;
187 case SdrRepeatFunc::Delete : rView.DeleteMarked(); break;
188 case SdrRepeatFunc::CombinePolyPoly : rView.CombineMarkedObjects(false); break;
189 case SdrRepeatFunc::CombineOnePoly : rView.CombineMarkedObjects(); break;
190 case SdrRepeatFunc::DismantlePolys : rView.DismantleMarkedObjects(); break;
191 case SdrRepeatFunc::DismantleLines : rView.DismantleMarkedObjects(true); break;
192 case SdrRepeatFunc::ConvertToPoly : rView.ConvertMarkedToPolyObj(); break;
193 case SdrRepeatFunc::ConvertToPath : rView.ConvertMarkedToPathObj(false); break;
194 case SdrRepeatFunc::Group : rView.GroupMarked(); break;
195 case SdrRepeatFunc::Ungroup : rView.UnGroupMarked(); break;
196 case SdrRepeatFunc::PutToTop : rView.PutMarkedToTop(); break;
197 case SdrRepeatFunc::PutToBottom : rView.PutMarkedToBtm(); break;
198 case SdrRepeatFunc::MoveToTop : rView.MovMarkedToTop(); break;
199 case SdrRepeatFunc::MoveToBottom : rView.MovMarkedToBtm(); break;
200 case SdrRepeatFunc::ReverseOrder : rView.ReverseOrderOfMarked(); break;
201 case SdrRepeatFunc::ImportMtf : rView.DoImportMarkedMtf(); break;
202 default: break;
203 } // switch
206 OUString SdrUndoGroup::GetSdrRepeatComment(SdrView& /*rView*/) const
208 return aComment.replaceAll("%1", ImpGetResStr(STR_ObjNameSingulPlural));
211 SdrUndoObj::SdrUndoObj(SdrObject& rNewObj)
212 : SdrUndoAction(*rNewObj.GetModel())
213 , pObj(&rNewObj)
217 OUString SdrUndoObj::GetDescriptionStringForObject( const SdrObject& _rForObject, const char* pStrCacheID, bool bRepeat )
219 const OUString rStr {ImpGetResStr(pStrCacheID)};
221 const sal_Int32 nPos = rStr.indexOf("%1");
222 if (nPos < 0)
223 return rStr;
225 if (bRepeat)
226 return rStr.replaceAt(nPos, 2, ImpGetResStr(STR_ObjNameSingulPlural));
228 return rStr.replaceAt(nPos, 2, _rForObject.TakeObjNameSingul());
231 void SdrUndoObj::ImpTakeDescriptionStr(const char* pStrCacheID, OUString& rStr, bool bRepeat) const
233 if ( pObj )
234 rStr = GetDescriptionStringForObject( *pObj, pStrCacheID, bRepeat );
237 // common call method for possible change of the page when UNDO/REDO is triggered
238 void SdrUndoObj::ImpShowPageOfThisObject()
240 if(pObj && pObj->IsInserted() && pObj->GetPage() && pObj->GetModel())
242 SdrHint aHint(SdrHintKind::SwitchToPage, *pObj, pObj->GetPage());
243 pObj->GetModel()->Broadcast(aHint);
247 void SdrUndoAttrObj::ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool& rStyleSheetPool, SfxStyleSheet& rSheet)
249 SfxStyleSheetBase* pThere = rStyleSheetPool.Find(rSheet.GetName(), rSheet.GetFamily());
251 if(!pThere)
253 // re-insert remembered style which was removed in the meantime. To do this
254 // without assertion, do it without parent and set parent after insertion
255 const OUString aParent(rSheet.GetParent());
257 rSheet.SetParent(OUString());
258 rStyleSheetPool.Insert(&rSheet);
259 rSheet.SetParent(aParent);
263 SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSaveText)
264 : SdrUndoObj(rNewObj)
265 , pUndoSet(nullptr)
266 , pRedoSet(nullptr)
267 , mxUndoStyleSheet()
268 , mxRedoStyleSheet()
269 , bHaveToTakeRedoSet(true)
270 , pTextUndo(nullptr)
271 , pTextRedo(nullptr)
272 , pUndoGroup(nullptr)
274 bStyleSheet = bStyleSheet1;
276 SdrObjList* pOL = rNewObj.GetSubList();
277 bool bIsGroup(pOL!=nullptr && pOL->GetObjCount());
278 bool bIs3DScene(bIsGroup && dynamic_cast< E3dScene* >(pObj) != nullptr);
280 if(bIsGroup)
282 // it's a group object!
283 pUndoGroup = new SdrUndoGroup(*pObj->GetModel());
284 const size_t nObjCount(pOL->GetObjCount());
286 for(size_t nObjNum = 0; nObjNum < nObjCount; ++nObjNum)
288 pUndoGroup->AddAction(
289 new SdrUndoAttrObj(*pOL->GetObj(nObjNum), bStyleSheet1));
293 if(!bIsGroup || bIs3DScene)
295 pUndoSet = new SfxItemSet(pObj->GetMergedItemSet());
297 if(bStyleSheet)
298 mxUndoStyleSheet = pObj->GetStyleSheet();
300 if(bSaveText)
302 pTextUndo = pObj->GetOutlinerParaObject();
303 if(pTextUndo)
304 pTextUndo = new OutlinerParaObject(*pTextUndo);
309 SdrUndoAttrObj::~SdrUndoAttrObj()
311 delete pUndoSet;
312 delete pRedoSet;
313 delete pUndoGroup;
314 delete pTextUndo;
315 delete pTextRedo;
318 void SdrUndoAttrObj::Undo()
320 E3DModifySceneSnapRectUpdater aUpdater(pObj);
321 bool bIs3DScene(dynamic_cast< E3dScene* >(pObj) != nullptr);
323 // Trigger PageChangeCall
324 ImpShowPageOfThisObject();
326 if(!pUndoGroup || bIs3DScene)
328 if(bHaveToTakeRedoSet)
330 bHaveToTakeRedoSet = false;
332 delete pRedoSet;
334 pRedoSet = new SfxItemSet(pObj->GetMergedItemSet());
336 if(bStyleSheet)
337 mxRedoStyleSheet = pObj->GetStyleSheet();
339 if(pTextUndo)
341 // #i8508#
342 pTextRedo = pObj->GetOutlinerParaObject();
344 if(pTextRedo)
345 pTextRedo = new OutlinerParaObject(*pTextRedo);
349 if(bStyleSheet)
351 mxRedoStyleSheet = pObj->GetStyleSheet();
352 SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxUndoStyleSheet.get());
354 if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
356 ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
357 pObj->SetStyleSheet(pSheet, true);
359 else
361 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
365 sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
367 // Since ClearItem sets back everything to normal
368 // it also sets fit-to-size text to non-fit-to-size text and
369 // switches on autogrowheight (the default). That may lead to
370 // losing the geometry size info for the object when it is
371 // laid out again from AdjustTextFrameWidthAndHeight(). This makes
372 // rescuing the size of the object necessary.
373 const tools::Rectangle aSnapRect = pObj->GetSnapRect();
375 if(pUndoSet)
377 if(dynamic_cast<const SdrCaptionObj*>( pObj) != nullptr)
379 // do a more smooth item deletion here, else the text
380 // rect will be reformatted, especially when information regarding
381 // vertical text is changed. When clearing only set items it's
382 // slower, but safer regarding such information (it's not changed
383 // usually)
384 SfxWhichIter aIter(*pUndoSet);
385 sal_uInt16 nWhich(aIter.FirstWhich());
387 while(nWhich)
389 if(SfxItemState::SET != pUndoSet->GetItemState(nWhich, false))
391 pObj->ClearMergedItem(nWhich);
394 nWhich = aIter.NextWhich();
397 else
399 pObj->ClearMergedItem();
402 pObj->SetMergedItemSet(*pUndoSet);
405 // Restore previous size here when it was changed.
406 if(aSnapRect != pObj->GetSnapRect())
408 pObj->NbcSetSnapRect(aSnapRect);
411 pObj->GetProperties().BroadcastItemChange(aItemChange);
413 if(pTextUndo)
415 pObj->SetOutlinerParaObject(new OutlinerParaObject(*pTextUndo));
419 if(pUndoGroup)
421 pUndoGroup->Undo();
425 void SdrUndoAttrObj::Redo()
427 E3DModifySceneSnapRectUpdater aUpdater(pObj);
428 bool bIs3DScene(dynamic_cast< E3dScene* >(pObj) != nullptr);
430 if(!pUndoGroup || bIs3DScene)
432 if(bStyleSheet)
434 mxUndoStyleSheet = pObj->GetStyleSheet();
435 SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxRedoStyleSheet.get());
437 if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
439 ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
440 pObj->SetStyleSheet(pSheet, true);
442 else
444 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
448 sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
450 const tools::Rectangle aSnapRect = pObj->GetSnapRect();
452 if(pRedoSet)
454 if(dynamic_cast<const SdrCaptionObj*>( pObj) != nullptr)
456 // do a more smooth item deletion here, else the text
457 // rect will be reformatted, especially when information regarding
458 // vertical text is changed. When clearing only set items it's
459 // slower, but safer regarding such information (it's not changed
460 // usually)
461 SfxWhichIter aIter(*pRedoSet);
462 sal_uInt16 nWhich(aIter.FirstWhich());
464 while(nWhich)
466 if(SfxItemState::SET != pRedoSet->GetItemState(nWhich, false))
468 pObj->ClearMergedItem(nWhich);
471 nWhich = aIter.NextWhich();
474 else
476 pObj->ClearMergedItem();
479 pObj->SetMergedItemSet(*pRedoSet);
482 // Restore previous size here when it was changed.
483 if(aSnapRect != pObj->GetSnapRect())
485 pObj->NbcSetSnapRect(aSnapRect);
488 pObj->GetProperties().BroadcastItemChange(aItemChange);
490 // #i8508#
491 if(pTextRedo)
493 pObj->SetOutlinerParaObject(new OutlinerParaObject(*pTextRedo));
497 if(pUndoGroup)
499 pUndoGroup->Redo();
502 // Trigger PageChangeCall
503 ImpShowPageOfThisObject();
506 OUString SdrUndoAttrObj::GetComment() const
508 OUString aStr;
510 if(bStyleSheet)
512 ImpTakeDescriptionStr(STR_EditSetStylesheet, aStr);
514 else
516 ImpTakeDescriptionStr(STR_EditSetAttributes, aStr);
519 return aStr;
522 OUString SdrUndoAttrObj::GetSdrRepeatComment(SdrView& /*rView*/) const
524 OUString aStr;
526 if(bStyleSheet)
528 ImpTakeDescriptionStr(STR_EditSetStylesheet, aStr, true);
530 else
532 ImpTakeDescriptionStr(STR_EditSetAttributes, aStr, true);
535 return aStr;
539 SdrUndoMoveObj::~SdrUndoMoveObj() {}
541 void SdrUndoMoveObj::Undo()
543 // Trigger PageChangeCall
544 ImpShowPageOfThisObject();
546 pObj->Move(Size(-aDistance.Width(),-aDistance.Height()));
549 void SdrUndoMoveObj::Redo()
551 pObj->Move(Size(aDistance.Width(),aDistance.Height()));
553 // Trigger PageChangeCall
554 ImpShowPageOfThisObject();
557 OUString SdrUndoMoveObj::GetComment() const
559 OUString aStr;
560 ImpTakeDescriptionStr(STR_EditMove,aStr);
561 return aStr;
564 void SdrUndoMoveObj::SdrRepeat(SdrView& rView)
566 rView.MoveMarkedObj(aDistance);
569 bool SdrUndoMoveObj::CanSdrRepeat(SdrView& rView) const
571 return rView.AreObjectsMarked();
574 OUString SdrUndoMoveObj::GetSdrRepeatComment(SdrView& /*rView*/) const
576 OUString aStr;
577 ImpTakeDescriptionStr(STR_EditMove,aStr,true);
578 return aStr;
582 SdrUndoGeoObj::SdrUndoGeoObj(SdrObject& rNewObj)
583 : SdrUndoObj(rNewObj)
584 , pUndoGeo(nullptr)
585 , pRedoGeo(nullptr)
586 , pUndoGroup(nullptr)
587 , mbSkipChangeLayout(false)
589 SdrObjList* pOL=rNewObj.GetSubList();
590 if (pOL!=nullptr && pOL->GetObjCount() && dynamic_cast<const E3dScene* >( &rNewObj) == nullptr)
592 // this is a group object!
593 // If this were 3D scene, we'd only add an Undo for the scene itself
594 // (which we do elsewhere).
595 pUndoGroup=new SdrUndoGroup(*pObj->GetModel());
596 const size_t nObjCount = pOL->GetObjCount();
597 for (size_t nObjNum = 0; nObjNum<nObjCount; ++nObjNum) {
598 pUndoGroup->AddAction(new SdrUndoGeoObj(*pOL->GetObj(nObjNum)));
601 else
603 pUndoGeo=pObj->GetGeoData();
607 SdrUndoGeoObj::~SdrUndoGeoObj()
609 delete pUndoGeo;
610 delete pRedoGeo;
611 delete pUndoGroup;
614 void SdrUndoGeoObj::Undo()
616 // Trigger PageChangeCall
617 ImpShowPageOfThisObject();
619 if(pUndoGroup)
621 pUndoGroup->Undo();
623 // only repaint, no objectchange
624 pObj->ActionChanged();
626 else
628 delete pRedoGeo;
629 pRedoGeo=pObj->GetGeoData();
631 auto pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(pObj);
632 if (pTableObj && mbSkipChangeLayout)
633 pTableObj->SetSkipChangeLayout(true);
634 pObj->SetGeoData(*pUndoGeo);
635 if (pTableObj && mbSkipChangeLayout)
636 pTableObj->SetSkipChangeLayout(false);
640 void SdrUndoGeoObj::Redo()
642 if(pUndoGroup)
644 pUndoGroup->Redo();
646 // only repaint, no objectchange
647 pObj->ActionChanged();
649 else
651 delete pUndoGeo;
652 pUndoGeo=pObj->GetGeoData();
653 pObj->SetGeoData(*pRedoGeo);
656 // Trigger PageChangeCall
657 ImpShowPageOfThisObject();
660 OUString SdrUndoGeoObj::GetComment() const
662 OUString aStr;
663 ImpTakeDescriptionStr(STR_DragMethObjOwn,aStr);
664 return aStr;
668 SdrUndoObjList::SdrUndoObjList(SdrObject& rNewObj, bool bOrdNumDirect)
669 : SdrUndoObj(rNewObj)
670 , bOwner(false)
672 pObjList=pObj->GetObjList();
673 if (bOrdNumDirect)
675 nOrdNum=pObj->GetOrdNumDirect();
677 else
679 nOrdNum=pObj->GetOrdNum();
683 SdrUndoObjList::~SdrUndoObjList()
685 SolarMutexGuard aGuard;
687 if (pObj!=nullptr && IsOwner())
689 // Attribute have to go back to the regular Pool
690 SetOwner(false);
692 // now delete
693 SdrObject::Free( pObj );
697 void SdrUndoObjList::SetOwner(bool bNew)
699 bOwner = bNew;
703 void SdrUndoRemoveObj::Undo()
705 // Trigger PageChangeCall
706 ImpShowPageOfThisObject();
708 DBG_ASSERT(!pObj->IsInserted(),"UndoRemoveObj: pObj has already been inserted.");
709 if (!pObj->IsInserted())
711 // #i11426#
712 // For UNDOs in Calc/Writer it is necessary to adapt the anchor
713 // position of the target object.
714 Point aOwnerAnchorPos(0, 0);
716 if (dynamic_cast<const SdrObjGroup*>(pObjList->GetOwnerObj()) != nullptr)
718 aOwnerAnchorPos = pObjList->GetOwnerObj()->GetAnchorPos();
721 E3DModifySceneSnapRectUpdater aUpdater(pObjList->GetOwnerObj());
722 pObjList->InsertObject(pObj,nOrdNum);
724 // #i11426#
725 if(aOwnerAnchorPos.X() || aOwnerAnchorPos.Y())
727 pObj->NbcSetAnchorPos(aOwnerAnchorPos);
732 void SdrUndoRemoveObj::Redo()
734 DBG_ASSERT(pObj->IsInserted(),"RedoRemoveObj: pObj is not inserted.");
735 if (pObj->IsInserted())
737 ImplUnmarkObject( pObj );
738 E3DModifySceneSnapRectUpdater aUpdater(pObj);
739 pObjList->RemoveObject(nOrdNum);
742 // Trigger PageChangeCall
743 ImpShowPageOfThisObject();
746 SdrUndoRemoveObj::~SdrUndoRemoveObj()
751 void SdrUndoInsertObj::Undo()
753 // Trigger PageChangeCall
754 ImpShowPageOfThisObject();
756 DBG_ASSERT(pObj->IsInserted(),"UndoInsertObj: pObj is not inserted.");
757 if (pObj->IsInserted())
759 ImplUnmarkObject( pObj );
761 SdrObject* pChkObj= pObjList->RemoveObject(nOrdNum);
762 DBG_ASSERT(pChkObj==pObj,"UndoInsertObj: RemoveObjNum!=pObj");
766 void SdrUndoInsertObj::Redo()
768 DBG_ASSERT(!pObj->IsInserted(),"RedoInsertObj: pObj is already inserted");
769 if (!pObj->IsInserted())
771 // Restore anchor position of an object,
772 // which becomes a member of a group, because its cleared in method
773 // <InsertObject(..)>. Needed for correct Redo in Writer. (#i45952#)
774 Point aAnchorPos( 0, 0 );
775 if (dynamic_cast<const SdrObjGroup*>(pObjList->GetOwnerObj()) != nullptr)
777 aAnchorPos = pObj->GetAnchorPos();
780 pObjList->InsertObject(pObj,nOrdNum);
782 // Arcs lose position when grouped (#i45952#)
783 if ( aAnchorPos.X() || aAnchorPos.Y() )
785 pObj->NbcSetAnchorPos( aAnchorPos );
789 // Trigger PageChangeCall
790 ImpShowPageOfThisObject();
793 SdrUndoDelObj::SdrUndoDelObj(SdrObject& rNewObj, bool bOrdNumDirect)
794 : SdrUndoRemoveObj(rNewObj,bOrdNumDirect)
796 SetOwner(true);
799 void SdrUndoDelObj::Undo()
801 SdrUndoRemoveObj::Undo();
802 DBG_ASSERT(IsOwner(),"UndoDeleteObj: pObj does not belong to UndoAction");
803 SetOwner(false);
806 void SdrUndoDelObj::Redo()
808 SdrUndoRemoveObj::Redo();
809 DBG_ASSERT(!IsOwner(),"RedoDeleteObj: pObj already belongs to UndoAction");
810 SetOwner(true);
813 OUString SdrUndoDelObj::GetComment() const
815 OUString aStr;
816 ImpTakeDescriptionStr(STR_EditDelete,aStr);
817 return aStr;
820 void SdrUndoDelObj::SdrRepeat(SdrView& rView)
822 rView.DeleteMarked();
825 bool SdrUndoDelObj::CanSdrRepeat(SdrView& rView) const
827 return rView.AreObjectsMarked();
830 OUString SdrUndoDelObj::GetSdrRepeatComment(SdrView& /*rView*/) const
832 OUString aStr;
833 ImpTakeDescriptionStr(STR_EditDelete,aStr,true);
834 return aStr;
838 void SdrUndoNewObj::Undo()
840 SdrUndoInsertObj::Undo();
841 DBG_ASSERT(!IsOwner(),"RedoNewObj: pObj already belongs to UndoAction");
842 SetOwner(true);
845 void SdrUndoNewObj::Redo()
847 SdrUndoInsertObj::Redo();
848 DBG_ASSERT(IsOwner(),"RedoNewObj: pObj does not belong to UndoAction");
849 SetOwner(false);
852 OUString SdrUndoNewObj::GetComment( const SdrObject& _rForObject )
854 return GetDescriptionStringForObject( _rForObject, STR_UndoInsertObj );
857 OUString SdrUndoNewObj::GetComment() const
859 OUString aStr;
860 ImpTakeDescriptionStr(STR_UndoInsertObj,aStr);
861 return aStr;
864 SdrUndoReplaceObj::SdrUndoReplaceObj(SdrObject& rOldObj1, SdrObject& rNewObj1, bool bOrdNumDirect)
865 : SdrUndoObj(rOldObj1)
866 , bOldOwner(false)
867 , bNewOwner(false)
868 , pNewObj(&rNewObj1)
870 SetOldOwner(true);
872 pObjList=pObj->GetObjList();
873 if (bOrdNumDirect)
875 nOrdNum=pObj->GetOrdNumDirect();
877 else
879 nOrdNum=pObj->GetOrdNum();
883 SdrUndoReplaceObj::~SdrUndoReplaceObj()
885 if (pObj!=nullptr && IsOldOwner())
887 // Attribute have to go back into the Pool
888 SetOldOwner(false);
890 // now delete
891 SdrObject::Free( pObj );
893 if (pNewObj!=nullptr && IsNewOwner())
895 // Attribute have to go back into the Pool
896 SetNewOwner(false);
898 // now delete
899 SdrObject::Free( pNewObj );
903 void SdrUndoReplaceObj::Undo()
905 // Trigger PageChangeCall
906 ImpShowPageOfThisObject();
908 if (IsOldOwner() && !IsNewOwner())
910 DBG_ASSERT(!pObj->IsInserted(),"SdrUndoReplaceObj::Undo(): Old object is already inserted!");
911 DBG_ASSERT(pNewObj->IsInserted(),"SdrUndoReplaceObj::Undo(): New object is not inserted!");
912 SetOldOwner(false);
913 SetNewOwner(true);
915 ImplUnmarkObject( pNewObj );
916 pObjList->ReplaceObject(pObj,nOrdNum);
918 else
920 OSL_FAIL("SdrUndoReplaceObj::Undo(): Wrong IsMine flags. Did you call Undo twice?");
924 void SdrUndoReplaceObj::Redo()
926 if (!IsOldOwner() && IsNewOwner())
928 DBG_ASSERT(!pNewObj->IsInserted(),"SdrUndoReplaceObj::Redo(): New object is already inserted!!");
929 DBG_ASSERT(pObj->IsInserted(),"SdrUndoReplaceObj::Redo(): Old object is not inserted!!");
930 SetOldOwner(true);
931 SetNewOwner(false);
933 ImplUnmarkObject( pObj );
934 pObjList->ReplaceObject(pNewObj,nOrdNum);
937 else
939 OSL_FAIL("SdrUndoReplaceObj::Redo(): Wrong IsMine flags. Did you call Redo twice?");
942 // Trigger PageChangeCall
943 ImpShowPageOfThisObject();
946 void SdrUndoReplaceObj::SetNewOwner(bool bNew)
948 bNewOwner = bNew;
951 void SdrUndoReplaceObj::SetOldOwner(bool bNew)
953 bOldOwner = bNew;
957 OUString SdrUndoCopyObj::GetComment() const
959 OUString aStr;
960 ImpTakeDescriptionStr(STR_UndoCopyObj,aStr);
961 return aStr;
965 // #i11702#
967 SdrUndoObjectLayerChange::SdrUndoObjectLayerChange(SdrObject& rObj, SdrLayerID aOldLayer, SdrLayerID aNewLayer)
968 : SdrUndoObj(rObj)
969 , maOldLayer(aOldLayer)
970 , maNewLayer(aNewLayer)
974 void SdrUndoObjectLayerChange::Undo()
976 ImpShowPageOfThisObject();
977 pObj->SetLayer(maOldLayer);
980 void SdrUndoObjectLayerChange::Redo()
982 pObj->SetLayer(maNewLayer);
983 ImpShowPageOfThisObject();
987 SdrUndoObjOrdNum::SdrUndoObjOrdNum(SdrObject& rNewObj, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
988 : SdrUndoObj(rNewObj)
989 , nOldOrdNum(nOldOrdNum1)
990 , nNewOrdNum(nNewOrdNum1)
994 void SdrUndoObjOrdNum::Undo()
996 // Trigger PageChangeCall
997 ImpShowPageOfThisObject();
999 SdrObjList* pOL=pObj->GetObjList();
1000 if (pOL==nullptr)
1002 OSL_FAIL("UndoObjOrdNum: pObj does not have an ObjList.");
1003 return;
1005 pOL->SetObjectOrdNum(nNewOrdNum,nOldOrdNum);
1008 void SdrUndoObjOrdNum::Redo()
1010 SdrObjList* pOL=pObj->GetObjList();
1011 if (pOL==nullptr)
1013 OSL_FAIL("RedoObjOrdNum: pObj does not have an ObjList.");
1014 return;
1016 pOL->SetObjectOrdNum(nOldOrdNum,nNewOrdNum);
1018 // Trigger PageChangeCall
1019 ImpShowPageOfThisObject();
1022 OUString SdrUndoObjOrdNum::GetComment() const
1024 OUString aStr;
1025 ImpTakeDescriptionStr(STR_UndoObjOrdNum,aStr);
1026 return aStr;
1030 SdrUndoObjSetText::SdrUndoObjSetText(SdrObject& rNewObj, sal_Int32 nText)
1031 : SdrUndoObj(rNewObj)
1032 , pOldText(nullptr)
1033 , pNewText(nullptr)
1034 , bNewTextAvailable(false)
1035 , bEmptyPresObj(false)
1036 , mnText(nText)
1038 SdrText* pText = static_cast< SdrTextObj*>( &rNewObj )->getText(mnText);
1039 if( pText && pText->GetOutlinerParaObject() )
1040 pOldText = new OutlinerParaObject(*pText->GetOutlinerParaObject());
1042 bEmptyPresObj = rNewObj.IsEmptyPresObj();
1045 SdrUndoObjSetText::~SdrUndoObjSetText()
1047 delete pOldText;
1048 delete pNewText;
1051 void SdrUndoObjSetText::AfterSetText()
1053 if (!bNewTextAvailable)
1055 SdrText* pText = static_cast< SdrTextObj*>( pObj )->getText(mnText);
1056 if( pText && pText->GetOutlinerParaObject() )
1057 pNewText = new OutlinerParaObject(*pText->GetOutlinerParaObject());
1058 bNewTextAvailable=true;
1062 void SdrUndoObjSetText::Undo()
1064 // only works with SdrTextObj
1065 SdrTextObj* pTarget = dynamic_cast< SdrTextObj* >(pObj);
1067 if(!pTarget)
1069 OSL_ENSURE(false, "SdrUndoObjSetText::Undo with SdrObject not based on SdrTextObj (!)");
1070 return;
1073 // Trigger PageChangeCall
1074 ImpShowPageOfThisObject();
1076 // save old text for Redo
1077 if(!bNewTextAvailable)
1079 AfterSetText();
1082 SdrText* pText = pTarget->getText(mnText);
1083 if (pText)
1085 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1086 OutlinerParaObject* pText1 = pOldText ? new OutlinerParaObject(*pOldText) : nullptr;
1087 pText->SetOutlinerParaObject(pText1);
1088 pTarget->NbcSetOutlinerParaObjectForText(pText1, pText);
1091 pTarget->SetEmptyPresObj(bEmptyPresObj);
1092 pTarget->ActionChanged();
1094 // #i124389# if it's a table, also need to relayout TextFrame
1095 if(dynamic_cast< sdr::table::SdrTableObj* >(pTarget) != nullptr)
1097 pTarget->NbcAdjustTextFrameWidthAndHeight();
1100 // #i122410# SetOutlinerParaObject at SdrText does not trigger a
1101 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1102 // update their preview.
1103 pTarget->BroadcastObjectChange();
1106 void SdrUndoObjSetText::Redo()
1108 // only works with SdrTextObj
1109 SdrTextObj* pTarget = dynamic_cast< SdrTextObj* >(pObj);
1111 if(!pTarget)
1113 OSL_ENSURE(false, "SdrUndoObjSetText::Redo with SdrObject not based on SdrTextObj (!)");
1114 return;
1117 SdrText* pText = pTarget->getText(mnText);
1118 if (pText)
1120 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1121 OutlinerParaObject* pText1 = pNewText ? new OutlinerParaObject(*pNewText) : nullptr;
1122 pTarget->NbcSetOutlinerParaObjectForText( pText1, pText );
1125 pTarget->ActionChanged();
1127 // #i124389# if it's a table, also need to relayout TextFrame
1128 if(dynamic_cast< sdr::table::SdrTableObj* >(pTarget) != nullptr)
1130 pTarget->NbcAdjustTextFrameWidthAndHeight();
1133 // #i122410# NbcSetOutlinerParaObjectForText at SdrTextObj does not trigger a
1134 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1135 // update their preview.
1136 pTarget->BroadcastObjectChange();
1138 // Trigger PageChangeCall
1139 ImpShowPageOfThisObject();
1142 OUString SdrUndoObjSetText::GetComment() const
1144 OUString aStr;
1145 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1146 return aStr;
1149 OUString SdrUndoObjSetText::GetSdrRepeatComment(SdrView& /*rView*/) const
1151 OUString aStr;
1152 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1153 return aStr;
1156 void SdrUndoObjSetText::SdrRepeat(SdrView& rView)
1158 if (bNewTextAvailable && rView.AreObjectsMarked())
1160 const SdrMarkList& rML=rView.GetMarkedObjectList();
1162 const bool bUndo = rView.IsUndoEnabled();
1163 if( bUndo )
1165 OUString aStr;
1166 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1167 rView.BegUndo(aStr);
1170 const size_t nCount=rML.GetMarkCount();
1171 for (size_t nm=0; nm<nCount; ++nm)
1173 SdrObject* pObj2=rML.GetMark(nm)->GetMarkedSdrObj();
1174 SdrTextObj* pTextObj=dynamic_cast<SdrTextObj*>( pObj2 );
1175 if (pTextObj!=nullptr)
1177 if( bUndo )
1178 rView.AddUndo(new SdrUndoObjSetText(*pTextObj,0));
1180 OutlinerParaObject* pText1=pNewText;
1181 if (pText1!=nullptr)
1182 pText1 = new OutlinerParaObject(*pText1);
1183 pTextObj->SetOutlinerParaObject(pText1);
1187 if( bUndo )
1188 rView.EndUndo();
1192 bool SdrUndoObjSetText::CanSdrRepeat(SdrView& rView) const
1194 bool bOk = false;
1195 if (bNewTextAvailable && rView.AreObjectsMarked()) {
1196 bOk=true;
1198 return bOk;
1201 // Undo/Redo for setting object's name (#i73249#)
1202 SdrUndoObjStrAttr::SdrUndoObjStrAttr( SdrObject& rNewObj,
1203 const ObjStrAttrType eObjStrAttr,
1204 const OUString& sOldStr,
1205 const OUString& sNewStr)
1206 : SdrUndoObj( rNewObj )
1207 , meObjStrAttr( eObjStrAttr )
1208 , msOldStr( sOldStr )
1209 , msNewStr( sNewStr )
1213 void SdrUndoObjStrAttr::Undo()
1215 ImpShowPageOfThisObject();
1217 switch ( meObjStrAttr )
1219 case ObjStrAttrType::Name:
1220 pObj->SetName( msOldStr );
1221 break;
1222 case ObjStrAttrType::Title:
1223 pObj->SetTitle( msOldStr );
1224 break;
1225 case ObjStrAttrType::Description:
1226 pObj->SetDescription( msOldStr );
1227 break;
1231 void SdrUndoObjStrAttr::Redo()
1233 switch ( meObjStrAttr )
1235 case ObjStrAttrType::Name:
1236 pObj->SetName( msNewStr );
1237 break;
1238 case ObjStrAttrType::Title:
1239 pObj->SetTitle( msNewStr );
1240 break;
1241 case ObjStrAttrType::Description:
1242 pObj->SetDescription( msNewStr );
1243 break;
1246 ImpShowPageOfThisObject();
1249 OUString SdrUndoObjStrAttr::GetComment() const
1251 OUString aStr;
1252 switch ( meObjStrAttr )
1254 case ObjStrAttrType::Name:
1255 ImpTakeDescriptionStr( STR_UndoObjName, aStr );
1256 aStr += " '" + msNewStr + "'";
1257 break;
1258 case ObjStrAttrType::Title:
1259 ImpTakeDescriptionStr( STR_UndoObjTitle, aStr );
1260 break;
1261 case ObjStrAttrType::Description:
1262 ImpTakeDescriptionStr( STR_UndoObjDescription, aStr );
1263 break;
1266 return aStr;
1270 SdrUndoLayer::SdrUndoLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1271 : SdrUndoAction(rNewModel)
1272 , pLayer(rNewLayerAdmin.GetLayer(nLayerNum))
1273 , pLayerAdmin(&rNewLayerAdmin)
1274 , nNum(nLayerNum)
1275 , bItsMine(false)
1279 SdrUndoLayer::~SdrUndoLayer()
1281 if (bItsMine)
1283 delete pLayer;
1288 void SdrUndoNewLayer::Undo()
1290 DBG_ASSERT(!bItsMine,"SdrUndoNewLayer::Undo(): Layer already belongs to UndoAction.");
1291 bItsMine=true;
1292 SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum);
1293 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoNewLayer::Undo(): Removed layer is != pLayer.");
1296 void SdrUndoNewLayer::Redo()
1298 DBG_ASSERT(bItsMine,"SdrUndoNewLayer::Undo(): Layer does not belong to UndoAction.");
1299 bItsMine=false;
1300 pLayerAdmin->InsertLayer(pLayer,nNum);
1303 OUString SdrUndoNewLayer::GetComment() const
1305 return ImpGetResStr(STR_UndoNewLayer);
1309 void SdrUndoDelLayer::Undo()
1311 DBG_ASSERT(bItsMine,"SdrUndoDelLayer::Undo(): Layer does not belong to UndoAction.");
1312 bItsMine=false;
1313 pLayerAdmin->InsertLayer(pLayer,nNum);
1316 void SdrUndoDelLayer::Redo()
1318 DBG_ASSERT(!bItsMine,"SdrUndoDelLayer::Undo(): Layer already belongs to UndoAction.");
1319 bItsMine=true;
1320 SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum);
1321 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoDelLayer::Redo(): Removed layer is != pLayer.");
1324 OUString SdrUndoDelLayer::GetComment() const
1326 return ImpGetResStr(STR_UndoDelLayer);
1330 void SdrUndoMoveLayer::Undo()
1332 SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNewPos);
1333 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoMoveLayer::Undo(): Removed layer is != pLayer.");
1334 pLayerAdmin->InsertLayer(pLayer,nNum);
1337 void SdrUndoMoveLayer::Redo()
1339 SdrLayer* pCmpLayer= pLayerAdmin->RemoveLayer(nNum);
1340 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoMoveLayer::Redo(): Removed layer is != pLayer.");
1341 pLayerAdmin->InsertLayer(pLayer,nNewPos);
1344 OUString SdrUndoMoveLayer::GetComment() const
1346 return ImpGetResStr(STR_UndoMovLayer);
1350 SdrUndoPage::SdrUndoPage(SdrPage& rNewPg)
1351 : SdrUndoAction(*rNewPg.GetModel())
1352 , mrPage(rNewPg)
1356 void SdrUndoPage::ImpInsertPage(sal_uInt16 nNum)
1358 DBG_ASSERT(!mrPage.IsInserted(),"SdrUndoPage::ImpInsertPage(): mrPage is already inserted.");
1359 if (!mrPage.IsInserted())
1361 if (mrPage.IsMasterPage())
1363 rMod.InsertMasterPage(&mrPage,nNum);
1365 else
1367 rMod.InsertPage(&mrPage,nNum);
1372 void SdrUndoPage::ImpRemovePage(sal_uInt16 nNum)
1374 DBG_ASSERT(mrPage.IsInserted(),"SdrUndoPage::ImpRemovePage(): mrPage is not inserted.");
1375 if (mrPage.IsInserted())
1377 SdrPage* pChkPg=nullptr;
1378 if (mrPage.IsMasterPage())
1380 pChkPg=rMod.RemoveMasterPage(nNum);
1382 else
1384 pChkPg=rMod.RemovePage(nNum);
1386 DBG_ASSERT(pChkPg==&mrPage,"SdrUndoPage::ImpRemovePage(): RemovePage!=&mrPage");
1390 void SdrUndoPage::ImpMovePage(sal_uInt16 nOldNum, sal_uInt16 nNewNum)
1392 DBG_ASSERT(mrPage.IsInserted(),"SdrUndoPage::ImpMovePage(): mrPage is not inserted.");
1393 if (mrPage.IsInserted())
1395 if (mrPage.IsMasterPage())
1397 rMod.MoveMasterPage(nOldNum,nNewNum);
1399 else
1401 rMod.MovePage(nOldNum,nNewNum);
1406 void SdrUndoPage::ImpTakeDescriptionStr(const char* pStrCacheID, OUString& rStr)
1408 rStr = ImpGetResStr(pStrCacheID);
1412 SdrUndoPageList::SdrUndoPageList(SdrPage& rNewPg)
1413 : SdrUndoPage(rNewPg)
1414 , bItsMine(false)
1416 nPageNum=rNewPg.GetPageNum();
1419 SdrUndoPageList::~SdrUndoPageList()
1421 if(bItsMine)
1423 delete (&mrPage);
1428 SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg)
1429 : SdrUndoPageList(rNewPg)
1430 , pUndoGroup(nullptr)
1431 , mbHasFillBitmap(false)
1433 bItsMine = true;
1435 // keep fill bitmap separately to remove it from pool if not used elsewhere
1436 if (mrPage.IsMasterPage())
1438 SfxStyleSheet* const pStyleSheet = mrPage.getSdrPageProperties().GetStyleSheet();
1439 if (pStyleSheet)
1440 queryFillBitmap(pStyleSheet->GetItemSet());
1442 else
1444 queryFillBitmap(mrPage.getSdrPageProperties().GetItemSet());
1446 if (bool(mpFillBitmapItem))
1447 clearFillBitmap();
1449 // now remember the master page relationships
1450 if(mrPage.IsMasterPage())
1452 sal_uInt16 nPageCnt(rMod.GetPageCount());
1454 for(sal_uInt16 nPageNum2(0); nPageNum2 < nPageCnt; nPageNum2++)
1456 SdrPage* pDrawPage = rMod.GetPage(nPageNum2);
1458 if(pDrawPage->TRG_HasMasterPage())
1460 SdrPage& rMasterPage = pDrawPage->TRG_GetMasterPage();
1462 if(&mrPage == &rMasterPage)
1464 if(!pUndoGroup)
1466 pUndoGroup.reset( new SdrUndoGroup(rMod) );
1469 pUndoGroup->AddAction(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage));
1476 SdrUndoDelPage::~SdrUndoDelPage()
1480 void SdrUndoDelPage::Undo()
1482 if (bool(mpFillBitmapItem))
1483 restoreFillBitmap();
1484 ImpInsertPage(nPageNum);
1485 if (pUndoGroup!=nullptr)
1487 // recover master page relationships
1488 pUndoGroup->Undo();
1490 DBG_ASSERT(bItsMine,"UndoDeletePage: mrPage does not belong to UndoAction.");
1491 bItsMine=false;
1494 void SdrUndoDelPage::Redo()
1496 ImpRemovePage(nPageNum);
1497 if (bool(mpFillBitmapItem))
1498 clearFillBitmap();
1499 // master page relations are dissolved automatically
1500 DBG_ASSERT(!bItsMine,"RedoDeletePage: mrPage already belongs to UndoAction.");
1501 bItsMine=true;
1504 OUString SdrUndoDelPage::GetComment() const
1506 OUString aStr;
1507 ImpTakeDescriptionStr(STR_UndoDelPage,aStr);
1508 return aStr;
1511 OUString SdrUndoDelPage::GetSdrRepeatComment(SdrView& /*rView*/) const
1513 OUString aStr;
1514 ImpTakeDescriptionStr(STR_UndoDelPage,aStr);
1515 return aStr;
1518 void SdrUndoDelPage::SdrRepeat(SdrView& /*rView*/)
1522 bool SdrUndoDelPage::CanSdrRepeat(SdrView& /*rView*/) const
1524 return false;
1527 void SdrUndoDelPage::queryFillBitmap(const SfxItemSet& rItemSet)
1529 const SfxPoolItem *pItem = nullptr;
1530 if (rItemSet.GetItemState(XATTR_FILLBITMAP, false, &pItem) == SfxItemState::SET)
1531 mpFillBitmapItem.reset(pItem->Clone());
1532 if (rItemSet.GetItemState(XATTR_FILLSTYLE, false, &pItem) == SfxItemState::SET)
1533 mbHasFillBitmap = static_cast<const XFillStyleItem*>(pItem)->GetValue() == css::drawing::FillStyle_BITMAP;
1536 void SdrUndoDelPage::clearFillBitmap()
1538 if (mrPage.IsMasterPage())
1540 SfxStyleSheet* const pStyleSheet = mrPage.getSdrPageProperties().GetStyleSheet();
1541 assert(bool(pStyleSheet)); // who took away my stylesheet?
1542 if (pStyleSheet->GetListenerCount() == 1)
1544 SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
1545 rItemSet.ClearItem(XATTR_FILLBITMAP);
1546 if (mbHasFillBitmap)
1547 rItemSet.ClearItem(XATTR_FILLSTYLE);
1550 else
1552 SdrPageProperties &rPageProps = mrPage.getSdrPageProperties();
1553 rPageProps.ClearItem(XATTR_FILLBITMAP);
1554 if (mbHasFillBitmap)
1555 rPageProps.ClearItem(XATTR_FILLSTYLE);
1559 void SdrUndoDelPage::restoreFillBitmap()
1561 if (mrPage.IsMasterPage())
1563 SfxStyleSheet* const pStyleSheet = mrPage.getSdrPageProperties().GetStyleSheet();
1564 assert(bool(pStyleSheet)); // who took away my stylesheet?
1565 if (pStyleSheet->GetListenerCount() == 1)
1567 SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
1568 rItemSet.Put(*mpFillBitmapItem);
1569 if (mbHasFillBitmap)
1570 rItemSet.Put(XFillStyleItem(css::drawing::FillStyle_BITMAP));
1573 else
1575 SdrPageProperties &rPageProps = mrPage.getSdrPageProperties();
1576 rPageProps.PutItem(*mpFillBitmapItem);
1577 if (mbHasFillBitmap)
1578 rPageProps.PutItem(XFillStyleItem(css::drawing::FillStyle_BITMAP));
1583 void SdrUndoNewPage::Undo()
1585 ImpRemovePage(nPageNum);
1586 DBG_ASSERT(!bItsMine,"UndoNewPage: mrPage already belongs to UndoAction.");
1587 bItsMine=true;
1590 void SdrUndoNewPage::Redo()
1592 ImpInsertPage(nPageNum);
1593 DBG_ASSERT(bItsMine,"RedoNewPage: mrPage does not belong to UndoAction.");
1594 bItsMine=false;
1597 OUString SdrUndoNewPage::GetComment() const
1599 OUString aStr;
1600 ImpTakeDescriptionStr(STR_UndoNewPage,aStr);
1601 return aStr;
1605 OUString SdrUndoCopyPage::GetComment() const
1607 OUString aStr;
1608 ImpTakeDescriptionStr(STR_UndoCopPage,aStr);
1609 return aStr;
1612 OUString SdrUndoCopyPage::GetSdrRepeatComment(SdrView& /*rView*/) const
1614 OUString aStr;
1615 ImpTakeDescriptionStr(STR_UndoCopPage,aStr);
1616 return aStr;
1619 void SdrUndoCopyPage::SdrRepeat(SdrView& /*rView*/)
1624 bool SdrUndoCopyPage::CanSdrRepeat(SdrView& /*rView*/) const
1626 return false;
1630 void SdrUndoSetPageNum::Undo()
1632 ImpMovePage(nNewPageNum,nOldPageNum);
1635 void SdrUndoSetPageNum::Redo()
1637 ImpMovePage(nOldPageNum,nNewPageNum);
1640 OUString SdrUndoSetPageNum::GetComment() const
1642 OUString aStr;
1643 ImpTakeDescriptionStr(STR_UndoMovPage,aStr);
1644 return aStr;
1647 SdrUndoPageMasterPage::SdrUndoPageMasterPage(SdrPage& rChangedPage)
1648 : SdrUndoPage(rChangedPage)
1649 , mbOldHadMasterPage(mrPage.TRG_HasMasterPage())
1650 , maOldMasterPageNumber(0)
1652 // get current state from page
1653 if(mbOldHadMasterPage)
1655 maOldSet = mrPage.TRG_GetMasterPageVisibleLayers();
1656 maOldMasterPageNumber = mrPage.TRG_GetMasterPage().GetPageNum();
1660 SdrUndoPageMasterPage::~SdrUndoPageMasterPage()
1664 SdrUndoPageRemoveMasterPage::SdrUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1665 : SdrUndoPageMasterPage(rChangedPage)
1669 void SdrUndoPageRemoveMasterPage::Undo()
1671 if(mbOldHadMasterPage)
1673 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
1674 mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
1678 void SdrUndoPageRemoveMasterPage::Redo()
1680 mrPage.TRG_ClearMasterPage();
1683 OUString SdrUndoPageRemoveMasterPage::GetComment() const
1685 OUString aStr;
1686 ImpTakeDescriptionStr(STR_UndoDelPageMasterDscr,aStr);
1687 return aStr;
1690 SdrUndoPageChangeMasterPage::SdrUndoPageChangeMasterPage(SdrPage& rChangedPage)
1691 : SdrUndoPageMasterPage(rChangedPage)
1692 , mbNewHadMasterPage(false)
1693 , maNewMasterPageNumber(0)
1697 void SdrUndoPageChangeMasterPage::Undo()
1699 // remember values from new page
1700 if(mrPage.TRG_HasMasterPage())
1702 mbNewHadMasterPage = true;
1703 maNewSet = mrPage.TRG_GetMasterPageVisibleLayers();
1704 maNewMasterPageNumber = mrPage.TRG_GetMasterPage().GetPageNum();
1707 // restore old values
1708 if(mbOldHadMasterPage)
1710 mrPage.TRG_ClearMasterPage();
1711 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
1712 mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
1716 void SdrUndoPageChangeMasterPage::Redo()
1718 // restore new values
1719 if(mbNewHadMasterPage)
1721 mrPage.TRG_ClearMasterPage();
1722 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maNewMasterPageNumber));
1723 mrPage.TRG_SetMasterPageVisibleLayers(maNewSet);
1727 OUString SdrUndoPageChangeMasterPage::GetComment() const
1729 OUString aStr;
1730 ImpTakeDescriptionStr(STR_UndoChgPageMasterDscr,aStr);
1731 return aStr;
1735 SdrUndoFactory::~SdrUndoFactory(){}
1736 // shapes
1737 SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject )
1739 return new SdrUndoMoveObj( rObject );
1742 SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist )
1744 return new SdrUndoMoveObj( rObject, rDist );
1747 SdrUndoAction* SdrUndoFactory::CreateUndoGeoObject( SdrObject& rObject )
1749 return new SdrUndoGeoObj( rObject );
1752 SdrUndoAction* SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
1754 return new SdrUndoAttrObj( rObject, bStyleSheet1, bSaveText );
1757 SdrUndoAction* SdrUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect )
1759 return new SdrUndoRemoveObj( rObject, bOrdNumDirect );
1762 SdrUndoAction* SdrUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect )
1764 return new SdrUndoInsertObj( rObject, bOrdNumDirect );
1767 SdrUndoAction* SdrUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
1769 return new SdrUndoDelObj( rObject, bOrdNumDirect );
1772 SdrUndoAction* SdrUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect )
1774 return new SdrUndoNewObj( rObject, bOrdNumDirect );
1777 SdrUndoAction* SdrUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect )
1779 return new SdrUndoCopyObj( rObject, bOrdNumDirect );
1782 SdrUndoAction* SdrUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
1784 return new SdrUndoObjOrdNum( rObject, nOldOrdNum1, nNewOrdNum1 );
1787 SdrUndoAction* SdrUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect )
1789 return new SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect );
1792 SdrUndoAction* SdrUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer )
1794 return new SdrUndoObjectLayerChange( rObject, aOldLayer, aNewLayer );
1797 SdrUndoAction* SdrUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText )
1799 return new SdrUndoObjSetText( rNewObj, nText );
1802 SdrUndoAction* SdrUndoFactory::CreateUndoObjectStrAttr( SdrObject& rObject,
1803 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType,
1804 const OUString& sOldStr,
1805 const OUString& sNewStr )
1807 return new SdrUndoObjStrAttr( rObject, eObjStrAttrType, sOldStr, sNewStr );
1811 // layer
1812 SdrUndoAction* SdrUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1814 return new SdrUndoNewLayer( nLayerNum, rNewLayerAdmin, rNewModel );
1817 SdrUndoAction* SdrUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1819 return new SdrUndoDelLayer( nLayerNum, rNewLayerAdmin, rNewModel );
1822 SdrUndoAction* SdrUndoFactory::CreateUndoMoveLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel, sal_uInt16 nNewPos1)
1824 return new SdrUndoMoveLayer( nLayerNum, rNewLayerAdmin, rNewModel, nNewPos1 );
1827 // page
1828 SdrUndoAction* SdrUndoFactory::CreateUndoDeletePage(SdrPage& rPage)
1830 return new SdrUndoDelPage(rPage);
1833 SdrUndoAction* SdrUndoFactory::CreateUndoNewPage(SdrPage& rPage)
1835 return new SdrUndoNewPage( rPage );
1838 SdrUndoAction* SdrUndoFactory::CreateUndoCopyPage(SdrPage& rPage)
1840 return new SdrUndoCopyPage( rPage );
1843 SdrUndoAction* SdrUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1)
1845 return new SdrUndoSetPageNum( rNewPg, nOldPageNum1, nNewPageNum1 );
1847 // master page
1848 SdrUndoAction* SdrUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1850 return new SdrUndoPageRemoveMasterPage( rChangedPage );
1853 SdrUndoAction* SdrUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage)
1855 return new SdrUndoPageChangeMasterPage(rChangedPage);
1859 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */