xref: /trunk/main/sw/source/core/inc/UndoCore.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_UNDOCORE_HXX
25 #define SW_UNDOCORE_HXX
26 
27 #include <undobj.hxx>
28 
29 #include <calbck.hxx>
30 
31 
32 class SfxItemSet;
33 class SwFmtColl;
34 class SwFmtAnchor;
35 class SdrMarkList;
36 class SwUndoDelete;
37 class SwRedlineSaveData;
38 class SwFrm;
39 class SwFmt;
40 
41 namespace sw {
42     class UndoManager;
43     class IShellCursorSupplier;
44 }
45 
46 
47 typedef SwRedlineSaveData* SwRedlineSaveDataPtr;
48 SV_DECL_PTRARR_DEL( SwRedlineSaveDatas, SwRedlineSaveDataPtr, 8, 8 )
49 
50 
51 namespace sw {
52 
53 class SW_DLLPRIVATE UndoRedoContext
54     : public SfxUndoContext
55 {
56 public:
UndoRedoContext(SwDoc & rDoc,IShellCursorSupplier & rCursorSupplier)57     UndoRedoContext(SwDoc & rDoc, IShellCursorSupplier & rCursorSupplier)
58         : m_rDoc(rDoc)
59         , m_rCursorSupplier(rCursorSupplier)
60         , m_pSelFmt(0)
61         , m_pMarkList(0)
62     { }
63 
GetDoc() const64     SwDoc & GetDoc() const { return m_rDoc; }
65 
GetCursorSupplier()66     IShellCursorSupplier & GetCursorSupplier() { return m_rCursorSupplier; }
67 
SetSelections(SwFrmFmt * const pSelFmt,SdrMarkList * const pMarkList)68     void SetSelections(SwFrmFmt *const pSelFmt, SdrMarkList *const pMarkList)
69     {
70         m_pSelFmt = pSelFmt;
71         m_pMarkList = pMarkList;
72     }
GetSelections(SwFrmFmt * & o_rpSelFmt,SdrMarkList * & o_rpMarkList)73     void GetSelections(SwFrmFmt *& o_rpSelFmt, SdrMarkList *& o_rpMarkList)
74     {
75         o_rpSelFmt = m_pSelFmt;
76         o_rpMarkList = m_pMarkList;
77     }
78 
79 private:
80     SwDoc & m_rDoc;
81     IShellCursorSupplier & m_rCursorSupplier;
82     SwFrmFmt * m_pSelFmt;
83     SdrMarkList * m_pMarkList;
84 };
85 
86 class SW_DLLPRIVATE RepeatContext
87     : public SfxRepeatTarget
88 {
89 public:
RepeatContext(SwDoc & rDoc,SwPaM & rPaM)90     RepeatContext(SwDoc & rDoc, SwPaM & rPaM)
91         : m_rDoc(rDoc)
92         , m_pCurrentPaM(& rPaM)
93         , m_bDeleteRepeated(false)
94     { }
95 
GetDoc() const96     SwDoc & GetDoc() const { return m_rDoc; }
97 
GetRepeatPaM()98     SwPaM & GetRepeatPaM()
99     {
100         return *m_pCurrentPaM;
101     }
102 
103 private:
104     friend class ::sw::UndoManager;
105     friend class ::SwUndoDelete;
106 
107     SwDoc & m_rDoc;
108     SwPaM * m_pCurrentPaM;
109     bool m_bDeleteRepeated; /// has a delete action been repeated?
110 };
111 
112 } // namespace sw
113 
114 
115 
116 class SwUndoFmtColl : public SwUndo, private SwUndRng
117 {
118     String aFmtName;
119     SwHistory* pHistory;
120     SwFmtColl* pFmtColl;
121     // --> OD 2008-04-15 #refactorlists# - for correct <ReDo(..)> and <Repeat(..)>
122     // boolean, which indicates that the attributes are reseted at the nodes
123     // before the format has been applied.
124     const bool mbReset;
125     // boolean, which indicates that the list attributes had been reseted at
126     // the nodes before the format has been applied.
127     const bool mbResetListAttrs;
128     // <--
129 
130     void DoSetFmtColl(SwDoc & rDoc, SwPaM & rPaM);
131 
132 public:
133     // --> OD 2008-04-15 #refactorlists#
134 //    SwUndoFmtColl( const SwPaM&, SwFmtColl* );
135     SwUndoFmtColl( const SwPaM&, SwFmtColl*,
136                    const bool bReset,
137                    const bool bResetListAttrs );
138     // <--
139     virtual ~SwUndoFmtColl();
140 
141     virtual void UndoImpl( ::sw::UndoRedoContext & );
142     virtual void RedoImpl( ::sw::UndoRedoContext & );
143     virtual void RepeatImpl( ::sw::RepeatContext & );
144 
145     // #111827#
146     /**
147        Returns the rewriter for this undo object.
148 
149        The rewriter contains one rule:
150 
151            $1 -> <name of format collection>
152 
153        <name of format collection> is the name of the format
154        collection that is applied by the action recorded by this undo
155        object.
156 
157        @return the rewriter for this undo object
158     */
159     virtual SwRewriter GetRewriter() const;
160 
GetHistory()161     SwHistory* GetHistory() { return pHistory; }
162 
163 };
164 
165 
166 class SwUndoSetFlyFmt : public SwUndo, public SwClient
167 {
168     SwFrmFmt* pFrmFmt;                  // das gespeicherte FlyFormat
169     SwFrmFmt* pOldFmt;                  // die alte Fly Vorlage
170     SwFrmFmt* pNewFmt;                  // die neue Fly Vorlage
171     SfxItemSet* pItemSet;               // die zurueck-/ gesetzten Attribute
172     sal_uLong nOldNode, nNewNode;
173     xub_StrLen nOldCntnt, nNewCntnt;
174     sal_uInt16 nOldAnchorTyp, nNewAnchorTyp;
175     sal_Bool bAnchorChgd;
176 
177     void PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem );
178     void Modify( const SfxPoolItem*, const SfxPoolItem* );
179     void GetAnchor( SwFmtAnchor& rAnhor, sal_uLong nNode, xub_StrLen nCntnt );
180 
181 public:
182     SwUndoSetFlyFmt( SwFrmFmt& rFlyFmt, SwFrmFmt& rNewFrmFmt );
183     virtual ~SwUndoSetFlyFmt();
184 
185     virtual void UndoImpl( ::sw::UndoRedoContext & );
186     virtual void RedoImpl( ::sw::UndoRedoContext & );
187 
188     virtual SwRewriter GetRewriter() const;
189     void DeRegisterFromFormat( SwFmt& );
190 };
191 
192 
193 //------------ Undo von verschieben/stufen von Gliederung ----------------
194 
195 class SwUndoOutlineLeftRight : public SwUndo, private SwUndRng
196 {
197     short nOffset;
198 public:
199     SwUndoOutlineLeftRight( const SwPaM& rPam, short nOffset );
200 
201     virtual void UndoImpl( ::sw::UndoRedoContext & );
202     virtual void RedoImpl( ::sw::UndoRedoContext & );
203     virtual void RepeatImpl( ::sw::RepeatContext & );
204 };
205 
206 
207 //--------------------------------------------------------------------
208 
209 // -> #111827#
210 const int nUndoStringLength = 20;
211 
212 /**
213    Shortens a string to a maximum length.
214 
215    @param rStr      the string to be shortened
216    @param nLength   the maximum length for rStr
217    @param rFillStr  string to replace cut out characters with
218 
219    If rStr has less than nLength characters it will be returned unaltered.
220 
221    If rStr has more than nLength characters the following algorithm
222    generates the shortened string:
223 
224        frontLength = (nLength - length(rFillStr)) / 2
225        rearLength = nLength - length(rFillStr) - frontLength
226        shortenedString = concat(<first frontLength characters of rStr,
227                                 rFillStr,
228                                 <last rearLength characters of rStr>)
229 
230    Preconditions:
231       - nLength - length(rFillStr) >= 2
232 
233    @return the shortened string
234  */
235 String
236 ShortenString(const String & rStr, xub_StrLen nLength, const String & rFillStr);
237 // <- #111827#
238 
239 // #16487#
240 /**
241    Denotes special characters in a string.
242 
243    The rStr is split into parts containing special characters and
244    parts not containing special characters. In a part containing
245    special characters all characters are equal. These parts are
246    maximal.
247 
248    @param rStr     the string to denote in
249 
250    The resulting string is generated by concatenating the found
251    parts. The parts without special characters are surrounded by
252    "'". The parts containing special characters are denoted as "n x",
253    where n is the length of the part and x is the representation of
254    the special character (i. e. "tab(s)").
255 
256    @return the denoted string
257 */
258 String DenoteSpecialCharacters(const String & rStr);
259 
260 
261 #endif // SW_UNDOCORE_HXX
262 
263