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 <sal/config.h>
28 #include <svl/undo.hxx>
29 #include <svl/style.hxx>
30 #include <tools/gen.hxx>
31 #include <svx/svdtypes.hxx>
32 #include <svx/svdsob.hxx>
33 #include <svx/svxdllapi.h>
47 class OutlinerParaObject
;
50 * Abstract base class (ABC) for all UndoActions of DrawingEngine
53 class SVX_DLLPUBLIC SdrUndoAction
: public SfxUndoAction
57 ViewShellId m_nViewShellId
;
60 SdrUndoAction(SdrModel
& rNewMod
);
63 virtual ~SdrUndoAction() override
;
65 virtual bool CanRepeat(SfxRepeatTarget
& rView
) const override
;
66 virtual void Repeat(SfxRepeatTarget
& rView
) override
;
68 virtual OUString
GetRepeatComment(SfxRepeatTarget
& rView
) const override
;
69 virtual OUString
GetSdrRepeatComment() const;
71 virtual bool CanSdrRepeat(SdrView
& rView
) const;
72 virtual void SdrRepeat(SdrView
& rView
);
74 /// See SfxUndoAction::GetViewShellId().
75 ViewShellId
GetViewShellId() const override
;
79 * Aggregation of arbitrarily many UndoActions to a single UndoAction.
80 * Undo() executes the single UndoActions backwards (LIFO, first the last
81 * ones attached), Redo() executes the UndoActions in the order they were
85 class SVX_DLLPUBLIC SdrUndoGroup final
: public SdrUndoAction
87 std::vector
<std::unique_ptr
<SdrUndoAction
>> maActions
;
89 // No expanded description of the Action (contains %O)
91 OUString aObjDescription
;
93 SdrRepeatFunc eFunction
;
96 SdrUndoGroup(SdrModel
& rNewMod
);
97 virtual ~SdrUndoGroup() override
;
99 sal_Int32
GetActionCount() const { return maActions
.size(); }
100 SdrUndoAction
* GetAction(sal_Int32 nNum
) const { return maActions
[nNum
].get(); }
101 void AddAction(std::unique_ptr
<SdrUndoAction
> pAct
);
103 void SetComment(const OUString
& rStr
) { aComment
=rStr
; }
104 void SetObjDescription(const OUString
& rStr
) { aObjDescription
=rStr
; }
105 virtual OUString
GetComment() const override
;
106 virtual OUString
GetSdrRepeatComment() const override
;
108 virtual void Undo() override
;
109 virtual void Redo() override
;
111 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
112 virtual void SdrRepeat(SdrView
& rView
) override
;
113 void SetRepeatFunction(SdrRepeatFunc eFunc
) { eFunction
=eFunc
; }
117 * Abstract base class for all UndoActions that handle objects.
120 class SVX_DLLPUBLIC SdrUndoObj
: public SdrUndoAction
126 SdrUndoObj(SdrObject
& rNewObj
);
128 OUString
ImpGetDescriptionStr(const char* pStrCacheID
, bool bRepeat
= false) const;
130 [[nodiscard
]] static OUString
GetDescriptionStringForObject( const SdrObject
& _rForObject
, const char* pStrCacheID
, bool bRepeat
= false );
132 // #94278# new method for evtl. PageChange at UNDO/REDO
133 void ImpShowPageOfThisObject();
137 * Changing the object attributes.
138 * Create Action right before setting the new attributes.
139 * Also for StyleSheets.
142 class SVX_DLLPUBLIC SdrUndoAttrObj
: public SdrUndoObj
145 std::unique_ptr
<SfxItemSet
> pUndoSet
;
146 std::unique_ptr
<SfxItemSet
> pRedoSet
;
148 // FIXME: Or should we better remember the StyleSheetNames?
149 rtl::Reference
< SfxStyleSheetBase
> mxUndoStyleSheet
;
150 rtl::Reference
< SfxStyleSheetBase
> mxRedoStyleSheet
;
152 bool bHaveToTakeRedoSet
;
154 // When assigning TextItems to a drawing object with text:
155 std::unique_ptr
<OutlinerParaObject
>
158 // The text rescue mechanism needs also to be implemented for redo actions.
159 std::unique_ptr
<OutlinerParaObject
>
162 // If we have a group object:
163 std::unique_ptr
<SdrUndoGroup
> pUndoGroup
;
165 // Helper to ensure StyleSheet is in pool (provided by SdrModel from SdrObject)
166 static void ensureStyleSheetInStyleSheetPool(SfxStyleSheetBasePool
& rStyleSheetPool
, SfxStyleSheet
& rSheet
);
169 SdrUndoAttrObj(SdrObject
& rNewObj
, bool bStyleSheet1
= false, bool bSaveText
= false);
170 virtual ~SdrUndoAttrObj() override
;
171 virtual void Undo() override
;
172 virtual void Redo() override
;
174 virtual OUString
GetComment() const override
;
175 virtual OUString
GetSdrRepeatComment() const override
;
179 * Only moving of an object.
180 * Create Action right before moving.
183 class SVX_DLLPUBLIC SdrUndoMoveObj final
: public SdrUndoObj
185 Size
const aDistance
; // Distance by which we move
188 SdrUndoMoveObj(SdrObject
& rNewObj
, const Size
& rDist
): SdrUndoObj(rNewObj
),aDistance(rDist
) {}
189 virtual ~SdrUndoMoveObj() override
;
191 virtual void Undo() override
;
192 virtual void Redo() override
;
194 virtual OUString
GetComment() const override
;
195 virtual OUString
GetSdrRepeatComment() const override
;
197 virtual void SdrRepeat(SdrView
& rView
) override
;
198 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
202 * Changing the geometry of an object.
203 * Create Action right before the geometric transformation.
206 class SVX_DLLPUBLIC SdrUndoGeoObj
: public SdrUndoObj
208 std::unique_ptr
<SdrObjGeoData
> pUndoGeo
;
209 std::unique_ptr
<SdrObjGeoData
> pRedoGeo
;
210 // If we have a group object:
211 std::unique_ptr
<SdrUndoGroup
> pUndoGroup
;
212 /// If we have a table object, should its layout change?
213 bool mbSkipChangeLayout
;
216 SdrUndoGeoObj(SdrObject
& rNewObj
);
217 virtual ~SdrUndoGeoObj() override
;
219 virtual void Undo() override
;
220 virtual void Redo() override
;
222 virtual OUString
GetComment() const override
;
223 void SetSkipChangeLayout(bool bOn
) { mbSkipChangeLayout
=bOn
; }
227 * Manipulation of an ObjList: New Object, DeleteObj, SetObjZLevel, Grouping, ...
228 * Abstract base class.
231 class SVX_DLLPUBLIC SdrUndoObjList
: public SdrUndoObj
{
232 class ObjListListener
;
233 friend class ObjListListener
;
239 SdrObjList
* pObjList
;
243 SdrUndoObjList(SdrObject
& rNewObj
, bool bOrdNumDirect
);
244 virtual ~SdrUndoObjList() override
;
246 bool IsOwner() const { return bOwner
; }
247 void SetOwner(bool bNew
);
251 * Removing an Object from an ObjectList.
252 * To be used with corresponding Inserts within a UndoGroup.
254 * Create Action before removing from the ObjList.
257 class SVX_DLLPUBLIC SdrUndoRemoveObj
: public SdrUndoObjList
260 SdrUndoRemoveObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
261 : SdrUndoObjList(rNewObj
,bOrdNumDirect
) {}
263 virtual void Undo() override
;
264 virtual void Redo() override
;
266 virtual ~SdrUndoRemoveObj() override
;
270 * Inserting Objects into an ObjectList.
271 * Use with corresponding Removes within an UndoGroup.
272 * Create Action before removal from ObjList.
275 class SVX_DLLPUBLIC SdrUndoInsertObj
: public SdrUndoObjList
278 SdrUndoInsertObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
279 : SdrUndoObjList(rNewObj
,bOrdNumDirect
) {}
281 virtual void Undo() override
;
282 virtual void Redo() override
;
286 * Deleting an Object.
287 * Create Action before removing from ObjList.
290 class SVX_DLLPUBLIC SdrUndoDelObj
: public SdrUndoRemoveObj
293 SdrUndoDelObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false);
295 virtual void Undo() override
;
296 virtual void Redo() override
;
298 virtual OUString
GetComment() const override
;
299 virtual OUString
GetSdrRepeatComment() const override
;
301 virtual void SdrRepeat(SdrView
& rView
) override
;
302 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
306 * Inserting a NEW Object.
307 * Create Action after insertion into the ObjList.
310 class SVX_DLLPUBLIC SdrUndoNewObj
: public SdrUndoInsertObj
313 SdrUndoNewObj(SdrObject
& rNewObj
, bool bOrdNumDirect
= false)
314 : SdrUndoInsertObj(rNewObj
,bOrdNumDirect
) {}
316 virtual void Undo() override
;
317 virtual void Redo() override
;
319 virtual OUString
GetComment() const override
;
321 static OUString
GetComment(const SdrObject
& _rForObject
);
325 * Replacing an Object.
326 * Create Action before Replace in ObjList.
329 class SVX_DLLPUBLIC SdrUndoReplaceObj
: public SdrUndoObj
334 SdrObjList
* pObjList
;
338 SdrUndoReplaceObj(SdrObject
& rOldObj1
, SdrObject
& rNewObj1
);
339 virtual ~SdrUndoReplaceObj() override
;
341 virtual void Undo() override
;
342 virtual void Redo() override
;
344 bool IsNewOwner() const { return bNewOwner
; }
345 void SetNewOwner(bool bNew
);
347 bool IsOldOwner() const { return bOldOwner
; }
348 void SetOldOwner(bool bNew
);
353 * Create Action before inserting into the ObjList.
356 class SdrUndoCopyObj final
: public SdrUndoNewObj
359 SdrUndoCopyObj(SdrObject
& rNewObj
, bool bOrdNumDirect
)
360 : SdrUndoNewObj(rNewObj
,bOrdNumDirect
) {}
362 virtual OUString
GetComment() const override
;
365 class SdrUndoObjOrdNum final
: public SdrUndoObj
367 sal_uInt32
const nOldOrdNum
;
368 sal_uInt32
const nNewOrdNum
;
371 SdrUndoObjOrdNum(SdrObject
& rNewObj
, sal_uInt32 nOldOrdNum1
, sal_uInt32 nNewOrdNum1
);
373 virtual void Undo() override
;
374 virtual void Redo() override
;
376 virtual OUString
GetComment() const override
;
382 class SVX_DLLPUBLIC SdrUndoObjectLayerChange final
: public SdrUndoObj
384 SdrLayerID
const maOldLayer
;
385 SdrLayerID
const maNewLayer
;
388 SdrUndoObjectLayerChange(SdrObject
& rObj
, SdrLayerID aOldLayer
, SdrLayerID aNewLayer
);
390 virtual void Undo() override
;
391 virtual void Redo() override
;
394 class SVX_DLLPUBLIC SdrUndoObjSetText
: public SdrUndoObj
397 std::unique_ptr
<OutlinerParaObject
>
399 std::unique_ptr
<OutlinerParaObject
>
401 bool bNewTextAvailable
;
403 sal_Int32
const mnText
;
406 SdrUndoObjSetText(SdrObject
& rNewObj
, sal_Int32 nText
);
407 virtual ~SdrUndoObjSetText() override
;
409 bool IsDifferent() const { return pOldText
!=pNewText
; }
412 virtual void Undo() override
;
413 virtual void Redo() override
;
415 virtual OUString
GetComment() const override
;
416 virtual OUString
GetSdrRepeatComment() const override
;
418 virtual void SdrRepeat(SdrView
& rView
) override
;
419 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
423 * Implement Title/Description Elements UI for Writer
424 * text frames, graphics and embedded objects (#i73249#)
426 class SdrUndoObjStrAttr final
: public SdrUndoObj
429 enum class ObjStrAttrType
436 SdrUndoObjStrAttr( SdrObject
& rNewObj
,
437 const ObjStrAttrType eObjStrAttr
,
438 const OUString
& sOldStr
,
439 const OUString
& sNewStr
);
441 virtual void Undo() override
;
442 virtual void Redo() override
;
444 virtual OUString
GetComment() const override
;
447 const ObjStrAttrType meObjStrAttr
;
448 const OUString msOldStr
;
449 const OUString msNewStr
;
459 * Abstract base class for all UndoActions that have something to do with SdrLayer.
462 class SdrUndoLayer
: public SdrUndoAction
465 SdrLayer
* const pLayer
;
466 SdrLayerAdmin
* pLayerAdmin
;
467 sal_uInt16
const nNum
;
471 SdrUndoLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
472 virtual ~SdrUndoLayer() override
;
476 * Inserting a new Layer.
477 * Create Action after Insertion.
480 class SdrUndoNewLayer final
: public SdrUndoLayer
483 SdrUndoNewLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
)
484 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
) {}
486 virtual void Undo() override
;
487 virtual void Redo() override
;
489 virtual OUString
GetComment() const override
;
494 * Create Action before the Remove.
497 class SdrUndoDelLayer final
: public SdrUndoLayer
500 SdrUndoDelLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
)
501 : SdrUndoLayer(nLayerNum
,rNewLayerAdmin
,rNewModel
) { bItsMine
=true; }
503 virtual void Undo() override
;
504 virtual void Redo() override
;
506 virtual OUString
GetComment() const override
;
514 * ABC for all UndoActions that have something to do with SdrPages.
517 class SVX_DLLPUBLIC SdrUndoPage
: public SdrUndoAction
523 void ImpInsertPage(sal_uInt16 nNum
);
524 void ImpRemovePage(sal_uInt16 nNum
);
525 void ImpMovePage(sal_uInt16 nOldNum
, sal_uInt16 nNewNum
);
528 SdrUndoPage(SdrPage
& rNewPg
);
530 static OUString
ImpGetDescriptionStr(const char* pStrCacheID
);
534 * ABC for manipulation of a PageList: New Page, DeletePage, MovePage (ChangePageNum).
537 class SVX_DLLPUBLIC SdrUndoPageList
: public SdrUndoPage
542 // It's possible that the object is re-assigned during a Undo/Redo.
543 // The Page is deleted in the dtor, if bItsMine==TRUE
547 SdrUndoPageList(SdrPage
& rNewPg
);
548 virtual ~SdrUndoPageList() override
;
553 * Create Action before removing from the List.
556 class SVX_DLLPUBLIC SdrUndoDelPage final
: public SdrUndoPageList
558 // When deleting a MasterPage, we remember all relations of the
559 // Character Page with the MasterPage in this UndoGroup.
560 std::unique_ptr
<SdrUndoGroup
> pUndoGroup
;
561 std::unique_ptr
<SfxPoolItem
> mpFillBitmapItem
;
562 bool mbHasFillBitmap
;
565 SdrUndoDelPage(SdrPage
& rNewPg
);
566 virtual ~SdrUndoDelPage() override
;
568 virtual void Undo() override
;
569 virtual void Redo() override
;
571 virtual OUString
GetComment() const override
;
572 virtual OUString
GetSdrRepeatComment() const override
;
574 virtual void SdrRepeat(SdrView
& rView
) override
;
575 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
578 void queryFillBitmap(const SfxItemSet
&rItemSet
);
579 void clearFillBitmap();
580 void restoreFillBitmap();
584 * Inserting a new Page.
585 * Create Action after inserting into the List.
588 class SVX_DLLPUBLIC SdrUndoNewPage
: public SdrUndoPageList
591 SdrUndoNewPage(SdrPage
& rNewPg
): SdrUndoPageList(rNewPg
) {}
593 virtual void Undo() override
;
594 virtual void Redo() override
;
596 virtual OUString
GetComment() const override
;
601 * Create Action after inserting into the List.
604 class SdrUndoCopyPage final
: public SdrUndoNewPage
607 SdrUndoCopyPage(SdrPage
& rNewPg
): SdrUndoNewPage(rNewPg
) {}
609 virtual OUString
GetComment() const override
;
610 virtual OUString
GetSdrRepeatComment() const override
;
612 virtual void SdrRepeat(SdrView
& rView
) override
;
613 virtual bool CanSdrRepeat(SdrView
& rView
) const override
;
617 * Moving a Page within the List.
618 * Create Action before moving the Page.
621 class SVX_DLLPUBLIC SdrUndoSetPageNum final
: public SdrUndoPage
623 sal_uInt16
const nOldPageNum
;
624 sal_uInt16
const nNewPageNum
;
627 SdrUndoSetPageNum(SdrPage
& rNewPg
, sal_uInt16 nOldPageNum1
, sal_uInt16 nNewPageNum1
)
628 : SdrUndoPage(rNewPg
),nOldPageNum(nOldPageNum1
),nNewPageNum(nNewPageNum1
) {}
630 virtual void Undo() override
;
631 virtual void Redo() override
;
633 virtual OUString
GetComment() const override
;
642 * ABC for all UndoActions that have something to do with
643 * MasterPage relationships.
646 class SdrUndoPageMasterPage
: public SdrUndoPage
649 bool const mbOldHadMasterPage
;
650 SdrLayerIDSet maOldSet
;
651 sal_uInt16 maOldMasterPageNumber
;
654 SdrUndoPageMasterPage(SdrPage
& rChangedPage
);
657 SVX_DLLPUBLIC
virtual ~SdrUndoPageMasterPage() override
;
661 * Removal of a MasterPage from a Character Page.
662 * Create Action before removing the MasterPageDescriptor.
665 class SdrUndoPageRemoveMasterPage final
: public SdrUndoPageMasterPage
668 SdrUndoPageRemoveMasterPage(SdrPage
& rChangedPage
);
670 virtual void Undo() override
;
671 virtual void Redo() override
;
673 virtual OUString
GetComment() const override
;
677 * Changing the MasterPageDescriptor (e.g. change of the VisibleLayer).
678 * Create Action before changing the MasterPageDescriptors.
681 class SVX_DLLPUBLIC SdrUndoPageChangeMasterPage final
: public SdrUndoPageMasterPage
683 bool mbNewHadMasterPage
;
684 SdrLayerIDSet maNewSet
;
685 sal_uInt16 maNewMasterPageNumber
;
688 SdrUndoPageChangeMasterPage(SdrPage
& rChangedPage
);
690 virtual void Undo() override
;
691 virtual void Redo() override
;
693 virtual OUString
GetComment() const override
;
698 * The SdrUndoFactory can be set and retrieved from the SdrModel.
699 * It is used by the drawing layer implementations to create undo actions.
700 * It can be used by applications to create application specific undo actions.
702 class SVX_DLLPUBLIC SdrUndoFactory
706 virtual ~SdrUndoFactory();
707 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoMoveObject( SdrObject
& rObject
, const Size
& rDist
);
708 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoGeoObject( SdrObject
& rObject
);
709 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoAttrObject( SdrObject
& rObject
, bool bStyleSheet1
= false, bool bSaveText
= false );
710 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoRemoveObject(SdrObject
& rObject
);
711 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoInsertObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
712 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoDeleteObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
713 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoNewObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
714 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoCopyObject( SdrObject
& rObject
, bool bOrdNumDirect
= false);
716 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoObjectOrdNum( SdrObject
& rObject
, sal_uInt32 nOldOrdNum1
, sal_uInt32 nNewOrdNum1
);
718 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoReplaceObject( SdrObject
& rOldObject
, SdrObject
& rNewObject
);
719 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoObjectLayerChange( SdrObject
& rObject
, SdrLayerID aOldLayer
, SdrLayerID aNewLayer
);
720 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoObjectSetText( SdrObject
& rNewObj
, sal_Int32 nText
);
722 // Implement Title/Description Elements UI for Writer text frames, graphics and embedded objects (#i73249#)
723 static std::unique_ptr
<SdrUndoAction
> CreateUndoObjectStrAttr( SdrObject
& rObject
,
724 SdrUndoObjStrAttr::ObjStrAttrType eObjStrAttrType
,
725 const OUString
& sOldStr
,
726 const OUString
& sNewStr
);
729 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoNewLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
730 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoDeleteLayer(sal_uInt16 nLayerNum
, SdrLayerAdmin
& rNewLayerAdmin
, SdrModel
& rNewModel
);
733 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoDeletePage(SdrPage
& rPage
);
734 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoNewPage(SdrPage
& rPage
);
735 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoCopyPage(SdrPage
& rPage
);
736 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoSetPageNum(SdrPage
& rNewPg
, sal_uInt16 nOldPageNum1
, sal_uInt16 nNewPageNum1
);
739 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoPageRemoveMasterPage(SdrPage
& rChangedPage
);
740 virtual std::unique_ptr
<SdrUndoAction
> CreateUndoPageChangeMasterPage(SdrPage
& rChangedPage
);
743 #endif // INCLUDED_SVX_SVDUNDO_HXX
745 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */