xref: /aoo41x/main/sw/source/core/inc/UndoInsert.hxx (revision cdf0e10c)
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_UNDO_INSERT_HXX
29 #define SW_UNDO_INSERT_HXX
30 
31 #include <undobj.hxx>
32 
33 #include <tools/mempool.hxx>
34 
35 #include <swtypes.hxx>
36 #include <IDocumentContentOperations.hxx>
37 
38 
39 class Graphic;
40 class SwGrfNode;
41 class SwUndoDelete;
42 class SwUndoFmtAttr;
43 
44 
45 class SwUndoInsert: public SwUndo, private SwUndoSaveCntnt
46 {
47     SwPosition *pPos;                   // Inhalt fuers Redo
48     String *pTxt, *pUndoTxt;
49     SwRedlineData* pRedlData;
50     sal_uLong nNode;
51     xub_StrLen nCntnt, nLen;
52     sal_Bool bIsWordDelim : 1;
53     sal_Bool bIsAppend : 1;
54 
55     const IDocumentContentOperations::InsertFlags m_nInsertFlags;
56 
57     friend class SwDoc;     // eigentlich nur SwDoc::Insert( String )
58     sal_Bool CanGrouping( sal_Unicode cIns );
59     sal_Bool CanGrouping( const SwPosition& rPos );
60 
61     SwDoc * pDoc;
62 
63     void Init(const SwNodeIndex & rNode);
64     String * GetTxtFromDoc() const;
65 
66 public:
67     SwUndoInsert( const SwNodeIndex& rNode, xub_StrLen nCntnt, xub_StrLen nLen,
68                   const IDocumentContentOperations::InsertFlags nInsertFlags,
69                   sal_Bool bWDelim = sal_True );
70     SwUndoInsert( const SwNodeIndex& rNode );
71     virtual ~SwUndoInsert();
72 
73     virtual void UndoImpl( ::sw::UndoRedoContext & );
74     virtual void RedoImpl( ::sw::UndoRedoContext & );
75     virtual void RepeatImpl( ::sw::RepeatContext & );
76 
77     // #111827#
78     /**
79        Returns rewriter for this undo object.
80 
81        The returned rewriter has the following rule:
82 
83            $1 -> '<inserted text>'
84 
85        <inserted text> is shortened to a length of nUndoStringLength.
86 
87        @return rewriter for this undo object
88      */
89     virtual SwRewriter GetRewriter() const;
90 
91 
92     DECL_FIXEDMEMPOOL_NEWDEL(SwUndoInsert)
93 };
94 
95 
96 //--------------------------------------------------------------------
97 
98 SwRewriter SW_DLLPRIVATE
99 MakeUndoReplaceRewriter(sal_uLong const ocurrences,
100     ::rtl::OUString const& sOld, ::rtl::OUString const& sNew);
101 
102 class SwUndoReplace
103     : public SwUndo
104 {
105 public:
106     SwUndoReplace(SwPaM const& rPam,
107             ::rtl::OUString const& rInsert, bool const bRegExp);
108 
109     virtual ~SwUndoReplace();
110 
111     virtual void UndoImpl( ::sw::UndoRedoContext & );
112     virtual void RedoImpl( ::sw::UndoRedoContext & );
113 
114     // #111827#
115     /**
116        Returns the rewriter of this undo object.
117 
118        If this undo object represents several replacements the
119        rewriter contains the following rules:
120 
121            $1 -> <number of replacements>
122            $2 -> occurrences of
123            $3 -> <replaced text>
124 
125        If this undo object represents one replacement the rewriter
126        contains these rules:
127 
128            $1 -> <replaced text>
129            $2 -> "->"                   (STR_YIELDS)
130            $3 -> <replacing text>
131 
132        @return the rewriter of this undo object
133     */
134     virtual SwRewriter GetRewriter() const;
135 
136     void SetEnd( const SwPaM& rPam );
137 
138 private:
139     class Impl;
140     ::std::auto_ptr<Impl> m_pImpl;
141 };
142 
143 
144 //--------------------------------------------------------------------
145 
146 class SwUndoReRead : public SwUndo
147 {
148     Graphic *pGrf;
149     String *pNm, *pFltr;
150     sal_uLong nPos;
151     sal_uInt16 nMirr;
152 
153     void SaveGraphicData( const SwGrfNode& );
154     void SetAndSave( ::sw::UndoRedoContext & );
155 
156 public:
157     SwUndoReRead( const SwPaM& rPam, const SwGrfNode& pGrfNd );
158 
159     virtual ~SwUndoReRead();
160 
161     virtual void UndoImpl( ::sw::UndoRedoContext & );
162     virtual void RedoImpl( ::sw::UndoRedoContext & );
163 };
164 
165 //--------------------------------------------------------------------
166 
167 class SwUndoInsertLabel : public SwUndo
168 {
169     union {
170         struct {
171             // fuer NoTxtFrms
172             SwUndoInsLayFmt* pUndoFly;
173             SwUndoFmtAttr* pUndoAttr;
174         } OBJECT;
175         struct {
176             // fuer Tabelle/TextRahmen
177             SwUndoDelete* pUndoInsNd;
178             sal_uLong nNode;
179         } NODE;
180     };
181 
182     String sText;
183     // --> PB 2005-01-06 #i39983# the separator is drawn with a character style
184     String sSeparator;
185     // <--
186     String sNumberSeparator;
187     String sCharacterStyle;
188     // OD 2004-04-15 #i26791# - re-store of drawing object position no longer needed
189     sal_uInt16 nFldId;
190     SwLabelType eType;
191     sal_uInt8 nLayerId;              // fuer Zeichen-Objekte
192     sal_Bool bBefore        :1;
193     sal_Bool bUndoKeep      :1;
194     sal_Bool bCpyBrd        :1;
195 
196 public:
197     SwUndoInsertLabel( const SwLabelType eTyp, const String &rText,
198     // --> PB 2005-01-06 #i39983# the separator is drawn with a character style
199                         const String& rSeparator,
200     // <--
201                         const String& rNumberSeparator, //#i61007# order of captions
202                         const sal_Bool bBefore, const sal_uInt16 nId,
203                         const String& rCharacterStyle,
204                         const sal_Bool bCpyBrd );
205     virtual ~SwUndoInsertLabel();
206 
207     virtual void UndoImpl( ::sw::UndoRedoContext & );
208     virtual void RedoImpl( ::sw::UndoRedoContext & );
209     virtual void RepeatImpl( ::sw::RepeatContext & );
210 
211     // #111827#
212     /**
213        Returns the rewriter of this undo object.
214 
215        The rewriter contains this rule:
216 
217            $1 -> '<text of inserted label>'
218 
219        <text of inserted label> is shortened to nUndoStringLength
220        characters.
221 
222        @return the rewriter of this undo object
223      */
224     virtual SwRewriter GetRewriter() const;
225 
226     void SetNodePos( sal_uLong nNd )
227         { if( LTYPE_OBJECT != eType ) NODE.nNode = nNd; }
228 
229     void SetUndoKeep()  { bUndoKeep = sal_True; }
230     void SetFlys( SwFrmFmt& rOldFly, SfxItemSet& rChgSet, SwFrmFmt& rNewFly );
231     void SetDrawObj( sal_uInt8 nLayerId );
232 };
233 
234 #endif // SW_UNDO_INSERT_HXX
235 
236