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