xref: /AOO41X/main/sc/source/ui/vba/vbatitle.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 #ifndef SC_VBA_TITLE_HXX
28*cdf0e10cSrcweir #define SC_VBA_TITLE_HXX
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <vbahelper/vbahelperinterface.hxx>
31*cdf0e10cSrcweir #include "excelvbahelper.hxx"
32*cdf0e10cSrcweir #include "vbainterior.hxx"
33*cdf0e10cSrcweir #include "vbafont.hxx"
34*cdf0e10cSrcweir #include "vbapalette.hxx"
35*cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
37*cdf0e10cSrcweir #include <ooo/vba/excel/XTitle.hpp>
38*cdf0e10cSrcweir #include <ooo/vba/excel/XCharacters.hpp>
39*cdf0e10cSrcweir #include <basic/sberrors.hxx>
40*cdf0e10cSrcweir #include <memory>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir template< typename Ifc1 >
43*cdf0e10cSrcweir class TitleImpl : public InheritedHelperInterfaceImpl< Ifc1 >
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir typedef InheritedHelperInterfaceImpl< Ifc1 > BaseClass;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir protected:
48*cdf0e10cSrcweir 	css::uno::Reference< css::drawing::XShape > xTitleShape;
49*cdf0e10cSrcweir 	css::uno::Reference< css::beans::XPropertySet > xShapePropertySet;
50*cdf0e10cSrcweir 	std::auto_ptr<ov::ShapeHelper> oShapeHelper;
51*cdf0e10cSrcweir 	ScVbaPalette m_Palette;
52*cdf0e10cSrcweir public:
53*cdf0e10cSrcweir 	TitleImpl(  const css::uno::Reference< ov::XHelperInterface >& xParent,   const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& _xTitleShape ) : BaseClass( xParent, xContext ), xTitleShape( _xTitleShape )
54*cdf0e10cSrcweir 	{
55*cdf0e10cSrcweir 		xShapePropertySet.set( xTitleShape, css::uno::UNO_QUERY_THROW );
56*cdf0e10cSrcweir 		oShapeHelper.reset( new ov::ShapeHelper(xTitleShape) );
57*cdf0e10cSrcweir 	}
58*cdf0e10cSrcweir 	css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
59*cdf0e10cSrcweir 	{
60*cdf0e10cSrcweir 		// #TODO find out what the proper parent should be
61*cdf0e10cSrcweir 		// leaving as set by the helperapi for the moment
62*cdf0e10cSrcweir 		// #TODO we really need the ScDocument to pass to ScVbaInterior
63*cdf0e10cSrcweir 		// otherwise attemps to access the palette will fail
64*cdf0e10cSrcweir 		return new ScVbaInterior( BaseClass::mxParent, BaseClass::mxContext, xShapePropertySet );
65*cdf0e10cSrcweir 	}
66*cdf0e10cSrcweir 	css::uno::Reference< ov::excel::XFont > SAL_CALL Font(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
67*cdf0e10cSrcweir 	{
68*cdf0e10cSrcweir 		// #TODO find out what the proper parent should be
69*cdf0e10cSrcweir 		// leaving as set by the helperapi for the moment
70*cdf0e10cSrcweir 		return new ScVbaFont( BaseClass::mxParent, BaseClass::mxContext, m_Palette, xShapePropertySet );
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 	}
73*cdf0e10cSrcweir 	void SAL_CALL setText( const ::rtl::OUString& Text ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
74*cdf0e10cSrcweir 	{
75*cdf0e10cSrcweir 		try
76*cdf0e10cSrcweir 		{
77*cdf0e10cSrcweir 			xShapePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ), css::uno::makeAny( Text ));
78*cdf0e10cSrcweir 		}
79*cdf0e10cSrcweir 		catch ( css::uno::Exception& )
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir 			throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
82*cdf0e10cSrcweir 		}
83*cdf0e10cSrcweir 	}
84*cdf0e10cSrcweir 	::rtl::OUString SAL_CALL getText(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
85*cdf0e10cSrcweir 	{
86*cdf0e10cSrcweir 		::rtl::OUString sText;
87*cdf0e10cSrcweir 		try
88*cdf0e10cSrcweir 		{
89*cdf0e10cSrcweir 			xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ) ) >>= sText;
90*cdf0e10cSrcweir 		}
91*cdf0e10cSrcweir 		catch ( css::uno::Exception& )
92*cdf0e10cSrcweir 		{
93*cdf0e10cSrcweir 			throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
94*cdf0e10cSrcweir 		}
95*cdf0e10cSrcweir 		return sText;
96*cdf0e10cSrcweir 	}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
99*cdf0e10cSrcweir 	{
100*cdf0e10cSrcweir 		// #FIXME #TODO the helperapi Characters implementation doesn't
101*cdf0e10cSrcweir 		// seem to do very much, need to know how the existing Characters
102*cdf0e10cSrcweir 		// impl ( that we use for Range ) can be reused
103*cdf0e10cSrcweir 		return 	css::uno::Reference< ov::excel::XCharacters > ();
104*cdf0e10cSrcweir 	}
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	void SAL_CALL setTop( double Top ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
107*cdf0e10cSrcweir 	{
108*cdf0e10cSrcweir 		oShapeHelper->setTop( Top );
109*cdf0e10cSrcweir 	}
110*cdf0e10cSrcweir 	double SAL_CALL getTop(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
111*cdf0e10cSrcweir 	{
112*cdf0e10cSrcweir 		return oShapeHelper->getTop();
113*cdf0e10cSrcweir 	}
114*cdf0e10cSrcweir 	void SAL_CALL setLeft( double Left ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
115*cdf0e10cSrcweir 	{
116*cdf0e10cSrcweir 		oShapeHelper->setLeft( Left );
117*cdf0e10cSrcweir 	}
118*cdf0e10cSrcweir 	double SAL_CALL getLeft(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
119*cdf0e10cSrcweir 	{
120*cdf0e10cSrcweir 		return oShapeHelper->getLeft();
121*cdf0e10cSrcweir 	}
122*cdf0e10cSrcweir 	void SAL_CALL setOrientation( ::sal_Int32 _nOrientation ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
123*cdf0e10cSrcweir 	{
124*cdf0e10cSrcweir 		try
125*cdf0e10cSrcweir 		{
126*cdf0e10cSrcweir 			xShapePropertySet->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation")), css::uno::makeAny(_nOrientation*100));
127*cdf0e10cSrcweir 		}
128*cdf0e10cSrcweir 		catch (css::uno::Exception& )
129*cdf0e10cSrcweir 		{
130*cdf0e10cSrcweir 			throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
131*cdf0e10cSrcweir 		}
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir 	::sal_Int32 SAL_CALL getOrientation(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
134*cdf0e10cSrcweir 	{
135*cdf0e10cSrcweir 		sal_Int32 nSOOrientation = 0;
136*cdf0e10cSrcweir 		try
137*cdf0e10cSrcweir 		{
138*cdf0e10cSrcweir 			xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation"))) >>= nSOOrientation;
139*cdf0e10cSrcweir 		}
140*cdf0e10cSrcweir 		catch (css::uno::Exception& )
141*cdf0e10cSrcweir 		{
142*cdf0e10cSrcweir 			throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
143*cdf0e10cSrcweir 		}
144*cdf0e10cSrcweir 		return static_cast< sal_Int32 >(nSOOrientation / 100) ;
145*cdf0e10cSrcweir 	}
146*cdf0e10cSrcweir // XHelperInterface
147*cdf0e10cSrcweir 	rtl::OUString& getServiceImplName()
148*cdf0e10cSrcweir 	{
149*cdf0e10cSrcweir 		static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("TitleImpl") );
150*cdf0e10cSrcweir 		return sImplName;
151*cdf0e10cSrcweir 	}
152*cdf0e10cSrcweir 	css::uno::Sequence< rtl::OUString > getServiceNames()
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		static css::uno::Sequence< rtl::OUString > aServiceNames;
155*cdf0e10cSrcweir 		if ( aServiceNames.getLength() == 0 )
156*cdf0e10cSrcweir 		{
157*cdf0e10cSrcweir 			aServiceNames.realloc( 1 );
158*cdf0e10cSrcweir 			aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XTitle" ) );
159*cdf0e10cSrcweir 		}
160*cdf0e10cSrcweir 		return aServiceNames;
161*cdf0e10cSrcweir 	}
162*cdf0e10cSrcweir };
163*cdf0e10cSrcweir #endif
164