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