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