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
10cdf0e10cSrcweir *
11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
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
28cdf0e10cSrcweir #include <node.hxx>
29cdf0e10cSrcweir #include <doc.hxx>
30cdf0e10cSrcweir #include <pam.hxx>
31cdf0e10cSrcweir #include <ndtxt.hxx>
32cdf0e10cSrcweir #include <fldbas.hxx> // UpdateFlds der KapitelNummerierung
33cdf0e10cSrcweir #include <docary.hxx>
34cdf0e10cSrcweir
_SV_IMPL_SORTAR_ALG(SwOutlineNodes,SwNodePtr)35cdf0e10cSrcweir _SV_IMPL_SORTAR_ALG( SwOutlineNodes, SwNodePtr )
36cdf0e10cSrcweir sal_Bool SwOutlineNodes::Seek_Entry( const SwNodePtr rSrch, sal_uInt16* pFndPos ) const
37cdf0e10cSrcweir {
38cdf0e10cSrcweir sal_uLong nIdx = rSrch->GetIndex();
39cdf0e10cSrcweir
40cdf0e10cSrcweir sal_uInt16 nO = Count(), nM, nU = 0;
41cdf0e10cSrcweir if( nO > 0 )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir //JP 17.03.98: aufgrund des Bug 48592 - wo unter anderem nach Undo/Redo
44cdf0e10cSrcweir // Nodes aus dem falschen NodesArray im OutlineArray standen,
45cdf0e10cSrcweir // jetzt mal einen Check eingebaut.
46cdf0e10cSrcweir #ifdef DBG_UTIL
47cdf0e10cSrcweir {
48cdf0e10cSrcweir for( sal_uInt16 n = 1; n < nO; ++n )
49cdf0e10cSrcweir if( &(*this)[ n-1 ]->GetNodes() !=
50cdf0e10cSrcweir &(*this)[ n ]->GetNodes() )
51cdf0e10cSrcweir {
52*870262e3SDon Lewis ASSERT( sal_False, "Node in the wrong outline array" );
53cdf0e10cSrcweir }
54cdf0e10cSrcweir }
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir
57cdf0e10cSrcweir nO--;
58cdf0e10cSrcweir while( nU <= nO )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir nM = nU + ( nO - nU ) / 2;
61cdf0e10cSrcweir if( (*this)[ nM ] == rSrch )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir if( pFndPos )
64cdf0e10cSrcweir *pFndPos = nM;
65cdf0e10cSrcweir return sal_True;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir else if( (*this)[ nM ]->GetIndex() < nIdx )
68cdf0e10cSrcweir nU = nM + 1;
69cdf0e10cSrcweir else if( nM == 0 )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir if( pFndPos )
72cdf0e10cSrcweir *pFndPos = nU;
73cdf0e10cSrcweir return sal_False;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir else
76cdf0e10cSrcweir nO = nM - 1;
77cdf0e10cSrcweir }
78cdf0e10cSrcweir }
79cdf0e10cSrcweir if( pFndPos )
80cdf0e10cSrcweir *pFndPos = nU;
81cdf0e10cSrcweir return sal_False;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir
UpdateOutlineNode(SwNode & rNd)84cdf0e10cSrcweir void SwNodes::UpdateOutlineNode(SwNode & rNd)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir SwTxtNode * pTxtNd = rNd.GetTxtNode();
87cdf0e10cSrcweir
88cdf0e10cSrcweir if (pTxtNd && pTxtNd->IsOutlineStateChanged())
89cdf0e10cSrcweir {
90cdf0e10cSrcweir sal_Bool bFound = pOutlineNds->Seek_Entry(pTxtNd);
91cdf0e10cSrcweir
92cdf0e10cSrcweir if (pTxtNd->IsOutline())
93cdf0e10cSrcweir {
94cdf0e10cSrcweir if (! bFound)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir // --> OD 2005-11-02 #125329#
97cdf0e10cSrcweir // assure that text is in the correct nodes array
98cdf0e10cSrcweir if ( &(pTxtNd->GetNodes()) == this )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir pOutlineNds->Insert(pTxtNd);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir else
103cdf0e10cSrcweir {
104cdf0e10cSrcweir ASSERT( false,
105cdf0e10cSrcweir "<SwNodes::UpdateOutlineNode(..)> - given text node isn't in the correct nodes array. This is a serious defect -> inform OD" );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir // <--
108cdf0e10cSrcweir }
109cdf0e10cSrcweir }
110cdf0e10cSrcweir else
111cdf0e10cSrcweir {
112cdf0e10cSrcweir if (bFound)
113cdf0e10cSrcweir pOutlineNds->Remove(pTxtNd);
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
116cdf0e10cSrcweir pTxtNd->UpdateOutlineState();
117cdf0e10cSrcweir
118cdf0e10cSrcweir // die Gliederungs-Felder Updaten
119cdf0e10cSrcweir GetDoc()->GetSysFldType( RES_CHAPTERFLD )->UpdateFlds();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir }
122cdf0e10cSrcweir
123cdf0e10cSrcweir //void SwNodes::UpdateOutlineNode( const SwNode& rNd, sal_uInt8 nOldLevel, //#outline level,removed by zhaojianwei
124cdf0e10cSrcweir // sal_uInt8 nNewLevel )
125cdf0e10cSrcweir //{
126cdf0e10cSrcweir // const SwNodePtr pSrch = (SwNodePtr)&rNd;
127cdf0e10cSrcweir // sal_uInt16 nSttPos;
128cdf0e10cSrcweir // sal_Bool bSeekIdx = pOutlineNds->Seek_Entry( pSrch, &nSttPos );
129cdf0e10cSrcweir //
130cdf0e10cSrcweir // //if( NO_NUMBERING == nOldLevel ) //#outline level,zhaojianwei
131cdf0e10cSrcweir // if( 0 == nOldLevel ) //<-end, zhaojianwei
132cdf0e10cSrcweir // {
133cdf0e10cSrcweir // // nicht vorhanden, also einfuegen
134cdf0e10cSrcweir // //ASSERT( !bSeekIdx, "Der Node ist schon als OutlineNode vorhanden" );
135cdf0e10cSrcweir //
136cdf0e10cSrcweir // //JP 12.03.99: 63293 - Nodes vom RedlineBereich NIE aufnehmen
137cdf0e10cSrcweir // sal_uLong nNd = rNd.GetIndex();
138cdf0e10cSrcweir // if( nNd < GetEndOfRedlines().GetIndex() &&
139cdf0e10cSrcweir // nNd > GetEndOfRedlines().StartOfSectionNode()->GetIndex() )
140cdf0e10cSrcweir // return ;
141cdf0e10cSrcweir //
142cdf0e10cSrcweir // // jetzt noch alle nachfolgende Outline-Nodes updaten
143cdf0e10cSrcweir // if (! bSeekIdx)
144cdf0e10cSrcweir // {
145cdf0e10cSrcweir // // --> OD 2005-11-03 #125329#
146cdf0e10cSrcweir // // assure that node <pSrch> is in the correct nodes array
147cdf0e10cSrcweir // if ( &(pSrch->GetNodes()) == this )
148cdf0e10cSrcweir // {
149cdf0e10cSrcweir // pOutlineNds->Insert( pSrch );
150cdf0e10cSrcweir // }
151cdf0e10cSrcweir // else
152cdf0e10cSrcweir // {
153cdf0e10cSrcweir // ASSERT( false,
154cdf0e10cSrcweir // "<SwNodes::UpdateOutlineNode(..)> - node <pSrch> isn't in correct nodes array. This is a serious defect -> inform OD" );
155cdf0e10cSrcweir // }
156cdf0e10cSrcweir // // <--
157cdf0e10cSrcweir // }
158cdf0e10cSrcweir //
159cdf0e10cSrcweir // }
160cdf0e10cSrcweir // //else if( NO_NUMBERING == nNewLevel ) //#outline level,removed by zhaojianwei
161cdf0e10cSrcweir // else if( 0 == nNewLevel ) //<-end,added by zhaojianwei // Level entfernen
162cdf0e10cSrcweir // {
163cdf0e10cSrcweir // if( !bSeekIdx )
164cdf0e10cSrcweir // return;
165cdf0e10cSrcweir //
166cdf0e10cSrcweir // // jetzt noch alle nachfolgende Outline-Nodes updaten
167cdf0e10cSrcweir // pOutlineNds->Remove( nSttPos );
168cdf0e10cSrcweir // }
169cdf0e10cSrcweir // else if( !bSeekIdx ) // Update und Index nicht gefunden ??
170cdf0e10cSrcweir // return ;
171cdf0e10cSrcweir //
172cdf0e10cSrcweir // {
173cdf0e10cSrcweir // SwTxtNode & rTxtNd = (SwTxtNode &) rNd;
174cdf0e10cSrcweir // SwPaM aPam(rTxtNd); // #115901#
175cdf0e10cSrcweir //
176cdf0e10cSrcweir // //if (nNewLevel != NO_NUMBERING) //#outline level,zhaojianwei // #115901#
177cdf0e10cSrcweir // if (nNewLevel != 0) //<-end,zhaojianwei // #115901#
178cdf0e10cSrcweir // {
179cdf0e10cSrcweir // //rTxtNd.SetLevel(rTxtNd.GetTxtColl()->GetOutlineLevel()); //#outline level,zhaojianwei
180cdf0e10cSrcweir // //rTxtNd.NumRuleChgd();
181cdf0e10cSrcweir // if(rTxtNd.GetTxtColl()->IsAssignedToListLevelOfOutlineStyle())
182cdf0e10cSrcweir // {
183cdf0e10cSrcweir // rTxtNd.SetLevel(rTxtNd.GetTxtColl()->GetAssignedOutlineStyleLevel());
184cdf0e10cSrcweir // rTxtNd.NumRuleChgd();
185cdf0e10cSrcweir // }//<-end,zhaojianwei
186cdf0e10cSrcweir //
187cdf0e10cSrcweir // //GetDoc()->SetNumRule(aPam, *GetDoc()->GetOutlineNumRule());
188cdf0e10cSrcweir // }
189cdf0e10cSrcweir // else
190cdf0e10cSrcweir // {
191cdf0e10cSrcweir // GetDoc()->DelNumRules(aPam);
192cdf0e10cSrcweir // }
193cdf0e10cSrcweir // }
194cdf0e10cSrcweir //
195cdf0e10cSrcweir // // die Gliederungs-Felder Updaten
196cdf0e10cSrcweir // GetDoc()->GetSysFldType( RES_CHAPTERFLD )->UpdateFlds();
197cdf0e10cSrcweir // GetDoc()->ChkCondColls();
198cdf0e10cSrcweir //}//<-end,zhaojianwei
199cdf0e10cSrcweir
UpdtOutlineIdx(const SwNode & rNd)200cdf0e10cSrcweir void SwNodes::UpdtOutlineIdx( const SwNode& rNd )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir if( !pOutlineNds->Count() ) // keine OutlineNodes vorhanden ?
203cdf0e10cSrcweir return;
204cdf0e10cSrcweir
205cdf0e10cSrcweir const SwNodePtr pSrch = (SwNodePtr)&rNd;
206cdf0e10cSrcweir sal_uInt16 nPos;
207cdf0e10cSrcweir pOutlineNds->Seek_Entry( pSrch, &nPos );
208cdf0e10cSrcweir if( nPos == pOutlineNds->Count() ) // keine zum Updaten vorhanden ?
209cdf0e10cSrcweir return;
210cdf0e10cSrcweir
211cdf0e10cSrcweir if( nPos )
212cdf0e10cSrcweir --nPos;
213cdf0e10cSrcweir
214cdf0e10cSrcweir if( !GetDoc()->IsInDtor() && IsDocNodes() )
215cdf0e10cSrcweir UpdateOutlineNode( *(*pOutlineNds)[ nPos ]);
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
GetOutLineNds() const218cdf0e10cSrcweir const SwOutlineNodes & SwNodes::GetOutLineNds() const
219cdf0e10cSrcweir {
220cdf0e10cSrcweir return *pOutlineNds;
221cdf0e10cSrcweir }
222