xref: /AOO41X/main/toolkit/inc/toolkit/controls/unocontrol.hxx (revision 50e6b0721ed882c1c74690abd9bee6b3a8da8cfd)
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 #ifndef _TOOLKIT_CONTROLS_UNOCONTROL_HXX_
25 #define _TOOLKIT_CONTROLS_UNOCONTROL_HXX_
26 
27 #include <toolkit/dllapi.h>
28 #include <com/sun/star/awt/XControl.hpp>
29 #include <com/sun/star/awt/XWindow2.hpp>
30 #ifndef _COM_SUN_STAR_AWT_XView_HPP_
31 #include <com/sun/star/awt/XView.hpp>
32 #endif
33 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XTypeProvider.hpp>
36 #include <com/sun/star/lang/XUnoTunnel.hpp>
37 #include <com/sun/star/awt/XUnitConversion.hpp>
38 #include <com/sun/star/awt/XStyleSettingsSupplier.hpp>
39 #include <com/sun/star/accessibility/XAccessible.hpp>
40 #include <cppuhelper/weakagg.hxx>
41 #include <osl/mutex.hxx>
42 #include <toolkit/helper/mutexandbroadcasthelper.hxx>
43 #include <toolkit/helper/listenermultiplexer.hxx>
44 #include <cppuhelper/propshlp.hxx>
45 #include <cppuhelper/interfacecontainer.hxx>
46 #include <cppuhelper/weakref.hxx>
47 #include <cppuhelper/implbase9.hxx>
48 #include <comphelper/componentcontext.hxx>
49 #include <com/sun/star/util/XModeChangeBroadcaster.hpp>
50 #include <com/sun/star/awt/XVclWindowPeer.hpp>
51 
52 
53 struct UnoControlComponentInfos
54 {
55     sal_Bool    bVisible;
56     sal_Bool    bEnable;
57     long        nX, nY, nWidth, nHeight;
58     sal_uInt16  nFlags;
59     float       nZoomX, nZoomY;
60 
UnoControlComponentInfosUnoControlComponentInfos61     UnoControlComponentInfos()
62     {
63         bVisible = sal_True;
64         bEnable = sal_True;
65         nX = nY = nWidth = nHeight = 0;
66         nFlags = 0; // POSSIZE_POSSIZE;
67         nZoomX = nZoomY = 1.0f;
68     }
69 };
70 
71 struct UnoControl_Data;
72 //  ----------------------------------------------------
73 //  class UnoControl
74 //  ----------------------------------------------------
75 typedef ::cppu::WeakAggImplHelper9  <   ::com::sun::star::awt::XControl
76                                     ,   ::com::sun::star::awt::XWindow2
77                                     ,   ::com::sun::star::awt::XView
78                                     ,   ::com::sun::star::beans::XPropertiesChangeListener
79                                     ,   ::com::sun::star::lang::XServiceInfo
80                                     ,   ::com::sun::star::accessibility::XAccessible
81                                     ,   ::com::sun::star::util::XModeChangeBroadcaster
82                                     ,   ::com::sun::star::awt::XUnitConversion
83                                     ,   ::com::sun::star::awt::XStyleSettingsSupplier
84                                     >   UnoControl_Base;
85 
86 class TOOLKIT_DLLPUBLIC UnoControl :    public UnoControl_Base
87 {
88 private:
89     ::osl::Mutex    maMutex;
90 
91     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >      mxPeer;
92     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >   mxVclWindowPeer; // just to avoid the query_interface thing
93 
94 protected:
95     const ::comphelper::ComponentContext    maContext;
96     EventListenerMultiplexer            maDisposeListeners;
97     WindowListenerMultiplexer           maWindowListeners;
98     FocusListenerMultiplexer            maFocusListeners;
99     KeyListenerMultiplexer              maKeyListeners;
100     MouseListenerMultiplexer            maMouseListeners;
101     MouseMotionListenerMultiplexer      maMouseMotionListeners;
102     PaintListenerMultiplexer            maPaintListeners;
103     ::cppu::OInterfaceContainerHelper   maModeChangeListeners;
104 
105     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >       mxContext;
106     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >    mxModel;
107     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >        mxGraphics;
108 
109     ::com::sun::star::uno::WeakReferenceHelper
110                                         maAccessibleContext;    /// our most recent XAccessibleContext instance
111 
112     sal_Bool                            mbDisposePeer;
113     sal_Bool                            mbRefeshingPeer;
114     sal_Bool                            mbCreatingPeer;
115     sal_Bool                            mbCreatingCompatiblePeer;
116     sal_Bool                            mbDesignMode;
117 
118     UnoControlComponentInfos            maComponentInfos;
119     UnoControl_Data*                    mpData;
120 
GetMutex()121     ::osl::Mutex&                                                               GetMutex() { return maMutex; }
122 
123     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >          getParentPeer() const;
124     virtual void                                                                updateFromModel();
125     void                                                                        peerCreated();
126     bool                                                                        ImplCheckLocalize( ::rtl::OUString& _rPossiblyLocalizable );
127     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >      ImplGetCompatiblePeer( sal_Bool bAcceptExistingPeer );
128     virtual void                                                                ImplSetPeerProperty( const ::rtl::OUString& rPropName, const ::com::sun::star::uno::Any& rVal );
129     virtual void                                                                PrepareWindowDescriptor( ::com::sun::star::awt::WindowDescriptor& rDesc );
130     virtual void                                                                ImplModelPropertiesChanged( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyChangeEvent >& rEvents );
131 
132     void                                                                        ImplLockPropertyChangeNotification( const ::rtl::OUString& rPropertyName, bool bLock );
133     void                                                                        ImplLockPropertyChangeNotifications( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rPropertyNames, bool bLock );
134 
135     void                                                                        disposeAccessibleContext();
136 
setPeer(const::com::sun::star::uno::Reference<::com::sun::star::awt::XWindowPeer> & _xPeer)137     inline void setPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& _xPeer)
138     {
139         mxPeer = _xPeer;
140         mxVclWindowPeer = ::com::sun::star::uno::Reference< ::com::sun::star::awt::XVclWindowPeer >(mxPeer,::com::sun::star::uno::UNO_QUERY); // just to avoid the query_interface thing
141     }
142 
143     virtual sal_Bool   requiresNewPeer( const ::rtl::OUString& _rPropertyName ) const;
144 
145 protected:
146                 UnoControl();
147 
148 public:
149                 UnoControl( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& i_factory );
150                 ~UnoControl();
151 
GetComponentInfos()152                 UnoControlComponentInfos&           GetComponentInfos() { return maComponentInfos; }
153 
154 
155     virtual ::rtl::OUString GetComponentServiceName();
156 
157     // ::com::sun::star::lang::XTypeProvider
158     ::com::sun::star::uno::Sequence< sal_Int8 >                     SAL_CALL getImplementationId() throw(::com::sun::star::uno::RuntimeException);
159 
160     // ::com::sun::star::lang::XComponent
161     void SAL_CALL dispose(  ) throw(::com::sun::star::uno::RuntimeException);
162     void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
163     void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw(::com::sun::star::uno::RuntimeException);
164 
165     // XEventListener
166     void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException);
167 
168     // ::com::sun::star::awt::XWindow2
169     virtual void SAL_CALL setOutputSize( const ::com::sun::star::awt::Size& aSize ) throw (::com::sun::star::uno::RuntimeException);
170     virtual ::com::sun::star::awt::Size SAL_CALL getOutputSize(  ) throw (::com::sun::star::uno::RuntimeException);
171     virtual ::sal_Bool SAL_CALL isVisible(  ) throw (::com::sun::star::uno::RuntimeException);
172     virtual ::sal_Bool SAL_CALL isActive(  ) throw (::com::sun::star::uno::RuntimeException);
173     virtual ::sal_Bool SAL_CALL isEnabled(  ) throw (::com::sun::star::uno::RuntimeException);
174     virtual ::sal_Bool SAL_CALL hasFocus(  ) throw (::com::sun::star::uno::RuntimeException);
175 
176     // ::com::sun::star::awt::XWindow
177     void SAL_CALL setPosSize( sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags ) throw(::com::sun::star::uno::RuntimeException);
178     ::com::sun::star::awt::Rectangle SAL_CALL getPosSize(  ) throw(::com::sun::star::uno::RuntimeException);
179     void SAL_CALL setVisible( sal_Bool Visible ) throw(::com::sun::star::uno::RuntimeException);
180     void SAL_CALL setEnable( sal_Bool Enable ) throw(::com::sun::star::uno::RuntimeException);
181     void SAL_CALL setFocus(  ) throw(::com::sun::star::uno::RuntimeException);
182     void SAL_CALL addWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
183     void SAL_CALL removeWindowListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
184     void SAL_CALL addFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
185     void SAL_CALL removeFocusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XFocusListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
186     void SAL_CALL addKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
187     void SAL_CALL removeKeyListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XKeyListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
188     void SAL_CALL addMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
189     void SAL_CALL removeMouseListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
190     void SAL_CALL addMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
191     void SAL_CALL removeMouseMotionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMouseMotionListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
192     void SAL_CALL addPaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
193     void SAL_CALL removePaintListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPaintListener >& xListener ) throw(::com::sun::star::uno::RuntimeException);
194 
195     // ::com::sun::star::awt::XView
196     sal_Bool SAL_CALL setGraphics( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics >& aDevice ) throw(::com::sun::star::uno::RuntimeException);
197     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XGraphics > SAL_CALL getGraphics(  ) throw(::com::sun::star::uno::RuntimeException);
198     ::com::sun::star::awt::Size SAL_CALL getSize(  ) throw(::com::sun::star::uno::RuntimeException);
199     void SAL_CALL draw( sal_Int32 nX, sal_Int32 nY ) throw(::com::sun::star::uno::RuntimeException);
200     void SAL_CALL setZoom( float fZoomX, float fZoomY ) throw(::com::sun::star::uno::RuntimeException);
201 
202     // ::com::sun::star::awt::XControl
203     void SAL_CALL setContext( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Context ) throw(::com::sun::star::uno::RuntimeException);
204     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getContext(  ) throw(::com::sun::star::uno::RuntimeException);
205     void SAL_CALL createPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit >& Toolkit, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& Parent ) throw(::com::sun::star::uno::RuntimeException);
206     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer > SAL_CALL getPeer(  ) throw(::com::sun::star::uno::RuntimeException);
207     sal_Bool SAL_CALL setModel( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& Model ) throw(::com::sun::star::uno::RuntimeException);
208     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel > SAL_CALL getModel(  ) throw(::com::sun::star::uno::RuntimeException);
209     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XView > SAL_CALL getView(  ) throw(::com::sun::star::uno::RuntimeException);
210     void SAL_CALL setDesignMode( sal_Bool bOn ) throw(::com::sun::star::uno::RuntimeException);
211     sal_Bool SAL_CALL isDesignMode(  ) throw(::com::sun::star::uno::RuntimeException);
212     sal_Bool SAL_CALL isTransparent(  ) throw(::com::sun::star::uno::RuntimeException);
213 
214     // ::com::sun::star::lang::XServiceInfo
215     ::rtl::OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
216     sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
217     ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
218 
219     // XAccessible
220     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException);
221 
222     // XModeChangeBroadcaster
223     virtual void SAL_CALL addModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
224     virtual void SAL_CALL removeModeChangeListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeListener >& _rxListener ) throw (::com::sun::star::uno::RuntimeException);
225     virtual void SAL_CALL addModeChangeApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeApproveListener >& _rxListener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
226     virtual void SAL_CALL removeModeChangeApproveListener( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModeChangeApproveListener >& _rxListener ) throw (::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException);
227 
228     // XUnitConversion
229     virtual ::com::sun::star::awt::Point SAL_CALL convertPointToLogic( const ::com::sun::star::awt::Point& Point, ::sal_Int16 TargetUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
230     virtual ::com::sun::star::awt::Point SAL_CALL convertPointToPixel( const ::com::sun::star::awt::Point& aPoint, ::sal_Int16 SourceUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
231     virtual ::com::sun::star::awt::Size SAL_CALL convertSizeToLogic( const ::com::sun::star::awt::Size& aSize, ::sal_Int16 TargetUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
232     virtual ::com::sun::star::awt::Size SAL_CALL convertSizeToPixel( const ::com::sun::star::awt::Size& aSize, ::sal_Int16 SourceUnit ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
233 
234     // XStyleSettingsSupplier
235     virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XStyleSettings > SAL_CALL getStyleSettings() throw (::com::sun::star::uno::RuntimeException);
236 
237 private:
238     // ::com::sun::star::beans::XPropertiesChangeListener
239     void SAL_CALL propertiesChange( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyChangeEvent >& evt ) throw(::com::sun::star::uno::RuntimeException);
240 };
241 
242 
243 
244 
245 #endif // _TOOLKIT_CONTROLS_UNOCONTROL_HXX_
246 
247