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