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 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
getCount()127 sal_Int32 SAL_CALL SvxUnoNumberingRules::getCount() throw( RuntimeException )
128 {
129 OGuard aGuard( Application::GetSolarMutex() );
130
131 return maRule.GetLevelCount();
132 }
133
getByIndex(sal_Int32 Index)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
getElementType()146 Type SAL_CALL SvxUnoNumberingRules::getElementType()
147 throw( RuntimeException )
148 {
149 return ::getCppuType(( const Sequence< beans::PropertyValue >*)0);
150 }
151
hasElements()152 sal_Bool SAL_CALL SvxUnoNumberingRules::hasElements() throw( RuntimeException )
153 {
154 return sal_True;
155 }
156
157 // XAnyCompare
compare(const Any & rAny1,const Any & rAny2)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
createClone()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
getImplementationName()172 OUString SAL_CALL SvxUnoNumberingRules::getImplementationName( ) throw(RuntimeException)
173 {
174 return OUString( RTL_CONSTASCII_USTRINGPARAM( "SvxUnoNumberingRules" ) );
175 }
176
supportsService(const OUString & ServiceName)177 sal_Bool SAL_CALL SvxUnoNumberingRules::supportsService( const OUString& ServiceName ) throw(RuntimeException)
178 {
179 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( pSvxUnoNumberingRulesService ) );
180 }
181
getSupportedServiceNames()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
getNumberingRuleByIndex(sal_Int32 nIndex) const189 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 if(SVX_NUM_CHAR_SPECIAL == rFmt.GetNumberingType())
225 {
226 sal_Unicode nCode = rFmt.GetBulletChar();
227 OUString aStr( &nCode, 1 );
228 aVal <<= aStr;
229 beans::PropertyValue aBulletProp( OUString(RTL_CONSTASCII_USTRINGPARAM("BulletChar")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
230 pArray[nIdx++] = aBulletProp;
231 }
232 }
233
234 if( rFmt.GetBulletFont() )
235 {
236 awt::FontDescriptor aDesc;
237 SvxUnoFontDescriptor::ConvertFromFont( *rFmt.GetBulletFont(), aDesc );
238 aVal.setValue(&aDesc, ::getCppuType((const awt::FontDescriptor*)0));
239 pArray[nIdx++] = beans::PropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_FONT)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
240 }
241
242 {
243 const SvxBrushItem* pBrush = rFmt.GetBrush();
244 if(pBrush && pBrush->GetGraphicObject())
245 {
246 const GraphicObject* pGrafObj = pBrush->GetGraphicObject();
247 OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
248 aURL += OUString::createFromAscii( pGrafObj->GetUniqueID().GetBuffer() );
249
250 aVal <<= aURL;
251 const beans::PropertyValue aGraphicProp( OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
252 pArray[nIdx++] = aGraphicProp;
253 }
254 }
255
256 {
257 const Size aSize( rFmt.GetGraphicSize() );
258 const awt::Size aUnoSize( aSize.Width(), aSize.Height() );
259 aVal <<= aUnoSize;
260 const beans::PropertyValue aGraphicSizeProp(OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicSize")), -1, aVal, beans::PropertyState_DIRECT_VALUE );
261 pArray[nIdx++] = aGraphicSizeProp;
262 }
263
264 aVal <<= (sal_Int16)rFmt.GetStart();
265 pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_START_WITH)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
266
267 aVal <<= (sal_Int32)rFmt.GetAbsLSpace();
268 pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
269
270 aVal <<= (sal_Int32)rFmt.GetFirstLineOffset();
271 pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
272
273 pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("SymbolTextDistance")), -1, aVal, beans::PropertyState_DIRECT_VALUE);
274
275 aVal <<= (sal_Int32)rFmt.GetBulletColor().GetColor();
276 pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
277
278 aVal <<= (sal_Int16)rFmt.GetBulletRelSize();
279 pArray[nIdx++] = beans::PropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE)), -1, aVal, beans::PropertyState_DIRECT_VALUE);
280
281 DBG_ASSERT( nIdx <= nProps, "FixMe: Array uebergelaufen!!!! [CL]" );
282 Sequence< beans::PropertyValue> aSeq(pArray, nIdx);
283
284 delete [] pArray;
285 return aSeq;
286 }
287
setNumberingRuleByIndex(const Sequence<beans::PropertyValue> & rProperties,sal_Int32 nIndex)288 void SvxUnoNumberingRules::setNumberingRuleByIndex( const Sequence< beans::PropertyValue >& rProperties, sal_Int32 nIndex)
289 throw( RuntimeException, IllegalArgumentException )
290 {
291 SvxNumberFormat aFmt(maRule.GetLevel( (sal_uInt16)nIndex ));
292 const beans::PropertyValue* pPropArray = rProperties.getConstArray();
293 for(int i = 0; i < rProperties.getLength(); i++)
294 {
295 const beans::PropertyValue& rProp = pPropArray[i];
296 const OUString& rPropName = rProp.Name;
297 const Any& aVal = rProp.Value;
298
299 if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_NUMBERINGTYPE)))
300 {
301 sal_Int16 nSet = sal_Int16();
302 aVal >>= nSet;
303
304 // There is no reason to limit numbering types.
305 if ( nSet>=0 )
306 {
307 aFmt.SetNumberingType(nSet);
308 continue;
309 }
310 }
311 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_PREFIX)))
312 {
313 OUString aPrefix;
314 if( aVal >>= aPrefix )
315 {
316 aFmt.SetPrefix(aPrefix);
317 continue;
318 }
319 }
320 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_SUFFIX)))
321 {
322 OUString aSuffix;
323 if( aVal >>= aSuffix )
324 {
325 aFmt.SetSuffix(aSuffix);
326 continue;
327 }
328 }
329 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLETID)))
330 {
331 sal_Int16 nSet = sal_Int16();
332 if( aVal >>= nSet )
333 {
334 if(nSet < 0x100)
335 {
336 aFmt.SetBulletChar(nSet);
337 continue;
338 }
339 }
340 }
341 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("BulletChar")))
342 {
343 OUString aStr;
344 if( aVal >>= aStr )
345 {
346 if(aStr.getLength())
347 {
348 aFmt.SetBulletChar(aStr[0]);
349 }
350 else
351 {
352 aFmt.SetBulletChar(0);
353 }
354 continue;
355 }
356 }
357 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_ADJUST)))
358 {
359 sal_Int16 nAdjust = sal_Int16();
360 if( aVal >>= nAdjust )
361 {
362 aFmt.SetNumAdjust(ConvertUnoAdjust( (unsigned short)nAdjust ));
363 continue;
364 }
365 }
366 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_FONT)))
367 {
368 awt::FontDescriptor aDesc;
369 if( aVal >>= aDesc )
370 {
371 Font aFont;
372 SvxUnoFontDescriptor::ConvertToFont( aDesc, aFont );
373 aFmt.SetBulletFont(&aFont);
374 continue;
375 }
376 }
377 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Graphic")))
378 {
379 Reference< awt::XBitmap > xBmp;
380 if( aVal >>= xBmp )
381 {
382 Graphic aGraf( VCLUnoHelper::GetBitmap( xBmp ) );
383 SvxBrushItem aBrushItem(aGraf, GPOS_AREA, SID_ATTR_BRUSH);
384 aFmt.SetGraphicBrush( &aBrushItem );
385 continue;
386 }
387 }
388 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicURL")))
389 {
390 OUString aURL;
391 if( aVal >>= aURL )
392 {
393 GraphicObject aGrafObj( GraphicObject::CreateGraphicObjectFromURL( aURL ) );
394 SvxBrushItem aBrushItem( aGrafObj, GPOS_AREA, SID_ATTR_BRUSH );
395 aFmt.SetGraphicBrush( &aBrushItem );
396 continue;
397 }
398 }
399 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("GraphicSize")))
400 {
401 awt::Size aUnoSize;
402 if( aVal >>= aUnoSize )
403 {
404 aFmt.SetGraphicSize( Size( aUnoSize.Width, aUnoSize.Height ) );
405 continue;
406 }
407 }
408 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_START_WITH)))
409 {
410 sal_Int16 nStart = sal_Int16();
411 if( aVal >>= nStart )
412 {
413 aFmt.SetStart( nStart );
414 continue;
415 }
416 }
417 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_LEFT_MARGIN)))
418 {
419 sal_Int32 nMargin = 0;
420 if( aVal >>= nMargin )
421 {
422 aFmt.SetAbsLSpace((sal_uInt16)nMargin);
423 continue;
424 }
425 }
426 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_FIRST_LINE_OFFSET)))
427 {
428 sal_Int32 nMargin = 0;
429 if( aVal >>= nMargin )
430 {
431 aFmt.SetFirstLineOffset((sal_uInt16)nMargin);
432 continue;
433 }
434 }
435 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SymbolTextDistance")))
436 {
437 sal_Int32 nTextDistance = 0;
438 if( aVal >>= nTextDistance )
439 {
440 aFmt.SetCharTextDistance((sal_uInt16)nTextDistance);
441 continue;
442 }
443 }
444 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_COLOR)))
445 {
446 sal_Int32 nColor = 0;
447 if( aVal >>= nColor )
448 {
449 aFmt.SetBulletColor( (Color) nColor );
450 continue;
451 }
452 }
453 else if(rPropName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(UNO_NAME_NRULE_BULLET_RELSIZE)))
454 {
455 sal_Int16 nSize = sal_Int16();
456 if( aVal >>= nSize )
457 {
458 // [Bug 120650] the slide content corrupt when open in Aoo
459 if ((nSize>250)||(nSize<=0))
460 {
461 nSize = 100;
462 }
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
SvxGetNumRule(Reference<XIndexReplace> xRule)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
SvxGetNumRule(Reference<XIndexReplace> xRule,SvxNumRule & rNumRule)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 ///////////////////////////////////////////////////////////////////////
SvxCreateNumRule(const SvxNumRule * pRule)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
compare(const Any & Any1,const Any & Any2)561 sal_Int16 SAL_CALL SvxUnoNumberingRulesCompare::compare( const Any& Any1, const Any& Any2 ) throw(RuntimeException)
562 {
563 return SvxUnoNumberingRules::Compare( Any1, Any2 );
564 }
565
Compare(const Any & Any1,const Any & Any2)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
SvxCreateNumRuleCompare()602 Reference< XAnyCompare > SvxCreateNumRuleCompare() throw()
603 {
604 return new SvxUnoNumberingRulesCompare();
605 }
606
SvxCreateNumRule()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