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