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 _ROLBCK_HXX 28 #define _ROLBCK_HXX 29 30 #include <tools/solar.h> 31 #ifndef _SVSTDARR_HXX 32 #define _SVSTDARR_USHORTS 33 #define _SVSTDARR_USHORTSSORT 34 #include <svl/svstdarr.hxx> 35 #endif 36 #include <svl/itemset.hxx> 37 38 //Nur die History anziehen, um das docnew.cxx gegen die CLOOK's zu behaupten. 39 40 namespace sfx2 { 41 class MetadatableUndo; 42 } 43 44 class SwDoc; 45 class SwFmt; 46 class SwFmtColl; 47 class SwHistoryHint; 48 class SwTxtAttr; 49 class SfxPoolItem; 50 class SwTxtNode; 51 class SwUndoSaveSection; 52 class SwTxtFtn; 53 class SwTxtFlyCnt; 54 class SwUndoDelLayFmt; 55 class SwFlyFrmFmt; 56 class SwFmtFld; 57 class SwTxtFld; 58 class SwFieldType; 59 class SwTxtTOXMark; 60 class SwTxtRefMark; 61 class SwFrmFmt; 62 class SwpHints; 63 class SwFmtChain; 64 class SwNode; 65 class SwCharFmt; 66 67 #ifndef ROLBCK_HISTORY_ONLY 68 69 #include <tox.hxx> 70 71 #include <SwNumberTreeTypes.hxx> 72 // --> OD 2007-10-17 #i81002# 73 #include <IDocumentMarkAccess.hxx> 74 // <-- 75 76 #include <memory> 77 78 79 enum HISTORY_HINT { 80 HSTRY_SETFMTHNT, 81 HSTRY_RESETFMTHNT, 82 HSTRY_SETTXTHNT, 83 HSTRY_SETTXTFLDHNT, 84 HSTRY_SETREFMARKHNT, 85 HSTRY_SETTOXMARKHNT, 86 HSTRY_RESETTXTHNT, 87 HSTRY_SETFTNHNT, 88 HSTRY_CHGFMTCOLL, 89 HSTRY_FLYCNT, 90 HSTRY_BOOKMARK, 91 HSTRY_SETATTRSET, 92 HSTRY_RESETATTRSET, 93 HSTRY_CHGFLYANCHOR, 94 HSTRY_CHGFLYCHAIN, 95 HSTRY_CHGCHARFMT, // #i27615# 96 HSTRY_END 97 }; 98 99 class SwHistoryHint 100 { 101 const HISTORY_HINT m_eWhichId; 102 103 public: 104 SwHistoryHint( HISTORY_HINT eWhich ) : m_eWhichId( eWhich ) {} 105 virtual ~SwHistoryHint() {} 106 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ) = 0; 107 HISTORY_HINT Which() const { return m_eWhichId; } 108 virtual String GetDescription() const; 109 }; 110 111 class SwHistorySetFmt : public SwHistoryHint 112 { 113 ::std::auto_ptr<SfxPoolItem> m_pAttr; 114 const sal_uLong m_nNodeIndex; 115 116 public: 117 SwHistorySetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNode ); 118 virtual ~SwHistorySetFmt(); 119 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 120 virtual String GetDescription() const; 121 122 }; 123 124 class SwHistoryResetFmt : public SwHistoryHint 125 { 126 const sal_uLong m_nNodeIndex; 127 const sal_uInt16 m_nWhich; 128 129 public: 130 // --> OD 2008-02-27 #refactorlists# - removed <rDoc> 131 SwHistoryResetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNodeIdx ); 132 // <-- 133 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 134 135 }; 136 137 class SwHistorySetTxt : public SwHistoryHint 138 { 139 ::std::auto_ptr<SfxPoolItem> m_pAttr; 140 const sal_uLong m_nNodeIndex; 141 const xub_StrLen m_nStart; 142 const xub_StrLen m_nEnd; 143 144 public: 145 SwHistorySetTxt( SwTxtAttr* pTxtHt, sal_uLong nNode ); 146 virtual ~SwHistorySetTxt(); 147 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 148 149 }; 150 151 class SwHistorySetTxtFld : public SwHistoryHint 152 { 153 //!! beware of the order for the declation of the auto_ptrs. 154 //!! If they get destroyed in the wrong order sw may crash (namely mail-merge as well) 155 ::std::auto_ptr<SwFieldType> m_pFldType; 156 const ::std::auto_ptr<SwFmtFld> m_pFld; 157 158 sal_uLong m_nNodeIndex; 159 xub_StrLen m_nPos; 160 sal_uInt16 m_nFldWhich; 161 162 public: 163 SwHistorySetTxtFld( SwTxtFld* pTxtFld, sal_uLong nNode ); 164 virtual ~SwHistorySetTxtFld(); 165 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 166 167 virtual String GetDescription() const; 168 169 }; 170 171 class SwHistorySetRefMark : public SwHistoryHint 172 { 173 const String m_RefName; 174 const sal_uLong m_nNodeIndex; 175 const xub_StrLen m_nStart; 176 const xub_StrLen m_nEnd; 177 178 public: 179 SwHistorySetRefMark( SwTxtRefMark* pTxtHt, sal_uLong nNode ); 180 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 181 182 }; 183 184 class SwHistorySetTOXMark : public SwHistoryHint 185 { 186 SwTOXMark m_TOXMark; 187 const String m_TOXName; 188 const TOXTypes m_eTOXTypes; 189 const sal_uLong m_nNodeIndex; 190 const xub_StrLen m_nStart; 191 const xub_StrLen m_nEnd; 192 193 public: 194 SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, sal_uLong nNode ); 195 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 196 int IsEqual( const SwTOXMark& rCmp ) const; 197 198 }; 199 200 class SwHistoryResetTxt : public SwHistoryHint 201 { 202 const sal_uLong m_nNodeIndex; 203 const xub_StrLen m_nStart; 204 const xub_StrLen m_nEnd; 205 const sal_uInt16 m_nAttr; 206 207 public: 208 SwHistoryResetTxt( sal_uInt16 nWhich, xub_StrLen nStt, xub_StrLen nEnd, 209 sal_uLong nNode ); 210 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 211 212 sal_uInt16 GetWhich() const { return m_nAttr; } 213 sal_uLong GetNode() const { return m_nNodeIndex; } 214 xub_StrLen GetCntnt() const { return m_nStart; } 215 216 }; 217 218 class SwHistorySetFootnote : public SwHistoryHint 219 { 220 const ::std::auto_ptr<SwUndoSaveSection> m_pUndo; 221 const String m_FootnoteNumber; 222 sal_uLong m_nNodeIndex; 223 const xub_StrLen m_nStart; 224 const bool m_bEndNote; 225 226 public: 227 SwHistorySetFootnote( SwTxtFtn* pTxtFtn, sal_uLong nNode ); 228 SwHistorySetFootnote( const SwTxtFtn& ); 229 virtual ~SwHistorySetFootnote(); 230 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 231 232 virtual String GetDescription() const; 233 234 }; 235 236 class SwHistoryChangeFmtColl : public SwHistoryHint 237 { 238 SwFmtColl * const m_pColl; 239 const sal_uLong m_nNodeIndex; 240 const sal_uInt8 m_nNodeType; 241 242 public: 243 SwHistoryChangeFmtColl( SwFmtColl* pColl, sal_uLong nNode, sal_uInt8 nNodeWhich ); 244 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 245 246 }; 247 248 class SwHistoryTxtFlyCnt : public SwHistoryHint 249 { 250 ::std::auto_ptr<SwUndoDelLayFmt> m_pUndo; 251 252 public: 253 SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt ); 254 virtual ~SwHistoryTxtFlyCnt(); 255 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 256 SwUndoDelLayFmt* GetUDelLFmt() { return m_pUndo.get(); } 257 258 }; 259 260 class SwHistoryBookmark : public SwHistoryHint 261 { 262 public: 263 SwHistoryBookmark(const ::sw::mark::IMark& rBkmk, 264 bool bSavePos, bool bSaveOtherPos); 265 virtual void SetInDoc(SwDoc * pDoc, bool); 266 267 bool IsEqualBookmark(const ::sw::mark::IMark& rBkmk); 268 const ::rtl::OUString& GetName() const; 269 270 271 private: 272 const ::rtl::OUString m_aName; 273 ::rtl::OUString m_aShortName; 274 KeyCode m_aKeycode; 275 const sal_uLong m_nNode; 276 const sal_uLong m_nOtherNode; 277 const xub_StrLen m_nCntnt; 278 const xub_StrLen m_nOtherCntnt; 279 const bool m_bSavePos; 280 const bool m_bSaveOtherPos; 281 const bool m_bHadOtherPos; 282 const IDocumentMarkAccess::MarkType m_eBkmkType; 283 ::boost::shared_ptr< ::sfx2::MetadatableUndo > m_pMetadataUndo; 284 }; 285 286 class SwHistorySetAttrSet : public SwHistoryHint 287 { 288 SfxItemSet m_OldSet; 289 SvUShorts m_ResetArray; 290 const sal_uLong m_nNodeIndex; 291 292 public: 293 SwHistorySetAttrSet( const SfxItemSet& rSet, sal_uLong nNode, 294 const SvUShortsSort& rSetArr ); 295 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 296 297 }; 298 299 300 class SwHistoryResetAttrSet : public SwHistoryHint 301 { 302 const sal_uLong m_nNodeIndex; 303 const xub_StrLen m_nStart; 304 const xub_StrLen m_nEnd; 305 SvUShorts m_Array; 306 307 public: 308 SwHistoryResetAttrSet( const SfxItemSet& rSet, sal_uLong nNode, 309 xub_StrLen nStt = STRING_MAXLEN, 310 xub_StrLen nEnd = STRING_MAXLEN ); 311 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 312 313 const SvUShorts& GetArr() const { return m_Array; } 314 sal_uLong GetNode() const { return m_nNodeIndex; } 315 xub_StrLen GetCntnt() const { return m_nStart; } 316 317 }; 318 319 class SwHistoryChangeFlyAnchor : public SwHistoryHint 320 { 321 SwFrmFmt & m_rFmt; 322 const sal_uLong m_nOldNodeIndex; 323 const xub_StrLen m_nOldContentIndex; 324 325 public: 326 SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt ); 327 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 328 }; 329 330 class SwHistoryChangeFlyChain : public SwHistoryHint 331 { 332 SwFlyFrmFmt * const m_pPrevFmt; 333 SwFlyFrmFmt * const m_pNextFmt; 334 SwFlyFrmFmt * const m_pFlyFmt; 335 336 public: 337 SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt, const SwFmtChain& rAttr ); 338 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 339 }; 340 341 // #i27615# 342 class SwHistoryChangeCharFmt : public SwHistoryHint 343 { 344 const SfxItemSet m_OldSet; 345 const String m_Fmt; 346 347 public: 348 SwHistoryChangeCharFmt( const SfxItemSet& rSet, const String & sFmt); 349 virtual void SetInDoc( SwDoc* pDoc, bool bTmpSet ); 350 351 }; 352 353 354 #endif 355 356 typedef SwHistoryHint* SwHistoryHintPtr; 357 SV_DECL_PTRARR_DEL( SwpHstry, SwHistoryHintPtr, 0, 2 ) 358 359 class SwHistory 360 { 361 friend class SwDoc; // actually only SwDoc::DelUndoObj may access 362 friend class SwUndoWriter; // for Undo/Redo Writer 363 friend class SwRegHistory; // for inserting History attributes 364 365 SwpHstry m_SwpHstry; 366 sal_uInt16 m_nEndDiff; 367 368 public: 369 SwHistory( sal_uInt16 nInitSz = 0, sal_uInt16 nGrowSz = 2 ); 370 ~SwHistory(); 371 372 // delete History from nStart to array end 373 void Delete( sal_uInt16 nStart = 0 ); 374 // call and delete all objects between nStart and array end 375 bool Rollback( SwDoc* pDoc, sal_uInt16 nStart = 0 ); 376 // call all objects between nStart and TmpEnd; store nStart as TmpEnd 377 bool TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool ToFirst = true ); 378 379 // --> OD 2008-02-27 #refactorlists# - removed <rDoc> 380 void Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue, 381 sal_uLong nNodeIdx ); 382 // <-- 383 void Add( SwTxtAttr* pTxtHt, sal_uLong nNodeIdx, bool bNewAttr = true ); 384 void Add( SwFmtColl*, sal_uLong nNodeIdx, sal_uInt8 nWhichNd ); 385 void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos ); 386 void Add( SwFrmFmt& rFmt ); 387 void Add( SwFlyFrmFmt&, sal_uInt16& rSetPos ); 388 void Add( const SwTxtFtn& ); 389 void Add( const SfxItemSet & rSet, const SwCharFmt & rCharFmt); // #i27615# 390 391 sal_uInt16 Count() const { return m_SwpHstry.Count(); } 392 sal_uInt16 GetTmpEnd() const { return m_SwpHstry.Count() - m_nEndDiff; } 393 sal_uInt16 SetTmpEnd( sal_uInt16 nTmpEnd ); // return previous value 394 SwHistoryHint * operator[]( sal_uInt16 nPos ) { return m_SwpHstry[nPos]; } 395 SwHistoryHint const* operator[]( sal_uInt16 nPos ) const 396 { return m_SwpHstry[nPos]; } 397 398 // for SwUndoDelete::Undo/Redo 399 void Move( sal_uInt16 nPos, SwHistory *pIns, 400 sal_uInt16 nStart = 0, sal_uInt16 nEnd = USHRT_MAX ) 401 { 402 m_SwpHstry.Insert( &pIns->m_SwpHstry, nPos, nStart, nEnd ); 403 pIns->m_SwpHstry.Remove( nStart, (nEnd == USHRT_MAX) 404 ? pIns->Count() - nStart 405 : nEnd ); 406 } 407 408 // helper methods for recording attribute in History 409 // used by Undo classes (Delete/Overwrite/Inserts) 410 void CopyAttr( SwpHints* pHts, sal_uLong nNodeIdx, xub_StrLen nStart, 411 xub_StrLen nEnd, bool bFields ); 412 // --> OD 2008-02-27 #refactorlists# - removed <rDoc> 413 void CopyFmtAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx ); 414 // <-- 415 }; 416 417 #ifndef ROLBCK_HISTORY_ONLY 418 419 class SwRegHistory : public SwClient 420 { 421 private: 422 SvUShortsSort m_WhichIdSet; 423 SwHistory * const m_pHistory; 424 sal_uLong m_nNodeIndex; 425 426 void _MakeSetWhichIds(); 427 428 protected: 429 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ); 430 431 public: 432 // --> OD 2008-02-27 #refactorlists# - removed <rDoc> 433 SwRegHistory( SwHistory* pHst ); 434 // <-- 435 SwRegHistory( const SwNode& rNd, SwHistory* pHst ); 436 SwRegHistory( SwModify* pRegIn, const SwNode& rNd, SwHistory* pHst ); 437 438 /// @return true iff at least 1 item was inserted 439 bool InsertItems( const SfxItemSet& rSet, 440 xub_StrLen const nStart, xub_StrLen const nEnd, 441 SetAttrMode const nFlags ); 442 443 void AddHint( SwTxtAttr* pHt, const bool bNew = false ); 444 445 void RegisterInModify( SwModify* pRegIn, const SwNode& rNd ); 446 void ChangeNodeIndex( sal_uLong nNew ) { m_nNodeIndex = nNew; } 447 }; 448 449 #endif 450 451 452 #endif // _ROLBCK_HXX 453 454