xref: /trunk/main/editeng/source/uno/unonrule.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_editeng.hxx"
26 
27 #define PROPERTY_NONE 0
28 
29 #include <com/sun/star/text/HoriOrientation.hpp>
30 #include <com/sun/star/awt/XBitmap.hpp>
31 
32 #include <vcl/svapp.hxx>
33 #include <vos/mutex.hxx>
34 #include <vcl/graph.hxx>
35 #include <svtools/grfmgr.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <rtl/uuid.h>
38 #include <rtl/memory.h>
39 
40 #include <editeng/brshitem.hxx>
41 #include <editeng/unoprnms.hxx>
42 #include <editeng/numitem.hxx>
43 #include <editeng/eeitem.hxx>
44 #include <editeng/unotext.hxx>
45 #include <editeng/numitem.hxx>
46 #include <editeng/unofdesc.hxx>
47 #include <editeng/unonrule.hxx>
48 #include <editeng/editids.hrc>
49 
50 using ::rtl::OUString;
51 using ::com::sun::star::util::XCloneable;
52 using ::com::sun::star::ucb::XAnyCompare;
53 
54 
55 using namespace ::vos;
56 using namespace ::std;
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::lang;
60 using namespace ::com::sun::star::container;
61 
62 const SvxAdjust aUnoToSvxAdjust[] =
63 {
64     SVX_ADJUST_LEFT,
65     SVX_ADJUST_RIGHT,
66     SVX_ADJUST_CENTER,
67     SVX_ADJUST_LEFT,
68     SVX_ADJUST_LEFT,
69     SVX_ADJUST_LEFT,
70     SVX_ADJUST_BLOCK
71 };
72 
73 const unsigned short aSvxToUnoAdjust[] =
74 {
75     text::HoriOrientation::LEFT,
76     text::HoriOrientation::RIGHT,
77     text::HoriOrientation::FULL,
78     text::HoriOrientation::CENTER,
79     text::HoriOrientation::FULL,
80     text::HoriOrientation::LEFT
81 };
82 
ConvertUnoAdjust(unsigned short nAdjust)83 SvxAdjust ConvertUnoAdjust( unsigned short nAdjust )
84 {
85     DBG_ASSERT( nAdjust <= 7, "Enum hat sich geaendert! [CL]" );
86     return aUnoToSvxAdjust[nAdjust];
87 }
88 
ConvertUnoAdjust(SvxAdjust eAdjust)89 unsigned short ConvertUnoAdjust( SvxAdjust eAdjust )
90 {
91     DBG_ASSERT( eAdjust <= 6, "Enum hat sich geaendert! [CL]" );
92     return aSvxToUnoAdjust[eAdjust];
93 }
94 
95 /******************************************************************
96  * SvxUnoNumberingRules
97  ******************************************************************/
98 
99 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoNumberingRules );
100 
SvxUnoNumberingRules(const SvxNumRule & rRule)101 SvxUnoNumberingRules::SvxUnoNumberingRules( const SvxNumRule& rRule ) throw()
102 : maRule( rRule )
103 {
104 }
105 
~SvxUnoNumberingRules()106 SvxUnoNumberingRules::~SvxUnoNumberingRules() throw()
107 {
108 }
109 
110 //XIndexReplace
replaceByIndex(sal_Int32 Index,const uno::Any & Element)111 void SAL_CALL SvxUnoNumberingRules::replaceByIndex( sal_Int32 Index, const uno::Any& Element )
112 {
113     OGuard aGuard( Application::GetSolarMutex() );
114 
115     if( Index < 0 || Index >= maRule.GetLevelCount() )
116         throw IndexOutOfBoundsException();
117 
118     Sequence< beans::PropertyValue > aSeq;
119 
120     if( !( Element >>= aSeq) )
121         throw IllegalArgumentException();
122     setNumberingRuleByIndex( aSeq, Index );
123 }
124 
125 // XIndexAccess
getCount()126 sal_Int32 SAL_CALL SvxUnoNumberingRules::getCount()
127 {
128     OGuard aGuard( Application::GetSolarMutex() );
129 
130     return maRule.GetLevelCount();
131 }
132 
getByIndex(sal_Int32 Index)133 Any SAL_CALL SvxUnoNumberingRules::getByIndex( sal_Int32 Index )
134 {
135     OGuard aGuard( Application::GetSolarMutex() );
136 
137     if( Index < 0 || Index >= maRule.GetLevelCount() )
138         throw IndexOutOfBoundsException();
139 
140     return Any( getNumberingRuleByIndex(Index) );
141 }
142 
143 //XElementAccess
getElementType()144 Type SAL_CALL SvxUnoNumberingRules::getElementType()
145 {
146     return ::getCppuType(( const Sequence< beans::PropertyValue >*)0);
147 }
148 
hasElements()149 sal_Bool SAL_CALL SvxUnoNumberingRules::hasElements()
150 {
151     return sal_True;
152 }
153 
154 // XAnyCompare
compare(const Any & rAny1,const Any & rAny2)155 sal_Int16 SAL_CALL SvxUnoNumberingRules::compare( const Any& rAny1, const Any& rAny2 )
156 {
157     return SvxUnoNumberingRules::Compare( rAny1, rAny2 );
158 }
159 
160 // XCloneable
createClone()161 Reference< XCloneable > SAL_CALL SvxUnoNumberingRules::createClone(  )
162 {
163     return new SvxUnoNumberingRules(maRule);
164 }
165 
166 // XServiceInfo
167 sal_Char pSvxUnoNumberingRulesService[sizeof("com.sun.star.text.NumberingRules")] = "com.sun.star.text.NumberingRules";
168 
getImplementationName()169 OUString SAL_CALL SvxUnoNumberingRules::getImplementationName(  )
170 {
171     return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxUnoNumberingRules" ) );
172 }
173 
supportsService(const OUString & ServiceName)174 sal_Bool SAL_CALL SvxUnoNumberingRules::supportsService( const OUString& ServiceName )
175 {
176     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSvxUnoNumberingRulesService ) );
177 }
178 
getSupportedServiceNames()179 Sequence< OUString > SAL_CALL SvxUnoNumberingRules::getSupportedServiceNames(  )
180 {
181     OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSvxUnoNumberingRulesService ) );
182     Sequence< OUString > aSeq( &aService, 1 );
183     return aSeq;
184 }
185 
getNumberingRuleByIndex(sal_Int32 nIndex) const186 Sequence<beans::PropertyValue> SvxUnoNumberingRules::getNumberingRuleByIndex( sal_Int32 nIndex) const throw()
187 {
188     //  NumberingRule aRule;
189     const SvxNumberFormat& rFmt = maRule.GetLevel((sal_uInt16) nIndex);
190     sal_uInt16 nIdx = 0;
191 
192     const int nProps = 15;
193     beans::PropertyValue* pArray = new beans::PropertyValue[nProps];
194 
195     Any aVal;
196     {
197         aVal <<= rFmt.GetNumberingType();
198         beans::PropertyValue aAlignProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
199         pArray[nIdx++] = aAlignProp;
200     }
201 
202     {
203         SvxAdjust eAdj = rFmt.GetNumAdjust();
204         aVal <<= ConvertUnoAdjust(eAdj);
205         pArray[nIdx++] = beans::PropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_ADJUST)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
206     }
207 
208     {
209         aVal <<= OUString(rFmt.GetPrefix());
210         beans::PropertyValue aPrefixProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_PREFIX)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
211         pArray[nIdx++] = aPrefixProp;
212     }
213 
214     {
215         aVal <<= OUString(rFmt.GetSuffix());
216         beans::PropertyValue aSuffixProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_SUFFIX)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
217         pArray[nIdx++] = aSuffixProp;
218     }
219 
220     {
221         if(SVX_NUM_CHAR_SPECIAL == rFmt.GetNumberingType())
222         {
223         sal_Unicode nCode = rFmt.GetBulletChar();
224         OUString aStr( &nCode, 1 );
225         aVal <<= aStr;
226         beans::PropertyValue aBulletProp( OUString(RTL_CONSTASCII_USTRINGPARAM("BulletChar")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
227         pArray[nIdx++] = aBulletProp;
228         }
229     }
230 
231     if( rFmt.GetBulletFont() )
232     {
233         awt::FontDescriptor aDesc;
234         SvxUnoFontDescriptor::ConvertFromFont( *rFmt.GetBulletFont(), aDesc );
235         aVal.setValue(&aDesc, ::getCppuType((const awt::FontDescriptor*)0));
236         pArray[nIdx++] = beans::PropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_FONT)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
237     }
238 
239     {
240         const SvxBrushItem* pBrush = rFmt.GetBrush();
241         if(pBrush && pBrush->GetGraphicObject())
242         {
243             const GraphicObject* pGrafObj = pBrush->GetGraphicObject();
244             OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
245             aURL += OUString::createFromAscii( pGrafObj->GetUniqueID().GetBuffer() );
246 
247             aVal <<= aURL;
248             const beans::PropertyValue aGraphicProp( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
249             pArray[nIdx++] = aGraphicProp;
250         }
251     }
252 
253     {
254         const Size aSize( rFmt.GetGraphicSize() );
255         const awt::Size aUnoSize( aSize.Width(), aSize.Height() );
256         aVal <<= aUnoSize;
257         const beans::PropertyValue aGraphicSizeProp(OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicSize")), -1, aVal, beans::PropertyState_DIRECT_VALUE );
258         pArray[nIdx++] = aGraphicSizeProp;
259     }
260 
261     aVal <<= (sal_Int16)rFmt.GetStart();
262     pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_START_WITH)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
263 
264     aVal <<= (sal_Int32)rFmt.GetAbsLSpace();
265     pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
266 
267     aVal <<= (sal_Int32)rFmt.GetFirstLineOffset();
268     pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
269 
270     pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolTextDistance")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
271 
272     aVal <<= (sal_Int32)rFmt.GetBulletColor().GetColor();
273     pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
274 
275     aVal <<= (sal_Int16)rFmt.GetBulletRelSize();
276     pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
277 
278     DBG_ASSERT( nIdx <= nProps, "FixMe: Array uebergelaufen!!!! [CL]" );
279     Sequence< beans::PropertyValue> aSeq(pArray, nIdx);
280 
281     delete [] pArray;
282     return aSeq;
283 }
284 
setNumberingRuleByIndex(const Sequence<beans::PropertyValue> & rProperties,sal_Int32 nIndex)285 void SvxUnoNumberingRules::setNumberingRuleByIndex( const Sequence< beans::PropertyValue >& rProperties, sal_Int32 nIndex)
286 {
287     SvxNumberFormat aFmt(maRule.GetLevel( (sal_uInt16)nIndex ));
288     const beans::PropertyValue* pPropArray = rProperties.getConstArray();
289     for(int i = 0; i < rProperties.getLength(); i++)
290     {
291         const beans::PropertyValue& rProp = pPropArray[i];
292         const OUString& rPropName = rProp.Name;
293         const Any& aVal = rProp.Value;
294 
295         if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE)))
296         {
297             sal_Int16 nSet = sal_Int16();
298             aVal >>= nSet;
299 
300             // There is no reason to limit numbering types.
301             if ( nSet>=0 )
302             {
303                 aFmt.SetNumberingType(nSet);
304                 continue;
305             }
306         }
307         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_PREFIX)))
308         {
309             OUString aPrefix;
310             if( aVal >>= aPrefix )
311             {
312                 aFmt.SetPrefix(aPrefix);
313                 continue;
314             }
315         }
316         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_SUFFIX)))
317         {
318             OUString aSuffix;
319             if( aVal >>= aSuffix )
320             {
321                 aFmt.SetSuffix(aSuffix);
322                 continue;
323             }
324         }
325         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLETID)))
326         {
327             sal_Int16 nSet = sal_Int16();
328             if( aVal >>= nSet )
329             {
330                 if(nSet < 0x100)
331                 {
332                     aFmt.SetBulletChar(nSet);
333                     continue;
334                 }
335             }
336         }
337         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("BulletChar")))
338         {
339             OUString aStr;
340             if( aVal >>= aStr )
341             {
342                 if(aStr.getLength())
343                 {
344                     aFmt.SetBulletChar(aStr[0]);
345                 }
346                 else
347                 {
348                     aFmt.SetBulletChar(0);
349                 }
350                 continue;
351             }
352         }
353         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_ADJUST)))
354         {
355             sal_Int16 nAdjust = sal_Int16();
356             if( aVal >>= nAdjust )
357             {
358                 aFmt.SetNumAdjust(ConvertUnoAdjust( (unsigned short)nAdjust ));
359                 continue;
360             }
361         }
362         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_FONT)))
363         {
364             awt::FontDescriptor aDesc;
365             if( aVal >>= aDesc )
366             {
367                 Font aFont;
368                 SvxUnoFontDescriptor::ConvertToFont( aDesc, aFont );
369                 aFmt.SetBulletFont(&aFont);
370                 continue;
371             }
372         }
373         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Graphic")))
374         {
375             Reference< awt::XBitmap > xBmp;
376             if( aVal >>= xBmp )
377             {
378                 Graphic aGraf( VCLUnoHelper::GetBitmap( xBmp ) );
379                 SvxBrushItem aBrushItem(aGraf, GPOS_AREA, SID_ATTR_BRUSH);
380                 aFmt.SetGraphicBrush( &aBrushItem );
381                 continue;
382             }
383         }
384         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicURL")))
385         {
386             OUString aURL;
387             if( aVal >>= aURL )
388             {
389                 GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) );
390                 SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH );
391                 aFmt.SetGraphicBrush( &aBrushItem );
392                 continue;
393             }
394         }
395         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicSize")))
396         {
397             awt::Size aUnoSize;
398             if( aVal >>= aUnoSize )
399             {
400                 aFmt.SetGraphicSize( Size( aUnoSize.Width, aUnoSize.Height ) );
401                 continue;
402             }
403         }
404         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_START_WITH)))
405         {
406             sal_Int16 nStart = sal_Int16();
407             if( aVal >>= nStart )
408             {
409                 aFmt.SetStart( nStart );
410                 continue;
411             }
412         }
413         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN)))
414         {
415             sal_Int32 nMargin = 0;
416             if( aVal >>= nMargin )
417             {
418                 aFmt.SetAbsLSpace((sal_uInt16)nMargin);
419                 continue;
420             }
421         }
422         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET)))
423         {
424             sal_Int32 nMargin = 0;
425             if( aVal >>= nMargin )
426             {
427                 aFmt.SetFirstLineOffset((sal_uInt16)nMargin);
428                 continue;
429             }
430         }
431         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SymbolTextDistance")))
432         {
433             sal_Int32 nTextDistance = 0;
434             if( aVal >>= nTextDistance )
435             {
436                 aFmt.SetCharTextDistance((sal_uInt16)nTextDistance);
437                 continue;
438             }
439         }
440         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR)))
441         {
442             sal_Int32 nColor = 0;
443             if( aVal >>= nColor )
444             {
445                 aFmt.SetBulletColor( (Color) nColor );
446                 continue;
447             }
448         }
449         else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE)))
450         {
451             sal_Int16 nSize = sal_Int16();
452             if( aVal >>= nSize )
453             {
454                 // [Bug 120650] the slide content corrupt when open in Aoo
455                 if ((nSize>250)||(nSize<=0))
456                 {
457                     nSize = 100;
458                 }
459 
460                 aFmt.SetBulletRelSize( (short)nSize );
461                 continue;
462             }
463         }
464         else
465         {
466             continue;
467         }
468 
469         throw IllegalArgumentException();
470     }
471 
472     // check that we always have a brush item for bitmap numbering
473     if( aFmt.GetNumberingType() == SVX_NUM_BITMAP )
474     {
475         if( NULL == aFmt.GetBrush() )
476         {
477             GraphicObject aGrafObj;
478             SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH );
479             aFmt.SetGraphicBrush( &aBrushItem );
480         }
481     }
482     maRule.SetLevel( (sal_uInt16)nIndex, aFmt );
483 }
484 
485 ///////////////////////////////////////////////////////////////////////
486 
SvxGetNumRule(Reference<XIndexReplace> xRule)487 const SvxNumRule& SvxGetNumRule( Reference< XIndexReplace > xRule )
488 {
489     SvxUnoNumberingRules* pRule = SvxUnoNumberingRules::getImplementation( xRule );
490     if( pRule == NULL )
491         throw IllegalArgumentException();
492 
493     return pRule->getNumRule();
494 }
495 
SvxGetNumRule(Reference<XIndexReplace> xRule,SvxNumRule & rNumRule)496 bool SvxGetNumRule( Reference< XIndexReplace > xRule, SvxNumRule& rNumRule )
497 {
498     SvxUnoNumberingRules* pRule = SvxUnoNumberingRules::getImplementation( xRule );
499     if( pRule )
500     {
501         rNumRule = pRule->getNumRule();
502     }
503     else if( xRule.is() )
504     {
505         try
506         {
507             pRule = new SvxUnoNumberingRules( rNumRule );
508 
509             Reference< XIndexReplace > xDestRule( pRule );
510 
511             const sal_Int32 nCount = min( xRule->getCount(), xDestRule->getCount() );
512             sal_Int32 nLevel;
513             for( nLevel = 0; nLevel < nCount; nLevel++ )
514             {
515                 xDestRule->replaceByIndex( nLevel, xRule->getByIndex( nLevel ) );
516             }
517 
518             rNumRule = pRule->getNumRule();
519         }
520         catch( Exception& )
521         {
522             return false;
523         }
524     }
525     else
526     {
527         return false;
528     }
529 
530     return true;
531 }
532 
533 ///////////////////////////////////////////////////////////////////////
SvxCreateNumRule(const SvxNumRule * pRule)534 com::sun::star::uno::Reference< com::sun::star::container::XIndexReplace > SvxCreateNumRule( const SvxNumRule* pRule ) throw()
535 {
536     DBG_ASSERT( pRule, "No default SvxNumRule!" );
537     if( pRule )
538     {
539         return new SvxUnoNumberingRules( *pRule );
540     }
541     else
542     {
543         SvxNumRule aDefaultRule( NUM_BULLET_REL_SIZE|NUM_BULLET_COLOR|NUM_CHAR_TEXT_DISTANCE, 10 , sal_False);
544         return new SvxUnoNumberingRules( aDefaultRule );
545     }
546 }
547 
548 
549 ///////////////////////////////////////////////////////////////////////
550 
551 class SvxUnoNumberingRulesCompare : public ::cppu::WeakAggImplHelper1< XAnyCompare >
552 {
553 public:
554     virtual sal_Int16 SAL_CALL compare( const Any& Any1, const Any& Any2 );
555 };
556 
compare(const Any & Any1,const Any & Any2)557 sal_Int16 SAL_CALL SvxUnoNumberingRulesCompare::compare( const Any& Any1, const Any& Any2 )
558 {
559     return SvxUnoNumberingRules::Compare( Any1, Any2 );
560 }
561 
Compare(const Any & Any1,const Any & Any2)562 sal_Int16 SvxUnoNumberingRules::Compare( const Any& Any1, const Any& Any2 )
563 {
564     Reference< XIndexReplace > x1( Any1, UNO_QUERY ), x2( Any2, UNO_QUERY );
565     if( x1.is() && x2.is() )
566     {
567         if( x1.get() == x2.get() )
568             return 0;
569 
570         SvxUnoNumberingRules* pRule1 = SvxUnoNumberingRules::getImplementation( x1 );
571         if( pRule1 )
572         {
573             SvxUnoNumberingRules* pRule2 = SvxUnoNumberingRules::getImplementation( x2 );
574             if( pRule2 )
575             {
576                 const SvxNumRule& rRule1 = pRule1->getNumRule();
577                 const SvxNumRule& rRule2 = pRule2->getNumRule();
578 
579                 const sal_uInt16 nLevelCount1 = rRule1.GetLevelCount();
580                 const sal_uInt16 nLevelCount2 = rRule2.GetLevelCount();
581 
582                 if( nLevelCount1 == 0 || nLevelCount2 == 0 )
583                     return -1;
584 
585                 for( sal_uInt16 i = 0; (i < nLevelCount1) && (i < nLevelCount2); i++ )
586                 {
587                     if( rRule1.GetLevel(i) != rRule2.GetLevel(i) )
588                         return -1;
589                 }
590                 return  0;
591             }
592         }
593     }
594 
595     return -1;
596 }
597 
SvxCreateNumRuleCompare()598 Reference< XAnyCompare > SvxCreateNumRuleCompare() throw()
599 {
600     return new SvxUnoNumberingRulesCompare();
601 }
602 
SvxCreateNumRule()603 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule() throw()
604 {
605     SvxNumRule aTempRule( 0, 10, false );
606     return SvxCreateNumRule( &aTempRule );
607 }
608