bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / svdraw / svdundo.cxx
blobe2111226ef157cbb96d5b79e910c598b2ab6d3cf
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" // names taken from the resource
31 #include "svx/svdglob.hxx" // StringCache
32 #include <svx/scene3d.hxx>
33 #include <editeng/editdata.hxx>
34 #include <editeng/outlobj.hxx>
35 #include <svx/svdogrp.hxx>
36 #include <svx/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>
42 #include "svx/svdviter.hxx"
44 ////////////////////////////////////////////////////////////////////////////////////////////////////
46 // iterates over all views and unmarks this SdrObject if it is marked
47 static void ImplUnmarkObject( SdrObject* pObj )
49 SdrViewIter aIter( pObj );
50 for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
52 pView->MarkObj( pObj, pView->GetSdrPageView(), sal_True );
56 ////////////////////////////////////////////////////////////////////////////////////////////////////
58 TYPEINIT1(SdrUndoAction,SfxUndoAction);
60 SdrUndoAction::~SdrUndoAction() {}
62 sal_Bool SdrUndoAction::CanRepeat(SfxRepeatTarget& rView) const
64 SdrView* pV=PTR_CAST(SdrView,&rView);
65 if (pV!=NULL) return CanSdrRepeat(*pV);
66 return sal_False;
69 void SdrUndoAction::Repeat(SfxRepeatTarget& rView)
71 SdrView* pV=PTR_CAST(SdrView,&rView);
72 if (pV!=NULL) SdrRepeat(*pV);
73 DBG_ASSERT(pV!=NULL,"Repeat: SfxRepeatTarget that was handed over is not a SdrView");
76 OUString SdrUndoAction::GetRepeatComment(SfxRepeatTarget& rView) const
78 SdrView* pV=PTR_CAST(SdrView,&rView);
79 if (pV!=NULL) return GetSdrRepeatComment(*pV);
80 return OUString();
83 bool SdrUndoAction::CanSdrRepeat(SdrView& /*rView*/) const
85 return sal_False;
88 void SdrUndoAction::SdrRepeat(SdrView& /*rView*/)
92 OUString SdrUndoAction::GetSdrRepeatComment(SdrView& /*rView*/) const
94 return String();
97 ////////////////////////////////////////////////////////////////////////////////////////////////////
99 SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod)
100 : SdrUndoAction(rNewMod),
101 aBuf(),
102 eFunction(SDRREPFUNC_OBJ_NONE)
105 SdrUndoGroup::~SdrUndoGroup()
107 Clear();
110 void SdrUndoGroup::Clear()
112 for (sal_uIntPtr nu=0; nu<GetActionCount(); nu++) {
113 SdrUndoAction* pAct=GetAction(nu);
114 delete pAct;
116 aBuf.clear();
119 void SdrUndoGroup::AddAction(SdrUndoAction* pAct)
121 aBuf.push_back(pAct);
124 void SdrUndoGroup::Undo()
126 for (sal_uIntPtr nu=GetActionCount(); nu>0;) {
127 nu--;
128 SdrUndoAction* pAct=GetAction(nu);
129 pAct->Undo();
133 void SdrUndoGroup::Redo()
135 for (sal_uIntPtr nu=0; nu<GetActionCount(); nu++) {
136 SdrUndoAction* pAct=GetAction(nu);
137 pAct->Redo();
141 OUString SdrUndoGroup::GetComment() const
143 return aComment.replaceAll("%1", aObjDescription);
146 bool SdrUndoGroup::CanSdrRepeat(SdrView& rView) const
148 switch (eFunction) {
149 case SDRREPFUNC_OBJ_NONE : return sal_False;
150 case SDRREPFUNC_OBJ_DELETE : return rView.AreObjectsMarked();
151 case SDRREPFUNC_OBJ_COMBINE_POLYPOLY: return rView.IsCombinePossible(sal_False);
152 case SDRREPFUNC_OBJ_COMBINE_ONEPOLY : return rView.IsCombinePossible(sal_True);
153 case SDRREPFUNC_OBJ_DISMANTLE_POLYS : return rView.IsDismantlePossible(sal_False);
154 case SDRREPFUNC_OBJ_DISMANTLE_LINES : return rView.IsDismantlePossible(sal_True);
155 case SDRREPFUNC_OBJ_CONVERTTOPOLY : return rView.IsConvertToPolyObjPossible(sal_False);
156 case SDRREPFUNC_OBJ_CONVERTTOPATH : return rView.IsConvertToPathObjPossible(sal_False);
157 case SDRREPFUNC_OBJ_GROUP : return rView.IsGroupPossible();
158 case SDRREPFUNC_OBJ_UNGROUP : return rView.IsUnGroupPossible();
159 case SDRREPFUNC_OBJ_PUTTOTOP : return rView.IsToTopPossible();
160 case SDRREPFUNC_OBJ_PUTTOBTM : return rView.IsToBtmPossible();
161 case SDRREPFUNC_OBJ_MOVTOTOP : return rView.IsToTopPossible();
162 case SDRREPFUNC_OBJ_MOVTOBTM : return rView.IsToBtmPossible();
163 case SDRREPFUNC_OBJ_REVORDER : return rView.IsReverseOrderPossible();
164 case SDRREPFUNC_OBJ_IMPORTMTF : return rView.IsImportMtfPossible();
165 default: break;
166 } // switch
167 return sal_False;
170 void SdrUndoGroup::SdrRepeat(SdrView& rView)
172 switch (eFunction) {
173 case SDRREPFUNC_OBJ_NONE : break;
174 case SDRREPFUNC_OBJ_DELETE : rView.DeleteMarked(); break;
175 case SDRREPFUNC_OBJ_COMBINE_POLYPOLY: rView.CombineMarkedObjects(sal_False); break;
176 case SDRREPFUNC_OBJ_COMBINE_ONEPOLY : rView.CombineMarkedObjects(sal_True); break;
177 case SDRREPFUNC_OBJ_DISMANTLE_POLYS : rView.DismantleMarkedObjects(sal_False); break;
178 case SDRREPFUNC_OBJ_DISMANTLE_LINES : rView.DismantleMarkedObjects(sal_True); break;
179 case SDRREPFUNC_OBJ_CONVERTTOPOLY : rView.ConvertMarkedToPolyObj(sal_False); break;
180 case SDRREPFUNC_OBJ_CONVERTTOPATH : rView.ConvertMarkedToPathObj(sal_False); break;
181 case SDRREPFUNC_OBJ_GROUP : rView.GroupMarked(); break;
182 case SDRREPFUNC_OBJ_UNGROUP : rView.UnGroupMarked(); break;
183 case SDRREPFUNC_OBJ_PUTTOTOP : rView.PutMarkedToTop(); break;
184 case SDRREPFUNC_OBJ_PUTTOBTM : rView.PutMarkedToBtm(); break;
185 case SDRREPFUNC_OBJ_MOVTOTOP : rView.MovMarkedToTop(); break;
186 case SDRREPFUNC_OBJ_MOVTOBTM : rView.MovMarkedToBtm(); break;
187 case SDRREPFUNC_OBJ_REVORDER : rView.ReverseOrderOfMarked(); break;
188 case SDRREPFUNC_OBJ_IMPORTMTF : rView.DoImportMarkedMtf(); break;
189 default: break;
190 } // switch
193 OUString SdrUndoGroup::GetSdrRepeatComment(SdrView& /*rView*/) const
195 return aComment.replaceAll("%1", ImpGetResStr(STR_ObjNameSingulPlural));
198 SdrUndoObj::SdrUndoObj(SdrObject& rNewObj):
199 SdrUndoAction(*rNewObj.GetModel()),
200 pObj(&rNewObj)
204 void SdrUndoObj::GetDescriptionStringForObject( const SdrObject& _rForObject, sal_uInt16 nStrCacheID, String& rStr, bool bRepeat )
206 rStr = ImpGetResStr(nStrCacheID);
208 String aSearchString(RTL_CONSTASCII_USTRINGPARAM("%1"));
210 xub_StrLen nPos = rStr.Search(aSearchString);
212 if(nPos != STRING_NOTFOUND)
214 rStr.Erase(nPos, 2);
216 if(bRepeat)
218 rStr.Insert(ImpGetResStr(STR_ObjNameSingulPlural), nPos);
220 else
222 XubString aStr;
223 _rForObject.TakeObjNameSingul(aStr);
224 rStr.Insert(aStr, nPos);
229 void SdrUndoObj::ImpTakeDescriptionStr(sal_uInt16 nStrCacheID, XubString& rStr, bool bRepeat) const
231 if ( pObj )
232 GetDescriptionStringForObject( *pObj, nStrCacheID, rStr, 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 UniString aParent(rSheet.GetParent());
259 rSheet.SetParent(UniString());
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(sal_True),
273 pTextUndo(NULL),
275 // #i8508#
276 pTextRedo(NULL),
278 pUndoGroup(NULL)
280 bStyleSheet = bStyleSheet1;
282 SdrObjList* pOL = rNewObj.GetSubList();
283 bool bIsGroup(pOL!=NULL && pOL->GetObjCount());
284 bool bIs3DScene(bIsGroup && pObj->ISA(E3dScene));
286 if(bIsGroup)
288 // it's a group object!
289 pUndoGroup = new SdrUndoGroup(*pObj->GetModel());
290 sal_uInt32 nObjAnz(pOL->GetObjCount());
292 for(sal_uInt32 nObjNum(0); nObjNum < nObjAnz; nObjNum++)
294 pUndoGroup->AddAction(
295 new SdrUndoAttrObj(*pOL->GetObj(nObjNum), bStyleSheet1));
299 if(!bIsGroup || bIs3DScene)
301 pUndoSet = new SfxItemSet(pObj->GetMergedItemSet());
303 if(bStyleSheet)
304 mxUndoStyleSheet = pObj->GetStyleSheet();
306 if(bSaveText)
308 pTextUndo = pObj->GetOutlinerParaObject();
309 if(pTextUndo)
310 pTextUndo = new OutlinerParaObject(*pTextUndo);
315 SdrUndoAttrObj::~SdrUndoAttrObj()
317 delete pUndoSet;
318 delete pRedoSet;
319 delete pRepeatSet;
320 delete pUndoGroup;
321 delete pTextUndo;
323 // #i8508#
324 delete pTextRedo;
327 void SdrUndoAttrObj::Undo()
329 E3DModifySceneSnapRectUpdater aUpdater(pObj);
330 bool bIs3DScene(pObj && pObj->ISA(E3dScene));
332 // Trigger PageChangeCall
333 ImpShowPageOfThisObject();
335 if(!pUndoGroup || bIs3DScene)
337 if(bHaveToTakeRedoSet)
339 bHaveToTakeRedoSet = sal_False;
341 delete pRedoSet;
343 pRedoSet = new SfxItemSet(pObj->GetMergedItemSet());
345 if(bStyleSheet)
346 mxRedoStyleSheet = pObj->GetStyleSheet();
348 if(pTextUndo)
350 // #i8508#
351 pTextRedo = pObj->GetOutlinerParaObject();
353 if(pTextRedo)
354 pTextRedo = new OutlinerParaObject(*pTextRedo);
358 if(bStyleSheet)
360 mxRedoStyleSheet = pObj->GetStyleSheet();
361 SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxUndoStyleSheet.get());
363 if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
365 ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
366 pObj->SetStyleSheet(pSheet, sal_True);
368 else
370 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
374 sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
376 // Since ClearItem sets back everything to normal
377 // it also sets fit-to-size text to non-fit-to-size text and
378 // switches on autogrowheight (the default). That may lead to
379 // loosing the geometry size info for the object when it is
380 // laid out again from AdjustTextFrameWidthAndHeight(). This makes
381 // rescuing the size of the object necessary.
382 const Rectangle aSnapRect = pObj->GetSnapRect();
384 if(pUndoSet)
386 if(pObj->ISA(SdrCaptionObj))
388 // do a more smooth item deletion here, else the text
389 // rect will be reformatted, especially when information regarding
390 // vertical text is changed. When clearing only set items it's
391 // slower, but safer regarding such information (it's not changed
392 // usually)
393 SfxWhichIter aIter(*pUndoSet);
394 sal_uInt16 nWhich(aIter.FirstWhich());
396 while(nWhich)
398 if(SFX_ITEM_SET != pUndoSet->GetItemState(nWhich, sal_False))
400 pObj->ClearMergedItem(nWhich);
403 nWhich = aIter.NextWhich();
406 else
408 pObj->ClearMergedItem();
411 pObj->SetMergedItemSet(*pUndoSet);
414 // Restore previous size here when it was changed.
415 if(aSnapRect != pObj->GetSnapRect())
417 pObj->NbcSetSnapRect(aSnapRect);
420 pObj->GetProperties().BroadcastItemChange(aItemChange);
422 if(pTextUndo)
424 pObj->SetOutlinerParaObject(new OutlinerParaObject(*pTextUndo));
428 if(pUndoGroup)
430 pUndoGroup->Undo();
434 void SdrUndoAttrObj::Redo()
436 E3DModifySceneSnapRectUpdater aUpdater(pObj);
437 bool bIs3DScene(pObj && pObj->ISA(E3dScene));
439 if(!pUndoGroup || bIs3DScene)
441 if(bStyleSheet)
443 mxUndoStyleSheet = pObj->GetStyleSheet();
444 SfxStyleSheet* pSheet = dynamic_cast< SfxStyleSheet* >(mxRedoStyleSheet.get());
446 if(pSheet && pObj->GetModel() && pObj->GetModel()->GetStyleSheetPool())
448 ensureStyleSheetInStyleSheetPool(*pObj->GetModel()->GetStyleSheetPool(), *pSheet);
449 pObj->SetStyleSheet(pSheet, sal_True);
451 else
453 OSL_ENSURE(false, "OOps, something went wrong in SdrUndoAttrObj (!)");
457 sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
459 const Rectangle aSnapRect = pObj->GetSnapRect();
461 if(pRedoSet)
463 if(pObj->ISA(SdrCaptionObj))
465 // do a more smooth item deletion here, else the text
466 // rect will be reformatted, especially when information regarding
467 // vertical text is changed. When clearing only set items it's
468 // slower, but safer regarding such information (it's not changed
469 // usually)
470 SfxWhichIter aIter(*pRedoSet);
471 sal_uInt16 nWhich(aIter.FirstWhich());
473 while(nWhich)
475 if(SFX_ITEM_SET != pRedoSet->GetItemState(nWhich, sal_False))
477 pObj->ClearMergedItem(nWhich);
480 nWhich = aIter.NextWhich();
483 else
485 pObj->ClearMergedItem();
488 pObj->SetMergedItemSet(*pRedoSet);
491 // Restore previous size here when it was changed.
492 if(aSnapRect != pObj->GetSnapRect())
494 pObj->NbcSetSnapRect(aSnapRect);
497 pObj->GetProperties().BroadcastItemChange(aItemChange);
499 // #i8508#
500 if(pTextRedo)
502 pObj->SetOutlinerParaObject(new OutlinerParaObject(*pTextRedo));
506 if(pUndoGroup)
508 pUndoGroup->Redo();
511 // Trigger PageChangeCall
512 ImpShowPageOfThisObject();
515 OUString SdrUndoAttrObj::GetComment() const
517 XubString aStr;
519 if(bStyleSheet)
521 ImpTakeDescriptionStr(STR_EditSetStylesheet, aStr);
523 else
525 ImpTakeDescriptionStr(STR_EditSetAttributes, aStr);
528 return aStr;
531 void SdrUndoAttrObj::SdrRepeat(SdrView& rView)
533 if(pRepeatSet)
535 rView.SetAttrToMarked(*pRepeatSet, sal_False);
539 bool SdrUndoAttrObj::CanSdrRepeat(SdrView& rView) const
541 return (pRepeatSet!=0L && rView.AreObjectsMarked());
544 OUString SdrUndoAttrObj::GetSdrRepeatComment(SdrView& /*rView*/) const
546 XubString aStr;
548 if(bStyleSheet)
550 ImpTakeDescriptionStr(STR_EditSetStylesheet, aStr, sal_True);
552 else
554 ImpTakeDescriptionStr(STR_EditSetAttributes, aStr, sal_True);
557 return aStr;
560 ////////////////////////////////////////////////////////////////////////////////////////////////////
562 SdrUndoMoveObj::~SdrUndoMoveObj() {}
564 void SdrUndoMoveObj::Undo()
566 // Trigger PageChangeCall
567 ImpShowPageOfThisObject();
569 pObj->Move(Size(-aDistance.Width(),-aDistance.Height()));
572 void SdrUndoMoveObj::Redo()
574 pObj->Move(Size(aDistance.Width(),aDistance.Height()));
576 // Trigger PageChangeCall
577 ImpShowPageOfThisObject();
580 OUString SdrUndoMoveObj::GetComment() const
582 XubString aStr;
583 ImpTakeDescriptionStr(STR_EditMove,aStr);
584 return aStr;
587 void SdrUndoMoveObj::SdrRepeat(SdrView& rView)
589 rView.MoveMarkedObj(aDistance);
592 bool SdrUndoMoveObj::CanSdrRepeat(SdrView& rView) const
594 return rView.AreObjectsMarked();
597 OUString SdrUndoMoveObj::GetSdrRepeatComment(SdrView& /*rView*/) const
599 XubString aStr;
600 ImpTakeDescriptionStr(STR_EditMove,aStr,sal_True);
601 return aStr;
604 ////////////////////////////////////////////////////////////////////////////////////////////////////
606 SdrUndoGeoObj::SdrUndoGeoObj(SdrObject& rNewObj):
607 SdrUndoObj(rNewObj),
608 pUndoGeo(NULL),
609 pRedoGeo(NULL),
610 pUndoGroup(NULL)
612 SdrObjList* pOL=rNewObj.GetSubList();
613 if (pOL!=NULL && pOL->GetObjCount() && !rNewObj.ISA(E3dScene))
615 // this is a group object!
616 // If this were 3D scene, we'd only add an Undo for the scene itself
617 // (which we do elsewhere).
618 pUndoGroup=new SdrUndoGroup(*pObj->GetModel());
619 sal_uIntPtr nObjAnz=pOL->GetObjCount();
620 for (sal_uIntPtr nObjNum=0; nObjNum<nObjAnz; nObjNum++) {
621 pUndoGroup->AddAction(new SdrUndoGeoObj(*pOL->GetObj(nObjNum)));
623 } else {
624 pUndoGeo=pObj->GetGeoData();
628 SdrUndoGeoObj::~SdrUndoGeoObj()
630 delete pUndoGeo;
631 delete pRedoGeo;
632 delete pUndoGroup;
635 void SdrUndoGeoObj::Undo()
637 // Trigger PageChangeCall
638 ImpShowPageOfThisObject();
640 if(pUndoGroup)
642 pUndoGroup->Undo();
644 // only repaint, no objectchange
645 pObj->ActionChanged();
647 else
649 delete pRedoGeo;
650 pRedoGeo=pObj->GetGeoData();
651 pObj->SetGeoData(*pUndoGeo);
655 void SdrUndoGeoObj::Redo()
657 if(pUndoGroup)
659 pUndoGroup->Redo();
661 // only repaint, no objectchange
662 pObj->ActionChanged();
664 else
666 delete pUndoGeo;
667 pUndoGeo=pObj->GetGeoData();
668 pObj->SetGeoData(*pRedoGeo);
671 // Trigger PageChangeCall
672 ImpShowPageOfThisObject();
675 OUString SdrUndoGeoObj::GetComment() const
677 XubString aStr;
678 ImpTakeDescriptionStr(STR_DragMethObjOwn,aStr);
679 return aStr;
682 ////////////////////////////////////////////////////////////////////////////////////////////////////
684 class SdrUndoObjList::ObjListListener : public SfxListener
686 public:
687 ObjListListener(SdrUndoObjList& rThat, SdrObject& rObject, SfxBroadcaster& rBroadcaster);
688 ~ObjListListener();
690 private:
691 virtual void Notify(SfxBroadcaster& rBroadcaster, const SfxHint& rHint);
693 private:
694 SdrUndoObjList& m_rThat;
695 SdrObject& m_rObject;
696 SfxBroadcaster* m_pBroadcaster;
699 SdrUndoObjList::ObjListListener::ObjListListener(SdrUndoObjList& rThat, SdrObject& rObject, SfxBroadcaster& rBroadcaster)
700 : m_rThat(rThat)
701 , m_rObject(rObject)
702 , m_pBroadcaster(&rBroadcaster)
704 StartListening(*m_pBroadcaster);
707 SdrUndoObjList::ObjListListener::~ObjListListener()
709 if (m_pBroadcaster)
710 EndListening(*m_pBroadcaster);
713 void SdrUndoObjList::ObjListListener::Notify(SfxBroadcaster&, const SfxHint& rHint)
715 const SdrHint* const pSdrHint(dynamic_cast<const SdrHint*>(&rHint));
716 if (pSdrHint)
718 if (pSdrHint->GetObject() == &m_rObject)
720 switch (pSdrHint->GetKind())
722 case HINT_OBJCHG :
723 if (IsListening(*m_pBroadcaster))
725 const sal_uInt32 nNewOrdNum(m_rObject.GetOrdNum());
726 if (nNewOrdNum != m_rThat.GetOrdNum())
727 m_rThat.SetOrdNum(nNewOrdNum);
729 break;
730 case HINT_OBJREMOVED :
731 SAL_WARN_IF(!IsListening(*m_pBroadcaster), "svx.sdr", "Object is not in any list");
732 EndListening(*m_pBroadcaster);
733 break;
734 case HINT_OBJINSERTED :
735 SAL_WARN_IF(IsListening(*m_pBroadcaster), "svx.sdr", "Object is already in a list");
736 StartListening(*m_pBroadcaster);
737 break;
738 default :
739 break;
745 SdrUndoObjList::SdrUndoObjList(SdrObject& rNewObj, bool bOrdNumDirect)
746 : SdrUndoObj(rNewObj),
747 bOwner(sal_False),
748 pView(NULL),
749 pPageView(NULL),
750 m_pListener(NULL)
752 pObjList=pObj->GetObjList();
753 if (bOrdNumDirect) {
754 nOrdNum=pObj->GetOrdNumDirect();
755 } 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(sal_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_;
791 ////////////////////////////////////////////////////////////////////////////////////////////////////
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 ////////////////////////////////////////////////////////////////////////////////////////////////////
841 void SdrUndoInsertObj::Undo()
843 // Trigger PageChangeCall
844 ImpShowPageOfThisObject();
846 DBG_ASSERT(pObj->IsInserted(),"UndoInsertObj: pObj is not inserted.");
847 if (pObj->IsInserted())
849 ImplUnmarkObject( pObj );
851 #ifdef DBG_UTIL
852 SdrObject* pChkObj=
853 #endif
854 pObjList->RemoveObject(nOrdNum);
855 DBG_ASSERT(pChkObj==pObj,"UndoInsertObj: RemoveObjNum!=pObj");
859 void SdrUndoInsertObj::Redo()
861 DBG_ASSERT(!pObj->IsInserted(),"RedoInsertObj: pObj is already inserted");
862 if (!pObj->IsInserted())
864 // Restore anchor position of an object,
865 // which becomes a member of a group, because its cleared in method
866 // <InsertObject(..)>. Needed for correct Redo in Writer. (#i45952#)
867 Point aAnchorPos( 0, 0 );
868 if ( pObjList &&
869 pObjList->GetOwnerObj() &&
870 pObjList->GetOwnerObj()->ISA(SdrObjGroup) )
872 aAnchorPos = pObj->GetAnchorPos();
875 SdrInsertReason aReason(SDRREASON_UNDO);
876 pObjList->InsertObject(pObj,nOrdNum,&aReason);
878 // Arcs lose position when grouped (#i45952#)
879 if ( aAnchorPos.X() || aAnchorPos.Y() )
881 pObj->NbcSetAnchorPos( aAnchorPos );
885 // Trigger PageChangeCall
886 ImpShowPageOfThisObject();
889 ////////////////////////////////////////////////////////////////////////////////////////////////////
891 void SdrUndoDelObj::Undo()
893 SdrUndoRemoveObj::Undo();
894 DBG_ASSERT(IsOwner(),"UndoDeleteObj: pObj does not belong to UndoAction");
895 SetOwner(sal_False);
898 void SdrUndoDelObj::Redo()
900 SdrUndoRemoveObj::Redo();
901 DBG_ASSERT(!IsOwner(),"RedoDeleteObj: pObj already belongs to UndoAction");
902 SetOwner(sal_True);
905 OUString SdrUndoDelObj::GetComment() const
907 XubString aStr;
908 ImpTakeDescriptionStr(STR_EditDelete,aStr);
909 return aStr;
912 void SdrUndoDelObj::SdrRepeat(SdrView& rView)
914 rView.DeleteMarked();
917 bool SdrUndoDelObj::CanSdrRepeat(SdrView& rView) const
919 return rView.AreObjectsMarked();
922 OUString SdrUndoDelObj::GetSdrRepeatComment(SdrView& /*rView*/) const
924 XubString aStr;
925 ImpTakeDescriptionStr(STR_EditDelete,aStr,sal_True);
926 return aStr;
929 ////////////////////////////////////////////////////////////////////////////////////////////////////
931 void SdrUndoNewObj::Undo()
933 SdrUndoInsertObj::Undo();
934 DBG_ASSERT(!IsOwner(),"RedoNewObj: pObj already belongs to UndoAction");
935 SetOwner(sal_True);
938 void SdrUndoNewObj::Redo()
940 SdrUndoInsertObj::Redo();
941 DBG_ASSERT(IsOwner(),"RedoNewObj: pObj does not belong to UndoAction");
942 SetOwner(sal_False);
945 OUString SdrUndoNewObj::GetComment( const SdrObject& _rForObject )
947 String sComment;
948 GetDescriptionStringForObject( _rForObject, STR_UndoInsertObj, sComment );
949 return sComment;
952 OUString SdrUndoNewObj::GetComment() const
954 XubString aStr;
955 ImpTakeDescriptionStr(STR_UndoInsertObj,aStr);
956 return aStr;
959 SdrUndoReplaceObj::SdrUndoReplaceObj(SdrObject& rOldObj1, SdrObject& rNewObj1, bool bOrdNumDirect)
960 : SdrUndoObj(rOldObj1),
961 bOldOwner(sal_False),
962 bNewOwner(sal_False),
963 pNewObj(&rNewObj1)
965 SetOldOwner(sal_True);
967 pObjList=pObj->GetObjList();
968 if (bOrdNumDirect) {
969 nOrdNum=pObj->GetOrdNumDirect();
970 } else {
971 nOrdNum=pObj->GetOrdNum();
975 SdrUndoReplaceObj::~SdrUndoReplaceObj()
977 if (pObj!=NULL && IsOldOwner())
979 // Attribute have to go back into the Pool
980 SetOldOwner(sal_False);
982 // now delete
983 SdrObject::Free( pObj );
985 if (pNewObj!=NULL && IsNewOwner())
987 // Attribute have to go back into the Pool
988 SetNewOwner(sal_False);
990 // now delete
991 SdrObject::Free( pNewObj );
995 void SdrUndoReplaceObj::Undo()
997 // Trigger PageChangeCall
998 ImpShowPageOfThisObject();
1000 if (IsOldOwner() && !IsNewOwner())
1002 DBG_ASSERT(!pObj->IsInserted(),"SdrUndoReplaceObj::Undo(): Old object is already inserted!");
1003 DBG_ASSERT(pNewObj->IsInserted(),"SdrUndoReplaceObj::Undo(): New object is not inserted!");
1004 SetOldOwner(sal_False);
1005 SetNewOwner(sal_True);
1007 ImplUnmarkObject( pNewObj );
1008 pObjList->ReplaceObject(pObj,nOrdNum);
1010 else
1012 OSL_FAIL("SdrUndoReplaceObj::Undo(): Wrong IsMine flags. Did you call Undo twice?");
1016 void SdrUndoReplaceObj::Redo()
1018 if (!IsOldOwner() && IsNewOwner())
1020 DBG_ASSERT(!pNewObj->IsInserted(),"SdrUndoReplaceObj::Redo(): New object is already inserted!!");
1021 DBG_ASSERT(pObj->IsInserted(),"SdrUndoReplaceObj::Redo(): Old object is not inserted!!");
1022 SetOldOwner(sal_True);
1023 SetNewOwner(sal_False);
1025 ImplUnmarkObject( pObj );
1026 pObjList->ReplaceObject(pNewObj,nOrdNum);
1029 else
1031 OSL_FAIL("SdrUndoReplaceObj::Redo(): Wrong IsMine flags. Did you call Redo twice?");
1034 // Trigger PageChangeCall
1035 ImpShowPageOfThisObject();
1038 void SdrUndoReplaceObj::SetNewOwner(bool bNew)
1040 bNewOwner = bNew;
1043 void SdrUndoReplaceObj::SetOldOwner(bool bNew)
1045 bOldOwner = bNew;
1048 ////////////////////////////////////////////////////////////////////////////////////////////////////
1050 OUString SdrUndoCopyObj::GetComment() const
1052 XubString aStr;
1053 ImpTakeDescriptionStr(STR_UndoCopyObj,aStr);
1054 return aStr;
1057 ////////////////////////////////////////////////////////////////////////////////////////////////////
1058 // #i11702#
1060 SdrUndoObjectLayerChange::SdrUndoObjectLayerChange(SdrObject& rObj, SdrLayerID aOldLayer, SdrLayerID aNewLayer)
1061 : SdrUndoObj(rObj),
1062 maOldLayer(aOldLayer),
1063 maNewLayer(aNewLayer)
1067 void SdrUndoObjectLayerChange::Undo()
1069 ImpShowPageOfThisObject();
1070 pObj->SetLayer(maOldLayer);
1073 void SdrUndoObjectLayerChange::Redo()
1075 pObj->SetLayer(maNewLayer);
1076 ImpShowPageOfThisObject();
1079 ////////////////////////////////////////////////////////////////////////////////////////////////////
1081 SdrUndoObjOrdNum::SdrUndoObjOrdNum(SdrObject& rNewObj, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1):
1082 SdrUndoObj(rNewObj),
1083 nOldOrdNum(nOldOrdNum1),
1084 nNewOrdNum(nNewOrdNum1)
1088 void SdrUndoObjOrdNum::Undo()
1090 // Trigger PageChangeCall
1091 ImpShowPageOfThisObject();
1093 SdrObjList* pOL=pObj->GetObjList();
1094 if (pOL==NULL) {
1095 OSL_FAIL("UndoObjOrdNum: pObj does not have an ObjList.");
1096 return;
1098 pOL->SetObjectOrdNum(nNewOrdNum,nOldOrdNum);
1101 void SdrUndoObjOrdNum::Redo()
1103 SdrObjList* pOL=pObj->GetObjList();
1104 if (pOL==NULL) {
1105 OSL_FAIL("RedoObjOrdNum: pObj does not have an ObjList.");
1106 return;
1108 pOL->SetObjectOrdNum(nOldOrdNum,nNewOrdNum);
1110 // Trigger PageChangeCall
1111 ImpShowPageOfThisObject();
1114 OUString SdrUndoObjOrdNum::GetComment() const
1116 XubString aStr;
1117 ImpTakeDescriptionStr(STR_UndoObjOrdNum,aStr);
1118 return aStr;
1121 ////////////////////////////////////////////////////////////////////////////////////////////////////
1123 SdrUndoObjSetText::SdrUndoObjSetText(SdrObject& rNewObj, sal_Int32 nText)
1124 : SdrUndoObj(rNewObj)
1125 , pOldText(NULL)
1126 , pNewText(NULL)
1127 , bNewTextAvailable(sal_False)
1128 , bEmptyPresObj(sal_False)
1129 , mnText(nText)
1131 SdrText* pText = static_cast< SdrTextObj*>( &rNewObj )->getText(mnText);
1132 if( pText && pText->GetOutlinerParaObject() )
1133 pOldText = new OutlinerParaObject(*pText->GetOutlinerParaObject());
1135 bEmptyPresObj = rNewObj.IsEmptyPresObj();
1138 SdrUndoObjSetText::~SdrUndoObjSetText()
1140 delete pOldText;
1141 delete pNewText;
1144 void SdrUndoObjSetText::AfterSetText()
1146 if (!bNewTextAvailable)
1148 SdrText* pText = static_cast< SdrTextObj*>( pObj )->getText(mnText);
1149 if( pText && pText->GetOutlinerParaObject() )
1150 pNewText = new OutlinerParaObject(*pText->GetOutlinerParaObject());
1151 bNewTextAvailable=sal_True;
1155 void SdrUndoObjSetText::Undo()
1157 // Trigger PageChangeCall
1158 ImpShowPageOfThisObject();
1160 // save old text for Redo
1161 if (!bNewTextAvailable)
1162 AfterSetText();
1164 SdrText* pText = static_cast< SdrTextObj*>( pObj )->getText(mnText);
1165 if (pText)
1167 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1168 OutlinerParaObject* pText1 = pOldText ? new OutlinerParaObject(*pOldText) : NULL;
1169 pText->SetOutlinerParaObject(pText1);
1172 pObj->SetEmptyPresObj( bEmptyPresObj );
1173 pObj->ActionChanged();
1175 // #i122410# SetOutlinerParaObject at SdrText does not trigger a
1176 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1177 // update their preview.
1178 pObj->BroadcastObjectChange();
1181 void SdrUndoObjSetText::Redo()
1183 SdrText* pText = static_cast< SdrTextObj*>( pObj )->getText(mnText);
1184 if (pText)
1186 // copy text for Undo, because the original now belongs to SetOutlinerParaObject()
1187 OutlinerParaObject* pText1 = pNewText ? new OutlinerParaObject(*pNewText) : NULL;
1188 static_cast< SdrTextObj* >( pObj )->NbcSetOutlinerParaObjectForText( pText1, pText );
1190 pObj->ActionChanged();
1192 // #i122410# NbcSetOutlinerParaObjectForText at SdrTextObj does not trigger a
1193 // BroadcastObjectChange, but it is needed to make evtl. SlideSorters
1194 // update their preview.
1195 pObj->BroadcastObjectChange();
1197 // Trigger PageChangeCall
1198 ImpShowPageOfThisObject();
1201 OUString SdrUndoObjSetText::GetComment() const
1203 XubString aStr;
1204 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1205 return aStr;
1208 OUString SdrUndoObjSetText::GetSdrRepeatComment(SdrView& /*rView*/) const
1210 XubString aStr;
1211 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1212 return aStr;
1215 void SdrUndoObjSetText::SdrRepeat(SdrView& rView)
1217 if (bNewTextAvailable && rView.AreObjectsMarked())
1219 const SdrMarkList& rML=rView.GetMarkedObjectList();
1221 const bool bUndo = rView.IsUndoEnabled();
1222 if( bUndo )
1224 XubString aStr;
1225 ImpTakeDescriptionStr(STR_UndoObjSetText,aStr);
1226 rView.BegUndo(aStr);
1229 sal_uIntPtr nAnz=rML.GetMarkCount();
1230 for (sal_uIntPtr nm=0; nm<nAnz; nm++)
1232 SdrObject* pObj2=rML.GetMark(nm)->GetMarkedSdrObj();
1233 SdrTextObj* pTextObj=PTR_CAST(SdrTextObj,pObj2);
1234 if (pTextObj!=NULL)
1236 if( bUndo )
1237 rView.AddUndo(new SdrUndoObjSetText(*pTextObj,0));
1239 OutlinerParaObject* pText1=pNewText;
1240 if (pText1!=NULL)
1241 pText1 = new OutlinerParaObject(*pText1);
1242 pTextObj->SetOutlinerParaObject(pText1);
1246 if( bUndo )
1247 rView.EndUndo();
1251 bool SdrUndoObjSetText::CanSdrRepeat(SdrView& rView) const
1253 bool bOk = false;
1254 if (bNewTextAvailable && rView.AreObjectsMarked()) {
1255 bOk=sal_True;
1257 return bOk;
1260 // Undo/Redo for setting object's name (#i73249#)
1261 SdrUndoObjStrAttr::SdrUndoObjStrAttr( SdrObject& rNewObj,
1262 const ObjStrAttrType eObjStrAttr,
1263 const String& sOldStr,
1264 const String& sNewStr)
1265 : SdrUndoObj( rNewObj ),
1266 meObjStrAttr( eObjStrAttr ),
1267 msOldStr( sOldStr ),
1268 msNewStr( sNewStr )
1272 void SdrUndoObjStrAttr::Undo()
1274 ImpShowPageOfThisObject();
1276 switch ( meObjStrAttr )
1278 case OBJ_NAME:
1280 pObj->SetName( msOldStr );
1282 break;
1283 case OBJ_TITLE:
1285 pObj->SetTitle( msOldStr );
1287 break;
1288 case OBJ_DESCRIPTION:
1290 pObj->SetDescription( msOldStr );
1292 break;
1296 void SdrUndoObjStrAttr::Redo()
1298 switch ( meObjStrAttr )
1300 case OBJ_NAME:
1302 pObj->SetName( msNewStr );
1304 break;
1305 case OBJ_TITLE:
1307 pObj->SetTitle( msNewStr );
1309 break;
1310 case OBJ_DESCRIPTION:
1312 pObj->SetDescription( msNewStr );
1314 break;
1317 ImpShowPageOfThisObject();
1320 OUString SdrUndoObjStrAttr::GetComment() const
1322 String aStr;
1323 switch ( meObjStrAttr )
1325 case OBJ_NAME:
1327 ImpTakeDescriptionStr( STR_UndoObjName, aStr );
1328 aStr += sal_Unicode(' ');
1329 aStr += sal_Unicode('\'');
1330 aStr += msNewStr;
1331 aStr += sal_Unicode('\'');
1333 break;
1334 case OBJ_TITLE:
1336 ImpTakeDescriptionStr( STR_UndoObjTitle, aStr );
1338 break;
1339 case OBJ_DESCRIPTION:
1341 ImpTakeDescriptionStr( STR_UndoObjDescription, aStr );
1343 break;
1346 return aStr;
1350 SdrUndoLayer::SdrUndoLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel):
1351 SdrUndoAction(rNewModel),
1352 pLayer(rNewLayerAdmin.GetLayer(nLayerNum)),
1353 pLayerAdmin(&rNewLayerAdmin),
1354 nNum(nLayerNum),
1355 bItsMine(sal_False)
1359 SdrUndoLayer::~SdrUndoLayer()
1361 if (bItsMine) {
1362 delete pLayer;
1366 ////////////////////////////////////////////////////////////////////////////////////////////////////
1368 void SdrUndoNewLayer::Undo()
1370 DBG_ASSERT(!bItsMine,"SdrUndoNewLayer::Undo(): Layer already belongs to UndoAction.");
1371 bItsMine=sal_True;
1372 #ifdef DBG_UTIL
1373 SdrLayer* pCmpLayer=
1374 #endif
1375 pLayerAdmin->RemoveLayer(nNum);
1376 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoNewLayer::Undo(): Removed layer is != pLayer.");
1379 void SdrUndoNewLayer::Redo()
1381 DBG_ASSERT(bItsMine,"SdrUndoNewLayer::Undo(): Layer does not belong to UndoAction.");
1382 bItsMine=sal_False;
1383 pLayerAdmin->InsertLayer(pLayer,nNum);
1386 OUString SdrUndoNewLayer::GetComment() const
1388 return ImpGetResStr(STR_UndoNewLayer);
1391 ////////////////////////////////////////////////////////////////////////////////////////////////////
1393 void SdrUndoDelLayer::Undo()
1395 DBG_ASSERT(bItsMine,"SdrUndoDelLayer::Undo(): Layer does not belong to UndoAction.");
1396 bItsMine=sal_False;
1397 pLayerAdmin->InsertLayer(pLayer,nNum);
1400 void SdrUndoDelLayer::Redo()
1402 DBG_ASSERT(!bItsMine,"SdrUndoDelLayer::Undo(): Layer already belongs to UndoAction.");
1403 bItsMine=sal_True;
1404 #ifdef DBG_UTIL
1405 SdrLayer* pCmpLayer=
1406 #endif
1407 pLayerAdmin->RemoveLayer(nNum);
1408 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoDelLayer::Redo(): Removed layer is != pLayer.");
1411 OUString SdrUndoDelLayer::GetComment() const
1413 return ImpGetResStr(STR_UndoDelLayer);
1416 ////////////////////////////////////////////////////////////////////////////////////////////////////
1418 void SdrUndoMoveLayer::Undo()
1420 #ifdef DBG_UTIL
1421 SdrLayer* pCmpLayer=
1422 #endif
1423 pLayerAdmin->RemoveLayer(nNeuPos);
1424 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoMoveLayer::Undo(): Removed layer is != pLayer.");
1425 pLayerAdmin->InsertLayer(pLayer,nNum);
1428 void SdrUndoMoveLayer::Redo()
1430 #ifdef DBG_UTIL
1431 SdrLayer* pCmpLayer=
1432 #endif
1433 pLayerAdmin->RemoveLayer(nNum);
1434 DBG_ASSERT(pCmpLayer==pLayer,"SdrUndoMoveLayer::Redo(): Removed layer is != pLayer.");
1435 pLayerAdmin->InsertLayer(pLayer,nNeuPos);
1438 OUString SdrUndoMoveLayer::GetComment() const
1440 return ImpGetResStr(STR_UndoMovLayer);
1444 SdrUndoPage::SdrUndoPage(SdrPage& rNewPg)
1445 : SdrUndoAction(*rNewPg.GetModel()),
1446 mrPage(rNewPg)
1450 void SdrUndoPage::ImpInsertPage(sal_uInt16 nNum)
1452 DBG_ASSERT(!mrPage.IsInserted(),"SdrUndoPage::ImpInsertPage(): mrPage is already inserted.");
1453 if (!mrPage.IsInserted()) {
1454 if (mrPage.IsMasterPage()) {
1455 rMod.InsertMasterPage(&mrPage,nNum);
1456 } else {
1457 rMod.InsertPage(&mrPage,nNum);
1462 void SdrUndoPage::ImpRemovePage(sal_uInt16 nNum)
1464 DBG_ASSERT(mrPage.IsInserted(),"SdrUndoPage::ImpRemovePage(): mrPage is not inserted.");
1465 if (mrPage.IsInserted()) {
1466 SdrPage* pChkPg=NULL;
1467 if (mrPage.IsMasterPage()) {
1468 pChkPg=rMod.RemoveMasterPage(nNum);
1469 } else {
1470 pChkPg=rMod.RemovePage(nNum);
1472 DBG_ASSERT(pChkPg==&mrPage,"SdrUndoPage::ImpRemovePage(): RemovePage!=&mrPage");
1473 (void)pChkPg;
1477 void SdrUndoPage::ImpMovePage(sal_uInt16 nOldNum, sal_uInt16 nNewNum)
1479 DBG_ASSERT(mrPage.IsInserted(),"SdrUndoPage::ImpMovePage(): mrPage is not inserted.");
1480 if (mrPage.IsInserted()) {
1481 if (mrPage.IsMasterPage()) {
1482 rMod.MoveMasterPage(nOldNum,nNewNum);
1483 } else {
1484 rMod.MovePage(nOldNum,nNewNum);
1489 void SdrUndoPage::ImpTakeDescriptionStr(sal_uInt16 nStrCacheID, XubString& rStr, sal_uInt16 /*n*/, bool /*bRepeat*/) const
1491 rStr=ImpGetResStr(nStrCacheID);
1494 ////////////////////////////////////////////////////////////////////////////////////////////////////
1496 SdrUndoPageList::SdrUndoPageList(SdrPage& rNewPg):
1497 SdrUndoPage(rNewPg),
1498 bItsMine(sal_False)
1500 nPageNum=rNewPg.GetPageNum();
1503 SdrUndoPageList::~SdrUndoPageList()
1505 if(bItsMine)
1507 delete (&mrPage);
1511 ////////////////////////////////////////////////////////////////////////////////////////////////////
1513 SdrUndoDelPage::SdrUndoDelPage(SdrPage& rNewPg):
1514 SdrUndoPageList(rNewPg),
1515 pUndoGroup(NULL)
1517 bItsMine = sal_True;
1519 // now remember the master page relationships
1520 if(mrPage.IsMasterPage())
1522 sal_uInt16 nPageAnz(rMod.GetPageCount());
1524 for(sal_uInt16 nPageNum2(0); nPageNum2 < nPageAnz; nPageNum2++)
1526 SdrPage* pDrawPage = rMod.GetPage(nPageNum2);
1528 if(pDrawPage->TRG_HasMasterPage())
1530 SdrPage& rMasterPage = pDrawPage->TRG_GetMasterPage();
1532 if(&mrPage == &rMasterPage)
1534 if(!pUndoGroup)
1536 pUndoGroup = new SdrUndoGroup(rMod);
1539 pUndoGroup->AddAction(rMod.GetSdrUndoFactory().CreateUndoPageRemoveMasterPage(*pDrawPage));
1546 SdrUndoDelPage::~SdrUndoDelPage()
1548 delete pUndoGroup;
1551 void SdrUndoDelPage::Undo()
1553 ImpInsertPage(nPageNum);
1554 if (pUndoGroup!=NULL) { // recover master page relationships
1555 pUndoGroup->Undo();
1557 DBG_ASSERT(bItsMine,"UndoDeletePage: mrPage does not belong to UndoAction.");
1558 bItsMine=sal_False;
1561 void SdrUndoDelPage::Redo()
1563 ImpRemovePage(nPageNum);
1564 // master page relations are dissolved automatically
1565 DBG_ASSERT(!bItsMine,"RedoDeletePage: mrPage already belongs to UndoAction.");
1566 bItsMine=sal_True;
1569 OUString SdrUndoDelPage::GetComment() const
1571 XubString aStr;
1572 ImpTakeDescriptionStr(STR_UndoDelPage,aStr,0,sal_False);
1573 return aStr;
1576 OUString SdrUndoDelPage::GetSdrRepeatComment(SdrView& /*rView*/) const
1578 XubString aStr;
1579 ImpTakeDescriptionStr(STR_UndoDelPage,aStr,0,sal_False);
1580 return aStr;
1583 void SdrUndoDelPage::SdrRepeat(SdrView& /*rView*/)
1587 bool SdrUndoDelPage::CanSdrRepeat(SdrView& /*rView*/) const
1589 return false;
1592 ////////////////////////////////////////////////////////////////////////////////////////////////////
1594 void SdrUndoNewPage::Undo()
1596 ImpRemovePage(nPageNum);
1597 DBG_ASSERT(!bItsMine,"UndoNewPage: mrPage already belongs to UndoAction.");
1598 bItsMine=sal_True;
1601 void SdrUndoNewPage::Redo()
1603 ImpInsertPage(nPageNum);
1604 DBG_ASSERT(bItsMine,"RedoNewPage: mrPage does not belong to UndoAction.");
1605 bItsMine=sal_False;
1608 OUString SdrUndoNewPage::GetComment() const
1610 XubString aStr;
1611 ImpTakeDescriptionStr(STR_UndoNewPage,aStr,0,sal_False);
1612 return aStr;
1615 ////////////////////////////////////////////////////////////////////////////////////////////////////
1617 OUString SdrUndoCopyPage::GetComment() const
1619 XubString aStr;
1620 ImpTakeDescriptionStr(STR_UndoCopPage,aStr,0,sal_False);
1621 return aStr;
1624 OUString SdrUndoCopyPage::GetSdrRepeatComment(SdrView& /*rView*/) const
1626 XubString aStr;
1627 ImpTakeDescriptionStr(STR_UndoCopPage,aStr,0,sal_False);
1628 return aStr;
1631 void SdrUndoCopyPage::SdrRepeat(SdrView& /*rView*/)
1636 bool SdrUndoCopyPage::CanSdrRepeat(SdrView& /*rView*/) const
1638 return false;
1641 ////////////////////////////////////////////////////////////////////////////////////////////////////
1643 void SdrUndoSetPageNum::Undo()
1645 ImpMovePage(nNewPageNum,nOldPageNum);
1648 void SdrUndoSetPageNum::Redo()
1650 ImpMovePage(nOldPageNum,nNewPageNum);
1653 OUString SdrUndoSetPageNum::GetComment() const
1655 XubString aStr;
1656 ImpTakeDescriptionStr(STR_UndoMovPage,aStr,0,sal_False);
1657 return aStr;
1660 SdrUndoPageMasterPage::SdrUndoPageMasterPage(SdrPage& rChangedPage)
1661 : SdrUndoPage(rChangedPage),
1662 mbOldHadMasterPage(mrPage.TRG_HasMasterPage())
1664 // get current state from page
1665 if(mbOldHadMasterPage)
1667 maOldSet = mrPage.TRG_GetMasterPageVisibleLayers();
1668 maOldMasterPageNumber = mrPage.TRG_GetMasterPage().GetPageNum();
1672 SdrUndoPageMasterPage::~SdrUndoPageMasterPage()
1676 ////////////////////////////////////////////////////////////////////////////////////////////////////
1678 SdrUndoPageRemoveMasterPage::SdrUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1679 : SdrUndoPageMasterPage(rChangedPage)
1683 void SdrUndoPageRemoveMasterPage::Undo()
1685 if(mbOldHadMasterPage)
1687 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
1688 mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
1692 void SdrUndoPageRemoveMasterPage::Redo()
1694 mrPage.TRG_ClearMasterPage();
1697 OUString SdrUndoPageRemoveMasterPage::GetComment() const
1699 XubString aStr;
1700 ImpTakeDescriptionStr(STR_UndoDelPageMasterDscr,aStr,0,sal_False);
1701 return aStr;
1704 ////////////////////////////////////////////////////////////////////////////////////////////////////
1706 SdrUndoPageChangeMasterPage::SdrUndoPageChangeMasterPage(SdrPage& rChangedPage)
1707 : SdrUndoPageMasterPage(rChangedPage),
1708 mbNewHadMasterPage(sal_False)
1712 void SdrUndoPageChangeMasterPage::Undo()
1714 // remember values from new page
1715 if(mrPage.TRG_HasMasterPage())
1717 mbNewHadMasterPage = sal_True;
1718 maNewSet = mrPage.TRG_GetMasterPageVisibleLayers();
1719 maNewMasterPageNumber = mrPage.TRG_GetMasterPage().GetPageNum();
1722 // restore old values
1723 if(mbOldHadMasterPage)
1725 mrPage.TRG_ClearMasterPage();
1726 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maOldMasterPageNumber));
1727 mrPage.TRG_SetMasterPageVisibleLayers(maOldSet);
1731 void SdrUndoPageChangeMasterPage::Redo()
1733 // restore new values
1734 if(mbNewHadMasterPage)
1736 mrPage.TRG_ClearMasterPage();
1737 mrPage.TRG_SetMasterPage(*mrPage.GetModel()->GetMasterPage(maNewMasterPageNumber));
1738 mrPage.TRG_SetMasterPageVisibleLayers(maNewSet);
1742 OUString SdrUndoPageChangeMasterPage::GetComment() const
1744 XubString aStr;
1745 ImpTakeDescriptionStr(STR_UndoChgPageMasterDscr,aStr,0,sal_False);
1746 return aStr;
1749 ///////////////////////////////////////////////////////////////////////
1750 SdrUndoFactory::~SdrUndoFactory(){}
1751 // shapes
1752 SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject )
1754 return new SdrUndoMoveObj( rObject );
1757 SdrUndoAction* SdrUndoFactory::CreateUndoMoveObject( SdrObject& rObject, const Size& rDist )
1759 return new SdrUndoMoveObj( rObject, rDist );
1762 SdrUndoAction* SdrUndoFactory::CreateUndoGeoObject( SdrObject& rObject )
1764 return new SdrUndoGeoObj( rObject );
1767 SdrUndoAction* SdrUndoFactory::CreateUndoAttrObject( SdrObject& rObject, bool bStyleSheet1, bool bSaveText )
1769 return new SdrUndoAttrObj( rObject, bStyleSheet1 ? sal_True : sal_False, bSaveText ? sal_True : sal_False );
1772 SdrUndoAction* SdrUndoFactory::CreateUndoRemoveObject( SdrObject& rObject, bool bOrdNumDirect )
1774 return new SdrUndoRemoveObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1777 SdrUndoAction* SdrUndoFactory::CreateUndoInsertObject( SdrObject& rObject, bool bOrdNumDirect )
1779 return new SdrUndoInsertObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1782 SdrUndoAction* SdrUndoFactory::CreateUndoDeleteObject( SdrObject& rObject, bool bOrdNumDirect )
1784 return new SdrUndoDelObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1787 SdrUndoAction* SdrUndoFactory::CreateUndoNewObject( SdrObject& rObject, bool bOrdNumDirect )
1789 return new SdrUndoNewObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1792 SdrUndoAction* SdrUndoFactory::CreateUndoCopyObject( SdrObject& rObject, bool bOrdNumDirect )
1794 return new SdrUndoCopyObj( rObject, bOrdNumDirect ? sal_True : sal_False );
1797 SdrUndoAction* SdrUndoFactory::CreateUndoObjectOrdNum( SdrObject& rObject, sal_uInt32 nOldOrdNum1, sal_uInt32 nNewOrdNum1)
1799 return new SdrUndoObjOrdNum( rObject, nOldOrdNum1, nNewOrdNum1 );
1802 SdrUndoAction* SdrUndoFactory::CreateUndoReplaceObject( SdrObject& rOldObject, SdrObject& rNewObject, bool bOrdNumDirect )
1804 return new SdrUndoReplaceObj( rOldObject, rNewObject, bOrdNumDirect ? sal_True : sal_False );
1807 SdrUndoAction* SdrUndoFactory::CreateUndoObjectLayerChange( SdrObject& rObject, SdrLayerID aOldLayer, SdrLayerID aNewLayer )
1809 return new SdrUndoObjectLayerChange( rObject, aOldLayer, aNewLayer );
1812 SdrUndoAction* SdrUndoFactory::CreateUndoObjectSetText( SdrObject& rNewObj, sal_Int32 nText )
1814 return new SdrUndoObjSetText( rNewObj, nText );
1817 SdrUndoAction* SdrUndoFactory::CreateUndoObjectStrAttr( SdrObject& rObject,
1818 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType,
1819 String sOldStr,
1820 String sNewStr )
1822 return new SdrUndoObjStrAttr( rObject, eObjStrAttrType, sOldStr, sNewStr );
1826 // layer
1827 SdrUndoAction* SdrUndoFactory::CreateUndoNewLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1829 return new SdrUndoNewLayer( nLayerNum, rNewLayerAdmin, rNewModel );
1832 SdrUndoAction* SdrUndoFactory::CreateUndoDeleteLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel)
1834 return new SdrUndoDelLayer( nLayerNum, rNewLayerAdmin, rNewModel );
1837 SdrUndoAction* SdrUndoFactory::CreateUndoMoveLayer(sal_uInt16 nLayerNum, SdrLayerAdmin& rNewLayerAdmin, SdrModel& rNewModel, sal_uInt16 nNeuPos1)
1839 return new SdrUndoMoveLayer( nLayerNum, rNewLayerAdmin, rNewModel, nNeuPos1 );
1842 // page
1843 SdrUndoAction* SdrUndoFactory::CreateUndoDeletePage(SdrPage& rPage)
1845 return new SdrUndoDelPage( rPage );
1848 SdrUndoAction* SdrUndoFactory::CreateUndoNewPage(SdrPage& rPage)
1850 return new SdrUndoNewPage( rPage );
1853 SdrUndoAction* SdrUndoFactory::CreateUndoCopyPage(SdrPage& rPage)
1855 return new SdrUndoCopyPage( rPage );
1858 SdrUndoAction* SdrUndoFactory::CreateUndoSetPageNum(SdrPage& rNewPg, sal_uInt16 nOldPageNum1, sal_uInt16 nNewPageNum1)
1860 return new SdrUndoSetPageNum( rNewPg, nOldPageNum1, nNewPageNum1 );
1862 // master page
1863 SdrUndoAction* SdrUndoFactory::CreateUndoPageRemoveMasterPage(SdrPage& rChangedPage)
1865 return new SdrUndoPageRemoveMasterPage( rChangedPage );
1868 SdrUndoAction* SdrUndoFactory::CreateUndoPageChangeMasterPage(SdrPage& rChangedPage)
1870 return new SdrUndoPageChangeMasterPage(rChangedPage);
1874 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */