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