xref: /aoo41x/main/sw/source/core/edit/ednumber.cxx (revision 1ff378ef)
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 <hintids.hxx>
29 #include <editsh.hxx>
30 #include <edimp.hxx>
31 #include <doc.hxx>
32 #include <IDocumentUndoRedo.hxx>
33 #include <ndtxt.hxx>
34 #include <paratr.hxx>
35 #include <swundo.hxx>
36 #include <numrule.hxx>
37 
38 SV_IMPL_VARARR_SORT( _SwPamRanges, SwPamRange )
39 
40 
41 SwPamRanges::SwPamRanges( const SwPaM& rRing )
42 {
43 	const SwPaM* pTmp = &rRing;
44 	do {
45 		Insert( pTmp->GetMark()->nNode, pTmp->GetPoint()->nNode );
46 	} while( &rRing != ( pTmp = (const SwPaM*)pTmp->GetNext() ));
47 }
48 
49 
50 void SwPamRanges::Insert( const SwNodeIndex& rIdx1, const SwNodeIndex& rIdx2 )
51 {
52 	SwPamRange aRg( rIdx1.GetIndex(), rIdx2.GetIndex() );
53 	if( aRg.nEnd < aRg.nStart )
54 	{	aRg.nStart = aRg.nEnd; aRg.nEnd = rIdx1.GetIndex(); }
55 
56 	sal_uInt16 nPos = 0;
57 	const SwPamRange* pTmp;
58 	if( Count() && Seek_Entry( aRg, &nPos ))		// suche Insert Position
59 	{
60 		// ist der im Array stehende kleiner ??
61 		if( ( pTmp = GetData()+ nPos )->nEnd < aRg.nEnd )
62 		{
63 			aRg.nEnd = pTmp->nEnd;
64 			Remove( nPos, 1 );		// zusammenfassen
65 		}
66 		else
67 			return;		// ende, weil schon alle zusammengefasst waren
68 	}
69 
70 	sal_Bool bEnde;
71 	do {
72 		bEnde = sal_True;
73 
74 		// mit dem Vorgaenger zusammenfassen ??
75 		if( nPos > 0 )
76 		{
77 			if( ( pTmp = GetData()+( nPos-1 ))->nEnd == aRg.nStart
78 				|| pTmp->nEnd+1 == aRg.nStart )
79 			{
80 				aRg.nStart = pTmp->nStart;
81 				bEnde = sal_False;
82 				Remove( --nPos, 1 );		// zusammenfassen
83 			}
84 			// SSelection im Bereich ??
85 			else if( pTmp->nStart <= aRg.nStart && aRg.nEnd <= pTmp->nEnd )
86 				return;
87 		}
88 			// mit dem Nachfolger zusammenfassen ??
89 		if( nPos < Count() )
90 		{
91 			if( ( pTmp = GetData() + nPos )->nStart == aRg.nEnd ||
92 				pTmp->nStart == aRg.nEnd+1 )
93 			{
94 				aRg.nEnd = pTmp->nEnd;
95 				bEnde = sal_False;
96 				Remove( nPos, 1 );		// zusammenfassen
97 			}
98 
99 			// SSelection im Bereich ??
100 			else if( pTmp->nStart <= aRg.nStart && aRg.nEnd <= pTmp->nEnd )
101 				return;
102 		}
103 	} while( !bEnde );
104 
105 	_SwPamRanges::Insert( aRg );
106 }
107 
108 
109 
110 SwPaM& SwPamRanges::SetPam( sal_uInt16 nArrPos, SwPaM& rPam )
111 {
112 	ASSERT_ID( nArrPos < Count(), ERR_VAR_IDX );
113 	const SwPamRange& rTmp = *(GetData() + nArrPos );
114 	rPam.GetPoint()->nNode = rTmp.nStart;
115 	rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
116 	rPam.SetMark();
117 	rPam.GetPoint()->nNode = rTmp.nEnd;
118 	rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
119 	return rPam;
120 }
121 
122 
123 
124 // Numerierung Outline Regelwerk
125 
126 
127 void SwEditShell::SetOutlineNumRule(const SwNumRule& rRule)
128 {
129 	StartAllAction();		// Klammern fuers Updaten !!
130 	GetDoc()->SetOutlineNumRule(rRule);
131 	EndAllAction();
132 }
133 
134 
135 const SwNumRule* SwEditShell::GetOutlineNumRule() const
136 {
137 	return GetDoc()->GetOutlineNumRule();
138 }
139 
140 // setzt, wenn noch keine Numerierung, sonst wird geaendert
141 // arbeitet mit alten und neuen Regeln, nur Differenzen aktualisieren
142 
143 // Absaetze ohne Numerierung, aber mit Einzuegen
144 
145 sal_Bool SwEditShell::NoNum()
146 {
147 	sal_Bool bRet = sal_True;
148 	StartAllAction();
149 
150 	SwPaM* pCrsr = GetCrsr();
151 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
152     {
153         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
154 		SwPamRanges aRangeArr( *pCrsr );
155 		SwPaM aPam( *pCrsr->GetPoint() );
156 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
157 			bRet = bRet && GetDoc()->NoNum( aRangeArr.SetPam( n, aPam ));
158         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
159     }
160     else
161 		bRet = GetDoc()->NoNum( *pCrsr );
162 
163 	EndAllAction();
164 	return bRet;
165 }
166 // Loeschen, Splitten der Aufzaehlungsliste
167 sal_Bool SwEditShell::SelectionHasNumber() const
168 {
169     sal_Bool bResult = HasNumber();
170     const SwTxtNode * pTxtNd =
171         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
172 	if (!bResult && pTxtNd && pTxtNd->Len()==0 && !pTxtNd->GetNumRule()) {
173 		SwPamRanges aRangeArr( *GetCrsr() );
174 		SwPaM aPam( *GetCrsr()->GetPoint() );
175 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
176         {
177             aRangeArr.SetPam( n, aPam );
178 			{
179 					sal_uInt32 nStt = aPam.GetPoint()->nNode.GetIndex(),
180 						  nEnd = aPam.GetMark()->nNode.GetIndex();
181 					if( nStt > nEnd )
182 					{
183 						sal_uInt32 nTmp = nStt; nStt = nEnd; nEnd = nTmp;
184 					}
185 					for (sal_uInt32 nPos = nStt; nPos<=nEnd; nPos++) {
186 						SwTxtNode * pTxtNd = pDoc->GetNodes()[nPos]->GetTxtNode();
187 						if (pTxtNd && pTxtNd->Len()!=0)
188 						{
189 							bResult = pTxtNd->HasNumber();
190 
191 							// --> OD 2005-10-26 #b6340308#
192 							// special case: outline numbered, not counted paragraph
193 							if ( bResult &&
194 								pTxtNd->GetNumRule() == GetDoc()->GetOutlineNumRule() &&
195 								!pTxtNd->IsCountedInList() )
196 							{
197 								bResult = sal_False;
198 							}
199 							if (bResult==sal_False) {
200 								break;
201 							}
202 							// <--
203 						}
204 					}
205 			}
206         }
207 
208 	}
209 
210     return bResult;
211 }
212 //Sym3_879 add a new function to determine number on/off status
213 sal_Bool SwEditShell::SelectionHasBullet() const
214 {
215     sal_Bool bResult = HasBullet();
216     const SwTxtNode * pTxtNd =
217         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
218 	if (!bResult && pTxtNd && pTxtNd->Len()==0 && !pTxtNd->GetNumRule()) {
219 		SwPamRanges aRangeArr( *GetCrsr() );
220 		SwPaM aPam( *GetCrsr()->GetPoint() );
221 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
222         {
223             aRangeArr.SetPam( n, aPam );
224 			{
225 					sal_uInt32 nStt = aPam.GetPoint()->nNode.GetIndex(),
226 						  nEnd = aPam.GetMark()->nNode.GetIndex();
227 					if( nStt > nEnd )
228 					{
229 						sal_uInt32 nTmp = nStt; nStt = nEnd; nEnd = nTmp;
230 					}
231 					for (sal_uInt32 nPos = nStt; nPos<=nEnd; nPos++) {
232 						SwTxtNode * pTxtNd = pDoc->GetNodes()[nPos]->GetTxtNode();
233 						if (pTxtNd && pTxtNd->Len()!=0)
234 						{
235 					        bResult = pTxtNd->HasBullet();
236 
237 							if (bResult==sal_False) {
238 								break;
239 							}
240 						}
241 					}
242 			}
243         }
244 
245 	}
246 
247     return bResult;
248 }
249 // -> #i29560#
250 sal_Bool SwEditShell::HasNumber() const
251 {
252     sal_Bool bResult = sal_False;
253 
254     const SwTxtNode * pTxtNd =
255         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
256 
257     if (pTxtNd)
258     {
259         bResult = pTxtNd->HasNumber();
260 
261         // --> OD 2005-10-26 #b6340308#
262         // special case: outline numbered, not counted paragraph
263         if ( bResult &&
264              pTxtNd->GetNumRule() == GetDoc()->GetOutlineNumRule() &&
265              !pTxtNd->IsCountedInList() )
266         {
267             bResult = sal_False;
268         }
269         // <--
270     }
271 
272     return bResult;
273 }
274 
275 sal_Bool SwEditShell::HasBullet() const
276 {
277     sal_Bool bResult = sal_False;
278 
279     const SwTxtNode * pTxtNd =
280         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
281 
282     if (pTxtNd)
283     {
284         bResult = pTxtNd->HasBullet();
285     }
286 
287     return bResult;
288 }
289 // <- #i29560#
290 
291 void SwEditShell::DelNumRules()
292 {
293 	StartAllAction();
294 
295 	SwPaM* pCrsr = GetCrsr();
296 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
297     {
298         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
299 		SwPamRanges aRangeArr( *pCrsr );
300 		SwPaM aPam( *pCrsr->GetPoint() );
301 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
302         {
303             GetDoc()->DelNumRules( aRangeArr.SetPam( n, aPam ) );
304         }
305         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
306     }
307     else
308         GetDoc()->DelNumRules( *pCrsr );
309 
310 	// rufe das AttrChangeNotify auf der UI-Seite. Sollte eigentlich
311 	// ueberfluessig sein, aber VB hatte darueber eine Bugrep.
312 	CallChgLnk();
313 
314     // --> OD 2005-10-24 #126346# - cursor can not be anymore in
315     // front of a label, because numbering/bullet is deleted.
316     SetInFrontOfLabel( sal_False );
317     // <--
318 
319 	GetDoc()->SetModified();
320 	EndAllAction();
321 }
322 
323 // Hoch-/Runterstufen
324 
325 
326 sal_Bool SwEditShell::NumUpDown( sal_Bool bDown )
327 {
328 	StartAllAction();
329 
330 	sal_Bool bRet = sal_True;
331 	SwPaM* pCrsr = GetCrsr();
332 	if( pCrsr->GetNext() == pCrsr )			// keine Mehrfachselektion ?
333 		bRet = GetDoc()->NumUpDown( *pCrsr, bDown );
334     else
335     {
336         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
337 		SwPamRanges aRangeArr( *pCrsr );
338 		SwPaM aPam( *pCrsr->GetPoint() );
339 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
340 			bRet = bRet && GetDoc()->NumUpDown( aRangeArr.SetPam( n, aPam ), bDown );
341         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
342     }
343 	GetDoc()->SetModified();
344 
345     // --> FME 2005-09-19 #i54693# Update marked numbering levels
346     if ( IsInFrontOfLabel() )
347         UpdateMarkedListLevel();
348     // <--
349 
350     CallChgLnk();
351 
352 	EndAllAction();
353 	return bRet;
354 }
355 // -> #i23726#
356 sal_Bool SwEditShell::IsFirstOfNumRule() const
357 {
358     sal_Bool bResult = sal_False;
359 
360     SwPaM * pCrsr = GetCrsr();
361     if (pCrsr->GetNext() == pCrsr)
362     {
363         bResult = IsFirstOfNumRule(*pCrsr);
364     }
365 
366     return bResult;
367 }
368 
369 sal_Bool SwEditShell::IsFirstOfNumRule(const SwPaM & rPaM) const
370 {
371     sal_Bool bResult = sal_False;
372 
373     SwPosition aPos(*rPaM.GetPoint());
374     bResult = GetDoc()->IsFirstOfNumRule(aPos);
375 
376     return bResult;
377 }
378 // <- #i23726#
379 
380 // -> #i23725#
381 // --> OD 2008-06-09 #i90078#
382 // Remove unused default parameter <nLevel> and <bRelative>.
383 // Adjust method name and parameter name
384 void SwEditShell::ChangeIndentOfAllListLevels( short nDiff )
385 {
386     StartAllAction();
387 
388     const SwNumRule *pCurNumRule = GetCurNumRule();
389     //#120911# check if numbering rule really exists
390     if (pCurNumRule)
391     {
392         SwNumRule aRule(*pCurNumRule);
393         // --> OD 2008-06-09 #i90078#
394         aRule.ChangeIndent( nDiff );
395         // <--
396 
397         // --> OD 2008-03-17 #refactorlists#
398         // no start of new list
399         SetCurNumRule( aRule, false );
400         // <--
401     }
402 
403     EndAllAction();
404 }
405 
406 // --> OD 2008-06-09 #i90078#
407 // Adjust method name
408 void SwEditShell::SetIndent(short nIndent, const SwPosition & rPos)
409 // <--
410 {
411     StartAllAction();
412 
413     SwNumRule *pCurNumRule = GetDoc()->GetCurrNumRule(rPos);
414 
415     if (pCurNumRule)
416     {
417         SwPaM aPaM(rPos);
418         SwTxtNode * pTxtNode = aPaM.GetNode()->GetTxtNode();
419 
420         // --> OD 2008-06-09 #i90078#
421 //        int nLevel = -1;
422 //        int nReferenceLevel = pTxtNode->GetActualListLevel();
423 //        if (! IsFirstOfNumRule(aPaM))
424 //            nLevel = nReferenceLevel;
425 
426         SwNumRule aRule(*pCurNumRule);
427 //        aRule.ChangeIndent(nIndent, nLevel, nReferenceLevel, sal_False);
428         if ( IsFirstOfNumRule() )
429         {
430             aRule.SetIndentOfFirstListLevelAndChangeOthers( nIndent );
431         }
432         else if ( pTxtNode->GetActualListLevel() >= 0  )
433         {
434             aRule.SetIndent( nIndent,
435                              static_cast<sal_uInt16>(pTxtNode->GetActualListLevel()) );
436         }
437         // <--
438 
439         // --> OD 2005-02-18 #i42921# - 3rd parameter = false in order to
440         // suppress setting of num rule at <aPaM>.
441         // --> OD 2008-03-17 #refactorlists#
442         // do not apply any list
443         GetDoc()->SetNumRule( aPaM, aRule, false, String(), sal_False );
444         // <--
445     }
446 
447     EndAllAction();
448 }
449 // <- #i23725#
450 
451 sal_Bool SwEditShell::MoveParagraph( long nOffset )
452 {
453 	StartAllAction();
454 
455 	SwPaM *pCrsr = GetCrsr();
456 	if( !pCrsr->HasMark() )
457 	{
458 		// sorge dafuer, das Bound1 und Bound2 im gleichen Node stehen
459 		pCrsr->SetMark();
460 		pCrsr->DeleteMark();
461 	}
462 
463 	sal_Bool bRet = GetDoc()->MoveParagraph( *pCrsr, nOffset );
464 
465 	GetDoc()->SetModified();
466 	EndAllAction();
467 	return bRet;
468 }
469 
470 //#outline level add by zhaojianwei
471 int SwEditShell::GetCurrentParaOutlineLevel( ) const
472 {
473 	int nLevel = 0;
474 
475 	SwPaM* pCrsr = GetCrsr();
476 	const SwTxtNode* pTxtNd = pCrsr->GetNode()->GetTxtNode();
477 	if( pTxtNd )
478 		nLevel = pTxtNd->GetAttrOutlineLevel();
479 	return nLevel;
480 }
481 //<-end,zhaojianwei
482 
483 void SwEditShell::GetCurrentOutlineLevels( sal_uInt8& rUpper, sal_uInt8& rLower )
484 {
485     SwPaM* pCrsr = GetCrsr();
486 	SwPaM aCrsr( *pCrsr->Start() );
487 	aCrsr.SetMark();
488 	if( pCrsr->HasMark() )
489 		*aCrsr.GetPoint() = *pCrsr->End();
490     GetDoc()->GotoNextNum( *aCrsr.GetPoint(), sal_False,
491                             &rUpper, &rLower );
492 }
493 
494 sal_Bool SwEditShell::MoveNumParas( sal_Bool bUpperLower, sal_Bool bUpperLeft )
495 {
496 	StartAllAction();
497 
498 	// auf alle Selektionen ??
499 	SwPaM* pCrsr = GetCrsr();
500 	SwPaM aCrsr( *pCrsr->Start() );
501 	aCrsr.SetMark();
502 
503 	if( pCrsr->HasMark() )
504 		*aCrsr.GetPoint() = *pCrsr->End();
505 
506 	sal_Bool bRet = sal_False;
507 	sal_uInt8 nUpperLevel, nLowerLevel;
508 	if( GetDoc()->GotoNextNum( *aCrsr.GetPoint(), sal_False,
509 								&nUpperLevel, &nLowerLevel ))
510 	{
511 		if( bUpperLower )
512 		{
513 			// ueber die naechste Nummerierung
514 			long nOffset = 0;
515 			const SwNode* pNd;
516 
517 			if( bUpperLeft )		// verschiebe nach oben
518 			{
519 				SwPosition aPos( *aCrsr.GetMark() );
520 				if( GetDoc()->GotoPrevNum( aPos, sal_False ) )
521 					nOffset = aPos.nNode.GetIndex() -
522 							aCrsr.GetMark()->nNode.GetIndex();
523 				else
524 				{
525 					sal_uLong nStt = aPos.nNode.GetIndex(), nIdx = nStt - 1;
526 					while( nIdx && (
527 						( pNd = GetDoc()->GetNodes()[ nIdx ])->IsSectionNode() ||
528                         ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsSectionNode())))
529 						--nIdx;
530 					if( GetDoc()->GetNodes()[ nIdx ]->IsTxtNode() )
531 						nOffset = nIdx - nStt;
532 				}
533 			}
534 			else					// verschiebe nach unten
535 			{
536 				const SwNumRule* pOrig = aCrsr.GetNode(sal_False)->GetTxtNode()->GetNumRule();
537 				if( aCrsr.GetNode()->IsTxtNode() &&
538 					pOrig == aCrsr.GetNode()->GetTxtNode()->GetNumRule() )
539 				{
540 					sal_uLong nStt = aCrsr.GetPoint()->nNode.GetIndex(), nIdx = nStt+1;
541 
542                     while (nIdx < GetDoc()->GetNodes().Count()-1)
543                     {
544                         pNd = GetDoc()->GetNodes()[ nIdx ];
545 
546                         if (pNd->IsSectionNode() ||
547                             ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsSectionNode()) ||
548                             ( pNd->IsTxtNode() && pOrig == ((SwTxtNode*)pNd)->GetNumRule() &&
549                               ((SwTxtNode*)pNd)->GetActualListLevel() > nUpperLevel ))
550                         {
551                             ++nIdx;
552                         }
553                         // --> OD 2005-11-14 #i57856#
554                         else
555                         {
556                             break;
557                         }
558                         // <--
559                     }
560 
561 					if( nStt == nIdx || !GetDoc()->GetNodes()[ nIdx ]->IsTxtNode() )
562 						nOffset = 1;
563 					else
564 						nOffset = nIdx - nStt;
565 				}
566 				else
567 					nOffset = 1;
568 			}
569 
570 			if( nOffset )
571 			{
572 				aCrsr.Move( fnMoveBackward, fnGoNode );
573 				bRet = GetDoc()->MoveParagraph( aCrsr, nOffset );
574 			}
575 		}
576 		else if( bUpperLeft ? nUpperLevel : nLowerLevel+1 < MAXLEVEL )
577 		{
578 			aCrsr.Move( fnMoveBackward, fnGoNode );
579 			bRet = GetDoc()->NumUpDown( aCrsr, !bUpperLeft );
580 		}
581 	}
582 
583 	GetDoc()->SetModified();
584 	EndAllAction();
585 	return bRet;
586 }
587 
588 sal_Bool SwEditShell::OutlineUpDown( short nOffset )
589 {
590 	StartAllAction();
591 
592 	sal_Bool bRet = sal_True;
593 	SwPaM* pCrsr = GetCrsr();
594 	if( pCrsr->GetNext() == pCrsr )			// keine Mehrfachselektion ?
595 		bRet = GetDoc()->OutlineUpDown( *pCrsr, nOffset );
596     else
597     {
598         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
599 		SwPamRanges aRangeArr( *pCrsr );
600 		SwPaM aPam( *pCrsr->GetPoint() );
601 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
602 			bRet = bRet && GetDoc()->OutlineUpDown(
603 									aRangeArr.SetPam( n, aPam ), nOffset );
604         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
605     }
606 	GetDoc()->SetModified();
607 	EndAllAction();
608 	return bRet;
609 }
610 
611 
612 sal_Bool SwEditShell::MoveOutlinePara( short nOffset )
613 {
614 	StartAllAction();
615 	sal_Bool bRet = GetDoc()->MoveOutlinePara( *GetCrsr(), nOffset );
616 	EndAllAction();
617 	return bRet;
618 }
619 
620 // Outlines and SubOutline are ReadOnly?
621 sal_Bool SwEditShell::IsProtectedOutlinePara() const
622 {
623 	sal_Bool bRet = sal_False;
624 	const SwNode& rNd = GetCrsr()->Start()->nNode.GetNode();
625 	if( rNd.IsTxtNode() )
626 	{
627 		const SwOutlineNodes& rOutlNd = GetDoc()->GetNodes().GetOutLineNds();
628 		SwNodePtr pNd = (SwNodePtr)&rNd;
629 		sal_Bool bFirst = sal_True;
630 		sal_uInt16 nPos;
631         int nLvl(0);
632 		if( !rOutlNd.Seek_Entry( pNd, &nPos ) && nPos )
633 			--nPos;
634 
635 		for( ; nPos < rOutlNd.Count(); ++nPos )
636 		{
637             SwNodePtr pTmpNd = rOutlNd[ nPos ];
638 
639 			// --> OD 2008-04-02 #refactorlists#
640 //            sal_uInt8 nTmpLvl = GetRealLevel( pTmpNd->GetTxtNode()->
641 //                                    GetTxtColl()->GetOutlineLevel() );
642  //           int nTmpLvl = pTmpNd->GetTxtNode()->GetOutlineLevel();//#outline level,zhaojianwei
643             int nTmpLvl = pTmpNd->GetTxtNode()->GetAttrOutlineLevel();
644  //           ASSERT( nTmpLvl >= 0 && nTmpLvl < MAXLEVEL,
645             ASSERT( nTmpLvl >= 0 && nTmpLvl <= MAXLEVEL,			//<-end,zhaojianwei
646                     "<SwEditShell::IsProtectedOutlinePara()>" );
647             // <--
648 			if( bFirst )
649 			{
650 				nLvl = nTmpLvl;
651 				bFirst = sal_False;
652 			}
653 			else if( nLvl >= nTmpLvl )
654 				break;
655 
656             if( pTmpNd->IsProtect() )
657 			{
658 				bRet = sal_True;
659 				break;
660 			}
661 		}
662 	}
663 #ifdef DBG_UTIL
664 	else
665 	{
666 		ASSERT(!this, "Cursor not on an outline node" );
667 	}
668 #endif
669 	return bRet;
670 }
671 
672 /** Test whether outline may be moved (bCopy == false)
673  *                           or copied (bCopy == true)
674  * Verify these conditions:
675  * 1) outline must be within main body (and not in redline)
676  * 2) outline must not be within table
677  * 3) if bCopy is set, outline must not be write protected
678  */
679 sal_Bool lcl_IsOutlineMoveAndCopyable( const SwDoc* pDoc, sal_uInt16 nIdx, bool bCopy )
680 {
681 	const SwNodes& rNds = pDoc->GetNodes();
682     const SwNode* pNd = rNds.GetOutLineNds()[ nIdx ];
683     return pNd->GetIndex() >= rNds.GetEndOfExtras().GetIndex() &&   // 1) body
684             !pNd->FindTableNode() &&                                // 2) table
685             ( bCopy || !pNd->IsProtect() );                         // 3) write
686 }
687 
688 sal_Bool SwEditShell::IsOutlineMovable( sal_uInt16 nIdx ) const
689 {
690     return lcl_IsOutlineMoveAndCopyable( GetDoc(), nIdx, false );
691 }
692 
693 sal_Bool SwEditShell::IsOutlineCopyable( sal_uInt16 nIdx ) const
694 {
695     return lcl_IsOutlineMoveAndCopyable( GetDoc(), nIdx, true );
696 }
697 
698 
699 sal_Bool SwEditShell::NumOrNoNum( sal_Bool bNumOn, sal_Bool bChkStart ) // #115901#
700 {
701 	sal_Bool bRet = sal_False;
702 	SwPaM* pCrsr = GetCrsr();
703 	if( pCrsr->GetNext() == pCrsr && !pCrsr->HasMark() &&
704 		( !bChkStart || !pCrsr->GetPoint()->nContent.GetIndex()) )
705 	{
706 		StartAllAction();		// Klammern fuers Updaten !!
707         // #115901#
708 		bRet = GetDoc()->NumOrNoNum( pCrsr->GetPoint()->nNode, !bNumOn ); // #i29560#
709 		EndAllAction();
710 	}
711 	return bRet;
712 }
713 
714 sal_Bool SwEditShell::IsNoNum( sal_Bool bChkStart ) const
715 {
716 	// ein Backspace im Absatz ohne Nummer wird zum Delete
717     sal_Bool bResult = sal_False;
718 	SwPaM* pCrsr = GetCrsr();
719 
720     if (pCrsr->GetNext() == pCrsr && !pCrsr->HasMark() &&
721 		(!bChkStart || !pCrsr->GetPoint()->nContent.GetIndex()))
722     {
723         const SwTxtNode* pTxtNd = pCrsr->GetNode()->GetTxtNode();
724 
725         if (pTxtNd)
726         {
727             bResult =  ! pTxtNd->IsCountedInList();
728         }
729     }
730 
731     return bResult;
732 }
733 
734 // --> OD 2008-02-29 #refactorlists# - removed <pHasChilds>
735 sal_uInt8 SwEditShell::GetNumLevel() const
736 {
737 	// gebe die akt. Ebene zurueck, auf der sich der Point vom Cursor befindet
738 	//sal_uInt8 nLevel = NO_NUMBERING;	//#outline level,zhaojianwei
739 	sal_uInt8 nLevel = MAXLEVEL;		//end,zhaojianwei
740 
741 	SwPaM* pCrsr = GetCrsr();
742 	const SwTxtNode* pTxtNd = pCrsr->GetNode()->GetTxtNode();
743 
744     // --> FME 2005-09-12 #124972# Made code robust:
745     ASSERT( pTxtNd, "GetNumLevel() without text node" )
746     if ( !pTxtNd )
747         return nLevel;
748     // <--
749 
750 	const SwNumRule* pRule = pTxtNd->GetNumRule();
751 	if(pRule)
752 	{
753         // --> OD 2008-05-09 #refactorlists#
754         const int nListLevelOfTxtNode( pTxtNd->GetActualListLevel() );
755         if ( nListLevelOfTxtNode >= 0 )
756         {
757             nLevel = static_cast<sal_uInt8>( nListLevelOfTxtNode );
758         }
759         // <--
760 	}
761 
762 	return nLevel;
763 }
764 
765 const SwNumRule* SwEditShell::GetCurNumRule() const
766 {
767 	return GetDoc()->GetCurrNumRule( *GetCrsr()->GetPoint() );
768 }
769 
770 // OD 2008-02-08 #newlistlevelattrs# - add handling of parameter <bResetIndentAttrs>
771 // --> OD 2008-03-17 #refactorlists#
772 void SwEditShell::SetCurNumRule( const SwNumRule& rRule,
773                                  const bool bCreateNewList,
774                                  const String sContinuedListId,
775                                  const bool bResetIndentAttrs )
776 {
777 	StartAllAction();
778 
779     GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
780 
781 	SwPaM* pCrsr = GetCrsr();
782 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
783     {
784 		SwPamRanges aRangeArr( *pCrsr );
785 		SwPaM aPam( *pCrsr->GetPoint() );
786 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
787 		  {
788 		    aRangeArr.SetPam( n, aPam );
789             // --> OD 2008-02-08 #newlistlevelattrs#
790             // --> OD 2008-03-17 #refactorlists#
791             GetDoc()->SetNumRule( aPam, rRule,
792                                   bCreateNewList, sContinuedListId,
793                                   sal_True, bResetIndentAttrs );
794             // <--
795 		    GetDoc()->SetCounted( aPam, true );
796           }
797     }
798     else
799     {
800         // --> OD 2008-02-08 #newlistlevelattrs#
801         // --> OD 2008-03-17 #refactorlists#
802         GetDoc()->SetNumRule( *pCrsr, rRule,
803                               bCreateNewList, sContinuedListId,
804                               sal_True, bResetIndentAttrs );
805         GetDoc()->SetCounted( *pCrsr, true );
806     }
807     GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
808 
809 	EndAllAction();
810 }
811 
812 String SwEditShell::GetUniqueNumRuleName( const String* pChkStr, sal_Bool bAutoNum ) const
813 {
814 	return GetDoc()->GetUniqueNumRuleName( pChkStr, bAutoNum );
815 }
816 
817 void SwEditShell::ChgNumRuleFmts( const SwNumRule& rRule )
818 {
819 	StartAllAction();
820 	GetDoc()->ChgNumRuleFmts( rRule );
821 	EndAllAction();
822 }
823 
824 sal_Bool SwEditShell::ReplaceNumRule( const String& rOldRule, const String& rNewRule )
825 {
826 	StartAllAction();
827 	sal_Bool bRet = GetDoc()->ReplaceNumRule( *GetCrsr()->GetPoint(), rOldRule, rNewRule );
828 	EndAllAction();
829 	return bRet;
830 }
831 
832 void SwEditShell::SetNumRuleStart( sal_Bool bFlag )
833 {
834 	StartAllAction();
835 
836 	SwPaM* pCrsr = GetCrsr();
837 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
838     {
839         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
840 		SwPamRanges aRangeArr( *pCrsr );
841 		SwPaM aPam( *pCrsr->GetPoint() );
842 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
843 			GetDoc()->SetNumRuleStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), bFlag );
844         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
845     }
846     else
847 		GetDoc()->SetNumRuleStart( *pCrsr->GetPoint(), bFlag );
848 
849 	EndAllAction();
850 }
851 
852 sal_Bool SwEditShell::IsNumRuleStart() const
853 {
854     sal_Bool bResult = sal_False;
855 	const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
856 	if( pTxtNd )
857         bResult = pTxtNd->IsListRestart() ? sal_True : sal_False;
858 	return bResult;
859 }
860 
861 void SwEditShell::SetNodeNumStart( sal_uInt16 nStt )
862 {
863 	StartAllAction();
864 
865 	SwPaM* pCrsr = GetCrsr();
866 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
867     {
868         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
869 		SwPamRanges aRangeArr( *pCrsr );
870 		SwPaM aPam( *pCrsr->GetPoint() );
871 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
872 			GetDoc()->SetNodeNumStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), nStt );
873         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
874     }
875     else
876 		GetDoc()->SetNodeNumStart( *pCrsr->GetPoint(), nStt );
877 
878 	EndAllAction();
879 }
880 
881 sal_uInt16 SwEditShell::GetNodeNumStart() const
882 {
883 	const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
884     // --> OD 2008-02-28 #refactorlists#
885     // correction: check, if list restart value is set at text node and
886     // use new method <SwTxtNode::GetAttrListRestartValue()>.
887     // return USHRT_MAX, if no list restart value is found.
888     if ( pTxtNd && pTxtNd->HasAttrListRestartValue() )
889     {
890         return static_cast<sal_uInt16>(pTxtNd->GetAttrListRestartValue());
891     }
892     return USHRT_MAX;
893     // <--
894 }
895 
896 /*-- 26.08.2005 14:47:17---------------------------------------------------
897 
898   -----------------------------------------------------------------------*/
899 // --> OD 2008-03-18 #refactorlists#
900 const SwNumRule * SwEditShell::SearchNumRule( const bool bForward,
901                                               const bool bNum,
902                                               const bool bOutline,
903                                               int nNonEmptyAllowed,
904                                               String& sListId )
905 {
906     return GetDoc()->SearchNumRule( *(bForward ? GetCrsr()->End() : GetCrsr()->Start()),
907                                     bForward, bNum, bOutline, nNonEmptyAllowed,
908                                     sListId );
909 }
910 // <--
911