xref: /AOO41X/main/sw/source/core/docnode/ndnum.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <node.hxx>
29 #include <doc.hxx>
30 #include <pam.hxx>
31 #include <ndtxt.hxx>
32 #include <fldbas.hxx>           // UpdateFlds der KapitelNummerierung
33 #include <docary.hxx>
34 
_SV_IMPL_SORTAR_ALG(SwOutlineNodes,SwNodePtr)35 _SV_IMPL_SORTAR_ALG( SwOutlineNodes, SwNodePtr )
36 sal_Bool SwOutlineNodes::Seek_Entry( const SwNodePtr rSrch, sal_uInt16* pFndPos ) const
37 {
38     sal_uLong nIdx = rSrch->GetIndex();
39 
40     sal_uInt16 nO = Count(), nM, nU = 0;
41     if( nO > 0 )
42     {
43 //JP 17.03.98: aufgrund des Bug 48592 - wo unter anderem nach Undo/Redo
44 //              Nodes aus dem falschen NodesArray im OutlineArray standen,
45 //              jetzt mal einen Check eingebaut.
46 #ifdef DBG_UTIL
47         {
48             for( sal_uInt16 n = 1; n < nO; ++n )
49                 if( &(*this)[ n-1 ]->GetNodes() !=
50                     &(*this)[ n ]->GetNodes() )
51                 {
52                     ASSERT( !this, "Node im falschen Outline-Array" );
53                 }
54         }
55 #endif
56 
57         nO--;
58         while( nU <= nO )
59         {
60             nM = nU + ( nO - nU ) / 2;
61             if( (*this)[ nM ] == rSrch )
62             {
63                 if( pFndPos )
64                     *pFndPos = nM;
65                 return sal_True;
66             }
67             else if( (*this)[ nM ]->GetIndex() < nIdx )
68                 nU = nM + 1;
69             else if( nM == 0 )
70             {
71                 if( pFndPos )
72                     *pFndPos = nU;
73                 return sal_False;
74             }
75             else
76                 nO = nM - 1;
77         }
78     }
79     if( pFndPos )
80         *pFndPos = nU;
81     return sal_False;
82 }
83 
UpdateOutlineNode(SwNode & rNd)84 void SwNodes::UpdateOutlineNode(SwNode & rNd)
85 {
86     SwTxtNode * pTxtNd = rNd.GetTxtNode();
87 
88     if (pTxtNd && pTxtNd->IsOutlineStateChanged())
89     {
90         sal_Bool bFound = pOutlineNds->Seek_Entry(pTxtNd);
91 
92         if (pTxtNd->IsOutline())
93         {
94             if (! bFound)
95             {
96                 // --> OD 2005-11-02 #125329#
97                 // assure that text is in the correct nodes array
98                 if ( &(pTxtNd->GetNodes()) == this )
99                 {
100                     pOutlineNds->Insert(pTxtNd);
101                 }
102                 else
103                 {
104                     ASSERT( false,
105                             "<SwNodes::UpdateOutlineNode(..)> - given text node isn't in the correct nodes array. This is a serious defect -> inform OD" );
106                 }
107                 // <--
108             }
109         }
110         else
111         {
112             if (bFound)
113                 pOutlineNds->Remove(pTxtNd);
114         }
115 
116         pTxtNd->UpdateOutlineState();
117 
118         // die Gliederungs-Felder Updaten
119         GetDoc()->GetSysFldType( RES_CHAPTERFLD )->UpdateFlds();
120     }
121 }
122 
123 //void SwNodes::UpdateOutlineNode( const SwNode& rNd, sal_uInt8 nOldLevel, //#outline level,removed by zhaojianwei
124 //                                 sal_uInt8 nNewLevel )
125 //{
126 //  const SwNodePtr pSrch = (SwNodePtr)&rNd;
127 //  sal_uInt16 nSttPos;
128 //  sal_Bool bSeekIdx = pOutlineNds->Seek_Entry( pSrch, &nSttPos );
129 //
130 //  //if( NO_NUMBERING == nOldLevel )   //#outline level,zhaojianwei
131 //  if( 0 == nOldLevel )                //<-end, zhaojianwei
132 //  {
133 //      // nicht vorhanden, also einfuegen
134 //      //ASSERT( !bSeekIdx, "Der Node ist schon als OutlineNode vorhanden" );
135 //
136 //      //JP 12.03.99: 63293 - Nodes vom RedlineBereich NIE aufnehmen
137 //      sal_uLong nNd = rNd.GetIndex();
138 //      if( nNd < GetEndOfRedlines().GetIndex() &&
139 //            nNd > GetEndOfRedlines().StartOfSectionNode()->GetIndex() )
140 //          return ;
141 //
142 //      // jetzt noch alle nachfolgende Outline-Nodes updaten
143 //        if (! bSeekIdx)
144 //        {
145 //            // --> OD 2005-11-03 #125329#
146 //            // assure that node <pSrch> is in the correct nodes array
147 //            if ( &(pSrch->GetNodes()) == this )
148 //            {
149 //                pOutlineNds->Insert( pSrch );
150 //            }
151 //            else
152 //            {
153 //                ASSERT( false,
154 //                        "<SwNodes::UpdateOutlineNode(..)> - node <pSrch> isn't in correct nodes array. This is a serious defect -> inform OD" );
155 //            }
156 //            // <--
157 //        }
158 //
159 //  }
160 //  //else if( NO_NUMBERING == nNewLevel )  //#outline level,removed by zhaojianwei
161 //  else if( 0 == nNewLevel )               //<-end,added by zhaojianwei    // Level entfernen
162 //  {
163 //      if( !bSeekIdx )
164 //          return;
165 //
166 //      // jetzt noch alle nachfolgende Outline-Nodes updaten
167 //      pOutlineNds->Remove( nSttPos );
168 //  }
169 //  else if( !bSeekIdx )        // Update und Index nicht gefunden ??
170 //      return ;
171 //
172 //    {
173 //        SwTxtNode & rTxtNd = (SwTxtNode &) rNd;
174 //        SwPaM aPam(rTxtNd); // #115901#
175 //
176 //        //if (nNewLevel != NO_NUMBERING) //#outline level,zhaojianwei // #115901#
177 //      if (nNewLevel != 0)              //<-end,zhaojianwei // #115901#
178 //        {
179 //            //rTxtNd.SetLevel(rTxtNd.GetTxtColl()->GetOutlineLevel());    //#outline level,zhaojianwei
180 //          //rTxtNd.NumRuleChgd();
181 //          if(rTxtNd.GetTxtColl()->IsAssignedToListLevelOfOutlineStyle())
182 //          {
183 //              rTxtNd.SetLevel(rTxtNd.GetTxtColl()->GetAssignedOutlineStyleLevel());
184 //              rTxtNd.NumRuleChgd();
185 //          }//<-end,zhaojianwei
186 //
187 //            //GetDoc()->SetNumRule(aPam, *GetDoc()->GetOutlineNumRule());
188 //        }
189 //        else
190 //        {
191 //            GetDoc()->DelNumRules(aPam);
192 //        }
193 //    }
194 //
195 //  // die Gliederungs-Felder Updaten
196 //  GetDoc()->GetSysFldType( RES_CHAPTERFLD )->UpdateFlds();
197 //    GetDoc()->ChkCondColls();
198 //}//<-end,zhaojianwei
199 
UpdtOutlineIdx(const SwNode & rNd)200 void SwNodes::UpdtOutlineIdx( const SwNode& rNd )
201 {
202     if( !pOutlineNds->Count() )     // keine OutlineNodes vorhanden ?
203         return;
204 
205     const SwNodePtr pSrch = (SwNodePtr)&rNd;
206     sal_uInt16 nPos;
207     pOutlineNds->Seek_Entry( pSrch, &nPos );
208     if( nPos == pOutlineNds->Count() )      // keine zum Updaten vorhanden ?
209         return;
210 
211     if( nPos )
212         --nPos;
213 
214     if( !GetDoc()->IsInDtor() && IsDocNodes() )
215         UpdateOutlineNode( *(*pOutlineNds)[ nPos ]);
216 }
217 
GetOutLineNds() const218 const SwOutlineNodes & SwNodes::GetOutLineNds() const
219 {
220     return *pOutlineNds;
221 }
222