Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / svx / source / svdraw / svdundo.cxx
blobb51142e6a50ee6e54150ca8aabf8776f3ea90ac0
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 .
21 #include <svl/lstner.hxx>
23 #include <svx/svdundo.hxx>
24 #include <svx/svdotext.hxx>
25 #include <svx/svdobj.hxx>
26 #include <svx/svdpage.hxx>
27 #include <svx/svdlayer.hxx>
28 #include <svx/svdmodel.hxx>
29 #include <svx/svdview.hxx>
30 #include "svx/svdstr.hrc"
31 #include "svdglob.hxx"
32 #include <svx/scene3d.hxx>
33 #include <editeng/editdata.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/svdograf.hxx>
43 #include <sdr/contact/viewcontactofgraphic.hxx>
44 #include <svx/svdotable.hxx> // #i124389#
47 // iterates over all views and unmarks this SdrObject if it is marked
48 static void ImplUnmarkObject( SdrObject* pObj )
50 SdrViewIter aIter( pObj );
51 for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
53 pView->MarkObj( pObj, pView->GetSdrPageView(), true );
59 TYPEINIT1(SdrUndoAction,SfxUndoAction);
61 SdrUndoAction::~SdrUndoAction() {}
63 bool SdrUndoAction::CanRepeat(SfxRepeatTarget& rView) const
65 SdrView* pV=PTR_CAST(SdrView,&rView);
66 if (pV!=NULL) return CanSdrRepeat(*pV);
67 return false;
70 void SdrUndoAction::Repeat(SfxRepeatTarget& rView)
72 SdrView* pV=PTR_CAST(SdrView,&rView);
73 if (pV!=NULL) SdrRepeat(*pV);
74 DBG_ASSERT(pV!=NULL,"Repeat: SfxRepeatTarget that was handed over is not a SdrView");
77 OUString SdrUndoAction::GetRepeatComment(SfxRepeatTarget& rView) const
79 SdrView* pV=PTR_CAST(SdrView,&rView);
80 if (pV!=NULL) return GetSdrRepeatComment(*pV);
81 return OUString();
84 bool SdrUndoAction::CanSdrRepeat(SdrView& /*rView*/) const
86 return false;
89 void SdrUndoAction::SdrRepeat(SdrView& /*rView*/)
93 OUString SdrUndoAction::GetSdrRepeatComment(SdrView& /*rView*/) const
95 return OUString();
100 SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod)
101 : SdrUndoAction(rNewMod),
102 aBuf(),
103 eFunction(SDRREPFUNC_OBJ_NONE)
106 SdrUndoGroup::~SdrUndoGroup()
108 Clear();
111 void SdrUndoGroup::Clear()
113 for (sal_uIntPtr nu=0; nu<GetActionCount(); nu++) {
114 SdrUndoAction* pAct=GetAction(nu);
115 delete pAct;
117 aBuf.clear();
120 void SdrUndoGroup::AddAction(SdrUndoAction* pAct)
122 aBuf.push_back(pAct);
125 void SdrUndoGroup::Undo()
127 for (sal_uIntPtr nu=GetActionCount(); nu>0;) {
128 nu--;
129 SdrUndoAction* pAct=GetAction(nu);
130 pAct->Undo();
134 void SdrUndoGroup::Redo()
136 for (sal_uIntPtr nu=0; nu<GetActionCount(); nu++) {
137 SdrUndoAction* pAct=GetAction(nu);
138 pAct->Redo();
142 OUString SdrUndoGroup::GetComment() const
144 return aComment.replaceAll("%1", aObjDescription);
147 bool SdrUndoGroup::CanSdrRepeat(SdrView& rView) const
149 switch (eFunction)
151 case SDRREPFUNC_OBJ_NONE : return false;
152 case SDRREPFUNC_OBJ_DELETE : return rView.AreObjectsMarked();
153 case SDRREPFUNC_OBJ_COMBINE_POLYPOLY: return rView.IsCombinePossible(false);
154 case SDRREPFUNC_OBJ_COMBINE_ONEPOLY : return rView.IsCombinePossible(true);
155 case SDRREPFUNC_OBJ_DISMANTLE_POLYS : return rView.IsDismantlePossible(false);
156 case SDRREPFUNC_OBJ_DISMANTLE_LINES : return rView.IsDismantlePossible(true);
157 case SDRREPFUNC_OBJ_CONVERTTOPOLY : return rView.IsConvertToPolyObjPossible(false);
158 case SDRREPFUNC_OBJ_CONVERTTOPATH : return rView.IsConvertToPathObjPossible(false);
159 case SDRREPFUNC_OBJ_GROUP : return rView.IsGroupPossible();
160 case SDRREPFUNC_OBJ_UNGROUP : return rView.IsUnGroupPossible();
161 case SDRREPFUNC_OBJ_PUTTOTOP : return rView.IsToTopPossible();
162 case SDRREPFUNC_OBJ_PUTTOBTM : return rView.IsToBtmPossible();
163 case SDRREPFUNC_OBJ_MOVTOTOP : return rView.IsToTopPossible();
164 case SDRREPFUNC_OBJ_MOVTOBTM : return rView.IsToBtmPossible();
165 case SDRREPFUNC_OBJ_REVORDER : return rView.IsReverseOrderPossible();
166 case SDRREPFUNC_OBJ_IMPORTMTF : return rView.IsImportMtfPossible();
167 default: break;
168 } // switch
169 return false;
172 void SdrUndoGroup::SdrRepeat(SdrView& rView)
174 switch (eFunction)
176 case SDRREPFUNC_OBJ_NONE : break;
177 case SDRREPFUNC_OBJ_DELETE : rView.DeleteMarked(); break;
178 case SDRREPFUNC_OBJ_COMBINE_POLYPOLY: rView.CombineMarkedObjects(false); break;
179 case SDRREPFUNC_OBJ_COMBINE_ONEPOLY : rView.CombineMarkedObjects(true); break;
180 case SDRREPFUNC_OBJ_DISMANTLE_POLYS : rView.DismantleMarkedObjects(false); break;
181 case SDRREPFUNC_OBJ_DISMANTLE_LINES : rView.DismantleMarkedObjects(true); break;
182 case SDRREPFUNC_OBJ_CONVERTTOPOLY : rView.ConvertMarkedToPolyObj(false); break;
183 case SDRREPFUNC_OBJ_CONVERTTOPATH : rView.ConvertMarkedToPathObj(false); break;
184 case SDRREPFUNC_OBJ_GROUP : rView.GroupMarked(); break;
185 case SDRREPFUNC_OBJ_UNGROUP : rView.UnGroupMarked(); break;
186 case SDRREPFUNC_OBJ_PUTTOTOP : rView.PutMarkedToTop(); break;
187 case SDRREPFUNC_OBJ_PUTTOBTM : rView.PutMarkedToBtm(); break;
188 case SDRREPFUNC_OBJ_MOVTOTOP : rView.MovMarkedToTop(); break;
189 case SDRREPFUNC_OBJ_MOVTOBTM : rView.MovMarkedToBtm(); break;
190 case SDRREPFUNC_OBJ_REVORDER : rView.ReverseOrderOfMarked(); break;
191 case SDRREPFUNC_OBJ_IMPORTMTF : rView.DoImportMarkedMtf(); break;
192 default: break;
193 } // switch
196 OUString SdrUndoGroup::GetSdrRepeatComment(SdrView& /*rView*/) const
198 return aComment.replaceAll("%1", ImpGetResStr(STR_ObjNameSingulPlural));
201 SdrUndoObj::SdrUndoObj(SdrObject& rNewObj)
202 : SdrUndoAction(*rNewObj.GetModel())
203 , pObj(&rNewObj)
207 OUString SdrUndoObj::GetDescriptionStringForObject( const SdrObject& _rForObject, sal_uInt16 nStrCacheID, bool bRepeat )
209 OUString rStr = ImpGetResStr(nStrCacheID);
211 sal_Int32 nPos = rStr.indexOf("%1");
213 if(nPos != -1)
215 if(bRepeat)
217 rStr = rStr.replaceAt(nPos, 2, ImpGetResStr(STR_ObjNameSingulPlural));
219 else
221 OUString aStr(_rForObject.TakeObjNameSingul());
222 rStr = rStr.replaceAt(nPos, 2, aStr);
226 return rStr;
229 void SdrUndoObj::ImpTakeDescriptionStr(sal_uInt16 nStrCacheID, OUString& rStr, bool bRepeat) const
231 if ( pObj )
232 rStr = GetDescriptionStringForObject( *pObj, nStrCacheID, bRepeat );
235 // common call method for possible change of the page when UNDO/REDO is triggered
236 void SdrUndoObj::ImpShowPageOfThisObject()
238 if(pObj && pObj->IsInserted() && pObj->GetPage() && pObj->GetModel())
240 SdrHint aHint(HINT_SWITCHTOPAGE);
242 aHint.SetObject(pObj);
243 aHint.SetPage(pObj->GetPage());
245 pObj->GetModel()->Broadcast(aHint);
249 void SdrUndoAttrObj::ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool& rStyleSheetPool, SfxStyleSheet& rSheet)
251 SfxStyleSheetBase* pThere = rStyleSheetPool.Find(rSheet.GetName(), rSheet.GetFamily());
253 if(!pThere)
255 // re-insert remembered style which was removed in the meantime. To do this
256 // without assertion, do it without parent and set parent after insertion
257 const OUString aParent(rSheet.GetParent());
259 rSheet.SetParent(OUString());
260 rStyleSheetPool.Insert(&rSheet);
261 rSheet.SetParent(aParent);
265 SdrUndoAttrObj::SdrUndoAttrObj(SdrObject& rNewObj, bool bStyleSheet1, bool bSaveText)
266 : SdrUndoObj(rNewObj)
267 , pUndoSet(NULL)
268 , pRedoSet(NULL)
269 , pRepeatSet(NULL)
270 , mxUndoStyleSheet()
271 , mxRedoStyleSheet()
272 , bHaveToTakeRedoSet(true)
273 , pTextUndo(NULL)
274 , pTextRedo(NULL)
275 , pUndoGroup(NULL)
277 bStyleSheet = bStyleSheet1;
279 SdrObjList* pOL = rNewObj.GetSubList();
280 bool bIsGroup(pOL!=NULL && pOL->GetObjCount());
281 bool bIs3DScene(bIsGroup && pObj->ISA(E3dScene));
283 if(bIsGroup)
285 // it's a group object!
286 pUndoGroup = new SdrUndoGroup(*pObj->GetModel());
287 sal_uInt32 nObjAnz(pOL->GetObjCount());
289 for(sal_uInt32 nObjNum(0); nObjNum < nObjAnz; nObjNum++)
291 pUndoGroup->AddAction(
292 new SdrUndoAttrObj(*pOL->GetObj(nObjNum), bStyleSheet1));
296 if(!bIsGroup || bIs3DScene)
298 pUndoSet = new SfxItemSet(pObj->GetMergedItemSet());
300 if(bStyleSheet)
301 mxUndoStyleSheet = pObj->GetStyleSheet();
303 if(bSaveText)
305 pTextUndo = pObj->GetOutlinerParaObject();
306 if(pTextUndo)
307 pTextUndo = new OutlinerParaObject(*pTextUndo);
312 SdrUndoAttrObj::~SdrUndoAttrObj()
314 delete pUndoSet;
315 delete pRedoSet;
316 delete pRepeatSet;
317 delete pUndoGroup;
318 delete pTextUndo;
319 delete pTextRedo;
322 void SdrUndoAttrObj::Undo()
324 E3DModifySceneSnapRectUpdater aUpdater(pObj);
325 bool bIs3DScene(pObj && pObj->ISA(E3dScene));
327 // Trigger PageChangeCall
328 ImpShowPageOfThisObject();
330 if(!pUndoGroup || bIs3DScene)
332 if(bHaveToTakeRedoSet)
334 bHaveToTakeRedoSet = false;
336 delete pRedoSet;
338 pRedoSet = new SfxItemSet(pObj->GetMergedItemSet());
340 if(bStyleSheet)
341 mxRedoStyleSheet = pObj->GetStyleSheet();
343 if(pTextUndo)
345 // #i8508#
346 pTextRedo = pObj->GetOutlinerParaObject();
348 if(pTextRedo)
349 pTextRedo = new OutlinerParaObject(*pTextRedo);
353 if(bStyleSheet)
355 mxRedoStyleSheet = pObj->GetStyleSheet();
356 SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxUndoStyleSheet.get());
358 if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
360 ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
361 pObj->SetStyleSheet(pSheet, true);
363 else
365 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
369 sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
371 // Since ClearItem sets back everything to normal
372 // it also sets fit-to-size text to non-fit-to-size text and
373 // switches on autogrowheight (the default). That may lead to
374 // loosing the geometry size info for the object when it is
375 // laid out again from AdjustTextFrameWidthAndHeight(). This makes
376 // rescuing the size of the object necessary.
377 const Rectangle aSnapRect = pObj->GetSnapRect();
379 if(pUndoSet)
381 if(pObj->ISA(SdrCaptionObj))
383 // do a more smooth item deletion here, else the text
384 // rect will be reformatted, especially when information regarding
385 // vertical text is changed. When clearing only set items it's
386 // slower, but safer regarding such information (it's not changed
387 // usually)
388 SfxWhichIter aIter(*pUndoSet);
389 sal_uInt16 nWhich(aIter.FirstWhich());
391 while(nWhich)
393 if(SFX_ITEM_SET != pUndoSet->GetItemState(nWhich, false))
395 pObj->ClearMergedItem(nWhich);
398 nWhich = aIter.NextWhich();
401 else
403 pObj->ClearMergedItem();
406 pObj->SetMergedItemSet(*pUndoSet);
409 // Restore previous size here when it was changed.
410 if(aSnapRect != pObj->GetSnapRect())
412 pObj->NbcSetSnapRect(aSnapRect);
415 pObj->GetProperties().BroadcastItemChange(aItemChange);
417 if(pTextUndo)
419 pObj->SetOutlinerParaObject(new OutlinerParaObject(*pTextUndo));
423 if(pUndoGroup)
425 pUndoGroup->Undo();
429 void SdrUndoAttrObj::Redo()
431 E3DModifySceneSnapRectUpdater aUpdater(pObj);
432 bool bIs3DScene(pObj && pObj->ISA(E3dScene));
434 if(!pUndoGroup || bIs3DScene)
436 if(bStyleSheet)
438 mxUndoStyleSheet = pObj->GetStyleSheet();
439 SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxRedoStyleSheet.get());
441 if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
443 ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
444 pObj->SetStyleSheet(pSheet, true);
446 else
448 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
452 sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
454 const Rectangle aSnapRect = pObj->GetSnapRect();
456 if(pRedoSet)
458 if(pObj->ISA(SdrCaptionObj))
460 // do a more smooth item deletion here, else the text
461 // rect will be reformatted, especially when information regarding
462 // vertical text is changed. When clearing only set items it's
463 // slower, but safer regarding such information (it's not changed
464 // usually)
465 SfxWhichIter aIter(*pRedoSet);
466 sal_uInt16 nWhich(aIter.FirstWhich());
468 while(nWhich)
470 if(SFX_ITEM_SET != pRedoSet->GetItemState(nWhich, false))
472 pObj->ClearMergedItem(nWhich);
475 nWhich = aIter.NextWhich();
478 else
480 pObj->ClearMergedItem();
483 pObj->SetMergedItemSet(*pRedoSet);
486 // Restore previous size here when it was changed.
487 if(aSnapRect != pObj->GetSnapRect())
489 pObj->NbcSetSnapRect(aSnapRect);
492 pObj->GetProperties().BroadcastItemChange(aItemChange);
494 // #i8508#
495 if(pTextRedo)
497 pObj->SetOutlinerParaObject(new OutlinerParaObject(*pTextRedo));
501 if(pUndoGroup)
503 pUndoGroup->Redo();
506 // Trigger PageChangeCall
507 ImpShowPageOfThisObject();
510 OUString SdrUndoAttrObj::GetComment() const
512 OUString aStr;
514 if(bStyleSheet)
516 ImpTakeDescriptionStr(STR_EditSetStylesheet, aStr);
518 else
520 ImpTakeDescriptionStr(STR_EditSetAttributes, aStr);
523 return aStr;
526 void SdrUndoAttrObj::SdrRepeat(SdrView& rView)
528 if(pRepeatSet)
530 rView.SetAttrToMarked(*pRepeatSet, false);
534 bool SdrUndoAttrObj::CanSdrRepeat(SdrView& rView) const
536 return (pRepeatSet!=0L && rView.AreObjectsMarked());
539 OUString SdrUndoAttrObj::GetSdrRepeatComment(SdrView& /*rView*/) const
541 OUString aStr;
543 if(bStyleSheet)
545 ImpTakeDescriptionStr(STR_EditSetStylesheet, aStr, true);
547 else
549 ImpTakeDescriptionStr(STR_EditSetAttributes, aStr, true);
552 return aStr;
557 SdrUndoMoveObj::~SdrUndoMoveObj() {}
559 void SdrUndoMoveObj::Undo()
561 // Trigger PageChangeCall
562 ImpShowPageOfThisObject();
564 pObj->Move(Size(-aDistance.Width(),-aDistance.Height()));
567 void SdrUndoMoveObj::Redo()
569 pObj->Move(Size(aDistance.Width(),aDistance.Height()));
571 // Trigger PageChangeCall
572 ImpShowPageOfThisObject();
575 OUString SdrUndoMoveObj::GetComment() const
577 OUString aStr;
578 ImpTakeDescriptionStr(STR_EditMove,aStr);
579 return aStr;
582 void SdrUndoMoveObj::SdrRepeat(SdrView& rView)
584 rView.MoveMarkedObj(aDistance);
587 bool SdrUndoMoveObj::CanSdrRepeat(SdrView& rView) const
589 return rView.AreObjectsMarked();
592 OUString SdrUndoMoveObj::GetSdrRepeatComment(SdrView& /*rView*/) const
594 OUString aStr;
595 ImpTakeDescriptionStr(STR_EditMove,aStr,true);
596 return aStr;
601 SdrUndoGeoObj::SdrUndoGeoObj(SdrObject& rNewObj)
602 : SdrUndoObj(rNewObj)
603 , pUndoGeo(NULL)
604 , pRedoGeo(NULL)
605 , pUndoGroup(NULL)
607 SdrObjList* pOL=rNewObj.GetSubList();
608 if (pOL!=NULL && pOL->GetObjCount() && !rNewObj.ISA(E3dScene))
610 // this is a group object!
611 // If this were 3D scene, we'd only add an Undo for the scene itself
612 // (which we do elsewhere).
613 pUndoGroup=new SdrUndoGroup(*pObj->GetModel());
614 sal_uIntPtr nObjAnz=pOL->GetObjCount();
615 for (sal_uIntPtr nObjNum=0; nObjNum<nObjAnz; nObjNum++) {
616 pUndoGroup->AddAction(new SdrUndoGeoObj(*pOL->GetObj(nObjNum)));
619 else
621 pUndoGeo=pObj->GetGeoData();
625 SdrUndoGeoObj::~SdrUndoGeoObj()
627 delete pUndoGeo;
628 delete pRedoGeo;
629 delete pUndoGroup;
632 void SdrUndoGeoObj::Undo()
634 // Trigger PageChangeCall
635 ImpShowPageOfThisObject();
637 if(pUndoGroup)
639 pUndoGroup->Undo();
641 // only repaint, no objectchange
642 pObj->ActionChanged();
644 else
646 delete pRedoGeo;
647 pRedoGeo=pObj->GetGeoData();
648 pObj->SetGeoData(*pUndoGeo);
652 void SdrUndoGeoObj::Redo()
654 if(pUndoGroup)
656 pUndoGroup->Redo();
658 // only repaint, no objectchange
659 pObj->ActionChanged();
661 else
663 delete pUndoGeo;
664 pUndoGeo=pObj->GetGeoData();
665 pObj->SetGeoData(*pRedoGeo);
668 // Trigger PageChangeCall
669 ImpShowPageOfThisObject();
672 OUString SdrUndoGeoObj::GetComment() const
674 OUString aStr;
675 ImpTakeDescriptionStr(STR_DragMethObjOwn,aStr);
676 return aStr;
681 class SdrUndoObjList::ObjListListener : public SfxListener
683 public:
684 ObjListListener(SdrUndoObjList& rThat, SdrObject& rObject, SfxBroadcaster& rBroadcaster);
685 virtual ~ObjListListener();
687 private:
688 virtual void Notify(SfxBroadcaster& rBroadcaster, const SfxHint& rHint) SAL_OVERRIDE;
690 private:
691 SdrUndoObjList& m_rThat;
692 SdrObject& m_rObject;
693 SfxBroadcaster* m_pBroadcaster;
696 SdrUndoObjList::ObjListListener::ObjListListener(SdrUndoObjList& rThat, SdrObject& rObject, SfxBroadcaster& rBroadcaster)
697 : m_rThat(rThat)
698 , m_rObject(rObject)
699 , m_pBroadcaster(&rBroadcaster)
701 StartListening(*m_pBroadcaster);
704 SdrUndoObjList::ObjListListener::~ObjListListener()
706 if (m_pBroadcaster)
707 EndListening(*m_pBroadcaster);
710 void SdrUndoObjList::ObjListListener::Notify(SfxBroadcaster&, const SfxHint& rHint)
712 const SdrHint* const pSdrHint(dynamic_cast<const SdrHint*>(&rHint));
713 if (pSdrHint)
715 if (pSdrHint->GetObject() == &m_rObject)
717 switch (pSdrHint->GetKind())
719 case HINT_OBJCHG :
720 if (IsListening(*m_pBroadcaster))
722 const sal_uInt32 nNewOrdNum(m_rObject.GetOrdNum());
723 if (nNewOrdNum != m_rThat.GetOrdNum())
724 m_rThat.SetOrdNum(nNewOrdNum);
726 break;
727 case HINT_OBJREMOVED :
728 SAL_WARN_IF(!IsListening(*m_pBroadcaster), "svx.sdr", "Object is not in any list");
729 EndListening(*m_pBroadcaster);
730 break;
731 case HINT_OBJINSERTED :
732 SAL_WARN_IF(IsListening(*m_pBroadcaster), "svx.sdr", "Object is already in a list");
733 StartListening(*m_pBroadcaster);
734 break;
735 default :
736 break;
742 SdrUndoObjList::SdrUndoObjList(SdrObject& rNewObj, bool bOrdNumDirect)
743 : SdrUndoObj(rNewObj)
744 , bOwner(false)
745 , pView(NULL)
746 , pPageView(NULL)
747 , m_pListener(NULL)
749 pObjList=pObj->GetObjList();
750 if (bOrdNumDirect)
752 nOrdNum=pObj->GetOrdNumDirect();
754 else
756 nOrdNum=pObj->GetOrdNum();
759 m_pListener = new ObjListListener(*this, *pObj, *pObj->GetModel());
762 SdrUndoObjList::~SdrUndoObjList()
764 delete m_pListener;
766 if (pObj!=NULL && IsOwner())
768 // Attribute have to go back to the regular Pool
769 SetOwner(false);
771 // now delete
772 SdrObject::Free( pObj );
776 void SdrUndoObjList::SetOwner(bool bNew)
778 bOwner = bNew;
781 sal_uInt32 SdrUndoObjList::GetOrdNum() const
783 return nOrdNum;
786 void SdrUndoObjList::SetOrdNum(sal_uInt32 nOrdNum_)
788 nOrdNum = nOrdNum_;
793 void SdrUndoRemoveObj::Undo()
795 // Trigger PageChangeCall
796 ImpShowPageOfThisObject();
798 DBG_ASSERT(!pObj->IsInserted(),"UndoRemoveObj: pObj has already been inserted.");
799 if (!pObj->IsInserted())
801 // #i11426#
802 // For UNDOs in Calc/Writer it is necessary to adapt the anchor
803 // position of the target object.
804 Point aOwnerAnchorPos(0, 0);
806 if(pObjList &&
807 pObjList->GetOwnerObj() &&
808 pObjList->GetOwnerObj()->ISA(SdrObjGroup))
810 aOwnerAnchorPos = pObjList->GetOwnerObj()->GetAnchorPos();
813 E3DModifySceneSnapRectUpdater aUpdater(pObjList->GetOwnerObj());
814 SdrInsertReason aReason(SDRREASON_UNDO);
815 pObjList->InsertObject(pObj,nOrdNum,&aReason);
817 // #i11426#
818 if(aOwnerAnchorPos.X() || aOwnerAnchorPos.Y())
820 pObj->NbcSetAnchorPos(aOwnerAnchorPos);
825 void SdrUndoRemoveObj::Redo()
827 DBG_ASSERT(pObj->IsInserted(),"RedoRemoveObj: pObj is not inserted.");
828 if (pObj->IsInserted())
830 ImplUnmarkObject( pObj );
831 E3DModifySceneSnapRectUpdater aUpdater(pObj);
832 pObjList->RemoveObject(nOrdNum);
835 // Trigger PageChangeCall
836 ImpShowPageOfThisObject();
839 SdrUndoRemoveObj::~SdrUndoRemoveObj()
845 void SdrUndoInsertObj::Undo()
847 // Trigger PageChangeCall
848 ImpShowPageOfThisObject();
850 DBG_ASSERT(pObj->IsInserted(),"UndoInsertObj: pObj is not inserted.");
851 if (pObj->IsInserted())
853 ImplUnmarkObject( pObj );
855 #ifdef DBG_UTIL
856 SdrObject* pChkObj=
857 #endif
858 pObjList->RemoveObject(nOrdNum);
859 DBG_ASSERT(pChkObj==pObj,"UndoInsertObj: RemoveObjNum!=pObj");
863 void SdrUndoInsertObj::Redo()
865 DBG_ASSERT(!pObj->IsInserted(),"RedoInsertObj: pObj is already inserted");
866 if (!pObj->IsInserted())
868 // Restore anchor position of an object,
869 // which becomes a member of a group, because its cleared in method
870 // <InsertObject(..)>. Needed for correct Redo in Writer. (#i45952#)
871 Point aAnchorPos( 0, 0 );
872 if ( pObjList &&
873 pObjList->GetOwnerObj() &&
874 pObjList->GetOwnerObj()->ISA(SdrObjGroup) )
876 aAnchorPos = pObj->GetAnchorPos();
879 SdrInsertReason aReason(SDRREASON_UNDO);
880 pObjList->InsertObject(pObj,nOrdNum,&aReason);
882 // Arcs lose position when grouped (#i45952#)
883 if ( aAnchorPos.X() || aAnchorPos.Y() )
885 pObj->NbcSetAnchorPos( aAnchorPos );
889 // Trigger PageChangeCall
890 ImpShowPageOfThisObject();
895 void SdrUndoDelObj::TryToFlushGraphicContent()
897 SdrGrafObj* pSdrGrafObj = dynamic_cast< SdrGrafObj* >(pObj);
899 if(pSdrGrafObj)
901 sdr::contact::ViewContactOfGraphic* pVC = dynamic_cast< sdr::contact::ViewContactOfGraphic* >(&pSdrGrafObj->GetViewContact());
903 if(pVC)
905 pVC->flushViewObjectContacts();
906 pVC->flushGraphicObjects();
909 pSdrGrafObj->ForceSwapOut();
913 SdrUndoDelObj::SdrUndoDelObj(SdrObject& rNewObj, bool bOrdNumDirect)
914 : SdrUndoRemoveObj(rNewObj,bOrdNumDirect)
916 SetOwner(true);
918 // #i122985# if graphic object is deleted (but goes to undo) flush it's graphic content
919 // since it is potentially no longer needed
920 TryToFlushGraphicContent();
923 void SdrUndoDelObj::Undo()
925 SdrUndoRemoveObj::Undo();
926 DBG_ASSERT(IsOwner(),"UndoDeleteObj: pObj does not belong to UndoAction");
927 SetOwner(false);
930 void SdrUndoDelObj::Redo()
932 SdrUndoRemoveObj::Redo();
933 DBG_ASSERT(!IsOwner(),"RedoDeleteObj: pObj already belongs to UndoAction");
934 SetOwner(true);
936 // #i122985# if graphic object is deleted (but goes to undo) flush it's graphic content
937 // since it is potentially no longer needed
938 TryToFlushGraphicContent();
941 OUString SdrUndoDelObj::GetComment() const
943 OUString aStr;
944 ImpTakeDescriptionStr(STR_EditDelete,aStr);
945 return aStr;
948 void SdrUndoDelObj::SdrRepeat(SdrView& rView)
950 rView.DeleteMarked();
953 bool SdrUndoDelObj::CanSdrRepeat(SdrView& rView) const
955 return rView.AreObjectsMarked();
958 OUString SdrUndoDelObj::GetSdrRepeatComment(SdrView& /*rView*/) const
960 OUString aStr;
961 ImpTakeDescriptionStr(STR_EditDelete,aStr,true);
962 return aStr;
967 void SdrUndoNewObj::Undo()
969 SdrUndoInsertObj::Undo();
970 DBG_ASSERT(!IsOwner(),"RedoNewObj: pObj already belongs to UndoAction");
971 SetOwner(true);
974 void SdrUndoNewObj::Redo()
976 SdrUndoInsertObj::Redo();
977 DBG_ASSERT(IsOwner(),"RedoNewObj: pObj does not belong to UndoAction");
978 SetOwner(false);
981 OUString SdrUndoNewObj::GetComment( const SdrObject& _rForObject )
983 return GetDescriptionStringForObject( _rForObject, STR_UndoInsertObj );
986 OUString SdrUndoNewObj::GetComment() const
988 OUString aStr;
989 ImpTakeDescriptionStr(STR_UndoInsertObj,aStr);
990 return aStr;
993 SdrUndoReplaceObj::SdrUndoReplaceObj(SdrObject& rOldObj1, SdrObject& rNewObj1, bool bOrdNumDirect)
994 : SdrUndoObj(rOldObj1)
995 , bOldOwner(false)
996 , bNewOwner(false)
997 , pNewObj(&rNewObj1)
999 SetOldOwner(true);
1001 pObjList=pObj->GetObjList();
1002 if (bOrdNumDirect)
1004 nOrdNum=pObj->GetOrdNumDirect();
1006 else
1008 nOrdNum=pObj->GetOrdNum();
1012 SdrUndoReplaceObj::~SdrUndoReplaceObj()
1014 if (pObj!=NULL && IsOldOwner())
1016 // Attribute have to go back into the Pool
1017 SetOldOwner(false);
1019 // now delete
1020 SdrObject::Free( pObj );
1022 if (pNewObj!=NULL && IsNewOwner())
1024 // Attribute have to go back into the Pool
1025 SetNewOwner(false);
1027 // now delete
1028 SdrObject::Free( pNewObj );
1032 void SdrUndoReplaceObj::Undo()
1034 // Trigger PageChangeCall
1035 ImpShowPageOfThisObject();
1037 if (IsOldOwner() && !IsNewOwner())
1039 DBG_ASSERT(!pObj->IsInserted(),"SdrUndoReplaceObj::Undo(): Old object is already inserted!");
1040 DBG_ASSERT(pNewObj->IsInserted(),"SdrUndoReplaceObj::Undo(): New object is not inserted!");
1041 SetOldOwner(false);
1042 SetNewOwner(true);
1044 ImplUnmarkObject( pNewObj );
1045 pObjList->ReplaceObject(pObj,nOrdNum);
1047 else
1049 OSL_FAIL("SdrUndoReplaceObj::Undo(): Wrong IsMine flags. Did you call Undo twice?");
1053 void SdrUndoReplaceObj::Redo()
1055 if (!IsOldOwner() && IsNewOwner())
1057 DBG_ASSERT(!pNewObj->IsInserted(),"SdrUndoReplaceObj::Redo(): New object is already inserted!!");
1058 DBG_ASSERT(pObj->IsInserted(),"SdrUndoReplaceObj::Redo(): Old object is not inserted!!");
1059 SetOldOwner(true);
1060 SetNewOwner(false);
1062 ImplUnmarkObject( pObj );
1063 pObjList->ReplaceObject(pNewObj,nOrdNum);
1066 else
1068 OSL_FAIL("SdrUndoReplaceObj::Redo(): Wrong IsMine flags. Did you call Redo twice?");
1071 // Trigger PageChangeCall
1072 ImpShowPageOfThisObject();
1075 void SdrUndoReplaceObj::SetNewOwner(bool bNew)
1077 bNewOwner = bNew;
1080 void SdrUndoReplaceObj::SetOldOwner(bool bNew)
1082 bOldOwner = bNew;
1087 OUString SdrUndoCopyObj::GetComment() const
1089 OUString aStr;
1090 ImpTakeDescriptionStr(STR_UndoCopyObj,aStr);
1091 return aStr;
1095 // #i11702#
1097 SdrUndoObjectLayerChange::SdrUndoObjectLayerChange(SdrObject& rObj, SdrLayerID aOldLayer, SdrLayerID aNewLayer)
1098 : SdrUndoObj(rObj)
1099 , maOldLayer(aOldLayer)
1100 , maNewLayer(aNewLayer)
1104 void SdrUndoObjectLayerChange::Undo()
1106 ImpShowPageOfThisObject();
1107 pObj->SetLayer(maOldLayer);
1110 void SdrUndoObjectLayerChange::Redo()
1112 pObj->SetLayer(maNewLayer);
1113 ImpShowPageOfThisObject();
1118 SdrUndoObjOrdNum::SdrUndoObjOrdNum(SdrObject& rNewObj, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
1119 : SdrUndoObj(rNewObj)
1120 , nOldOrdNum(nOldOrdNum1)
1121 , nNewOrdNum(nNewOrdNum1)
1125 void SdrUndoObjOrdNum::Undo()
1127 // Trigger PageChangeCall
1128 ImpShowPageOfThisObject();
1130 SdrObjList* pOL=pObj->GetObjList();
1131 if (pOL==NULL)
1133 OSL_FAIL("UndoObjOrdNum: pObj does not have an ObjList.");
1134 return;
1136 pOL->SetObjectOrdNum(nNewOrdNum,nOldOrdNum);
1139 void SdrUndoObjOrdNum::Redo()
1141 SdrObjList* pOL=pObj->GetObjList();
1142 if (pOL==NULL)
1144 OSL_FAIL("RedoObjOrdNum: pObj does not have an ObjList.");
1145 return;
1147 pOL->SetObjectOrdNum(nOldOrdNum,nNewOrdNum);
1149 // Trigger PageChangeCall
1150 ImpShowPageOfThisObject();
1153 OUString SdrUndoObjOrdNum::GetComment() const
1155 OUString aStr;
1156 ImpTakeDescriptionStr(STR_UndoObjOrdNum,aStr);
1157 return aStr;
1162 SdrUndoObjSetText::SdrUndoObjSetText(SdrObject& rNewObj, sal_Int32 nText)
1163 : SdrUndoObj(rNewObj)
1164 , pOldText(NULL)
1165 , pNewText(NULL)
1166 , bNewTextAvailable(false)
1167 , bEmptyPresObj(false)
1168 , mnText(nText)
1170 SdrText* pText = static_cast< SdrTextObj*>( &rNewObj )->getText(mnText);
1171 if( pText && pText->GetOutlinerParaObject() )
1172 pOldText = new OutlinerParaObject(*pText->GetOutlinerParaObject());
1174 bEmptyPresObj = rNewObj.IsEmptyPresObj();
1177 SdrUndoObjSetText::~SdrUndoObjSetText()
1179 delete pOldText;
1180 delete pNewText;
1183 void SdrUndoObjSetText::AfterSetText()
1185 if (!bNewTextAvailable)
1187 SdrText* pText = static_cast< SdrTextObj*>( pObj )->getText(mnText);
1188 if( pText && pText->GetOutlinerParaObject() )
1189 pNewText = new OutlinerParaObject(*pText->GetOutlinerParaObject());
1190 bNewTextAvailable=true;
1194 void SdrUndoObjSetText::Undo()
1196 // only works with SdrTextObj
1197 SdrTextObj* pTarget = dynamic_cast< SdrTextObj* >(pObj);
1199 if(!pTarget)
1201 OSL_ENSURE(false, "SdrUndoObjSetText::Undo with SdrObject not based on SdrTextObj (!)");
1202 return;
1205 // Trigger PageChangeCall
1206 ImpShowPageOfThisObject();
1208 // save old text for Redo
1209 if(!bNewTextAvailable)
1211 AfterSetText();
1214 SdrText* pText = pTarget->getText(mnText);
1215 if (pText)
1217 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1218 OutlinerParaObject* pText1 = pOldText ? new OutlinerParaObject(*pOldText) : NULL;
1219 pText->SetOutlinerParaObject(pText1);
1220 pTarget->NbcSetOutlinerParaObjectForText(pText1, pText);
1223 pTarget->SetEmptyPresObj(bEmptyPresObj);
1224 pTarget->ActionChanged();
1226 // #i124389# if it's a table, also need to relayout TextFrame
1227 if(0 != dynamic_cast< sdr::table::SdrTableObj* >(pTarget))
1229 pTarget->NbcAdjustTextFrameWidthAndHeight();
1232 // #i122410# SetOutlinerParaObject at SdrText does not trigger a
1233 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1234 // update their preview.
1235 pTarget->BroadcastObjectChange();
1238 void SdrUndoObjSetText::Redo()
1240 // only works with SdrTextObj
1241 SdrTextObj* pTarget = dynamic_cast< SdrTextObj* >(pObj);
1243 if(!pTarget)
1245 OSL_ENSURE(false, "SdrUndoObjSetText::Redo with SdrObject not based on SdrTextObj (!)");
1246 return;
1249 SdrText* pText = pTarget->getText(mnText);
1250 if (pText)
1252 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1253 OutlinerParaObject* pText1 = pNewText ? new OutlinerParaObject(*pNewText) : NULL;
1254 pTarget->NbcSetOutlinerParaObjectForText( pText1, pText );
1257 pTarget->ActionChanged();
1259 // #i124389# if it's a table, als oneed to relayout TextFrame
1260 if(0 != dynamic_cast< sdr::table::SdrTableObj* >(pTarget))
1262 pTarget->NbcAdjustTextFrameWidthAndHeight();
1265 // #i122410# NbcSetOutlinerParaObjectForText at SdrTextObj does not trigger a
1266 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1267 // update their preview.
1268 pTarget->BroadcastObjectChange();
1270 // Trigger PageChangeCall
1271 ImpShowPageOfThisObject();
1274 OUString SdrUndoObjSetText::GetComment() const
1276 OUString aStr;
1277 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1278 return aStr;
1281 OUString SdrUndoObjSetText::GetSdrRepeatComment(SdrView& /*rView*/) const
1283 OUString aStr;
1284 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1285 return aStr;
1288 void SdrUndoObjSetText::SdrRepeat(SdrView& rView)
1290 if (bNewTextAvailable && rView.AreObjectsMarked())
1292 const SdrMarkList& rML=rView.GetMarkedObjectList();
1294 const bool bUndo = rView.IsUndoEnabled();
1295 if( bUndo )
1297 OUString aStr;
1298 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1299 rView.BegUndo(aStr);
1302 sal_uIntPtr nAnz=rML.GetMarkCount();
1303 for (sal_uIntPtr nm=0; nm<nAnz; nm++)
1305 SdrObject* pObj2=rML.GetMark(nm)->GetMarkedSdrObj();
1306 SdrTextObj* pTextObj=PTR_CAST(SdrTextObj,pObj2);
1307 if (pTextObj!=NULL)
1309 if( bUndo )
1310 rView.AddUndo(new SdrUndoObjSetText(*pTextObj,0));
1312 OutlinerParaObject* pText1=pNewText;
1313 if (pText1!=NULL)
1314 pText1 = new OutlinerParaObject(*pText1);
1315 pTextObj->SetOutlinerParaObject(pText1);
1319 if( bUndo )
1320 rView.EndUndo();
1324 bool SdrUndoObjSetText::CanSdrRepeat(SdrView& rView) const
1326 bool bOk = false;
1327 if (bNewTextAvailable && rView.AreObjectsMarked()) {
1328 bOk=true;
1330 return bOk;
1333 // Undo/Redo for setting object's name (#i73249#)
1334 SdrUndoObjStrAttr::SdrUndoObjStrAttr( SdrObject& rNewObj,
1335 const ObjStrAttrType eObjStrAttr,
1336 const OUString& sOldStr,
1337 const OUString& sNewStr)
1338 : SdrUndoObj( rNewObj )
1339 , meObjStrAttr( eObjStrAttr )
1340 , msOldStr( sOldStr )
1341 , msNewStr( sNewStr )
1345 void SdrUndoObjStrAttr::Undo()
1347 ImpShowPageOfThisObject();
1349 switch ( meObjStrAttr )
1351 case OBJ_NAME:
1352 pObj->SetName( msOldStr );
1353 break;
1354 case OBJ_TITLE:
1355 pObj->SetTitle( msOldStr );
1356 break;
1357 case OBJ_DESCRIPTION:
1358 pObj->SetDescription( msOldStr );
1359 break;
1363 void SdrUndoObjStrAttr::Redo()
1365 switch ( meObjStrAttr )
1367 case OBJ_NAME:
1368 pObj->SetName( msNewStr );
1369 break;
1370 case OBJ_TITLE:
1371 pObj->SetTitle( msNewStr );
1372 break;
1373 case OBJ_DESCRIPTION:
1374 pObj->SetDescription( msNewStr );
1375 break;
1378 ImpShowPageOfThisObject();
1381 OUString SdrUndoObjStrAttr::GetComment() const
1383 OUString aStr;
1384 switch ( meObjStrAttr )
1386 case OBJ_NAME:
1387 ImpTakeDescriptionStr( STR_UndoObjName, aStr );
1388 aStr += " '" + msNewStr + "'";
1389 break;
1390 case OBJ_TITLE:
1391 ImpTakeDescriptionStr( STR_UndoObjTitle, aStr );
1392 break;
1393 case OBJ_DESCRIPTION:
1394 ImpTakeDescriptionStr( STR_UndoObjDescription, aStr );
1395 break;
1398 return aStr;
1402 SdrUndoLayer::SdrUndoLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1403 : SdrUndoAction(rNewModel)
1404 , pLayer(rNewLayerAdmin.GetLayer(nLayerNum))
1405 , pLayerAdmin(&rNewLayerAdmin)
1406 , nNum(nLayerNum)
1407 , bItsMine(false)
1411 SdrUndoLayer::~SdrUndoLayer()
1413 if (bItsMine)
1415 delete pLayer;
1421 void SdrUndoNewLayer::Undo()
1423 DBG_ASSERT(!bItsMine,"SdrUndoNewLayer::Undo(): Layer already belongs to UndoAction.");
1424 bItsMine=true;
1425 #ifdef DBG_UTIL
1426 SdrLayer* pCmpLayer=
1427 #endif
1428 pLayerAdmin->RemoveLayer(nNum);
1429 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoNewLayer::Undo(): Removed layer is != pLayer.");
1432 void SdrUndoNewLayer::Redo()
1434 DBG_ASSERT(bItsMine,"SdrUndoNewLayer::Undo(): Layer does not belong to UndoAction.");
1435 bItsMine=false;
1436 pLayerAdmin->InsertLayer(pLayer,nNum);
1439 OUString SdrUndoNewLayer::GetComment() const
1441 return ImpGetResStr(STR_UndoNewLayer);
1446 void SdrUndoDelLayer::Undo()
1448 DBG_ASSERT(bItsMine,"SdrUndoDelLayer::Undo(): Layer does not belong to UndoAction.");
1449 bItsMine=false;
1450 pLayerAdmin->InsertLayer(pLayer,nNum);
1453 void SdrUndoDelLayer::Redo()
1455 DBG_ASSERT(!bItsMine,"SdrUndoDelLayer::Undo(): Layer already belongs to UndoAction.");
1456 bItsMine=true;
1457 #ifdef DBG_UTIL
1458 SdrLayer* pCmpLayer=
1459 #endif
1460 pLayerAdmin->RemoveLayer(nNum);
1461 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoDelLayer::Redo(): Removed layer is != pLayer.");
1464 OUString SdrUndoDelLayer::GetComment() const
1466 return ImpGetResStr(STR_UndoDelLayer);
1471 void SdrUndoMoveLayer::Undo()
1473 #ifdef DBG_UTIL
1474 SdrLayer* pCmpLayer=
1475 #endif
1476 pLayerAdmin->RemoveLayer(nNeuPos);
1477 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoMoveLayer::Undo(): Removed layer is != pLayer.");
1478 pLayerAdmin->InsertLayer(pLayer,nNum);
1481 void SdrUndoMoveLayer::Redo()
1483 #ifdef DBG_UTIL
1484 SdrLayer* pCmpLayer=
1485 #endif
1486 pLayerAdmin->RemoveLayer(nNum);
1487 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoMoveLayer::Redo(): Removed layer is != pLayer.");
1488 pLayerAdmin->InsertLayer(pLayer,nNeuPos);
1491 OUString SdrUndoMoveLayer::GetComment() const
1493 return ImpGetResStr(STR_UndoMovLayer);
1497 SdrUndoPage::SdrUndoPage(SdrPage& rNewPg)
1498 : SdrUndoAction(*rNewPg.GetModel())
1499 , mrPage(rNewPg)
1503 void SdrUndoPage::ImpInsertPage(sal_uInt16 nNum)
1505 DBG_ASSERT(!mrPage.IsInserted(),"SdrUndoPage::ImpInsertPage(): mrPage is already inserted.");
1506 if (!mrPage.IsInserted())
1508 if (mrPage.IsMasterPage())
1510 rMod.InsertMasterPage(&mrPage,nNum);
1512 else
1514 rMod.InsertPage(&mrPage,nNum);
1519 void SdrUndoPage::ImpRemovePage(sal_uInt16 nNum)
1521 DBG_ASSERT(mrPage.IsInserted(),"SdrUndoPage::ImpRemovePage(): mrPage is not inserted.");
1522 if (mrPage.IsInserted())
1524 SdrPage* pChkPg=NULL;
1525 if (mrPage.IsMasterPage())
1527 pChkPg=rMod.RemoveMasterPage(nNum);
1529 else
1531 pChkPg=rMod.RemovePage(nNum);
1533 DBG_ASSERT(pChkPg==&mrPage,"SdrUndoPage::ImpRemovePage(): RemovePage!=&mrPage");
1534 (void)pChkPg;
1538 void SdrUndoPage::ImpMovePage(sal_uInt16 nOldNum, sal_uInt16 nNewNum)
1540 DBG_ASSERT(mrPage.IsInserted(),"SdrUndoPage::ImpMovePage(): mrPage is not inserted.");
1541 if (mrPage.IsInserted())
1543 if (mrPage.IsMasterPage())
1545 rMod.MoveMasterPage(nOldNum,nNewNum);
1547 else
1549 rMod.MovePage(nOldNum,nNewNum);
1554 void SdrUndoPage::ImpTakeDescriptionStr(sal_uInt16 nStrCacheID, OUString& rStr, sal_uInt16 /*n*/, bool /*bRepeat*/) const
1556 rStr = ImpGetResStr(nStrCacheID);
1561 SdrUndoPageList::SdrUndoPageList(SdrPage& rNewPg)
1562 : SdrUndoPage(rNewPg)
1563 , bItsMine(false)
1565 nPageNum=rNewPg.GetPageNum();
1568 SdrUndoPageList::~SdrUndoPageList()
1570 if(bItsMine)
1572 delete (&mrPage);
1578 SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg)
1579 : SdrUndoPageList(rNewPg)
1580 , pUndoGroup(NULL)
1582 bItsMine = true;
1584 // now remember the master page relationships
1585 if(mrPage.IsMasterPage())
1587 sal_uInt16 nPageAnz(rMod.GetPageCount());
1589 for(sal_uInt16 nPageNum2(0); nPageNum2 < nPageAnz; nPageNum2++)
1591 SdrPage* pDrawPage = rMod.GetPage(nPageNum2);
1593 if(pDrawPage->TRG_HasMasterPage())
1595 SdrPage& rMasterPage = pDrawPage->TRG_GetMasterPage();
1597 if(&mrPage == &rMasterPage)
1599 if(!pUndoGroup)
1601 pUndoGroup = new SdrUndoGroup(rMod);
1604 pUndoGroup->AddAction(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage));
1611 SdrUndoDelPage::~SdrUndoDelPage()
1613 delete pUndoGroup;
1616 void SdrUndoDelPage::Undo()
1618 ImpInsertPage(nPageNum);
1619 if (pUndoGroup!=NULL)
1621 // recover master page relationships
1622 pUndoGroup->Undo();
1624 DBG_ASSERT(bItsMine,"UndoDeletePage: mrPage does not belong to UndoAction.");
1625 bItsMine=false;
1628 void SdrUndoDelPage::Redo()
1630 ImpRemovePage(nPageNum);
1631 // master page relations are dissolved automatically
1632 DBG_ASSERT(!bItsMine,"RedoDeletePage: mrPage already belongs to UndoAction.");
1633 bItsMine=true;
1636 OUString SdrUndoDelPage::GetComment() const
1638 OUString aStr;
1639 ImpTakeDescriptionStr(STR_UndoDelPage,aStr,0,false);
1640 return aStr;
1643 OUString SdrUndoDelPage::GetSdrRepeatComment(SdrView& /*rView*/) const
1645 OUString aStr;
1646 ImpTakeDescriptionStr(STR_UndoDelPage,aStr,0,false);
1647 return aStr;
1650 void SdrUndoDelPage::SdrRepeat(SdrView& /*rView*/)
1654 bool SdrUndoDelPage::CanSdrRepeat(SdrView& /*rView*/) const
1656 return false;
1661 void SdrUndoNewPage::Undo()
1663 ImpRemovePage(nPageNum);
1664 DBG_ASSERT(!bItsMine,"UndoNewPage: mrPage already belongs to UndoAction.");
1665 bItsMine=true;
1668 void SdrUndoNewPage::Redo()
1670 ImpInsertPage(nPageNum);
1671 DBG_ASSERT(bItsMine,"RedoNewPage: mrPage does not belong to UndoAction.");
1672 bItsMine=false;
1675 OUString SdrUndoNewPage::GetComment() const
1677 OUString aStr;
1678 ImpTakeDescriptionStr(STR_UndoNewPage,aStr,0,false);
1679 return aStr;
1684 OUString SdrUndoCopyPage::GetComment() const
1686 OUString aStr;
1687 ImpTakeDescriptionStr(STR_UndoCopPage,aStr,0,false);
1688 return aStr;
1691 OUString SdrUndoCopyPage::GetSdrRepeatComment(SdrView& /*rView*/) const
1693 OUString aStr;
1694 ImpTakeDescriptionStr(STR_UndoCopPage,aStr,0,false);
1695 return aStr;
1698 void SdrUndoCopyPage::SdrRepeat(SdrView& /*rView*/)
1703 bool SdrUndoCopyPage::CanSdrRepeat(SdrView& /*rView*/) const
1705 return false;
1710 void SdrUndoSetPageNum::Undo()
1712 ImpMovePage(nNewPageNum,nOldPageNum);
1715 void SdrUndoSetPageNum::Redo()
1717 ImpMovePage(nOldPageNum,nNewPageNum);
1720 OUString SdrUndoSetPageNum::GetComment() const
1722 OUString aStr;
1723 ImpTakeDescriptionStr(STR_UndoMovPage,aStr,0,false);
1724 return aStr;
1727 SdrUndoPageMasterPage::SdrUndoPageMasterPage(SdrPage& rChangedPage)
1728 : SdrUndoPage(rChangedPage)
1729 , mbOldHadMasterPage(mrPage.TRG_HasMasterPage())
1730 , maOldMasterPageNumber(0)
1732 // get current state from page
1733 if(mbOldHadMasterPage)
1735 maOldSet = mrPage.TRG_GetMasterPageVisibleLayers();
1736 maOldMasterPageNumber = mrPage.TRG_GetMasterPage().GetPageNum();
1740 SdrUndoPageMasterPage::~SdrUndoPageMasterPage()
1744 SdrUndoPageRemoveMasterPage::SdrUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1745 : SdrUndoPageMasterPage(rChangedPage)
1749 void SdrUndoPageRemoveMasterPage::Undo()
1751 if(mbOldHadMasterPage)
1753 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
1754 mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
1758 void SdrUndoPageRemoveMasterPage::Redo()
1760 mrPage.TRG_ClearMasterPage();
1763 OUString SdrUndoPageRemoveMasterPage::GetComment() const
1765 OUString aStr;
1766 ImpTakeDescriptionStr(STR_UndoDelPageMasterDscr,aStr,0,false);
1767 return aStr;
1770 SdrUndoPageChangeMasterPage::SdrUndoPageChangeMasterPage(SdrPage& rChangedPage)
1771 : SdrUndoPageMasterPage(rChangedPage)
1772 , mbNewHadMasterPage(false)
1773 , maNewMasterPageNumber(0)
1777 void SdrUndoPageChangeMasterPage::Undo()
1779 // remember values from new page
1780 if(mrPage.TRG_HasMasterPage())
1782 mbNewHadMasterPage = true;
1783 maNewSet = mrPage.TRG_GetMasterPageVisibleLayers();
1784 maNewMasterPageNumber = mrPage.TRG_GetMasterPage().GetPageNum();
1787 // restore old values
1788 if(mbOldHadMasterPage)
1790 mrPage.TRG_ClearMasterPage();
1791 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
1792 mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
1796 void SdrUndoPageChangeMasterPage::Redo()
1798 // restore new values
1799 if(mbNewHadMasterPage)
1801 mrPage.TRG_ClearMasterPage();
1802 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maNewMasterPageNumber));
1803 mrPage.TRG_SetMasterPageVisibleLayers(maNewSet);
1807 OUString SdrUndoPageChangeMasterPage::GetComment() const
1809 OUString aStr;
1810 ImpTakeDescriptionStr(STR_UndoChgPageMasterDscr,aStr,0,false);
1811 return aStr;
1815 SdrUndoFactory::~SdrUndoFactory(){}
1816 // shapes
1817 SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject )
1819 return new SdrUndoMoveObj( rObject );
1822 SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist )
1824 return new SdrUndoMoveObj( rObject, rDist );
1827 SdrUndoAction* SdrUndoFactory::CreateUndoGeoObject( SdrObject& rObject )
1829 return new SdrUndoGeoObj( rObject );
1832 SdrUndoAction* SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
1834 return new SdrUndoAttrObj( rObject, bStyleSheet1 ? sal_True : sal_False, bSaveText ? sal_True : sal_False );
1837 SdrUndoAction* SdrUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect )
1839 return new SdrUndoRemoveObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1842 SdrUndoAction* SdrUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect )
1844 return new SdrUndoInsertObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1847 SdrUndoAction* SdrUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
1849 return new SdrUndoDelObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1852 SdrUndoAction* SdrUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect )
1854 return new SdrUndoNewObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1857 SdrUndoAction* SdrUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect )
1859 return new SdrUndoCopyObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1862 SdrUndoAction* SdrUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
1864 return new SdrUndoObjOrdNum( rObject, nOldOrdNum1, nNewOrdNum1 );
1867 SdrUndoAction* SdrUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect )
1869 return new SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect ? sal_True : sal_False );
1872 SdrUndoAction* SdrUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer )
1874 return new SdrUndoObjectLayerChange( rObject, aOldLayer, aNewLayer );
1877 SdrUndoAction* SdrUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText )
1879 return new SdrUndoObjSetText( rNewObj, nText );
1882 SdrUndoAction* SdrUndoFactory::CreateUndoObjectStrAttr( SdrObject& rObject,
1883 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType,
1884 const OUString& sOldStr,
1885 const OUString& sNewStr )
1887 return new SdrUndoObjStrAttr( rObject, eObjStrAttrType, sOldStr, sNewStr );
1891 // layer
1892 SdrUndoAction* SdrUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1894 return new SdrUndoNewLayer( nLayerNum, rNewLayerAdmin, rNewModel );
1897 SdrUndoAction* SdrUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1899 return new SdrUndoDelLayer( nLayerNum, rNewLayerAdmin, rNewModel );
1902 SdrUndoAction* SdrUndoFactory::CreateUndoMoveLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel, sal_uInt16 nNeuPos1)
1904 return new SdrUndoMoveLayer( nLayerNum, rNewLayerAdmin, rNewModel, nNeuPos1 );
1907 // page
1908 SdrUndoAction* SdrUndoFactory::CreateUndoDeletePage(SdrPage& rPage)
1910 return new SdrUndoDelPage( rPage );
1913 SdrUndoAction* SdrUndoFactory::CreateUndoNewPage(SdrPage& rPage)
1915 return new SdrUndoNewPage( rPage );
1918 SdrUndoAction* SdrUndoFactory::CreateUndoCopyPage(SdrPage& rPage)
1920 return new SdrUndoCopyPage( rPage );
1923 SdrUndoAction* SdrUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1)
1925 return new SdrUndoSetPageNum( rNewPg, nOldPageNum1, nNewPageNum1 );
1927 // master page
1928 SdrUndoAction* SdrUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1930 return new SdrUndoPageRemoveMasterPage( rChangedPage );
1933 SdrUndoAction* SdrUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage)
1935 return new SdrUndoPageChangeMasterPage(rChangedPage);
1939 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */