xref: /aoo42x/main/editeng/source/uno/unonrule.cxx (revision 190118d0)
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/unohlp.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 
83 SvxAdjust ConvertUnoAdjust( unsigned short nAdjust )
84 {
85 	DBG_ASSERT( nAdjust <= 7, "Enum hat sich geaendert! [CL]" );
86 	return aUnoToSvxAdjust[nAdjust];
87 }
88 
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 
101 SvxUnoNumberingRules::SvxUnoNumberingRules( const SvxNumRule& rRule ) throw()
102 : maRule( rRule )
103 {
104 }
105 
106 SvxUnoNumberingRules::~SvxUnoNumberingRules() throw()
107 {
108 }
109 
110 //XIndexReplace
111 void SAL_CALL SvxUnoNumberingRules::replaceByIndex( sal_Int32 Index, const uno::Any& Element )
112 	throw( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
113 {
114 	OGuard aGuard( Application::GetSolarMutex() );
115 
116 	if( Index < 0 || Index >= maRule.GetLevelCount() )
117 		throw IndexOutOfBoundsException();
118 
119 	Sequence< beans::PropertyValue > aSeq;
120 
121 	if( !( Element >>= aSeq) )
122 		throw IllegalArgumentException();
123 	setNumberingRuleByIndex( aSeq, Index );
124 }
125 
126 // XIndexAccess
127 sal_Int32 SAL_CALL SvxUnoNumberingRules::getCount() throw( RuntimeException )
128 {
129 	OGuard aGuard( Application::GetSolarMutex() );
130 
131 	return maRule.GetLevelCount();
132 }
133 
134 Any SAL_CALL SvxUnoNumberingRules::getByIndex( sal_Int32 Index )
135 	throw( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
136 {
137 	OGuard aGuard( Application::GetSolarMutex() );
138 
139 	if( Index < 0 || Index >= maRule.GetLevelCount() )
140 		throw IndexOutOfBoundsException();
141 
142 	return Any( getNumberingRuleByIndex(Index) );
143 }
144 
145 //XElementAccess
146 Type SAL_CALL SvxUnoNumberingRules::getElementType()
147 	throw( RuntimeException )
148 {
149 	return ::getCppuType(( const Sequence< beans::PropertyValue >*)0);
150 }
151 
152 sal_Bool SAL_CALL SvxUnoNumberingRules::hasElements() throw( RuntimeException )
153 {
154 	return sal_True;
155 }
156 
157 // XAnyCompare
158 sal_Int16 SAL_CALL SvxUnoNumberingRules::compare( const Any& rAny1, const Any& rAny2 ) throw(RuntimeException)
159 {
160     return SvxUnoNumberingRules::Compare( rAny1, rAny2 );
161 }
162 
163 // XCloneable
164 Reference< XCloneable > SAL_CALL SvxUnoNumberingRules::createClone(  ) throw (RuntimeException)
165 {
166     return new SvxUnoNumberingRules(maRule);
167 }
168 
169 // XServiceInfo
170 sal_Char pSvxUnoNumberingRulesService[sizeof("com.sun.star.text.NumberingRules")] = "com.sun.star.text.NumberingRules";
171 
172 OUString SAL_CALL SvxUnoNumberingRules::getImplementationName(  ) throw(RuntimeException)
173 {
174 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxUnoNumberingRules" ) );
175 }
176 
177 sal_Bool SAL_CALL SvxUnoNumberingRules::supportsService( const OUString& ServiceName ) throw(RuntimeException)
178 {
179 	return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSvxUnoNumberingRulesService ) );
180 }
181 
182 Sequence< OUString > SAL_CALL SvxUnoNumberingRules::getSupportedServiceNames(  ) throw(RuntimeException)
183 {
184 	OUString aService( RTL_CONSTASCII_USTRINGPARAM( pSvxUnoNumberingRulesService ) );
185 	Sequence< OUString > aSeq( &aService, 1 );
186 	return aSeq;
187 }
188 
189 Sequence<beans::PropertyValue> SvxUnoNumberingRules::getNumberingRuleByIndex( sal_Int32 nIndex) const throw()
190 {
191 	//	NumberingRule aRule;
192 	const SvxNumberFormat& rFmt = maRule.GetLevel((sal_uInt16) nIndex);
193 	sal_uInt16 nIdx = 0;
194 
195 	const int nProps = 15;
196 	beans::PropertyValue* pArray = new beans::PropertyValue[nProps];
197 
198 	Any aVal;
199 	{
200 		aVal <<= rFmt.GetNumberingType();
201 		beans::PropertyValue aAlignProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
202 		pArray[nIdx++] = aAlignProp;
203 	}
204 
205 	{
206 		SvxAdjust eAdj = rFmt.GetNumAdjust();
207 		aVal <<= ConvertUnoAdjust(eAdj);
208 		pArray[nIdx++] = beans::PropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_ADJUST)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
209 	}
210 
211 	{
212 		aVal <<= OUString(rFmt.GetPrefix());
213 		beans::PropertyValue aPrefixProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_PREFIX)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
214 		pArray[nIdx++] = aPrefixProp;
215 	}
216 
217 	{
218 		aVal <<= OUString(rFmt.GetSuffix());
219 		beans::PropertyValue aSuffixProp( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_SUFFIX)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
220 		pArray[nIdx++] = aSuffixProp;
221 	}
222 
223 	{
224 		sal_Unicode nCode = rFmt.GetBulletChar();
225 		OUString aStr( &nCode, 1 );
226 		aVal <<= aStr;
227 		beans::PropertyValue aBulletProp( OUString(RTL_CONSTASCII_USTRINGPARAM("BulletChar")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
228 		pArray[nIdx++] = aBulletProp;
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 
285 void SvxUnoNumberingRules::setNumberingRuleByIndex(	const Sequence< beans::PropertyValue >& rProperties, sal_Int32 nIndex)
286 	throw( RuntimeException, IllegalArgumentException )
287 {
288 	SvxNumberFormat aFmt(maRule.GetLevel( (sal_uInt16)nIndex ));
289 	const beans::PropertyValue* pPropArray = rProperties.getConstArray();
290 	for(int i = 0; i < rProperties.getLength(); i++)
291 	{
292 		const beans::PropertyValue& rProp = pPropArray[i];
293 		const OUString& rPropName = rProp.Name;
294 		const Any& aVal = rProp.Value;
295 
296 		if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE)))
297 		{
298 			sal_Int16 nSet = sal_Int16();
299 			aVal >>= nSet;
300 
301 			switch(nSet)
302 			{
303 			case SVX_NUM_BITMAP:
304 			case SVX_NUM_CHAR_SPECIAL:
305 			case SVX_NUM_ROMAN_UPPER:
306 			case SVX_NUM_ROMAN_LOWER:
307 			case SVX_NUM_CHARS_UPPER_LETTER:
308 			case SVX_NUM_CHARS_LOWER_LETTER:
309 			case SVX_NUM_ARABIC:
310 			case SVX_NUM_NUMBER_NONE:
311 			case SVX_NUM_CHARS_UPPER_LETTER_N:
312 			case SVX_NUM_CHARS_LOWER_LETTER_N:
313 				aFmt.SetNumberingType(nSet);
314 				continue;
315 			}
316 		}
317 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_PREFIX)))
318 		{
319 			OUString aPrefix;
320 			if( aVal >>= aPrefix )
321 			{
322 				aFmt.SetPrefix(aPrefix);
323 				continue;
324 			}
325 		}
326 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_SUFFIX)))
327 		{
328 			OUString aSuffix;
329 			if( aVal >>= aSuffix )
330 			{
331 				aFmt.SetSuffix(aSuffix);
332 				continue;
333 			}
334 		}
335 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLETID)))
336 		{
337 			sal_Int16 nSet = sal_Int16();
338 			if( aVal >>= nSet )
339 			{
340 				if(nSet < 0x100)
341 				{
342 					aFmt.SetBulletChar(nSet);
343 					continue;
344 				}
345 			}
346 		}
347 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("BulletChar")))
348 		{
349 			OUString aStr;
350 			if( aVal >>= aStr )
351 			{
352 				if(aStr.getLength())
353 				{
354 					aFmt.SetBulletChar(aStr[0]);
355 				}
356 				else
357 				{
358 					aFmt.SetBulletChar(0);
359 				}
360 				continue;
361 			}
362 		}
363 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_ADJUST)))
364 		{
365 			sal_Int16 nAdjust = sal_Int16();
366 			if( aVal >>= nAdjust )
367 			{
368 				aFmt.SetNumAdjust(ConvertUnoAdjust( (unsigned short)nAdjust ));
369 				continue;
370 			}
371 		}
372 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_FONT)))
373 		{
374 			awt::FontDescriptor aDesc;
375 			if( aVal >>= aDesc )
376 			{
377 				Font aFont;
378 				SvxUnoFontDescriptor::ConvertToFont( aDesc, aFont );
379 				aFmt.SetBulletFont(&aFont);
380 				continue;
381 			}
382 		}
383 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Graphic")))
384 		{
385 			Reference< awt::XBitmap > xBmp;
386 			if( aVal >>= xBmp )
387 			{
388 				Graphic aGraf( VCLUnoHelper::GetBitmap( xBmp ) );
389                 SvxBrushItem aBrushItem(aGraf, GPOS_AREA, SID_ATTR_BRUSH);
390 				aFmt.SetGraphicBrush( &aBrushItem );
391 				continue;
392 			}
393 		}
394 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicURL")))
395 		{
396 			OUString aURL;
397 			if( aVal >>= aURL )
398 			{
399 				GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) );
400                 SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH );
401 				aFmt.SetGraphicBrush( &aBrushItem );
402 				continue;
403 			}
404 		}
405 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicSize")))
406 		{
407 			awt::Size aUnoSize;
408 			if( aVal >>= aUnoSize )
409 			{
410 				aFmt.SetGraphicSize( Size( aUnoSize.Width, aUnoSize.Height ) );
411 				continue;
412 			}
413 		}
414 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_START_WITH)))
415 		{
416 			sal_Int16 nStart = sal_Int16();
417 			if( aVal >>= nStart )
418 			{
419 				aFmt.SetStart( nStart );
420 				continue;
421 			}
422 		}
423 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN)))
424 		{
425 			sal_Int32 nMargin = 0;
426 			if( aVal >>= nMargin )
427 			{
428 				aFmt.SetAbsLSpace((sal_uInt16)nMargin);
429 				continue;
430 			}
431 		}
432 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET)))
433 		{
434 			sal_Int32 nMargin = 0;
435 			if( aVal >>= nMargin )
436 			{
437 				aFmt.SetFirstLineOffset((sal_uInt16)nMargin);
438 				continue;
439 			}
440 		}
441 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SymbolTextDistance")))
442 		{
443 			sal_Int32 nTextDistance = 0;
444 			if( aVal >>= nTextDistance )
445 			{
446 				aFmt.SetCharTextDistance((sal_uInt16)nTextDistance);
447 				continue;
448 			}
449 		}
450 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR)))
451 		{
452 			sal_Int32 nColor = 0;
453 			if( aVal >>= nColor )
454 			{
455 				aFmt.SetBulletColor( (Color) nColor );
456 				continue;
457 			}
458 		}
459 		else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE)))
460 		{
461 			sal_Int16 nSize = sal_Int16();
462 			if( aVal >>= nSize )
463 			{
464 				aFmt.SetBulletRelSize( (short)nSize );
465 				continue;
466 			}
467 		}
468 		else
469 		{
470 			continue;
471 		}
472 
473 		throw IllegalArgumentException();
474 	}
475 
476 	// check that we always have a brush item for bitmap numbering
477 	if( aFmt.GetNumberingType() == SVX_NUM_BITMAP )
478 	{
479 		if( NULL == aFmt.GetBrush() )
480 		{
481 			GraphicObject aGrafObj;
482             SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH );
483 			aFmt.SetGraphicBrush( &aBrushItem );
484 		}
485 	}
486 	maRule.SetLevel( (sal_uInt16)nIndex, aFmt );
487 }
488 
489 ///////////////////////////////////////////////////////////////////////
490 
491 const SvxNumRule& SvxGetNumRule( Reference< XIndexReplace > xRule ) throw( IllegalArgumentException )
492 {
493 	SvxUnoNumberingRules* pRule = SvxUnoNumberingRules::getImplementation( xRule );
494 	if( pRule == NULL )
495 		throw IllegalArgumentException();
496 
497 	return pRule->getNumRule();
498 }
499 
500 bool SvxGetNumRule( Reference< XIndexReplace > xRule, SvxNumRule& rNumRule )
501 {
502 	SvxUnoNumberingRules* pRule = SvxUnoNumberingRules::getImplementation( xRule );
503 	if( pRule )
504 	{
505 		rNumRule = pRule->getNumRule();
506 	}
507 	else if( xRule.is() )
508 	{
509 		try
510 		{
511 			pRule = new SvxUnoNumberingRules( rNumRule );
512 
513 			Reference< XIndexReplace > xDestRule( pRule );
514 
515 			const sal_Int32 nCount = min( xRule->getCount(), xDestRule->getCount() );
516 			sal_Int32 nLevel;
517 			for( nLevel = 0; nLevel < nCount; nLevel++ )
518 			{
519 				xDestRule->replaceByIndex( nLevel, xRule->getByIndex( nLevel ) );
520 			}
521 
522 			rNumRule = pRule->getNumRule();
523 		}
524 		catch( Exception& )
525 		{
526 			return false;
527 		}
528 	}
529 	else
530 	{
531 		return false;
532 	}
533 
534 	return true;
535 }
536 
537 ///////////////////////////////////////////////////////////////////////
538 com::sun::star::uno::Reference< com::sun::star::container::XIndexReplace > SvxCreateNumRule( const SvxNumRule* pRule ) throw()
539 {
540 	DBG_ASSERT( pRule, "No default SvxNumRule!" );
541 	if( pRule )
542 	{
543 		return new SvxUnoNumberingRules( *pRule );
544 	}
545 	else
546 	{
547 		SvxNumRule aDefaultRule( NUM_BULLET_REL_SIZE|NUM_BULLET_COLOR|NUM_CHAR_TEXT_DISTANCE, 10 , sal_False);
548 		return new SvxUnoNumberingRules( aDefaultRule );
549 	}
550 }
551 
552 
553 ///////////////////////////////////////////////////////////////////////
554 
555 class SvxUnoNumberingRulesCompare : public ::cppu::WeakAggImplHelper1< XAnyCompare >
556 {
557 public:
558     virtual sal_Int16 SAL_CALL compare( const Any& Any1, const Any& Any2 ) throw(RuntimeException);
559 };
560 
561 sal_Int16 SAL_CALL SvxUnoNumberingRulesCompare::compare( const Any& Any1, const Any& Any2 ) throw(RuntimeException)
562 {
563     return SvxUnoNumberingRules::Compare( Any1, Any2 );
564 }
565 
566 sal_Int16 SvxUnoNumberingRules::Compare( const Any& Any1, const Any& Any2 )
567 {
568 	Reference< XIndexReplace > x1( Any1, UNO_QUERY ), x2( Any2, UNO_QUERY );
569 	if( x1.is() && x2.is() )
570 	{
571 		if( x1.get() == x2.get() )
572 			return 0;
573 
574 		SvxUnoNumberingRules* pRule1 = SvxUnoNumberingRules::getImplementation( x1 );
575 		if( pRule1 )
576 		{
577 			SvxUnoNumberingRules* pRule2 = SvxUnoNumberingRules::getImplementation( x2 );
578 			if( pRule2 )
579 			{
580 				const SvxNumRule& rRule1 = pRule1->getNumRule();
581 				const SvxNumRule& rRule2 = pRule2->getNumRule();
582 
583 				const sal_uInt16 nLevelCount1 = rRule1.GetLevelCount();
584 				const sal_uInt16 nLevelCount2 = rRule2.GetLevelCount();
585 
586 				if( nLevelCount1 == 0 || nLevelCount2 == 0 )
587 					return -1;
588 
589 				for( sal_uInt16 i = 0; (i < nLevelCount1) && (i < nLevelCount2); i++ )
590 				{
591 					if( rRule1.GetLevel(i) != rRule2.GetLevel(i) )
592 						return -1;
593 				}
594 				return  0;
595 			}
596 		}
597 	}
598 
599 	return -1;
600 }
601 
602 Reference< XAnyCompare > SvxCreateNumRuleCompare() throw()
603 {
604 	return new SvxUnoNumberingRulesCompare();
605 }
606 
607 ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace > SvxCreateNumRule() throw()
608 {
609 	SvxNumRule aTempRule( 0, 10, false );
610 	return SvxCreateNumRule( &aTempRule );
611 }
612