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