1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef SC_VBA_TITLE_HXX 28 #define SC_VBA_TITLE_HXX 29 30 #include <vbahelper/vbahelperinterface.hxx> 31 #include "excelvbahelper.hxx" 32 #include "vbainterior.hxx" 33 #include "vbafont.hxx" 34 #include "vbapalette.hxx" 35 #include <com/sun/star/drawing/XShape.hpp> 36 #include <com/sun/star/beans/XPropertySet.hpp> 37 #include <ooo/vba/excel/XTitle.hpp> 38 #include <ooo/vba/excel/XCharacters.hpp> 39 #include <basic/sberrors.hxx> 40 #include <memory> 41 42 template< typename Ifc1 > 43 class TitleImpl : public InheritedHelperInterfaceImpl< Ifc1 > 44 { 45 typedef InheritedHelperInterfaceImpl< Ifc1 > BaseClass; 46 47 protected: 48 css::uno::Reference< css::drawing::XShape > xTitleShape; 49 css::uno::Reference< css::beans::XPropertySet > xShapePropertySet; 50 std::auto_ptr<ov::ShapeHelper> oShapeHelper; 51 ScVbaPalette m_Palette; 52 public: 53 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 { 55 xShapePropertySet.set( xTitleShape, css::uno::UNO_QUERY_THROW ); 56 oShapeHelper.reset( new ov::ShapeHelper(xTitleShape) ); 57 } 58 css::uno::Reference< ov::excel::XInterior > SAL_CALL Interior( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 59 { 60 // #TODO find out what the proper parent should be 61 // leaving as set by the helperapi for the moment 62 // #TODO we really need the ScDocument to pass to ScVbaInterior 63 // otherwise attemps to access the palette will fail 64 return new ScVbaInterior( BaseClass::mxParent, BaseClass::mxContext, xShapePropertySet ); 65 } 66 css::uno::Reference< ov::excel::XFont > SAL_CALL Font( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 67 { 68 // #TODO find out what the proper parent should be 69 // leaving as set by the helperapi for the moment 70 return new ScVbaFont( BaseClass::mxParent, BaseClass::mxContext, m_Palette, xShapePropertySet ); 71 72 } 73 void SAL_CALL setText( const ::rtl::OUString& Text ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 74 { 75 try 76 { 77 xShapePropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ), css::uno::makeAny( Text )); 78 } 79 catch ( css::uno::Exception& ) 80 { 81 throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); 82 } 83 } 84 ::rtl::OUString SAL_CALL getText( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 85 { 86 ::rtl::OUString sText; 87 try 88 { 89 xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("String") ) ) >>= sText; 90 } 91 catch ( css::uno::Exception& ) 92 { 93 throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); 94 } 95 return sText; 96 } 97 98 css::uno::Reference< ov::excel::XCharacters > SAL_CALL Characters( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 99 { 100 // #FIXME #TODO the helperapi Characters implementation doesn't 101 // seem to do very much, need to know how the existing Characters 102 // impl ( that we use for Range ) can be reused 103 return css::uno::Reference< ov::excel::XCharacters > (); 104 } 105 106 void SAL_CALL setTop( double Top ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 107 { 108 oShapeHelper->setTop( Top ); 109 } 110 double SAL_CALL getTop( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 111 { 112 return oShapeHelper->getTop(); 113 } 114 void SAL_CALL setLeft( double Left ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 115 { 116 oShapeHelper->setLeft( Left ); 117 } 118 double SAL_CALL getLeft( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 119 { 120 return oShapeHelper->getLeft(); 121 } 122 void SAL_CALL setOrientation( ::sal_Int32 _nOrientation ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 123 { 124 try 125 { 126 xShapePropertySet->setPropertyValue(rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation")), css::uno::makeAny(_nOrientation*100)); 127 } 128 catch (css::uno::Exception& ) 129 { 130 throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); 131 } 132 } 133 ::sal_Int32 SAL_CALL getOrientation( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) 134 { 135 sal_Int32 nSOOrientation = 0; 136 try 137 { 138 xShapePropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRotation"))) >>= nSOOrientation; 139 } 140 catch (css::uno::Exception& ) 141 { 142 throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); 143 } 144 return static_cast< sal_Int32 >(nSOOrientation / 100) ; 145 } 146 // XHelperInterface 147 rtl::OUString& getServiceImplName() 148 { 149 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("TitleImpl") ); 150 return sImplName; 151 } 152 css::uno::Sequence< rtl::OUString > getServiceNames() 153 { 154 static css::uno::Sequence< rtl::OUString > aServiceNames; 155 if ( aServiceNames.getLength() == 0 ) 156 { 157 aServiceNames.realloc( 1 ); 158 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.XTitle" ) ); 159 } 160 return aServiceNames; 161 } 162 }; 163 #endif 164