xref: /aoo4110/main/sw/source/core/edit/ednumber.cxx (revision b1cdbd2c)
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 
SV_IMPL_VARARR_SORT(_SwPamRanges,SwPamRange)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 
Insert(const SwNodeIndex & rIdx1,const SwNodeIndex & rIdx2)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 
SetPam(sal_uInt16 nArrPos,SwPaM & rPam)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 
SetOutlineNumRule(const SwNumRule & rRule)127 void SwEditShell::SetOutlineNumRule(const SwNumRule& rRule)
128 {
129 	StartAllAction();		// Klammern fuers Updaten !!
130 	GetDoc()->SetOutlineNumRule(rRule);
131 	EndAllAction();
132 }
133 
134 
GetOutlineNumRule() const135 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 
NoNum()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
SelectionHasNumber() const167 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 //add a new function to determine number on/off status
SelectionHasBullet() const213 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#
HasNumber() const250 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 
HasBullet() const275 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 
DelNumRules()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 
NumUpDown(sal_Bool bDown)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#
IsFirstOfNumRule() const356 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 
IsFirstOfNumRule(const SwPaM & rPaM) const369 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
ChangeIndentOfAllListLevels(short nDiff)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
SetIndent(short nIndent,const SwPosition & rPos)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 
MoveParagraph(long nOffset)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
GetCurrentParaOutlineLevel() const471 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 
GetCurrentOutlineLevels(sal_uInt8 & rUpper,sal_uInt8 & rLower)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 
MoveNumParas(sal_Bool bUpperLower,sal_Bool bUpperLeft)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 
OutlineUpDown(short nOffset)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 
MoveOutlinePara(short nOffset)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?
IsProtectedOutlinePara() const621 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  */
lcl_IsOutlineMoveAndCopyable(const SwDoc * pDoc,sal_uInt16 nIdx,bool bCopy)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 
IsOutlineMovable(sal_uInt16 nIdx) const688 sal_Bool SwEditShell::IsOutlineMovable( sal_uInt16 nIdx ) const
689 {
690     return lcl_IsOutlineMoveAndCopyable( GetDoc(), nIdx, false );
691 }
692 
IsOutlineCopyable(sal_uInt16 nIdx) const693 sal_Bool SwEditShell::IsOutlineCopyable( sal_uInt16 nIdx ) const
694 {
695     return lcl_IsOutlineMoveAndCopyable( GetDoc(), nIdx, true );
696 }
697 
698 
NumOrNoNum(sal_Bool bNumOn,sal_Bool bChkStart)699 sal_Bool SwEditShell::NumOrNoNum(
700     sal_Bool bNumOn,
701     sal_Bool bChkStart )
702 {
703     sal_Bool bRet = sal_False;
704 
705     if ( !IsMultiSelection()
706          && !HasSelection()
707          && ( !bChkStart || IsSttPara() ) )
708     {
709         StartAllAction();
710         bRet = GetDoc()->NumOrNoNum( GetCrsr()->GetPoint()->nNode, !bNumOn );
711         EndAllAction();
712     }
713     return bRet;
714 }
715 
716 
IsNoNum(sal_Bool bChkStart) const717 sal_Bool SwEditShell::IsNoNum( sal_Bool bChkStart ) const
718 {
719     sal_Bool bResult = sal_False;
720 
721     if ( !IsMultiSelection()
722          && !HasSelection()
723          && ( !bChkStart || IsSttPara() ) )
724     {
725         const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
726         if ( pTxtNd != NULL )
727         {
728             bResult =  !pTxtNd->IsCountedInList();
729         }
730     }
731 
732     return bResult;
733 }
734 
GetNumLevel() const735 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     ASSERT( pTxtNd != NULL, "GetNumLevel() without text node" )
745     if ( pTxtNd == NULL )
746         return nLevel;
747 
748     const SwNumRule* pRule = pTxtNd->GetNumRule();
749     if ( pRule != NULL )
750     {
751         const int nListLevelOfTxtNode( pTxtNd->GetActualListLevel() );
752         if ( nListLevelOfTxtNode >= 0 )
753         {
754             nLevel = static_cast<sal_uInt8>( nListLevelOfTxtNode );
755         }
756     }
757 
758     return nLevel;
759 }
760 
GetCurNumRule() const761 const SwNumRule* SwEditShell::GetCurNumRule() const
762 {
763 	return GetDoc()->GetCurrNumRule( *GetCrsr()->GetPoint() );
764 }
765 
766 // OD 2008-02-08 #newlistlevelattrs# - add handling of parameter <bResetIndentAttrs>
767 // --> OD 2008-03-17 #refactorlists#
SetCurNumRule(const SwNumRule & rRule,const bool bCreateNewList,const String sContinuedListId,const bool bResetIndentAttrs)768 void SwEditShell::SetCurNumRule( const SwNumRule& rRule,
769                                  const bool bCreateNewList,
770                                  const String sContinuedListId,
771                                  const bool bResetIndentAttrs )
772 {
773     StartAllAction();
774 
775     GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
776 
777     SwPaM* pCrsr = GetCrsr();
778     if( IsMultiSelection() )
779     {
780         SwPamRanges aRangeArr( *pCrsr );
781         SwPaM aPam( *pCrsr->GetPoint() );
782         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
783         {
784             aRangeArr.SetPam( n, aPam );
785             GetDoc()->SetNumRule( aPam, rRule,
786                                   bCreateNewList, sContinuedListId,
787                                   sal_True, bResetIndentAttrs );
788             GetDoc()->SetCounted( aPam, true );
789         }
790     }
791     else
792     {
793         GetDoc()->SetNumRule( *pCrsr, rRule,
794                               bCreateNewList, sContinuedListId,
795                               sal_True, bResetIndentAttrs );
796         GetDoc()->SetCounted( *pCrsr, true );
797     }
798     GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
799 
800     EndAllAction();
801 }
802 
GetUniqueNumRuleName(const String * pChkStr,sal_Bool bAutoNum) const803 String SwEditShell::GetUniqueNumRuleName( const String* pChkStr, sal_Bool bAutoNum ) const
804 {
805 	return GetDoc()->GetUniqueNumRuleName( pChkStr, bAutoNum );
806 }
807 
ChgNumRuleFmts(const SwNumRule & rRule)808 void SwEditShell::ChgNumRuleFmts( const SwNumRule& rRule )
809 {
810 	StartAllAction();
811 	GetDoc()->ChgNumRuleFmts( rRule );
812 	EndAllAction();
813 }
814 
ReplaceNumRule(const String & rOldRule,const String & rNewRule)815 sal_Bool SwEditShell::ReplaceNumRule( const String& rOldRule, const String& rNewRule )
816 {
817 	StartAllAction();
818 	sal_Bool bRet = GetDoc()->ReplaceNumRule( *GetCrsr()->GetPoint(), rOldRule, rNewRule );
819 	EndAllAction();
820 	return bRet;
821 }
822 
SetNumRuleStart(sal_Bool bFlag)823 void SwEditShell::SetNumRuleStart( sal_Bool bFlag )
824 {
825 	StartAllAction();
826 
827 	SwPaM* pCrsr = GetCrsr();
828 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
829     {
830         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
831 		SwPamRanges aRangeArr( *pCrsr );
832 		SwPaM aPam( *pCrsr->GetPoint() );
833 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
834 			GetDoc()->SetNumRuleStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), bFlag );
835         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
836     }
837     else
838 		GetDoc()->SetNumRuleStart( *pCrsr->GetPoint(), bFlag );
839 
840 	EndAllAction();
841 }
842 
IsNumRuleStart() const843 sal_Bool SwEditShell::IsNumRuleStart() const
844 {
845     sal_Bool bResult = sal_False;
846 	const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
847 	if( pTxtNd )
848         bResult = pTxtNd->IsListRestart() ? sal_True : sal_False;
849 	return bResult;
850 }
851 
SetNodeNumStart(sal_uInt16 nStt)852 void SwEditShell::SetNodeNumStart( sal_uInt16 nStt )
853 {
854 	StartAllAction();
855 
856 	SwPaM* pCrsr = GetCrsr();
857 	if( pCrsr->GetNext() != pCrsr )			// Mehrfachselektion ?
858     {
859         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
860 		SwPamRanges aRangeArr( *pCrsr );
861 		SwPaM aPam( *pCrsr->GetPoint() );
862 		for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
863 			GetDoc()->SetNodeNumStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), nStt );
864         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
865     }
866     else
867 		GetDoc()->SetNodeNumStart( *pCrsr->GetPoint(), nStt );
868 
869 	EndAllAction();
870 }
871 
GetNodeNumStart() const872 sal_uInt16 SwEditShell::GetNodeNumStart() const
873 {
874 	const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
875     // --> OD 2008-02-28 #refactorlists#
876     // correction: check, if list restart value is set at text node and
877     // use new method <SwTxtNode::GetAttrListRestartValue()>.
878     // return USHRT_MAX, if no list restart value is found.
879     if ( pTxtNd && pTxtNd->HasAttrListRestartValue() )
880     {
881         return static_cast<sal_uInt16>(pTxtNd->GetAttrListRestartValue());
882     }
883     return USHRT_MAX;
884     // <--
885 }
886 
887 /*-- 26.08.2005 14:47:17---------------------------------------------------
888 
889   -----------------------------------------------------------------------*/
890 // --> OD 2008-03-18 #refactorlists#
SearchNumRule(const bool bForward,const bool bNum,const bool bOutline,int nNonEmptyAllowed,String & sListId)891 const SwNumRule * SwEditShell::SearchNumRule( const bool bForward,
892                                               const bool bNum,
893                                               const bool bOutline,
894                                               int nNonEmptyAllowed,
895                                               String& sListId )
896 {
897     return GetDoc()->SearchNumRule( *(bForward ? GetCrsr()->End() : GetCrsr()->Start()),
898                                     bForward, bNum, bOutline, nNonEmptyAllowed,
899                                     sListId );
900 }
901 // <--
902