xref: /aoo42x/main/sc/source/ui/vba/vbaformat.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 #include "vbaformat.hxx"
28*cdf0e10cSrcweir #include <ooo/vba/excel/XStyle.hpp>
29*cdf0e10cSrcweir #include <ooo/vba/excel/XlVAlign.hpp>
30*cdf0e10cSrcweir #include <ooo/vba/excel/XlHAlign.hpp>
31*cdf0e10cSrcweir #include <ooo/vba/excel/XlOrientation.hpp>
32*cdf0e10cSrcweir #include <ooo/vba/excel/Constants.hpp>
33*cdf0e10cSrcweir #include <ooo/vba/excel/XRange.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/table/CellVertJustify.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/table/CellHoriJustify.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/table/CellOrientation.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/table/XCellRange.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/text/WritingMode.hpp>
39*cdf0e10cSrcweir #include <com/sun/star/util/CellProtection.hpp>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <rtl/math.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include "excelvbahelper.hxx"
44*cdf0e10cSrcweir #include "vbaborders.hxx"
45*cdf0e10cSrcweir #include "vbapalette.hxx"
46*cdf0e10cSrcweir #include "vbafont.hxx"
47*cdf0e10cSrcweir #include "vbainterior.hxx"
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <unonames.hxx>
50*cdf0e10cSrcweir #include <cellsuno.hxx>
51*cdf0e10cSrcweir #include <scitems.hxx>
52*cdf0e10cSrcweir #include <attrib.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir using namespace ::ooo::vba;
55*cdf0e10cSrcweir using namespace ::com::sun::star;
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #define FORMATSTRING "FormatString"
58*cdf0e10cSrcweir #define LOCALE "Locale"
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir template< typename Ifc1 >
61*cdf0e10cSrcweir ScVbaFormat< Ifc1 >::ScVbaFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< beans::XPropertySet >& _xPropertySet, const uno::Reference< frame::XModel >& xModel, bool bCheckAmbiguoity ) throw ( script::BasicErrorException ) : ScVbaFormat_BASE( xParent, xContext ), m_aDefaultLocale( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("en") ), rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "US") ), rtl::OUString() ), mxPropertySet( _xPropertySet ), mxModel( xModel ), mbCheckAmbiguoity( bCheckAmbiguoity ), mbAddIndent( sal_False )
62*cdf0e10cSrcweir {
63*cdf0e10cSrcweir 	try
64*cdf0e10cSrcweir 	{
65*cdf0e10cSrcweir 		if ( !mxModel.is() )
66*cdf0e10cSrcweir 			DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "XModel Interface could not be retrieved") ) );
67*cdf0e10cSrcweir         // mxServiceInfo is unused,
68*cdf0e10cSrcweir         // mxNumberFormatsSupplier is initialized when needed in initializeNumberFormats.
69*cdf0e10cSrcweir 	}
70*cdf0e10cSrcweir 	catch (uno::Exception& )
71*cdf0e10cSrcweir 	{
72*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
73*cdf0e10cSrcweir 	}
74*cdf0e10cSrcweir }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir template< typename Ifc1 >
77*cdf0e10cSrcweir void SAL_CALL
78*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setVerticalAlignment( const uno::Any& _oAlignment)   throw (script::BasicErrorException, uno::RuntimeException)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	try
81*cdf0e10cSrcweir 	{
82*cdf0e10cSrcweir 		uno::Any aVal;
83*cdf0e10cSrcweir 		sal_Int32 nAlignment = 0;
84*cdf0e10cSrcweir 		if ( !(_oAlignment >>= nAlignment ))
85*cdf0e10cSrcweir 			throw uno::RuntimeException();
86*cdf0e10cSrcweir 		switch (nAlignment)
87*cdf0e10cSrcweir 		{
88*cdf0e10cSrcweir 			case excel::XlVAlign::xlVAlignBottom :
89*cdf0e10cSrcweir 				aVal =  uno::makeAny( table::CellVertJustify_BOTTOM );
90*cdf0e10cSrcweir 				break;
91*cdf0e10cSrcweir 			case excel::XlVAlign::xlVAlignCenter :
92*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellVertJustify_CENTER );
93*cdf0e10cSrcweir 				break;
94*cdf0e10cSrcweir 			case excel::XlVAlign::xlVAlignDistributed:
95*cdf0e10cSrcweir 			case excel::XlVAlign::xlVAlignJustify:
96*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellVertJustify_STANDARD );
97*cdf0e10cSrcweir 				break;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 			case excel::XlVAlign::xlVAlignTop:
100*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellVertJustify_TOP);
101*cdf0e10cSrcweir 				break;
102*cdf0e10cSrcweir 			default:
103*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellVertJustify_STANDARD );
104*cdf0e10cSrcweir 				break;
105*cdf0e10cSrcweir 		}
106*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS ) ), aVal );
107*cdf0e10cSrcweir 	}
108*cdf0e10cSrcweir 	catch (uno::Exception& )
109*cdf0e10cSrcweir 	{
110*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
111*cdf0e10cSrcweir 	}
112*cdf0e10cSrcweir }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir template< typename Ifc1 >
115*cdf0e10cSrcweir uno::Any SAL_CALL
116*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getVerticalAlignment(  ) throw (script::BasicErrorException, uno::RuntimeException)
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir 	uno::Any aResult = aNULL();
119*cdf0e10cSrcweir 	try
120*cdf0e10cSrcweir 	{
121*cdf0e10cSrcweir 		if (!isAmbiguous( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS ) ) ) )
122*cdf0e10cSrcweir 		{
123*cdf0e10cSrcweir 			table::CellVertJustify aAPIAlignment;
124*cdf0e10cSrcweir 			mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLVJUS ) ) ) >>= aAPIAlignment;
125*cdf0e10cSrcweir 			switch( aAPIAlignment )
126*cdf0e10cSrcweir 			{
127*cdf0e10cSrcweir 				case table::CellVertJustify_BOTTOM:
128*cdf0e10cSrcweir 					aResult = uno::makeAny( excel::XlVAlign::xlVAlignBottom );
129*cdf0e10cSrcweir 					break;
130*cdf0e10cSrcweir 				case table::CellVertJustify_CENTER:
131*cdf0e10cSrcweir 					aResult = uno::makeAny( excel::XlVAlign::xlVAlignCenter );
132*cdf0e10cSrcweir 					break;
133*cdf0e10cSrcweir 				case table::CellVertJustify_STANDARD:
134*cdf0e10cSrcweir 					aResult = uno::makeAny( excel::XlVAlign::xlVAlignBottom );
135*cdf0e10cSrcweir 					break;
136*cdf0e10cSrcweir 				case table::CellVertJustify_TOP:
137*cdf0e10cSrcweir 					aResult = uno::makeAny( excel::XlVAlign::xlVAlignTop );
138*cdf0e10cSrcweir 					break;
139*cdf0e10cSrcweir 				default:
140*cdf0e10cSrcweir 					break;
141*cdf0e10cSrcweir 			}
142*cdf0e10cSrcweir 		}
143*cdf0e10cSrcweir 	}
144*cdf0e10cSrcweir 	catch (uno::Exception& )
145*cdf0e10cSrcweir 	{
146*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
147*cdf0e10cSrcweir 	}
148*cdf0e10cSrcweir 	return aResult;
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir template< typename Ifc1 >
152*cdf0e10cSrcweir void SAL_CALL
153*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setHorizontalAlignment( const uno::Any& HorizontalAlignment ) throw (script::BasicErrorException, uno::RuntimeException)
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir 	try
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		uno::Any aVal;
158*cdf0e10cSrcweir 		sal_Int32 nAlignment = 0;
159*cdf0e10cSrcweir 		if ( !( HorizontalAlignment >>= nAlignment ) )
160*cdf0e10cSrcweir 			throw uno::RuntimeException();
161*cdf0e10cSrcweir 		switch ( nAlignment )
162*cdf0e10cSrcweir 		{
163*cdf0e10cSrcweir 			case excel::XlHAlign::xlHAlignJustify:
164*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellHoriJustify_BLOCK);
165*cdf0e10cSrcweir 				break;
166*cdf0e10cSrcweir 			case excel::XlHAlign::xlHAlignCenter:
167*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellHoriJustify_CENTER );
168*cdf0e10cSrcweir 				break;
169*cdf0e10cSrcweir 			case excel::XlHAlign::xlHAlignDistributed:
170*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellHoriJustify_BLOCK);
171*cdf0e10cSrcweir 				break;
172*cdf0e10cSrcweir 			case excel::XlHAlign::xlHAlignLeft:
173*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellHoriJustify_LEFT);
174*cdf0e10cSrcweir 				break;
175*cdf0e10cSrcweir 			case excel::XlHAlign::xlHAlignRight:
176*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellHoriJustify_RIGHT);
177*cdf0e10cSrcweir 				break;
178*cdf0e10cSrcweir 		}
179*cdf0e10cSrcweir 		// #FIXME what about the default case above?
180*cdf0e10cSrcweir 		// shouldn't need the test below
181*cdf0e10cSrcweir 		if ( aVal.hasValue() )
182*cdf0e10cSrcweir 			mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS ) ), aVal );
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 	catch (uno::Exception& )
185*cdf0e10cSrcweir 	{
186*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
187*cdf0e10cSrcweir 	}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir template< typename Ifc1 >
192*cdf0e10cSrcweir uno::Any SAL_CALL
193*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getHorizontalAlignment(  ) throw (script::BasicErrorException, uno::RuntimeException)
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir 	uno::Any NRetAlignment = aNULL();
196*cdf0e10cSrcweir 	try
197*cdf0e10cSrcweir 	{
198*cdf0e10cSrcweir 		rtl::OUString sHoriJust( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS ) );
199*cdf0e10cSrcweir 		if (!isAmbiguous(sHoriJust))
200*cdf0e10cSrcweir 		{
201*cdf0e10cSrcweir 			table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_BLOCK;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 			if ( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment )
204*cdf0e10cSrcweir 			{
205*cdf0e10cSrcweir 				switch( aAPIAlignment )
206*cdf0e10cSrcweir 				{
207*cdf0e10cSrcweir 					case table::CellHoriJustify_BLOCK:
208*cdf0e10cSrcweir 						NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignJustify );
209*cdf0e10cSrcweir 						break;
210*cdf0e10cSrcweir 					case table::CellHoriJustify_CENTER:
211*cdf0e10cSrcweir 						NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignCenter );
212*cdf0e10cSrcweir 						break;
213*cdf0e10cSrcweir 					case table::CellHoriJustify_LEFT:
214*cdf0e10cSrcweir 						NRetAlignment = uno::makeAny( excel::XlHAlign::xlHAlignLeft );
215*cdf0e10cSrcweir 						break;
216*cdf0e10cSrcweir 					case table::CellHoriJustify_RIGHT:
217*cdf0e10cSrcweir 						NRetAlignment =  uno::makeAny( excel::XlHAlign::xlHAlignRight );
218*cdf0e10cSrcweir 						break;
219*cdf0e10cSrcweir 					 default: // handle those other cases with a NULL return
220*cdf0e10cSrcweir 						break;
221*cdf0e10cSrcweir 				}
222*cdf0e10cSrcweir 			}
223*cdf0e10cSrcweir 		}
224*cdf0e10cSrcweir 	}
225*cdf0e10cSrcweir 	catch (uno::Exception& )
226*cdf0e10cSrcweir 	{
227*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
228*cdf0e10cSrcweir 	}
229*cdf0e10cSrcweir 	return NRetAlignment;
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir template< typename Ifc1 >
233*cdf0e10cSrcweir void SAL_CALL
234*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setOrientation( const uno::Any& _aOrientation ) throw (script::BasicErrorException, uno::RuntimeException)
235*cdf0e10cSrcweir {
236*cdf0e10cSrcweir 	try
237*cdf0e10cSrcweir 	{
238*cdf0e10cSrcweir 		sal_Int32 nOrientation = 0;
239*cdf0e10cSrcweir 		if ( !( _aOrientation >>= nOrientation ) )
240*cdf0e10cSrcweir 			throw uno::RuntimeException();
241*cdf0e10cSrcweir 		uno::Any aVal;
242*cdf0e10cSrcweir 		switch( nOrientation )
243*cdf0e10cSrcweir 		{
244*cdf0e10cSrcweir 			case excel::XlOrientation::xlDownward:
245*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellOrientation_TOPBOTTOM);
246*cdf0e10cSrcweir 				break;
247*cdf0e10cSrcweir 			case excel::XlOrientation::xlHorizontal:
248*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellOrientation_STANDARD );
249*cdf0e10cSrcweir 				mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ROTANG ) ), uno::makeAny( sal_Int32(0) ) );
250*cdf0e10cSrcweir 				break;
251*cdf0e10cSrcweir 			case excel::XlOrientation::xlUpward:
252*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellOrientation_BOTTOMTOP);
253*cdf0e10cSrcweir 				break;
254*cdf0e10cSrcweir 			case excel::XlOrientation::xlVertical:
255*cdf0e10cSrcweir 				aVal = uno::makeAny( table::CellOrientation_STACKED);
256*cdf0e10cSrcweir 				break;
257*cdf0e10cSrcweir 		}
258*cdf0e10cSrcweir 		// #FIXME what about the default case above?
259*cdf0e10cSrcweir 		// shouldn't need the test below
260*cdf0e10cSrcweir 		if ( aVal.hasValue() )
261*cdf0e10cSrcweir 			mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI ) ), aVal );
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 	}
264*cdf0e10cSrcweir 	catch (uno::Exception& )
265*cdf0e10cSrcweir 	{
266*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
267*cdf0e10cSrcweir 	}
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir template< typename Ifc1 >
270*cdf0e10cSrcweir uno::Any SAL_CALL
271*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getOrientation(  ) throw (script::BasicErrorException, uno::RuntimeException)
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir 	uno::Any NRetOrientation = aNULL();
274*cdf0e10cSrcweir 	try
275*cdf0e10cSrcweir 	{
276*cdf0e10cSrcweir 		if (!isAmbiguous(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI ) )))
277*cdf0e10cSrcweir 		{
278*cdf0e10cSrcweir 			table::CellOrientation aOrientation = table::CellOrientation_STANDARD;
279*cdf0e10cSrcweir 			if ( !(  mxPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLORI ) ) ) >>= aOrientation ) )
280*cdf0e10cSrcweir 				throw uno::RuntimeException();
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir 			switch(aOrientation)
283*cdf0e10cSrcweir 			{
284*cdf0e10cSrcweir 				case table::CellOrientation_STANDARD:
285*cdf0e10cSrcweir 					NRetOrientation = uno::makeAny( excel::XlOrientation::xlHorizontal );
286*cdf0e10cSrcweir 					break;
287*cdf0e10cSrcweir 				case table::CellOrientation_BOTTOMTOP:
288*cdf0e10cSrcweir 					NRetOrientation = uno::makeAny( excel::XlOrientation::xlUpward );
289*cdf0e10cSrcweir 					break;
290*cdf0e10cSrcweir 				case table::CellOrientation_TOPBOTTOM:
291*cdf0e10cSrcweir 					NRetOrientation = uno::makeAny( excel::XlOrientation::xlDownward );
292*cdf0e10cSrcweir 					break;
293*cdf0e10cSrcweir 				case table::CellOrientation_STACKED:
294*cdf0e10cSrcweir 					NRetOrientation = uno::makeAny( excel::XlOrientation::xlVertical );
295*cdf0e10cSrcweir 					break;
296*cdf0e10cSrcweir 				default:
297*cdf0e10cSrcweir 					NRetOrientation = uno::makeAny( excel::XlOrientation::xlHorizontal );
298*cdf0e10cSrcweir 			}
299*cdf0e10cSrcweir 		}
300*cdf0e10cSrcweir 	}
301*cdf0e10cSrcweir 	catch (uno::Exception& )
302*cdf0e10cSrcweir 	{
303*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
304*cdf0e10cSrcweir 	}
305*cdf0e10cSrcweir 	return NRetOrientation;
306*cdf0e10cSrcweir }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir template< typename Ifc1 >
309*cdf0e10cSrcweir void SAL_CALL
310*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setWrapText( const uno::Any& _aWrapText ) throw (script::BasicErrorException, uno::RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir 	try
313*cdf0e10cSrcweir 	{
314*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRAP ) ), _aWrapText);
315*cdf0e10cSrcweir 	}
316*cdf0e10cSrcweir 	catch (uno::Exception& )
317*cdf0e10cSrcweir 	{
318*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
319*cdf0e10cSrcweir 	}
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir template< typename Ifc1 >
323*cdf0e10cSrcweir uno::Any SAL_CALL
324*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getWrapText(  ) throw (script::BasicErrorException, uno::RuntimeException)
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir 	uno::Any aWrap = aNULL();
327*cdf0e10cSrcweir 	try
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 		rtl::OUString aPropName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRAP ) ) );
330*cdf0e10cSrcweir 		if (!isAmbiguous( aPropName ))
331*cdf0e10cSrcweir 		{
332*cdf0e10cSrcweir 			aWrap = mxPropertySet->getPropertyValue(aPropName);
333*cdf0e10cSrcweir 		}
334*cdf0e10cSrcweir 	}
335*cdf0e10cSrcweir 	catch (uno::Exception& )
336*cdf0e10cSrcweir 	{
337*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
338*cdf0e10cSrcweir 	}
339*cdf0e10cSrcweir 	return aWrap;
340*cdf0e10cSrcweir }
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir template< typename Ifc1 >
343*cdf0e10cSrcweir uno::Any SAL_CALL
344*cdf0e10cSrcweir ScVbaFormat<Ifc1>::Borders( const uno::Any& Index ) throw (script::BasicErrorException, uno::RuntimeException )
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir 	ScVbaPalette aPalette( excel::getDocShell( mxModel ) );
347*cdf0e10cSrcweir 	uno::Reference< XCollection > xColl =  new ScVbaBorders( thisHelperIface(), ScVbaFormat_BASE::mxContext, uno::Reference< table::XCellRange >( mxPropertySet, uno::UNO_QUERY_THROW ), aPalette );
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir 	if ( Index.hasValue() )
350*cdf0e10cSrcweir 	{
351*cdf0e10cSrcweir 		return xColl->Item( Index, uno::Any() );
352*cdf0e10cSrcweir 	}
353*cdf0e10cSrcweir 	return uno::makeAny( xColl );
354*cdf0e10cSrcweir }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir template< typename Ifc1 >
357*cdf0e10cSrcweir uno::Reference< excel::XFont > SAL_CALL
358*cdf0e10cSrcweir ScVbaFormat<Ifc1>::Font(  ) throw (script::BasicErrorException, uno::RuntimeException)
359*cdf0e10cSrcweir {
360*cdf0e10cSrcweir 	ScVbaPalette aPalette( excel::getDocShell( mxModel ) );
361*cdf0e10cSrcweir 	return new ScVbaFont( thisHelperIface(), ScVbaFormat_BASE::mxContext, aPalette, mxPropertySet );
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir template< typename Ifc1 >
365*cdf0e10cSrcweir uno::Reference< excel::XInterior > SAL_CALL
366*cdf0e10cSrcweir ScVbaFormat<Ifc1>::Interior(  ) throw (script::BasicErrorException, uno::RuntimeException)
367*cdf0e10cSrcweir {
368*cdf0e10cSrcweir 	return new ScVbaInterior( thisHelperIface(), ScVbaFormat_BASE::mxContext, mxPropertySet );
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir template< typename Ifc1 >
372*cdf0e10cSrcweir uno::Any SAL_CALL
373*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getNumberFormatLocal(  ) throw (script::BasicErrorException, uno::RuntimeException)
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir 	uno::Any aRet = uno::makeAny( rtl::OUString() );
376*cdf0e10cSrcweir 	try
377*cdf0e10cSrcweir 	{
378*cdf0e10cSrcweir 		rtl::OUString sPropName( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) );
379*cdf0e10cSrcweir 		if (!isAmbiguous( sPropName ))
380*cdf0e10cSrcweir 		{
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 			initializeNumberFormats();
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir 			sal_Int32 nFormat = 0;
385*cdf0e10cSrcweir 			if ( ! (mxPropertySet->getPropertyValue( sPropName ) >>= nFormat ) )
386*cdf0e10cSrcweir 				throw uno::RuntimeException();
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir 			rtl::OUString sFormat;
389*cdf0e10cSrcweir 			xNumberFormats->getByKey(nFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( FORMATSTRING ))) >>= sFormat;
390*cdf0e10cSrcweir 			aRet = uno::makeAny( sFormat.toAsciiLowerCase() );
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 		}
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir 	catch (uno::Exception& )
395*cdf0e10cSrcweir 	{
396*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
397*cdf0e10cSrcweir 	}
398*cdf0e10cSrcweir 	return aRet;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir }
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir template< typename Ifc1 >
403*cdf0e10cSrcweir void
404*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setNumberFormat( lang::Locale _aLocale, const rtl::OUString& _sFormatString) throw( script::BasicErrorException )
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir 	try
407*cdf0e10cSrcweir 	{
408*cdf0e10cSrcweir 		initializeNumberFormats();
409*cdf0e10cSrcweir 		sal_Int32 nFormat = xNumberFormats->queryKey(_sFormatString, _aLocale , sal_True);
410*cdf0e10cSrcweir 		if (nFormat == -1)
411*cdf0e10cSrcweir 		{
412*cdf0e10cSrcweir 			xNumberFormats->addNew(_sFormatString, _aLocale);
413*cdf0e10cSrcweir 		}
414*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ), uno::makeAny( nFormat ) );
415*cdf0e10cSrcweir 	}
416*cdf0e10cSrcweir 	catch (uno::Exception& )
417*cdf0e10cSrcweir 	{
418*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
419*cdf0e10cSrcweir 	}
420*cdf0e10cSrcweir }
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir template< typename Ifc1 >
423*cdf0e10cSrcweir void SAL_CALL
424*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setNumberFormatLocal( const uno::Any& _oLocalFormatString ) throw (script::BasicErrorException, uno::RuntimeException)
425*cdf0e10cSrcweir {
426*cdf0e10cSrcweir 	try
427*cdf0e10cSrcweir 	{
428*cdf0e10cSrcweir 		rtl::OUString sLocalFormatString;
429*cdf0e10cSrcweir 		sal_Int32 nFormat = -1;
430*cdf0e10cSrcweir 		rtl::OUString sNumFormat( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) );
431*cdf0e10cSrcweir 		if ( !(_oLocalFormatString >>= sLocalFormatString )
432*cdf0e10cSrcweir 		|| !( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat ) )
433*cdf0e10cSrcweir 			throw uno::RuntimeException();
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 		sLocalFormatString = sLocalFormatString.toAsciiUpperCase();
436*cdf0e10cSrcweir 		initializeNumberFormats();
437*cdf0e10cSrcweir 		lang::Locale aRangeLocale;
438*cdf0e10cSrcweir 		xNumberFormats->getByKey(nFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALE ) ) ) >>= aRangeLocale;
439*cdf0e10cSrcweir 		sal_Int32 nNewFormat = xNumberFormats->queryKey(sLocalFormatString, aRangeLocale, sal_True);
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 		if (nNewFormat == -1)
442*cdf0e10cSrcweir 			nNewFormat = xNumberFormats->addNew(sLocalFormatString, aRangeLocale);
443*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue(sNumFormat, uno::makeAny( nNewFormat ));
444*cdf0e10cSrcweir 	}
445*cdf0e10cSrcweir 	catch (uno::Exception& )
446*cdf0e10cSrcweir 	{
447*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
448*cdf0e10cSrcweir 	}
449*cdf0e10cSrcweir }
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir template< typename Ifc1 >
452*cdf0e10cSrcweir void SAL_CALL
453*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setNumberFormat( const uno::Any& _oFormatString ) throw (script::BasicErrorException, uno::RuntimeException)
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir 	try
456*cdf0e10cSrcweir 	{
457*cdf0e10cSrcweir 		rtl::OUString sFormatString;
458*cdf0e10cSrcweir 		if ( !( _oFormatString >>= sFormatString ) )
459*cdf0e10cSrcweir 			throw uno::RuntimeException();
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir 		sFormatString = sFormatString.toAsciiUpperCase();
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 		lang::Locale aDefaultLocale = m_aDefaultLocale;
464*cdf0e10cSrcweir 		initializeNumberFormats();
465*cdf0e10cSrcweir 		sal_Int32 nFormat = xNumberFormats->queryKey(sFormatString, aDefaultLocale, sal_True);
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 		if (nFormat == -1)
468*cdf0e10cSrcweir 			nFormat = xNumberFormats->addNew(sFormatString, aDefaultLocale);
469*cdf0e10cSrcweir 
470*cdf0e10cSrcweir 		lang::Locale aRangeLocale;
471*cdf0e10cSrcweir 		xNumberFormats->getByKey(nFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( LOCALE ) ) ) >>= aRangeLocale;
472*cdf0e10cSrcweir 		sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, aRangeLocale);
473*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) ), uno::makeAny( nNewFormat));
474*cdf0e10cSrcweir 	}
475*cdf0e10cSrcweir 	catch (uno::Exception& )
476*cdf0e10cSrcweir 	{
477*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
478*cdf0e10cSrcweir 	}
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir template< typename Ifc1 >
483*cdf0e10cSrcweir void SAL_CALL
484*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setIndentLevel( const uno::Any& _aLevel ) throw (script::BasicErrorException, uno::RuntimeException)
485*cdf0e10cSrcweir {
486*cdf0e10cSrcweir 	try
487*cdf0e10cSrcweir 	{
488*cdf0e10cSrcweir 		sal_Int32 nLevel = 0;
489*cdf0e10cSrcweir 		if ( !(_aLevel >>= nLevel ) )
490*cdf0e10cSrcweir 			throw uno::RuntimeException();
491*cdf0e10cSrcweir 		table::CellHoriJustify aAPIAlignment = table::CellHoriJustify_STANDARD;
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 		rtl::OUString sHoriJust( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLHJUS ) );
494*cdf0e10cSrcweir 		if ( !( mxPropertySet->getPropertyValue(sHoriJust) >>= aAPIAlignment ) )
495*cdf0e10cSrcweir 			throw uno::RuntimeException();
496*cdf0e10cSrcweir 		if (aAPIAlignment == table::CellHoriJustify_STANDARD)
497*cdf0e10cSrcweir 			mxPropertySet->setPropertyValue( sHoriJust, uno::makeAny( table::CellHoriJustify_LEFT) ) ;
498*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_PINDENT ) ), uno::makeAny( sal_Int16(nLevel * 352.8) ) );
499*cdf0e10cSrcweir 	}
500*cdf0e10cSrcweir 	catch (uno::Exception& )
501*cdf0e10cSrcweir 	{
502*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
503*cdf0e10cSrcweir 	}
504*cdf0e10cSrcweir }
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir template< typename Ifc1 >
507*cdf0e10cSrcweir uno::Any SAL_CALL
508*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getIndentLevel(  ) throw (script::BasicErrorException, uno::RuntimeException)
509*cdf0e10cSrcweir {
510*cdf0e10cSrcweir 	uno::Any NRetIndentLevel = aNULL();
511*cdf0e10cSrcweir 	try
512*cdf0e10cSrcweir 	{
513*cdf0e10cSrcweir 		rtl::OUString sParaIndent( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_PINDENT ) );
514*cdf0e10cSrcweir 		if (!isAmbiguous(sParaIndent))
515*cdf0e10cSrcweir 		{
516*cdf0e10cSrcweir 			sal_Int16 IndentLevel = 0;
517*cdf0e10cSrcweir 			if ( ( mxPropertySet->getPropertyValue(sParaIndent) >>= IndentLevel  ) )
518*cdf0e10cSrcweir 				NRetIndentLevel = uno::makeAny( sal_Int32( rtl::math::round(static_cast<double>( IndentLevel ) / 352.8)) );
519*cdf0e10cSrcweir 			else
520*cdf0e10cSrcweir 				NRetIndentLevel = uno::makeAny( sal_Int32(0) );
521*cdf0e10cSrcweir 		}
522*cdf0e10cSrcweir 	}
523*cdf0e10cSrcweir 	catch (uno::Exception& )
524*cdf0e10cSrcweir 	{
525*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
526*cdf0e10cSrcweir 	}
527*cdf0e10cSrcweir 	return NRetIndentLevel;
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir template< typename Ifc1 >
531*cdf0e10cSrcweir void SAL_CALL
532*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setLocked( const uno::Any& _aLocked ) throw (script::BasicErrorException, uno::RuntimeException)
533*cdf0e10cSrcweir {
534*cdf0e10cSrcweir 	try
535*cdf0e10cSrcweir 	{
536*cdf0e10cSrcweir 		sal_Bool bIsLocked = sal_False;
537*cdf0e10cSrcweir 		if ( !( _aLocked >>= bIsLocked ) )
538*cdf0e10cSrcweir 			throw uno::RuntimeException();
539*cdf0e10cSrcweir 		util::CellProtection aCellProtection;
540*cdf0e10cSrcweir 		rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) );
541*cdf0e10cSrcweir 		mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
542*cdf0e10cSrcweir 		aCellProtection.IsLocked = bIsLocked;
543*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue(sCellProt, uno::makeAny( aCellProtection ) );
544*cdf0e10cSrcweir 	}
545*cdf0e10cSrcweir 	catch (uno::Exception& )
546*cdf0e10cSrcweir 	{
547*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString() );
548*cdf0e10cSrcweir 	}
549*cdf0e10cSrcweir }
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir template< typename Ifc1 >
552*cdf0e10cSrcweir void SAL_CALL
553*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setFormulaHidden( const uno::Any& FormulaHidden ) throw (script::BasicErrorException, uno::RuntimeException)
554*cdf0e10cSrcweir {
555*cdf0e10cSrcweir 	try
556*cdf0e10cSrcweir 	{
557*cdf0e10cSrcweir 		sal_Bool bIsFormulaHidden = sal_False;
558*cdf0e10cSrcweir 		FormulaHidden >>= bIsFormulaHidden;
559*cdf0e10cSrcweir 		util::CellProtection aCellProtection;
560*cdf0e10cSrcweir 		rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) );
561*cdf0e10cSrcweir 		mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
562*cdf0e10cSrcweir 		aCellProtection.IsFormulaHidden = bIsFormulaHidden;
563*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue(sCellProt,uno::makeAny(aCellProtection));
564*cdf0e10cSrcweir 	}
565*cdf0e10cSrcweir 	catch (uno::Exception& )
566*cdf0e10cSrcweir 	{
567*cdf0e10cSrcweir 		DebugHelper::exception( SbERR_METHOD_FAILED, rtl::OUString() );
568*cdf0e10cSrcweir 	}
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir template< typename Ifc1 >
572*cdf0e10cSrcweir uno::Any SAL_CALL
573*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getLocked(  ) throw (script::BasicErrorException, uno::RuntimeException)
574*cdf0e10cSrcweir {
575*cdf0e10cSrcweir 	uno::Any aCellProtection = aNULL();
576*cdf0e10cSrcweir 	try
577*cdf0e10cSrcweir 	{
578*cdf0e10cSrcweir 		rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) );
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 		if (!isAmbiguous(sCellProt))
581*cdf0e10cSrcweir 		{
582*cdf0e10cSrcweir 			SfxItemSet* pDataSet = getCurrentDataSet();
583*cdf0e10cSrcweir 			if ( pDataSet )
584*cdf0e10cSrcweir 			{
585*cdf0e10cSrcweir 				const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, sal_True);
586*cdf0e10cSrcweir 				SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, sal_True, NULL);
587*cdf0e10cSrcweir 				if(eState != SFX_ITEM_DONTCARE)
588*cdf0e10cSrcweir 					aCellProtection =  uno::makeAny(rProtAttr.GetProtection());
589*cdf0e10cSrcweir 			}
590*cdf0e10cSrcweir 			else // fallback to propertyset
591*cdf0e10cSrcweir 			{
592*cdf0e10cSrcweir 				util::CellProtection cellProtection;
593*cdf0e10cSrcweir 				mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
594*cdf0e10cSrcweir 				aCellProtection = uno::makeAny( cellProtection.IsLocked );
595*cdf0e10cSrcweir 			}
596*cdf0e10cSrcweir 		}
597*cdf0e10cSrcweir 	}
598*cdf0e10cSrcweir 	catch (uno::Exception& )
599*cdf0e10cSrcweir 	{
600*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
601*cdf0e10cSrcweir 	}
602*cdf0e10cSrcweir 	return aCellProtection;
603*cdf0e10cSrcweir }
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir template< typename Ifc1 >
606*cdf0e10cSrcweir uno::Any SAL_CALL
607*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getFormulaHidden(  ) throw (script::BasicErrorException, uno::RuntimeException)
608*cdf0e10cSrcweir {
609*cdf0e10cSrcweir 	uno::Any aBoolRet = aNULL();
610*cdf0e10cSrcweir 	try
611*cdf0e10cSrcweir 	{
612*cdf0e10cSrcweir 		rtl::OUString sCellProt( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CELLPRO ) );
613*cdf0e10cSrcweir 		if (!isAmbiguous(sCellProt))
614*cdf0e10cSrcweir 		{
615*cdf0e10cSrcweir 			SfxItemSet* pDataSet = getCurrentDataSet();
616*cdf0e10cSrcweir 			if ( pDataSet )
617*cdf0e10cSrcweir 			{
618*cdf0e10cSrcweir 				const ScProtectionAttr& rProtAttr = (const ScProtectionAttr &) pDataSet->Get(ATTR_PROTECTION, sal_True);
619*cdf0e10cSrcweir 				SfxItemState eState = pDataSet->GetItemState(ATTR_PROTECTION, sal_True, NULL);
620*cdf0e10cSrcweir 				if(eState != SFX_ITEM_DONTCARE)
621*cdf0e10cSrcweir 					aBoolRet = uno::makeAny(rProtAttr.GetHideFormula());
622*cdf0e10cSrcweir 			}
623*cdf0e10cSrcweir 			else
624*cdf0e10cSrcweir 			{
625*cdf0e10cSrcweir 				util::CellProtection aCellProtection;
626*cdf0e10cSrcweir 				mxPropertySet->getPropertyValue(sCellProt) >>= aCellProtection;
627*cdf0e10cSrcweir 				aBoolRet = uno::makeAny( aCellProtection.IsFormulaHidden );
628*cdf0e10cSrcweir 			}
629*cdf0e10cSrcweir 		}
630*cdf0e10cSrcweir 	}
631*cdf0e10cSrcweir 	catch (uno::Exception e)
632*cdf0e10cSrcweir 	{
633*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
634*cdf0e10cSrcweir 	}
635*cdf0e10cSrcweir 	return aBoolRet;
636*cdf0e10cSrcweir }
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir template< typename Ifc1 >
639*cdf0e10cSrcweir void SAL_CALL
640*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setShrinkToFit( const uno::Any& ShrinkToFit ) throw (script::BasicErrorException, uno::RuntimeException)
641*cdf0e10cSrcweir {
642*cdf0e10cSrcweir 	try
643*cdf0e10cSrcweir 	{
644*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHRINK_TO_FIT ) ), ShrinkToFit);
645*cdf0e10cSrcweir 	}
646*cdf0e10cSrcweir 	catch (uno::Exception& )
647*cdf0e10cSrcweir 	{
648*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString() );
649*cdf0e10cSrcweir 	}
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir }
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir template< typename Ifc1 >
654*cdf0e10cSrcweir uno::Any SAL_CALL
655*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getShrinkToFit(  ) throw (script::BasicErrorException, uno::RuntimeException)
656*cdf0e10cSrcweir {
657*cdf0e10cSrcweir 	uno::Any aRet = aNULL();
658*cdf0e10cSrcweir 	try
659*cdf0e10cSrcweir 	{
660*cdf0e10cSrcweir 		rtl::OUString sShrinkToFit( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SHRINK_TO_FIT ) );
661*cdf0e10cSrcweir 		if (!isAmbiguous(sShrinkToFit))
662*cdf0e10cSrcweir 			aRet = mxPropertySet->getPropertyValue(sShrinkToFit);
663*cdf0e10cSrcweir 	}
664*cdf0e10cSrcweir 	catch (uno::Exception& )
665*cdf0e10cSrcweir 	{
666*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
667*cdf0e10cSrcweir 	}
668*cdf0e10cSrcweir 	return aRet;
669*cdf0e10cSrcweir }
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir template< typename Ifc1 >
672*cdf0e10cSrcweir void SAL_CALL
673*cdf0e10cSrcweir ScVbaFormat<Ifc1>::setReadingOrder( const uno::Any& ReadingOrder ) throw (script::BasicErrorException, uno::RuntimeException)
674*cdf0e10cSrcweir {
675*cdf0e10cSrcweir 	try
676*cdf0e10cSrcweir 	{
677*cdf0e10cSrcweir 		sal_Int32 nReadingOrder = 0;
678*cdf0e10cSrcweir 		if ( !(ReadingOrder >>= nReadingOrder ))
679*cdf0e10cSrcweir 			throw uno::RuntimeException();
680*cdf0e10cSrcweir 		uno::Any aVal;
681*cdf0e10cSrcweir 		switch(nReadingOrder)
682*cdf0e10cSrcweir 		{
683*cdf0e10cSrcweir 			case excel::Constants::xlLTR:
684*cdf0e10cSrcweir 				aVal = uno::makeAny( text::WritingMode_LR_TB );
685*cdf0e10cSrcweir 				break;
686*cdf0e10cSrcweir 			case excel::Constants::xlRTL:
687*cdf0e10cSrcweir 				aVal = uno::makeAny( text::WritingMode_RL_TB );
688*cdf0e10cSrcweir 				break;
689*cdf0e10cSrcweir 			case excel::Constants::xlContext:
690*cdf0e10cSrcweir 				DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
691*cdf0e10cSrcweir 				break;
692*cdf0e10cSrcweir 			default:
693*cdf0e10cSrcweir 				DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
694*cdf0e10cSrcweir 		}
695*cdf0e10cSrcweir 		mxPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRITING ) ), aVal );
696*cdf0e10cSrcweir 	}
697*cdf0e10cSrcweir 	catch (uno::Exception& )
698*cdf0e10cSrcweir 	{
699*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
700*cdf0e10cSrcweir 	}
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir }
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir template< typename Ifc1 >
705*cdf0e10cSrcweir uno::Any SAL_CALL
706*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getReadingOrder(  ) throw (script::BasicErrorException, uno::RuntimeException)
707*cdf0e10cSrcweir {
708*cdf0e10cSrcweir 	uno::Any NRetReadingOrder = aNULL();
709*cdf0e10cSrcweir 	try
710*cdf0e10cSrcweir 	{
711*cdf0e10cSrcweir 		rtl::OUString sWritingMode( RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_WRITING ) );
712*cdf0e10cSrcweir 		if (!isAmbiguous(sWritingMode))
713*cdf0e10cSrcweir 		{
714*cdf0e10cSrcweir 			text::WritingMode aWritingMode = text::WritingMode_LR_TB;
715*cdf0e10cSrcweir 			if ( ( mxPropertySet->getPropertyValue(sWritingMode) ) >>= aWritingMode )
716*cdf0e10cSrcweir 			switch (aWritingMode){
717*cdf0e10cSrcweir 				case text::WritingMode_LR_TB:
718*cdf0e10cSrcweir 					NRetReadingOrder = uno::makeAny(excel::Constants::xlLTR);
719*cdf0e10cSrcweir 					break;
720*cdf0e10cSrcweir 				case text::WritingMode_RL_TB:
721*cdf0e10cSrcweir 					NRetReadingOrder = uno::makeAny(excel::Constants::xlRTL);
722*cdf0e10cSrcweir 					break;
723*cdf0e10cSrcweir 				default:
724*cdf0e10cSrcweir 					NRetReadingOrder = uno::makeAny(excel::Constants::xlRTL);
725*cdf0e10cSrcweir 			}
726*cdf0e10cSrcweir 		}
727*cdf0e10cSrcweir 	}
728*cdf0e10cSrcweir 	catch (uno::Exception& )
729*cdf0e10cSrcweir 	{
730*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_NOT_IMPLEMENTED, rtl::OUString());
731*cdf0e10cSrcweir 	}
732*cdf0e10cSrcweir 	return NRetReadingOrder;
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir }
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir template< typename Ifc1 >
737*cdf0e10cSrcweir uno::Any SAL_CALL
738*cdf0e10cSrcweir ScVbaFormat< Ifc1 >::getNumberFormat(  ) throw (script::BasicErrorException, uno::RuntimeException)
739*cdf0e10cSrcweir {
740*cdf0e10cSrcweir 	uno::Any aFormat = aNULL();
741*cdf0e10cSrcweir 	try
742*cdf0e10cSrcweir 	{
743*cdf0e10cSrcweir 		sal_Int32 nFormat = -1;
744*cdf0e10cSrcweir 		rtl::OUString sNumFormat( RTL_CONSTASCII_USTRINGPARAM( SC_UNO_NUMBERFO ) );
745*cdf0e10cSrcweir 		if (!isAmbiguous(sNumFormat) &&
746*cdf0e10cSrcweir 			( mxPropertySet->getPropertyValue(sNumFormat) >>= nFormat) )
747*cdf0e10cSrcweir 		{
748*cdf0e10cSrcweir 			initializeNumberFormats();
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir 			sal_Int32 nNewFormat = xNumberFormatTypes->getFormatForLocale(nFormat, getDefaultLocale() );
751*cdf0e10cSrcweir 			rtl::OUString sFormat;
752*cdf0e10cSrcweir 			xNumberFormats->getByKey(nNewFormat)->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( FORMATSTRING ))) >>= sFormat;
753*cdf0e10cSrcweir 			aFormat = uno::makeAny( sFormat );
754*cdf0e10cSrcweir 		}
755*cdf0e10cSrcweir 	}
756*cdf0e10cSrcweir 	catch (uno::Exception& )
757*cdf0e10cSrcweir 	{
758*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
759*cdf0e10cSrcweir 	}
760*cdf0e10cSrcweir 	return aFormat;
761*cdf0e10cSrcweir }
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir template< typename Ifc1 >
764*cdf0e10cSrcweir bool
765*cdf0e10cSrcweir ScVbaFormat<Ifc1>::isAmbiguous(const rtl::OUString& _sPropertyName) throw ( script::BasicErrorException )
766*cdf0e10cSrcweir {
767*cdf0e10cSrcweir 	bool bResult = false;
768*cdf0e10cSrcweir 	try
769*cdf0e10cSrcweir 	{
770*cdf0e10cSrcweir 		if (mbCheckAmbiguoity)
771*cdf0e10cSrcweir 			bResult = ( getXPropertyState()->getPropertyState(_sPropertyName) == beans::PropertyState_AMBIGUOUS_VALUE );
772*cdf0e10cSrcweir 	}
773*cdf0e10cSrcweir 	catch (uno::Exception& )
774*cdf0e10cSrcweir 	{
775*cdf0e10cSrcweir 		DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
776*cdf0e10cSrcweir 	}
777*cdf0e10cSrcweir 	return bResult;
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir template< typename Ifc1 >
781*cdf0e10cSrcweir void
782*cdf0e10cSrcweir ScVbaFormat<Ifc1>::initializeNumberFormats() throw ( script::BasicErrorException )
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir 	if ( !xNumberFormats.is() )
785*cdf0e10cSrcweir 	{
786*cdf0e10cSrcweir 		mxNumberFormatsSupplier.set( mxModel, uno::UNO_QUERY_THROW );
787*cdf0e10cSrcweir 		xNumberFormats = mxNumberFormatsSupplier->getNumberFormats();
788*cdf0e10cSrcweir 		xNumberFormatTypes.set( xNumberFormats, uno::UNO_QUERY ); // _THROW?
789*cdf0e10cSrcweir 	}
790*cdf0e10cSrcweir }
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir template< typename Ifc1 >
793*cdf0e10cSrcweir uno::Reference< beans::XPropertyState >
794*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getXPropertyState() throw ( uno::RuntimeException )
795*cdf0e10cSrcweir {
796*cdf0e10cSrcweir 	if ( !xPropertyState.is() )
797*cdf0e10cSrcweir 		xPropertyState.set( mxPropertySet, uno::UNO_QUERY_THROW );
798*cdf0e10cSrcweir 	return xPropertyState;
799*cdf0e10cSrcweir }
800*cdf0e10cSrcweir 
801*cdf0e10cSrcweir template< typename Ifc1 >
802*cdf0e10cSrcweir rtl::OUString&
803*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getServiceImplName()
804*cdf0e10cSrcweir {
805*cdf0e10cSrcweir         static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFormat") );
806*cdf0e10cSrcweir         return sImplName;
807*cdf0e10cSrcweir }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir template< typename Ifc1 >
810*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
811*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getServiceNames()
812*cdf0e10cSrcweir {
813*cdf0e10cSrcweir         static uno::Sequence< rtl::OUString > aServiceNames;
814*cdf0e10cSrcweir         if ( aServiceNames.getLength() == 0 )
815*cdf0e10cSrcweir         {
816*cdf0e10cSrcweir                 aServiceNames.realloc( 1 );
817*cdf0e10cSrcweir                 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Format" ) );
818*cdf0e10cSrcweir         }
819*cdf0e10cSrcweir         return aServiceNames;
820*cdf0e10cSrcweir }
821*cdf0e10cSrcweir 
822*cdf0e10cSrcweir template< typename Ifc1 >
823*cdf0e10cSrcweir ScCellRangesBase*
824*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getCellRangesBase() throw ( ::uno::RuntimeException )
825*cdf0e10cSrcweir {
826*cdf0e10cSrcweir     return ScCellRangesBase::getImplementation( mxPropertySet );
827*cdf0e10cSrcweir }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir template< typename Ifc1 >
830*cdf0e10cSrcweir SfxItemSet*
831*cdf0e10cSrcweir ScVbaFormat<Ifc1>::getCurrentDataSet( ) throw ( uno::RuntimeException )
832*cdf0e10cSrcweir {
833*cdf0e10cSrcweir 	SfxItemSet* pDataSet = excel::ScVbaCellRangeAccess::GetDataSet( getCellRangesBase() );
834*cdf0e10cSrcweir 	if ( !pDataSet )
835*cdf0e10cSrcweir 		throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't access Itemset for XPropertySet" ) ), uno::Reference< uno::XInterface >() );
836*cdf0e10cSrcweir 	return pDataSet;
837*cdf0e10cSrcweir }
838*cdf0e10cSrcweir 
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir template class ScVbaFormat< excel::XStyle >;
841*cdf0e10cSrcweir template class ScVbaFormat< excel::XRange >;
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir 
844