update dev300-m58
[ooovba.git] / sc / source / ui / vba / vbaoleobject.cxx
bloba13180142f9fdc37b770283318a9e82039423548
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vbaoleobject.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <com/sun/star/awt/XControlModel.hpp>
32 #include <com/sun/star/awt/XWindow2.hpp>
33 #include <com/sun/star/view/XControlAccess.hpp>
34 #include <com/sun/star/container/XChild.hpp>
35 #include <com/sun/star/drawing/XShape.hpp>
36 #include <ooo/vba/XControlProvider.hpp>
38 #include "vbaoleobject.hxx"
40 using namespace com::sun::star;
41 using namespace ooo::vba;
44 sal_Int32 pt2mm( double pt ) //1/100mm
46 return static_cast<sal_Int32>(pt * 0.352778);
49 double mm2pt( sal_Int32 mm )
51 return mm * 2.8345;
55 ScVbaOLEObject::ScVbaOLEObject( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext,
56 css::uno::Reference< css::drawing::XControlShape > xControlShape )
57 : OLEObjectImpl_BASE( xParent, xContext ), m_xControlShape( xControlShape )
59 //init m_xWindowPeer
60 uno::Reference< awt::XControlModel > xControlModel( xControlShape->getControl(), css::uno::UNO_QUERY_THROW );
61 uno::Reference< container::XChild > xChild( xControlModel, uno::UNO_QUERY_THROW );
62 xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW );
63 xChild.set( xChild->getParent(), uno::UNO_QUERY_THROW );
64 css::uno::Reference< css::frame::XModel > xModel( xChild->getParent(), uno::UNO_QUERY_THROW );
65 uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
66 uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW );
67 m_xControl.set( xControlProvider->createControl( xControlShape, xModel ) );
70 uno::Reference< uno::XInterface > SAL_CALL
71 ScVbaOLEObject::getObject() throw (uno::RuntimeException)
73 return uno::Reference< uno::XInterface >( m_xControlShape, uno::UNO_QUERY_THROW );
76 sal_Bool SAL_CALL
77 ScVbaOLEObject::getEnabled() throw (uno::RuntimeException)
79 return m_xControl->getEnabled();
82 void SAL_CALL
83 ScVbaOLEObject::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException)
85 m_xControl->setEnabled( _enabled );
88 sal_Bool SAL_CALL
89 ScVbaOLEObject::getVisible() throw (uno::RuntimeException)
91 OSL_TRACE("OleObject %s returning visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), m_xControl->getVisible() ? "true" : "false" );
92 return m_xControl->getVisible();
95 void SAL_CALL
96 ScVbaOLEObject::setVisible( sal_Bool _visible ) throw (uno::RuntimeException)
98 OSL_TRACE("OleObject %s set visible %s", rtl::OUStringToOString( m_xControl->getName(), RTL_TEXTENCODING_UTF8 ).getStr(), _visible ? "true" : "false" );
99 m_xControl->setVisible( _visible );
102 double SAL_CALL
103 ScVbaOLEObject::getLeft() throw (uno::RuntimeException)
105 return m_xControl->getLeft();
108 void SAL_CALL
109 ScVbaOLEObject::setLeft( double _left ) throw (uno::RuntimeException)
111 m_xControl->setLeft( _left );
115 double SAL_CALL
116 ScVbaOLEObject::getTop() throw (uno::RuntimeException)
118 return m_xControl->getTop();
121 void SAL_CALL
122 ScVbaOLEObject::setTop( double _top ) throw (uno::RuntimeException)
124 m_xControl->setTop( _top );
127 double SAL_CALL
128 ScVbaOLEObject::getHeight() throw (uno::RuntimeException)
130 return m_xControl->getHeight();
133 void SAL_CALL
134 ScVbaOLEObject::setHeight( double _height ) throw (uno::RuntimeException)
136 m_xControl->setHeight( _height );
139 double SAL_CALL
140 ScVbaOLEObject::getWidth() throw (uno::RuntimeException)
142 return m_xControl->getWidth();
145 void SAL_CALL
146 ScVbaOLEObject::setWidth( double _width ) throw (uno::RuntimeException)
148 m_xControl->setWidth( _width );
150 rtl::OUString&
151 ScVbaOLEObject::getServiceImplName()
153 static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaOLEObject") );
154 return sImplName;
157 uno::Sequence< rtl::OUString >
158 ScVbaOLEObject::getServiceNames()
160 static uno::Sequence< rtl::OUString > aServiceNames;
161 if ( aServiceNames.getLength() == 0 )
163 aServiceNames.realloc( 1 );
164 aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.OLEObject" ) );
166 return aServiceNames;