Update ooo320-m1
[ooovba.git] / sw / source / core / docnode / ndnum.cxx
blobef07ac70f69b99189e7c12ee1f114981c5feefe2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ndnum.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <node.hxx>
36 #include <doc.hxx>
37 #include <pam.hxx>
38 #include <ndtxt.hxx>
39 #include <fldbas.hxx> // UpdateFlds der KapitelNummerierung
40 #include <docary.hxx>
42 _SV_IMPL_SORTAR_ALG( SwOutlineNodes, SwNodePtr )
43 BOOL SwOutlineNodes::Seek_Entry( const SwNodePtr rSrch, USHORT* pFndPos ) const
45 ULONG nIdx = rSrch->GetIndex();
47 USHORT nO = Count(), nM, nU = 0;
48 if( nO > 0 )
50 //JP 17.03.98: aufgrund des Bug 48592 - wo unter anderem nach Undo/Redo
51 // Nodes aus dem falschen NodesArray im OutlineArray standen,
52 // jetzt mal einen Check eingebaut.
53 #ifndef PRODUCT
55 for( USHORT n = 1; n < nO; ++n )
56 if( &(*this)[ n-1 ]->GetNodes() !=
57 &(*this)[ n ]->GetNodes() )
59 ASSERT( !this, "Node im falschen Outline-Array" );
62 #endif
64 nO--;
65 while( nU <= nO )
67 nM = nU + ( nO - nU ) / 2;
68 if( (*this)[ nM ] == rSrch )
70 if( pFndPos )
71 *pFndPos = nM;
72 return TRUE;
74 else if( (*this)[ nM ]->GetIndex() < nIdx )
75 nU = nM + 1;
76 else if( nM == 0 )
78 if( pFndPos )
79 *pFndPos = nU;
80 return FALSE;
82 else
83 nO = nM - 1;
86 if( pFndPos )
87 *pFndPos = nU;
88 return FALSE;
91 void SwNodes::UpdateOutlineNode(SwNode & rNd)
93 SwTxtNode * pTxtNd = rNd.GetTxtNode();
95 if (pTxtNd && pTxtNd->IsOutlineStateChanged())
97 BOOL bFound = pOutlineNds->Seek_Entry(pTxtNd);
99 if (pTxtNd->IsOutline())
101 if (! bFound)
103 // --> OD 2005-11-02 #125329#
104 // assure that text is in the correct nodes array
105 if ( &(pTxtNd->GetNodes()) == this )
107 pOutlineNds->Insert(pTxtNd);
109 else
111 ASSERT( false,
112 "<SwNodes::UpdateOutlineNode(..)> - given text node isn't in the correct nodes array. This is a serious defect -> inform OD" );
114 // <--
117 else
119 if (bFound)
120 pOutlineNds->Remove(pTxtNd);
123 pTxtNd->UpdateOutlineState();
125 // die Gliederungs-Felder Updaten
126 GetDoc()->GetSysFldType( RES_CHAPTERFLD )->UpdateFlds();
130 //void SwNodes::UpdateOutlineNode( const SwNode& rNd, BYTE nOldLevel, //#outline level,removed by zhaojianwei
131 // BYTE nNewLevel )
133 // const SwNodePtr pSrch = (SwNodePtr)&rNd;
134 // USHORT nSttPos;
135 // BOOL bSeekIdx = pOutlineNds->Seek_Entry( pSrch, &nSttPos );
137 // //if( NO_NUMBERING == nOldLevel ) //#outline level,zhaojianwei
138 // if( 0 == nOldLevel ) //<-end, zhaojianwei
139 // {
140 // // nicht vorhanden, also einfuegen
141 // //ASSERT( !bSeekIdx, "Der Node ist schon als OutlineNode vorhanden" );
143 // //JP 12.03.99: 63293 - Nodes vom RedlineBereich NIE aufnehmen
144 // ULONG nNd = rNd.GetIndex();
145 // if( nNd < GetEndOfRedlines().GetIndex() &&
146 // nNd > GetEndOfRedlines().StartOfSectionNode()->GetIndex() )
147 // return ;
149 // // jetzt noch alle nachfolgende Outline-Nodes updaten
150 // if (! bSeekIdx)
151 // {
152 // // --> OD 2005-11-03 #125329#
153 // // assure that node <pSrch> is in the correct nodes array
154 // if ( &(pSrch->GetNodes()) == this )
155 // {
156 // pOutlineNds->Insert( pSrch );
157 // }
158 // else
159 // {
160 // ASSERT( false,
161 // "<SwNodes::UpdateOutlineNode(..)> - node <pSrch> isn't in correct nodes array. This is a serious defect -> inform OD" );
162 // }
163 // // <--
164 // }
166 // }
167 // //else if( NO_NUMBERING == nNewLevel ) //#outline level,removed by zhaojianwei
168 // else if( 0 == nNewLevel ) //<-end,added by zhaojianwei // Level entfernen
169 // {
170 // if( !bSeekIdx )
171 // return;
173 // // jetzt noch alle nachfolgende Outline-Nodes updaten
174 // pOutlineNds->Remove( nSttPos );
175 // }
176 // else if( !bSeekIdx ) // Update und Index nicht gefunden ??
177 // return ;
179 // {
180 // SwTxtNode & rTxtNd = (SwTxtNode &) rNd;
181 // SwPaM aPam(rTxtNd); // #115901#
183 // //if (nNewLevel != NO_NUMBERING) //#outline level,zhaojianwei // #115901#
184 // if (nNewLevel != 0) //<-end,zhaojianwei // #115901#
185 // {
186 // //rTxtNd.SetLevel(rTxtNd.GetTxtColl()->GetOutlineLevel()); //#outline level,zhaojianwei
187 // //rTxtNd.NumRuleChgd();
188 // if(rTxtNd.GetTxtColl()->IsAssignedToListLevelOfOutlineStyle())
189 // {
190 // rTxtNd.SetLevel(rTxtNd.GetTxtColl()->GetAssignedOutlineStyleLevel());
191 // rTxtNd.NumRuleChgd();
192 // }//<-end,zhaojianwei
194 // //GetDoc()->SetNumRule(aPam, *GetDoc()->GetOutlineNumRule());
195 // }
196 // else
197 // {
198 // GetDoc()->DelNumRules(aPam);
199 // }
200 // }
202 // // die Gliederungs-Felder Updaten
203 // GetDoc()->GetSysFldType( RES_CHAPTERFLD )->UpdateFlds();
204 // GetDoc()->ChkCondColls();
205 //}//<-end,zhaojianwei
207 void SwNodes::UpdtOutlineIdx( const SwNode& rNd )
209 if( !pOutlineNds->Count() ) // keine OutlineNodes vorhanden ?
210 return;
212 const SwNodePtr pSrch = (SwNodePtr)&rNd;
213 USHORT nPos;
214 pOutlineNds->Seek_Entry( pSrch, &nPos );
215 if( nPos == pOutlineNds->Count() ) // keine zum Updaten vorhanden ?
216 return;
218 if( nPos )
219 --nPos;
221 if( !GetDoc()->IsInDtor() && IsDocNodes() )
222 UpdateOutlineNode( *(*pOutlineNds)[ nPos ]);
225 const SwOutlineNodes & SwNodes::GetOutLineNds() const
227 return *pOutlineNds;