1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <com/sun/star/awt/XControlModel.hpp> 25cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp> 26cdf0e10cSrcweir #include <com/sun/star/view/XControlAccess.hpp> 27cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp> 28cdf0e10cSrcweir #include <com/sun/star/drawing/XShape.hpp> 29cdf0e10cSrcweir #include <ooo/vba/XControlProvider.hpp> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "vbaoleobject.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace com::sun::star; 34cdf0e10cSrcweir using namespace ooo::vba; 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir sal_Int32 pt2mm( double pt ) //1/100mm 38cdf0e10cSrcweir { 39cdf0e10cSrcweir return static_cast<sal_Int32>(pt * 0.352778); 40cdf0e10cSrcweir } 41cdf0e10cSrcweir 42cdf0e10cSrcweir double mm2pt( sal_Int32 mm ) 43cdf0e10cSrcweir { 44cdf0e10cSrcweir return mm * 2.8345; 45cdf0e10cSrcweir } 46cdf0e10cSrcweir 47cdf0e10cSrcweir 48cdf0e10cSrcweir ScVbaOLEObject::ScVbaOLEObject( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, 49cdf0e10cSrcweir css::uno::Reference< css::drawing::XControlShape > xControlShape ) 50cdf0e10cSrcweir : OLEObjectImpl_BASE( xParent, xContext ), m_xControlShape( xControlShape ) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir //init m_xWindowPeer 53cdf0e10cSrcweir uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl(), css::uno::UNO_QUERY_THROW ); 54cdf0e10cSrcweir uno::Reference< container::XChild > xChild( xControlModel, uno::UNO_QUERY_THROW ); 55cdf0e10cSrcweir xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW ); 56cdf0e10cSrcweir xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW ); 57cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel( xChild->getParent(), uno::UNO_QUERY_THROW ); 58cdf0e10cSrcweir uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); 59cdf0e10cSrcweir uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW ); 60cdf0e10cSrcweir m_xControl.set( xControlProvider->createControl( xControlShape, xModel ) ); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL 64cdf0e10cSrcweir ScVbaOLEObject::getObject() throw (uno::RuntimeException) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir return uno::Reference< uno::XInterface >( m_xControlShape, uno::UNO_QUERY_THROW ); 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir sal_Bool SAL_CALL 70cdf0e10cSrcweir ScVbaOLEObject::getEnabled() throw (uno::RuntimeException) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir return m_xControl->getEnabled(); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir void SAL_CALL 76cdf0e10cSrcweir ScVbaOLEObject::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir m_xControl->setEnabled( _enabled ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir sal_Bool SAL_CALL 82cdf0e10cSrcweir ScVbaOLEObject::getVisible() throw (uno::RuntimeException) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir OSL_TRACE("OleObject %s returning visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), m_xControl->getVisible() ? "true" : "false" ); 85cdf0e10cSrcweir return m_xControl->getVisible(); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir void SAL_CALL 89cdf0e10cSrcweir ScVbaOLEObject::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir OSL_TRACE("OleObject %s set visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), _visible ? "true" : "false" ); 92cdf0e10cSrcweir m_xControl->setVisible( _visible ); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir double SAL_CALL 96cdf0e10cSrcweir ScVbaOLEObject::getLeft() throw (uno::RuntimeException) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir return m_xControl->getLeft(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir void SAL_CALL 102cdf0e10cSrcweir ScVbaOLEObject::setLeft( double _left ) throw (uno::RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir m_xControl->setLeft( _left ); 105cdf0e10cSrcweir 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir double SAL_CALL 109cdf0e10cSrcweir ScVbaOLEObject::getTop() throw (uno::RuntimeException) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir return m_xControl->getTop(); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir void SAL_CALL 115cdf0e10cSrcweir ScVbaOLEObject::setTop( double _top ) throw (uno::RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir m_xControl->setTop( _top ); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir double SAL_CALL 121cdf0e10cSrcweir ScVbaOLEObject::getHeight() throw (uno::RuntimeException) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir return m_xControl->getHeight(); 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir void SAL_CALL 127cdf0e10cSrcweir ScVbaOLEObject::setHeight( double _height ) throw (uno::RuntimeException) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir m_xControl->setHeight( _height ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir 132cdf0e10cSrcweir double SAL_CALL 133cdf0e10cSrcweir ScVbaOLEObject::getWidth() throw (uno::RuntimeException) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir return m_xControl->getWidth(); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir void SAL_CALL 139cdf0e10cSrcweir ScVbaOLEObject::setWidth( double _width ) throw (uno::RuntimeException) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir m_xControl->setWidth( _width ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir rtl::OUString& 144cdf0e10cSrcweir ScVbaOLEObject::getServiceImplName() 145cdf0e10cSrcweir { 146cdf0e10cSrcweir static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaOLEObject") ); 147cdf0e10cSrcweir return sImplName; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir uno::Sequence< rtl::OUString > 151cdf0e10cSrcweir ScVbaOLEObject::getServiceNames() 152cdf0e10cSrcweir { 153cdf0e10cSrcweir static uno::Sequence< rtl::OUString > aServiceNames; 154cdf0e10cSrcweir if ( aServiceNames.getLength() == 0 ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir aServiceNames.realloc( 1 ); 157cdf0e10cSrcweir aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.OLEObject" ) ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir return aServiceNames; 160cdf0e10cSrcweir } 161