1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SVX_SVDUNDO_HXX
21 #define INCLUDED_SVX_SVDUNDO_HXX
23 #include <svl/solar.hrc>
24 #include <svl/undo.hxx>
25 #include <svl/style.hxx>
26 #include <tools/gen.hxx>
27 #include <svx/svdtypes.hxx>
28 #include <svx/svdsob.hxx>
29 #include <svx/svxdllapi.h>
42 class OutlinerParaObject
;
45 * Abstract base class (ABC) for all UndoActions of DrawingEngine
48 class SVX_DLLPUBLIC SdrUndoAction
: public SfxUndoAction
54 SdrUndoAction(SdrModel
& rNewMod
)
60 virtual ~SdrUndoAction();
62 virtual bool CanRepeat(SfxRepeatTarget
& rView
) const;
63 virtual void Repeat(SfxRepeatTarget
& rView
);
65 virtual OUString
GetRepeatComment(SfxRepeatTarget
& rView
) const;
66 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
68 virtual bool CanSdrRepeat(SdrView
& rView
) const;
69 virtual void SdrRepeat(SdrView
& rView
);
73 * Aggregation of arbitrarily many UndoActions to a single UndoAction.
74 * Undo() executes the single UndoActions backwards (LIFO, first the last
75 * ones attached), Redo() executes the UndoActions in the order they were
79 class SVX_DLLPUBLIC SdrUndoGroup
: public SdrUndoAction
82 std::vector
<SdrUndoAction
*> aBuf
;
84 // No expanded description of the Action (contains %O)
86 OUString aObjDescription
;
88 SdrRepeatFunc eFunction
;
91 SdrUndoGroup(SdrModel
& rNewMod
);
92 virtual ~SdrUndoGroup();
95 sal_uIntPtr
GetActionCount() const { return aBuf
.size(); }
96 SdrUndoAction
* GetAction(sal_uIntPtr nNum
) const { return aBuf
[nNum
]; }
97 void AddAction(SdrUndoAction
* pAct
);
99 void SetComment(const OUString
& rStr
) { aComment
=rStr
; }
100 void SetObjDescription(const OUString
& rStr
) { aObjDescription
=rStr
; }
101 virtual OUString
GetComment() const;
102 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
107 virtual bool CanSdrRepeat(SdrView
& rView
) const;
108 virtual void SdrRepeat(SdrView
& rView
);
109 void SetRepeatFunction(SdrRepeatFunc eFunc
) { eFunction
=eFunc
; }
110 SdrRepeatFunc
GetRepeatFunction() const { return eFunction
; }
114 * Abstract base class for all UndoActions that handle objects.
117 class SVX_DLLPUBLIC SdrUndoObj
: public SdrUndoAction
123 SdrUndoObj(SdrObject
& rNewObj
);
125 void ImpTakeDescriptionStr(sal_uInt16 nStrCacheID
, OUString
& rStr
, bool bRepeat
= false) const;
127 static SAL_WARN_UNUSED_RESULT OUString
GetDescriptionStringForObject( const SdrObject
& _rForObject
, sal_uInt16 nStrCacheID
, bool bRepeat
= false );
129 // #94278# new method for evtl. PageChange at UNDO/REDO
130 void ImpShowPageOfThisObject();
134 * Changing the object attributes.
135 * Create Action right before setting the new attributes.
136 * Also for StyleSheets.
139 class SVX_DLLPUBLIC SdrUndoAttrObj
: public SdrUndoObj
142 SfxItemSet
* pUndoSet
;
143 SfxItemSet
* pRedoSet
;
144 SfxItemSet
* pRepeatSet
;
146 // FIXME: Or should we better remember the StyleSheetNames?
147 rtl::Reference
< SfxStyleSheetBase
> mxUndoStyleSheet
;
148 rtl::Reference
< SfxStyleSheetBase
> mxRedoStyleSheet
;
150 bool bHaveToTakeRedoSet
;
152 // When assigning TextItems to a drawing object with text:
153 OutlinerParaObject
* pTextUndo
;
155 // The text rescue mechanism needs also to be implemented for redo actions.
156 OutlinerParaObject
* pTextRedo
;
158 // If we have a group object:
159 SdrUndoGroup
* pUndoGroup
;
161 // Helper to ensure StyleSheet is in pool (provided by SdrModel from SdrObject)
162 void ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool
& rStyleSheetPool
, SfxStyleSheet
& rSheet
);
165 SdrUndoAttrObj(SdrObject
& rNewObj
, bool bStyleSheet1
= false, bool bSaveText
= false);
166 virtual ~SdrUndoAttrObj();
170 virtual OUString
GetComment() const;
171 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
173 virtual void SdrRepeat(SdrView
& rView
);
174 virtual bool CanSdrRepeat(SdrView
& rView
) const;
178 * Only moving of an object.
179 * Create Action right before moving.
182 class SVX_DLLPUBLIC SdrUndoMoveObj
: public SdrUndoObj
185 Size aDistance
; // Distance by which we move
188 SdrUndoMoveObj(SdrObject
& rNewObj
): SdrUndoObj(rNewObj
) {}
189 SdrUndoMoveObj(SdrObject
& rNewObj
, const Size
& rDist
): SdrUndoObj(rNewObj
),aDistance(rDist
) {}
190 virtual ~SdrUndoMoveObj();
192 void SetDistance(const Size
& rDist
) { aDistance
=rDist
; }
193 const Size
& GetDistance() const { return aDistance
; }
198 virtual OUString
GetComment() const;
199 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
201 virtual void SdrRepeat(SdrView
& rView
);
202 virtual bool CanSdrRepeat(SdrView
& rView
) const;
206 * Changing the geometry of an object.
207 * Create Action right before the geometric transformation.
210 class SVX_DLLPUBLIC SdrUndoGeoObj
: public SdrUndoObj
213 SdrObjGeoData
* pUndoGeo
;
214 SdrObjGeoData
* pRedoGeo
;
215 // If we have a group object:
216 SdrUndoGroup
* pUndoGroup
;
219 SdrUndoGeoObj(SdrObject
& rNewObj
);
220 virtual ~SdrUndoGeoObj();
225 virtual OUString
GetComment() const;
229 * Manipulation of an ObjList: New Object, DeleteObj, SetObjZLevel, Grouping, ...
230 * Abstract base class.
233 class SVX_DLLPUBLIC SdrUndoObjList
: public SdrUndoObj
{
234 class ObjListListener
;
235 friend class ObjListListener
;
241 SdrObjList
* pObjList
;
242 SdrView
* pView
; // To be able to re-create the selection for a
243 SdrPageView
* pPageView
; // for a ObjDel, Undo
245 // It's possible that the object is re-assigned during a Undo/Redo.
246 // The object is deleted in the dtor, if bOwner==TRUE
247 ObjListListener
* m_pListener
;
250 SdrUndoObjList(SdrObject
& rNewObj
, bool bOrdNumDirect
= false);
251 virtual ~SdrUndoObjList();
253 void SetView(SdrView
* pView1
, SdrPageView
* pPageView1
) { pView
=pView1
; pPageView
=pPageView1
; }
254 bool IsOwner() { return bOwner
; }
255 void SetOwner(bool bNew
);
258 sal_uInt32
GetOrdNum() const;
259 void SetOrdNum(sal_uInt32 nOrdNum_
);
263 * Removing an Object from an ObjectList.
264 * To be used with corresponding Inserts within a UndoGroup.
266 * Create Action before removing from the ObjList.
269 class SVX_DLLPUBLIC SdrUndoRemoveObj
: public SdrUndoObjList
272 SdrUndoRemoveObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
273 : SdrUndoObjList(rNewObj
,bOrdNumDirect
) {}
278 virtual ~SdrUndoRemoveObj();
282 * Inserting Objects into a ObjectList.
283 * Use with corresponding Removes within an UndoGroup.
284 * Create Action before removal from ObjList.
287 class SVX_DLLPUBLIC SdrUndoInsertObj
: public SdrUndoObjList
290 SdrUndoInsertObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
291 : SdrUndoObjList(rNewObj
,bOrdNumDirect
) {}
298 * Deleting an Object.
299 * Create Action before removing from ObjList.
302 class SVX_DLLPUBLIC SdrUndoDelObj
: public SdrUndoRemoveObj
305 void TryToFlushGraphicContent();
308 SdrUndoDelObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false);
313 virtual OUString
GetComment() const;
314 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
316 virtual void SdrRepeat(SdrView
& rView
);
317 virtual bool CanSdrRepeat(SdrView
& rView
) const;
321 * Inserting a NEW Object.
322 * Create Actio after insertion into the ObjList.
325 class SVX_DLLPUBLIC SdrUndoNewObj
: public SdrUndoInsertObj
328 SdrUndoNewObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
329 : SdrUndoInsertObj(rNewObj
,bOrdNumDirect
) {}
334 virtual OUString
GetComment() const;
336 static OUString
GetComment(const SdrObject
& _rForObject
);
340 * Replacing an Object.
341 * Create Action before Replace in ObjList.
344 class SVX_DLLPUBLIC SdrUndoReplaceObj
: public SdrUndoObj
350 SdrObjList
* pObjList
;
355 SdrUndoReplaceObj(SdrObject
& rOldObj1
, SdrObject
& rNewObj1
, bool bOrdNumDirect
= false);
356 virtual ~SdrUndoReplaceObj();
361 bool IsNewOwner() { return bNewOwner
; }
362 void SetNewOwner(bool bNew
);
364 bool IsOldOwner() { return bOldOwner
; }
365 void SetOldOwner(bool bNew
);
370 * Create Action before inserting into the ObjList.
373 class SdrUndoCopyObj
: public SdrUndoNewObj
376 SdrUndoCopyObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
377 : SdrUndoNewObj(rNewObj
,bOrdNumDirect
) {}
379 virtual OUString
GetComment() const;
382 class SdrUndoObjOrdNum
: public SdrUndoObj
385 sal_uInt32 nOldOrdNum
;
386 sal_uInt32 nNewOrdNum
;
389 SdrUndoObjOrdNum(SdrObject
& rNewObj
, sal_uInt32 nOldOrdNum1
, sal_uInt32 nNewOrdNum1
);
394 virtual OUString
GetComment() const;
397 //////////////////////////////////////////////////////////////////////////////
400 class SVX_DLLPUBLIC SdrUndoObjectLayerChange
: public SdrUndoObj
403 SdrLayerID maOldLayer
;
404 SdrLayerID maNewLayer
;
407 SdrUndoObjectLayerChange(SdrObject
& rObj
, SdrLayerID aOldLayer
, SdrLayerID aNewLayer
);
413 class SVX_DLLPUBLIC SdrUndoObjSetText
: public SdrUndoObj
416 OutlinerParaObject
* pOldText
;
417 OutlinerParaObject
* pNewText
;
418 bool bNewTextAvailable
;
419 sal_Bool bEmptyPresObj
;
423 SdrUndoObjSetText(SdrObject
& rNewObj
, sal_Int32 nText
);
424 virtual ~SdrUndoObjSetText();
426 bool IsDifferent() const { return pOldText
!=pNewText
; }
432 virtual OUString
GetComment() const;
433 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
435 virtual void SdrRepeat(SdrView
& rView
);
436 virtual bool CanSdrRepeat(SdrView
& rView
) const;
440 * Implement Title/Description Elements UI for Writer
441 * text frames, graphics and embedded objects (#i73249#)
443 class SdrUndoObjStrAttr
: public SdrUndoObj
454 const ObjStrAttrType meObjStrAttr
;
455 const OUString msOldStr
;
456 const OUString msNewStr
;
459 SdrUndoObjStrAttr( SdrObject
& rNewObj
,
460 const ObjStrAttrType eObjStrAttr
,
461 const OUString
& sOldStr
,
462 const OUString
& sNewStr
);
467 virtual OUString
GetComment() const;
476 * Abstract base class for all UndoActions that have something to do with SdrLayer.
479 class SdrUndoLayer
: public SdrUndoAction
483 SdrLayerAdmin
* pLayerAdmin
;
488 SdrUndoLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
489 virtual ~SdrUndoLayer();
493 * Inserting a new Layer.
494 * Create Action after Insertion.
497 class SdrUndoNewLayer
: public SdrUndoLayer
500 SdrUndoNewLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
)
501 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
) {}
506 virtual OUString
GetComment() const;
511 * Create Action before the Remove.
514 class SdrUndoDelLayer
: public SdrUndoLayer
517 SdrUndoDelLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
)
518 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
) { bItsMine
=sal_True
; }
523 virtual OUString
GetComment() const;
528 * Create Action before the Move.
531 class SdrUndoMoveLayer
: public SdrUndoLayer
536 SdrUndoMoveLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
, sal_uInt16 nNeuPos1
)
537 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
), nNeuPos(nNeuPos1
) {}
542 virtual OUString
GetComment() const;
551 * ABC for all UndoActions that have something to do with SdrPages.
554 class SVX_DLLPUBLIC SdrUndoPage
: public SdrUndoAction
560 void ImpInsertPage(sal_uInt16 nNum
);
561 void ImpRemovePage(sal_uInt16 nNum
);
562 void ImpMovePage(sal_uInt16 nOldNum
, sal_uInt16 nNewNum
);
565 SdrUndoPage(SdrPage
& rNewPg
);
567 void ImpTakeDescriptionStr(sal_uInt16 nStrCacheID
, OUString
& rStr
, sal_uInt16 n
=0, bool bRepeat
= false) const;
571 * ABC for manipulation of a PageList: New Page, DeletePage, MovePage (ChangePageNum).
574 class SVX_DLLPUBLIC SdrUndoPageList
: public SdrUndoPage
579 // It's possible that the object is re-assigned during a Undo/Redo.
580 // The Page is deleted in the dtor, if bItsMine==TRUE
584 SdrUndoPageList(SdrPage
& rNewPg
);
585 virtual ~SdrUndoPageList();
590 * Create Action before removing from the List.
593 class SVX_DLLPUBLIC SdrUndoDelPage
: public SdrUndoPageList
595 // When deleting a MasterPage, we remember all relations of the
596 // Character Page with the MasterPage in this UndoGroup.
597 SdrUndoGroup
* pUndoGroup
;
600 SdrUndoDelPage(SdrPage
& rNewPg
);
601 virtual ~SdrUndoDelPage();
606 virtual OUString
GetComment() const;
607 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
609 virtual void SdrRepeat(SdrView
& rView
);
610 virtual bool CanSdrRepeat(SdrView
& rView
) const;
614 * Inserting a new Page.
615 * Create Action after inserting into the List.
618 class SVX_DLLPUBLIC SdrUndoNewPage
: public SdrUndoPageList
621 SdrUndoNewPage(SdrPage
& rNewPg
): SdrUndoPageList(rNewPg
) {}
626 virtual OUString
GetComment() const;
631 * Create Action after inserting into the List.
634 class SdrUndoCopyPage
: public SdrUndoNewPage
637 SdrUndoCopyPage(SdrPage
& rNewPg
): SdrUndoNewPage(rNewPg
) {}
639 virtual OUString
GetComment() const;
640 virtual OUString
GetSdrRepeatComment(SdrView
& rView
) const;
642 virtual void SdrRepeat(SdrView
& rView
);
643 virtual bool CanSdrRepeat(SdrView
& rView
) const;
647 * Moving a Page within the List.
648 * Create Action before moving the Page.
651 class SVX_DLLPUBLIC SdrUndoSetPageNum
: public SdrUndoPage
654 sal_uInt16 nOldPageNum
;
655 sal_uInt16 nNewPageNum
;
658 SdrUndoSetPageNum(SdrPage
& rNewPg
, sal_uInt16 nOldPageNum1
, sal_uInt16 nNewPageNum1
)
659 : SdrUndoPage(rNewPg
),nOldPageNum(nOldPageNum1
),nNewPageNum(nNewPageNum1
) {}
664 virtual OUString
GetComment() const;
673 * ABC for all UndoActions that have something to do with
674 * MasterPage relationships.
677 class SdrUndoPageMasterPage
: public SdrUndoPage
680 sal_Bool mbOldHadMasterPage
;
682 sal_uInt16 maOldMasterPageNumber
;
685 SdrUndoPageMasterPage(SdrPage
& rChangedPage
);
688 SVX_DLLPUBLIC
virtual ~SdrUndoPageMasterPage();
692 * Removal of a MasterPage from a Character Page.
693 * Create Action before removing the MasterPageDescriptor.
696 class SdrUndoPageRemoveMasterPage
: public SdrUndoPageMasterPage
699 SdrUndoPageRemoveMasterPage(SdrPage
& rChangedPage
);
704 virtual OUString
GetComment() const;
708 * Changing the MasterPageDescriptor (e.g. change of the VisibleLayer).
709 * Create Action before changing the MasterPageDescriptors.
712 class SVX_DLLPUBLIC SdrUndoPageChangeMasterPage
: public SdrUndoPageMasterPage
715 sal_Bool mbNewHadMasterPage
;
717 sal_uInt16 maNewMasterPageNumber
;
720 SdrUndoPageChangeMasterPage(SdrPage
& rChangedPage
);
725 virtual OUString
GetComment() const;
728 ///////////////////////////////////////////////////////////////////////
731 * The SdrUndoFactory can be set and retrieved from the SdrModel.
732 * It is used by the drawing layer implementations to create undo actions.
733 * It can be used by applications to create application specific undo actions.
735 class SVX_DLLPUBLIC SdrUndoFactory
739 virtual ~SdrUndoFactory();
740 virtual SdrUndoAction
* CreateUndoMoveObject( SdrObject
& rObject
);
741 virtual SdrUndoAction
* CreateUndoMoveObject( SdrObject
& rObject
, const Size
& rDist
);
742 virtual SdrUndoAction
* CreateUndoGeoObject( SdrObject
& rObject
);
743 virtual SdrUndoAction
* CreateUndoAttrObject( SdrObject
& rObject
, bool bStyleSheet1
= false, bool bSaveText
= false );
744 virtual SdrUndoAction
* CreateUndoRemoveObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
745 virtual SdrUndoAction
* CreateUndoInsertObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
746 virtual SdrUndoAction
* CreateUndoDeleteObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
747 virtual SdrUndoAction
* CreateUndoNewObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
748 virtual SdrUndoAction
* CreateUndoCopyObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
750 virtual SdrUndoAction
* CreateUndoObjectOrdNum( SdrObject
& rObject
, sal_uInt32 nOldOrdNum1
, sal_uInt32 nNewOrdNum1
);
752 virtual SdrUndoAction
* CreateUndoReplaceObject( SdrObject
& rOldObject
, SdrObject
& rNewObject
, bool bOrdNumDirect
= false );
753 virtual SdrUndoAction
* CreateUndoObjectLayerChange( SdrObject
& rObject
, SdrLayerID aOldLayer
, SdrLayerID aNewLayer
);
754 virtual SdrUndoAction
* CreateUndoObjectSetText( SdrObject
& rNewObj
, sal_Int32 nText
);
756 // Implement Title/Description Elements UI for Writer text frames, graphics and embedded objects (#i73249#)
757 virtual SdrUndoAction
* CreateUndoObjectStrAttr( SdrObject
& rObject
,
758 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType
,
759 const OUString
& sOldStr
,
760 const OUString
& sNewStr
);
763 virtual SdrUndoAction
* CreateUndoNewLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
764 virtual SdrUndoAction
* CreateUndoDeleteLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
765 virtual SdrUndoAction
* CreateUndoMoveLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
, sal_uInt16 nNeuPos1
);
768 virtual SdrUndoAction
* CreateUndoDeletePage(SdrPage
& rPage
);
769 virtual SdrUndoAction
* CreateUndoNewPage(SdrPage
& rPage
);
770 virtual SdrUndoAction
* CreateUndoCopyPage(SdrPage
& rPage
);
771 virtual SdrUndoAction
* CreateUndoSetPageNum(SdrPage
& rNewPg
, sal_uInt16 nOldPageNum1
, sal_uInt16 nNewPageNum1
);
774 virtual SdrUndoAction
* CreateUndoPageRemoveMasterPage(SdrPage
& rChangedPage
);
775 virtual SdrUndoAction
* CreateUndoPageChangeMasterPage(SdrPage
& rChangedPage
);
778 #endif // INCLUDED_SVX_SVDUNDO_HXX
780 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */