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