xref: /trunk/main/sw/source/core/edit/ednumber.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <hintids.hxx>
29cdf0e10cSrcweir #include <editsh.hxx>
30cdf0e10cSrcweir #include <edimp.hxx>
31cdf0e10cSrcweir #include <doc.hxx>
32cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
33cdf0e10cSrcweir #include <ndtxt.hxx>
34cdf0e10cSrcweir #include <paratr.hxx>
35cdf0e10cSrcweir #include <swundo.hxx>
36cdf0e10cSrcweir #include <numrule.hxx>
37cdf0e10cSrcweir 
SV_IMPL_VARARR_SORT(_SwPamRanges,SwPamRange)38cdf0e10cSrcweir SV_IMPL_VARARR_SORT( _SwPamRanges, SwPamRange )
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir SwPamRanges::SwPamRanges( const SwPaM& rRing )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     const SwPaM* pTmp = &rRing;
44cdf0e10cSrcweir     do {
45cdf0e10cSrcweir         Insert( pTmp->GetMark()->nNode, pTmp->GetPoint()->nNode );
46cdf0e10cSrcweir     } while( &rRing != ( pTmp = (const SwPaM*)pTmp->GetNext() ));
47cdf0e10cSrcweir }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
Insert(const SwNodeIndex & rIdx1,const SwNodeIndex & rIdx2)50cdf0e10cSrcweir void SwPamRanges::Insert( const SwNodeIndex& rIdx1, const SwNodeIndex& rIdx2 )
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     SwPamRange aRg( rIdx1.GetIndex(), rIdx2.GetIndex() );
53cdf0e10cSrcweir     if( aRg.nEnd < aRg.nStart )
54cdf0e10cSrcweir     {   aRg.nStart = aRg.nEnd; aRg.nEnd = rIdx1.GetIndex(); }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     sal_uInt16 nPos = 0;
57cdf0e10cSrcweir     const SwPamRange* pTmp;
58cdf0e10cSrcweir     if( Count() && Seek_Entry( aRg, &nPos ))        // suche Insert Position
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         // ist der im Array stehende kleiner ??
61cdf0e10cSrcweir         if( ( pTmp = GetData()+ nPos )->nEnd < aRg.nEnd )
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             aRg.nEnd = pTmp->nEnd;
64cdf0e10cSrcweir             Remove( nPos, 1 );      // zusammenfassen
65cdf0e10cSrcweir         }
66cdf0e10cSrcweir         else
67cdf0e10cSrcweir             return;     // ende, weil schon alle zusammengefasst waren
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     sal_Bool bEnde;
71cdf0e10cSrcweir     do {
72cdf0e10cSrcweir         bEnde = sal_True;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         // mit dem Vorgaenger zusammenfassen ??
75cdf0e10cSrcweir         if( nPos > 0 )
76cdf0e10cSrcweir         {
77cdf0e10cSrcweir             if( ( pTmp = GetData()+( nPos-1 ))->nEnd == aRg.nStart
78cdf0e10cSrcweir                 || pTmp->nEnd+1 == aRg.nStart )
79cdf0e10cSrcweir             {
80cdf0e10cSrcweir                 aRg.nStart = pTmp->nStart;
81cdf0e10cSrcweir                 bEnde = sal_False;
82cdf0e10cSrcweir                 Remove( --nPos, 1 );        // zusammenfassen
83cdf0e10cSrcweir             }
84cdf0e10cSrcweir             // SSelection im Bereich ??
85cdf0e10cSrcweir             else if( pTmp->nStart <= aRg.nStart && aRg.nEnd <= pTmp->nEnd )
86cdf0e10cSrcweir                 return;
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir             // mit dem Nachfolger zusammenfassen ??
89cdf0e10cSrcweir         if( nPos < Count() )
90cdf0e10cSrcweir         {
91cdf0e10cSrcweir             if( ( pTmp = GetData() + nPos )->nStart == aRg.nEnd ||
92cdf0e10cSrcweir                 pTmp->nStart == aRg.nEnd+1 )
93cdf0e10cSrcweir             {
94cdf0e10cSrcweir                 aRg.nEnd = pTmp->nEnd;
95cdf0e10cSrcweir                 bEnde = sal_False;
96cdf0e10cSrcweir                 Remove( nPos, 1 );      // zusammenfassen
97cdf0e10cSrcweir             }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir             // SSelection im Bereich ??
100cdf0e10cSrcweir             else if( pTmp->nStart <= aRg.nStart && aRg.nEnd <= pTmp->nEnd )
101cdf0e10cSrcweir                 return;
102cdf0e10cSrcweir         }
103cdf0e10cSrcweir     } while( !bEnde );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     _SwPamRanges::Insert( aRg );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
SetPam(sal_uInt16 nArrPos,SwPaM & rPam)110cdf0e10cSrcweir SwPaM& SwPamRanges::SetPam( sal_uInt16 nArrPos, SwPaM& rPam )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     ASSERT_ID( nArrPos < Count(), ERR_VAR_IDX );
113cdf0e10cSrcweir     const SwPamRange& rTmp = *(GetData() + nArrPos );
114cdf0e10cSrcweir     rPam.GetPoint()->nNode = rTmp.nStart;
115cdf0e10cSrcweir     rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
116cdf0e10cSrcweir     rPam.SetMark();
117cdf0e10cSrcweir     rPam.GetPoint()->nNode = rTmp.nEnd;
118cdf0e10cSrcweir     rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), 0 );
119cdf0e10cSrcweir     return rPam;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // Numerierung Outline Regelwerk
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
SetOutlineNumRule(const SwNumRule & rRule)127cdf0e10cSrcweir void SwEditShell::SetOutlineNumRule(const SwNumRule& rRule)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     StartAllAction();       // Klammern fuers Updaten !!
130cdf0e10cSrcweir     GetDoc()->SetOutlineNumRule(rRule);
131cdf0e10cSrcweir     EndAllAction();
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
GetOutlineNumRule() const135cdf0e10cSrcweir const SwNumRule* SwEditShell::GetOutlineNumRule() const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     return GetDoc()->GetOutlineNumRule();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir // setzt, wenn noch keine Numerierung, sonst wird geaendert
141cdf0e10cSrcweir // arbeitet mit alten und neuen Regeln, nur Differenzen aktualisieren
142cdf0e10cSrcweir 
143cdf0e10cSrcweir // Absaetze ohne Numerierung, aber mit Einzuegen
144cdf0e10cSrcweir 
NoNum()145cdf0e10cSrcweir sal_Bool SwEditShell::NoNum()
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     sal_Bool bRet = sal_True;
148cdf0e10cSrcweir     StartAllAction();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
151cdf0e10cSrcweir     if( pCrsr->GetNext() != pCrsr )         // Mehrfachselektion ?
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
154cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
155cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
156cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
157cdf0e10cSrcweir             bRet = bRet && GetDoc()->NoNum( aRangeArr.SetPam( n, aPam ));
158cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir     else
161cdf0e10cSrcweir         bRet = GetDoc()->NoNum( *pCrsr );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir     EndAllAction();
164cdf0e10cSrcweir     return bRet;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir // Loeschen, Splitten der Aufzaehlungsliste
SelectionHasNumber() const1671ff378efSZheng Fan sal_Bool SwEditShell::SelectionHasNumber() const
1681ff378efSZheng Fan {
1691ff378efSZheng Fan     sal_Bool bResult = HasNumber();
1701ff378efSZheng Fan     const SwTxtNode * pTxtNd =
1711ff378efSZheng Fan         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
1721ff378efSZheng Fan     if (!bResult && pTxtNd && pTxtNd->Len()==0 && !pTxtNd->GetNumRule()) {
1731ff378efSZheng Fan         SwPamRanges aRangeArr( *GetCrsr() );
1741ff378efSZheng Fan         SwPaM aPam( *GetCrsr()->GetPoint() );
1751ff378efSZheng Fan         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
1761ff378efSZheng Fan         {
1771ff378efSZheng Fan             aRangeArr.SetPam( n, aPam );
1781ff378efSZheng Fan             {
1791ff378efSZheng Fan                     sal_uInt32 nStt = aPam.GetPoint()->nNode.GetIndex(),
1801ff378efSZheng Fan                           nEnd = aPam.GetMark()->nNode.GetIndex();
1811ff378efSZheng Fan                     if( nStt > nEnd )
1821ff378efSZheng Fan                     {
1831ff378efSZheng Fan                         sal_uInt32 nTmp = nStt; nStt = nEnd; nEnd = nTmp;
1841ff378efSZheng Fan                     }
1851ff378efSZheng Fan                     for (sal_uInt32 nPos = nStt; nPos<=nEnd; nPos++) {
1861ff378efSZheng Fan                         SwTxtNode * pTxtNd = pDoc->GetNodes()[nPos]->GetTxtNode();
1871ff378efSZheng Fan                         if (pTxtNd && pTxtNd->Len()!=0)
1881ff378efSZheng Fan                         {
1891ff378efSZheng Fan                             bResult = pTxtNd->HasNumber();
190cdf0e10cSrcweir 
1911ff378efSZheng Fan                             // --> OD 2005-10-26 #b6340308#
1921ff378efSZheng Fan                             // special case: outline numbered, not counted paragraph
1931ff378efSZheng Fan                             if ( bResult &&
1941ff378efSZheng Fan                                 pTxtNd->GetNumRule() == GetDoc()->GetOutlineNumRule() &&
1951ff378efSZheng Fan                                 !pTxtNd->IsCountedInList() )
1961ff378efSZheng Fan                             {
1971ff378efSZheng Fan                                 bResult = sal_False;
1981ff378efSZheng Fan                             }
1991ff378efSZheng Fan                             if (bResult==sal_False) {
2001ff378efSZheng Fan                                 break;
2011ff378efSZheng Fan                             }
2021ff378efSZheng Fan                             // <--
2031ff378efSZheng Fan                         }
2041ff378efSZheng Fan                     }
2051ff378efSZheng Fan             }
2061ff378efSZheng Fan         }
2071ff378efSZheng Fan 
2081ff378efSZheng Fan     }
2091ff378efSZheng Fan 
2101ff378efSZheng Fan     return bResult;
2111ff378efSZheng Fan }
2120deba7fbSSteve Yin //add a new function to determine number on/off status
SelectionHasBullet() const2131ff378efSZheng Fan sal_Bool SwEditShell::SelectionHasBullet() const
2141ff378efSZheng Fan {
2151ff378efSZheng Fan     sal_Bool bResult = HasBullet();
2161ff378efSZheng Fan     const SwTxtNode * pTxtNd =
2171ff378efSZheng Fan         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
2181ff378efSZheng Fan     if (!bResult && pTxtNd && pTxtNd->Len()==0 && !pTxtNd->GetNumRule()) {
2191ff378efSZheng Fan         SwPamRanges aRangeArr( *GetCrsr() );
2201ff378efSZheng Fan         SwPaM aPam( *GetCrsr()->GetPoint() );
2211ff378efSZheng Fan         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
2221ff378efSZheng Fan         {
2231ff378efSZheng Fan             aRangeArr.SetPam( n, aPam );
2241ff378efSZheng Fan             {
2251ff378efSZheng Fan                     sal_uInt32 nStt = aPam.GetPoint()->nNode.GetIndex(),
2261ff378efSZheng Fan                           nEnd = aPam.GetMark()->nNode.GetIndex();
2271ff378efSZheng Fan                     if( nStt > nEnd )
2281ff378efSZheng Fan                     {
2291ff378efSZheng Fan                         sal_uInt32 nTmp = nStt; nStt = nEnd; nEnd = nTmp;
2301ff378efSZheng Fan                     }
2311ff378efSZheng Fan                     for (sal_uInt32 nPos = nStt; nPos<=nEnd; nPos++) {
2321ff378efSZheng Fan                         SwTxtNode * pTxtNd = pDoc->GetNodes()[nPos]->GetTxtNode();
2331ff378efSZheng Fan                         if (pTxtNd && pTxtNd->Len()!=0)
2341ff378efSZheng Fan                         {
2351ff378efSZheng Fan                             bResult = pTxtNd->HasBullet();
2361ff378efSZheng Fan 
2371ff378efSZheng Fan                             if (bResult==sal_False) {
2381ff378efSZheng Fan                                 break;
2391ff378efSZheng Fan                             }
2401ff378efSZheng Fan                         }
2411ff378efSZheng Fan                     }
2421ff378efSZheng Fan             }
2431ff378efSZheng Fan         }
2441ff378efSZheng Fan 
2451ff378efSZheng Fan     }
2461ff378efSZheng Fan 
2471ff378efSZheng Fan     return bResult;
2481ff378efSZheng Fan }
249cdf0e10cSrcweir // -> #i29560#
HasNumber() const250cdf0e10cSrcweir sal_Bool SwEditShell::HasNumber() const
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     sal_Bool bResult = sal_False;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir     const SwTxtNode * pTxtNd =
255cdf0e10cSrcweir         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     if (pTxtNd)
258cdf0e10cSrcweir     {
259cdf0e10cSrcweir         bResult = pTxtNd->HasNumber();
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         // --> OD 2005-10-26 #b6340308#
262cdf0e10cSrcweir         // special case: outline numbered, not counted paragraph
263cdf0e10cSrcweir         if ( bResult &&
264cdf0e10cSrcweir              pTxtNd->GetNumRule() == GetDoc()->GetOutlineNumRule() &&
265cdf0e10cSrcweir              !pTxtNd->IsCountedInList() )
266cdf0e10cSrcweir         {
267cdf0e10cSrcweir             bResult = sal_False;
268cdf0e10cSrcweir         }
269cdf0e10cSrcweir         // <--
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     return bResult;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
HasBullet() const275cdf0e10cSrcweir sal_Bool SwEditShell::HasBullet() const
276cdf0e10cSrcweir {
277cdf0e10cSrcweir     sal_Bool bResult = sal_False;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     const SwTxtNode * pTxtNd =
280cdf0e10cSrcweir         GetCrsr()->GetPoint()->nNode.GetNode().GetTxtNode();
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     if (pTxtNd)
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir         bResult = pTxtNd->HasBullet();
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     return bResult;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir // <- #i29560#
290cdf0e10cSrcweir 
DelNumRules()291cdf0e10cSrcweir void SwEditShell::DelNumRules()
292cdf0e10cSrcweir {
293cdf0e10cSrcweir     StartAllAction();
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
296cdf0e10cSrcweir     if( pCrsr->GetNext() != pCrsr )         // Mehrfachselektion ?
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
299cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
300cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
301cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
302cdf0e10cSrcweir         {
303cdf0e10cSrcweir             GetDoc()->DelNumRules( aRangeArr.SetPam( n, aPam ) );
304cdf0e10cSrcweir         }
305cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
306cdf0e10cSrcweir     }
307cdf0e10cSrcweir     else
308cdf0e10cSrcweir         GetDoc()->DelNumRules( *pCrsr );
309cdf0e10cSrcweir 
310cdf0e10cSrcweir     // rufe das AttrChangeNotify auf der UI-Seite. Sollte eigentlich
311cdf0e10cSrcweir     // ueberfluessig sein, aber VB hatte darueber eine Bugrep.
312cdf0e10cSrcweir     CallChgLnk();
313cdf0e10cSrcweir 
314cdf0e10cSrcweir     // --> OD 2005-10-24 #126346# - cursor can not be anymore in
315cdf0e10cSrcweir     // front of a label, because numbering/bullet is deleted.
316cdf0e10cSrcweir     SetInFrontOfLabel( sal_False );
317cdf0e10cSrcweir     // <--
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     GetDoc()->SetModified();
320cdf0e10cSrcweir     EndAllAction();
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir // Hoch-/Runterstufen
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 
NumUpDown(sal_Bool bDown)326cdf0e10cSrcweir sal_Bool SwEditShell::NumUpDown( sal_Bool bDown )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     StartAllAction();
329cdf0e10cSrcweir 
330cdf0e10cSrcweir     sal_Bool bRet = sal_True;
331cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
332cdf0e10cSrcweir     if( pCrsr->GetNext() == pCrsr )         // keine Mehrfachselektion ?
333cdf0e10cSrcweir         bRet = GetDoc()->NumUpDown( *pCrsr, bDown );
334cdf0e10cSrcweir     else
335cdf0e10cSrcweir     {
336cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
337cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
338cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
339cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
340cdf0e10cSrcweir             bRet = bRet && GetDoc()->NumUpDown( aRangeArr.SetPam( n, aPam ), bDown );
341cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir     GetDoc()->SetModified();
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     // --> FME 2005-09-19 #i54693# Update marked numbering levels
346cdf0e10cSrcweir     if ( IsInFrontOfLabel() )
347cdf0e10cSrcweir         UpdateMarkedListLevel();
348cdf0e10cSrcweir     // <--
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     CallChgLnk();
351cdf0e10cSrcweir 
352cdf0e10cSrcweir     EndAllAction();
353cdf0e10cSrcweir     return bRet;
354cdf0e10cSrcweir }
355cdf0e10cSrcweir 
35634760e49SOliver-Rainer Wittmann 
IsFirstOfNumRuleAtCrsrPos() const35734760e49SOliver-Rainer Wittmann bool SwEditShell::IsFirstOfNumRuleAtCrsrPos() const
358cdf0e10cSrcweir {
35934760e49SOliver-Rainer Wittmann     return GetDoc()->IsFirstOfNumRuleAtPos( *GetCrsr()->GetPoint() );
360cdf0e10cSrcweir }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 
ChangeIndentOfAllListLevels(const short nDiff)36334760e49SOliver-Rainer Wittmann void SwEditShell::ChangeIndentOfAllListLevels( const short nDiff )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir     StartAllAction();
366cdf0e10cSrcweir 
36734760e49SOliver-Rainer Wittmann     const SwNumRule *pCurNumRule = GetNumRuleAtCurrCrsrPos();
36834760e49SOliver-Rainer Wittmann     if ( pCurNumRule != NULL )
369cdf0e10cSrcweir     {
370cdf0e10cSrcweir         SwNumRule aRule(*pCurNumRule);
371cdf0e10cSrcweir         aRule.ChangeIndent( nDiff );
372cdf0e10cSrcweir 
373cdf0e10cSrcweir         SetCurNumRule( aRule, false );
374cdf0e10cSrcweir     }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     EndAllAction();
377cdf0e10cSrcweir }
378cdf0e10cSrcweir 
37934760e49SOliver-Rainer Wittmann 
SetIndent(short nIndent,const SwPosition & rPos)38034760e49SOliver-Rainer Wittmann void SwEditShell::SetIndent(
38134760e49SOliver-Rainer Wittmann     short nIndent,
38234760e49SOliver-Rainer Wittmann     const SwPosition & rPos )
383cdf0e10cSrcweir {
384cdf0e10cSrcweir     StartAllAction();
385cdf0e10cSrcweir 
38634760e49SOliver-Rainer Wittmann     SwNumRule *pCurNumRule = GetDoc()->GetNumRuleAtPos(rPos);
387cdf0e10cSrcweir 
388cdf0e10cSrcweir     if (pCurNumRule)
389cdf0e10cSrcweir     {
390cdf0e10cSrcweir         SwNumRule aRule(*pCurNumRule);
39134760e49SOliver-Rainer Wittmann         if ( !IsMultiSelection() && IsFirstOfNumRuleAtCrsrPos() )
392cdf0e10cSrcweir         {
393cdf0e10cSrcweir             aRule.SetIndentOfFirstListLevelAndChangeOthers( nIndent );
394cdf0e10cSrcweir         }
39534760e49SOliver-Rainer Wittmann         else
396cdf0e10cSrcweir         {
39734760e49SOliver-Rainer Wittmann             const SwTxtNode* pTxtNode = rPos.nNode.GetNode().GetTxtNode();
39834760e49SOliver-Rainer Wittmann             if ( pTxtNode != NULL
39934760e49SOliver-Rainer Wittmann                  && pTxtNode->GetActualListLevel() >= 0 )
40034760e49SOliver-Rainer Wittmann             {
40134760e49SOliver-Rainer Wittmann                 aRule.SetIndent( nIndent, static_cast< sal_uInt16 >( pTxtNode->GetActualListLevel() ) );
402cdf0e10cSrcweir             }
40334760e49SOliver-Rainer Wittmann         }
404cdf0e10cSrcweir 
40534760e49SOliver-Rainer Wittmann         // change numbering rule - changed numbering rule is not applied at <aPaM>
40634760e49SOliver-Rainer Wittmann         SwPaM aPaM(rPos);
40734760e49SOliver-Rainer Wittmann         GetDoc()->SetNumRule( aPaM, aRule, false, String(), false );
408cdf0e10cSrcweir     }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     EndAllAction();
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
MoveParagraph(long nOffset)413cdf0e10cSrcweir sal_Bool SwEditShell::MoveParagraph( long nOffset )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     StartAllAction();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir     SwPaM *pCrsr = GetCrsr();
418cdf0e10cSrcweir     if( !pCrsr->HasMark() )
419cdf0e10cSrcweir     {
420cdf0e10cSrcweir         // sorge dafuer, das Bound1 und Bound2 im gleichen Node stehen
421cdf0e10cSrcweir         pCrsr->SetMark();
422cdf0e10cSrcweir         pCrsr->DeleteMark();
423cdf0e10cSrcweir     }
424cdf0e10cSrcweir 
425cdf0e10cSrcweir     sal_Bool bRet = GetDoc()->MoveParagraph( *pCrsr, nOffset );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir     GetDoc()->SetModified();
428cdf0e10cSrcweir     EndAllAction();
429cdf0e10cSrcweir     return bRet;
430cdf0e10cSrcweir }
431cdf0e10cSrcweir 
432cdf0e10cSrcweir //#outline level add by zhaojianwei
GetCurrentParaOutlineLevel() const433cdf0e10cSrcweir int SwEditShell::GetCurrentParaOutlineLevel( ) const
434cdf0e10cSrcweir {
435cdf0e10cSrcweir     int nLevel = 0;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
438cdf0e10cSrcweir     const SwTxtNode* pTxtNd = pCrsr->GetNode()->GetTxtNode();
439cdf0e10cSrcweir     if( pTxtNd )
440cdf0e10cSrcweir         nLevel = pTxtNd->GetAttrOutlineLevel();
441cdf0e10cSrcweir     return nLevel;
442cdf0e10cSrcweir }
443cdf0e10cSrcweir //<-end,zhaojianwei
444cdf0e10cSrcweir 
GetCurrentOutlineLevels(sal_uInt8 & rUpper,sal_uInt8 & rLower)445cdf0e10cSrcweir void SwEditShell::GetCurrentOutlineLevels( sal_uInt8& rUpper, sal_uInt8& rLower )
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
448cdf0e10cSrcweir     SwPaM aCrsr( *pCrsr->Start() );
449cdf0e10cSrcweir     aCrsr.SetMark();
450cdf0e10cSrcweir     if( pCrsr->HasMark() )
451cdf0e10cSrcweir         *aCrsr.GetPoint() = *pCrsr->End();
452cdf0e10cSrcweir     GetDoc()->GotoNextNum( *aCrsr.GetPoint(), sal_False,
453cdf0e10cSrcweir                             &rUpper, &rLower );
454cdf0e10cSrcweir }
455cdf0e10cSrcweir 
MoveNumParas(sal_Bool bUpperLower,sal_Bool bUpperLeft)456cdf0e10cSrcweir sal_Bool SwEditShell::MoveNumParas( sal_Bool bUpperLower, sal_Bool bUpperLeft )
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     StartAllAction();
459cdf0e10cSrcweir 
460cdf0e10cSrcweir     // auf alle Selektionen ??
461cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
462cdf0e10cSrcweir     SwPaM aCrsr( *pCrsr->Start() );
463cdf0e10cSrcweir     aCrsr.SetMark();
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     if( pCrsr->HasMark() )
466cdf0e10cSrcweir         *aCrsr.GetPoint() = *pCrsr->End();
467cdf0e10cSrcweir 
468cdf0e10cSrcweir     sal_Bool bRet = sal_False;
469cdf0e10cSrcweir     sal_uInt8 nUpperLevel, nLowerLevel;
470cdf0e10cSrcweir     if( GetDoc()->GotoNextNum( *aCrsr.GetPoint(), sal_False,
471cdf0e10cSrcweir                                 &nUpperLevel, &nLowerLevel ))
472cdf0e10cSrcweir     {
473cdf0e10cSrcweir         if( bUpperLower )
474cdf0e10cSrcweir         {
475cdf0e10cSrcweir             // ueber die naechste Nummerierung
476cdf0e10cSrcweir             long nOffset = 0;
477cdf0e10cSrcweir             const SwNode* pNd;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir             if( bUpperLeft )        // verschiebe nach oben
480cdf0e10cSrcweir             {
481cdf0e10cSrcweir                 SwPosition aPos( *aCrsr.GetMark() );
482cdf0e10cSrcweir                 if( GetDoc()->GotoPrevNum( aPos, sal_False ) )
483cdf0e10cSrcweir                     nOffset = aPos.nNode.GetIndex() -
484cdf0e10cSrcweir                             aCrsr.GetMark()->nNode.GetIndex();
485cdf0e10cSrcweir                 else
486cdf0e10cSrcweir                 {
487cdf0e10cSrcweir                     sal_uLong nStt = aPos.nNode.GetIndex(), nIdx = nStt - 1;
488cdf0e10cSrcweir                     while( nIdx && (
489cdf0e10cSrcweir                         ( pNd = GetDoc()->GetNodes()[ nIdx ])->IsSectionNode() ||
490cdf0e10cSrcweir                         ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsSectionNode())))
491cdf0e10cSrcweir                         --nIdx;
492cdf0e10cSrcweir                     if( GetDoc()->GetNodes()[ nIdx ]->IsTxtNode() )
493cdf0e10cSrcweir                         nOffset = nIdx - nStt;
494cdf0e10cSrcweir                 }
495cdf0e10cSrcweir             }
496cdf0e10cSrcweir             else                    // verschiebe nach unten
497cdf0e10cSrcweir             {
498cdf0e10cSrcweir                 const SwNumRule* pOrig = aCrsr.GetNode(sal_False)->GetTxtNode()->GetNumRule();
499cdf0e10cSrcweir                 if( aCrsr.GetNode()->IsTxtNode() &&
500cdf0e10cSrcweir                     pOrig == aCrsr.GetNode()->GetTxtNode()->GetNumRule() )
501cdf0e10cSrcweir                 {
502cdf0e10cSrcweir                     sal_uLong nStt = aCrsr.GetPoint()->nNode.GetIndex(), nIdx = nStt+1;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir                     while (nIdx < GetDoc()->GetNodes().Count()-1)
505cdf0e10cSrcweir                     {
506cdf0e10cSrcweir                         pNd = GetDoc()->GetNodes()[ nIdx ];
507cdf0e10cSrcweir 
508cdf0e10cSrcweir                         if (pNd->IsSectionNode() ||
509cdf0e10cSrcweir                             ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsSectionNode()) ||
510cdf0e10cSrcweir                             ( pNd->IsTxtNode() && pOrig == ((SwTxtNode*)pNd)->GetNumRule() &&
511cdf0e10cSrcweir                               ((SwTxtNode*)pNd)->GetActualListLevel() > nUpperLevel ))
512cdf0e10cSrcweir                         {
513cdf0e10cSrcweir                             ++nIdx;
514cdf0e10cSrcweir                         }
515cdf0e10cSrcweir                         // --> OD 2005-11-14 #i57856#
516cdf0e10cSrcweir                         else
517cdf0e10cSrcweir                         {
518cdf0e10cSrcweir                             break;
519cdf0e10cSrcweir                         }
520cdf0e10cSrcweir                         // <--
521cdf0e10cSrcweir                     }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir                     if( nStt == nIdx || !GetDoc()->GetNodes()[ nIdx ]->IsTxtNode() )
524cdf0e10cSrcweir                         nOffset = 1;
525cdf0e10cSrcweir                     else
526cdf0e10cSrcweir                         nOffset = nIdx - nStt;
527cdf0e10cSrcweir                 }
528cdf0e10cSrcweir                 else
529cdf0e10cSrcweir                     nOffset = 1;
530cdf0e10cSrcweir             }
531cdf0e10cSrcweir 
532cdf0e10cSrcweir             if( nOffset )
533cdf0e10cSrcweir             {
534cdf0e10cSrcweir                 aCrsr.Move( fnMoveBackward, fnGoNode );
535cdf0e10cSrcweir                 bRet = GetDoc()->MoveParagraph( aCrsr, nOffset );
536cdf0e10cSrcweir             }
537cdf0e10cSrcweir         }
538cdf0e10cSrcweir         else if( bUpperLeft ? nUpperLevel : nLowerLevel+1 < MAXLEVEL )
539cdf0e10cSrcweir         {
540cdf0e10cSrcweir             aCrsr.Move( fnMoveBackward, fnGoNode );
541cdf0e10cSrcweir             bRet = GetDoc()->NumUpDown( aCrsr, !bUpperLeft );
542cdf0e10cSrcweir         }
543cdf0e10cSrcweir     }
544cdf0e10cSrcweir 
545cdf0e10cSrcweir     GetDoc()->SetModified();
546cdf0e10cSrcweir     EndAllAction();
547cdf0e10cSrcweir     return bRet;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
OutlineUpDown(short nOffset)550cdf0e10cSrcweir sal_Bool SwEditShell::OutlineUpDown( short nOffset )
551cdf0e10cSrcweir {
552cdf0e10cSrcweir     StartAllAction();
553cdf0e10cSrcweir 
554cdf0e10cSrcweir     sal_Bool bRet = sal_True;
555cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
556cdf0e10cSrcweir     if( pCrsr->GetNext() == pCrsr )         // keine Mehrfachselektion ?
557cdf0e10cSrcweir         bRet = GetDoc()->OutlineUpDown( *pCrsr, nOffset );
558cdf0e10cSrcweir     else
559cdf0e10cSrcweir     {
560cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
561cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
562cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
563cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
564cdf0e10cSrcweir             bRet = bRet && GetDoc()->OutlineUpDown(
565cdf0e10cSrcweir                                     aRangeArr.SetPam( n, aPam ), nOffset );
566cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
567cdf0e10cSrcweir     }
568cdf0e10cSrcweir     GetDoc()->SetModified();
569cdf0e10cSrcweir     EndAllAction();
570cdf0e10cSrcweir     return bRet;
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 
MoveOutlinePara(short nOffset)574cdf0e10cSrcweir sal_Bool SwEditShell::MoveOutlinePara( short nOffset )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     StartAllAction();
577cdf0e10cSrcweir     sal_Bool bRet = GetDoc()->MoveOutlinePara( *GetCrsr(), nOffset );
578cdf0e10cSrcweir     EndAllAction();
579cdf0e10cSrcweir     return bRet;
580cdf0e10cSrcweir }
581cdf0e10cSrcweir 
582cdf0e10cSrcweir // Outlines and SubOutline are ReadOnly?
IsProtectedOutlinePara() const583cdf0e10cSrcweir sal_Bool SwEditShell::IsProtectedOutlinePara() const
584cdf0e10cSrcweir {
585cdf0e10cSrcweir     sal_Bool bRet = sal_False;
586cdf0e10cSrcweir     const SwNode& rNd = GetCrsr()->Start()->nNode.GetNode();
587cdf0e10cSrcweir     if( rNd.IsTxtNode() )
588cdf0e10cSrcweir     {
589cdf0e10cSrcweir         const SwOutlineNodes& rOutlNd = GetDoc()->GetNodes().GetOutLineNds();
590cdf0e10cSrcweir         SwNodePtr pNd = (SwNodePtr)&rNd;
591cdf0e10cSrcweir         sal_Bool bFirst = sal_True;
592cdf0e10cSrcweir         sal_uInt16 nPos;
593cdf0e10cSrcweir         int nLvl(0);
594cdf0e10cSrcweir         if( !rOutlNd.Seek_Entry( pNd, &nPos ) && nPos )
595cdf0e10cSrcweir             --nPos;
596cdf0e10cSrcweir 
597cdf0e10cSrcweir         for( ; nPos < rOutlNd.Count(); ++nPos )
598cdf0e10cSrcweir         {
599cdf0e10cSrcweir             SwNodePtr pTmpNd = rOutlNd[ nPos ];
600cdf0e10cSrcweir 
601cdf0e10cSrcweir             // --> OD 2008-04-02 #refactorlists#
602cdf0e10cSrcweir //            sal_uInt8 nTmpLvl = GetRealLevel( pTmpNd->GetTxtNode()->
603cdf0e10cSrcweir //                                    GetTxtColl()->GetOutlineLevel() );
604cdf0e10cSrcweir  //           int nTmpLvl = pTmpNd->GetTxtNode()->GetOutlineLevel();//#outline level,zhaojianwei
605cdf0e10cSrcweir             int nTmpLvl = pTmpNd->GetTxtNode()->GetAttrOutlineLevel();
606cdf0e10cSrcweir  //           ASSERT( nTmpLvl >= 0 && nTmpLvl < MAXLEVEL,
607cdf0e10cSrcweir             ASSERT( nTmpLvl >= 0 && nTmpLvl <= MAXLEVEL,            //<-end,zhaojianwei
608cdf0e10cSrcweir                     "<SwEditShell::IsProtectedOutlinePara()>" );
609cdf0e10cSrcweir             // <--
610cdf0e10cSrcweir             if( bFirst )
611cdf0e10cSrcweir             {
612cdf0e10cSrcweir                 nLvl = nTmpLvl;
613cdf0e10cSrcweir                 bFirst = sal_False;
614cdf0e10cSrcweir             }
615cdf0e10cSrcweir             else if( nLvl >= nTmpLvl )
616cdf0e10cSrcweir                 break;
617cdf0e10cSrcweir 
618cdf0e10cSrcweir             if( pTmpNd->IsProtect() )
619cdf0e10cSrcweir             {
620cdf0e10cSrcweir                 bRet = sal_True;
621cdf0e10cSrcweir                 break;
622cdf0e10cSrcweir             }
623cdf0e10cSrcweir         }
624cdf0e10cSrcweir     }
625cdf0e10cSrcweir #ifdef DBG_UTIL
626cdf0e10cSrcweir     else
627cdf0e10cSrcweir     {
628*870262e3SDon Lewis         ASSERT(sal_False, "Cursor not on an outline node" );
629cdf0e10cSrcweir     }
630cdf0e10cSrcweir #endif
631cdf0e10cSrcweir     return bRet;
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir /** Test whether outline may be moved (bCopy == false)
635cdf0e10cSrcweir  *                           or copied (bCopy == true)
636cdf0e10cSrcweir  * Verify these conditions:
637cdf0e10cSrcweir  * 1) outline must be within main body (and not in redline)
638cdf0e10cSrcweir  * 2) outline must not be within table
639cdf0e10cSrcweir  * 3) if bCopy is set, outline must not be write protected
640cdf0e10cSrcweir  */
lcl_IsOutlineMoveAndCopyable(const SwDoc * pDoc,sal_uInt16 nIdx,bool bCopy)641cdf0e10cSrcweir sal_Bool lcl_IsOutlineMoveAndCopyable( const SwDoc* pDoc, sal_uInt16 nIdx, bool bCopy )
642cdf0e10cSrcweir {
643cdf0e10cSrcweir     const SwNodes& rNds = pDoc->GetNodes();
644cdf0e10cSrcweir     const SwNode* pNd = rNds.GetOutLineNds()[ nIdx ];
645cdf0e10cSrcweir     return pNd->GetIndex() >= rNds.GetEndOfExtras().GetIndex() &&   // 1) body
646cdf0e10cSrcweir             !pNd->FindTableNode() &&                                // 2) table
647cdf0e10cSrcweir             ( bCopy || !pNd->IsProtect() );                         // 3) write
648cdf0e10cSrcweir }
649cdf0e10cSrcweir 
IsOutlineMovable(sal_uInt16 nIdx) const650cdf0e10cSrcweir sal_Bool SwEditShell::IsOutlineMovable( sal_uInt16 nIdx ) const
651cdf0e10cSrcweir {
652cdf0e10cSrcweir     return lcl_IsOutlineMoveAndCopyable( GetDoc(), nIdx, false );
653cdf0e10cSrcweir }
654cdf0e10cSrcweir 
IsOutlineCopyable(sal_uInt16 nIdx) const655cdf0e10cSrcweir sal_Bool SwEditShell::IsOutlineCopyable( sal_uInt16 nIdx ) const
656cdf0e10cSrcweir {
657cdf0e10cSrcweir     return lcl_IsOutlineMoveAndCopyable( GetDoc(), nIdx, true );
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir 
NumOrNoNum(sal_Bool bNumOn,sal_Bool bChkStart)66123d8f725SOliver-Rainer Wittmann sal_Bool SwEditShell::NumOrNoNum(
66223d8f725SOliver-Rainer Wittmann     sal_Bool bNumOn,
66323d8f725SOliver-Rainer Wittmann     sal_Bool bChkStart )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     sal_Bool bRet = sal_False;
66623d8f725SOliver-Rainer Wittmann 
66723d8f725SOliver-Rainer Wittmann     if ( !IsMultiSelection()
66823d8f725SOliver-Rainer Wittmann          && !HasSelection()
66923d8f725SOliver-Rainer Wittmann          && ( !bChkStart || IsSttPara() ) )
670cdf0e10cSrcweir     {
67123d8f725SOliver-Rainer Wittmann         StartAllAction();
67223d8f725SOliver-Rainer Wittmann         bRet = GetDoc()->NumOrNoNum( GetCrsr()->GetPoint()->nNode, !bNumOn );
673cdf0e10cSrcweir         EndAllAction();
674cdf0e10cSrcweir     }
675cdf0e10cSrcweir     return bRet;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
67823d8f725SOliver-Rainer Wittmann 
IsNoNum(sal_Bool bChkStart) const679cdf0e10cSrcweir sal_Bool SwEditShell::IsNoNum( sal_Bool bChkStart ) const
680cdf0e10cSrcweir {
681cdf0e10cSrcweir     sal_Bool bResult = sal_False;
682cdf0e10cSrcweir 
68323d8f725SOliver-Rainer Wittmann     if ( !IsMultiSelection()
68423d8f725SOliver-Rainer Wittmann          && !HasSelection()
68523d8f725SOliver-Rainer Wittmann          && ( !bChkStart || IsSttPara() ) )
686cdf0e10cSrcweir     {
68723d8f725SOliver-Rainer Wittmann         const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
68823d8f725SOliver-Rainer Wittmann         if ( pTxtNd != NULL )
689cdf0e10cSrcweir         {
690cdf0e10cSrcweir             bResult =  !pTxtNd->IsCountedInList();
691cdf0e10cSrcweir         }
692cdf0e10cSrcweir     }
693cdf0e10cSrcweir 
694cdf0e10cSrcweir     return bResult;
695cdf0e10cSrcweir }
696cdf0e10cSrcweir 
GetNumLevel() const697cdf0e10cSrcweir sal_uInt8 SwEditShell::GetNumLevel() const
698cdf0e10cSrcweir {
699cdf0e10cSrcweir     // gebe die akt. Ebene zurueck, auf der sich der Point vom Cursor befindet
700cdf0e10cSrcweir     //sal_uInt8 nLevel = NO_NUMBERING;  //#outline level,zhaojianwei
701cdf0e10cSrcweir     sal_uInt8 nLevel = MAXLEVEL;        //end,zhaojianwei
702cdf0e10cSrcweir 
703cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
704cdf0e10cSrcweir     const SwTxtNode* pTxtNd = pCrsr->GetNode()->GetTxtNode();
705cdf0e10cSrcweir 
70623d8f725SOliver-Rainer Wittmann     ASSERT( pTxtNd != NULL, "GetNumLevel() without text node" )
70723d8f725SOliver-Rainer Wittmann     if ( pTxtNd == NULL )
708cdf0e10cSrcweir         return nLevel;
709cdf0e10cSrcweir 
710cdf0e10cSrcweir     const SwNumRule* pRule = pTxtNd->GetNumRule();
71123d8f725SOliver-Rainer Wittmann     if ( pRule != NULL )
712cdf0e10cSrcweir     {
713cdf0e10cSrcweir         const int nListLevelOfTxtNode( pTxtNd->GetActualListLevel() );
714cdf0e10cSrcweir         if ( nListLevelOfTxtNode >= 0 )
715cdf0e10cSrcweir         {
716cdf0e10cSrcweir             nLevel = static_cast<sal_uInt8>( nListLevelOfTxtNode );
717cdf0e10cSrcweir         }
718cdf0e10cSrcweir     }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     return nLevel;
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
GetNumRuleAtCurrCrsrPos() const72334760e49SOliver-Rainer Wittmann const SwNumRule* SwEditShell::GetNumRuleAtCurrCrsrPos() const
724cdf0e10cSrcweir {
72534760e49SOliver-Rainer Wittmann     return GetDoc()->GetNumRuleAtPos( *GetCrsr()->GetPoint() );
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
GetNumRuleAtCurrentSelection() const72834760e49SOliver-Rainer Wittmann const SwNumRule* SwEditShell::GetNumRuleAtCurrentSelection() const
72934760e49SOliver-Rainer Wittmann {
73034760e49SOliver-Rainer Wittmann     const SwNumRule* pNumRuleAtCurrentSelection = NULL;
73134760e49SOliver-Rainer Wittmann 
73234760e49SOliver-Rainer Wittmann     const SwPaM* pCurrentCrsr = GetCrsr();
73334760e49SOliver-Rainer Wittmann     bool bDifferentNumRuleFound = false;
73434760e49SOliver-Rainer Wittmann     const SwPaM* pCrsr = pCurrentCrsr;
73534760e49SOliver-Rainer Wittmann     do
73634760e49SOliver-Rainer Wittmann     {
73734760e49SOliver-Rainer Wittmann         const SwNodeIndex aEndNode = pCrsr->End()->nNode;
73834760e49SOliver-Rainer Wittmann 
73934760e49SOliver-Rainer Wittmann         for ( SwNodeIndex aNode = pCrsr->Start()->nNode; aNode <= aEndNode; aNode++ )
74034760e49SOliver-Rainer Wittmann         {
74134760e49SOliver-Rainer Wittmann             const SwNumRule* pNumRule = GetDoc()->GetNumRuleAtPos( SwPosition( aNode ) );
74234760e49SOliver-Rainer Wittmann             if ( pNumRule == NULL )
74334760e49SOliver-Rainer Wittmann             {
74434760e49SOliver-Rainer Wittmann                 continue;
74534760e49SOliver-Rainer Wittmann             }
74634760e49SOliver-Rainer Wittmann             else if ( pNumRule != pNumRuleAtCurrentSelection )
74734760e49SOliver-Rainer Wittmann             {
74834760e49SOliver-Rainer Wittmann                 if ( pNumRuleAtCurrentSelection == NULL )
74934760e49SOliver-Rainer Wittmann                 {
75034760e49SOliver-Rainer Wittmann                     pNumRuleAtCurrentSelection = pNumRule;
75134760e49SOliver-Rainer Wittmann                 }
75234760e49SOliver-Rainer Wittmann                 else
75334760e49SOliver-Rainer Wittmann                 {
75434760e49SOliver-Rainer Wittmann                     pNumRuleAtCurrentSelection = NULL;
75534760e49SOliver-Rainer Wittmann                     bDifferentNumRuleFound = true;
75634760e49SOliver-Rainer Wittmann                     break;
75734760e49SOliver-Rainer Wittmann                 }
75834760e49SOliver-Rainer Wittmann             }
75934760e49SOliver-Rainer Wittmann         }
76034760e49SOliver-Rainer Wittmann 
76134760e49SOliver-Rainer Wittmann         pCrsr = static_cast< const SwPaM* >(pCrsr->GetNext());
76234760e49SOliver-Rainer Wittmann     } while ( !bDifferentNumRuleFound && pCrsr != pCurrentCrsr );
76334760e49SOliver-Rainer Wittmann 
76434760e49SOliver-Rainer Wittmann     return pNumRuleAtCurrentSelection;
76534760e49SOliver-Rainer Wittmann }
76634760e49SOliver-Rainer Wittmann 
76734760e49SOliver-Rainer Wittmann 
SetCurNumRule(const SwNumRule & rRule,const bool bCreateNewList,const String sContinuedListId,const bool bResetIndentAttrs)768cdf0e10cSrcweir void SwEditShell::SetCurNumRule( const SwNumRule& rRule,
769cdf0e10cSrcweir                                  const bool bCreateNewList,
770cdf0e10cSrcweir                                  const String sContinuedListId,
771cdf0e10cSrcweir                                  const bool bResetIndentAttrs )
772cdf0e10cSrcweir {
773cdf0e10cSrcweir     StartAllAction();
774cdf0e10cSrcweir 
775cdf0e10cSrcweir     GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
77823d8f725SOliver-Rainer Wittmann     if( IsMultiSelection() )
779cdf0e10cSrcweir     {
780cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
781cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
782cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
783cdf0e10cSrcweir         {
784cdf0e10cSrcweir             aRangeArr.SetPam( n, aPam );
785cdf0e10cSrcweir             GetDoc()->SetNumRule( aPam, rRule,
786cdf0e10cSrcweir                                   bCreateNewList, sContinuedListId,
78734760e49SOliver-Rainer Wittmann                                   true, bResetIndentAttrs );
788cdf0e10cSrcweir             GetDoc()->SetCounted( aPam, true );
789cdf0e10cSrcweir         }
790cdf0e10cSrcweir     }
791cdf0e10cSrcweir     else
792cdf0e10cSrcweir     {
793cdf0e10cSrcweir         GetDoc()->SetNumRule( *pCrsr, rRule,
794cdf0e10cSrcweir                               bCreateNewList, sContinuedListId,
79534760e49SOliver-Rainer Wittmann                               true, bResetIndentAttrs );
796cdf0e10cSrcweir         GetDoc()->SetCounted( *pCrsr, true );
797cdf0e10cSrcweir     }
798cdf0e10cSrcweir     GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     EndAllAction();
801cdf0e10cSrcweir }
802cdf0e10cSrcweir 
80334760e49SOliver-Rainer Wittmann 
GetUniqueNumRuleName(const String * pChkStr,sal_Bool bAutoNum) const804cdf0e10cSrcweir String SwEditShell::GetUniqueNumRuleName( const String* pChkStr, sal_Bool bAutoNum ) const
805cdf0e10cSrcweir {
806cdf0e10cSrcweir     return GetDoc()->GetUniqueNumRuleName( pChkStr, bAutoNum );
807cdf0e10cSrcweir }
808cdf0e10cSrcweir 
ChgNumRuleFmts(const SwNumRule & rRule)809cdf0e10cSrcweir void SwEditShell::ChgNumRuleFmts( const SwNumRule& rRule )
810cdf0e10cSrcweir {
811cdf0e10cSrcweir     StartAllAction();
812cdf0e10cSrcweir     GetDoc()->ChgNumRuleFmts( rRule );
813cdf0e10cSrcweir     EndAllAction();
814cdf0e10cSrcweir }
815cdf0e10cSrcweir 
ReplaceNumRule(const String & rOldRule,const String & rNewRule)816cdf0e10cSrcweir sal_Bool SwEditShell::ReplaceNumRule( const String& rOldRule, const String& rNewRule )
817cdf0e10cSrcweir {
818cdf0e10cSrcweir     StartAllAction();
819cdf0e10cSrcweir     sal_Bool bRet = GetDoc()->ReplaceNumRule( *GetCrsr()->GetPoint(), rOldRule, rNewRule );
820cdf0e10cSrcweir     EndAllAction();
821cdf0e10cSrcweir     return bRet;
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
SetNumRuleStart(sal_Bool bFlag)824cdf0e10cSrcweir void SwEditShell::SetNumRuleStart( sal_Bool bFlag )
825cdf0e10cSrcweir {
826cdf0e10cSrcweir     StartAllAction();
827cdf0e10cSrcweir 
828cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
829cdf0e10cSrcweir     if( pCrsr->GetNext() != pCrsr )         // Mehrfachselektion ?
830cdf0e10cSrcweir     {
831cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
832cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
833cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
834cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
835cdf0e10cSrcweir             GetDoc()->SetNumRuleStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), bFlag );
836cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
837cdf0e10cSrcweir     }
838cdf0e10cSrcweir     else
839cdf0e10cSrcweir         GetDoc()->SetNumRuleStart( *pCrsr->GetPoint(), bFlag );
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     EndAllAction();
842cdf0e10cSrcweir }
843cdf0e10cSrcweir 
IsNumRuleStart() const844cdf0e10cSrcweir sal_Bool SwEditShell::IsNumRuleStart() const
845cdf0e10cSrcweir {
846cdf0e10cSrcweir     sal_Bool bResult = sal_False;
847cdf0e10cSrcweir     const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
848cdf0e10cSrcweir     if( pTxtNd )
849cdf0e10cSrcweir         bResult = pTxtNd->IsListRestart() ? sal_True : sal_False;
850cdf0e10cSrcweir     return bResult;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir 
SetNodeNumStart(sal_uInt16 nStt)853cdf0e10cSrcweir void SwEditShell::SetNodeNumStart( sal_uInt16 nStt )
854cdf0e10cSrcweir {
855cdf0e10cSrcweir     StartAllAction();
856cdf0e10cSrcweir 
857cdf0e10cSrcweir     SwPaM* pCrsr = GetCrsr();
858cdf0e10cSrcweir     if( pCrsr->GetNext() != pCrsr )         // Mehrfachselektion ?
859cdf0e10cSrcweir     {
860cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
861cdf0e10cSrcweir         SwPamRanges aRangeArr( *pCrsr );
862cdf0e10cSrcweir         SwPaM aPam( *pCrsr->GetPoint() );
863cdf0e10cSrcweir         for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
864cdf0e10cSrcweir             GetDoc()->SetNodeNumStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), nStt );
865cdf0e10cSrcweir         GetDoc()->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
866cdf0e10cSrcweir     }
867cdf0e10cSrcweir     else
868cdf0e10cSrcweir         GetDoc()->SetNodeNumStart( *pCrsr->GetPoint(), nStt );
869cdf0e10cSrcweir 
870cdf0e10cSrcweir     EndAllAction();
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
GetNodeNumStart() const873cdf0e10cSrcweir sal_uInt16 SwEditShell::GetNodeNumStart() const
874cdf0e10cSrcweir {
875cdf0e10cSrcweir     const SwTxtNode* pTxtNd = GetCrsr()->GetNode()->GetTxtNode();
876cdf0e10cSrcweir     // --> OD 2008-02-28 #refactorlists#
877cdf0e10cSrcweir     // correction: check, if list restart value is set at text node and
878cdf0e10cSrcweir     // use new method <SwTxtNode::GetAttrListRestartValue()>.
879cdf0e10cSrcweir     // return USHRT_MAX, if no list restart value is found.
880cdf0e10cSrcweir     if ( pTxtNd && pTxtNd->HasAttrListRestartValue() )
881cdf0e10cSrcweir     {
882cdf0e10cSrcweir         return static_cast<sal_uInt16>(pTxtNd->GetAttrListRestartValue());
883cdf0e10cSrcweir     }
884cdf0e10cSrcweir     return USHRT_MAX;
885cdf0e10cSrcweir     // <--
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
888cdf0e10cSrcweir /*-- 26.08.2005 14:47:17---------------------------------------------------
889cdf0e10cSrcweir 
890cdf0e10cSrcweir   -----------------------------------------------------------------------*/
891cdf0e10cSrcweir // --> OD 2008-03-18 #refactorlists#
SearchNumRule(const bool bForward,const bool bNum,const bool bOutline,int nNonEmptyAllowed,String & sListId)892cdf0e10cSrcweir const SwNumRule * SwEditShell::SearchNumRule( const bool bForward,
893cdf0e10cSrcweir                                               const bool bNum,
894cdf0e10cSrcweir                                               const bool bOutline,
895cdf0e10cSrcweir                                               int nNonEmptyAllowed,
896cdf0e10cSrcweir                                               String& sListId )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir     return GetDoc()->SearchNumRule( *(bForward ? GetCrsr()->End() : GetCrsr()->Start()),
899cdf0e10cSrcweir                                     bForward, bNum, bOutline, nNonEmptyAllowed,
900cdf0e10cSrcweir                                     sListId );
901cdf0e10cSrcweir }
902cdf0e10cSrcweir // <--
903