xref: /trunk/main/sw/source/core/doc/number.cxx (revision f6c78b21b9451944eb43023c08ad1a3c8ad54ae4)
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 
30 #include <string.h>
31 #include <vcl/font.hxx>
32 #include <editeng/brshitem.hxx>
33 #include <editeng/lrspitem.hxx>
34 #include <editeng/numitem.hxx>
35 #include <fmtornt.hxx>
36 #include <doc.hxx>
37 #include <pam.hxx>
38 #include <charfmt.hxx>
39 #include <paratr.hxx>
40 #include <frmfmt.hxx>
41 #include <ndtxt.hxx>
42 #include <docary.hxx>
43 #ifndef _DOCSH_HXX
44 #include <docsh.hxx>
45 #endif
46 #include <SwStyleNameMapper.hxx>
47 // --> OD 2006-06-28 #b6440955#
48 // Needed to load default bullet list configuration
49 #include <unotools/configitem.hxx>
50 // <--
51 #include <numrule.hxx>
52 #include <SwNodeNum.hxx>
53 
54 #include <unordered_map>
55 // --> OD 2008-02-19 #refactorlists#
56 #include <list.hxx>
57 #include <algorithm>
58 #include <functional>
59 // <--
60 // --> OD 2008-06-06 #i89178#
61 #include <unotools/saveopt.hxx>
62 // <--
63 // --> OD 2008-07-08 #i91400#
64 #include <IDocumentListsAccess.hxx>
65 // <--
66 
67 using namespace ::com::sun::star;
68 
69 
70 sal_uInt16 SwNumRule::nRefCount = 0;
71 SwNumFmt* SwNumRule::aBaseFmts[ RULE_END ][ MAXLEVEL ] = {
72     {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
73 // --> OD 2008-02-11 #newlistlevelattrs#
74 SwNumFmt* SwNumRule::aLabelAlignmentBaseFmts[ RULE_END ][ MAXLEVEL ] = {
75     {0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } };
76 
77 char sOutline[] = "Outline";
78 char* SwNumRule::pDefOutlineName = sOutline;
79 
80 // #i30312#
81 sal_uInt16 SwNumRule::aDefNumIndents[ MAXLEVEL ] = {
82 //inch:   0,5  1,0  1,5  2,0   2,5   3,0   3,5   4,0   4,5   5,0
83         1440/4, 1440/2, 1440*3/4, 1440, 1440*5/4, 1440*3/2, 1440*7/4, 1440*2,
84         1440*9/4, 1440*5/2
85 };
86 
Get(sal_uInt16 i) const87 const SwNumFmt& SwNumRule::Get( sal_uInt16 i ) const
88 {
89     ASSERT_ID( i < MAXLEVEL && eRuleType < RULE_END, ERR_NUMLEVEL);
90     return aFmts[ i ]
91            ? *aFmts[ i ]
92            // --> OD 2008-02-11 #newlistlevelattrs#
93            : ( meDefaultNumberFormatPositionAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION
94                ? *aBaseFmts[ eRuleType ][ i ]
95                : *aLabelAlignmentBaseFmts[ eRuleType ][ i ] );
96            // <--
97 }
98 
GetNumFmt(sal_uInt16 i) const99 const SwNumFmt* SwNumRule::GetNumFmt( sal_uInt16 i ) const
100 {
101     const SwNumFmt * pResult = NULL;
102 
103     ASSERT_ID( i < MAXLEVEL && eRuleType < RULE_END, ERR_NUMLEVEL);
104     if ( i < MAXLEVEL && eRuleType < RULE_END)
105     {
106         pResult = aFmts[ i ];
107     }
108 
109     return pResult;
110 }
111 
112 // --> OD 2008-07-08 #i91400#
SetName(const String & rName,IDocumentListsAccess & rDocListAccess)113 void SwNumRule::SetName( const String & rName,
114                          IDocumentListsAccess& rDocListAccess)
115 // <--
116 {
117     if ( sName != rName )
118     {
119         if (pNumRuleMap)
120         {
121             pNumRuleMap->erase(sName);
122             (*pNumRuleMap)[rName] = this;
123 
124             // --> OD 2008-07-08 #i91400#
125             if ( GetDefaultListId().Len() > 0 )
126             {
127                 rDocListAccess.trackChangeOfListStyleName( sName, rName );
128             }
129             // <--
130         }
131 
132         sName = rName;
133     }
134 }
135 
136 // --> OD 2008-02-19 #refactorlists#
GetTxtNodeList(SwNumRule::tTxtNodeList & rTxtNodeList) const137 void SwNumRule::GetTxtNodeList( SwNumRule::tTxtNodeList& rTxtNodeList ) const
138 {
139     rTxtNodeList = maTxtNodeList;
140 }
141 
GetTxtNodeListSize() const142 SwNumRule::tTxtNodeList::size_type SwNumRule::GetTxtNodeListSize() const
143 {
144     return maTxtNodeList.size();
145 }
146 
AddTxtNode(SwTxtNode & rTxtNode)147 void SwNumRule::AddTxtNode( SwTxtNode& rTxtNode )
148 {
149     tTxtNodeList::iterator aIter =
150         std::find( maTxtNodeList.begin(), maTxtNodeList.end(), &rTxtNode );
151 
152     if ( aIter == maTxtNodeList.end() )
153     {
154         maTxtNodeList.push_back( &rTxtNode );
155     }
156 }
157 
RemoveTxtNode(SwTxtNode & rTxtNode)158 void SwNumRule::RemoveTxtNode( SwTxtNode& rTxtNode )
159 {
160     tTxtNodeList::iterator aIter =
161         std::find( maTxtNodeList.begin(), maTxtNodeList.end(), &rTxtNode );
162 
163     if ( aIter != maTxtNodeList.end() )
164     {
165         maTxtNodeList.erase( aIter );
166     }
167 }
168 // <--
169 
SetNumRuleMap(std::unordered_map<String,SwNumRule *,StringHash> * _pNumRuleMap)170 void SwNumRule::SetNumRuleMap(std::unordered_map<String, SwNumRule *, StringHash> *
171                               _pNumRuleMap)
172 {
173     pNumRuleMap = _pNumRuleMap;
174 }
175 
GetNumIndent(sal_uInt8 nLvl)176 sal_uInt16 SwNumRule::GetNumIndent( sal_uInt8 nLvl )
177 {
178     ASSERT( MAXLEVEL > nLvl, "NumLevel is out of range" );
179     return aDefNumIndents[ nLvl ];
180 }
181 
GetBullIndent(sal_uInt8 nLvl)182 sal_uInt16 SwNumRule::GetBullIndent( sal_uInt8 nLvl )
183 {
184     ASSERT( MAXLEVEL > nLvl, "NumLevel is out of range" );
185     return aDefNumIndents[ nLvl ];
186 }
187 
188 
189 
lcl_SetRuleChgd(SwTxtNode & rNd,sal_uInt8 nLevel)190 static void lcl_SetRuleChgd( SwTxtNode& rNd, sal_uInt8 nLevel )
191 {
192     if( rNd.GetActualListLevel() == nLevel )
193         rNd.NumRuleChgd();
194 }
195 /* -----------------------------22.02.01 13:41--------------------------------
196 
197  ---------------------------------------------------------------------------*/
SwNumFmt()198 SwNumFmt::SwNumFmt() :
199     SvxNumberFormat(SVX_NUM_ARABIC),
200     SwClient( 0 ),
201     pVertOrient(new SwFmtVertOrient( 0, text::VertOrientation::NONE))
202     ,cGrfBulletCP(USHRT_MAX)//For i120928,record the cp info of graphic within bullet
203 {
204 }
205 /* -----------------------------22.02.01 13:42--------------------------------
206 
207  ---------------------------------------------------------------------------*/
SwNumFmt(const SwNumFmt & rFmt)208 SwNumFmt::SwNumFmt( const SwNumFmt& rFmt) :
209     SvxNumberFormat(rFmt),
210     SwClient( rFmt.GetRegisteredInNonConst() ),
211     pVertOrient(new SwFmtVertOrient( 0, rFmt.GetVertOrient()))
212     ,cGrfBulletCP(rFmt.cGrfBulletCP)//For i120928,record the cp info of graphic within bullet
213 {
214     sal_Int16 eMyVertOrient = rFmt.GetVertOrient();
215     SetGraphicBrush( rFmt.GetBrush(), &rFmt.GetGraphicSize(),
216                                                 &eMyVertOrient);
217 }
218 /* -----------------------------22.02.01 13:58--------------------------------
219 
220  ---------------------------------------------------------------------------*/
SwNumFmt(const SvxNumberFormat & rNumFmt,SwDoc * pDoc)221 SwNumFmt::SwNumFmt(const SvxNumberFormat& rNumFmt, SwDoc* pDoc) :
222     SvxNumberFormat(rNumFmt),
223     pVertOrient(new SwFmtVertOrient( 0, rNumFmt.GetVertOrient()))
224 {
225     sal_Int16 eMyVertOrient = rNumFmt.GetVertOrient();
226     SetGraphicBrush( rNumFmt.GetBrush(), &rNumFmt.GetGraphicSize(),
227                                                 &eMyVertOrient);
228     const String& rCharStyleName = rNumFmt.SvxNumberFormat::GetCharFmtName();
229     if( rCharStyleName.Len() )
230     {
231         SwCharFmt* pCFmt = pDoc->FindCharFmtByName( rCharStyleName );
232         if( !pCFmt )
233         {
234             sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCharStyleName,
235                                             nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
236             pCFmt = nId != USHRT_MAX
237                         ? pDoc->GetCharFmtFromPool( nId )
238                         : pDoc->MakeCharFmt( rCharStyleName, 0 );
239         }
240         pCFmt->Add( this );
241     }
242     else if( GetRegisteredIn() )
243         GetRegisteredInNonConst()->Remove( this );
244 
245 }
246 /* -----------------------------22.02.01 13:42--------------------------------
247 
248  ---------------------------------------------------------------------------*/
~SwNumFmt()249 SwNumFmt::~SwNumFmt()
250 {
251     delete pVertOrient;
252 }
253 /* -----------------------------02.07.01 15:37--------------------------------
254 
255  ---------------------------------------------------------------------------*/
NotifyGraphicArrived()256 void SwNumFmt::NotifyGraphicArrived()
257 {
258     if( GetCharFmt() )
259         UpdateNumNodes( (SwDoc*)GetCharFmt()->GetDoc() );
260 }
261 
262 // #i22362#
IsEnumeration() const263 sal_Bool SwNumFmt::IsEnumeration() const
264 {
265     // --> FME 2004-08-12 #i30655# native numbering did not work any longer
266     // using this code. Therefore HBRINKM and I agreed upon defining
267     // IsEnumeration() as !IsItemize()
268     return !IsItemize();
269     // <--
270 
271     /*
272     sal_Bool bResult;
273 
274     switch(GetNumberingType())
275     {
276     case SVX_NUM_CHARS_UPPER_LETTER:
277     case SVX_NUM_CHARS_LOWER_LETTER:
278     case SVX_NUM_ROMAN_UPPER:
279     case SVX_NUM_ROMAN_LOWER:
280     case SVX_NUM_ARABIC:
281     case SVX_NUM_PAGEDESC:
282     case SVX_NUM_CHARS_UPPER_LETTER_N:
283     case SVX_NUM_CHARS_LOWER_LETTER_N:
284         bResult = sal_True;
285 
286         break;
287 
288     default:
289         bResult = sal_False;
290     }
291 
292     return bResult;
293      */
294 }
295 
296 // #i29560#
IsItemize() const297 sal_Bool SwNumFmt::IsItemize() const
298 {
299     sal_Bool bResult;
300 
301     switch(GetNumberingType())
302     {
303     case SVX_NUM_CHAR_SPECIAL:
304     case SVX_NUM_BITMAP:
305         bResult = sal_True;
306 
307         break;
308 
309     default:
310         bResult = sal_False;
311     }
312 
313     return bResult;
314 
315 }
316 
317 
318 /* -----------------------------23.02.01 09:28--------------------------------
319 
320  ---------------------------------------------------------------------------*/
operator =(const SwNumFmt & rNumFmt)321 SwNumFmt& SwNumFmt::operator=( const SwNumFmt& rNumFmt)
322 {
323     SvxNumberFormat::operator=(rNumFmt);
324     if( rNumFmt.GetRegisteredIn() )
325         rNumFmt.GetRegisteredInNonConst()->Add( this );
326     else if( GetRegisteredIn() )
327         GetRegisteredInNonConst()->Remove( this );
328     //For i120928,record the cp info of graphic within bullet
329     cGrfBulletCP = rNumFmt.cGrfBulletCP;
330     return *this;
331 }
332 /* -----------------------------23.02.01 09:28--------------------------------
333 
334  ---------------------------------------------------------------------------*/
operator ==(const SwNumFmt & rNumFmt) const335 sal_Bool SwNumFmt::operator==( const SwNumFmt& rNumFmt) const
336 {
337     sal_Bool bRet = SvxNumberFormat::operator==(rNumFmt) &&
338         GetRegisteredIn() == rNumFmt.GetRegisteredIn();
339     return bRet;
340 }
341 
342 /* -----------------------------22.02.01 13:44--------------------------------
343 
344  ---------------------------------------------------------------------------*/
SetCharFmt(SwCharFmt * pChFmt)345 void SwNumFmt::SetCharFmt( SwCharFmt* pChFmt)
346 {
347     if( pChFmt )
348         pChFmt->Add( this );
349     else if( GetRegisteredIn() )
350         GetRegisteredInNonConst()->Remove( this );
351 }
352 /* -----------------------------22.02.01 13:45--------------------------------
353 
354  ---------------------------------------------------------------------------*/
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)355 void SwNumFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
356 {
357     // dann suche mal in dem Doc nach dem NumRules-Object, in dem dieses
358     // NumFormat gesetzt ist. Das Format muss es nicht geben!
359     const SwCharFmt* pFmt = 0;
360     sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
361     switch( nWhich )
362     {
363     case RES_ATTRSET_CHG:
364     case RES_FMT_CHG:
365         pFmt = GetCharFmt();
366         break;
367     }
368 
369     if( pFmt && !pFmt->GetDoc()->IsInDtor() )
370         UpdateNumNodes( (SwDoc*)pFmt->GetDoc() );
371     else
372         CheckRegistration( pOld, pNew );
373 }
374 /* -----------------------------23.02.01 11:08--------------------------------
375 
376  ---------------------------------------------------------------------------*/
SetCharFmtName(const String & rSet)377 void SwNumFmt::SetCharFmtName(const String& rSet)
378 {
379     SvxNumberFormat::SetCharFmtName(rSet);
380 }
381 /* -----------------------------22.02.01 13:47--------------------------------
382 
383  ---------------------------------------------------------------------------*/
GetCharFmtName() const384 const String&   SwNumFmt::GetCharFmtName() const
385 {
386     if((SwCharFmt*)GetRegisteredIn())
387         return ((SwCharFmt*)GetRegisteredIn())->GetName();
388     else
389         return aEmptyStr;
390 }
391 
ForgetCharFmt()392 void SwNumFmt::ForgetCharFmt()
393 {
394     if ( GetRegisteredIn() )
395         GetRegisteredInNonConst()->Remove( this );
396 }
397 
398 /* -----------------------------22.02.01 16:05--------------------------------
399 
400  ---------------------------------------------------------------------------*/
SetGraphicBrush(const SvxBrushItem * pBrushItem,const Size * pSize,const sal_Int16 * pOrient)401 void    SwNumFmt::SetGraphicBrush( const SvxBrushItem* pBrushItem, const Size* pSize,
402     const sal_Int16* pOrient)
403 {
404     if(pOrient)
405         pVertOrient->SetVertOrient( *pOrient );
406     SvxNumberFormat::SetGraphicBrush( pBrushItem, pSize, pOrient);
407 }
408 /* -----------------------------22.02.01 16:05--------------------------------
409 
410  ---------------------------------------------------------------------------*/
SetVertOrient(sal_Int16 eSet)411 void    SwNumFmt::SetVertOrient(sal_Int16 eSet)
412 {
413     SvxNumberFormat::SetVertOrient(eSet);
414 }
415 /* -----------------------------22.02.01 16:05--------------------------------
416 
417  ---------------------------------------------------------------------------*/
GetVertOrient() const418 sal_Int16   SwNumFmt::GetVertOrient() const
419 {
420     return SvxNumberFormat::GetVertOrient();
421 }
422 /* -----------------------------22.02.01 13:54--------------------------------
423 
424  ---------------------------------------------------------------------------*/
UpdateNumNodes(SwDoc * pDoc)425 void SwNumFmt::UpdateNumNodes( SwDoc* pDoc )
426 {
427     sal_Bool bDocIsModified = pDoc->IsModified();
428     sal_Bool bFnd = sal_False;
429     const SwNumRule* pRule;
430     for( sal_uInt16 n = pDoc->GetNumRuleTbl().Count(); !bFnd && n; )
431     {
432         pRule = pDoc->GetNumRuleTbl()[ --n ];
433         for( sal_uInt8 i = 0; i < MAXLEVEL; ++i )
434             if( pRule->GetNumFmt( i ) == this )
435             {
436                 // --> OD 2008-02-19 #refactorlists#
437 //                const String& rRuleNm = pRule->GetName();
438 
439 //                SwModify* pMod;
440 //                const SfxPoolItem* pItem;
441 //                sal_uInt16 k, nMaxItems = pDoc->GetAttrPool().GetItemCount(
442 //                                                    RES_PARATR_NUMRULE );
443 //                for( k = 0; k < nMaxItems; ++k )
444 //                    if( 0 != (pItem = pDoc->GetAttrPool().GetItem(
445 //                        RES_PARATR_NUMRULE, k ) ) &&
446 //                        0 != ( pMod = (SwModify*)((SwNumRuleItem*)pItem)->
447 //                                GetDefinedIn()) &&
448 //                        ((SwNumRuleItem*)pItem)->GetValue() == rRuleNm )
449 //                    {
450 //                        if( pMod->IsA( TYPE( SwFmt )) )
451 //                        {
452 //                            SwNumRuleInfo aInfo( rRuleNm );
453 //                            pMod->GetInfo( aInfo );
454 
455 //                            for( sal_uLong nFirst = 0, nLast = aInfo.GetList().Count();
456 //                                nFirst < nLast; ++nFirst )
457 //                                lcl_SetRuleChgd(
458 //                                    *aInfo.GetList().GetObject( nFirst ), i );
459 //                        }
460 //                        else if( ((SwTxtNode*)pMod)->GetNodes().IsDocNodes() )
461 //                            lcl_SetRuleChgd( *(SwTxtNode*)pMod, i );
462 //                    }
463                 SwNumRule::tTxtNodeList aTxtNodeList;
464                 pRule->GetTxtNodeList( aTxtNodeList );
465                 for ( SwNumRule::tTxtNodeList::iterator aIter = aTxtNodeList.begin();
466                       aIter != aTxtNodeList.end(); ++aIter )
467                 {
468                     lcl_SetRuleChgd( *(*aIter), i );
469                 }
470                 // <--
471                 bFnd = sal_True;
472                 break;
473             }
474     }
475 
476     if( bFnd && !bDocIsModified )
477         pDoc->ResetModified();
478 }
479 /* -----------------------------31.05.01 16:08--------------------------------
480 
481  ---------------------------------------------------------------------------*/
GetGraphicOrientation() const482 const SwFmtVertOrient*      SwNumFmt::GetGraphicOrientation() const
483 {
484     sal_Int16  eOrient = SvxNumberFormat::GetVertOrient();
485     if(text::VertOrientation::NONE == eOrient)
486         return 0;
487     else
488     {
489         pVertOrient->SetVertOrient(eOrient);
490         return pVertOrient;
491     }
492 }
493 
494 #ifdef DBG_UTIL
495 long int SwNumRule::nInstances = 0;
496 #endif
497 
498 // --> OD 2008-02-11 #newlistlevelattrs#
499 // handle new parameter <eDefaultNumberFormatPositionAndSpaceMode>
SwNumRule(const String & rNm,const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,SwNumRuleType eType,sal_Bool bAutoFlg)500 SwNumRule::SwNumRule( const String& rNm,
501                       const SvxNumberFormat::SvxNumPositionAndSpaceMode eDefaultNumberFormatPositionAndSpaceMode,
502                       SwNumRuleType eType,
503                       sal_Bool bAutoFlg )
504     : maTxtNodeList(),
505       // --> OD 2008-03-03 #refactorlists#
506       maParagraphStyleList(),
507       // <--
508     pNumRuleMap(0),
509     sName( rNm ),
510     eRuleType( eType ),
511     nPoolFmtId( USHRT_MAX ),
512     nPoolHelpId( USHRT_MAX ),
513     nPoolHlpFileId( UCHAR_MAX ),
514     bAutoRuleFlag( bAutoFlg ),
515     bInvalidRuleFlag( sal_True ),
516     bContinusNum( sal_False ),
517     bAbsSpaces( sal_False ),
518     // --> OD 2005-10-21 - initialize member <mbCountPhantoms>
519     mbCountPhantoms( true ),
520     // <--
521     // --> OD 2008-02-11 #newlistlevelattrs#
522     meDefaultNumberFormatPositionAndSpaceMode( eDefaultNumberFormatPositionAndSpaceMode ),
523     // <--
524     // --> OD 2008-04-03 #refactorlists#
525     msDefaultListId()
526     // <--
527 {
528 #ifdef DBG_UTIL
529     nSerial = nInstances++;
530 #endif
531 
532     if( !nRefCount++ )          // zum erstmal, also initialisiern
533     {
534         SwNumFmt* pFmt;
535         sal_uInt8 n;
536 
537         // numbering:
538         // position-and-space mode LABEL_WIDTH_AND_POSITION:
539         for( n = 0; n < MAXLEVEL; ++n )
540         {
541             pFmt = new SwNumFmt;
542             pFmt->SetIncludeUpperLevels( 1 );
543             pFmt->SetStart( 1 );
544             pFmt->SetLSpace( lNumIndent );
545             pFmt->SetAbsLSpace( lNumIndent + SwNumRule::GetNumIndent( n ) );
546             pFmt->SetFirstLineOffset( lNumFirstLineOffset );
547             pFmt->SetSuffix( aDotStr );
548             // --> OD 2006-06-29 #b6440955#
549             pFmt->SetBulletChar( numfunc::GetBulletChar(n));
550             // <--
551             SwNumRule::aBaseFmts[ NUM_RULE ][ n ] = pFmt;
552         }
553         // --> OD 2008-02-11 #newlistlevelattrs#
554         // position-and-space mode LABEL_ALIGNMENT
555         // first line indent of general numbering in inch: -0,25 inch
556         const long cFirstLineIndent = -1440/4;
557         // indent values of general numbering in inch:
558         //  0,5         0,75        1,0         1,25        1,5
559         //  1,75        2,0         2,25        2,5         2,75
560         const long cIndentAt[ MAXLEVEL ] = {
561             1440/2,     1440*3/4,   1440,       1440*5/4,   1440*3/2,
562             1440*7/4,   1440*2,     1440*9/4,   1440*5/2,   1440*11/4 };
563         for( n = 0; n < MAXLEVEL; ++n )
564         {
565             pFmt = new SwNumFmt;
566             pFmt->SetIncludeUpperLevels( 1 );
567             pFmt->SetStart( 1 );
568             // --> OD 2008-01-15 #newlistlevelattrs#
569             pFmt->SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
570             pFmt->SetLabelFollowedBy( SvxNumberFormat::LISTTAB );
571             pFmt->SetListtabPos( cIndentAt[ n ] );
572             pFmt->SetFirstLineIndent( cFirstLineIndent );
573             pFmt->SetIndentAt( cIndentAt[ n ] );
574             // <--
575             pFmt->SetSuffix( aDotStr );
576             pFmt->SetBulletChar( numfunc::GetBulletChar(n));
577             SwNumRule::aLabelAlignmentBaseFmts[ NUM_RULE ][ n ] = pFmt;
578         }
579         // <--
580 
581         // outline:
582         // position-and-space mode LABEL_WIDTH_AND_POSITION:
583         for( n = 0; n < MAXLEVEL; ++n )
584         {
585             pFmt = new SwNumFmt;
586             pFmt->SetNumberingType(SVX_NUM_NUMBER_NONE);
587             pFmt->SetIncludeUpperLevels( MAXLEVEL );
588             pFmt->SetStart( 1 );
589             pFmt->SetCharTextDistance( lOutlineMinTextDistance );
590             // --> OD 2006-06-29 #b6440955#
591             pFmt->SetBulletChar( numfunc::GetBulletChar(n));
592             // <--
593             SwNumRule::aBaseFmts[ OUTLINE_RULE ][ n ] = pFmt;
594         }
595         // --> OD 2008-02-11 #newlistlevelattrs#
596         // position-and-space mode LABEL_ALIGNMENT:
597         // indent values of default outline numbering in inch:
598         //  0,3         0,4         0,5         0,6         0,7
599         //  0,8         0,9         1,0         1,1         1,2
600         const long cOutlineIndentAt[ MAXLEVEL ] = {
601             1440*3/10,  1440*2/5,   1440/2,     1440*3/5,   1440*7/10,
602             1440*4/5,   1440*9/10,  1440,       1440*11/10, 1440*6/5 };
603         for( n = 0; n < MAXLEVEL; ++n )
604         {
605             pFmt = new SwNumFmt;
606             pFmt->SetNumberingType(SVX_NUM_NUMBER_NONE);
607             pFmt->SetIncludeUpperLevels( MAXLEVEL );
608             pFmt->SetStart( 1 );
609             pFmt->SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
610             pFmt->SetLabelFollowedBy( SvxNumberFormat::LISTTAB );
611             pFmt->SetListtabPos( cOutlineIndentAt[ n ] );
612             pFmt->SetFirstLineIndent( -cOutlineIndentAt[ n ] );
613             pFmt->SetIndentAt( cOutlineIndentAt[ n ] );
614             pFmt->SetBulletChar( numfunc::GetBulletChar(n));
615             SwNumRule::aLabelAlignmentBaseFmts[ OUTLINE_RULE ][ n ] = pFmt;
616         }
617         // <--
618     }
619     memset( aFmts, 0, sizeof( aFmts ));
620     ASSERT( sName.Len(), "NumRule ohne Namen!" );
621 }
622 
SwNumRule(const SwNumRule & rNumRule)623 SwNumRule::SwNumRule( const SwNumRule& rNumRule )
624     : maTxtNodeList(),
625       // --> OD 2008-03-03 #refactorlists#
626       maParagraphStyleList(),
627       // <--
628       pNumRuleMap(0),
629       sName( rNumRule.sName ),
630       eRuleType( rNumRule.eRuleType ),
631       nPoolFmtId( rNumRule.GetPoolFmtId() ),
632       nPoolHelpId( rNumRule.GetPoolHelpId() ),
633       nPoolHlpFileId( rNumRule.GetPoolHlpFileId() ),
634       bAutoRuleFlag( rNumRule.bAutoRuleFlag ),
635       bInvalidRuleFlag( sal_True ),
636       bContinusNum( rNumRule.bContinusNum ),
637       bAbsSpaces( rNumRule.bAbsSpaces ),
638       // --> OD 2005-10-21 - initialize member <mbCountPhantoms>
639       mbCountPhantoms( true ),
640       // <--
641       // --> OD 2008-02-11 #newlistlevelattrs#
642       meDefaultNumberFormatPositionAndSpaceMode( rNumRule.meDefaultNumberFormatPositionAndSpaceMode ),
643       // <--
644       // --> OD 2008-04-03 #refactorlists#
645       msDefaultListId( rNumRule.msDefaultListId )
646       // <--
647 {
648 #ifdef DBG_UTIL
649     nSerial = nInstances++;
650 #endif
651 
652     ++nRefCount;
653     memset( aFmts, 0, sizeof( aFmts ));
654     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
655         if( rNumRule.aFmts[ n ] )
656             Set( n, *rNumRule.aFmts[ n ] );
657 }
658 
~SwNumRule()659 SwNumRule::~SwNumRule()
660 {
661     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
662         delete aFmts[ n ];
663 
664     if (pNumRuleMap)
665     {
666         pNumRuleMap->erase(GetName());
667     }
668 
669     if( !--nRefCount )          // der letzte macht die Tuer zu
670     {
671             // Nummerierung:
672             SwNumFmt** ppFmts = (SwNumFmt**)SwNumRule::aBaseFmts;
673             int n;
674 
675             for( n = 0; n < MAXLEVEL; ++n, ++ppFmts )
676                 delete *ppFmts, *ppFmts = 0;
677 
678             // Gliederung:
679             for( n = 0; n < MAXLEVEL; ++n, ++ppFmts )
680                 delete *ppFmts, *ppFmts = 0;
681 
682             // --> OD 2008-02-11 #newlistlevelattrs#
683             ppFmts = (SwNumFmt**)SwNumRule::aLabelAlignmentBaseFmts;
684             for( n = 0; n < MAXLEVEL; ++n, ++ppFmts )
685                 delete *ppFmts, *ppFmts = 0;
686             for( n = 0; n < MAXLEVEL; ++n, ++ppFmts )
687                 delete *ppFmts, *ppFmts = 0;
688             // <--
689     }
690 
691     // --> OD 2008-02-19 #refactorlists#
692     maTxtNodeList.clear();
693     maParagraphStyleList.clear();
694     // <--
695 }
696 
CheckCharFmts(SwDoc * pDoc)697 void SwNumRule::CheckCharFmts( SwDoc* pDoc )
698 {
699     SwCharFmt* pFmt;
700     for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
701         if( aFmts[ n ] && 0 != ( pFmt = aFmts[ n ]->GetCharFmt() ) &&
702             pFmt->GetDoc() != pDoc )
703         {
704             // dann kopieren!
705             SwNumFmt* pNew = new SwNumFmt( *aFmts[ n ] );
706             pNew->SetCharFmt( pDoc->CopyCharFmt( *pFmt ) );
707             delete aFmts[ n ];
708             aFmts[ n ] = pNew;
709         }
710 }
711 
operator =(const SwNumRule & rNumRule)712 SwNumRule& SwNumRule::operator=( const SwNumRule& rNumRule )
713 {
714     if( this != &rNumRule )
715     {
716         for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
717             Set( n, rNumRule.aFmts[ n ] );
718 
719         eRuleType = rNumRule.eRuleType;
720         sName = rNumRule.sName;
721         bAutoRuleFlag = rNumRule.bAutoRuleFlag;
722         bInvalidRuleFlag = sal_True;
723         bContinusNum = rNumRule.bContinusNum;
724         bAbsSpaces = rNumRule.bAbsSpaces;
725         nPoolFmtId = rNumRule.GetPoolFmtId();
726         nPoolHelpId = rNumRule.GetPoolHelpId();
727         nPoolHlpFileId = rNumRule.GetPoolHlpFileId();
728     }
729     return *this;
730 }
731 
732 
operator ==(const SwNumRule & rRule) const733 sal_Bool SwNumRule::operator==( const SwNumRule& rRule ) const
734 {
735     sal_Bool bRet = eRuleType == rRule.eRuleType &&
736                 sName == rRule.sName &&
737                 bAutoRuleFlag == rRule.bAutoRuleFlag &&
738                 bContinusNum == rRule.bContinusNum &&
739                 bAbsSpaces == rRule.bAbsSpaces &&
740                 nPoolFmtId == rRule.GetPoolFmtId() &&
741                 nPoolHelpId == rRule.GetPoolHelpId() &&
742                 nPoolHlpFileId == rRule.GetPoolHlpFileId();
743     if( bRet )
744     {
745         for( sal_uInt8 n = 0; n < MAXLEVEL; ++n )
746             if( !( rRule.Get( n ) == Get( n ) ))
747             {
748                 bRet = sal_False;
749                 break;
750             }
751     }
752     return bRet;
753 }
754 
755 
Set(sal_uInt16 i,const SwNumFmt & rNumFmt)756 void SwNumRule::Set( sal_uInt16 i, const SwNumFmt& rNumFmt )
757 {
758     ASSERT( i < MAXLEVEL, "Serious defect, please inform OD" )
759     if( i < MAXLEVEL )
760     {
761         if( !aFmts[ i ] || !(rNumFmt == Get( i )) )
762         {
763             delete aFmts[ i ];
764             aFmts[ i ] = new SwNumFmt( rNumFmt );
765             bInvalidRuleFlag = sal_True;
766         }
767     }
768 }
769 
Set(sal_uInt16 i,const SwNumFmt * pNumFmt)770 void SwNumRule::Set( sal_uInt16 i, const SwNumFmt* pNumFmt )
771 {
772     ASSERT( i < MAXLEVEL, "Serious defect, please inform OD" )
773     if( i >= MAXLEVEL )
774         return;
775     SwNumFmt* pOld = aFmts[ i ];
776     if( !pOld )
777     {
778         if( pNumFmt )
779         {
780             aFmts[ i ] = new SwNumFmt( *pNumFmt );
781             bInvalidRuleFlag = sal_True;
782         }
783     }
784     else if( !pNumFmt )
785         delete pOld, aFmts[ i ] = 0, bInvalidRuleFlag = sal_True;
786     else if( *pOld != *pNumFmt )
787         *pOld = *pNumFmt, bInvalidRuleFlag = sal_True;
788 }
789 
790 
MakeNumString(const SwNodeNum & rNum,sal_Bool bInclStrings,sal_Bool bOnlyArabic) const791 String SwNumRule::MakeNumString( const SwNodeNum& rNum, sal_Bool bInclStrings,
792                                 sal_Bool bOnlyArabic ) const
793 {
794     String aStr;
795 
796     if (rNum.IsCounted())
797         aStr = MakeNumString(rNum.GetNumberVector(),
798                              bInclStrings, bOnlyArabic, MAXLEVEL);
799 
800     return aStr;
801 }
802 
MakeNumString(const SwNumberTree::tNumberVector & rNumVector,const sal_Bool bInclStrings,const sal_Bool bOnlyArabic,const unsigned int _nRestrictToThisLevel) const803 String SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVector,
804                                  const sal_Bool bInclStrings,
805                                  const sal_Bool bOnlyArabic,
806                                  const unsigned int _nRestrictToThisLevel ) const
807 {
808     String aStr;
809 
810     unsigned int nLevel = rNumVector.size() - 1;
811     // --> OD 2005-10-17 #126238#
812     if ( nLevel > _nRestrictToThisLevel )
813     {
814         nLevel = _nRestrictToThisLevel;
815     }
816     // <--
817 
818     if (nLevel < MAXLEVEL)
819     {
820         const SwNumFmt& rMyNFmt = Get( static_cast<sal_uInt16>(nLevel) );
821         // --> OD 2006-06-02 #b6432095#
822         // - levels with numbering none has to provide prefix and suffix string
823 //        if( SVX_NUM_NUMBER_NONE != rMyNFmt.GetNumberingType() )
824         // <--
825         {
826             sal_uInt8 i = static_cast<sal_uInt8>(nLevel);
827 
828             if( !IsContinusNum() &&
829                 // --> OD 2006-09-19 #i69672#
830                 // - do not include upper levels, if level isn't numbered.
831                 rMyNFmt.GetNumberingType() != SVX_NUM_NUMBER_NONE &&
832                 // <--
833                 rMyNFmt.GetIncludeUpperLevels() )  // nur der eigene Level ?
834             {
835                 sal_uInt8 n = rMyNFmt.GetIncludeUpperLevels();
836                 if( 1 < n )
837                 {
838                     if( i+1 >= n )
839                         i -= n - 1;
840                     else
841                         i = 0;
842                 }
843             }
844 
845             for( ; i <= nLevel; ++i )
846             {
847                 const SwNumFmt& rNFmt = Get( i );
848                 if( SVX_NUM_NUMBER_NONE == rNFmt.GetNumberingType() )
849                 {
850                     // Soll aus 1.1.1 --> 2. NoNum --> 1..1 oder 1.1 ??
851                     //                 if( i != rNum.nMyLevel )
852                     //                    aStr += aDotStr;
853                     continue;
854                 }
855 
856                 if( rNumVector[ i ] )
857                 {
858                     if( bOnlyArabic )
859                         aStr += String::CreateFromInt32( rNumVector[ i ] );
860                     else
861                         aStr += rNFmt.GetNumStr( rNumVector[ i ] );
862                 }
863                 else
864                     aStr += '0';        // alle 0-Level sind eine 0
865                 if( i != nLevel && aStr.Len() )
866                     aStr += aDotStr;
867             }
868 
869             //JP 14.12.99: the type dont have any number, so dont append
870             //              the Post-/Prefix String
871             if( bInclStrings && !bOnlyArabic &&
872                 SVX_NUM_CHAR_SPECIAL != rMyNFmt.GetNumberingType() &&
873                 SVX_NUM_BITMAP != rMyNFmt.GetNumberingType() )
874             {
875                 aStr.Insert( rMyNFmt.GetPrefix(), 0 );
876                 aStr += rMyNFmt.GetSuffix();
877             }
878         }
879     }
880 
881     return aStr;
882 }
883 
884 // --> OD 2007-09-07 #i81002#
MakeRefNumString(const SwNodeNum & rNodeNum,const bool bInclSuperiorNumLabels,const sal_uInt8 nRestrictInclToThisLevel) const885 String SwNumRule::MakeRefNumString( const SwNodeNum& rNodeNum,
886                                     const bool bInclSuperiorNumLabels,
887                                     const sal_uInt8 nRestrictInclToThisLevel ) const
888 {
889     String aRefNumStr;
890 
891     if ( rNodeNum.GetLevelInListTree() >= 0 )
892     {
893         const SwNodeNum* pWorkingNodeNum( &rNodeNum );
894         do
895         {
896             bool bMakeNumStringForPhantom( false );
897             if ( pWorkingNodeNum->IsPhantom() )
898             {
899                 SwNumFmt aFmt( Get( static_cast<sal_uInt16>(pWorkingNodeNum->GetLevelInListTree()) ) );
900                 bMakeNumStringForPhantom = aFmt.IsEnumeration() &&
901                                            SVX_NUM_NUMBER_NONE != aFmt.GetNumberingType();
902 
903             }
904             if ( bMakeNumStringForPhantom ||
905                  ( !pWorkingNodeNum->IsPhantom() &&
906                    pWorkingNodeNum->GetTxtNode() &&
907                    pWorkingNodeNum->GetTxtNode()->HasNumber() ) )
908             {
909                 aRefNumStr.Insert( MakeNumString( pWorkingNodeNum->GetNumberVector() ), 0 );
910             }
911             else if ( aRefNumStr.Len() > 0 )
912             {
913                 aRefNumStr.Insert( String::CreateFromAscii(" "), 0 );
914             }
915 
916             if ( bInclSuperiorNumLabels && pWorkingNodeNum->GetLevelInListTree() > 0 )
917             {
918                 sal_uInt8 n = Get( static_cast<sal_uInt16>(pWorkingNodeNum->GetLevelInListTree()) ).GetIncludeUpperLevels();
919                 pWorkingNodeNum = dynamic_cast<SwNodeNum*>(pWorkingNodeNum->GetParent());
920                 // skip parents, whose list label is already contained in the actual list label.
921                 while ( pWorkingNodeNum && n > 1 )
922                 {
923                     pWorkingNodeNum = dynamic_cast<SwNodeNum*>(pWorkingNodeNum->GetParent());
924                     --n;
925                 }
926             }
927             else
928             {
929                 break;
930             }
931         } while ( pWorkingNodeNum &&
932                   pWorkingNodeNum->GetLevelInListTree() >= 0 &&
933                   static_cast<sal_uInt8>(pWorkingNodeNum->GetLevelInListTree()) >= nRestrictInclToThisLevel );
934     }
935 
936     return aRefNumStr;
937 }
938 
939 //  ----- Copy-Methode vom SwNumRule ------
940 
941     // eine Art Copy-Constructor, damit die Num-Formate auch an den
942     // richtigen CharFormaten eines Dokumentes haengen !!
943     // (Kopiert die NumFormate und returnt sich selbst)
944 
CopyNumRule(SwDoc * pDoc,const SwNumRule & rNumRule)945 SwNumRule& SwNumRule::CopyNumRule( SwDoc* pDoc, const SwNumRule& rNumRule )
946 {
947     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
948     {
949         Set( n, rNumRule.aFmts[ n ] );
950         if( aFmts[ n ] && aFmts[ n ]->GetCharFmt() &&
951             USHRT_MAX == pDoc->GetCharFmts()->GetPos( aFmts[n]->GetCharFmt() ))
952             // ueber unterschiedliche Dokumente kopieren, dann
953             // kopiere das entsprechende Char-Format ins neue
954             // Dokument.
955             aFmts[n]->SetCharFmt( pDoc->CopyCharFmt( *aFmts[n]->
956                                         GetCharFmt() ) );
957     }
958     eRuleType = rNumRule.eRuleType;
959     sName = rNumRule.sName;
960     bAutoRuleFlag = rNumRule.bAutoRuleFlag;
961     nPoolFmtId = rNumRule.GetPoolFmtId();
962     nPoolHelpId = rNumRule.GetPoolHelpId();
963     nPoolHlpFileId = rNumRule.GetPoolHlpFileId();
964     bInvalidRuleFlag = sal_True;
965     return *this;
966 }
967 /* -----------------30.10.98 08:33-------------------
968  *
969  * --------------------------------------------------*/
SetSvxRule(const SvxNumRule & rNumRule,SwDoc * pDoc)970 void SwNumRule::SetSvxRule(const SvxNumRule& rNumRule, SwDoc* pDoc)
971 {
972     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
973     {
974         const SvxNumberFormat* pSvxFmt = rNumRule.Get(n);
975         delete aFmts[n];
976         aFmts[n] = pSvxFmt ? new SwNumFmt(*pSvxFmt, pDoc) : 0;
977     }
978 
979     bInvalidRuleFlag = sal_True;
980     bContinusNum = rNumRule.IsContinuousNumbering();
981 }
982 /* -----------------30.10.98 08:33-------------------
983  *
984  * --------------------------------------------------*/
MakeSvxNumRule() const985 SvxNumRule SwNumRule::MakeSvxNumRule() const
986 {
987     SvxNumRule aRule(NUM_CONTINUOUS|NUM_CHAR_TEXT_DISTANCE|NUM_CHAR_STYLE|
988                         NUM_ENABLE_LINKED_BMP|NUM_ENABLE_EMBEDDED_BMP,
989                         MAXLEVEL, bContinusNum,
990                         eRuleType ==
991                             NUM_RULE ?
992                                 SVX_RULETYPE_NUMBERING :
993                                     SVX_RULETYPE_OUTLINE_NUMBERING );
994     for( sal_uInt16 n = 0; n < MAXLEVEL; ++n )
995     {
996         SwNumFmt aNumFmt = Get(n);
997         if(aNumFmt.GetCharFmt())
998             aNumFmt.SetCharFmtName(aNumFmt.GetCharFmt()->GetName());
999         aRule.SetLevel(n, aNumFmt, aFmts[n] != 0);
1000     }
1001     return aRule;
1002 }
1003 
SetInvalidRule(sal_Bool bFlag)1004 void SwNumRule::SetInvalidRule(sal_Bool bFlag)
1005 {
1006     if (bFlag)
1007     {
1008         // --> OD 2008-03-13 #refactorlists#
1009 //        tPamAndNums::iterator aIt;
1010 //        for (aIt = aNumberRanges.begin(); aIt != aNumberRanges.end(); aIt++)
1011 //            (*aIt).second->InvalidateTree();
1012         std::set< SwList* > aLists;
1013         tTxtNodeList::iterator aIter;
1014         for ( aIter = maTxtNodeList.begin(); aIter != maTxtNodeList.end(); ++aIter )
1015         {
1016             const SwTxtNode* pTxtNode = *aIter;
1017             // --> OD 2010-06-04 #i111681# - applying patch from cmc
1018 //            aLists.insert( pTxtNode->GetDoc()->getListByName( pTxtNode->GetListId() ) );
1019             SwList* pList = pTxtNode->GetDoc()->getListByName( pTxtNode->GetListId() );
1020             ASSERT( pList, "<SwNumRule::SetInvalidRule(..)> - list at which the text node is registered at does not exist. This is a serious issue --> please inform OD.");
1021             if ( pList )
1022             {
1023                 aLists.insert( pList );
1024             }
1025             // <--
1026         }
1027         std::for_each( aLists.begin(), aLists.end(),
1028                        std::mem_fn( &SwList::InvalidateListTree ) );
1029         // <--
1030     }
1031 
1032     bInvalidRuleFlag = bFlag;
1033 }
1034 
1035 // --> OD 2008-06-16 #i90078#
1036 // #i23725#, #i23726#
1037 //void SwNumRule::Indent(short nAmount, int nLevel, int nReferenceLevel,
1038 //                       sal_Bool bRelative, sal_Bool bFirstLine, sal_Bool bCheckGtZero)
1039 //{
1040 //    int nStartLevel = 0;
1041 //    int nEndLevel = MAXLEVEL - 1;
1042 //    sal_Bool bGotInvalid = sal_False;
1043 
1044 //    if (nLevel >= 0)
1045 //        nStartLevel = nEndLevel = nLevel;
1046 
1047 //    int i;
1048 //    short nRealAmount =  nAmount;
1049 
1050 //    if (! bRelative)
1051 //    {
1052 //        if (bFirstLine)
1053 //        {
1054 //            if (nReferenceLevel >= 0)
1055 //                nAmount = nAmount - Get(static_cast<sal_uInt16>(nReferenceLevel)).GetFirstLineOffset();
1056 //            else
1057 //                nAmount = nAmount - Get(static_cast<sal_uInt16>(nStartLevel)).GetFirstLineOffset();
1058 //        }
1059 
1060 //        sal_Bool bFirst = sal_True;
1061 
1062 //        if (nReferenceLevel >= 0)
1063 //            nRealAmount = nAmount - Get(static_cast<sal_uInt16>(nReferenceLevel)).GetAbsLSpace();
1064 //        else
1065 //            for (i = nStartLevel; i < nEndLevel + 1; i++)
1066 //            {
1067 //                short nTmp = nAmount - Get(static_cast<sal_uInt16>(i)).GetAbsLSpace();
1068 
1069 //                if (bFirst || nTmp > nRealAmount)
1070 //                {
1071 //                    nRealAmount = nTmp;
1072 //                    bFirst = sal_False;
1073 //                }
1074 //            }
1075 //    }
1076 
1077 //    if (nRealAmount < 0)
1078 //        for (i = nStartLevel; i < nEndLevel + 1; i++)
1079 //            if (Get(static_cast<sal_uInt16>(i)).GetAbsLSpace() + nRealAmount < 0)
1080 //                nRealAmount = -Get(static_cast<sal_uInt16>(i)).GetAbsLSpace();
1081 
1082 //    for (i = nStartLevel; i < nEndLevel + 1; i++)
1083 //    {
1084 //        short nNew = Get(static_cast<sal_uInt16>(i)).GetAbsLSpace() + nRealAmount;
1085 
1086 //        if (bCheckGtZero && nNew < 0)
1087 //            nNew = 0;
1088 
1089 //        SwNumFmt aTmpNumFmt(Get(static_cast<sal_uInt16>(i)));
1090 //        aTmpNumFmt.SetAbsLSpace(nNew);
1091 
1092 //        Set(static_cast<sal_uInt16>(i), aTmpNumFmt);
1093 
1094 //        bGotInvalid = sal_True;
1095 //    }
1096 
1097 //    if (bGotInvalid)
1098 //        SetInvalidRule(bGotInvalid);
1099 //}
1100 
1101 // change indent of all list levels by given difference
ChangeIndent(const short nDiff)1102 void SwNumRule::ChangeIndent( const short nDiff )
1103 {
1104     for ( sal_uInt16 i = 0; i < MAXLEVEL; ++i )
1105     {
1106         SwNumFmt aTmpNumFmt( Get(i) );
1107 
1108         const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
1109                                         aTmpNumFmt.GetPositionAndSpaceMode() );
1110         if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1111         {
1112             short nNewIndent = nDiff +
1113                                aTmpNumFmt.GetAbsLSpace();
1114             if ( nNewIndent < 0 )
1115             {
1116                 nNewIndent = 0;
1117             }
1118             aTmpNumFmt.SetAbsLSpace( nNewIndent );
1119         }
1120         else if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
1121         {
1122             // --> OD 2009-01-20 #i93399#
1123             // adjust also the list tab position, if a list tab stop is applied
1124             if ( aTmpNumFmt.GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
1125             {
1126                 const long nNewListTab = aTmpNumFmt.GetListtabPos() +  nDiff;
1127                 aTmpNumFmt.SetListtabPos( nNewListTab );
1128             }
1129             // <--
1130             const long nNewIndent = nDiff +
1131                               aTmpNumFmt.GetIndentAt();
1132             aTmpNumFmt.SetIndentAt( nNewIndent );
1133         }
1134 
1135         Set( i, aTmpNumFmt );
1136     }
1137 
1138     SetInvalidRule( sal_True );
1139 }
1140 
1141 // set indent of certain list level to given value
SetIndent(const short nNewIndent,const sal_uInt16 nListLevel)1142 void SwNumRule::SetIndent( const short nNewIndent,
1143                            const sal_uInt16 nListLevel )
1144 {
1145     SwNumFmt aTmpNumFmt( Get(nListLevel) );
1146 
1147     const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
1148                                         aTmpNumFmt.GetPositionAndSpaceMode() );
1149     if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1150     {
1151         aTmpNumFmt.SetAbsLSpace( nNewIndent );
1152     }
1153     else if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
1154     {
1155         // --> OD 2009-01-20 #i93399#
1156         // adjust also the list tab position, if a list tab stop is applied
1157         if ( aTmpNumFmt.GetLabelFollowedBy() == SvxNumberFormat::LISTTAB )
1158         {
1159             const long nNewListTab = aTmpNumFmt.GetListtabPos() +
1160                                      ( nNewIndent - aTmpNumFmt.GetIndentAt() );
1161             aTmpNumFmt.SetListtabPos( nNewListTab );
1162         }
1163         // <--
1164         aTmpNumFmt.SetIndentAt( nNewIndent );
1165     }
1166 
1167     SetInvalidRule( sal_True );
1168 }
1169 
1170 // set indent of first list level to given value and change other list level's
1171 // indents accordingly
SetIndentOfFirstListLevelAndChangeOthers(const short nNewIndent)1172 void SwNumRule::SetIndentOfFirstListLevelAndChangeOthers( const short nNewIndent )
1173 {
1174     SwNumFmt aTmpNumFmt( Get(0) );
1175 
1176     short nDiff( 0 );
1177     const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
1178                                         aTmpNumFmt.GetPositionAndSpaceMode() );
1179     if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
1180     {
1181         nDiff = nNewIndent
1182                 - aTmpNumFmt.GetFirstLineOffset()
1183                 - aTmpNumFmt.GetAbsLSpace();
1184     }
1185     else if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
1186     {
1187         nDiff = static_cast<short>(nNewIndent
1188                                    - aTmpNumFmt.GetIndentAt());
1189     }
1190     if ( nDiff != 0  )
1191     {
1192         ChangeIndent( nDiff );
1193     }
1194 }
1195 // <--
1196 
Validate()1197 void SwNumRule::Validate()
1198 {
1199     // --> OD 2008-03-13 #refactorlists#
1200 //    tPamAndNums::iterator aIt;
1201 //    for (aIt = aNumberRanges.begin(); aIt != aNumberRanges.end(); aIt++)
1202 //        (*aIt).second->NotifyInvalidChildren();
1203     std::set< SwList* > aLists;
1204     tTxtNodeList::iterator aIter;
1205     for ( aIter = maTxtNodeList.begin(); aIter != maTxtNodeList.end(); ++aIter )
1206     {
1207         const SwTxtNode* pTxtNode = *aIter;
1208         aLists.insert( pTxtNode->GetDoc()->getListByName( pTxtNode->GetListId() ) );
1209     }
1210     std::for_each( aLists.begin(), aLists.end(),
1211                    std::mem_fn( &SwList::ValidateListTree ) );
1212     // <--
1213 
1214     SetInvalidRule(sal_False);
1215 }
1216 
IsCountPhantoms() const1217 bool SwNumRule::IsCountPhantoms() const
1218 {
1219     return mbCountPhantoms;
1220 }
1221 
SetCountPhantoms(bool bCountPhantoms)1222 void SwNumRule::SetCountPhantoms(bool bCountPhantoms)
1223 {
1224     mbCountPhantoms = bCountPhantoms;
1225 }
1226 
1227 // --> OD 2008-03-03 #refactorlists#
GetParagraphStyleListSize() const1228 SwNumRule::tParagraphStyleList::size_type SwNumRule::GetParagraphStyleListSize() const
1229 {
1230     return maParagraphStyleList.size();
1231 }
1232 
AddParagraphStyle(SwTxtFmtColl & rTxtFmtColl)1233 void SwNumRule::AddParagraphStyle( SwTxtFmtColl& rTxtFmtColl )
1234 {
1235     tParagraphStyleList::iterator aIter =
1236         std::find( maParagraphStyleList.begin(), maParagraphStyleList.end(), &rTxtFmtColl );
1237 
1238     if ( aIter == maParagraphStyleList.end() )
1239     {
1240         maParagraphStyleList.push_back( &rTxtFmtColl );
1241     }
1242 }
1243 
RemoveParagraphStyle(SwTxtFmtColl & rTxtFmtColl)1244 void SwNumRule::RemoveParagraphStyle( SwTxtFmtColl& rTxtFmtColl )
1245 {
1246     tParagraphStyleList::iterator aIter =
1247         std::find( maParagraphStyleList.begin(), maParagraphStyleList.end(), &rTxtFmtColl );
1248 
1249     if ( aIter != maParagraphStyleList.end() )
1250     {
1251         maParagraphStyleList.erase( aIter );
1252     }
1253 }
1254 // <--
1255 
1256 // --> OD 2006-06-27 #b6440955#
1257 namespace numfunc
1258 {
1259     /** class containing default bullet list configuration data
1260 
1261         @author OD
1262     */
1263     class SwDefBulletConfig : private utl::ConfigItem
1264     {
1265         public:
getInstance()1266             static SwDefBulletConfig* getInstance()
1267             {
1268                 if ( mpInstance == 0 )
1269                 {
1270                     mpInstance = new SwDefBulletConfig;
1271                 }
1272 
1273                 return mpInstance;
1274             }
1275 
GetFontname() const1276             inline const String& GetFontname() const
1277             {
1278                 return msFontname;
1279             }
1280             // --> OD 2008-06-02 #i63395#
IsFontnameUserDefined() const1281             inline bool IsFontnameUserDefined() const
1282             {
1283                 return mbUserDefinedFontname;
1284             }
1285             // <--
GetFont() const1286             inline const Font& GetFont() const
1287             {
1288                 return *mpFont;
1289             }
GetFontWeight() const1290             inline short GetFontWeight() const
1291             {
1292                 return static_cast<short>(meFontWeight);
1293             }
GetFontItalic() const1294             inline short GetFontItalic() const
1295             {
1296                 return static_cast<short>(meFontItalic);
1297             }
GetChar(sal_uInt8 p_nListLevel) const1298             inline sal_Unicode GetChar( sal_uInt8 p_nListLevel ) const
1299             {
1300                 if (p_nListLevel >= MAXLEVEL)
1301                 {
1302                     p_nListLevel = MAXLEVEL - 1;
1303                 }
1304 
1305                 return mnLevelChars[p_nListLevel];
1306             }
1307 
1308         private:
1309             SwDefBulletConfig();
1310 
1311             /** sets internal default bullet configuration data to default values
1312 
1313                 @author OD
1314             */
1315             void SetToDefault();
1316 
1317             /** returns sequence of default bullet configuration property names
1318 
1319                 @author OD
1320             */
1321             uno::Sequence<rtl::OUString> GetPropNames() const;
1322 
1323             /** loads default bullet configuration properties and applies
1324                 values to internal data
1325 
1326                 @author OD
1327             */
1328             void LoadConfig();
1329 
1330             /** initialize font instance for default bullet list
1331 
1332                 @author OD
1333             */
1334             void InitFont();
1335 
1336             /** catches notification about changed default bullet configuration data
1337 
1338                 @author OD
1339             */
1340             virtual void Notify( const uno::Sequence<rtl::OUString>& aPropertyNames );
1341             virtual void Commit();
1342 
1343             static SwDefBulletConfig* mpInstance;
1344 
1345             // default bullet list configuration data
1346             String msFontname;
1347             // --> OD 2008-06-02 #i63395#
1348             bool mbUserDefinedFontname;
1349             // <--
1350             FontWeight meFontWeight;
1351             FontItalic meFontItalic;
1352             sal_Unicode mnLevelChars[MAXLEVEL];
1353 
1354             // default bullet list font instance
1355             Font* mpFont;
1356     };
1357 
1358     SwDefBulletConfig* SwDefBulletConfig::mpInstance = 0;
1359 
SwDefBulletConfig()1360     SwDefBulletConfig::SwDefBulletConfig()
1361         : ConfigItem( rtl::OUString::createFromAscii("Office.Writer/Numbering/DefaultBulletList") ),
1362           // --> OD 2008-06-02 #i63395#
1363           // default bullet font is now OpenSymbol
1364           msFontname( String::CreateFromAscii("OpenSymbol") ),
1365           mbUserDefinedFontname( false ),
1366           // <--
1367           meFontWeight( WEIGHT_DONTKNOW ),
1368           meFontItalic( ITALIC_NONE ),
1369           mpFont( 0 )
1370     {
1371         SetToDefault();
1372         LoadConfig();
1373         InitFont();
1374 
1375         // enable notification for changes on default bullet configuration change
1376         EnableNotification( GetPropNames() );
1377     }
1378 
SetToDefault()1379     void SwDefBulletConfig::SetToDefault()
1380     {
1381         // --> OD 2008-06-02 #i63395#
1382         // default bullet font name is now OpenSymbol
1383 //        msFontname = String::CreateFromAscii("StarSymbol");
1384         msFontname = String::CreateFromAscii("OpenSymbol");
1385         mbUserDefinedFontname = false;
1386         // <--
1387         meFontWeight = WEIGHT_DONTKNOW;
1388         meFontItalic = ITALIC_NONE;
1389 
1390         // --> OD 2008-06-03 #i63395#
1391         // new bullet characters
1392 //        mnLevelChars[0] = 0x25cf;
1393 //        mnLevelChars[1] = 0x25cb;
1394 //        mnLevelChars[2] = 0x25a0;
1395 //        mnLevelChars[3] = 0x25cf;
1396 //        mnLevelChars[4] = 0x25cb;
1397 //        mnLevelChars[5] = 0x25a0;
1398 //        mnLevelChars[6] = 0x25cf;
1399 //        mnLevelChars[7] = 0x25cb;
1400 //        mnLevelChars[8] = 0x25a0;
1401 //        mnLevelChars[9] = 0x25cf;
1402         mnLevelChars[0] = 0x2022;
1403         mnLevelChars[1] = 0x25e6;
1404         mnLevelChars[2] = 0x25aa;
1405         mnLevelChars[3] = 0x2022;
1406         mnLevelChars[4] = 0x25e6;
1407         mnLevelChars[5] = 0x25aa;
1408         mnLevelChars[6] = 0x2022;
1409         mnLevelChars[7] = 0x25e6;
1410         mnLevelChars[8] = 0x25aa;
1411         mnLevelChars[9] = 0x2022;
1412         // <--
1413     }
1414 
GetPropNames() const1415     uno::Sequence<rtl::OUString> SwDefBulletConfig::GetPropNames() const
1416     {
1417         uno::Sequence<rtl::OUString> aPropNames(13);
1418         rtl::OUString* pNames = aPropNames.getArray();
1419         pNames[0] = rtl::OUString::createFromAscii("BulletFont/FontFamilyname");
1420         pNames[1] = rtl::OUString::createFromAscii("BulletFont/FontWeight");
1421         pNames[2] = rtl::OUString::createFromAscii("BulletFont/FontItalic");
1422         pNames[3] = rtl::OUString::createFromAscii("BulletCharLvl1");
1423         pNames[4] = rtl::OUString::createFromAscii("BulletCharLvl2");
1424         pNames[5] = rtl::OUString::createFromAscii("BulletCharLvl3");
1425         pNames[6] = rtl::OUString::createFromAscii("BulletCharLvl4");
1426         pNames[7] = rtl::OUString::createFromAscii("BulletCharLvl5");
1427         pNames[8] = rtl::OUString::createFromAscii("BulletCharLvl6");
1428         pNames[9] = rtl::OUString::createFromAscii("BulletCharLvl7");
1429         pNames[10] = rtl::OUString::createFromAscii("BulletCharLvl8");
1430         pNames[11] = rtl::OUString::createFromAscii("BulletCharLvl9");
1431         pNames[12] = rtl::OUString::createFromAscii("BulletCharLvl10");
1432 
1433         return aPropNames;
1434     }
1435 
LoadConfig()1436     void SwDefBulletConfig::LoadConfig()
1437     {
1438         uno::Sequence<rtl::OUString> aPropNames = GetPropNames();
1439         uno::Sequence<uno::Any> aValues =
1440                                                     GetProperties( aPropNames );
1441         const uno::Any* pValues = aValues.getConstArray();
1442         ASSERT( aValues.getLength() == aPropNames.getLength(),
1443                 "<SwDefBulletConfig::SwDefBulletConfig()> - GetProperties failed")
1444         if ( aValues.getLength() == aPropNames.getLength() )
1445         {
1446             for ( int nProp = 0; nProp < aPropNames.getLength(); ++nProp )
1447             {
1448                 if ( pValues[nProp].hasValue() )
1449                 {
1450                     switch ( nProp )
1451                     {
1452                         case 0:
1453                         {
1454                             rtl::OUString aStr;
1455                             pValues[nProp] >>= aStr;
1456                             msFontname = aStr;
1457                             // --> OD 2008-06-02 #i63395#
1458                             mbUserDefinedFontname = true;
1459                             // <--
1460                         }
1461                         break;
1462                         case 1:
1463                         case 2:
1464                         {
1465                             sal_uInt8 nTmp = 0;
1466                             pValues[nProp] >>= nTmp;
1467                             if ( nProp == 1 )
1468                                 meFontWeight = static_cast<FontWeight>(nTmp);
1469                             else if ( nProp == 2 )
1470                                 meFontItalic = static_cast<FontItalic>(nTmp);
1471                         }
1472                         break;
1473                         case 3:
1474                         case 4:
1475                         case 5:
1476                         case 6:
1477                         case 7:
1478                         case 8:
1479                         case 9:
1480                         case 10:
1481                         case 11:
1482                         case 12:
1483                         {
1484                             sal_Unicode cChar = sal_Unicode();
1485                             pValues[nProp] >>= cChar;
1486                             mnLevelChars[nProp-3] = cChar;
1487                         }
1488                         break;
1489                     }
1490                 }
1491             }
1492         }
1493 
1494     }
1495 
InitFont()1496     void SwDefBulletConfig::InitFont()
1497     {
1498         delete mpFont;
1499 
1500         mpFont = new Font( msFontname, aEmptyStr, Size( 0, 14 ) );
1501         mpFont->SetWeight( meFontWeight );
1502         mpFont->SetItalic( meFontItalic );
1503     }
1504 
Notify(const uno::Sequence<rtl::OUString> &)1505     void SwDefBulletConfig::Notify( const uno::Sequence<rtl::OUString>& )
1506     {
1507         SetToDefault();
1508         LoadConfig();
1509         InitFont();
1510     }
1511 
Commit()1512     void SwDefBulletConfig::Commit()
1513     {
1514     }
1515 
GetDefBulletFontname()1516     const String& GetDefBulletFontname()
1517     {
1518         return SwDefBulletConfig::getInstance()->GetFontname();
1519     }
1520 
1521     // --> OD 2008-06-02 #i63395#
IsDefBulletFontUserDefined()1522     bool IsDefBulletFontUserDefined()
1523     {
1524         return SwDefBulletConfig::getInstance()->IsFontnameUserDefined();
1525     }
1526     // <--
1527 
GetDefBulletFont()1528     const Font& GetDefBulletFont()
1529     {
1530         return SwDefBulletConfig::getInstance()->GetFont();
1531     }
1532 
GetBulletChar(sal_uInt8 nLevel)1533     sal_Unicode GetBulletChar( sal_uInt8 nLevel )
1534     {
1535         return SwDefBulletConfig::getInstance()->GetChar( nLevel );
1536     }
1537 
1538     /** class containing configuration data about user interface behavior
1539         regarding lists and list items.
1540 
1541         OD 2007-10-01 #b660435#
1542         configuration item about behavior of <TAB>/<SHIFT-TAB>-key at first
1543         position of first list item
1544 
1545         @author OD
1546     */
1547     class SwNumberingUIBehaviorConfig : private utl::ConfigItem
1548     {
1549         public:
getInstance()1550             static SwNumberingUIBehaviorConfig* getInstance()
1551             {
1552                 if ( mpInstance == 0 )
1553                 {
1554                     mpInstance = new SwNumberingUIBehaviorConfig();
1555                 }
1556 
1557                 return mpInstance;
1558             }
1559 
ChangeIndentOnTabAtFirstPosOfFirstListItem() const1560             inline sal_Bool ChangeIndentOnTabAtFirstPosOfFirstListItem() const
1561             {
1562                 return mbChangeIndentOnTabAtFirstPosOfFirstListItem;
1563             }
1564 
1565         private:
1566             SwNumberingUIBehaviorConfig();
1567 
1568             /** sets internal configuration data to default values
1569 
1570                 @author OD
1571             */
1572             void SetToDefault();
1573 
1574             /** returns sequence of configuration property names
1575 
1576                 @author OD
1577             */
1578             com::sun::star::uno::Sequence<rtl::OUString> GetPropNames() const;
1579 
1580             /** loads configuration properties and applies values to internal data
1581 
1582                 @author OD
1583             */
1584             void LoadConfig();
1585 
1586             /** catches notification about changed configuration data
1587 
1588                 @author OD
1589             */
1590             virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames );
1591             virtual void Commit();
1592 
1593             static SwNumberingUIBehaviorConfig* mpInstance;
1594 
1595             // configuration data
1596             sal_Bool mbChangeIndentOnTabAtFirstPosOfFirstListItem;
1597     };
1598 
1599     SwNumberingUIBehaviorConfig* SwNumberingUIBehaviorConfig::mpInstance = 0;
1600 
SwNumberingUIBehaviorConfig()1601     SwNumberingUIBehaviorConfig::SwNumberingUIBehaviorConfig()
1602         : ConfigItem( rtl::OUString::createFromAscii("Office.Writer/Numbering/UserInterfaceBehavior") ),
1603           mbChangeIndentOnTabAtFirstPosOfFirstListItem( sal_True )
1604     {
1605         SetToDefault();
1606         LoadConfig();
1607 
1608         // enable notification for changes on configuration change
1609         EnableNotification( GetPropNames() );
1610     }
1611 
SetToDefault()1612     void SwNumberingUIBehaviorConfig::SetToDefault()
1613     {
1614         mbChangeIndentOnTabAtFirstPosOfFirstListItem = sal_True;
1615     }
1616 
GetPropNames() const1617     com::sun::star::uno::Sequence<rtl::OUString> SwNumberingUIBehaviorConfig::GetPropNames() const
1618     {
1619         com::sun::star::uno::Sequence<rtl::OUString> aPropNames(1);
1620         rtl::OUString* pNames = aPropNames.getArray();
1621         pNames[0] = rtl::OUString::createFromAscii("ChangeIndentOnTabAtFirstPosOfFirstListItem");
1622 
1623         return aPropNames;
1624     }
1625 
Commit()1626     void SwNumberingUIBehaviorConfig::Commit() {}
1627 
LoadConfig()1628     void SwNumberingUIBehaviorConfig::LoadConfig()
1629     {
1630         com::sun::star::uno::Sequence<rtl::OUString> aPropNames = GetPropNames();
1631         com::sun::star::uno::Sequence<com::sun::star::uno::Any> aValues =
1632                                                     GetProperties( aPropNames );
1633         const com::sun::star::uno::Any* pValues = aValues.getConstArray();
1634         ASSERT( aValues.getLength() == aPropNames.getLength(),
1635                 "<SwNumberingUIBehaviorConfig::LoadConfig()> - GetProperties failed")
1636         if ( aValues.getLength() == aPropNames.getLength() )
1637         {
1638             for ( int nProp = 0; nProp < aPropNames.getLength(); ++nProp )
1639             {
1640                 if ( pValues[nProp].hasValue() )
1641                 {
1642                     switch ( nProp )
1643                     {
1644                         case 0:
1645                         {
1646                             pValues[nProp] >>= mbChangeIndentOnTabAtFirstPosOfFirstListItem;
1647                         }
1648                         break;
1649                         default:
1650                         {
1651                             ASSERT( false,
1652                                     "<SwNumberingUIBehaviorConfig::LoadConfig()> - unknown configuration property")
1653                         }
1654                     }
1655                 }
1656             }
1657         }
1658     }
1659 
Notify(const com::sun::star::uno::Sequence<rtl::OUString> & aPropertyNames)1660     void SwNumberingUIBehaviorConfig::Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames )
1661     {
1662         (void) aPropertyNames;
1663         SetToDefault();
1664         LoadConfig();
1665     }
1666 
ChangeIndentOnTabAtFirstPosOfFirstListItem()1667     sal_Bool ChangeIndentOnTabAtFirstPosOfFirstListItem()
1668     {
1669         return SwNumberingUIBehaviorConfig::getInstance()->ChangeIndentOnTabAtFirstPosOfFirstListItem();
1670     }
1671 
1672     // --> OD 2008-06-06 #i89178#
GetDefaultPositionAndSpaceMode()1673     SvxNumberFormat::SvxNumPositionAndSpaceMode GetDefaultPositionAndSpaceMode()
1674     {
1675         SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode;
1676         SvtSaveOptions aSaveOptions;
1677         switch ( aSaveOptions.GetODFDefaultVersion() )
1678         {
1679             case SvtSaveOptions::ODFVER_010:
1680             case SvtSaveOptions::ODFVER_011:
1681             {
1682                 ePosAndSpaceMode = SvxNumberFormat::LABEL_WIDTH_AND_POSITION;
1683             }
1684             break;
1685             default: // ODFVER_UNKNOWN or ODFVER_012
1686             {
1687                 ePosAndSpaceMode = SvxNumberFormat::LABEL_ALIGNMENT;
1688             }
1689         }
1690 
1691         return ePosAndSpaceMode;
1692     }
1693     // <--
1694 }
1695 // <--
1696