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