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 28 #include <com/sun/star/awt/XControlModel.hpp> 29 #include <com/sun/star/awt/XWindow2.hpp> 30 #include <com/sun/star/view/XControlAccess.hpp> 31 #include <com/sun/star/container/XChild.hpp> 32 #include <com/sun/star/drawing/XShape.hpp> 33 #include <ooo/vba/XControlProvider.hpp> 34 35 #include "vbaoleobject.hxx" 36 37 using namespace com::sun::star; 38 using namespace ooo::vba; 39 40 41 sal_Int32 pt2mm( double pt ) //1/100mm 42 { 43 return static_cast<sal_Int32>(pt * 0.352778); 44 } 45 46 double mm2pt( sal_Int32 mm ) 47 { 48 return mm * 2.8345; 49 } 50 51 52 ScVbaOLEObject::ScVbaOLEObject( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, 53 css::uno::Reference< css::drawing::XControlShape > xControlShape ) 54 : OLEObjectImpl_BASE( xParent, xContext ), m_xControlShape( xControlShape ) 55 { 56 //init m_xWindowPeer 57 uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl(), css::uno::UNO_QUERY_THROW ); 58 uno::Reference< container::XChild > xChild( xControlModel, uno::UNO_QUERY_THROW ); 59 xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW ); 60 xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW ); 61 css::uno::Reference< css::frame::XModel > xModel( xChild->getParent(), uno::UNO_QUERY_THROW ); 62 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); 63 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW ); 64 m_xControl.set( xControlProvider->createControl( xControlShape, xModel ) ); 65 } 66 67 uno::Reference< uno::XInterface > SAL_CALL 68 ScVbaOLEObject::getObject() throw (uno::RuntimeException) 69 { 70 return uno::Reference< uno::XInterface >( m_xControlShape, uno::UNO_QUERY_THROW ); 71 } 72 73 sal_Bool SAL_CALL 74 ScVbaOLEObject::getEnabled() throw (uno::RuntimeException) 75 { 76 return m_xControl->getEnabled(); 77 } 78 79 void SAL_CALL 80 ScVbaOLEObject::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) 81 { 82 m_xControl->setEnabled( _enabled ); 83 } 84 85 sal_Bool SAL_CALL 86 ScVbaOLEObject::getVisible() throw (uno::RuntimeException) 87 { 88 OSL_TRACE("OleObject %s returning visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), m_xControl->getVisible() ? "true" : "false" ); 89 return m_xControl->getVisible(); 90 } 91 92 void SAL_CALL 93 ScVbaOLEObject::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) 94 { 95 OSL_TRACE("OleObject %s set visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), _visible ? "true" : "false" ); 96 m_xControl->setVisible( _visible ); 97 } 98 99 double SAL_CALL 100 ScVbaOLEObject::getLeft() throw (uno::RuntimeException) 101 { 102 return m_xControl->getLeft(); 103 } 104 105 void SAL_CALL 106 ScVbaOLEObject::setLeft( double _left ) throw (uno::RuntimeException) 107 { 108 m_xControl->setLeft( _left ); 109 110 } 111 112 double SAL_CALL 113 ScVbaOLEObject::getTop() throw (uno::RuntimeException) 114 { 115 return m_xControl->getTop(); 116 } 117 118 void SAL_CALL 119 ScVbaOLEObject::setTop( double _top ) throw (uno::RuntimeException) 120 { 121 m_xControl->setTop( _top ); 122 } 123 124 double SAL_CALL 125 ScVbaOLEObject::getHeight() throw (uno::RuntimeException) 126 { 127 return m_xControl->getHeight(); 128 } 129 130 void SAL_CALL 131 ScVbaOLEObject::setHeight( double _height ) throw (uno::RuntimeException) 132 { 133 m_xControl->setHeight( _height ); 134 } 135 136 double SAL_CALL 137 ScVbaOLEObject::getWidth() throw (uno::RuntimeException) 138 { 139 return m_xControl->getWidth(); 140 } 141 142 void SAL_CALL 143 ScVbaOLEObject::setWidth( double _width ) throw (uno::RuntimeException) 144 { 145 m_xControl->setWidth( _width ); 146 } 147 rtl::OUString& 148 ScVbaOLEObject::getServiceImplName() 149 { 150 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaOLEObject") ); 151 return sImplName; 152 } 153 154 uno::Sequence< rtl::OUString > 155 ScVbaOLEObject::getServiceNames() 156 { 157 static uno::Sequence< rtl::OUString > aServiceNames; 158 if ( aServiceNames.getLength() == 0 ) 159 { 160 aServiceNames.realloc( 1 ); 161 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.OLEObject" ) ); 162 } 163 return aServiceNames; 164 } 165