xref: /trunk/main/sc/source/ui/vba/vbatitle.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir #ifndef SC_VBA_TITLE_HXX
24cdf0e10cSrcweir #define SC_VBA_TITLE_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <vbahelper/vbahelperinterface.hxx>
27cdf0e10cSrcweir #include "excelvbahelper.hxx"
28cdf0e10cSrcweir #include "vbainterior.hxx"
29cdf0e10cSrcweir #include "vbafont.hxx"
30cdf0e10cSrcweir #include "vbapalette.hxx"
31cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
33cdf0e10cSrcweir #include <ooo/vba/excel/XTitle.hpp>
34cdf0e10cSrcweir #include <ooo/vba/excel/XCharacters.hpp>
35cdf0e10cSrcweir #include <basic/sberrors.hxx>
36cdf0e10cSrcweir #include <memory>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir template< typename Ifc1 >
39cdf0e10cSrcweir class TitleImpl : public InheritedHelperInterfaceImpl< Ifc1 >
40cdf0e10cSrcweir {
41cdf0e10cSrcweir typedef InheritedHelperInterfaceImpl< Ifc1 > BaseClass;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir protected:
44cdf0e10cSrcweir     css::uno::Reference< css::drawing::XShape > xTitleShape;
45cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertySet > xShapePropertySet;
46cdf0e10cSrcweir     std::auto_ptr<ov::ShapeHelper> oShapeHelper;
47cdf0e10cSrcweir     ScVbaPalette m_Palette;
48cdf0e10cSrcweir public:
TitleImpl(const css::uno::Reference<ov::XHelperInterface> & xParent,const css::uno::Reference<css::uno::XComponentContext> & xContext,const css::uno::Reference<css::drawing::XShape> & _xTitleShape)49cdf0e10cSrcweir     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 )
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         xShapePropertySet.set( xTitleShape, css::uno::UNO_QUERY_THROW );
52cdf0e10cSrcweir         oShapeHelper.reset( new ov::ShapeHelper(xTitleShape) );
53cdf0e10cSrcweir     }
Interior()54cdf0e10cSrcweir     css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir         // #TODO find out what the proper parent should be
57cdf0e10cSrcweir         // leaving as set by the helperapi for the moment
58cdf0e10cSrcweir         // #TODO we really need the ScDocument to pass to ScVbaInterior
59cdf0e10cSrcweir         // otherwise attemps to access the palette will fail
60cdf0e10cSrcweir         return new ScVbaInterior( BaseClass::mxParent, BaseClass::mxContext, xShapePropertySet );
61cdf0e10cSrcweir     }
Font()62cdf0e10cSrcweir     css::uno::Reference< ov::excel::XFont > SAL_CALL Font(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         // #TODO find out what the proper parent should be
65cdf0e10cSrcweir         // leaving as set by the helperapi for the moment
66cdf0e10cSrcweir         return new ScVbaFont( BaseClass::mxParent, BaseClass::mxContext, m_Palette, xShapePropertySet );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     }
setText(const::rtl::OUString & Text)69cdf0e10cSrcweir     void SAL_CALL setText( const ::rtl::OUString& Text ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir         try
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             xShapePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ), css::uno::makeAny( Text ));
74cdf0e10cSrcweir         }
75cdf0e10cSrcweir         catch ( css::uno::Exception& )
76cdf0e10cSrcweir         {
77cdf0e10cSrcweir             throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir     }
getText()80cdf0e10cSrcweir     ::rtl::OUString SAL_CALL getText(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         ::rtl::OUString sText;
83cdf0e10cSrcweir         try
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ) ) >>= sText;
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir         catch ( css::uno::Exception& )
88cdf0e10cSrcweir         {
89cdf0e10cSrcweir             throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
90cdf0e10cSrcweir         }
91cdf0e10cSrcweir         return sText;
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
Characters()94cdf0e10cSrcweir     css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         // #FIXME #TODO the helperapi Characters implementation doesn't
97cdf0e10cSrcweir         // seem to do very much, need to know how the existing Characters
98cdf0e10cSrcweir         // impl ( that we use for Range ) can be reused
99cdf0e10cSrcweir         return  css::uno::Reference< ov::excel::XCharacters > ();
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
setTop(double Top)102cdf0e10cSrcweir     void SAL_CALL setTop( double Top ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         oShapeHelper->setTop( Top );
105cdf0e10cSrcweir     }
getTop()106cdf0e10cSrcweir     double SAL_CALL getTop(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         return oShapeHelper->getTop();
109cdf0e10cSrcweir     }
setLeft(double Left)110cdf0e10cSrcweir     void SAL_CALL setLeft( double Left ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         oShapeHelper->setLeft( Left );
113cdf0e10cSrcweir     }
getLeft()114cdf0e10cSrcweir     double SAL_CALL getLeft(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         return oShapeHelper->getLeft();
117cdf0e10cSrcweir     }
setOrientation(::sal_Int32 _nOrientation)118cdf0e10cSrcweir     void SAL_CALL setOrientation( ::sal_Int32 _nOrientation ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
119cdf0e10cSrcweir     {
120cdf0e10cSrcweir         try
121cdf0e10cSrcweir         {
122cdf0e10cSrcweir             xShapePropertySet->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation")), css::uno::makeAny(_nOrientation*100));
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir         catch (css::uno::Exception& )
125cdf0e10cSrcweir         {
126cdf0e10cSrcweir             throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir     }
getOrientation()129cdf0e10cSrcweir     ::sal_Int32 SAL_CALL getOrientation(  ) throw (css::script::BasicErrorException, css::uno::RuntimeException)
130cdf0e10cSrcweir     {
131cdf0e10cSrcweir         sal_Int32 nSOOrientation = 0;
132cdf0e10cSrcweir         try
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir             xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation"))) >>= nSOOrientation;
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir         catch (css::uno::Exception& )
137cdf0e10cSrcweir         {
138cdf0e10cSrcweir             throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() );
139cdf0e10cSrcweir         }
140cdf0e10cSrcweir         return static_cast< sal_Int32 >(nSOOrientation / 100) ;
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir // XHelperInterface
getServiceImplName()143cdf0e10cSrcweir     rtl::OUString& getServiceImplName()
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("TitleImpl") );
146cdf0e10cSrcweir         return sImplName;
147cdf0e10cSrcweir     }
getServiceNames()148cdf0e10cSrcweir     css::uno::Sequence< rtl::OUString > getServiceNames()
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         static css::uno::Sequence< rtl::OUString > aServiceNames;
151cdf0e10cSrcweir         if ( aServiceNames.getLength() == 0 )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             aServiceNames.realloc( 1 );
154cdf0e10cSrcweir             aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XTitle" ) );
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir         return aServiceNames;
157cdf0e10cSrcweir     }
158cdf0e10cSrcweir };
159cdf0e10cSrcweir #endif
160