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_CONTROL_HXX
28 #define SC_VBA_CONTROL_HXX
29 
30 #include <cppuhelper/implbase1.hxx>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
33 #include <com/sun/star/script/XDefaultProperty.hpp>
34 #include <com/sun/star/drawing/XControlShape.hpp>
35 #include <com/sun/star/awt/XControl.hpp>
36 #include <com/sun/star/awt/XWindowPeer.hpp>
37 #include <ooo/vba/msforms/XControl.hpp>
38 
39 #include <vbahelper/vbahelper.hxx>
40 #include <vbahelper/vbahelperinterface.hxx>
41 #include <memory>
42 
43 //typedef ::cppu::WeakImplHelper1< ov::msforms::XControl > ControlImpl_BASE;
44 //template SAL_DLLPUBLIC_IMPORT InheritedHelperInterfaceImpl1< ov::msforms::XControl >;
45 typedef InheritedHelperInterfaceImpl1< ov::msforms::XControl > ControlImpl_BASE;
46 
47 class ScVbaControl : public ControlImpl_BASE
48 {
49 private:
50     com::sun::star::uno::Reference< com::sun::star::lang::XEventListener > m_xEventListener;
51 protected:
52     // awt control has nothing similar to Tag property of Mso controls,
53     // whether it is necessary is another question
54     ::rtl::OUString m_aControlTag;
55 
56     std::auto_ptr< ov::AbstractGeometryAttributes > mpGeometryHelper;
57     css::uno::Reference< css::beans::XPropertySet > m_xProps;
58     css::uno::Reference< css::uno::XInterface > m_xControl;
59     css::uno::Reference< css::frame::XModel > m_xModel;
60 
61     virtual css::uno::Reference< css::awt::XWindowPeer > getWindowPeer() throw (css::uno::RuntimeException);
62 public:
63     ScVbaControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext,
64                     const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pHelper );
65     virtual ~ScVbaControl();
66     // This class will own the helper, so make sure it is allocated from
67     // the heap
68     void setGeometryHelper( ov::AbstractGeometryAttributes* pHelper );
69     // XControl
70     virtual sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException);
71     virtual void SAL_CALL setEnabled( sal_Bool _enabled ) throw (css::uno::RuntimeException);
72     virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException);
73     virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException);
74     virtual double SAL_CALL getHeight() throw (css::uno::RuntimeException);
75     virtual void SAL_CALL setHeight( double _height ) throw (css::uno::RuntimeException);
76     virtual double SAL_CALL getWidth() throw (css::uno::RuntimeException);
77     virtual void SAL_CALL setWidth( double _width ) throw (css::uno::RuntimeException);
78     virtual double SAL_CALL getLeft() throw (css::uno::RuntimeException);
79     virtual void SAL_CALL setLeft( double _left ) throw (css::uno::RuntimeException);
80     virtual double SAL_CALL getTop() throw (css::uno::RuntimeException);
81     virtual void SAL_CALL setTop( double _top ) throw (css::uno::RuntimeException);
82     virtual void SAL_CALL SetFocus(  ) throw (css::uno::RuntimeException);
83     virtual void SAL_CALL Move( double Left, double Top, const ::com::sun::star::uno::Any& Width, const ::com::sun::star::uno::Any& Height ) throw (::com::sun::star::uno::RuntimeException);
84 
85     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getObject() throw (css::uno::RuntimeException);
86     virtual rtl::OUString SAL_CALL getControlSource() throw (css::uno::RuntimeException);
87     virtual void SAL_CALL setControlSource( const rtl::OUString& _controlsource ) throw (css::uno::RuntimeException);
88     virtual rtl::OUString SAL_CALL getRowSource() throw (css::uno::RuntimeException);
89     virtual void SAL_CALL setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException);
90     virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException);
91     virtual void SAL_CALL setName( const rtl::OUString& _name ) throw (css::uno::RuntimeException);
92     virtual rtl::OUString SAL_CALL getControlTipText() throw (css::uno::RuntimeException);
93     virtual void SAL_CALL setControlTipText( const rtl::OUString& ) throw (css::uno::RuntimeException);
94     virtual ::rtl::OUString SAL_CALL getTag() throw (css::uno::RuntimeException);
95     virtual void SAL_CALL setTag( const ::rtl::OUString& aTag ) throw (css::uno::RuntimeException);
96     virtual sal_Int32 SAL_CALL getTabIndex() throw (css::uno::RuntimeException);
97     virtual void SAL_CALL setTabIndex( sal_Int32 nTabIndex ) throw (css::uno::RuntimeException);
98     //remove resouce because ooo.vba.excel.XControl is a wrapper of com.sun.star.drawing.XControlShape
99     virtual void removeResouce() throw( css::uno::RuntimeException );
100     //XHelperInterface
101     virtual rtl::OUString& getServiceImplName();
102     virtual css::uno::Sequence<rtl::OUString> getServiceNames();
103 };
104 
105 
106 class ScVbaControlFactory
107 {
108 public:
109     static css::uno::Reference< ov::msforms::XControl > createShapeControl(
110         const css::uno::Reference< css::uno::XComponentContext >& xContext,
111         const css::uno::Reference< css::drawing::XControlShape >& xControlShape,
112         const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException);
113 
114     static css::uno::Reference< ov::msforms::XControl > createUserformControl(
115         const css::uno::Reference< css::uno::XComponentContext >& xContext,
116         const css::uno::Reference< css::awt::XControl >& xControl,
117         const css::uno::Reference< css::awt::XControl >& xDialog,
118         const css::uno::Reference< css::frame::XModel >& xModel,
119         double fOffsetX, double fOffsetY ) throw (css::uno::RuntimeException);
120 
121 private:
122     ScVbaControlFactory();
123     ~ScVbaControlFactory();
124 };
125 
126 #endif//SC_VBA_CONTROL_HXX
127