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