xref: /aoo41x/main/sw/source/core/undo/unsect.cxx (revision 69a74367)
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 <UndoSection.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <sfx2/linkmgr.hxx>
30cdf0e10cSrcweir #include <fmtcntnt.hxx>
31cdf0e10cSrcweir #include <doc.hxx>
32cdf0e10cSrcweir #include <docary.hxx>
33cdf0e10cSrcweir #include <swundo.hxx>			// fuer die UndoIds
34cdf0e10cSrcweir #include <pam.hxx>
35cdf0e10cSrcweir #include <ndtxt.hxx>
36cdf0e10cSrcweir #include <UndoCore.hxx>
37cdf0e10cSrcweir #include <section.hxx>
38cdf0e10cSrcweir #include <rolbck.hxx>
39cdf0e10cSrcweir #include <redline.hxx>
40cdf0e10cSrcweir #include <doctxm.hxx>
41cdf0e10cSrcweir #include <ftnidx.hxx>
42cdf0e10cSrcweir #include <editsh.hxx>
43cdf0e10cSrcweir /// OD 04.10.2002 #102894#
44cdf0e10cSrcweir /// class Calc needed for calculation of the hidden condition of a section.
45cdf0e10cSrcweir #include <calc.hxx>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
lcl_GetAttrSet(const SwSection & rSect)48cdf0e10cSrcweir SfxItemSet* lcl_GetAttrSet( const SwSection& rSect )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	// Attribute des Formate sichern (Spalten, Farbe, ... )
51cdf0e10cSrcweir 	// Cntnt- und Protect- Items interessieren nicht (stehen schon in der
52cdf0e10cSrcweir 	// Section), muessen also entfernen werden
53cdf0e10cSrcweir 	SfxItemSet* pAttr = 0;
54cdf0e10cSrcweir 	if( rSect.GetFmt() )
55cdf0e10cSrcweir 	{
56cdf0e10cSrcweir 		sal_uInt16 nCnt = 1;
57cdf0e10cSrcweir 		if( rSect.IsProtect() )
58cdf0e10cSrcweir 			++nCnt;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 		if( nCnt < rSect.GetFmt()->GetAttrSet().Count() )
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir 			pAttr = new SfxItemSet( rSect.GetFmt()->GetAttrSet() );
63cdf0e10cSrcweir 			pAttr->ClearItem( RES_PROTECT );
64cdf0e10cSrcweir 			pAttr->ClearItem( RES_CNTNT );
65cdf0e10cSrcweir 			if( !pAttr->Count() )
66cdf0e10cSrcweir 				delete pAttr, pAttr = 0;
67cdf0e10cSrcweir 		}
68cdf0e10cSrcweir 	}
69cdf0e10cSrcweir 	return pAttr;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////
74cdf0e10cSrcweir 
SwUndoInsSection(SwPaM const & rPam,SwSectionData const & rNewData,SfxItemSet const * const pSet,SwTOXBase const * const pTOXBase)75cdf0e10cSrcweir SwUndoInsSection::SwUndoInsSection(
76cdf0e10cSrcweir         SwPaM const& rPam, SwSectionData const& rNewData,
77cdf0e10cSrcweir         SfxItemSet const*const pSet, SwTOXBase const*const pTOXBase)
78cdf0e10cSrcweir     : SwUndo( UNDO_INSSECTION ), SwUndRng( rPam )
79cdf0e10cSrcweir     , m_pSectionData(new SwSectionData(rNewData))
80cdf0e10cSrcweir     , m_pTOXBase( (pTOXBase) ? new SwTOXBase(*pTOXBase) : 0 )
81cdf0e10cSrcweir     , m_pAttrSet( (pSet && pSet->Count()) ? new SfxItemSet( *pSet ) : 0 )
82cdf0e10cSrcweir     , m_pHistory(0)
83cdf0e10cSrcweir     , m_pRedlData(0)
84cdf0e10cSrcweir     , m_nSectionNodePos(0)
85cdf0e10cSrcweir     , m_bSplitAtStart(false)
86cdf0e10cSrcweir     , m_bSplitAtEnd(false)
87cdf0e10cSrcweir     , m_bUpdateFtn(false)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir 	SwDoc& rDoc = *(SwDoc*)rPam.GetDoc();
90cdf0e10cSrcweir 	if( rDoc.IsRedlineOn() )
91cdf0e10cSrcweir     {
92cdf0e10cSrcweir         m_pRedlData.reset(new SwRedlineData( nsRedlineType_t::REDLINE_INSERT,
93cdf0e10cSrcweir                                         rDoc.GetRedlineAuthor() ));
94cdf0e10cSrcweir 		SetRedlineMode( rDoc.GetRedlineMode() );
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	if( !rPam.HasMark() )
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir 		const SwCntntNode* pCNd = rPam.GetPoint()->nNode.GetNode().GetCntntNode();
101cdf0e10cSrcweir         if( pCNd && pCNd->HasSwAttrSet() && (
102cdf0e10cSrcweir 			!rPam.GetPoint()->nContent.GetIndex() ||
103cdf0e10cSrcweir 			rPam.GetPoint()->nContent.GetIndex() == pCNd->Len() ))
104cdf0e10cSrcweir 		{
105cdf0e10cSrcweir 			SfxItemSet aBrkSet( rDoc.GetAttrPool(), aBreakSetRange );
106cdf0e10cSrcweir 			aBrkSet.Put( *pCNd->GetpSwAttrSet() );
107cdf0e10cSrcweir 			if( aBrkSet.Count() )
108cdf0e10cSrcweir             {
109cdf0e10cSrcweir                 m_pHistory.reset( new SwHistory );
110cdf0e10cSrcweir                 m_pHistory->CopyFmtAttr( aBrkSet, pCNd->GetIndex() );
111cdf0e10cSrcweir             }
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
~SwUndoInsSection()116cdf0e10cSrcweir SwUndoInsSection::~SwUndoInsSection()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
UndoImpl(::sw::UndoRedoContext & rContext)120cdf0e10cSrcweir void SwUndoInsSection::UndoImpl(::sw::UndoRedoContext & rContext)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     SwDoc & rDoc = rContext.GetDoc();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     RemoveIdxFromSection( rDoc, m_nSectionNodePos );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     SwSectionNode *const pNd =
127cdf0e10cSrcweir         rDoc.GetNodes()[ m_nSectionNodePos ]->GetSectionNode();
128cdf0e10cSrcweir 	ASSERT( pNd, "wo ist mein SectionNode?" );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 	if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
131cdf0e10cSrcweir 		rDoc.DeleteRedline( *pNd, true, USHRT_MAX );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	// lag keine Selektion vor ??
134cdf0e10cSrcweir 	SwNodeIndex aIdx( *pNd );
135cdf0e10cSrcweir 	if( ( !nEndNode && STRING_MAXLEN == nEndCntnt ) ||
136cdf0e10cSrcweir 		( nSttNode == nEndNode && nSttCntnt == nEndCntnt ))
137cdf0e10cSrcweir 		// loesche einfach alle Nodes
138cdf0e10cSrcweir 		rDoc.GetNodes().Delete( aIdx, pNd->EndOfSectionIndex() -
139cdf0e10cSrcweir 										aIdx.GetIndex() );
140cdf0e10cSrcweir 	else
141cdf0e10cSrcweir 		// einfach das Format loeschen, der Rest erfolgt automatisch
142cdf0e10cSrcweir 		rDoc.DelSectionFmt( pNd->GetSection().GetFmt() );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	// muessen wir noch zusammenfassen ?
145cdf0e10cSrcweir     if (m_bSplitAtStart)
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir 		Join( rDoc, nSttNode );
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     if (m_bSplitAtEnd)
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir 		Join( rDoc, nEndNode );
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     if (m_pHistory.get())
156cdf0e10cSrcweir     {
157cdf0e10cSrcweir         m_pHistory->TmpRollback( &rDoc, 0, false );
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     if (m_bUpdateFtn)
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir 		rDoc.GetFtnIdxs().UpdateFtn( aIdx );
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     AddUndoRedoPaM(rContext);
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
RedoImpl(::sw::UndoRedoContext & rContext)168cdf0e10cSrcweir void SwUndoInsSection::RedoImpl(::sw::UndoRedoContext & rContext)
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     SwDoc & rDoc = rContext.GetDoc();
171cdf0e10cSrcweir     SwPaM & rPam( AddUndoRedoPaM(rContext) );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 	const SwTOXBaseSection* pUpdateTOX = 0;
174cdf0e10cSrcweir     if (m_pTOXBase.get())
175cdf0e10cSrcweir     {
176cdf0e10cSrcweir         pUpdateTOX = rDoc.InsertTableOf( *rPam.GetPoint(),
177cdf0e10cSrcweir                                         *m_pTOXBase, m_pAttrSet.get(), true);
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     else
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         rDoc.InsertSwSection(rPam, *m_pSectionData, 0, m_pAttrSet.get(), true);
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     if (m_pHistory.get())
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         m_pHistory->SetTmpEnd( m_pHistory->Count() );
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     SwSectionNode *const pSectNd =
190cdf0e10cSrcweir         rDoc.GetNodes()[ m_nSectionNodePos ]->GetSectionNode();
191cdf0e10cSrcweir     if (m_pRedlData.get() &&
192cdf0e10cSrcweir         IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode()))
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir 		RedlineMode_t eOld = rDoc.GetRedlineMode();
195cdf0e10cSrcweir 		rDoc.SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 		SwPaM aPam( *pSectNd->EndOfSectionNode(), *pSectNd, 1 );
198cdf0e10cSrcweir         rDoc.AppendRedline( new SwRedline( *m_pRedlData, aPam ), true);
199cdf0e10cSrcweir 		rDoc.SetRedlineMode_intern( eOld );
200cdf0e10cSrcweir 	}
201cdf0e10cSrcweir 	else if( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
202cdf0e10cSrcweir 			rDoc.GetRedlineTbl().Count() )
203cdf0e10cSrcweir 	{
204cdf0e10cSrcweir 		SwPaM aPam( *pSectNd->EndOfSectionNode(), *pSectNd, 1 );
205cdf0e10cSrcweir 		rDoc.SplitRedline( aPam );
206cdf0e10cSrcweir 	}
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	if( pUpdateTOX )
209cdf0e10cSrcweir 	{
210cdf0e10cSrcweir 		// Formatierung anstossen
211cdf0e10cSrcweir 		SwEditShell* pESh = rDoc.GetEditShell();
212cdf0e10cSrcweir 		if( pESh )
213cdf0e10cSrcweir 			pESh->CalcLayout();
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 		// Seitennummern eintragen
216cdf0e10cSrcweir 		((SwTOXBaseSection*)pUpdateTOX)->UpdatePageNum();
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
RepeatImpl(::sw::RepeatContext & rContext)220cdf0e10cSrcweir void SwUndoInsSection::RepeatImpl(::sw::RepeatContext & rContext)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     SwDoc & rDoc = rContext.GetDoc();
223cdf0e10cSrcweir     if (m_pTOXBase.get())
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         rDoc.InsertTableOf(*rContext.GetRepeatPaM().GetPoint(),
226cdf0e10cSrcweir                                         *m_pTOXBase, m_pAttrSet.get(), true);
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir     else
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         rDoc.InsertSwSection(rContext.GetRepeatPaM(),
231cdf0e10cSrcweir             *m_pSectionData, 0, m_pAttrSet.get());
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
Join(SwDoc & rDoc,sal_uLong nNode)235cdf0e10cSrcweir void SwUndoInsSection::Join( SwDoc& rDoc, sal_uLong nNode )
236cdf0e10cSrcweir {
237*69a74367SOliver-Rainer Wittmann     SwNodeIndex aIdx( rDoc.GetNodes(), nNode );
238*69a74367SOliver-Rainer Wittmann     SwTxtNode* pTxtNd = aIdx.GetNode().GetTxtNode();
239*69a74367SOliver-Rainer Wittmann     ASSERT( pTxtNd, "wo ist mein TextNode?" );
240cdf0e10cSrcweir 
241*69a74367SOliver-Rainer Wittmann     {
242*69a74367SOliver-Rainer Wittmann         RemoveIdxRel(
243*69a74367SOliver-Rainer Wittmann             nNode + 1,
244*69a74367SOliver-Rainer Wittmann             SwPosition( aIdx, SwIndex( pTxtNd, pTxtNd->GetTxt().Len() ) ) );
245*69a74367SOliver-Rainer Wittmann     }
246*69a74367SOliver-Rainer Wittmann     pTxtNd->JoinNext();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     if (m_pHistory.get())
249cdf0e10cSrcweir     {
250*69a74367SOliver-Rainer Wittmann         SwIndex aCntIdx( pTxtNd, 0 );
251*69a74367SOliver-Rainer Wittmann         pTxtNd->RstTxtAttr( aCntIdx, pTxtNd->Len(), 0, 0, true );
252*69a74367SOliver-Rainer Wittmann     }
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 
256cdf0e10cSrcweir void
SaveSplitNode(SwTxtNode * const pTxtNd,bool const bAtStart)257cdf0e10cSrcweir SwUndoInsSection::SaveSplitNode(SwTxtNode *const pTxtNd, bool const bAtStart)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	if( pTxtNd->GetpSwpHints() )
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         if (!m_pHistory.get())
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir             m_pHistory.reset( new SwHistory );
264cdf0e10cSrcweir         }
265cdf0e10cSrcweir         m_pHistory->CopyAttr( pTxtNd->GetpSwpHints(), pTxtNd->GetIndex(), 0,
266cdf0e10cSrcweir                             pTxtNd->GetTxt().Len(), false );
267cdf0e10cSrcweir     }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir     if (bAtStart)
270cdf0e10cSrcweir     {
271cdf0e10cSrcweir         m_bSplitAtStart = true;
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir     else
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir         m_bSplitAtEnd = true;
276cdf0e10cSrcweir     }
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 
280cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////
281cdf0e10cSrcweir 
282cdf0e10cSrcweir class SwUndoDelSection
283cdf0e10cSrcweir     : public SwUndo
284cdf0e10cSrcweir {
285cdf0e10cSrcweir private:
286cdf0e10cSrcweir     ::std::auto_ptr<SwSectionData> const m_pSectionData; /// section not TOX
287cdf0e10cSrcweir     ::std::auto_ptr<SwTOXBase> const m_pTOXBase; /// set iff section is TOX
288cdf0e10cSrcweir     ::std::auto_ptr<SfxItemSet> const m_pAttrSet;
289cdf0e10cSrcweir     ::boost::shared_ptr< ::sfx2::MetadatableUndo > const m_pMetadataUndo;
290cdf0e10cSrcweir     sal_uLong const m_nStartNode;
291cdf0e10cSrcweir     sal_uLong const m_nEndNode;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir public:
294cdf0e10cSrcweir     SwUndoDelSection(
295cdf0e10cSrcweir         SwSectionFmt const&, SwSection const&, SwNodeIndex const*const);
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     virtual ~SwUndoDelSection();
298cdf0e10cSrcweir 
299cdf0e10cSrcweir     virtual void UndoImpl( ::sw::UndoRedoContext & );
300cdf0e10cSrcweir     virtual void RedoImpl( ::sw::UndoRedoContext & );
301cdf0e10cSrcweir };
302cdf0e10cSrcweir 
MakeUndoDelSection(SwSectionFmt const & rFormat)303cdf0e10cSrcweir SW_DLLPRIVATE SwUndo * MakeUndoDelSection(SwSectionFmt const& rFormat)
304cdf0e10cSrcweir {
305cdf0e10cSrcweir     return new SwUndoDelSection(rFormat, *rFormat.GetSection(),
306cdf0e10cSrcweir                 rFormat.GetCntnt().GetCntntIdx());
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
SwUndoDelSection(SwSectionFmt const & rSectionFmt,SwSection const & rSection,SwNodeIndex const * const pIndex)309cdf0e10cSrcweir SwUndoDelSection::SwUndoDelSection(
310cdf0e10cSrcweir             SwSectionFmt const& rSectionFmt, SwSection const& rSection,
311cdf0e10cSrcweir             SwNodeIndex const*const pIndex)
312cdf0e10cSrcweir     : SwUndo( UNDO_DELSECTION )
313cdf0e10cSrcweir     , m_pSectionData( new SwSectionData(rSection) )
314cdf0e10cSrcweir     , m_pTOXBase( rSection.ISA( SwTOXBaseSection )
315cdf0e10cSrcweir             ? new SwTOXBase(static_cast<SwTOXBaseSection const&>(rSection))
316cdf0e10cSrcweir             : 0 )
317cdf0e10cSrcweir     , m_pAttrSet( ::lcl_GetAttrSet(rSection) )
318cdf0e10cSrcweir     , m_pMetadataUndo( rSectionFmt.CreateUndo() )
319cdf0e10cSrcweir     , m_nStartNode( pIndex->GetIndex() )
320cdf0e10cSrcweir     , m_nEndNode( pIndex->GetNode().EndOfSectionIndex() )
321cdf0e10cSrcweir {
322cdf0e10cSrcweir }
323cdf0e10cSrcweir 
~SwUndoDelSection()324cdf0e10cSrcweir SwUndoDelSection::~SwUndoDelSection()
325cdf0e10cSrcweir {
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
UndoImpl(::sw::UndoRedoContext & rContext)328cdf0e10cSrcweir void SwUndoDelSection::UndoImpl(::sw::UndoRedoContext & rContext)
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     SwDoc & rDoc = rContext.GetDoc();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     if (m_pTOXBase.get())
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         rDoc.InsertTableOf(m_nStartNode, m_nEndNode-2, *m_pTOXBase,
335cdf0e10cSrcweir                 m_pAttrSet.get());
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir     else
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         SwNodeIndex aStt( rDoc.GetNodes(), m_nStartNode );
340cdf0e10cSrcweir         SwNodeIndex aEnd( rDoc.GetNodes(), m_nEndNode-2 );
341cdf0e10cSrcweir 		SwSectionFmt* pFmt = rDoc.MakeSectionFmt( 0 );
342cdf0e10cSrcweir         if (m_pAttrSet.get())
343cdf0e10cSrcweir         {
344cdf0e10cSrcweir             pFmt->SetFmtAttr( *m_pAttrSet );
345cdf0e10cSrcweir         }
346cdf0e10cSrcweir 
347cdf0e10cSrcweir         /// OD 04.10.2002 #102894#
348cdf0e10cSrcweir         /// remember inserted section node for further calculations
349cdf0e10cSrcweir         SwSectionNode* pInsertedSectNd = rDoc.GetNodes().InsertTextSection(
350cdf0e10cSrcweir                 aStt, *pFmt, *m_pSectionData, 0, & aEnd);
351cdf0e10cSrcweir 
352cdf0e10cSrcweir 		if( SFX_ITEM_SET == pFmt->GetItemState( RES_FTN_AT_TXTEND ) ||
353cdf0e10cSrcweir 			SFX_ITEM_SET == pFmt->GetItemState( RES_END_AT_TXTEND ))
354cdf0e10cSrcweir         {
355cdf0e10cSrcweir 			rDoc.GetFtnIdxs().UpdateFtn( aStt );
356cdf0e10cSrcweir         }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir         /// OD 04.10.2002 #102894#
359cdf0e10cSrcweir         /// consider that section is hidden by condition.
360cdf0e10cSrcweir         /// If section is hidden by condition,
361cdf0e10cSrcweir         /// recalculate condition and update hidden condition flag.
362cdf0e10cSrcweir         /// Recalculation is necessary, because fields, on which the hide
363cdf0e10cSrcweir         /// condition depends, can be changed - fields changes aren't undoable.
364cdf0e10cSrcweir         /// NOTE: setting hidden condition flag also creates/deletes corresponding
365cdf0e10cSrcweir         ///     frames, if the hidden condition flag changes.
366cdf0e10cSrcweir         SwSection& aInsertedSect = pInsertedSectNd->GetSection();
367cdf0e10cSrcweir         if ( aInsertedSect.IsHidden() &&
368cdf0e10cSrcweir              aInsertedSect.GetCondition().Len() > 0 )
369cdf0e10cSrcweir         {
370cdf0e10cSrcweir             SwCalc aCalc( rDoc );
371cdf0e10cSrcweir             rDoc.FldsToCalc(aCalc, pInsertedSectNd->GetIndex(), USHRT_MAX);
372cdf0e10cSrcweir             bool bRecalcCondHidden =
373cdf0e10cSrcweir                     aCalc.Calculate( aInsertedSect.GetCondition() ).GetBool() ? true : false;
374cdf0e10cSrcweir             aInsertedSect.SetCondHidden( bRecalcCondHidden );
375cdf0e10cSrcweir         }
376cdf0e10cSrcweir 
377cdf0e10cSrcweir         pFmt->RestoreMetadata(m_pMetadataUndo);
378cdf0e10cSrcweir     }
379cdf0e10cSrcweir }
380cdf0e10cSrcweir 
RedoImpl(::sw::UndoRedoContext & rContext)381cdf0e10cSrcweir void SwUndoDelSection::RedoImpl(::sw::UndoRedoContext & rContext)
382cdf0e10cSrcweir {
383cdf0e10cSrcweir     SwDoc & rDoc = rContext.GetDoc();
384cdf0e10cSrcweir 
385cdf0e10cSrcweir     SwSectionNode *const pNd =
386cdf0e10cSrcweir         rDoc.GetNodes()[ m_nStartNode ]->GetSectionNode();
387cdf0e10cSrcweir     OSL_ENSURE(pNd, "SwUndoDelSection::RedoImpl(): no SectionNode?");
388cdf0e10cSrcweir 	// einfach das Format loeschen, der Rest erfolgt automatisch
389cdf0e10cSrcweir 	rDoc.DelSectionFmt( pNd->GetSection().GetFmt() );
390cdf0e10cSrcweir }
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 
393cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////
394cdf0e10cSrcweir 
395cdf0e10cSrcweir class SwUndoUpdateSection
396cdf0e10cSrcweir     : public SwUndo
397cdf0e10cSrcweir {
398cdf0e10cSrcweir private:
399cdf0e10cSrcweir     ::std::auto_ptr<SwSectionData> m_pSectionData;
400cdf0e10cSrcweir     ::std::auto_ptr<SfxItemSet> m_pAttrSet;
401cdf0e10cSrcweir     sal_uLong const m_nStartNode;
402cdf0e10cSrcweir     bool const m_bOnlyAttrChanged;
403cdf0e10cSrcweir 
404cdf0e10cSrcweir public:
405cdf0e10cSrcweir     SwUndoUpdateSection(
406cdf0e10cSrcweir         SwSection const&, SwNodeIndex const*const, bool const bOnlyAttr);
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     virtual ~SwUndoUpdateSection();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     virtual void UndoImpl( ::sw::UndoRedoContext & );
411cdf0e10cSrcweir     virtual void RedoImpl( ::sw::UndoRedoContext & );
412cdf0e10cSrcweir };
413cdf0e10cSrcweir 
414cdf0e10cSrcweir SW_DLLPRIVATE SwUndo *
MakeUndoUpdateSection(SwSectionFmt const & rFormat,bool const bOnlyAttr)415cdf0e10cSrcweir MakeUndoUpdateSection(SwSectionFmt const& rFormat, bool const bOnlyAttr)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir     return new SwUndoUpdateSection(*rFormat.GetSection(),
418cdf0e10cSrcweir                 rFormat.GetCntnt().GetCntntIdx(), bOnlyAttr);
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
SwUndoUpdateSection(SwSection const & rSection,SwNodeIndex const * const pIndex,bool const bOnlyAttr)421cdf0e10cSrcweir SwUndoUpdateSection::SwUndoUpdateSection(
422cdf0e10cSrcweir         SwSection const& rSection, SwNodeIndex const*const pIndex,
423cdf0e10cSrcweir         bool const bOnlyAttr)
424cdf0e10cSrcweir     : SwUndo( UNDO_CHGSECTION )
425cdf0e10cSrcweir     , m_pSectionData( new SwSectionData(rSection) )
426cdf0e10cSrcweir     , m_pAttrSet( ::lcl_GetAttrSet(rSection) )
427cdf0e10cSrcweir     , m_nStartNode( pIndex->GetIndex() )
428cdf0e10cSrcweir     , m_bOnlyAttrChanged( bOnlyAttr )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
~SwUndoUpdateSection()432cdf0e10cSrcweir SwUndoUpdateSection::~SwUndoUpdateSection()
433cdf0e10cSrcweir {
434cdf0e10cSrcweir }
435cdf0e10cSrcweir 
UndoImpl(::sw::UndoRedoContext & rContext)436cdf0e10cSrcweir void SwUndoUpdateSection::UndoImpl(::sw::UndoRedoContext & rContext)
437cdf0e10cSrcweir {
438cdf0e10cSrcweir     SwDoc & rDoc = rContext.GetDoc();
439cdf0e10cSrcweir     SwSectionNode *const pSectNd =
440cdf0e10cSrcweir         rDoc.GetNodes()[ m_nStartNode ]->GetSectionNode();
441cdf0e10cSrcweir 	ASSERT( pSectNd, "wo ist mein SectionNode?" );
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 	SwSection& rNdSect = pSectNd->GetSection();
444cdf0e10cSrcweir 	SwFmt* pFmt = rNdSect.GetFmt();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	SfxItemSet* pCur = ::lcl_GetAttrSet( rNdSect );
447cdf0e10cSrcweir     if (m_pAttrSet.get())
448cdf0e10cSrcweir     {
449cdf0e10cSrcweir 		// das Content- und Protect-Item muss bestehen bleiben
450cdf0e10cSrcweir 		const SfxPoolItem* pItem;
451cdf0e10cSrcweir         m_pAttrSet->Put( pFmt->GetFmtAttr( RES_CNTNT ));
452cdf0e10cSrcweir 		if( SFX_ITEM_SET == pFmt->GetItemState( RES_PROTECT, sal_True, &pItem ))
453cdf0e10cSrcweir         {
454cdf0e10cSrcweir             m_pAttrSet->Put( *pItem );
455cdf0e10cSrcweir         }
456cdf0e10cSrcweir         pFmt->DelDiffs( *m_pAttrSet );
457cdf0e10cSrcweir         m_pAttrSet->ClearItem( RES_CNTNT );
458cdf0e10cSrcweir         pFmt->SetFmtAttr( *m_pAttrSet );
459cdf0e10cSrcweir     }
460cdf0e10cSrcweir 	else
461cdf0e10cSrcweir 	{
462cdf0e10cSrcweir 		// dann muessen die alten entfernt werden
463cdf0e10cSrcweir         pFmt->ResetFmtAttr( RES_FRMATR_BEGIN, RES_BREAK );
464cdf0e10cSrcweir         pFmt->ResetFmtAttr( RES_HEADER, RES_OPAQUE );
465cdf0e10cSrcweir         pFmt->ResetFmtAttr( RES_SURROUND, RES_FRMATR_END-1 );
466cdf0e10cSrcweir 	}
467cdf0e10cSrcweir     m_pAttrSet.reset(pCur);
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     if (!m_bOnlyAttrChanged)
470cdf0e10cSrcweir     {
471cdf0e10cSrcweir         const bool bUpdate =
472cdf0e10cSrcweir                (!rNdSect.IsLinkType() && m_pSectionData->IsLinkType())
473cdf0e10cSrcweir             || (    m_pSectionData->GetLinkFileName().Len()
474cdf0e10cSrcweir                 &&  (m_pSectionData->GetLinkFileName() !=
475cdf0e10cSrcweir                         rNdSect.GetLinkFileName()));
476cdf0e10cSrcweir 
477cdf0e10cSrcweir         // swap stored section data with live section data
478cdf0e10cSrcweir         SwSectionData *const pOld( new SwSectionData(rNdSect) );
479cdf0e10cSrcweir         rNdSect.SetSectionData(*m_pSectionData);
480cdf0e10cSrcweir         m_pSectionData.reset(pOld);
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 		if( bUpdate )
483cdf0e10cSrcweir 			rNdSect.CreateLink( CREATE_UPDATE );
484cdf0e10cSrcweir 		else if( CONTENT_SECTION == rNdSect.GetType() && rNdSect.IsConnected() )
485cdf0e10cSrcweir 		{
486cdf0e10cSrcweir 			rNdSect.Disconnect();
487cdf0e10cSrcweir 			rDoc.GetLinkManager().Remove( &rNdSect.GetBaseLink() );
488cdf0e10cSrcweir 		}
489cdf0e10cSrcweir 	}
490cdf0e10cSrcweir }
491cdf0e10cSrcweir 
RedoImpl(::sw::UndoRedoContext & rContext)492cdf0e10cSrcweir void SwUndoUpdateSection::RedoImpl(::sw::UndoRedoContext & rContext)
493cdf0e10cSrcweir {
494cdf0e10cSrcweir     UndoImpl(rContext);
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
497