1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef SW_UNDOBJ_HXX
#define SW_UNDOBJ_HXX
#include <vector>
#include <boost/shared_ptr.hpp>
#include <svl/undo.hxx>
#include <SwRewriter.hxx>
#include <swundo.hxx>
class SwHistory;
class SwIndex;
class SwPaM;
struct SwPosition;
class SwDoc;
class SwTxtFmtColl;
class SwFrmFmt;
class SwNodeIndex;
class SwNodeRange;
class SwRedlineData;
class SwRedlineSaveDatas;
namespace sw {
class UndoRedoContext;
class RepeatContext;
}
class SwUndo
: public SfxUndoAction
{
SwUndoId const m_nId;
sal_uInt16 nOrigRedlineMode;
protected:
bool bCacheComment;
mutable String * pComment;
void RemoveIdxFromSection( SwDoc&, sal_uLong nSttIdx, sal_uLong* pEndIdx = 0 );
void RemoveIdxFromRange( SwPaM& rPam, sal_Bool bMoveNext );
void RemoveIdxRel( sal_uLong, const SwPosition& );
static sal_Bool CanRedlineGroup( SwRedlineSaveDatas& rCurr,
const SwRedlineSaveDatas& rCheck,
sal_Bool bCurrIsEnd );
/**
Returns the rewriter for this object.
@return the rewriter for this object
*/
virtual SwRewriter GetRewriter() const;
// return type is sal_uInt16 because this overrides SfxUndoAction::GetId()
virtual sal_uInt16 GetId() const { return static_cast<sal_uInt16>(m_nId); }
// the 4 methods that derived classes have to override
// base implementation does nothing
virtual void RepeatImpl( ::sw::RepeatContext & );
virtual bool CanRepeatImpl( ::sw::RepeatContext & ) const;
public: // should not be public, but ran into trouble in untbl.cxx
virtual void UndoImpl( ::sw::UndoRedoContext & ) = 0;
virtual void RedoImpl( ::sw::UndoRedoContext & ) = 0;
private:
// SfxUndoAction
virtual void Undo();
virtual void Redo();
virtual void UndoWithContext(SfxUndoContext &);
virtual void RedoWithContext(SfxUndoContext &);
virtual void Repeat(SfxRepeatTarget &);
virtual sal_Bool CanRepeat(SfxRepeatTarget &) const;
public:
SwUndo(SwUndoId const nId);
virtual ~SwUndo();
/**
Returns textual comment for this undo object.
The textual comment is created from the resource string
corresponding to this object's ID. The rewriter of this object
is applied to the resource string to get the final comment.
@return textual comment for this undo object
*/
virtual String GetComment() const;
// UndoObject remembers which mode was turned on.
// In Undo/Redo/Repeat this remembered mode is switched on.
sal_uInt16 GetRedlineMode() const { return nOrigRedlineMode; }
void SetRedlineMode( sal_uInt16 eMode ) { nOrigRedlineMode = eMode; }
bool IsDelBox() const;
// Save and set Redline data.
static sal_Bool FillSaveData( const SwPaM& rRange, SwRedlineSaveDatas& rSData,
sal_Bool bDelRange = sal_True, sal_Bool bCopyNext = sal_True );
static sal_Bool FillSaveDataForFmt( const SwPaM& , SwRedlineSaveDatas& );
static void SetSaveData( SwDoc& rDoc, const SwRedlineSaveDatas& rSData );
static sal_Bool HasHiddenRedlines( const SwRedlineSaveDatas& rSData );
};
typedef sal_uInt16 DelCntntType;
namespace nsDelCntntType
{
const DelCntntType DELCNT_FTN = 0x01;
const DelCntntType DELCNT_FLY = 0x02;
const DelCntntType DELCNT_TOC = 0x04;
const DelCntntType DELCNT_BKM = 0x08;
const DelCntntType DELCNT_ALL = 0x0F;
const DelCntntType DELCNT_CHKNOCNTNT = 0x80;
}
/// will DelCntntIndex destroy a frame anchored at character at rAnchorPos?
bool IsDestroyFrameAnchoredAtChar(SwPosition const & rAnchorPos,
SwPosition const & rStart, SwPosition const & rEnd,
DelCntntType const nDelCntntType = nsDelCntntType::DELCNT_ALL);
// This class has to be inherited into an Undo-object if it saves content
// for Redo/Undo...
class SwUndoSaveCntnt
{
protected:
SwHistory* pHistory;
// Needed for deletion of content. For Redo content is moved into the
// UndoNodesArray. These methods insert a separator for the attributes
// at the end of a TextNode. So the attributes do not get expanded.
// MoveTo: moves from the NodesArray into the UndoNodesArray.
// MoveFrom: moves from the UndoNodesArray into the NodesArray.
void MoveToUndoNds( SwPaM& rPam,
SwNodeIndex* pNodeIdx = 0, SwIndex* pCntIdx = 0,
sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
void MoveFromUndoNds( SwDoc& rDoc, sal_uLong nNodeIdx, xub_StrLen nCntntIdx,
SwPosition& rInsPos,
sal_uLong* pEndNdIdx = 0, xub_StrLen * pEndCntIdx = 0 );
// These two methods move the SPoint back/forth from PaM. With it
// a range can be spanned for Undo/Redo. (In this case the SPoint
// is before the manipulated range!!)
// The flag indicates if there is content before the SPoint.
sal_Bool MovePtBackward( SwPaM& rPam );
void MovePtForward( SwPaM& rPam, sal_Bool bMvBkwrd );
// Before moving stuff into UndoNodes-Array care has to be taken that
// the content-bearing attributes are removed from the nodes-array.
void DelCntntIndex( const SwPosition& pMark, const SwPosition& pPoint,
DelCntntType nDelCntntType = nsDelCntntType::DELCNT_ALL );
public:
SwUndoSaveCntnt();
~SwUndoSaveCntnt();
};
// Save a complete section in nodes-array.
class SwUndoSaveSection : private SwUndoSaveCntnt
{
SwNodeIndex *pMvStt;
SwRedlineSaveDatas* pRedlSaveData;
sal_uLong nMvLen; // Index into UndoNodes-Array.
sal_uLong nStartPos;
protected:
SwNodeIndex* GetMvSttIdx() const { return pMvStt; }
sal_uLong GetMvNodeCnt() const { return nMvLen; }
public:
SwUndoSaveSection();
~SwUndoSaveSection();
void SaveSection( SwDoc* pDoc, const SwNodeIndex& rSttIdx );
void SaveSection( SwDoc* pDoc, const SwNodeRange& rRange );
void RestoreSection( SwDoc* pDoc, SwNodeIndex* pIdx, sal_uInt16 nSectType );
void RestoreSection( SwDoc* pDoc, const SwNodeIndex& rInsPos );
const SwHistory* GetHistory() const { return pHistory; }
SwHistory* GetHistory() { return pHistory; }
};
// This class saves the PaM as sal_uInt16's and is able to restore it
// into a PaM.
class SwUndRng
{
public:
sal_uLong nSttNode, nEndNode;
xub_StrLen nSttCntnt, nEndCntnt;
SwUndRng();
SwUndRng( const SwPaM& );
void SetValues( const SwPaM& rPam );
void SetPaM( SwPaM&, sal_Bool bCorrToCntnt = sal_False ) const;
SwPaM & AddUndoRedoPaM(
::sw::UndoRedoContext &, bool const bCorrToCntnt = false) const;
};
class SwUndoInsLayFmt;
// base class for insertion of Document, Glossaries and Copy
class SwUndoInserts : public SwUndo, public SwUndRng, private SwUndoSaveCntnt
{
SwTxtFmtColl *pTxtFmtColl, *pLastNdColl;
SvPtrarr* pFrmFmts;
::std::vector< ::boost::shared_ptr<SwUndoInsLayFmt> > m_FlyUndos;
SwRedlineData* pRedlData;
sal_Bool bSttWasTxtNd;
protected:
sal_uLong nNdDiff;
SwPosition *pPos; // Content for Redo.
sal_uInt16 nSetPos; // Start in the history list.
SwUndoInserts( SwUndoId nUndoId, const SwPaM& );
public:
virtual ~SwUndoInserts();
virtual void UndoImpl( ::sw::UndoRedoContext & );
virtual void RedoImpl( ::sw::UndoRedoContext & );
virtual void RepeatImpl( ::sw::RepeatContext & );
// Set destination range after reading.
void SetInsertRange( const SwPaM&, sal_Bool bScanFlys = sal_True,
sal_Bool bSttWasTxtNd = sal_True );
};
class SwUndoInsDoc : public SwUndoInserts
{
public:
SwUndoInsDoc( const SwPaM& );
};
class SwUndoCpyDoc : public SwUndoInserts
{
public:
SwUndoCpyDoc( const SwPaM& );
};
//--------------------------------------------------------------------
class SwUndoFlyBase : public SwUndo, private SwUndoSaveSection
{
protected:
SwFrmFmt* pFrmFmt; // The saved FlyFormat.
sal_uLong nNdPgPos;
xub_StrLen nCntPos; // Page at/in paragraph.
sal_uInt16 nRndId;
sal_Bool bDelFmt; // Delete saved format.
void InsFly(::sw::UndoRedoContext & rContext, bool bShowSel = true);
void DelFly( SwDoc* );
SwUndoFlyBase( SwFrmFmt* pFormat, SwUndoId nUndoId );
SwNodeIndex* GetMvSttIdx() const { return SwUndoSaveSection::GetMvSttIdx(); }
sal_uLong GetMvNodeCnt() const { return SwUndoSaveSection::GetMvNodeCnt(); }
public:
virtual ~SwUndoFlyBase();
};
class SwUndoInsLayFmt : public SwUndoFlyBase
{
sal_uLong mnCrsrSaveIndexPara; // Cursor position
xub_StrLen mnCrsrSaveIndexPos; // for undo
public:
SwUndoInsLayFmt( SwFrmFmt* pFormat, sal_uLong nNodeIdx, xub_StrLen nCntIdx );
virtual ~SwUndoInsLayFmt();
virtual void UndoImpl( ::sw::UndoRedoContext & );
virtual void RedoImpl( ::sw::UndoRedoContext & );
virtual void RepeatImpl( ::sw::RepeatContext & );
String GetComment() const;
};
class SwUndoDelLayFmt : public SwUndoFlyBase
{
sal_Bool bShowSelFrm;
public:
SwUndoDelLayFmt( SwFrmFmt* pFormat );
virtual void UndoImpl( ::sw::UndoRedoContext & );
virtual void RedoImpl( ::sw::UndoRedoContext & );
void RedoForRollback();
void ChgShowSel( sal_Bool bNew ) { bShowSelFrm = bNew; }
virtual SwRewriter GetRewriter() const;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|