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 <config_options.h>
24 #include <sal/config.h>
29 #include <svl/undo.hxx>
30 #include <svl/style.hxx>
31 #include <tools/gen.hxx>
32 #include <svx/svdtypes.hxx>
33 #include <svx/svdsob.hxx>
34 #include <svx/svxdllapi.h>
48 class OutlinerParaObject
;
51 * Abstract base class (ABC) for all UndoActions of DrawingEngine
54 class SVXCORE_DLLPUBLIC SdrUndoAction
: public SfxUndoAction
58 ViewShellId m_nViewShellId
;
61 SdrUndoAction(SdrModel
& rNewMod
);
64 virtual ~SdrUndoAction() override
;
66 virtual bool CanRepeat(SfxRepeatTarget
& rView
) const override
;
67 virtual void Repeat(SfxRepeatTarget
& rView
) override
;
69 virtual OUString
GetRepeatComment(SfxRepeatTarget
& rView
) const override
;
70 virtual OUString
GetSdrRepeatComment() const;
72 virtual bool CanSdrRepeat(SdrView
& rView
) const;
73 virtual void SdrRepeat(SdrView
& rView
);
75 /// See SfxUndoAction::GetViewShellId().
76 ViewShellId
GetViewShellId() const override
;
80 * Aggregation of arbitrarily many UndoActions to a single UndoAction.
81 * Undo() executes the single UndoActions backwards (LIFO, first the last
82 * ones attached), Redo() executes the UndoActions in the order they were
86 class SVXCORE_DLLPUBLIC SdrUndoGroup final
: public SdrUndoAction
88 std::vector
<std::unique_ptr
<SdrUndoAction
>> maActions
;
90 // No expanded description of the Action (contains %O)
92 OUString aObjDescription
;
94 SdrRepeatFunc eFunction
;
97 SdrUndoGroup(SdrModel
& rNewMod
);
98 virtual ~SdrUndoGroup() override
;
100 sal_Int32
GetActionCount() const { return maActions
.size(); }
101 SdrUndoAction
* GetAction(sal_Int32 nNum
) const { return maActions
[nNum
].get(); }
102 void AddAction(std::unique_ptr
<SdrUndoAction
> pAct
);
104 void SetComment(const OUString
& rStr
) { aComment
=rStr
; }
105 void SetObjDescription(const OUString
& rStr
) { aObjDescription
=rStr
; }
106 virtual OUString
GetComment() const override
;
107 virtual OUString
GetSdrRepeatComment() const override
;
109 virtual void Undo() override
;
110 virtual void Redo() override
;
112 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
113 virtual void SdrRepeat(SdrView
& rView
) override
;
114 void SetRepeatFunction(SdrRepeatFunc eFunc
) { eFunction
=eFunc
; }
118 * Abstract base class for all UndoActions that handle objects.
121 class SVXCORE_DLLPUBLIC SdrUndoObj
: public SdrUndoAction
127 SdrUndoObj(SdrObject
& rNewObj
);
129 OUString
ImpGetDescriptionStr(const char* pStrCacheID
, bool bRepeat
= false) const;
131 [[nodiscard
]] static OUString
GetDescriptionStringForObject( const SdrObject
& _rForObject
, const char* pStrCacheID
, bool bRepeat
= false );
133 // #94278# new method for evtl. PageChange at UNDO/REDO
134 void ImpShowPageOfThisObject();
138 * Changing the object attributes.
139 * Create Action right before setting the new attributes.
140 * Also for StyleSheets.
143 class SVXCORE_DLLPUBLIC SdrUndoAttrObj
: public SdrUndoObj
146 std::unique_ptr
<SfxItemSet
> pUndoSet
;
147 std::unique_ptr
<SfxItemSet
> pRedoSet
;
149 // FIXME: Or should we better remember the StyleSheetNames?
150 rtl::Reference
< SfxStyleSheetBase
> mxUndoStyleSheet
;
151 rtl::Reference
< SfxStyleSheetBase
> mxRedoStyleSheet
;
153 bool bHaveToTakeRedoSet
;
155 // When assigning TextItems to a drawing object with text:
156 std::unique_ptr
<OutlinerParaObject
>
159 // The text rescue mechanism needs also to be implemented for redo actions.
160 std::unique_ptr
<OutlinerParaObject
>
163 // If we have a group object:
164 std::unique_ptr
<SdrUndoGroup
> pUndoGroup
;
166 // Helper to ensure StyleSheet is in pool (provided by SdrModel from SdrObject)
167 static void ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool
& rStyleSheetPool
, SfxStyleSheet
& rSheet
);
170 SdrUndoAttrObj(SdrObject
& rNewObj
, bool bStyleSheet1
= false, bool bSaveText
= false);
171 virtual ~SdrUndoAttrObj() override
;
172 virtual void Undo() override
;
173 virtual void Redo() override
;
175 virtual OUString
GetComment() const override
;
176 virtual OUString
GetSdrRepeatComment() const override
;
180 * Only moving of an object.
181 * Create Action right before moving.
184 class SVXCORE_DLLPUBLIC SdrUndoMoveObj final
: public SdrUndoObj
186 Size aDistance
; // Distance by which we move
189 SdrUndoMoveObj(SdrObject
& rNewObj
, const Size
& rDist
): SdrUndoObj(rNewObj
),aDistance(rDist
) {}
190 virtual ~SdrUndoMoveObj() override
;
192 virtual void Undo() override
;
193 virtual void Redo() override
;
195 virtual OUString
GetComment() const override
;
196 virtual OUString
GetSdrRepeatComment() const override
;
198 virtual void SdrRepeat(SdrView
& rView
) override
;
199 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
203 * Changing the geometry of an object.
204 * Create Action right before the geometric transformation.
207 class SVXCORE_DLLPUBLIC SdrUndoGeoObj
: public SdrUndoObj
209 std::unique_ptr
<SdrObjGeoData
> pUndoGeo
;
210 std::unique_ptr
<SdrObjGeoData
> pRedoGeo
;
211 // If we have a group object:
212 std::unique_ptr
<SdrUndoGroup
> pUndoGroup
;
213 /// If we have a table object, should its layout change?
214 bool mbSkipChangeLayout
;
217 SdrUndoGeoObj(SdrObject
& rNewObj
);
218 virtual ~SdrUndoGeoObj() override
;
220 virtual void Undo() override
;
221 virtual void Redo() override
;
223 virtual OUString
GetComment() const override
;
224 void SetSkipChangeLayout(bool bOn
) { mbSkipChangeLayout
=bOn
; }
228 * Manipulation of an ObjList: New Object, DeleteObj, SetObjZLevel, Grouping, ...
229 * Abstract base class.
232 class SVXCORE_DLLPUBLIC SdrUndoObjList
: public SdrUndoObj
{
233 class ObjListListener
;
234 friend class ObjListListener
;
240 SdrObjList
* pObjList
;
244 SdrUndoObjList(SdrObject
& rNewObj
, bool bOrdNumDirect
);
245 virtual ~SdrUndoObjList() override
;
247 bool IsOwner() const { return bOwner
; }
248 void SetOwner(bool bNew
);
252 * Removing an Object from an ObjectList.
253 * To be used with corresponding Inserts within a UndoGroup.
255 * Create Action before removing from the ObjList.
258 class SVXCORE_DLLPUBLIC SdrUndoRemoveObj
: public SdrUndoObjList
261 SdrUndoRemoveObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
262 : SdrUndoObjList(rNewObj
,bOrdNumDirect
) {}
264 virtual void Undo() override
;
265 virtual void Redo() override
;
267 virtual ~SdrUndoRemoveObj() override
;
271 * Inserting Objects into an ObjectList.
272 * Use with corresponding Removes within an UndoGroup.
273 * Create Action before removal from ObjList.
276 class SVXCORE_DLLPUBLIC SdrUndoInsertObj
: public SdrUndoObjList
279 SdrUndoInsertObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
280 : SdrUndoObjList(rNewObj
,bOrdNumDirect
) {}
282 virtual void Undo() override
;
283 virtual void Redo() override
;
287 * Deleting an Object.
288 * Create Action before removing from ObjList.
291 class SVXCORE_DLLPUBLIC SdrUndoDelObj
: public SdrUndoRemoveObj
294 SdrUndoDelObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false);
296 virtual void Undo() override
;
297 virtual void Redo() override
;
299 virtual OUString
GetComment() const override
;
300 virtual OUString
GetSdrRepeatComment() const override
;
302 virtual void SdrRepeat(SdrView
& rView
) override
;
303 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
307 * Inserting a NEW Object.
308 * Create Action after insertion into the ObjList.
311 class SVXCORE_DLLPUBLIC SdrUndoNewObj
: public SdrUndoInsertObj
314 SdrUndoNewObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
315 : SdrUndoInsertObj(rNewObj
,bOrdNumDirect
) {}
317 virtual void Undo() override
;
318 virtual void Redo() override
;
320 virtual OUString
GetComment() const override
;
322 static OUString
GetComment(const SdrObject
& _rForObject
);
326 * Replacing an Object.
327 * Create Action before Replace in ObjList.
330 class SVXCORE_DLLPUBLIC SdrUndoReplaceObj
: public SdrUndoObj
335 SdrObjList
* pObjList
;
339 SdrUndoReplaceObj(SdrObject
& rOldObj1
, SdrObject
& rNewObj1
);
340 virtual ~SdrUndoReplaceObj() override
;
342 virtual void Undo() override
;
343 virtual void Redo() override
;
345 bool IsNewOwner() const { return bNewOwner
; }
346 void SetNewOwner(bool bNew
);
348 bool IsOldOwner() const { return bOldOwner
; }
349 void SetOldOwner(bool bNew
);
354 * Create Action before inserting into the ObjList.
357 class SdrUndoCopyObj final
: public SdrUndoNewObj
360 SdrUndoCopyObj(SdrObject
& rNewObj
, bool bOrdNumDirect
)
361 : SdrUndoNewObj(rNewObj
,bOrdNumDirect
) {}
363 virtual OUString
GetComment() const override
;
366 class SdrUndoObjOrdNum final
: public SdrUndoObj
368 sal_uInt32 nOldOrdNum
;
369 sal_uInt32 nNewOrdNum
;
372 SdrUndoObjOrdNum(SdrObject
& rNewObj
, sal_uInt32 nOldOrdNum1
, sal_uInt32 nNewOrdNum1
);
374 virtual void Undo() override
;
375 virtual void Redo() override
;
377 virtual OUString
GetComment() const override
;
383 class SVXCORE_DLLPUBLIC SdrUndoObjectLayerChange final
: public SdrUndoObj
385 SdrLayerID maOldLayer
;
386 SdrLayerID maNewLayer
;
389 SdrUndoObjectLayerChange(SdrObject
& rObj
, SdrLayerID aOldLayer
, SdrLayerID aNewLayer
);
391 virtual void Undo() override
;
392 virtual void Redo() override
;
395 class SVXCORE_DLLPUBLIC SdrUndoObjSetText
: public SdrUndoObj
398 std::unique_ptr
<OutlinerParaObject
>
400 std::unique_ptr
<OutlinerParaObject
>
402 bool bNewTextAvailable
;
407 SdrUndoObjSetText(SdrObject
& rNewObj
, sal_Int32 nText
);
408 virtual ~SdrUndoObjSetText() override
;
410 bool IsDifferent() const { return pOldText
!=pNewText
; }
413 virtual void Undo() override
;
414 virtual void Redo() override
;
416 virtual OUString
GetComment() const override
;
417 virtual OUString
GetSdrRepeatComment() const override
;
419 virtual void SdrRepeat(SdrView
& rView
) override
;
420 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
424 * Implement Title/Description Elements UI for Writer
425 * text frames, graphics and embedded objects (#i73249#)
427 class SdrUndoObjStrAttr final
: public SdrUndoObj
430 enum class ObjStrAttrType
437 SdrUndoObjStrAttr( SdrObject
& rNewObj
,
438 const ObjStrAttrType eObjStrAttr
,
439 const OUString
& sOldStr
,
440 const OUString
& sNewStr
);
442 virtual void Undo() override
;
443 virtual void Redo() override
;
445 virtual OUString
GetComment() const override
;
448 const ObjStrAttrType meObjStrAttr
;
449 const OUString msOldStr
;
450 const OUString msNewStr
;
460 * Abstract base class for all UndoActions that have something to do with SdrLayer.
463 class SdrUndoLayer
: public SdrUndoAction
467 SdrLayerAdmin
* pLayerAdmin
;
472 SdrUndoLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
473 virtual ~SdrUndoLayer() override
;
477 * Inserting a new Layer.
478 * Create Action after Insertion.
481 class SdrUndoNewLayer final
: public SdrUndoLayer
484 SdrUndoNewLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
)
485 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
) {}
487 virtual void Undo() override
;
488 virtual void Redo() override
;
490 virtual OUString
GetComment() const override
;
495 * Create Action before the Remove.
498 class SdrUndoDelLayer final
: public SdrUndoLayer
501 SdrUndoDelLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
)
502 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
) { bItsMine
=true; }
504 virtual void Undo() override
;
505 virtual void Redo() override
;
507 virtual OUString
GetComment() const override
;
515 * ABC for all UndoActions that have something to do with SdrPages.
518 class SdrUndoPage
: public SdrUndoAction
524 void ImpInsertPage(sal_uInt16 nNum
);
525 void ImpRemovePage(sal_uInt16 nNum
);
526 void ImpMovePage(sal_uInt16 nOldNum
, sal_uInt16 nNewNum
);
529 SdrUndoPage(SdrPage
& rNewPg
);
531 static OUString
ImpGetDescriptionStr(const char* pStrCacheID
);
535 * ABC for manipulation of a PageList: New Page, DeletePage, MovePage (ChangePageNum).
538 class SVXCORE_DLLPUBLIC SdrUndoPageList
: public SdrUndoPage
543 // It's possible that the object is re-assigned during a Undo/Redo.
544 // The Page is deleted in the dtor, if bItsMine==TRUE
548 SdrUndoPageList(SdrPage
& rNewPg
);
549 virtual ~SdrUndoPageList() override
;
554 * Create Action before removing from the List.
557 class SVXCORE_DLLPUBLIC SdrUndoDelPage final
: public SdrUndoPageList
559 // When deleting a MasterPage, we remember all relations of the
560 // Character Page with the MasterPage in this UndoGroup.
561 std::unique_ptr
<SdrUndoGroup
> pUndoGroup
;
562 std::unique_ptr
<SfxPoolItem
> mpFillBitmapItem
;
563 bool mbHasFillBitmap
;
566 SdrUndoDelPage(SdrPage
& rNewPg
);
567 virtual ~SdrUndoDelPage() override
;
569 virtual void Undo() override
;
570 virtual void Redo() override
;
572 virtual OUString
GetComment() const override
;
573 virtual OUString
GetSdrRepeatComment() const override
;
575 virtual void SdrRepeat(SdrView
& rView
) override
;
576 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
579 void queryFillBitmap(const SfxItemSet
&rItemSet
);
580 void clearFillBitmap();
581 void restoreFillBitmap();
585 * Inserting a new Page.
586 * Create Action after inserting into the List.
589 class SVXCORE_DLLPUBLIC SdrUndoNewPage
: public SdrUndoPageList
592 SdrUndoNewPage(SdrPage
& rNewPg
): SdrUndoPageList(rNewPg
) {}
594 virtual void Undo() override
;
595 virtual void Redo() override
;
597 virtual OUString
GetComment() const override
;
602 * Create Action after inserting into the List.
605 class SdrUndoCopyPage final
: public SdrUndoNewPage
608 SdrUndoCopyPage(SdrPage
& rNewPg
): SdrUndoNewPage(rNewPg
) {}
610 virtual OUString
GetComment() const override
;
611 virtual OUString
GetSdrRepeatComment() const override
;
613 virtual void SdrRepeat(SdrView
& rView
) override
;
614 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
618 * Moving a Page within the List.
619 * Create Action before moving the Page.
622 class SdrUndoSetPageNum final
: public SdrUndoPage
624 sal_uInt16 nOldPageNum
;
625 sal_uInt16 nNewPageNum
;
628 SdrUndoSetPageNum(SdrPage
& rNewPg
, sal_uInt16 nOldPageNum1
, sal_uInt16 nNewPageNum1
)
629 : SdrUndoPage(rNewPg
),nOldPageNum(nOldPageNum1
),nNewPageNum(nNewPageNum1
) {}
631 virtual void Undo() override
;
632 virtual void Redo() override
;
634 virtual OUString
GetComment() const override
;
643 * ABC for all UndoActions that have something to do with
644 * MasterPage relationships.
647 class SdrUndoPageMasterPage
: public SdrUndoPage
650 bool mbOldHadMasterPage
;
651 SdrLayerIDSet maOldSet
;
652 sal_uInt16 maOldMasterPageNumber
;
655 SdrUndoPageMasterPage(SdrPage
& rChangedPage
);
658 UNLESS_MERGELIBS(SVXCORE_DLLPUBLIC
) virtual ~SdrUndoPageMasterPage() override
;
662 * Removal of a MasterPage from a Character Page.
663 * Create Action before removing the MasterPageDescriptor.
666 class SdrUndoPageRemoveMasterPage final
: public SdrUndoPageMasterPage
669 SdrUndoPageRemoveMasterPage(SdrPage
& rChangedPage
);
671 virtual void Undo() override
;
672 virtual void Redo() override
;
674 virtual OUString
GetComment() const override
;
678 * Changing the MasterPageDescriptor (e.g. change of the VisibleLayer).
679 * Create Action before changing the MasterPageDescriptors.
682 class SdrUndoPageChangeMasterPage final
: public SdrUndoPageMasterPage
684 bool mbNewHadMasterPage
;
685 SdrLayerIDSet maNewSet
;
686 sal_uInt16 maNewMasterPageNumber
;
689 SdrUndoPageChangeMasterPage(SdrPage
& rChangedPage
);
691 virtual void Undo() override
;
692 virtual void Redo() override
;
694 virtual OUString
GetComment() const override
;
699 * The SdrUndoFactory can be set and retrieved from the SdrModel.
700 * It is used by the drawing layer implementations to create undo actions.
701 * It can be used by applications to create application specific undo actions.
703 class SVXCORE_DLLPUBLIC SdrUndoFactory
707 virtual ~SdrUndoFactory();
708 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoMoveObject( SdrObject
& rObject
, const Size
& rDist
);
709 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoGeoObject( SdrObject
& rObject
);
710 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoAttrObject( SdrObject
& rObject
, bool bStyleSheet1
= false, bool bSaveText
= false );
711 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoRemoveObject(SdrObject
& rObject
);
712 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoInsertObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
713 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoDeleteObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
714 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoNewObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
715 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoCopyObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
717 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoObjectOrdNum( SdrObject
& rObject
, sal_uInt32 nOldOrdNum1
, sal_uInt32 nNewOrdNum1
);
719 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoReplaceObject( SdrObject
& rOldObject
, SdrObject
& rNewObject
);
720 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoObjectLayerChange( SdrObject
& rObject
, SdrLayerID aOldLayer
, SdrLayerID aNewLayer
);
721 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoObjectSetText( SdrObject
& rNewObj
, sal_Int32 nText
);
723 // Implement Title/Description Elements UI for Writer text frames, graphics and embedded objects (#i73249#)
724 static std::unique_ptr
<SdrUndoAction
> CreateUndoObjectStrAttr( SdrObject
& rObject
,
725 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType
,
726 const OUString
& sOldStr
,
727 const OUString
& sNewStr
);
730 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoNewLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
731 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoDeleteLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
734 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoDeletePage(SdrPage
& rPage
);
735 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoNewPage(SdrPage
& rPage
);
736 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoCopyPage(SdrPage
& rPage
);
737 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoSetPageNum(SdrPage
& rNewPg
, sal_uInt16 nOldPageNum1
, sal_uInt16 nNewPageNum1
);
740 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoPageRemoveMasterPage(SdrPage
& rChangedPage
);
741 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoPageChangeMasterPage(SdrPage
& rChangedPage
);
744 #endif // INCLUDED_SVX_SVDUNDO_HXX
746 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */