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