xref: /trunk/main/sw/inc/undobj.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 #ifndef SW_UNDOBJ_HXX
24 #define SW_UNDOBJ_HXX
25 
26 #include <vector>
27 
28 #include <boost/shared_ptr.hpp>
29 
30 #include <svl/undo.hxx>
31 
32 #include <SwRewriter.hxx>
33 #include <swundo.hxx>
34 
35 
36 class SwHistory;
37 class SwIndex;
38 class SwPaM;
39 struct SwPosition;
40 class SwDoc;
41 class SwTxtFmtColl;
42 class SwFrmFmt;
43 class SwNodeIndex;
44 class SwNodeRange;
45 class SwRedlineData;
46 class SwRedlineSaveDatas;
47 
48 namespace sw {
49     class UndoRedoContext;
50     class RepeatContext;
51 }
52 
53 
54 class SwUndo
55     : public SfxUndoAction
56 {
57     SwUndoId const m_nId;
58 	sal_uInt16 nOrigRedlineMode;
59 
60 protected:
61     bool bCacheComment;
62     mutable String * pComment;
63 
64 	void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
65 	void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext );
66 	void RemoveIdxRel( sal_uLong, const SwPosition& );
67 
68 	static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
69 								const SwRedlineSaveDatas& rCheck,
70 								sal_Bool bCurrIsEnd );
71 
72     // #111827#
73     /**
74        Returns the rewriter for this object.
75 
76        @return the rewriter for this object
77     */
78     virtual SwRewriter GetRewriter() const;
79 
80     // return type is sal_uInt16 because this overrides SfxUndoAction::GetId()
GetId() const81     virtual sal_uInt16 GetId() const { return static_cast<sal_uInt16>(m_nId); }
82 
83     // the 4 methods that derived classes have to override
84     // base implementation does nothing
85     virtual void RepeatImpl( ::sw::RepeatContext & );
86     virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const;
87 public: // should not be public, but ran into trouble in untbl.cxx
88     virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
89     virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
90 
91 private:
92     // SfxUndoAction
93     virtual void Undo();
94     virtual void Redo();
95     virtual void UndoWithContext(SfxUndoContext &);
96     virtual void RedoWithContext(SfxUndoContext &);
97     virtual void Repeat(SfxRepeatTarget &);
98     virtual sal_Bool CanRepeat(SfxRepeatTarget &) const;
99 
100 public:
101     SwUndo(SwUndoId const nId);
102 	virtual ~SwUndo();
103 
104     // #111827#
105     /**
106        Returns textual comment for this undo object.
107 
108        The textual comment is created from the resource string
109        corresponding to this object's ID. The rewriter of this object
110        is applied to the resource string to get the final comment.
111 
112        @return textual comment for this undo object
113     */
114     virtual String GetComment() const;
115 
116 		// das UndoObject merkt sich, welcher Mode eingeschaltet war.
117 		// In Undo/Redo/Repeat wird dann immer auf diesen zurueck geschaltet
GetRedlineMode() const118 	sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
SetRedlineMode(sal_uInt16 eMode)119 	void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
120 
121     bool IsDelBox() const;
122 
123 		// sicher und setze die RedlineDaten
124 	static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
125 							sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True );
126 	static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
127 	static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
128 	static sal_Bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
129 };
130 
131 typedef sal_uInt16 DelCntntType;
132 namespace nsDelCntntType
133 {
134     const DelCntntType DELCNT_FTN = 0x01;
135     const DelCntntType DELCNT_FLY = 0x02;
136     const DelCntntType DELCNT_TOC = 0x04;
137     const DelCntntType DELCNT_BKM = 0x08;
138     const DelCntntType DELCNT_ALL = 0x0F;
139     const DelCntntType DELCNT_CHKNOCNTNT = 0x80;
140 }
141 
142 /// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
143 bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
144         SwPosition const & rStart, SwPosition const & rEnd,
145         DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
146 
147 // diese Klasse muss in ein Undo-Object vererbt werden, wenn dieses Inhalt
148 // fuers Redo/Undo ... speichert
149 class SwUndoSaveCntnt
150 {
151 protected:
152 
153 	SwHistory* pHistory;
154 
155 	// wird fuer das loeschen von Inhalt benoetigt. Fuer das ReDo werden
156 	// Inhalte in das UndoNodesArray verschoben. Diese Methoden fuegen
157 	// am Ende eines TextNodes ein Trenner fuer die Attribute. Damit werden
158 	// Attribute nicht expandiert.
159 	// MoveTo.. 	verschiebt aus dem NodesArray in das UndoNodesArray
160 	// MoveFrom..	verschiebt aus dem UndoNodesArray in das NodesArray
161 	void MoveToUndoNds( SwPaM& rPam,
162 						SwNodeIndex* pNodeIdx = 0, SwIndex* pCntIdx = 0,
163 						sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
164 	void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx, xub_StrLen nCntntIdx,
165 						  SwPosition& rInsPos,
166 						  sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
167 
168 	// diese beiden Methoden bewegen den SPoint vom Pam zurueck/vor. Damit
169 	// kann fuer ein Undo/Redo ein Bereich aufgespannt werden. (Der
170 	// SPoint liegt dann vor dem manipuliertem Bereich !!)
171 	// Das Flag gibt an, ob noch vorm SPoint Inhalt steht.
172 	sal_Bool MovePtBackward( SwPaM& rPam );
173 	void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd );
174 
175 	// vor dem Move ins UndoNodes-Array muss dafuer gesorgt werden, das
176 	// die Inhaltstragenden Attribute aus dem Nodes-Array entfernt werden.
177     void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
178                         DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
179 
180 public:
181 	SwUndoSaveCntnt();
182 	~SwUndoSaveCntnt();
183 };
184 
185 
186 // sicher eine vollstaendige Section im Nodes-Array
187 class SwUndoSaveSection : private SwUndoSaveCntnt
188 {
189 	SwNodeIndex *pMvStt;
190 	SwRedlineSaveDatas* pRedlSaveData;
191 	sal_uLong nMvLen;			// Index ins UndoNodes-Array
192 	sal_uLong nStartPos;
193 
194 protected:
GetMvSttIdx() const195 	SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
GetMvNodeCnt() const196 	sal_uLong GetMvNodeCnt() const { return nMvLen; }
197 
198 public:
199 	SwUndoSaveSection();
200 	~SwUndoSaveSection();
201 
202 	void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
203 	void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
204 	void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
205 	void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
206 
GetHistory() const207 	const SwHistory* GetHistory() const { return pHistory; }
GetHistory()208 		  SwHistory* GetHistory() 		{ return pHistory; }
209 };
210 
211 
212 // Diese Klasse speichert den Pam als sal_uInt16's und kann diese wieder zu
213 // einem PaM zusammensetzen
214 class SwUndRng
215 {
216 public:
217 	sal_uLong nSttNode, nEndNode;
218 	xub_StrLen nSttCntnt, nEndCntnt;
219 
220 	SwUndRng();
221 	SwUndRng( const SwPaM& );
222 
223 	void SetValues( const SwPaM& rPam );
224 	void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const;
225     SwPaM & AddUndoRedoPaM(
226         ::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
227 };
228 
229 
230 
231 class SwUndoInsLayFmt;
232 
233 // base class for insertion of Document, Glossaries and Copy
234 class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
235 {
236 	SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
237 	SvPtrarr* pFrmFmts;
238     ::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
239 	SwRedlineData* pRedlData;
240 	sal_Bool bSttWasTxtNd;
241 protected:
242 	sal_uLong nNdDiff;
243 	SwPosition *pPos; 					// Inhalt fuers Redo
244 	sal_uInt16 nSetPos;						// Start in der History-Liste
245 
246     SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
247 public:
248 	virtual ~SwUndoInserts();
249 
250     virtual void UndoImpl( ::sw::UndoRedoContext & );
251     virtual void RedoImpl( ::sw::UndoRedoContext & );
252     virtual void RepeatImpl( ::sw::RepeatContext & );
253 
254 	// setze den Destination-Bereich nach dem Einlesen.
255 	void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True,
256 						sal_Bool bSttWasTxtNd = sal_True );
257 };
258 
259 class SwUndoInsDoc : public SwUndoInserts
260 {
261 public:
262 	SwUndoInsDoc( const SwPaM& );
263 };
264 
265 class SwUndoCpyDoc : public SwUndoInserts
266 {
267 public:
268 	SwUndoCpyDoc( const SwPaM& );
269 };
270 
271 
272 
273 //--------------------------------------------------------------------
274 
275 class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
276 {
277 protected:
278 	SwFrmFmt* pFrmFmt;					// das gespeicherte FlyFormat
279 	sal_uLong nNdPgPos;
280 	xub_StrLen nCntPos;	 				// Seite/am Absatz/im Absatz
281 	sal_uInt16 nRndId;
282 	sal_Bool bDelFmt;						// loesche das gespeicherte Format
283 
284     void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
285 	void DelFly( SwDoc* );
286 
287     SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
288 
GetMvSttIdx() const289 	SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
GetMvNodeCnt() const290 	sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
291 
292 public:
293 	virtual ~SwUndoFlyBase();
294 
295 };
296 
297 class SwUndoInsLayFmt : public SwUndoFlyBase
298 {
299     sal_uLong mnCrsrSaveIndexPara;           // Cursor position
300     xub_StrLen mnCrsrSaveIndexPos;            // for undo
301 public:
302 	SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx );
303 
304     virtual ~SwUndoInsLayFmt();
305 
306     virtual void UndoImpl( ::sw::UndoRedoContext & );
307     virtual void RedoImpl( ::sw::UndoRedoContext & );
308     virtual void RepeatImpl( ::sw::RepeatContext & );
309 
310     String GetComment() const;
311 
312 };
313 
314 class SwUndoDelLayFmt : public SwUndoFlyBase
315 {
316 	sal_Bool bShowSelFrm;
317 public:
318 	SwUndoDelLayFmt( SwFrmFmt* pFormat );
319 
320     virtual void UndoImpl( ::sw::UndoRedoContext & );
321     virtual void RedoImpl( ::sw::UndoRedoContext & );
322 
323     void RedoForRollback();
324 
ChgShowSel(sal_Bool bNew)325 	void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; }
326 
327     virtual SwRewriter GetRewriter() const;
328 
329 };
330 
331 #endif
332