xref: /aoo41x/main/sw/source/core/undo/rolbck.cxx (revision dec99bbd)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rolbck.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/resid.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svl/itemiter.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <editeng/brkitem.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <hints.hxx>
36cdf0e10cSrcweir #include <hintids.hxx>
37cdf0e10cSrcweir #include <fmtftn.hxx>
38cdf0e10cSrcweir #include <fchrfmt.hxx>
39cdf0e10cSrcweir #include <fmtflcnt.hxx>
40cdf0e10cSrcweir #include <fmtrfmrk.hxx>
41cdf0e10cSrcweir #include <fmtfld.hxx>
42cdf0e10cSrcweir #include <fmtpdsc.hxx>
43cdf0e10cSrcweir #include <txtfld.hxx>
44cdf0e10cSrcweir #include <txtrfmrk.hxx>
45cdf0e10cSrcweir #include <txttxmrk.hxx>
46cdf0e10cSrcweir #include <txtftn.hxx>
47cdf0e10cSrcweir #include <txtflcnt.hxx>
48cdf0e10cSrcweir #include <fmtanchr.hxx>
49cdf0e10cSrcweir #include <fmtcnct.hxx>
50cdf0e10cSrcweir #include <frmfmt.hxx>
51cdf0e10cSrcweir #include <ftnidx.hxx>
52cdf0e10cSrcweir #include <doc.hxx>              // SwDoc.GetNodes()
53cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
54cdf0e10cSrcweir #include <docary.hxx>
55cdf0e10cSrcweir #include <ndtxt.hxx>			// SwTxtNode
56cdf0e10cSrcweir #include <paratr.hxx>			//
57cdf0e10cSrcweir #include <cellatr.hxx>			//
58cdf0e10cSrcweir #include <fldbas.hxx>			// fuer Felder
59cdf0e10cSrcweir #include <pam.hxx>				// fuer SwPaM
60cdf0e10cSrcweir #include <swtable.hxx>
61cdf0e10cSrcweir #include <ndgrf.hxx>			// SwGrfNode
62cdf0e10cSrcweir #include <UndoCore.hxx>
63cdf0e10cSrcweir #include <IMark.hxx> 			// fuer SwBookmark
64cdf0e10cSrcweir #include <charfmt.hxx> // #i27615#
65cdf0e10cSrcweir #include <comcore.hrc>
66cdf0e10cSrcweir #include <undo.hrc>
67cdf0e10cSrcweir #include <bookmrk.hxx>
68cdf0e10cSrcweir 
SV_IMPL_PTRARR(SwpHstry,SwHistoryHintPtr)69cdf0e10cSrcweir SV_IMPL_PTRARR( SwpHstry, SwHistoryHintPtr)
70cdf0e10cSrcweir 
71cdf0e10cSrcweir String SwHistoryHint::GetDescription() const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     return String();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
SwHistorySetFmt(const SfxPoolItem * pFmtHt,sal_uLong nNd)77cdf0e10cSrcweir SwHistorySetFmt::SwHistorySetFmt( const SfxPoolItem* pFmtHt, sal_uLong nNd )
78cdf0e10cSrcweir     :  SwHistoryHint( HSTRY_SETFMTHNT )
79cdf0e10cSrcweir     ,  m_pAttr( pFmtHt->Clone() )
80cdf0e10cSrcweir     ,  m_nNodeIndex( nNd )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     switch ( m_pAttr->Which() )
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         case RES_PAGEDESC:
85cdf0e10cSrcweir             static_cast<SwFmtPageDesc&>(*m_pAttr).ChgDefinedIn( 0 );
86cdf0e10cSrcweir             break;
87cdf0e10cSrcweir         case RES_PARATR_DROP:
88cdf0e10cSrcweir             static_cast<SwFmtDrop&>(*m_pAttr).ChgDefinedIn( 0 );
89cdf0e10cSrcweir             break;
90cdf0e10cSrcweir         case RES_BOXATR_FORMULA:
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir 			//JP 30.07.98: Bug 54295 - Formeln immer im Klartext speichern
93cdf0e10cSrcweir             SwTblBoxFormula& rNew = static_cast<SwTblBoxFormula&>(*m_pAttr);
94cdf0e10cSrcweir             if ( rNew.IsIntrnlName() )
95cdf0e10cSrcweir             {
96cdf0e10cSrcweir                 const SwTblBoxFormula& rOld =
97cdf0e10cSrcweir                     *static_cast<const SwTblBoxFormula*>(pFmtHt);
98cdf0e10cSrcweir                 const SwNode* pNd = rOld.GetNodeOfFormula();
99cdf0e10cSrcweir                 if ( pNd )
100cdf0e10cSrcweir                 {
101cdf0e10cSrcweir                     const SwTableNode* pTableNode = pNd->FindTableNode();
102cdf0e10cSrcweir                     if (pTableNode)
103cdf0e10cSrcweir                     {
104cdf0e10cSrcweir                         SwTableFmlUpdate aMsgHnt( &pTableNode->GetTable() );
105cdf0e10cSrcweir                         aMsgHnt.eFlags = TBL_BOXNAME;
106cdf0e10cSrcweir                         rNew.ChgDefinedIn( rOld.GetDefinedIn() );
107cdf0e10cSrcweir                         rNew.ChangeState( &aMsgHnt );
108cdf0e10cSrcweir                     }
109cdf0e10cSrcweir                 }
110cdf0e10cSrcweir             }
111cdf0e10cSrcweir 			rNew.ChgDefinedIn( 0 );
112cdf0e10cSrcweir 		}
113cdf0e10cSrcweir 		break;
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
GetDescription() const117cdf0e10cSrcweir String SwHistorySetFmt::GetDescription() const
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     String aResult ;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     sal_uInt16 nWhich = m_pAttr->Which();
122cdf0e10cSrcweir     switch (nWhich)
123cdf0e10cSrcweir     {
124cdf0e10cSrcweir     case RES_BREAK:
125cdf0e10cSrcweir         switch ((static_cast<SvxFmtBreakItem &>(*m_pAttr)).GetBreak())
126cdf0e10cSrcweir         {
127cdf0e10cSrcweir         case SVX_BREAK_PAGE_BEFORE:
128cdf0e10cSrcweir         case SVX_BREAK_PAGE_AFTER:
129cdf0e10cSrcweir         case SVX_BREAK_PAGE_BOTH:
130cdf0e10cSrcweir             aResult = SW_RES(STR_UNDO_PAGEBREAKS);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir             break;
133cdf0e10cSrcweir         case SVX_BREAK_COLUMN_BEFORE:
134cdf0e10cSrcweir         case SVX_BREAK_COLUMN_AFTER:
135cdf0e10cSrcweir         case SVX_BREAK_COLUMN_BOTH:
136cdf0e10cSrcweir             aResult = SW_RES(STR_UNDO_COLBRKS);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             break;
139cdf0e10cSrcweir         default:
140cdf0e10cSrcweir             break;
141cdf0e10cSrcweir         }
142cdf0e10cSrcweir         break;
143cdf0e10cSrcweir     default:
144cdf0e10cSrcweir         break;
145cdf0e10cSrcweir     }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     return aResult;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool bTmpSet)150cdf0e10cSrcweir void SwHistorySetFmt::SetInDoc( SwDoc* pDoc, bool bTmpSet )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir     SwNode * pNode = pDoc->GetNodes()[ m_nNodeIndex ];
153cdf0e10cSrcweir     if ( pNode->IsCntntNode() )
154cdf0e10cSrcweir     {
155cdf0e10cSrcweir         static_cast<SwCntntNode*>(pNode)->SetAttr( *m_pAttr );
156cdf0e10cSrcweir     }
157cdf0e10cSrcweir     else if ( pNode->IsTableNode() )
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         static_cast<SwTableNode*>(pNode)->GetTable().GetFrmFmt()->SetFmtAttr(
160cdf0e10cSrcweir                 *m_pAttr );
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir     else if ( pNode->IsStartNode() && (SwTableBoxStartNode ==
163cdf0e10cSrcweir                 static_cast<SwStartNode*>(pNode)->GetStartNodeType()) )
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         SwTableNode* pTNd = pNode->FindTableNode();
166cdf0e10cSrcweir         if ( pTNd )
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             SwTableBox* pBox = pTNd->GetTable().GetTblBox( m_nNodeIndex );
169cdf0e10cSrcweir             if (pBox)
170cdf0e10cSrcweir             {
171cdf0e10cSrcweir                 pBox->ClaimFrmFmt()->SetFmtAttr( *m_pAttr );
172cdf0e10cSrcweir             }
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir     }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir     if ( !bTmpSet )
177cdf0e10cSrcweir     {
178cdf0e10cSrcweir         m_pAttr.reset();
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
~SwHistorySetFmt()182cdf0e10cSrcweir SwHistorySetFmt::~SwHistorySetFmt()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // --> OD 2008-02-27 #refactorlists# - removed <rDoc>
SwHistoryResetFmt(const SfxPoolItem * pFmtHt,sal_uLong nNodeIdx)188cdf0e10cSrcweir SwHistoryResetFmt::SwHistoryResetFmt(const SfxPoolItem* pFmtHt, sal_uLong nNodeIdx)
189cdf0e10cSrcweir // <--
190cdf0e10cSrcweir     : SwHistoryHint( HSTRY_RESETFMTHNT )
191cdf0e10cSrcweir     , m_nNodeIndex( nNodeIdx )
192cdf0e10cSrcweir     , m_nWhich( pFmtHt->Which() )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)197cdf0e10cSrcweir void SwHistoryResetFmt::SetInDoc( SwDoc* pDoc, bool )
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     SwNode * pNode = pDoc->GetNodes()[ m_nNodeIndex ];
200cdf0e10cSrcweir     if ( pNode->IsCntntNode() )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         static_cast<SwCntntNode*>(pNode)->ResetAttr( m_nWhich );
203cdf0e10cSrcweir     }
204cdf0e10cSrcweir     else if ( pNode->IsTableNode() )
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir         static_cast<SwTableNode*>(pNode)->GetTable().GetFrmFmt()->
207cdf0e10cSrcweir             ResetFmtAttr( m_nWhich );
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
SwHistorySetTxt(SwTxtAttr * pTxtHt,sal_uLong nNodePos)212cdf0e10cSrcweir SwHistorySetTxt::SwHistorySetTxt( SwTxtAttr* pTxtHt, sal_uLong nNodePos )
213cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETTXTHNT )
214cdf0e10cSrcweir     , m_nNodeIndex( nNodePos )
215cdf0e10cSrcweir     , m_nStart( *pTxtHt->GetStart() )
216cdf0e10cSrcweir     , m_nEnd( *pTxtHt->GetAnyEnd() )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	// !! Achtung: folgende Attribute erzeugen keine FormatAttribute:
219cdf0e10cSrcweir 	//  - NoLineBreak, NoHypen, Inserted, Deleted
220cdf0e10cSrcweir 	// Dafuer muessen Sonderbehandlungen gemacht werden !!!
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 	// ein bisschen kompliziert, aber ist Ok so: erst vom default
223cdf0e10cSrcweir 	// eine Kopie und dann die Werte aus dem Text Attribut zuweisen
224cdf0e10cSrcweir 	sal_uInt16 nWhich = pTxtHt->Which();
225cdf0e10cSrcweir     if ( RES_TXTATR_CHARFMT == nWhich )
226cdf0e10cSrcweir     {
227cdf0e10cSrcweir         m_pAttr.reset( new SwFmtCharFmt( pTxtHt->GetCharFmt().GetCharFmt() ) );
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir     else
230cdf0e10cSrcweir     {
231cdf0e10cSrcweir         m_pAttr.reset( pTxtHt->GetAttr().Clone() );
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
~SwHistorySetTxt()236cdf0e10cSrcweir SwHistorySetTxt::~SwHistorySetTxt()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)241cdf0e10cSrcweir void SwHistorySetTxt::SetInDoc( SwDoc* pDoc, bool )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     if ( !m_pAttr.get() )
244cdf0e10cSrcweir         return;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     if ( RES_TXTATR_CHARFMT == m_pAttr->Which() )
247cdf0e10cSrcweir     {
248cdf0e10cSrcweir         // ask the Doc if the CharFmt still exists
249cdf0e10cSrcweir         if ( USHRT_MAX == pDoc->GetCharFmts()->GetPos(
250cdf0e10cSrcweir                         (static_cast<SwFmtCharFmt&>(*m_pAttr)).GetCharFmt() ) )
251cdf0e10cSrcweir             return; // do not set, format does not exist
252cdf0e10cSrcweir     }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     SwTxtNode * pTxtNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTxtNode();
255cdf0e10cSrcweir     ASSERT( pTxtNd, "SwHistorySetTxt::SetInDoc: not a TextNode" );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     if ( pTxtNd )
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         pTxtNd->InsertItem( *m_pAttr, m_nStart, m_nEnd,
260cdf0e10cSrcweir                         nsSetAttrMode::SETATTR_NOTXTATRCHR |
261cdf0e10cSrcweir                         nsSetAttrMode::SETATTR_NOHINTADJUST );
262cdf0e10cSrcweir     }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 
SwHistorySetTxtFld(SwTxtFld * pTxtFld,sal_uLong nNodePos)266cdf0e10cSrcweir SwHistorySetTxtFld::SwHistorySetTxtFld( SwTxtFld* pTxtFld, sal_uLong nNodePos )
267cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETTXTFLDHNT )
268cdf0e10cSrcweir     , m_pFldType( 0 )
269c0286415SOliver-Rainer Wittmann     , m_pFld( new SwFmtFld( *pTxtFld->GetFmtFld().GetField() ) )
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     // only copy if not Sys-FieldType
272cdf0e10cSrcweir     SwDoc* pDoc = pTxtFld->GetTxtNode().GetDoc();
273cdf0e10cSrcweir 
274c0286415SOliver-Rainer Wittmann     m_nFldWhich = m_pFld->GetField()->GetTyp()->Which();
275cdf0e10cSrcweir     if (m_nFldWhich == RES_DBFLD ||
276cdf0e10cSrcweir         m_nFldWhich == RES_USERFLD ||
277cdf0e10cSrcweir         m_nFldWhich == RES_SETEXPFLD ||
278cdf0e10cSrcweir         m_nFldWhich == RES_DDEFLD ||
279cdf0e10cSrcweir         !pDoc->GetSysFldType( m_nFldWhich ))
280cdf0e10cSrcweir     {
281c0286415SOliver-Rainer Wittmann         m_pFldType.reset( m_pFld->GetField()->GetTyp()->Copy() );
282c0286415SOliver-Rainer Wittmann         m_pFld->GetField()->ChgTyp( m_pFldType.get() ); // change field type
283cdf0e10cSrcweir     }
284cdf0e10cSrcweir     m_nNodeIndex = nNodePos;
285cdf0e10cSrcweir     m_nPos = *pTxtFld->GetStart();
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
GetDescription() const288cdf0e10cSrcweir String SwHistorySetTxtFld::GetDescription() const
289cdf0e10cSrcweir {
290c0286415SOliver-Rainer Wittmann     return m_pFld->GetField()->GetDescription();;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
~SwHistorySetTxtFld()293cdf0e10cSrcweir SwHistorySetTxtFld::~SwHistorySetTxtFld()
294cdf0e10cSrcweir {
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)298cdf0e10cSrcweir void SwHistorySetTxtFld::SetInDoc( SwDoc* pDoc, bool )
299cdf0e10cSrcweir {
300cdf0e10cSrcweir     if ( !m_pFld.get() )
301cdf0e10cSrcweir         return;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     SwFieldType* pNewFldType = m_pFldType.get();
304cdf0e10cSrcweir     if ( !pNewFldType )
305cdf0e10cSrcweir     {
306cdf0e10cSrcweir         pNewFldType = pDoc->GetSysFldType( m_nFldWhich );
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir     else
309cdf0e10cSrcweir     {
310cdf0e10cSrcweir         // register type with the document
311cdf0e10cSrcweir         pNewFldType = pDoc->InsertFldType( *m_pFldType );
312cdf0e10cSrcweir     }
313cdf0e10cSrcweir 
314c0286415SOliver-Rainer Wittmann     m_pFld->GetField()->ChgTyp( pNewFldType ); // change field type
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     SwTxtNode * pTxtNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTxtNode();
317cdf0e10cSrcweir     ASSERT( pTxtNd, "SwHistorySetTxtFld: no TextNode" );
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     if ( pTxtNd )
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir         pTxtNd->InsertItem( *m_pFld, m_nPos, m_nPos,
322cdf0e10cSrcweir                     nsSetAttrMode::SETATTR_NOTXTATRCHR );
323cdf0e10cSrcweir     }
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 
SwHistorySetRefMark(SwTxtRefMark * pTxtHt,sal_uLong nNodePos)328cdf0e10cSrcweir SwHistorySetRefMark::SwHistorySetRefMark( SwTxtRefMark* pTxtHt, sal_uLong nNodePos )
329cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETREFMARKHNT )
330cdf0e10cSrcweir     , m_RefName( pTxtHt->GetRefMark().GetRefName() )
331cdf0e10cSrcweir     , m_nNodeIndex( nNodePos )
332cdf0e10cSrcweir     , m_nStart( *pTxtHt->GetStart() )
333cdf0e10cSrcweir     , m_nEnd( *pTxtHt->GetAnyEnd() )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir }
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)338cdf0e10cSrcweir void SwHistorySetRefMark::SetInDoc( SwDoc* pDoc, bool )
339cdf0e10cSrcweir {
340cdf0e10cSrcweir     SwTxtNode * pTxtNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTxtNode();
341cdf0e10cSrcweir     ASSERT( pTxtNd, "SwHistorySetRefMark: no TextNode" );
342cdf0e10cSrcweir     if ( !pTxtNd )
343cdf0e10cSrcweir         return;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     SwFmtRefMark aRefMark( m_RefName );
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     // if a reference mark without an end already exists here: must not insert!
348cdf0e10cSrcweir     if ( m_nStart != m_nEnd ||
349cdf0e10cSrcweir          !pTxtNd->GetTxtAttrForCharAt( m_nStart, RES_TXTATR_REFMARK ) )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         pTxtNd->InsertItem( aRefMark, m_nStart, m_nEnd,
352cdf0e10cSrcweir                             nsSetAttrMode::SETATTR_NOTXTATRCHR );
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 
SwHistorySetTOXMark(SwTxtTOXMark * pTxtHt,sal_uLong nNodePos)357cdf0e10cSrcweir SwHistorySetTOXMark::SwHistorySetTOXMark( SwTxtTOXMark* pTxtHt, sal_uLong nNodePos )
358cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETTOXMARKHNT )
359cdf0e10cSrcweir     , m_TOXMark( pTxtHt->GetTOXMark() )
360cdf0e10cSrcweir     , m_TOXName( m_TOXMark.GetTOXType()->GetTypeName() )
361cdf0e10cSrcweir     , m_eTOXTypes( m_TOXMark.GetTOXType()->GetType() )
362cdf0e10cSrcweir     , m_nNodeIndex( nNodePos )
363cdf0e10cSrcweir     , m_nStart( *pTxtHt->GetStart() )
364cdf0e10cSrcweir     , m_nEnd( *pTxtHt->GetAnyEnd() )
365cdf0e10cSrcweir {
366cdf0e10cSrcweir     m_TOXMark.DeRegister();
367cdf0e10cSrcweir }
368cdf0e10cSrcweir 
369cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)370cdf0e10cSrcweir void SwHistorySetTOXMark::SetInDoc( SwDoc* pDoc, bool )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     SwTxtNode * pTxtNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTxtNode();
373cdf0e10cSrcweir     ASSERT( pTxtNd, "SwHistorySetTOXMark: no TextNode" );
374cdf0e10cSrcweir     if ( !pTxtNd )
375cdf0e10cSrcweir         return;
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     // search for respective TOX type
378cdf0e10cSrcweir     sal_uInt16 nCnt = pDoc->GetTOXTypeCount( m_eTOXTypes );
379cdf0e10cSrcweir     SwTOXType* pToxType = 0;
380cdf0e10cSrcweir     for ( sal_uInt16 n = 0; n < nCnt; ++n )
381cdf0e10cSrcweir     {
382cdf0e10cSrcweir         pToxType = const_cast<SwTOXType*>(pDoc->GetTOXType( m_eTOXTypes, n ));
383cdf0e10cSrcweir         if ( pToxType->GetTypeName() == m_TOXName )
384cdf0e10cSrcweir             break;
385cdf0e10cSrcweir         pToxType = 0;
386cdf0e10cSrcweir     }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     if ( !pToxType )  // TOX type not found, create new
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         pToxType = const_cast<SwTOXType*>(
391cdf0e10cSrcweir                 pDoc->InsertTOXType( SwTOXType( m_eTOXTypes, m_TOXName )));
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     SwTOXMark aNew( m_TOXMark );
395cdf0e10cSrcweir     aNew.RegisterToTOXType( *pToxType );
396cdf0e10cSrcweir 
397cdf0e10cSrcweir     pTxtNd->InsertItem( aNew, m_nStart, m_nEnd,
398cdf0e10cSrcweir                         nsSetAttrMode::SETATTR_NOTXTATRCHR );
399cdf0e10cSrcweir }
400cdf0e10cSrcweir 
401cdf0e10cSrcweir 
IsEqual(const SwTOXMark & rCmp) const402cdf0e10cSrcweir int SwHistorySetTOXMark::IsEqual( const SwTOXMark& rCmp ) const
403cdf0e10cSrcweir {
404cdf0e10cSrcweir     return m_TOXName   == rCmp.GetTOXType()->GetTypeName() &&
405cdf0e10cSrcweir            m_eTOXTypes == rCmp.GetTOXType()->GetType() &&
406cdf0e10cSrcweir            m_TOXMark.GetAlternativeText() == rCmp.GetAlternativeText() &&
407cdf0e10cSrcweir            ( (TOX_INDEX == m_eTOXTypes)
408cdf0e10cSrcweir               ?   ( m_TOXMark.GetPrimaryKey()   == rCmp.GetPrimaryKey()  &&
409cdf0e10cSrcweir                     m_TOXMark.GetSecondaryKey() == rCmp.GetSecondaryKey()   )
410cdf0e10cSrcweir               :   m_TOXMark.GetLevel() == rCmp.GetLevel()
411cdf0e10cSrcweir            );
412cdf0e10cSrcweir }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 
SwHistoryResetTxt(sal_uInt16 nWhich,xub_StrLen nAttrStart,xub_StrLen nAttrEnd,sal_uLong nNodePos)415cdf0e10cSrcweir SwHistoryResetTxt::SwHistoryResetTxt( sal_uInt16 nWhich,
416cdf0e10cSrcweir             xub_StrLen nAttrStart, xub_StrLen nAttrEnd, sal_uLong nNodePos )
417cdf0e10cSrcweir     : SwHistoryHint( HSTRY_RESETTXTHNT )
418cdf0e10cSrcweir     , m_nNodeIndex( nNodePos ), m_nStart( nAttrStart ), m_nEnd( nAttrEnd )
419cdf0e10cSrcweir     , m_nAttr( nWhich )
420cdf0e10cSrcweir {
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)424cdf0e10cSrcweir void SwHistoryResetTxt::SetInDoc( SwDoc* pDoc, bool )
425cdf0e10cSrcweir {
426cdf0e10cSrcweir     SwTxtNode * pTxtNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTxtNode();
427cdf0e10cSrcweir     ASSERT( pTxtNd, "SwHistoryResetTxt: no TextNode" );
428cdf0e10cSrcweir     if ( pTxtNd )
429cdf0e10cSrcweir     {
430cdf0e10cSrcweir         pTxtNd->DeleteAttributes( m_nAttr, m_nStart, m_nEnd );
431cdf0e10cSrcweir     }
432cdf0e10cSrcweir }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 
SwHistorySetFootnote(SwTxtFtn * pTxtFtn,sal_uLong nNodePos)435cdf0e10cSrcweir SwHistorySetFootnote::SwHistorySetFootnote( SwTxtFtn* pTxtFtn, sal_uLong nNodePos )
436cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETFTNHNT )
437cdf0e10cSrcweir     , m_pUndo( new SwUndoSaveSection )
438cdf0e10cSrcweir     , m_FootnoteNumber( pTxtFtn->GetFtn().GetNumStr() )
439cdf0e10cSrcweir     , m_nNodeIndex( nNodePos )
440cdf0e10cSrcweir     , m_nStart( *pTxtFtn->GetStart() )
441cdf0e10cSrcweir     , m_bEndNote( pTxtFtn->GetFtn().IsEndNote() )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir     ASSERT( pTxtFtn->GetStartNode(),
444cdf0e10cSrcweir             "SwHistorySetFootnote: Footnote without Section" );
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	// merke die alte NodePos, denn wer weiss was alles in der SaveSection
447cdf0e10cSrcweir 	// gespeichert (geloescht) wird
448cdf0e10cSrcweir     SwDoc* pDoc = const_cast<SwDoc*>(pTxtFtn->GetTxtNode().GetDoc());
449cdf0e10cSrcweir     SwNode* pSaveNd = pDoc->GetNodes()[ m_nNodeIndex ];
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	//Pointer auf StartNode der FtnSection merken und erstmal den Pointer im
452cdf0e10cSrcweir 	//Attribut zuruecksetzen -> Damit werden automatisch die Frms vernichtet.
453cdf0e10cSrcweir 	SwNodeIndex aSttIdx( *pTxtFtn->GetStartNode() );
454cdf0e10cSrcweir 	pTxtFtn->SetStartNode( 0, sal_False );
455cdf0e10cSrcweir 
456cdf0e10cSrcweir     m_pUndo->SaveSection( pDoc, aSttIdx );
457cdf0e10cSrcweir     m_nNodeIndex = pSaveNd->GetIndex();
458cdf0e10cSrcweir }
459cdf0e10cSrcweir 
SwHistorySetFootnote(const SwTxtFtn & rTxtFtn)460cdf0e10cSrcweir SwHistorySetFootnote::SwHistorySetFootnote( const SwTxtFtn &rTxtFtn )
461cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETFTNHNT )
462cdf0e10cSrcweir     , m_pUndo( 0 )
463cdf0e10cSrcweir     , m_FootnoteNumber( rTxtFtn.GetFtn().GetNumStr() )
464cdf0e10cSrcweir     , m_nNodeIndex( _SwTxtFtn_GetIndex( (&rTxtFtn) ) )
465cdf0e10cSrcweir     , m_nStart( *rTxtFtn.GetStart() )
466cdf0e10cSrcweir     , m_bEndNote( rTxtFtn.GetFtn().IsEndNote() )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir     ASSERT( rTxtFtn.GetStartNode(),
469cdf0e10cSrcweir             "SwHistorySetFootnote: Footnote without Section" );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
GetDescription() const472cdf0e10cSrcweir String SwHistorySetFootnote::GetDescription() const
473cdf0e10cSrcweir {
474cdf0e10cSrcweir     return SW_RES(STR_FOOTNOTE);
475cdf0e10cSrcweir }
476cdf0e10cSrcweir 
~SwHistorySetFootnote()477cdf0e10cSrcweir SwHistorySetFootnote::~SwHistorySetFootnote()
478cdf0e10cSrcweir {
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)482cdf0e10cSrcweir void SwHistorySetFootnote::SetInDoc( SwDoc* pDoc, bool )
483cdf0e10cSrcweir {
484cdf0e10cSrcweir     SwTxtNode * pTxtNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetTxtNode();
485cdf0e10cSrcweir     ASSERT( pTxtNd, "SwHistorySetFootnote: no TextNode" );
486cdf0e10cSrcweir     if ( !pTxtNd )
487cdf0e10cSrcweir         return;
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     if ( m_pUndo.get() )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         // set the footnote in the TextNode
492cdf0e10cSrcweir         SwFmtFtn aTemp( m_bEndNote );
493cdf0e10cSrcweir         SwFmtFtn& rNew = const_cast<SwFmtFtn&>(
494cdf0e10cSrcweir                 static_cast<const SwFmtFtn&>(pDoc->GetAttrPool().Put(aTemp)) );
495cdf0e10cSrcweir         if ( m_FootnoteNumber.Len() )
496cdf0e10cSrcweir         {
497cdf0e10cSrcweir             rNew.SetNumStr( m_FootnoteNumber );
498cdf0e10cSrcweir         }
499cdf0e10cSrcweir         SwTxtFtn* pTxtFtn = new SwTxtFtn( rNew, m_nStart );
500cdf0e10cSrcweir 
501cdf0e10cSrcweir         // create the section of the Footnote
502cdf0e10cSrcweir         SwNodeIndex aIdx( *pTxtNd );
503cdf0e10cSrcweir         m_pUndo->RestoreSection( pDoc, &aIdx, SwFootnoteStartNode );
504cdf0e10cSrcweir         pTxtFtn->SetStartNode( &aIdx );
505cdf0e10cSrcweir         if ( m_pUndo->GetHistory() )
506cdf0e10cSrcweir         {
507cdf0e10cSrcweir             // create frames only now
508cdf0e10cSrcweir             m_pUndo->GetHistory()->Rollback( pDoc );
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir         pTxtNd->InsertHint( pTxtFtn );
512cdf0e10cSrcweir     }
513cdf0e10cSrcweir     else
514cdf0e10cSrcweir     {
515cdf0e10cSrcweir         SwTxtFtn * const pFtn =
516cdf0e10cSrcweir             const_cast<SwTxtFtn*>( static_cast<const SwTxtFtn*>(
517cdf0e10cSrcweir                 pTxtNd->GetTxtAttrForCharAt( m_nStart )));
518cdf0e10cSrcweir         SwFmtFtn &rFtn = const_cast<SwFmtFtn&>(pFtn->GetFtn());
519cdf0e10cSrcweir         rFtn.SetNumStr( m_FootnoteNumber  );
520cdf0e10cSrcweir         if ( rFtn.IsEndNote() != m_bEndNote )
521cdf0e10cSrcweir         {
522cdf0e10cSrcweir             rFtn.SetEndNote( m_bEndNote );
523cdf0e10cSrcweir             pFtn->CheckCondColl();
524cdf0e10cSrcweir         }
525cdf0e10cSrcweir     }
526cdf0e10cSrcweir }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 
SwHistoryChangeFmtColl(SwFmtColl * pFmtColl,sal_uLong nNd,sal_uInt8 nNodeWhich)529cdf0e10cSrcweir SwHistoryChangeFmtColl::SwHistoryChangeFmtColl( SwFmtColl* pFmtColl, sal_uLong nNd,
530cdf0e10cSrcweir                             sal_uInt8 nNodeWhich )
531cdf0e10cSrcweir     : SwHistoryHint( HSTRY_CHGFMTCOLL )
532cdf0e10cSrcweir     , m_pColl( pFmtColl )
533cdf0e10cSrcweir     , m_nNodeIndex( nNd )
534cdf0e10cSrcweir     , m_nNodeType( nNodeWhich )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir }
537cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)538cdf0e10cSrcweir void SwHistoryChangeFmtColl::SetInDoc( SwDoc* pDoc, bool )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir     SwCntntNode * pCntntNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetCntntNode();
541cdf0e10cSrcweir     ASSERT( pCntntNd, "SwHistoryChangeFmtColl: no ContentNode" );
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     // before setting the format, check if it is still available in the
544cdf0e10cSrcweir     // document. if it has been deleted, there is no undo!
545cdf0e10cSrcweir     if ( pCntntNd && m_nNodeType == pCntntNd->GetNodeType() )
546cdf0e10cSrcweir     {
547cdf0e10cSrcweir         if ( ND_TEXTNODE == m_nNodeType )
548cdf0e10cSrcweir         {
549cdf0e10cSrcweir             if ( USHRT_MAX != pDoc->GetTxtFmtColls()->GetPos(
550cdf0e10cSrcweir                             static_cast<SwTxtFmtColl * const>(m_pColl) ))
551cdf0e10cSrcweir             {
552cdf0e10cSrcweir                 pCntntNd->ChgFmtColl( m_pColl );
553cdf0e10cSrcweir             }
554cdf0e10cSrcweir         }
555cdf0e10cSrcweir         else if ( USHRT_MAX != pDoc->GetGrfFmtColls()->GetPos(
556cdf0e10cSrcweir                             static_cast<SwGrfFmtColl * const>(m_pColl) ))
557cdf0e10cSrcweir         {
558cdf0e10cSrcweir             pCntntNd->ChgFmtColl( m_pColl );
559cdf0e10cSrcweir         }
560cdf0e10cSrcweir     }
561cdf0e10cSrcweir }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 
SwHistoryTxtFlyCnt(SwFrmFmt * const pFlyFmt)564cdf0e10cSrcweir SwHistoryTxtFlyCnt::SwHistoryTxtFlyCnt( SwFrmFmt* const pFlyFmt )
565cdf0e10cSrcweir     : SwHistoryHint( HSTRY_FLYCNT )
566cdf0e10cSrcweir     , m_pUndo( new SwUndoDelLayFmt( pFlyFmt ) )
567cdf0e10cSrcweir {
568cdf0e10cSrcweir     ASSERT( pFlyFmt, "SwHistoryTxtFlyCnt: no Format" );
569cdf0e10cSrcweir     m_pUndo->ChgShowSel( sal_False );
570cdf0e10cSrcweir }
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 
~SwHistoryTxtFlyCnt()573cdf0e10cSrcweir SwHistoryTxtFlyCnt::~SwHistoryTxtFlyCnt()
574cdf0e10cSrcweir {
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)578cdf0e10cSrcweir void SwHistoryTxtFlyCnt::SetInDoc( SwDoc* pDoc, bool )
579cdf0e10cSrcweir {
580cdf0e10cSrcweir     ::sw::IShellCursorSupplier *const pISCS(pDoc->GetIShellCursorSupplier());
581cdf0e10cSrcweir     OSL_ASSERT(pISCS);
582cdf0e10cSrcweir     ::sw::UndoRedoContext context(*pDoc, *pISCS);
583cdf0e10cSrcweir     m_pUndo->UndoImpl(context);
584cdf0e10cSrcweir }
585cdf0e10cSrcweir 
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 
SwHistoryBookmark(const::sw::mark::IMark & rBkmk,bool bSavePos,bool bSaveOtherPos)588cdf0e10cSrcweir SwHistoryBookmark::SwHistoryBookmark(
589cdf0e10cSrcweir     const ::sw::mark::IMark& rBkmk,
590cdf0e10cSrcweir     bool bSavePos,
591cdf0e10cSrcweir     bool bSaveOtherPos)
592cdf0e10cSrcweir     : SwHistoryHint(HSTRY_BOOKMARK)
593cdf0e10cSrcweir     , m_aName(rBkmk.GetName())
594cdf0e10cSrcweir     , m_aShortName()
595cdf0e10cSrcweir     , m_aKeycode()
596cdf0e10cSrcweir     , m_nNode(bSavePos ?
597cdf0e10cSrcweir         rBkmk.GetMarkPos().nNode.GetIndex() : 0)
598cdf0e10cSrcweir     , m_nOtherNode(bSaveOtherPos ?
599cdf0e10cSrcweir         rBkmk.GetOtherMarkPos().nNode.GetIndex() : 0)
600cdf0e10cSrcweir     , m_nCntnt(bSavePos ?
601cdf0e10cSrcweir         rBkmk.GetMarkPos().nContent.GetIndex() : 0)
602cdf0e10cSrcweir     , m_nOtherCntnt(bSaveOtherPos ?
603cdf0e10cSrcweir         rBkmk.GetOtherMarkPos().nContent.GetIndex() :0)
604cdf0e10cSrcweir     , m_bSavePos(bSavePos)
605cdf0e10cSrcweir     , m_bSaveOtherPos(bSaveOtherPos)
606cdf0e10cSrcweir     , m_bHadOtherPos(rBkmk.IsExpanded())
607cdf0e10cSrcweir     , m_eBkmkType(IDocumentMarkAccess::GetType(rBkmk))
608cdf0e10cSrcweir {
609cdf0e10cSrcweir     const ::sw::mark::IBookmark* const pBookmark = dynamic_cast< const ::sw::mark::IBookmark* >(&rBkmk);
610cdf0e10cSrcweir     if(pBookmark)
611cdf0e10cSrcweir     {
612cdf0e10cSrcweir         m_aKeycode = pBookmark->GetKeyCode();
613cdf0e10cSrcweir         m_aShortName = pBookmark->GetShortName();
614cdf0e10cSrcweir 
615cdf0e10cSrcweir         ::sfx2::Metadatable const*const pMetadatable(
616cdf0e10cSrcweir                 dynamic_cast< ::sfx2::Metadatable const* >(pBookmark));
617cdf0e10cSrcweir         if (pMetadatable)
618cdf0e10cSrcweir         {
619cdf0e10cSrcweir             m_pMetadataUndo = pMetadatable->CreateUndo();
620cdf0e10cSrcweir         }
621cdf0e10cSrcweir     }
622cdf0e10cSrcweir }
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)625cdf0e10cSrcweir void SwHistoryBookmark::SetInDoc( SwDoc* pDoc, bool )
626cdf0e10cSrcweir {
627cdf0e10cSrcweir     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
628cdf0e10cSrcweir 
629cdf0e10cSrcweir     SwNodes& rNds = pDoc->GetNodes();
630cdf0e10cSrcweir     IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
631cdf0e10cSrcweir     ::std::auto_ptr<SwPaM> pPam;
632cdf0e10cSrcweir     ::sw::mark::IMark* pMark = NULL;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     if(m_bSavePos)
635cdf0e10cSrcweir     {
636cdf0e10cSrcweir         SwCntntNode* const pCntntNd = rNds[m_nNode]->GetCntntNode();
637cdf0e10cSrcweir         OSL_ENSURE(pCntntNd,
638cdf0e10cSrcweir             "<SwHistoryBookmark::SetInDoc(..)>"
639cdf0e10cSrcweir             " - wrong node for a mark");
640cdf0e10cSrcweir 
641cdf0e10cSrcweir         // #111660# don't crash when nNode1 doesn't point to content node.
642cdf0e10cSrcweir         if(pCntntNd)
643cdf0e10cSrcweir             pPam = ::std::auto_ptr<SwPaM>(new SwPaM(*pCntntNd, m_nCntnt));
644cdf0e10cSrcweir     }
645cdf0e10cSrcweir     else
646cdf0e10cSrcweir     {
647cdf0e10cSrcweir         pMark = pMarkAccess->findMark(m_aName)->get();
648cdf0e10cSrcweir         pPam = ::std::auto_ptr<SwPaM>(new SwPaM(pMark->GetMarkPos()));
649cdf0e10cSrcweir     }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir     if(m_bSaveOtherPos)
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         SwCntntNode* const pCntntNd = rNds[m_nOtherNode]->GetCntntNode();
654cdf0e10cSrcweir         OSL_ENSURE(pCntntNd,
655cdf0e10cSrcweir             "<SwHistoryBookmark::SetInDoc(..)>"
656cdf0e10cSrcweir             " - wrong node for a mark");
657cdf0e10cSrcweir 
658cdf0e10cSrcweir         if(pPam.get() != NULL && pCntntNd)
659cdf0e10cSrcweir         {
660cdf0e10cSrcweir             pPam->SetMark();
661cdf0e10cSrcweir             pPam->GetMark()->nNode = m_nOtherNode;
662cdf0e10cSrcweir             pPam->GetMark()->nContent.Assign(pCntntNd, m_nOtherCntnt);
663cdf0e10cSrcweir         }
664cdf0e10cSrcweir     }
665cdf0e10cSrcweir     else if(m_bHadOtherPos)
666cdf0e10cSrcweir     {
667cdf0e10cSrcweir         if(!pMark)
668cdf0e10cSrcweir             pMark = pMarkAccess->findMark(m_aName)->get();
669cdf0e10cSrcweir         OSL_ENSURE(pMark->IsExpanded(),
670cdf0e10cSrcweir             "<SwHistoryBookmark::SetInDoc(..)>"
671cdf0e10cSrcweir             " - missing pos on old mark");
672cdf0e10cSrcweir         pPam->SetMark();
673cdf0e10cSrcweir         *pPam->GetMark() = pMark->GetOtherMarkPos();
674cdf0e10cSrcweir     }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir     if(pPam.get())
677cdf0e10cSrcweir     {
678*dec99bbdSOliver-Rainer Wittmann         if ( pMark != NULL )
679*dec99bbdSOliver-Rainer Wittmann         {
680*dec99bbdSOliver-Rainer Wittmann             pMarkAccess->deleteMark( pMark );
681*dec99bbdSOliver-Rainer Wittmann         }
682*dec99bbdSOliver-Rainer Wittmann         ::sw::mark::IBookmark* const pBookmark =
683*dec99bbdSOliver-Rainer Wittmann             dynamic_cast< ::sw::mark::IBookmark* >( pMarkAccess->makeMark(*pPam, m_aName, m_eBkmkType) );
684*dec99bbdSOliver-Rainer Wittmann         if ( pBookmark != NULL )
685cdf0e10cSrcweir         {
686cdf0e10cSrcweir             pBookmark->SetKeyCode(m_aKeycode);
687cdf0e10cSrcweir             pBookmark->SetShortName(m_aShortName);
688cdf0e10cSrcweir             if (m_pMetadataUndo)
689cdf0e10cSrcweir             {
690cdf0e10cSrcweir                 ::sfx2::Metadatable * const pMeta(
691cdf0e10cSrcweir                     dynamic_cast< ::sfx2::Metadatable* >(pBookmark));
692cdf0e10cSrcweir                 OSL_ENSURE(pMeta, "metadata undo, but not metadatable?");
693cdf0e10cSrcweir                 if (pMeta)
694cdf0e10cSrcweir                 {
695cdf0e10cSrcweir                     pMeta->RestoreMetadata(m_pMetadataUndo);
696cdf0e10cSrcweir                 }
697cdf0e10cSrcweir             }
698cdf0e10cSrcweir         }
699cdf0e10cSrcweir     }
700cdf0e10cSrcweir }
701cdf0e10cSrcweir 
702cdf0e10cSrcweir 
IsEqualBookmark(const::sw::mark::IMark & rBkmk)703cdf0e10cSrcweir bool SwHistoryBookmark::IsEqualBookmark(const ::sw::mark::IMark& rBkmk)
704cdf0e10cSrcweir {
705cdf0e10cSrcweir     return m_nNode == rBkmk.GetMarkPos().nNode.GetIndex()
706cdf0e10cSrcweir         && m_nCntnt == rBkmk.GetMarkPos().nContent.GetIndex()
707cdf0e10cSrcweir         && m_aName == rBkmk.GetName();
708cdf0e10cSrcweir }
709cdf0e10cSrcweir 
GetName() const710cdf0e10cSrcweir const ::rtl::OUString& SwHistoryBookmark::GetName() const
711cdf0e10cSrcweir {
712cdf0e10cSrcweir     return m_aName;
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir /*************************************************************************/
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 
SwHistorySetAttrSet(const SfxItemSet & rSet,sal_uLong nNodePos,const SvUShortsSort & rSetArr)718cdf0e10cSrcweir SwHistorySetAttrSet::SwHistorySetAttrSet( const SfxItemSet& rSet,
719cdf0e10cSrcweir                         sal_uLong nNodePos, const SvUShortsSort& rSetArr )
720cdf0e10cSrcweir     : SwHistoryHint( HSTRY_SETATTRSET )
721cdf0e10cSrcweir     , m_OldSet( rSet )
722cdf0e10cSrcweir     , m_ResetArray( 0, 4 )
723cdf0e10cSrcweir     , m_nNodeIndex( nNodePos )
724cdf0e10cSrcweir {
725cdf0e10cSrcweir     SfxItemIter aIter( m_OldSet ), aOrigIter( rSet );
726cdf0e10cSrcweir 	const SfxPoolItem* pItem = aIter.FirstItem(),
727cdf0e10cSrcweir 					 * pOrigItem = aOrigIter.FirstItem();
728cdf0e10cSrcweir 	do {
729cdf0e10cSrcweir 		if( !rSetArr.Seek_Entry( pOrigItem->Which() ))
730cdf0e10cSrcweir         {
731cdf0e10cSrcweir             m_ResetArray.Insert( pOrigItem->Which(), m_ResetArray.Count() );
732cdf0e10cSrcweir             m_OldSet.ClearItem( pOrigItem->Which() );
733cdf0e10cSrcweir         }
734cdf0e10cSrcweir         else
735cdf0e10cSrcweir         {
736cdf0e10cSrcweir             switch ( pItem->Which() )
737cdf0e10cSrcweir             {
738cdf0e10cSrcweir                 case RES_PAGEDESC:
739cdf0e10cSrcweir                     static_cast<SwFmtPageDesc*>(
740cdf0e10cSrcweir                         const_cast<SfxPoolItem*>(pItem))->ChgDefinedIn( 0 );
741cdf0e10cSrcweir                     break;
742cdf0e10cSrcweir 
743cdf0e10cSrcweir                 case RES_PARATR_DROP:
744cdf0e10cSrcweir                     static_cast<SwFmtDrop*>(
745cdf0e10cSrcweir                         const_cast<SfxPoolItem*>(pItem))->ChgDefinedIn( 0 );
746cdf0e10cSrcweir                     break;
747cdf0e10cSrcweir 
748cdf0e10cSrcweir                 case RES_BOXATR_FORMULA:
749cdf0e10cSrcweir                     {
750cdf0e10cSrcweir 					//JP 20.04.98: Bug 49502 - wenn eine Formel gesetzt ist, nie den
751cdf0e10cSrcweir 					//				Value mit sichern. Der muss gegebenfalls neu
752cdf0e10cSrcweir 					//				errechnet werden!
753cdf0e10cSrcweir 					//JP 30.07.98: Bug 54295 - Formeln immer im Klartext speichern
754cdf0e10cSrcweir                         m_OldSet.ClearItem( RES_BOXATR_VALUE );
755cdf0e10cSrcweir 
756cdf0e10cSrcweir                         SwTblBoxFormula& rNew =
757cdf0e10cSrcweir                             *static_cast<SwTblBoxFormula*>(
758cdf0e10cSrcweir                                 const_cast<SfxPoolItem*>(pItem));
759cdf0e10cSrcweir                         if ( rNew.IsIntrnlName() )
760cdf0e10cSrcweir                         {
761cdf0e10cSrcweir                             const SwTblBoxFormula& rOld =
762cdf0e10cSrcweir                                 static_cast<const SwTblBoxFormula&>(
763cdf0e10cSrcweir                                         rSet.Get( RES_BOXATR_FORMULA ));
764cdf0e10cSrcweir                             const SwNode* pNd = rOld.GetNodeOfFormula();
765cdf0e10cSrcweir                             if ( pNd )
766cdf0e10cSrcweir                             {
767cdf0e10cSrcweir                                 const SwTableNode* pTableNode
768cdf0e10cSrcweir                                     = pNd->FindTableNode();
769cdf0e10cSrcweir                                 if (pTableNode)
770cdf0e10cSrcweir                                 {
771cdf0e10cSrcweir                                     SwTableFmlUpdate aMsgHnt(
772cdf0e10cSrcweir                                         &pTableNode->GetTable() );
773cdf0e10cSrcweir                                     aMsgHnt.eFlags = TBL_BOXNAME;
774cdf0e10cSrcweir                                     rNew.ChgDefinedIn( rOld.GetDefinedIn() );
775cdf0e10cSrcweir                                     rNew.ChangeState( &aMsgHnt );
776cdf0e10cSrcweir                                 }
777cdf0e10cSrcweir                             }
778cdf0e10cSrcweir                         }
779cdf0e10cSrcweir                         rNew.ChgDefinedIn( 0 );
780cdf0e10cSrcweir                     }
781cdf0e10cSrcweir                     break;
782cdf0e10cSrcweir             }
783cdf0e10cSrcweir         }
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 		if( aIter.IsAtEnd() )
786cdf0e10cSrcweir 			break;
787cdf0e10cSrcweir 		pItem = aIter.NextItem();
788cdf0e10cSrcweir 		pOrigItem = aOrigIter.NextItem();
789cdf0e10cSrcweir 	} while( sal_True );
790cdf0e10cSrcweir }
791cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)792cdf0e10cSrcweir void SwHistorySetAttrSet::SetInDoc( SwDoc* pDoc, bool )
793cdf0e10cSrcweir {
794cdf0e10cSrcweir     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
795cdf0e10cSrcweir 
796cdf0e10cSrcweir     SwNode * pNode = pDoc->GetNodes()[ m_nNodeIndex ];
797cdf0e10cSrcweir     if ( pNode->IsCntntNode() )
798cdf0e10cSrcweir     {
799cdf0e10cSrcweir         static_cast<SwCntntNode*>(pNode)->SetAttr( m_OldSet );
800cdf0e10cSrcweir         if ( m_ResetArray.Count() )
801cdf0e10cSrcweir         {
802cdf0e10cSrcweir             static_cast<SwCntntNode*>(pNode)->ResetAttr( m_ResetArray );
803cdf0e10cSrcweir         }
804cdf0e10cSrcweir     }
805cdf0e10cSrcweir     else if ( pNode->IsTableNode() )
806cdf0e10cSrcweir     {
807cdf0e10cSrcweir         SwFmt& rFmt =
808cdf0e10cSrcweir             *static_cast<SwTableNode*>(pNode)->GetTable().GetFrmFmt();
809cdf0e10cSrcweir         rFmt.SetFmtAttr( m_OldSet );
810cdf0e10cSrcweir         if ( m_ResetArray.Count() )
811cdf0e10cSrcweir         {
812cdf0e10cSrcweir             rFmt.ResetFmtAttr( *m_ResetArray.GetData() );
813cdf0e10cSrcweir         }
814cdf0e10cSrcweir     }
815cdf0e10cSrcweir }
816cdf0e10cSrcweir 
817cdf0e10cSrcweir /*************************************************************************/
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 
SwHistoryResetAttrSet(const SfxItemSet & rSet,sal_uLong nNodePos,xub_StrLen nAttrStt,xub_StrLen nAttrEnd)820cdf0e10cSrcweir SwHistoryResetAttrSet::SwHistoryResetAttrSet( const SfxItemSet& rSet,
821cdf0e10cSrcweir                     sal_uLong nNodePos, xub_StrLen nAttrStt, xub_StrLen nAttrEnd )
822cdf0e10cSrcweir     : SwHistoryHint( HSTRY_RESETATTRSET )
823cdf0e10cSrcweir     , m_nNodeIndex( nNodePos ), m_nStart( nAttrStt ), m_nEnd( nAttrEnd )
824cdf0e10cSrcweir     , m_Array( (sal_uInt8)rSet.Count() )
825cdf0e10cSrcweir {
826cdf0e10cSrcweir 	SfxItemIter aIter( rSet );
827cdf0e10cSrcweir     bool bAutoStyle = false;
828cdf0e10cSrcweir 
829cdf0e10cSrcweir 	while( sal_True )
830cdf0e10cSrcweir 	{
831cdf0e10cSrcweir         const sal_uInt16 nWhich = aIter.GetCurItem()->Which();
832cdf0e10cSrcweir 
833cdf0e10cSrcweir #ifndef PRODUCT
834cdf0e10cSrcweir         switch (nWhich)
835cdf0e10cSrcweir         {
836cdf0e10cSrcweir             case RES_TXTATR_REFMARK:
837cdf0e10cSrcweir             case RES_TXTATR_TOXMARK:
838cdf0e10cSrcweir                 if (m_nStart != m_nEnd) break; // else: fall through!
839cdf0e10cSrcweir             case RES_TXTATR_FIELD:
840*dec99bbdSOliver-Rainer Wittmann             case RES_TXTATR_ANNOTATION:
841cdf0e10cSrcweir             case RES_TXTATR_FLYCNT:
842cdf0e10cSrcweir             case RES_TXTATR_FTN:
843cdf0e10cSrcweir             case RES_TXTATR_META:
844cdf0e10cSrcweir             case RES_TXTATR_METAFIELD:
845cdf0e10cSrcweir                 ASSERT(rSet.Count() == 1,
846cdf0e10cSrcweir                     "text attribute with CH_TXTATR, but not the only one:"
847cdf0e10cSrcweir                     "\nnot such a good idea");
848cdf0e10cSrcweir                 break;
849cdf0e10cSrcweir         }
850cdf0e10cSrcweir #endif
851cdf0e10cSrcweir 
852cdf0e10cSrcweir         // Character attribute cannot be inserted into the hints array
853cdf0e10cSrcweir         // anymore. Therefore we have to treat them as one RES_TXTATR_AUTOFMT:
854cdf0e10cSrcweir         if (isCHRATR(nWhich))
855cdf0e10cSrcweir         {
856cdf0e10cSrcweir             bAutoStyle = true;
857cdf0e10cSrcweir         }
858cdf0e10cSrcweir         else
859cdf0e10cSrcweir         {
860cdf0e10cSrcweir             m_Array.Insert( aIter.GetCurItem()->Which(), m_Array.Count() );
861cdf0e10cSrcweir         }
862cdf0e10cSrcweir 
863cdf0e10cSrcweir         if( aIter.IsAtEnd() )
864cdf0e10cSrcweir 			break;
865cdf0e10cSrcweir 
866cdf0e10cSrcweir 		aIter.NextItem();
867cdf0e10cSrcweir 	}
868cdf0e10cSrcweir 
869cdf0e10cSrcweir     if ( bAutoStyle )
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir         m_Array.Insert( RES_TXTATR_AUTOFMT, m_Array.Count() );
872cdf0e10cSrcweir     }
873cdf0e10cSrcweir }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)876cdf0e10cSrcweir void SwHistoryResetAttrSet::SetInDoc( SwDoc* pDoc, bool )
877cdf0e10cSrcweir {
878cdf0e10cSrcweir     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
879cdf0e10cSrcweir 
880cdf0e10cSrcweir     SwCntntNode * pCntntNd = pDoc->GetNodes()[ m_nNodeIndex ]->GetCntntNode();
881cdf0e10cSrcweir     ASSERT( pCntntNd, "SwHistoryResetAttrSet: no CntntNode" );
882cdf0e10cSrcweir 
883cdf0e10cSrcweir     if (pCntntNd)
884cdf0e10cSrcweir     {
885cdf0e10cSrcweir         const sal_uInt16* pArr = m_Array.GetData();
886cdf0e10cSrcweir         if ( USHRT_MAX == m_nEnd && USHRT_MAX == m_nStart )
887cdf0e10cSrcweir         {
888cdf0e10cSrcweir             // no area: use ContentNode
889cdf0e10cSrcweir             for ( sal_uInt16 n = m_Array.Count(); n; --n, ++pArr )
890cdf0e10cSrcweir             {
891cdf0e10cSrcweir                 pCntntNd->ResetAttr( *pArr );
892cdf0e10cSrcweir             }
893cdf0e10cSrcweir         }
894cdf0e10cSrcweir         else
895cdf0e10cSrcweir         {
896cdf0e10cSrcweir             // area: use TextNode
897cdf0e10cSrcweir             for ( sal_uInt16 n = m_Array.Count(); n; --n, ++pArr )
898cdf0e10cSrcweir             {
899cdf0e10cSrcweir                 static_cast<SwTxtNode*>(pCntntNd)->
900cdf0e10cSrcweir                     DeleteAttributes( *pArr, m_nStart, m_nEnd );
901cdf0e10cSrcweir             }
902cdf0e10cSrcweir         }
903cdf0e10cSrcweir     }
904cdf0e10cSrcweir }
905cdf0e10cSrcweir 
906cdf0e10cSrcweir 
907cdf0e10cSrcweir /*************************************************************************/
908cdf0e10cSrcweir 
909cdf0e10cSrcweir 
SwHistoryChangeFlyAnchor(SwFrmFmt & rFmt)910cdf0e10cSrcweir SwHistoryChangeFlyAnchor::SwHistoryChangeFlyAnchor( SwFrmFmt& rFmt )
911cdf0e10cSrcweir     : SwHistoryHint( HSTRY_CHGFLYANCHOR )
912cdf0e10cSrcweir     , m_rFmt( rFmt )
913cdf0e10cSrcweir     , m_nOldNodeIndex( rFmt.GetAnchor().GetCntntAnchor()->nNode.GetIndex() )
914cdf0e10cSrcweir     , m_nOldContentIndex( (FLY_AT_CHAR == rFmt.GetAnchor().GetAnchorId())
915cdf0e10cSrcweir             ?   rFmt.GetAnchor().GetCntntAnchor()->nContent.GetIndex()
916cdf0e10cSrcweir             :   STRING_MAXLEN )
917cdf0e10cSrcweir {
918cdf0e10cSrcweir }
919cdf0e10cSrcweir 
920cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)921cdf0e10cSrcweir void SwHistoryChangeFlyAnchor::SetInDoc( SwDoc* pDoc, bool )
922cdf0e10cSrcweir {
923cdf0e10cSrcweir     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
924cdf0e10cSrcweir 
925cdf0e10cSrcweir     sal_uInt16 nPos = pDoc->GetSpzFrmFmts()->GetPos( &m_rFmt );
926cdf0e10cSrcweir     if ( USHRT_MAX != nPos )    // Format does still exist
927cdf0e10cSrcweir     {
928cdf0e10cSrcweir         SwFmtAnchor aTmp( m_rFmt.GetAnchor() );
929cdf0e10cSrcweir 
930cdf0e10cSrcweir         SwNode* pNd = pDoc->GetNodes()[ m_nOldNodeIndex ];
931cdf0e10cSrcweir         SwCntntNode* pCNd = pNd->GetCntntNode();
932cdf0e10cSrcweir         SwPosition aPos( *pNd );
933cdf0e10cSrcweir         if ( STRING_MAXLEN != m_nOldContentIndex )
934cdf0e10cSrcweir         {
935cdf0e10cSrcweir             ASSERT(pCNd, "SwHistoryChangeFlyAnchor: no ContentNode");
936cdf0e10cSrcweir             if (pCNd)
937cdf0e10cSrcweir             {
938cdf0e10cSrcweir                 aPos.nContent.Assign( pCNd, m_nOldContentIndex );
939cdf0e10cSrcweir             }
940cdf0e10cSrcweir         }
941cdf0e10cSrcweir         aTmp.SetAnchor( &aPos );
942cdf0e10cSrcweir 
943cdf0e10cSrcweir         // so the Layout does not get confused
944cdf0e10cSrcweir         if ( !pCNd || !pCNd->getLayoutFrm( pDoc->GetCurrentLayout(), 0, 0, sal_False ) )
945cdf0e10cSrcweir         {
946cdf0e10cSrcweir             m_rFmt.DelFrms();
947cdf0e10cSrcweir         }
948cdf0e10cSrcweir 
949cdf0e10cSrcweir         m_rFmt.SetFmtAttr( aTmp );
950cdf0e10cSrcweir     }
951cdf0e10cSrcweir }
952cdf0e10cSrcweir 
953cdf0e10cSrcweir 
954cdf0e10cSrcweir /*************************************************************************/
955cdf0e10cSrcweir 
SwHistoryChangeFlyChain(SwFlyFrmFmt & rFmt,const SwFmtChain & rAttr)956cdf0e10cSrcweir SwHistoryChangeFlyChain::SwHistoryChangeFlyChain( SwFlyFrmFmt& rFmt,
957cdf0e10cSrcweir                                         const SwFmtChain& rAttr )
958cdf0e10cSrcweir     : SwHistoryHint( HSTRY_CHGFLYCHAIN )
959cdf0e10cSrcweir     , m_pPrevFmt( rAttr.GetPrev() )
960cdf0e10cSrcweir     , m_pNextFmt( rAttr.GetNext() )
961cdf0e10cSrcweir     , m_pFlyFmt( &rFmt )
962cdf0e10cSrcweir {
963cdf0e10cSrcweir }
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)966cdf0e10cSrcweir void SwHistoryChangeFlyChain::SetInDoc( SwDoc* pDoc, bool )
967cdf0e10cSrcweir {
968cdf0e10cSrcweir     if ( USHRT_MAX != pDoc->GetSpzFrmFmts()->GetPos( m_pFlyFmt ) )
969cdf0e10cSrcweir     {
970cdf0e10cSrcweir         SwFmtChain aChain;
971cdf0e10cSrcweir 
972cdf0e10cSrcweir         if ( m_pPrevFmt &&
973cdf0e10cSrcweir              USHRT_MAX != pDoc->GetSpzFrmFmts()->GetPos( m_pPrevFmt ) )
974cdf0e10cSrcweir         {
975cdf0e10cSrcweir             aChain.SetPrev( m_pPrevFmt );
976cdf0e10cSrcweir             SwFmtChain aTmp( m_pPrevFmt->GetChain() );
977cdf0e10cSrcweir             aTmp.SetNext( m_pFlyFmt );
978cdf0e10cSrcweir             m_pPrevFmt->SetFmtAttr( aTmp );
979cdf0e10cSrcweir         }
980cdf0e10cSrcweir 
981cdf0e10cSrcweir         if ( m_pNextFmt &&
982cdf0e10cSrcweir              USHRT_MAX != pDoc->GetSpzFrmFmts()->GetPos( m_pNextFmt ) )
983cdf0e10cSrcweir         {
984cdf0e10cSrcweir             aChain.SetNext( m_pNextFmt );
985cdf0e10cSrcweir             SwFmtChain aTmp( m_pNextFmt->GetChain() );
986cdf0e10cSrcweir             aTmp.SetPrev( m_pFlyFmt );
987cdf0e10cSrcweir             m_pNextFmt->SetFmtAttr( aTmp );
988cdf0e10cSrcweir         }
989cdf0e10cSrcweir 
990cdf0e10cSrcweir         if ( aChain.GetNext() || aChain.GetPrev() )
991cdf0e10cSrcweir         {
992cdf0e10cSrcweir             m_pFlyFmt->SetFmtAttr( aChain );
993cdf0e10cSrcweir         }
994cdf0e10cSrcweir     }
995cdf0e10cSrcweir }
996cdf0e10cSrcweir 
997cdf0e10cSrcweir 
998cdf0e10cSrcweir // -> #i27615#
SwHistoryChangeCharFmt(const SfxItemSet & rSet,const String & sFmt)999cdf0e10cSrcweir SwHistoryChangeCharFmt::SwHistoryChangeCharFmt(const SfxItemSet & rSet,
1000cdf0e10cSrcweir                                      const String & sFmt)
1001cdf0e10cSrcweir     : SwHistoryHint(HSTRY_CHGCHARFMT)
1002cdf0e10cSrcweir     , m_OldSet(rSet), m_Fmt(sFmt)
1003cdf0e10cSrcweir {
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir 
SetInDoc(SwDoc * pDoc,bool)1006cdf0e10cSrcweir void SwHistoryChangeCharFmt::SetInDoc(SwDoc * pDoc, bool )
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir     SwCharFmt * pCharFmt = pDoc->FindCharFmtByName(m_Fmt);
1009cdf0e10cSrcweir 
1010cdf0e10cSrcweir     if (pCharFmt)
1011cdf0e10cSrcweir     {
1012cdf0e10cSrcweir         pCharFmt->SetFmtAttr(m_OldSet);
1013cdf0e10cSrcweir     }
1014cdf0e10cSrcweir }
1015cdf0e10cSrcweir // <- #i27615#
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir /*  */
1018cdf0e10cSrcweir 
1019cdf0e10cSrcweir 
SwHistory(sal_uInt16 nInitSz,sal_uInt16 nGrowSz)1020cdf0e10cSrcweir SwHistory::SwHistory( sal_uInt16 nInitSz, sal_uInt16 nGrowSz )
1021cdf0e10cSrcweir     : m_SwpHstry( (sal_uInt8)nInitSz, (sal_uInt8)nGrowSz )
1022cdf0e10cSrcweir     , m_nEndDiff( 0 )
1023cdf0e10cSrcweir {}
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 
~SwHistory()1026cdf0e10cSrcweir SwHistory::~SwHistory()
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir 	Delete( 0 );
1029cdf0e10cSrcweir }
1030cdf0e10cSrcweir 
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir /*************************************************************************
1033cdf0e10cSrcweir |*
1034cdf0e10cSrcweir |*    void SwHistory::Add()
1035cdf0e10cSrcweir |*
1036cdf0e10cSrcweir |*    Beschreibung		Dokument 1.0
1037cdf0e10cSrcweir |*    Ersterstellung    JP 18.02.91
1038cdf0e10cSrcweir |*    Letzte Aenderung  JP 18.02.91
1039cdf0e10cSrcweir |*
1040cdf0e10cSrcweir *************************************************************************/
1041cdf0e10cSrcweir 
Add(const SfxPoolItem * pOldValue,const SfxPoolItem * pNewValue,sal_uLong nNodeIdx)1042cdf0e10cSrcweir void SwHistory::Add( const SfxPoolItem* pOldValue, const SfxPoolItem* pNewValue,
1043cdf0e10cSrcweir                      sal_uLong nNodeIdx )
1044cdf0e10cSrcweir {
1045cdf0e10cSrcweir     ASSERT( !m_nEndDiff, "History was not deleted after REDO" );
1046cdf0e10cSrcweir 
104769a74367SOliver-Rainer Wittmann     sal_uInt16 nWhich = pNewValue->Which();
1048*dec99bbdSOliver-Rainer Wittmann     if( (nWhich >= POOLATTR_END)
1049*dec99bbdSOliver-Rainer Wittmann         || (nWhich == RES_TXTATR_FIELD)
1050*dec99bbdSOliver-Rainer Wittmann         || (nWhich == RES_TXTATR_ANNOTATION) )
105169a74367SOliver-Rainer Wittmann         return;
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir     // no default Attribute?
1054cdf0e10cSrcweir     SwHistoryHint * pHt;
1055cdf0e10cSrcweir     if ( pOldValue && pOldValue != GetDfltAttr( pOldValue->Which() ) )
1056cdf0e10cSrcweir     {
1057cdf0e10cSrcweir         pHt = new SwHistorySetFmt( pOldValue, nNodeIdx );
1058cdf0e10cSrcweir     }
1059cdf0e10cSrcweir     else
1060cdf0e10cSrcweir     {
1061cdf0e10cSrcweir         pHt = new SwHistoryResetFmt( pNewValue, nNodeIdx );
1062cdf0e10cSrcweir     }
1063cdf0e10cSrcweir     m_SwpHstry.Insert( pHt, Count() );
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir 
Add(SwTxtAttr * pHint,sal_uLong nNodeIdx,bool bNewAttr)1067cdf0e10cSrcweir void SwHistory::Add( SwTxtAttr* pHint, sal_uLong nNodeIdx, bool bNewAttr )
1068cdf0e10cSrcweir {
1069cdf0e10cSrcweir     ASSERT( !m_nEndDiff, "History was not deleted after REDO" );
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir     SwHistoryHint * pHt;
1072cdf0e10cSrcweir 	sal_uInt16 nAttrWhich = pHint->Which();
1073cdf0e10cSrcweir 
1074cdf0e10cSrcweir 	if( !bNewAttr )
1075cdf0e10cSrcweir 	{
1076cdf0e10cSrcweir 		switch ( nAttrWhich )
1077cdf0e10cSrcweir         {
1078cdf0e10cSrcweir             case RES_TXTATR_FTN:
1079cdf0e10cSrcweir                 pHt = new SwHistorySetFootnote(
1080cdf0e10cSrcweir                             static_cast<SwTxtFtn*>(pHint), nNodeIdx );
1081cdf0e10cSrcweir                 break;
1082cdf0e10cSrcweir             case RES_TXTATR_FLYCNT:
1083cdf0e10cSrcweir                 pHt = new SwHistoryTxtFlyCnt( static_cast<SwTxtFlyCnt*>(pHint)
1084cdf0e10cSrcweir                             ->GetFlyCnt().GetFrmFmt() );
1085cdf0e10cSrcweir                 break;
1086cdf0e10cSrcweir             case RES_TXTATR_FIELD:
1087*dec99bbdSOliver-Rainer Wittmann             case RES_TXTATR_ANNOTATION:
1088cdf0e10cSrcweir                 pHt = new SwHistorySetTxtFld(
1089cdf0e10cSrcweir                             static_cast<SwTxtFld*>(pHint), nNodeIdx );
1090cdf0e10cSrcweir                 break;
1091cdf0e10cSrcweir             case RES_TXTATR_TOXMARK:
1092cdf0e10cSrcweir                 pHt = new SwHistorySetTOXMark(
1093cdf0e10cSrcweir                             static_cast<SwTxtTOXMark*>(pHint), nNodeIdx );
1094cdf0e10cSrcweir                 break;
1095cdf0e10cSrcweir             case RES_TXTATR_REFMARK:
1096cdf0e10cSrcweir                 pHt = new SwHistorySetRefMark(
1097cdf0e10cSrcweir                             static_cast<SwTxtRefMark*>(pHint), nNodeIdx );
1098cdf0e10cSrcweir                 break;
1099cdf0e10cSrcweir             default:
1100cdf0e10cSrcweir                 pHt = new SwHistorySetTxt(
1101cdf0e10cSrcweir                             static_cast<SwTxtAttr*>(pHint), nNodeIdx );
1102cdf0e10cSrcweir         }
1103cdf0e10cSrcweir     }
1104cdf0e10cSrcweir     else
1105cdf0e10cSrcweir     {
1106cdf0e10cSrcweir         pHt = new SwHistoryResetTxt( pHint->Which(), *pHint->GetStart(),
1107cdf0e10cSrcweir                                     *pHint->GetAnyEnd(), nNodeIdx );
1108cdf0e10cSrcweir     }
1109cdf0e10cSrcweir     m_SwpHstry.Insert( pHt, Count() );
1110cdf0e10cSrcweir }
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir 
Add(SwFmtColl * pColl,sal_uLong nNodeIdx,sal_uInt8 nWhichNd)1113cdf0e10cSrcweir void SwHistory::Add( SwFmtColl* pColl, sal_uLong nNodeIdx, sal_uInt8 nWhichNd )
1114cdf0e10cSrcweir {
1115cdf0e10cSrcweir     ASSERT( !m_nEndDiff, "History was not deleted after REDO" );
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir     SwHistoryHint * pHt =
1118cdf0e10cSrcweir         new SwHistoryChangeFmtColl( pColl, nNodeIdx, nWhichNd );
1119cdf0e10cSrcweir     m_SwpHstry.Insert( pHt, Count() );
1120cdf0e10cSrcweir }
1121cdf0e10cSrcweir 
1122cdf0e10cSrcweir 
Add(const::sw::mark::IMark & rBkmk,bool bSavePos,bool bSaveOtherPos)1123cdf0e10cSrcweir void SwHistory::Add(const ::sw::mark::IMark& rBkmk, bool bSavePos, bool bSaveOtherPos)
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir     ASSERT( !m_nEndDiff, "History was not deleted after REDO" );
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir     SwHistoryHint * pHt = new SwHistoryBookmark(rBkmk, bSavePos, bSaveOtherPos);
1128cdf0e10cSrcweir     m_SwpHstry.Insert( pHt, Count() );
1129cdf0e10cSrcweir }
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 
Add(SwFrmFmt & rFmt)1132cdf0e10cSrcweir void SwHistory::Add( SwFrmFmt& rFmt )
1133cdf0e10cSrcweir {
1134cdf0e10cSrcweir     SwHistoryHint * pHt = new SwHistoryChangeFlyAnchor( rFmt );
1135cdf0e10cSrcweir     m_SwpHstry.Insert( pHt, Count() );
1136cdf0e10cSrcweir }
1137cdf0e10cSrcweir 
Add(SwFlyFrmFmt & rFmt,sal_uInt16 & rSetPos)1138cdf0e10cSrcweir void SwHistory::Add( SwFlyFrmFmt& rFmt, sal_uInt16& rSetPos )
1139cdf0e10cSrcweir {
1140cdf0e10cSrcweir     ASSERT( !m_nEndDiff, "History was not deleted after REDO" );
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 	SwHistoryHint * pHint;
1143cdf0e10cSrcweir 	const sal_uInt16 nWh = rFmt.Which();
1144cdf0e10cSrcweir 	if( RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh )
1145cdf0e10cSrcweir     {
1146cdf0e10cSrcweir         pHint = new SwHistoryTxtFlyCnt( &rFmt );
1147cdf0e10cSrcweir         m_SwpHstry.Insert( pHint, Count() );
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir 		const SwFmtChain* pChainItem;
1150cdf0e10cSrcweir 		if( SFX_ITEM_SET == rFmt.GetItemState( RES_CHAIN, sal_False,
1151cdf0e10cSrcweir 			(const SfxPoolItem**)&pChainItem ))
1152cdf0e10cSrcweir 		{
1153cdf0e10cSrcweir 			if( pChainItem->GetNext() || pChainItem->GetPrev() )
1154cdf0e10cSrcweir             {
1155cdf0e10cSrcweir                 SwHistoryHint * pHt =
1156cdf0e10cSrcweir                     new SwHistoryChangeFlyChain( rFmt, *pChainItem );
1157cdf0e10cSrcweir                 m_SwpHstry.Insert( pHt, rSetPos++ );
1158cdf0e10cSrcweir 				if ( pChainItem->GetNext() )
1159cdf0e10cSrcweir 				{
1160cdf0e10cSrcweir 					SwFmtChain aTmp( pChainItem->GetNext()->GetChain() );
1161cdf0e10cSrcweir 					aTmp.SetPrev( 0 );
1162cdf0e10cSrcweir                     pChainItem->GetNext()->SetFmtAttr( aTmp );
1163cdf0e10cSrcweir 				}
1164cdf0e10cSrcweir 				if ( pChainItem->GetPrev() )
1165cdf0e10cSrcweir 				{
1166cdf0e10cSrcweir 					SwFmtChain aTmp( pChainItem->GetPrev()->GetChain() );
1167cdf0e10cSrcweir 					aTmp.SetNext( 0 );
1168cdf0e10cSrcweir                     pChainItem->GetPrev()->SetFmtAttr( aTmp );
1169cdf0e10cSrcweir                 }
1170cdf0e10cSrcweir             }
1171cdf0e10cSrcweir             rFmt.ResetFmtAttr( RES_CHAIN );
1172cdf0e10cSrcweir         }
1173cdf0e10cSrcweir     }
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir 
Add(const SwTxtFtn & rFtn)1176cdf0e10cSrcweir void SwHistory::Add( const SwTxtFtn& rFtn )
1177cdf0e10cSrcweir {
1178cdf0e10cSrcweir     SwHistoryHint *pHt = new SwHistorySetFootnote( rFtn );
1179cdf0e10cSrcweir     m_SwpHstry.Insert( pHt, Count() );
1180cdf0e10cSrcweir }
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir // #i27615#
Add(const SfxItemSet & rSet,const SwCharFmt & rFmt)1183cdf0e10cSrcweir void SwHistory::Add(const SfxItemSet & rSet, const SwCharFmt & rFmt)
1184cdf0e10cSrcweir {
1185cdf0e10cSrcweir     SwHistoryHint * pHt = new SwHistoryChangeCharFmt(rSet, rFmt.GetName());
1186cdf0e10cSrcweir     m_SwpHstry.Insert(pHt, Count());
1187cdf0e10cSrcweir }
1188cdf0e10cSrcweir 
1189cdf0e10cSrcweir /*************************************************************************
1190cdf0e10cSrcweir |*
1191cdf0e10cSrcweir |*    sal_Bool SwHistory::Rollback()
1192cdf0e10cSrcweir |*
1193cdf0e10cSrcweir |*    Beschreibung		Dokument 1.0
1194cdf0e10cSrcweir |*    Ersterstellung    JP 18.02.91
1195cdf0e10cSrcweir |*    Letzte Aenderung  JP 18.02.91
1196cdf0e10cSrcweir |*
1197cdf0e10cSrcweir *************************************************************************/
1198cdf0e10cSrcweir 
1199cdf0e10cSrcweir 
Rollback(SwDoc * pDoc,sal_uInt16 nStart)1200cdf0e10cSrcweir bool SwHistory::Rollback( SwDoc* pDoc, sal_uInt16 nStart )
1201cdf0e10cSrcweir {
1202cdf0e10cSrcweir     if ( !Count() )
1203cdf0e10cSrcweir         return false;
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir     SwHistoryHint * pHHt;
1206cdf0e10cSrcweir     sal_uInt16 i;
1207cdf0e10cSrcweir     for ( i = Count(); i > nStart ; )
1208cdf0e10cSrcweir     {
1209cdf0e10cSrcweir         pHHt = m_SwpHstry[ --i ];
1210cdf0e10cSrcweir         pHHt->SetInDoc( pDoc, false );
1211cdf0e10cSrcweir         delete pHHt;
1212cdf0e10cSrcweir     }
1213cdf0e10cSrcweir     m_SwpHstry.Remove( nStart, Count() - nStart );
1214cdf0e10cSrcweir     m_nEndDiff = 0;
1215cdf0e10cSrcweir     return true;
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir 
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir 
TmpRollback(SwDoc * pDoc,sal_uInt16 nStart,bool bToFirst)1220cdf0e10cSrcweir bool SwHistory::TmpRollback( SwDoc* pDoc, sal_uInt16 nStart, bool bToFirst )
1221cdf0e10cSrcweir {
1222cdf0e10cSrcweir     sal_uInt16 nEnd = Count() - m_nEndDiff;
1223cdf0e10cSrcweir     if ( !Count() || !nEnd || nStart >= nEnd )
1224cdf0e10cSrcweir         return false;
1225cdf0e10cSrcweir 
1226cdf0e10cSrcweir     SwHistoryHint * pHHt;
1227cdf0e10cSrcweir     if ( bToFirst )
1228cdf0e10cSrcweir     {
1229cdf0e10cSrcweir         for ( ; nEnd > nStart; ++m_nEndDiff )
1230cdf0e10cSrcweir         {
1231cdf0e10cSrcweir             pHHt = m_SwpHstry[ --nEnd ];
1232cdf0e10cSrcweir             pHHt->SetInDoc( pDoc, true );
1233cdf0e10cSrcweir         }
1234cdf0e10cSrcweir     }
1235cdf0e10cSrcweir     else
1236cdf0e10cSrcweir     {
1237cdf0e10cSrcweir         for ( ; nStart < nEnd; ++m_nEndDiff, ++nStart )
1238cdf0e10cSrcweir         {
1239cdf0e10cSrcweir             pHHt = m_SwpHstry[ nStart ];
1240cdf0e10cSrcweir             pHHt->SetInDoc( pDoc, true );
1241cdf0e10cSrcweir         }
1242cdf0e10cSrcweir     }
1243cdf0e10cSrcweir     return true;
1244cdf0e10cSrcweir }
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 
Delete(sal_uInt16 nStart)1247cdf0e10cSrcweir void SwHistory::Delete( sal_uInt16 nStart )
1248cdf0e10cSrcweir {
1249cdf0e10cSrcweir     for ( sal_uInt16 n = Count(); n > nStart; )
1250cdf0e10cSrcweir     {
1251cdf0e10cSrcweir         m_SwpHstry.DeleteAndDestroy( --n, 1 );
1252cdf0e10cSrcweir     }
1253cdf0e10cSrcweir     m_nEndDiff = 0;
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir 
SetTmpEnd(sal_uInt16 nNewTmpEnd)1257cdf0e10cSrcweir sal_uInt16 SwHistory::SetTmpEnd( sal_uInt16 nNewTmpEnd )
1258cdf0e10cSrcweir {
1259cdf0e10cSrcweir     ASSERT( nNewTmpEnd <= Count(),  "SwHistory::SetTmpEnd: out of bounds" );
1260cdf0e10cSrcweir 
1261cdf0e10cSrcweir     sal_uInt16 nOld = Count() - m_nEndDiff;
1262cdf0e10cSrcweir     m_nEndDiff = Count() - nNewTmpEnd;
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir     // for every SwHistoryFlyCnt, call the Redo of its UndoObject.
1265cdf0e10cSrcweir     // this saves the formats of the flys!
1266cdf0e10cSrcweir     for ( sal_uInt16 n = nOld; n < nNewTmpEnd; n++ )
1267cdf0e10cSrcweir     {
1268cdf0e10cSrcweir         if ( HSTRY_FLYCNT == (*this)[ n ]->Which() )
1269cdf0e10cSrcweir         {
1270cdf0e10cSrcweir             static_cast<SwHistoryTxtFlyCnt*>((*this)[ n ])
1271cdf0e10cSrcweir                 ->GetUDelLFmt()->RedoForRollback();
1272cdf0e10cSrcweir         }
1273cdf0e10cSrcweir     }
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir     return nOld;
1276cdf0e10cSrcweir }
1277cdf0e10cSrcweir 
CopyFmtAttr(const SfxItemSet & rSet,sal_uLong nNodeIdx)1278cdf0e10cSrcweir void SwHistory::CopyFmtAttr( const SfxItemSet& rSet, sal_uLong nNodeIdx )
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir 	if( rSet.Count() )
1281cdf0e10cSrcweir 	{
1282cdf0e10cSrcweir 		SfxItemIter aIter( rSet );
1283cdf0e10cSrcweir 		do {
1284cdf0e10cSrcweir 			if( (SfxPoolItem*)-1 != aIter.GetCurItem() )
1285cdf0e10cSrcweir 			{
1286cdf0e10cSrcweir 				const SfxPoolItem* pNew = aIter.GetCurItem();
1287cdf0e10cSrcweir                 Add( pNew, pNew, nNodeIdx );
1288cdf0e10cSrcweir 			}
1289cdf0e10cSrcweir 			if( aIter.IsAtEnd() )
1290cdf0e10cSrcweir 				break;
1291cdf0e10cSrcweir 			aIter.NextItem();
1292cdf0e10cSrcweir 		} while( sal_True );
1293cdf0e10cSrcweir 	}
1294cdf0e10cSrcweir }
1295cdf0e10cSrcweir 
CopyAttr(SwpHints * pHts,const sal_uLong nNodeIdx,const xub_StrLen nStart,const xub_StrLen nEnd,const bool bCopyFields)129669a74367SOliver-Rainer Wittmann void SwHistory::CopyAttr(
129769a74367SOliver-Rainer Wittmann     SwpHints* pHts,
129869a74367SOliver-Rainer Wittmann     const sal_uLong nNodeIdx,
129969a74367SOliver-Rainer Wittmann     const xub_StrLen nStart,
130069a74367SOliver-Rainer Wittmann     const xub_StrLen nEnd,
130169a74367SOliver-Rainer Wittmann     const bool bCopyFields )
1302cdf0e10cSrcweir {
1303cdf0e10cSrcweir 	if( !pHts  )
1304cdf0e10cSrcweir 		return;
1305cdf0e10cSrcweir 
1306cdf0e10cSrcweir     // copy all attributes of the TextNode in the area from nStart to nEnd
1307cdf0e10cSrcweir     SwTxtAttr* pHt;
130869a74367SOliver-Rainer Wittmann     xub_StrLen nAttrStt;
130969a74367SOliver-Rainer Wittmann     const xub_StrLen * pEndIdx;
131069a74367SOliver-Rainer Wittmann     for( sal_uInt16 n = 0; n < pHts->Count(); n++ )
131169a74367SOliver-Rainer Wittmann     {
1312cdf0e10cSrcweir         pHt = pHts->GetTextHint(n);
1313cdf0e10cSrcweir         nAttrStt = *pHt->GetStart();
131469a74367SOliver-Rainer Wittmann         if( 0 != ( pEndIdx = pHt->GetEnd() ) && nAttrStt > nEnd )
131569a74367SOliver-Rainer Wittmann             break;
1316cdf0e10cSrcweir 
131769a74367SOliver-Rainer Wittmann         // Flys und Ftn nie kopieren !!
131869a74367SOliver-Rainer Wittmann         sal_Bool bNextAttr = sal_False;
131969a74367SOliver-Rainer Wittmann         switch( pHt->Which() )
132069a74367SOliver-Rainer Wittmann         {
132169a74367SOliver-Rainer Wittmann         case RES_TXTATR_FIELD:
1322*dec99bbdSOliver-Rainer Wittmann         case RES_TXTATR_ANNOTATION:
132369a74367SOliver-Rainer Wittmann         case RES_TXTATR_INPUTFIELD:
132469a74367SOliver-Rainer Wittmann             if( !bCopyFields )
132569a74367SOliver-Rainer Wittmann                 bNextAttr = sal_True;
132669a74367SOliver-Rainer Wittmann             break;
132769a74367SOliver-Rainer Wittmann         case RES_TXTATR_FLYCNT:
132869a74367SOliver-Rainer Wittmann         case RES_TXTATR_FTN:
132969a74367SOliver-Rainer Wittmann             bNextAttr = sal_True;
133069a74367SOliver-Rainer Wittmann             break;
133169a74367SOliver-Rainer Wittmann         }
1332cdf0e10cSrcweir 
133369a74367SOliver-Rainer Wittmann         if( bNextAttr )
133469a74367SOliver-Rainer Wittmann             continue;
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir         // save all attributes that are somehow in this area
1337cdf0e10cSrcweir         if ( nStart <= nAttrStt )
1338cdf0e10cSrcweir         {
133969a74367SOliver-Rainer Wittmann             if ( nEnd > nAttrStt )
1340cdf0e10cSrcweir             {
1341cdf0e10cSrcweir                 Add( pHt, nNodeIdx, false );
1342cdf0e10cSrcweir             }
1343cdf0e10cSrcweir         }
1344cdf0e10cSrcweir         else if ( pEndIdx && nStart < *pEndIdx )
1345cdf0e10cSrcweir         {
1346cdf0e10cSrcweir             Add( pHt, nNodeIdx, false );
1347cdf0e10cSrcweir         }
1348cdf0e10cSrcweir     }
1349cdf0e10cSrcweir }
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir 
1352cdf0e10cSrcweir /*************************************************************************/
1353cdf0e10cSrcweir 
1354cdf0e10cSrcweir // Klasse zum Registrieren der History am Node, Format, HintsArray, ...
1355cdf0e10cSrcweir 
SwRegHistory(SwHistory * pHst)1356cdf0e10cSrcweir SwRegHistory::SwRegHistory( SwHistory* pHst )
1357cdf0e10cSrcweir     : SwClient( 0 )
1358cdf0e10cSrcweir     , m_pHistory( pHst )
1359cdf0e10cSrcweir     , m_nNodeIndex( ULONG_MAX )
1360cdf0e10cSrcweir {
1361cdf0e10cSrcweir     _MakeSetWhichIds();
1362cdf0e10cSrcweir }
1363cdf0e10cSrcweir 
SwRegHistory(SwModify * pRegIn,const SwNode & rNd,SwHistory * pHst)1364cdf0e10cSrcweir SwRegHistory::SwRegHistory( SwModify* pRegIn, const SwNode& rNd,
1365cdf0e10cSrcweir                             SwHistory* pHst )
1366cdf0e10cSrcweir     : SwClient( pRegIn )
1367cdf0e10cSrcweir     , m_pHistory( pHst )
1368cdf0e10cSrcweir     , m_nNodeIndex( rNd.GetIndex() )
1369cdf0e10cSrcweir {
1370cdf0e10cSrcweir     _MakeSetWhichIds();
1371cdf0e10cSrcweir }
1372cdf0e10cSrcweir 
SwRegHistory(const SwNode & rNd,SwHistory * pHst)1373cdf0e10cSrcweir SwRegHistory::SwRegHistory( const SwNode& rNd, SwHistory* pHst )
1374cdf0e10cSrcweir     : SwClient( 0 )
1375cdf0e10cSrcweir     , m_pHistory( pHst )
1376cdf0e10cSrcweir     , m_nNodeIndex( rNd.GetIndex() )
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir     _MakeSetWhichIds();
1379cdf0e10cSrcweir }
1380cdf0e10cSrcweir 
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)1381cdf0e10cSrcweir void SwRegHistory::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
1382cdf0e10cSrcweir {
1383cdf0e10cSrcweir     // --> OD 2010-10-05 #i114861#
1384cdf0e10cSrcweir     // Do not handle a "noop" modify
1385cdf0e10cSrcweir     // - e.g. <SwTxtNode::NumRuleChgd()> uses such a "noop" modify
1386cdf0e10cSrcweir //    if ( m_pHistory && ( pOld || pNew ) )
1387cdf0e10cSrcweir     if ( m_pHistory && ( pOld || pNew ) &&
1388cdf0e10cSrcweir          pOld != pNew )
1389cdf0e10cSrcweir     // <--
1390cdf0e10cSrcweir     {
1391cdf0e10cSrcweir         if ( pNew->Which() < POOLATTR_END )
1392cdf0e10cSrcweir         {
1393cdf0e10cSrcweir             m_pHistory->Add( pOld, pNew, m_nNodeIndex );
1394cdf0e10cSrcweir         }
1395cdf0e10cSrcweir         else if ( RES_ATTRSET_CHG == pNew->Which() )
1396cdf0e10cSrcweir         {
1397cdf0e10cSrcweir             SwHistoryHint* pNewHstr;
1398cdf0e10cSrcweir             const SfxItemSet& rSet =
1399cdf0e10cSrcweir                 *static_cast<const SwAttrSetChg*>(pOld)->GetChgSet();
1400cdf0e10cSrcweir             if ( 1 < rSet.Count() )
1401cdf0e10cSrcweir             {
1402cdf0e10cSrcweir                 pNewHstr =
1403cdf0e10cSrcweir                     new SwHistorySetAttrSet( rSet, m_nNodeIndex, m_WhichIdSet );
1404cdf0e10cSrcweir             }
1405cdf0e10cSrcweir             else
1406cdf0e10cSrcweir             {
1407cdf0e10cSrcweir                 const SfxPoolItem* pItem = SfxItemIter( rSet ).FirstItem();
1408cdf0e10cSrcweir                 if ( m_WhichIdSet.Seek_Entry( pItem->Which() ) )
1409cdf0e10cSrcweir                 {
1410cdf0e10cSrcweir                     pNewHstr = new SwHistorySetFmt( pItem, m_nNodeIndex );
1411cdf0e10cSrcweir                 }
1412cdf0e10cSrcweir                 else
1413cdf0e10cSrcweir                 {
1414cdf0e10cSrcweir                     pNewHstr = new SwHistoryResetFmt( pItem, m_nNodeIndex );
1415cdf0e10cSrcweir                 }
1416cdf0e10cSrcweir             }
1417cdf0e10cSrcweir             m_pHistory->m_SwpHstry.Insert( pNewHstr, m_pHistory->Count() );
1418cdf0e10cSrcweir         }
1419cdf0e10cSrcweir     }
1420cdf0e10cSrcweir }
1421cdf0e10cSrcweir 
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir 
AddHint(SwTxtAttr * pHt,const bool bNew)1424cdf0e10cSrcweir void SwRegHistory::AddHint( SwTxtAttr* pHt, const bool bNew )
1425cdf0e10cSrcweir {
1426cdf0e10cSrcweir     m_pHistory->Add( pHt, m_nNodeIndex, bNew );
1427cdf0e10cSrcweir }
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir 
InsertItems(const SfxItemSet & rSet,xub_StrLen const nStart,xub_StrLen const nEnd,SetAttrMode const nFlags)1430cdf0e10cSrcweir bool SwRegHistory::InsertItems( const SfxItemSet& rSet,
1431cdf0e10cSrcweir     xub_StrLen const nStart, xub_StrLen const nEnd, SetAttrMode const nFlags )
1432cdf0e10cSrcweir {
1433cdf0e10cSrcweir 	if( !rSet.Count() )
1434cdf0e10cSrcweir         return false;
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir     SwTxtNode * const pTxtNode =
1437cdf0e10cSrcweir         dynamic_cast<SwTxtNode *>(const_cast<SwModify *>(GetRegisteredIn()));
1438cdf0e10cSrcweir 
1439cdf0e10cSrcweir     ASSERT(pTxtNode, "SwRegHistory not registered at text node?");
1440cdf0e10cSrcweir     if (!pTxtNode)
1441cdf0e10cSrcweir         return false;
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir     if ( pTxtNode->GetpSwpHints() && m_pHistory )
1444cdf0e10cSrcweir     {
1445cdf0e10cSrcweir         pTxtNode->GetpSwpHints()->Register( this );
1446cdf0e10cSrcweir     }
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir     const bool bInserted = pTxtNode->SetAttr( rSet, nStart, nEnd, nFlags );
1449cdf0e10cSrcweir 
1450cdf0e10cSrcweir 		// Achtung: Durch das Einfuegen eines Attributs kann das Array
1451cdf0e10cSrcweir 		// geloescht werden!!! Wenn das einzufuegende zunaechst ein vorhandenes
1452cdf0e10cSrcweir 		// loescht, selbst aber nicht eingefuegt werden braucht, weil die
1453cdf0e10cSrcweir 		// Absatzattribute identisch sind( -> bForgetAttr in SwpHints::Insert )
1454cdf0e10cSrcweir     if ( pTxtNode->GetpSwpHints() && m_pHistory )
1455cdf0e10cSrcweir     {
1456cdf0e10cSrcweir         pTxtNode->GetpSwpHints()->DeRegister();
1457cdf0e10cSrcweir     }
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir     if ( m_pHistory && bInserted )
1460cdf0e10cSrcweir     {
1461cdf0e10cSrcweir         SwHistoryHint* pNewHstr = new SwHistoryResetAttrSet( rSet,
1462cdf0e10cSrcweir                                     pTxtNode->GetIndex(), nStart, nEnd );
1463cdf0e10cSrcweir 		// der NodeIndex kann verschoben sein !!
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir         m_pHistory->m_SwpHstry.Insert( pNewHstr, m_pHistory->Count() );
1466cdf0e10cSrcweir     }
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir     return bInserted;
1469cdf0e10cSrcweir }
1470cdf0e10cSrcweir 
RegisterInModify(SwModify * pRegIn,const SwNode & rNd)1471cdf0e10cSrcweir void SwRegHistory::RegisterInModify( SwModify* pRegIn, const SwNode& rNd )
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir     if ( m_pHistory && pRegIn )
1474cdf0e10cSrcweir     {
1475cdf0e10cSrcweir         pRegIn->Add( this );
1476cdf0e10cSrcweir         m_nNodeIndex = rNd.GetIndex();
1477cdf0e10cSrcweir         _MakeSetWhichIds();
1478cdf0e10cSrcweir     }
1479cdf0e10cSrcweir     else if ( m_WhichIdSet.Count() )
1480cdf0e10cSrcweir     {
1481cdf0e10cSrcweir         m_WhichIdSet.Remove( 0, m_WhichIdSet.Count() );
1482cdf0e10cSrcweir     }
1483cdf0e10cSrcweir }
1484cdf0e10cSrcweir 
_MakeSetWhichIds()1485cdf0e10cSrcweir void SwRegHistory::_MakeSetWhichIds()
1486cdf0e10cSrcweir {
1487cdf0e10cSrcweir     if (!m_pHistory) return;
1488cdf0e10cSrcweir 
1489cdf0e10cSrcweir     if ( m_WhichIdSet.Count() )
1490cdf0e10cSrcweir     {
1491cdf0e10cSrcweir         m_WhichIdSet.Remove( 0, m_WhichIdSet.Count() );
1492cdf0e10cSrcweir     }
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir 	if( GetRegisteredIn() )
1495cdf0e10cSrcweir 	{
1496cdf0e10cSrcweir 		const SfxItemSet* pSet = 0;
1497cdf0e10cSrcweir 		if( GetRegisteredIn()->ISA( SwCntntNode ) )
1498cdf0e10cSrcweir         {
1499cdf0e10cSrcweir             pSet = static_cast<SwCntntNode*>(
1500cdf0e10cSrcweir                     const_cast<SwModify*>(GetRegisteredIn()))->GetpSwAttrSet();
1501cdf0e10cSrcweir         }
1502cdf0e10cSrcweir         else if ( GetRegisteredIn()->ISA( SwFmt ) )
1503cdf0e10cSrcweir         {
1504cdf0e10cSrcweir             pSet = &static_cast<SwFmt*>(
1505cdf0e10cSrcweir                     const_cast<SwModify*>(GetRegisteredIn()))->GetAttrSet();
1506cdf0e10cSrcweir         }
1507cdf0e10cSrcweir 		if( pSet && pSet->Count() )
1508cdf0e10cSrcweir 		{
1509cdf0e10cSrcweir 			SfxItemIter aIter( *pSet );
1510cdf0e10cSrcweir 			sal_uInt16 nW = aIter.FirstItem()->Which();
1511cdf0e10cSrcweir 			while( sal_True )
1512cdf0e10cSrcweir 			{
1513cdf0e10cSrcweir 				m_WhichIdSet.Insert( nW );
1514cdf0e10cSrcweir 				if( aIter.IsAtEnd() )
1515cdf0e10cSrcweir 					break;
1516cdf0e10cSrcweir 				nW = aIter.NextItem()->Which();
1517cdf0e10cSrcweir 			}
1518cdf0e10cSrcweir 		}
1519cdf0e10cSrcweir 	}
1520cdf0e10cSrcweir }
1521cdf0e10cSrcweir 
1522