LibreOffice Module UnoControls (master)  1
basecontrol.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #pragma once
21 
22 #include <com/sun/star/awt/XPaintListener.hpp>
23 #include <com/sun/star/awt/XWindowListener.hpp>
24 #include <com/sun/star/awt/XControl.hpp>
25 #include <com/sun/star/awt/XWindow.hpp>
26 #include <com/sun/star/awt/XView.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <osl/mutex.hxx>
29 #include <cppuhelper/component.hxx>
30 #include <rtl/ref.hxx>
31 
32 namespace com::sun::star::uno { class XComponentContext; }
33 namespace com::sun::star::awt { class XFocusListener; }
34 namespace com::sun::star::awt { class XMouseListener; }
35 namespace com::sun::star::awt { class XMouseMotionListener; }
36 namespace com::sun::star::awt { struct PaintEvent; }
37 namespace com::sun::star::awt { struct WindowEvent; }
38 namespace unocontrols { class OMRCListenerMultiplexerHelper; }
39 
40 namespace unocontrols {
41 
43 {
44  // Is necessary to initialize "BaseControl" and make this class thread-safe.
45  ::osl::Mutex m_aMutex;
46 };
47 
48 class BaseControl : public css::lang::XServiceInfo
49  , public css::awt::XPaintListener
50  , public css::awt::XWindowListener
51  , public css::awt::XView
52  , public css::awt::XWindow
53  , public css::awt::XControl
54  , public IMPL_MutexContainer
56 {
57 public:
58  BaseControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
59 
60  virtual ~BaseControl() override;
61 
62  // XInterface
63 
77  virtual css::uno::Any SAL_CALL queryInterface(
78  const css::uno::Type& aType
79  ) override;
80 
88  virtual void SAL_CALL acquire() throw() override;
89 
97  virtual void SAL_CALL release() throw() override;
98 
99  // XTypeProvider
100 
109  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
110 
122  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
123 
124  // XAggregation
125 
126  virtual void SAL_CALL setDelegator(
127  const css::uno::Reference< css::uno::XInterface >& xDelegator
128  ) override;
129 
130  virtual css::uno::Any SAL_CALL queryAggregation(
131  const css::uno::Type& aType
132  ) override;
133 
134  // XServiceInfo
135 
136  virtual sal_Bool SAL_CALL supportsService(
137  const OUString& sServiceName
138  ) override;
139 
140  virtual OUString SAL_CALL getImplementationName() override;
141 
142  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
143 
144  // XComponent
145 
146  virtual void SAL_CALL dispose() override;
147 
148  virtual void SAL_CALL addEventListener(
149  const css::uno::Reference< css::lang::XEventListener >& xListener
150  ) override;
151 
152  virtual void SAL_CALL removeEventListener(
153  const css::uno::Reference< css::lang::XEventListener >& xListener
154  ) override;
155 
156  // XControl
157 
158  virtual void SAL_CALL createPeer(
159  const css::uno::Reference< css::awt::XToolkit >& xToolkit,
160  const css::uno::Reference< css::awt::XWindowPeer >& xParent
161  ) override;
162 
163  virtual void SAL_CALL setContext(
164  const css::uno::Reference< css::uno::XInterface >& xContext
165  ) override;
166 
167  virtual sal_Bool SAL_CALL setModel(
168  const css::uno::Reference< css::awt::XControlModel >& xModel
169  ) override = 0;
170 
171  virtual void SAL_CALL setDesignMode( sal_Bool bOn ) override;
172 
173  virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getContext() override;
174 
175  virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override = 0;
176 
177  virtual css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override;
178 
179  virtual css::uno::Reference< css::awt::XView > SAL_CALL getView() override;
180 
181  virtual sal_Bool SAL_CALL isDesignMode() override;
182 
183  virtual sal_Bool SAL_CALL isTransparent() override;
184 
185  // XWindow
186 
187  virtual void SAL_CALL setPosSize( sal_Int32 nX ,
188  sal_Int32 nY ,
189  sal_Int32 nWidth ,
190  sal_Int32 nHeight ,
191  sal_Int16 nFlags ) override;
192 
193  virtual void SAL_CALL setVisible( sal_Bool bVisible ) override;
194 
195  virtual void SAL_CALL setEnable( sal_Bool bEnable ) override;
196 
197  virtual void SAL_CALL setFocus() override;
198 
199  virtual css::awt::Rectangle SAL_CALL getPosSize() override;
200 
201  virtual void SAL_CALL addWindowListener(
202  const css::uno::Reference< css::awt::XWindowListener >& xListener
203  ) override;
204 
205  virtual void SAL_CALL addFocusListener(
206  const css::uno::Reference< css::awt::XFocusListener >& xListener
207  ) override;
208 
209  virtual void SAL_CALL addKeyListener(
210  const css::uno::Reference< css::awt::XKeyListener >& xListener ) override;
211 
212  virtual void SAL_CALL addMouseListener(
213  const css::uno::Reference< css::awt::XMouseListener >& xListener
214  ) override;
215 
216  virtual void SAL_CALL addMouseMotionListener(
217  const css::uno::Reference< css::awt::XMouseMotionListener >& xListener
218  ) override;
219 
220  virtual void SAL_CALL addPaintListener(
221  const css::uno::Reference< css::awt::XPaintListener >& xListener
222  ) override;
223 
224  virtual void SAL_CALL removeWindowListener(
225  const css::uno::Reference< css::awt::XWindowListener >& xListener
226  ) override;
227 
228  virtual void SAL_CALL removeFocusListener(
229  const css::uno::Reference< css::awt::XFocusListener >& xListener
230  ) override;
231 
232  virtual void SAL_CALL removeKeyListener(
233  const css::uno::Reference< css::awt::XKeyListener >& xListener
234  ) override;
235 
236  virtual void SAL_CALL removeMouseListener(
237  const css::uno::Reference< css::awt::XMouseListener >& xListener
238  ) override;
239 
240  virtual void SAL_CALL removeMouseMotionListener(
241  const css::uno::Reference< css::awt::XMouseMotionListener >& xListener
242  ) override;
243 
244  virtual void SAL_CALL removePaintListener(
245  const css::uno::Reference< css::awt::XPaintListener >& xListener
246  ) override;
247 
248  // XView
249 
250  virtual void SAL_CALL draw( sal_Int32 nX ,
251  sal_Int32 nY ) override;
252 
253  virtual sal_Bool SAL_CALL setGraphics(
254  const css::uno::Reference< css::awt::XGraphics >& xDevice
255  ) override;
256 
257  virtual void SAL_CALL setZoom( float fZoomX ,
258  float fZoomY ) override;
259 
260  virtual css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics() override;
261 
262  virtual css::awt::Size SAL_CALL getSize() override;
263 
264  // css::lang::XEventListener
265 
266  virtual void SAL_CALL disposing(
267  const css::lang::EventObject& rSource
268  ) override;
269 
270  // XPaintListener
271 
272  virtual void SAL_CALL windowPaint(
273  const css::awt::PaintEvent& rEvent
274  ) override;
275 
276  // XWindowListener
277 
278  virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) override;
279  virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) override;
280  virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) override;
281  virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override;
282 
283 protected:
284  using OComponentHelper::disposing;
285 
286  const css::uno::Reference< css::uno::XComponentContext >& impl_getComponentContext() const { return m_xComponentContext;}
287 
288  const css::uno::Reference< css::awt::XWindow >& impl_getPeerWindow() const { return m_xPeerWindow;}
289 
290  const css::uno::Reference< css::awt::XGraphics >& impl_getGraphicsPeer() const { return m_xGraphicsPeer;}
291 
292  sal_Int32 impl_getWidth() const { return m_nWidth;}
293 
294  sal_Int32 impl_getHeight() const { return m_nHeight;}
295 
296  virtual css::awt::WindowDescriptor impl_getWindowDescriptor(
297  const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer
298  );
299 
300  virtual void impl_paint( sal_Int32 nX ,
301  sal_Int32 nY ,
302  const css::uno::Reference< css::awt::XGraphics >& xGraphics );
303 
304  virtual void impl_recalcLayout( const css::awt::WindowEvent& aEvent );
305 
306  const css::uno::Reference< css::uno::XInterface >& impl_getDelegator() const { return m_xDelegator;}
307 
308 private:
310 
311  css::uno::Reference< css::uno::XComponentContext > m_xComponentContext;
312  css::uno::Reference< css::uno::XInterface > m_xDelegator;
314  css::uno::Reference< css::uno::XInterface > m_xContext;
315  css::uno::Reference< css::awt::XWindowPeer > m_xPeer;
316  css::uno::Reference< css::awt::XWindow > m_xPeerWindow;
317  css::uno::Reference< css::awt::XGraphics > m_xGraphicsView; // graphics for css::awt::XView-operations
318  css::uno::Reference< css::awt::XGraphics > m_xGraphicsPeer; // graphics for painting on a peer
319  sal_Int32 m_nX; // Position ...
320  sal_Int32 m_nY;
321  sal_Int32 m_nWidth; // ... and size of window
322  sal_Int32 m_nHeight;
323  bool m_bVisible; // Some state flags
325  bool m_bEnable;
326 };
327 
328 }
329 
330 
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OMRCListenerMultiplexerHelper * impl_getMultiplexer()
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
bool bVisible
rtl::Reference< OMRCListenerMultiplexerHelper > m_xMultiplexer
const css::uno::Reference< css::uno::XComponentContext > & impl_getComponentContext() const
virtual void SAL_CALL windowPaint(const css::awt::PaintEvent &rEvent) override
virtual void SAL_CALL setContext(const css::uno::Reference< css::uno::XInterface > &xContext) override
virtual void impl_paint(sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< css::awt::XGraphics > &xGraphics)
virtual void SAL_CALL setEnable(sal_Bool bEnable) override
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual void SAL_CALL setVisible(sal_Bool bVisible) override
virtual void SAL_CALL windowMoved(const css::awt::WindowEvent &aEvent) override
virtual void SAL_CALL removePaintListener(const css::uno::Reference< css::awt::XPaintListener > &xListener) override
virtual void SAL_CALL setZoom(float fZoomX, float fZoomY) override
const css::uno::Reference< css::awt::XGraphics > & impl_getGraphicsPeer() const
virtual void SAL_CALL windowResized(const css::awt::WindowEvent &aEvent) override
css::uno::Reference< css::awt::XGraphics > m_xGraphicsView
virtual void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &xToolkit, const css::uno::Reference< css::awt::XWindowPeer > &xParent) override
virtual void SAL_CALL dispose() override
sal_Int32 impl_getHeight() const
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::awt::XWindowPeer > m_xPeer
virtual void SAL_CALL addWindowListener(const css::uno::Reference< css::awt::XWindowListener > &xListener) override
virtual css::uno::Reference< css::awt::XView > SAL_CALL getView() override
css::uno::Reference< css::awt::XGraphics > m_xGraphicsPeer
css::uno::Reference< css::awt::XWindow > m_xPeerWindow
virtual void SAL_CALL disposing()
virtual void SAL_CALL addMouseMotionListener(const css::uno::Reference< css::awt::XMouseMotionListener > &xListener) override
virtual void SAL_CALL removeMouseListener(const css::uno::Reference< css::awt::XMouseListener > &xListener) override
virtual sal_Bool SAL_CALL setModel(const css::uno::Reference< css::awt::XControlModel > &xModel) override=0
virtual void SAL_CALL setDesignMode(sal_Bool bOn) override
virtual css::awt::Size SAL_CALL getSize() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeKeyListener(const css::uno::Reference< css::awt::XKeyListener > &xListener) override
sal_Int32 impl_getWidth() const
css::uno::Reference< css::uno::XInterface > m_xDelegator
unsigned char sal_Bool
virtual void SAL_CALL acquire() override
increment refcount XInterface release() A RuntimeException is thrown.
Definition: basecontrol.cxx:91
virtual void SAL_CALL setFocus() override
virtual void SAL_CALL setPosSize(sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags) override
virtual void impl_recalcLayout(const css::awt::WindowEvent &aEvent)
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &aType) override
virtual void SAL_CALL removeMouseMotionListener(const css::uno::Reference< css::awt::XMouseMotionListener > &xListener) override
virtual css::awt::WindowDescriptor impl_getWindowDescriptor(const css::uno::Reference< css::awt::XWindowPeer > &xParentPeer)
BaseControl(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
Definition: basecontrol.cxx:51
virtual css::awt::Rectangle SAL_CALL getPosSize() override
virtual ~BaseControl() override
Definition: basecontrol.cxx:65
virtual css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override
virtual void SAL_CALL windowShown(const css::lang::EventObject &aEvent) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getContext() override
virtual sal_Bool SAL_CALL isDesignMode() override
virtual css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics() override
virtual void SAL_CALL addFocusListener(const css::uno::Reference< css::awt::XFocusListener > &xListener) override
virtual void SAL_CALL removeFocusListener(const css::uno::Reference< css::awt::XFocusListener > &xListener) override
const css::uno::Reference< css::uno::XInterface > & impl_getDelegator() const
virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override=0
virtual sal_Bool SAL_CALL setGraphics(const css::uno::Reference< css::awt::XGraphics > &xDevice) override
virtual void SAL_CALL addMouseListener(const css::uno::Reference< css::awt::XMouseListener > &xListener) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
get information about supported interfaces XTypeProvider
virtual void SAL_CALL addKeyListener(const css::uno::Reference< css::awt::XKeyListener > &xListener) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
give answer, if interface is supported The interfaces are searched by type.
Definition: basecontrol.cxx:71
virtual void SAL_CALL draw(sal_Int32 nX, sal_Int32 nY) override
virtual void SAL_CALL addPaintListener(const css::uno::Reference< css::awt::XPaintListener > &xListener) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Reference< XModel > xModel
virtual sal_Bool SAL_CALL isTransparent() override
const char sServiceName[]
css::uno::WeakReferenceHelper xDelegator
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
get implementation id This ID is necessary for UNO-caching.
virtual void SAL_CALL setDelegator(const css::uno::Reference< css::uno::XInterface > &xDelegator) override
AnyEventRef aEvent
virtual void SAL_CALL release() override
decrement refcount XInterface acquire() A RuntimeException is thrown.
virtual void SAL_CALL windowHidden(const css::lang::EventObject &aEvent) override
const css::uno::Reference< css::awt::XWindow > & impl_getPeerWindow() const
css::uno::Reference< css::uno::XInterface > m_xContext
virtual void SAL_CALL removeWindowListener(const css::uno::Reference< css::awt::XWindowListener > &xListener) override