xref: /aoo42x/main/sw/source/core/inc/UndoAttribute.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef SW_UNDO_ATTRIBUTE_HXX
29 #define SW_UNDO_ATTRIBUTE_HXX
30 
31 #include <undobj.hxx>
32 
33 #include <memory>
34 
35 #ifndef _SVSTDARR_HXX
36 #define _SVSTDARR_USHORTS
37 #define _SVSTDARR_ULONGS
38 #define _SVSTDARR_BOOLS
39 #define _SVSTDARR_BYTES
40 #define _SVSTDARR_USHORTSSORT
41 #include <svl/svstdarr.hxx>
42 #endif
43 #include <svl/itemset.hxx>
44 
45 #include <swtypes.hxx>
46 #include <calbck.hxx>
47 
48 
49 class SvxTabStopItem;
50 class SwFmt;
51 class SwFtnInfo;
52 class SwEndNoteInfo;
53 
54 
55 class SwUndoAttr : public SwUndo, private SwUndRng
56 {
57     SfxItemSet m_AttrSet;                           // attributes for Redo
58     const ::std::auto_ptr<SwHistory> m_pHistory;    // History for Undo
59     ::std::auto_ptr<SwRedlineData> m_pRedlineData;  // Redlining
60     ::std::auto_ptr<SwRedlineSaveDatas> m_pRedlineSaveData;
61     sal_uLong m_nNodeIndex;                             // Offset: for Redlining
62     const SetAttrMode m_nInsertFlags;               // insert flags
63 
64     void RemoveIdx( SwDoc& rDoc );
65 
66 public:
67     SwUndoAttr( const SwPaM&, const SfxItemSet &, const SetAttrMode nFlags );
68     SwUndoAttr( const SwPaM&, const SfxPoolItem&, const SetAttrMode nFlags );
69 
70     virtual ~SwUndoAttr();
71 
72     virtual void UndoImpl( ::sw::UndoRedoContext & );
73     virtual void RedoImpl( ::sw::UndoRedoContext & );
74     virtual void RepeatImpl( ::sw::RepeatContext & );
75 
76     void SaveRedlineData( const SwPaM& rPam, sal_Bool bInsCntnt );
77 
78     SwHistory& GetHistory() { return *m_pHistory; }
79 
80 };
81 
82 class SwUndoResetAttr : public SwUndo, private SwUndRng
83 {
84     const ::std::auto_ptr<SwHistory> m_pHistory;
85     SvUShortsSort m_Ids;
86     const sal_uInt16 m_nFormatId;             // Format-Id for Redo
87 
88 public:
89     SwUndoResetAttr( const SwPaM&, sal_uInt16 nFmtId );
90     SwUndoResetAttr( const SwPosition&, sal_uInt16 nFmtId );
91 
92     virtual ~SwUndoResetAttr();
93 
94     virtual void UndoImpl( ::sw::UndoRedoContext & );
95     virtual void RedoImpl( ::sw::UndoRedoContext & );
96     virtual void RepeatImpl( ::sw::RepeatContext & );
97 
98     void SetAttrs( const SvUShortsSort& rArr );
99 
100     SwHistory& GetHistory() { return *m_pHistory; }
101 
102 };
103 
104 class SwUndoFmtAttr : public SwUndo
105 {
106     friend class SwUndoDefaultAttr;
107     SwFmt * m_pFmt;
108     ::std::auto_ptr<SfxItemSet> m_pOldSet;    // old attributes
109     sal_uLong m_nNodeIndex;
110     const sal_uInt16 m_nFmtWhich;
111     const bool m_bSaveDrawPt;
112 
113     bool IsFmtInDoc( SwDoc* );   //is the attribute format still in the Doc?
114     void SaveFlyAnchor( bool bSaveDrawPt = false );
115     // --> OD 2004-10-26 #i35443# - Add return value, type <bool>.
116     // Return value indicates, if anchor attribute is restored.
117     // Notes: - If anchor attribute is restored, all other existing attributes
118     //          are also restored.
119     //        - Anchor attribute isn't restored successfully, if it contains
120     //          an invalid anchor position and all other existing attributes
121     //          aren't restored.
122     //          This situation occurs for undo of styles.
123     bool RestoreFlyAnchor(::sw::UndoRedoContext & rContext);
124     // <--
125     // --> OD 2008-02-27 #refactorlists# - removed <rAffectedItemSet>
126     void Init();
127     // <--
128 
129 public:
130     // register at the Format and save old attributes
131     // --> OD 2008-02-27 #refactorlists# - removed <rNewSet>
132     SwUndoFmtAttr( const SfxItemSet& rOldSet,
133                    SwFmt& rFmt,
134                    bool bSaveDrawPt = true );
135     // <--
136     SwUndoFmtAttr( const SfxPoolItem& rItem,
137                    SwFmt& rFmt,
138                    bool bSaveDrawPt = true );
139 
140     virtual ~SwUndoFmtAttr();
141 
142     virtual void UndoImpl( ::sw::UndoRedoContext & );
143     virtual void RedoImpl( ::sw::UndoRedoContext & );
144     virtual void RepeatImpl( ::sw::RepeatContext & );
145 
146     virtual SwRewriter GetRewriter() const;
147 
148     void PutAttr( const SfxPoolItem& rItem );
149     SwFmt* GetFmt( SwDoc& rDoc );   // checks if it is still in the Doc!
150 };
151 
152 // --> OD 2008-02-12 #newlistlevelattrs#
153 class SwUndoFmtResetAttr : public SwUndo
154 {
155     public:
156         SwUndoFmtResetAttr( SwFmt& rChangedFormat,
157                             const sal_uInt16 nWhichId );
158         ~SwUndoFmtResetAttr();
159 
160         virtual void UndoImpl( ::sw::UndoRedoContext & );
161         virtual void RedoImpl( ::sw::UndoRedoContext & );
162 
163     private:
164         // format at which a certain attribute is reset.
165         SwFmt * const m_pChangedFormat;
166         // which ID of the reset attribute
167         const sal_uInt16 m_nWhichId;
168         // old attribute which has been reset - needed for undo.
169         ::std::auto_ptr<SfxPoolItem> m_pOldItem;
170 };
171 // <--
172 
173 class SwUndoDontExpandFmt : public SwUndo
174 {
175     const sal_uLong m_nNodeIndex;
176     const xub_StrLen m_nContentIndex;
177 
178 public:
179     SwUndoDontExpandFmt( const SwPosition& rPos );
180 
181     virtual void UndoImpl( ::sw::UndoRedoContext & );
182     virtual void RedoImpl( ::sw::UndoRedoContext & );
183     virtual void RepeatImpl( ::sw::RepeatContext & );
184 };
185 
186 // helper class to receive changed attribute sets
187 class SwUndoFmtAttrHelper : public SwClient
188 {
189     ::std::auto_ptr<SwUndoFmtAttr> m_pUndo;
190     const bool m_bSaveDrawPt;
191 
192 public:
193     SwUndoFmtAttrHelper( SwFmt& rFmt, bool bSaveDrawPt = true );
194 
195     virtual void Modify( const SfxPoolItem*, const SfxPoolItem* );
196 
197     SwUndoFmtAttr* GetUndo() const  { return m_pUndo.get(); }
198     // release the undo object (so it is not deleted here), and return it
199     SwUndoFmtAttr* ReleaseUndo()    { return m_pUndo.release(); }
200 };
201 
202 
203 class SwUndoMoveLeftMargin : public SwUndo, private SwUndRng
204 {
205     const ::std::auto_ptr<SwHistory> m_pHistory;
206     const bool m_bModulus;
207 
208 public:
209     SwUndoMoveLeftMargin( const SwPaM&, sal_Bool bRight, sal_Bool bModulus );
210 
211     virtual ~SwUndoMoveLeftMargin();
212 
213     virtual void UndoImpl( ::sw::UndoRedoContext & );
214     virtual void RedoImpl( ::sw::UndoRedoContext & );
215     virtual void RepeatImpl( ::sw::RepeatContext & );
216 
217     SwHistory& GetHistory() { return *m_pHistory; }
218 
219 };
220 
221 
222 //--------------------------------------------------------------------
223 
224 class SwUndoDefaultAttr : public SwUndo
225 {
226     ::std::auto_ptr<SfxItemSet> m_pOldSet;        // the old attributes
227     ::std::auto_ptr<SvxTabStopItem> m_pTabStop;
228 
229 public:
230     // registers at the format and saves old attributes
231     SwUndoDefaultAttr( const SfxItemSet& rOldSet );
232 
233     virtual ~SwUndoDefaultAttr();
234 
235     virtual void UndoImpl( ::sw::UndoRedoContext & );
236     virtual void RedoImpl( ::sw::UndoRedoContext & );
237 };
238 
239 
240 //--------------------------------------------------------------------
241 
242 class SwUndoChangeFootNote : public SwUndo, private SwUndRng
243 {
244     const ::std::auto_ptr<SwHistory> m_pHistory;
245     const String m_Text;
246     const sal_uInt16 m_nNumber;
247     const bool m_bEndNote;
248 
249 public:
250     SwUndoChangeFootNote( const SwPaM& rRange, const String& rTxt,
251                           sal_uInt16 nNum, bool bIsEndNote );
252     virtual ~SwUndoChangeFootNote();
253 
254     virtual void UndoImpl( ::sw::UndoRedoContext & );
255     virtual void RedoImpl( ::sw::UndoRedoContext & );
256     virtual void RepeatImpl( ::sw::RepeatContext & );
257 
258     SwHistory& GetHistory() { return *m_pHistory; }
259 };
260 
261 class SwUndoFootNoteInfo : public SwUndo
262 {
263     ::std::auto_ptr<SwFtnInfo> m_pFootNoteInfo;
264 
265 public:
266     SwUndoFootNoteInfo( const SwFtnInfo &rInfo );
267 
268     virtual ~SwUndoFootNoteInfo();
269 
270     virtual void UndoImpl( ::sw::UndoRedoContext & );
271     virtual void RedoImpl( ::sw::UndoRedoContext & );
272 };
273 
274 class SwUndoEndNoteInfo : public SwUndo
275 {
276     ::std::auto_ptr<SwEndNoteInfo> m_pEndNoteInfo;
277 
278 public:
279     SwUndoEndNoteInfo( const SwEndNoteInfo &rInfo );
280 
281     virtual ~SwUndoEndNoteInfo();
282 
283     virtual void UndoImpl( ::sw::UndoRedoContext & );
284     virtual void RedoImpl( ::sw::UndoRedoContext & );
285 };
286 
287 #endif // SW_UNDO_ATTRIBUTE_HXX
288 
289