Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
21 : #define INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
22 :
23 : #include <undobj.hxx>
24 : #include <calbck.hxx>
25 : #include <rtl/ustring.hxx>
26 :
27 : class SfxItemSet;
28 : class SwFmtColl;
29 : class SwFmtAnchor;
30 : class SdrMarkList;
31 : class SwUndoDelete;
32 : class SwRedlineSaveData;
33 : class SwFmt;
34 :
35 : namespace sw {
36 : class UndoManager;
37 : class IShellCursorSupplier;
38 : }
39 :
40 0 : class SwRedlineSaveDatas : public std::vector<SwRedlineSaveData*> {
41 : public:
42 0 : ~SwRedlineSaveDatas() { DeleteAndDestroyAll(); }
43 :
44 : void DeleteAndDestroyAll();
45 : };
46 :
47 : namespace sw {
48 0 : class UndoRedoContext
49 : : public SfxUndoContext
50 : {
51 : public:
52 0 : UndoRedoContext(SwDoc & rDoc, IShellCursorSupplier & rCursorSupplier)
53 : : m_rDoc(rDoc)
54 : , m_rCursorSupplier(rCursorSupplier)
55 : , m_pSelFmt(0)
56 0 : , m_pMarkList(0)
57 0 : { }
58 :
59 0 : SwDoc & GetDoc() const { return m_rDoc; }
60 :
61 0 : IShellCursorSupplier & GetCursorSupplier() { return m_rCursorSupplier; }
62 :
63 0 : void SetSelections(SwFrmFmt *const pSelFmt, SdrMarkList *const pMarkList)
64 : {
65 0 : m_pSelFmt = pSelFmt;
66 0 : m_pMarkList = pMarkList;
67 0 : }
68 0 : void GetSelections(SwFrmFmt *& o_rpSelFmt, SdrMarkList *& o_rpMarkList)
69 : {
70 0 : o_rpSelFmt = m_pSelFmt;
71 0 : o_rpMarkList = m_pMarkList;
72 0 : }
73 :
74 : private:
75 : SwDoc & m_rDoc;
76 : IShellCursorSupplier & m_rCursorSupplier;
77 : SwFrmFmt * m_pSelFmt;
78 : SdrMarkList * m_pMarkList;
79 : };
80 :
81 0 : class RepeatContext
82 : : public SfxRepeatTarget
83 : {
84 : public:
85 0 : RepeatContext(SwDoc & rDoc, SwPaM & rPaM)
86 : : m_rDoc(rDoc)
87 : , m_pCurrentPaM(& rPaM)
88 0 : , m_bDeleteRepeated(false)
89 0 : { }
90 :
91 0 : SwDoc & GetDoc() const { return m_rDoc; }
92 :
93 0 : SwPaM & GetRepeatPaM()
94 : {
95 0 : return *m_pCurrentPaM;
96 : }
97 :
98 : private:
99 : friend class ::sw::UndoManager;
100 : friend class ::SwUndoDelete;
101 :
102 : SwDoc & m_rDoc;
103 : SwPaM * m_pCurrentPaM;
104 : bool m_bDeleteRepeated; /// has a delete action been repeated?
105 : };
106 :
107 : } // namespace sw
108 :
109 : class SwUndoFmtColl : public SwUndo, private SwUndRng
110 : {
111 : OUString aFmtName;
112 : SwHistory* pHistory;
113 : SwFmtColl* pFmtColl;
114 : // for correct <ReDo(..)> and <Repeat(..)>
115 : // boolean, which indicates that the attributes are reseted at the nodes
116 : // before the format has been applied.
117 : const bool mbReset;
118 : // boolean, which indicates that the list attributes had been reseted at
119 : // the nodes before the format has been applied.
120 : const bool mbResetListAttrs;
121 :
122 : void DoSetFmtColl(SwDoc & rDoc, SwPaM & rPaM);
123 :
124 : public:
125 : SwUndoFmtColl( const SwPaM&, SwFmtColl*,
126 : const bool bReset,
127 : const bool bResetListAttrs );
128 : virtual ~SwUndoFmtColl();
129 :
130 : virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
131 : virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
132 : virtual void RepeatImpl( ::sw::RepeatContext & ) SAL_OVERRIDE;
133 :
134 : /**
135 : Returns the rewriter for this undo object.
136 :
137 : The rewriter contains one rule:
138 :
139 : $1 -> <name of format collection>
140 :
141 : <name of format collection> is the name of the format
142 : collection that is applied by the action recorded by this undo
143 : object.
144 :
145 : @return the rewriter for this undo object
146 : */
147 : virtual SwRewriter GetRewriter() const SAL_OVERRIDE;
148 :
149 0 : SwHistory* GetHistory() { return pHistory; }
150 :
151 : };
152 :
153 : class SwUndoSetFlyFmt : public SwUndo, public SwClient
154 : {
155 : SwFrmFmt* pFrmFmt; // saved FlyFormat
156 : SwFrmFmt* pOldFmt;
157 : SwFrmFmt* pNewFmt;
158 : SfxItemSet* pItemSet; // the re-/ set attributes
159 : sal_uLong nOldNode, nNewNode;
160 : sal_Int32 nOldCntnt, nNewCntnt;
161 : sal_uInt16 nOldAnchorTyp, nNewAnchorTyp;
162 : bool bAnchorChgd;
163 :
164 : void PutAttr( sal_uInt16 nWhich, const SfxPoolItem* pItem );
165 : void Modify( const SfxPoolItem*, const SfxPoolItem* ) SAL_OVERRIDE;
166 : void GetAnchor( SwFmtAnchor& rAnhor, sal_uLong nNode, sal_Int32 nCntnt );
167 :
168 : public:
169 : SwUndoSetFlyFmt( SwFrmFmt& rFlyFmt, SwFrmFmt& rNewFrmFmt );
170 : virtual ~SwUndoSetFlyFmt();
171 :
172 : virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
173 : virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
174 :
175 : virtual SwRewriter GetRewriter() const SAL_OVERRIDE;
176 : void DeRegisterFromFormat( SwFmt& );
177 : };
178 :
179 0 : class SwUndoOutlineLeftRight : public SwUndo, private SwUndRng
180 : {
181 : short nOffset;
182 :
183 : public:
184 : SwUndoOutlineLeftRight( const SwPaM& rPam, short nOffset );
185 :
186 : virtual void UndoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
187 : virtual void RedoImpl( ::sw::UndoRedoContext & ) SAL_OVERRIDE;
188 : virtual void RepeatImpl( ::sw::RepeatContext & ) SAL_OVERRIDE;
189 : };
190 :
191 : const int nUndoStringLength = 20;
192 :
193 : /**
194 : Shortens a string to a maximum length.
195 :
196 : @param rStr the string to be shortened
197 : @param nLength the maximum length for rStr
198 : @param rFillStr string to replace cut out characters with
199 :
200 : If rStr has less than nLength characters it will be returned unaltered.
201 :
202 : If rStr has more than nLength characters the following algorithm
203 : generates the shortened string:
204 :
205 : frontLength = (nLength - length(rFillStr)) / 2
206 : rearLength = nLength - length(rFillStr) - frontLength
207 : shortenedString = concat(<first frontLength characters of rStr,
208 : rFillStr,
209 : <last rearLength characters of rStr>)
210 :
211 : Preconditions:
212 : - nLength - length(rFillStr) >= 2
213 :
214 : @return the shortened string
215 : */
216 : OUString
217 : ShortenString(const OUString & rStr, sal_Int32 nLength, const OUString & rFillStr);
218 : /**
219 : Denotes special characters in a string.
220 :
221 : The rStr is split into parts containing special characters and
222 : parts not containing special characters. In a part containing
223 : special characters all characters are equal. These parts are
224 : maximal.
225 :
226 : @param rStr the string to denote in
227 :
228 : The resulting string is generated by concatenating the found
229 : parts. The parts without special characters are surrounded by
230 : "'". The parts containing special characters are denoted as "n x",
231 : where n is the length of the part and x is the representation of
232 : the special character (i. e. "tab(s)").
233 :
234 : @return the denoted string
235 : */
236 : OUString DenoteSpecialCharacters(const OUString & rStr);
237 :
238 : #endif // INCLUDED_SW_SOURCE_CORE_INC_UNDOCORE_HXX
239 :
240 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|