1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _UNOCONTROLS_BASECONTROL_CTRL_HXX
21 #define _UNOCONTROLS_BASECONTROL_CTRL_HXX
23 #include <com/sun/star/awt/XKeyListener.hpp>
24 #include <com/sun/star/awt/XPaintListener.hpp>
25 #include <com/sun/star/awt/KeyEvent.hpp>
26 #include <com/sun/star/awt/KeyModifier.hpp>
27 #include <com/sun/star/awt/XMouseMotionListener.hpp>
28 #include <com/sun/star/awt/FocusEvent.hpp>
29 #include <com/sun/star/awt/XWindowListener.hpp>
30 #include <com/sun/star/awt/XActivateListener.hpp>
31 #include <com/sun/star/awt/MouseEvent.hpp>
32 #include <com/sun/star/awt/XTopWindowListener.hpp>
33 #include <com/sun/star/awt/PaintEvent.hpp>
34 #include <com/sun/star/awt/InputEvent.hpp>
35 #include <com/sun/star/awt/KeyGroup.hpp>
36 #include <com/sun/star/awt/Key.hpp>
37 #include <com/sun/star/awt/WindowEvent.hpp>
38 #include <com/sun/star/awt/XMouseListener.hpp>
39 #include <com/sun/star/awt/KeyFunction.hpp>
40 #include <com/sun/star/awt/FocusChangeReason.hpp>
41 #include <com/sun/star/awt/MouseButton.hpp>
42 #include <com/sun/star/awt/XFocusListener.hpp>
43 #include <com/sun/star/awt/XFileDialog.hpp>
44 #include <com/sun/star/awt/XTextComponent.hpp>
45 #include <com/sun/star/awt/XListBox.hpp>
46 #include <com/sun/star/awt/XProgressMonitor.hpp>
47 #include <com/sun/star/awt/TextAlign.hpp>
48 #include <com/sun/star/awt/XScrollBar.hpp>
49 #include <com/sun/star/awt/XVclContainerPeer.hpp>
50 #include <com/sun/star/awt/XTabControllerModel.hpp>
51 #include <com/sun/star/awt/XMessageBox.hpp>
52 #include <com/sun/star/awt/XTextEditField.hpp>
53 #include <com/sun/star/awt/Style.hpp>
54 #include <com/sun/star/awt/XTimeField.hpp>
55 #include <com/sun/star/awt/XVclWindowPeer.hpp>
56 #include <com/sun/star/awt/XControlModel.hpp>
57 #include <com/sun/star/awt/XSpinField.hpp>
58 #include <com/sun/star/awt/XUnoControlContainer.hpp>
59 #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
60 #include <com/sun/star/awt/XNumericField.hpp>
61 #include <com/sun/star/awt/XButton.hpp>
62 #include <com/sun/star/awt/XTextArea.hpp>
63 #include <com/sun/star/awt/XImageButton.hpp>
64 #include <com/sun/star/awt/XFixedText.hpp>
65 #include <com/sun/star/awt/XControlContainer.hpp>
66 #include <com/sun/star/awt/XDialog.hpp>
67 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
68 #include <com/sun/star/awt/XRadioButton.hpp>
69 #include <com/sun/star/awt/XCurrencyField.hpp>
70 #include <com/sun/star/awt/XPatternField.hpp>
71 #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
72 #include <com/sun/star/awt/XTabController.hpp>
73 #include <com/sun/star/awt/XVclContainer.hpp>
74 #include <com/sun/star/awt/XDateField.hpp>
75 #include <com/sun/star/awt/XComboBox.hpp>
76 #include <com/sun/star/awt/XControl.hpp>
77 #include <com/sun/star/awt/XCheckBox.hpp>
78 #include <com/sun/star/awt/MessageBoxCommand.hpp>
79 #include <com/sun/star/awt/XLayoutConstrains.hpp>
80 #include <com/sun/star/awt/XProgressBar.hpp>
81 #include <com/sun/star/awt/XTopWindow.hpp>
82 #include <com/sun/star/awt/XWindow.hpp>
83 #include <com/sun/star/awt/PosSize.hpp>
84 #include <com/sun/star/awt/XView.hpp>
85 #include <com/sun/star/lang/XServiceInfo.hpp>
86 #include <osl/mutex.hxx>
87 #include <cppuhelper/weak.hxx>
88 #include <cppuhelper/component.hxx>
90 #include "multiplexer.hxx"
92 //____________________________________________________________________________________________________________
94 //____________________________________________________________________________________________________________
96 namespace unocontrols
{
98 //____________________________________________________________________________________________________________
100 //____________________________________________________________________________________________________________
102 #define TRGB_COLORDATA(TRANSPARENCE,RED,GREEN,BLUE) \
103 ((sal_Int32)(((sal_uInt32)((sal_uInt8)(BLUE))))|(((sal_uInt32)((sal_uInt8)(GREEN)))<<8)|(((sal_uInt32)((sal_uInt8)(RED)))<<16)|(((sal_uInt32)((sal_uInt8)(TRANSPARENCE)))<<24))
105 //____________________________________________________________________________________________________________
107 //____________________________________________________________________________________________________________
109 struct IMPL_MutexContainer
111 // Is necassery to initialize "BaseControl" and make this class thread-safe.
112 ::osl::Mutex m_aMutex
;
115 class BaseControl
: public ::com::sun::star::lang::XServiceInfo
116 , public ::com::sun::star::awt::XPaintListener
117 , public ::com::sun::star::awt::XWindowListener
118 , public ::com::sun::star::awt::XView
119 , public ::com::sun::star::awt::XWindow
120 , public ::com::sun::star::awt::XControl
121 , public IMPL_MutexContainer
122 , public ::cppu::OComponentHelper
124 //____________________________________________________________________________________________________________
126 //____________________________________________________________________________________________________________
130 //________________________________________________________________________________________________________
131 // construct/destruct
132 //________________________________________________________________________________________________________
134 /**_______________________________________________________________________________________________________
147 BaseControl( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
);
149 /**_______________________________________________________________________________________________________
162 virtual ~BaseControl();
164 //________________________________________________________________________________________________________
166 //________________________________________________________________________________________________________
168 /**_______________________________________________________________________________________________________
169 @short give answer, if interface is supported
170 @descr The interfaces are searched by type.
174 @param "rType" is the type of searched interface.
176 @return Any information about found interface
178 @onerror A RuntimeException is thrown.
181 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(
182 const ::com::sun::star::uno::Type
& aType
183 ) throw( ::com::sun::star::uno::RuntimeException
);
185 /**_______________________________________________________________________________________________________
186 @short increment refcount
196 @onerror A RuntimeException is thrown.
199 virtual void SAL_CALL
acquire() throw();
201 /**_______________________________________________________________________________________________________
202 @short decrement refcount
212 @onerror A RuntimeException is thrown.
215 virtual void SAL_CALL
release() throw();
217 //________________________________________________________________________________________________________
219 //________________________________________________________________________________________________________
221 /**_______________________________________________________________________________________________________
222 @short get information about supported interfaces
225 @seealso XTypeProvider
229 @return Sequence of types of all supported interfaces
231 @onerror A RuntimeException is thrown.
234 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes()
235 throw( ::com::sun::star::uno::RuntimeException
);
237 /**_______________________________________________________________________________________________________
238 @short get implementation id
239 @descr This ID is neccessary for UNO-caching. If there no ID, cache is disabled.
240 Another way, cache is enabled.
242 @seealso XTypeProvider
246 @return ID as Sequence of byte
248 @onerror A RuntimeException is thrown.
251 virtual ::com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId()
252 throw( ::com::sun::star::uno::RuntimeException
);
254 //________________________________________________________________________________________________________
256 //________________________________________________________________________________________________________
258 /**_______________________________________________________________________________________________________
271 virtual void SAL_CALL
setDelegator(
272 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xDelegator
273 ) throw( ::com::sun::star::uno::RuntimeException
);
275 /**_______________________________________________________________________________________________________
288 virtual ::com::sun::star::uno::Any SAL_CALL
queryAggregation(
289 const ::com::sun::star::uno::Type
& aType
290 ) throw( ::com::sun::star::uno::RuntimeException
);
292 //________________________________________________________________________________________________________
294 //________________________________________________________________________________________________________
296 /**_______________________________________________________________________________________________________
309 virtual sal_Bool SAL_CALL
supportsService(
310 const OUString
& sServiceName
311 ) throw( ::com::sun::star::uno::RuntimeException
);
313 /**_______________________________________________________________________________________________________
326 virtual OUString SAL_CALL
getImplementationName()
327 throw( ::com::sun::star::uno::RuntimeException
);
329 /**_______________________________________________________________________________________________________
342 virtual ::com::sun::star::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames()
343 throw( ::com::sun::star::uno::RuntimeException
);
345 //________________________________________________________________________________________________________
347 //________________________________________________________________________________________________________
349 /**_______________________________________________________________________________________________________
362 virtual void SAL_CALL
dispose() throw( ::com::sun::star::uno::RuntimeException
);
364 /**_______________________________________________________________________________________________________
377 virtual void SAL_CALL
addEventListener(
378 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
379 ) throw( ::com::sun::star::uno::RuntimeException
);
381 /**_______________________________________________________________________________________________________
394 virtual void SAL_CALL
removeEventListener(
395 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
396 ) throw( ::com::sun::star::uno::RuntimeException
);
398 //________________________________________________________________________________________________________
400 //________________________________________________________________________________________________________
402 /**_______________________________________________________________________________________________________
415 virtual void SAL_CALL
createPeer(
416 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XToolkit
>& xToolkit
,
417 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& xParent
418 ) throw( ::com::sun::star::uno::RuntimeException
);
420 /**_______________________________________________________________________________________________________
433 virtual void SAL_CALL
setContext(
434 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& xContext
435 ) throw( ::com::sun::star::uno::RuntimeException
);
437 /**_______________________________________________________________________________________________________
450 virtual sal_Bool SAL_CALL
setModel(
451 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
>& xModel
452 ) throw( ::com::sun::star::uno::RuntimeException
) = 0 ;
454 /**_______________________________________________________________________________________________________
467 virtual void SAL_CALL
setDesignMode( sal_Bool bOn
) throw( ::com::sun::star::uno::RuntimeException
);
469 /**_______________________________________________________________________________________________________
482 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
getContext()
483 throw( ::com::sun::star::uno::RuntimeException
);
485 /**_______________________________________________________________________________________________________
498 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XControlModel
> SAL_CALL
getModel()
499 throw( ::com::sun::star::uno::RuntimeException
) = 0;
501 /**_______________________________________________________________________________________________________
514 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> SAL_CALL
getPeer()
515 throw( ::com::sun::star::uno::RuntimeException
);
517 /**_______________________________________________________________________________________________________
530 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XView
> SAL_CALL
getView()
531 throw( ::com::sun::star::uno::RuntimeException
);
533 /**_______________________________________________________________________________________________________
546 virtual sal_Bool SAL_CALL
isDesignMode() throw( ::com::sun::star::uno::RuntimeException
);
548 /**_______________________________________________________________________________________________________
561 virtual sal_Bool SAL_CALL
isTransparent() throw( ::com::sun::star::uno::RuntimeException
);
563 //________________________________________________________________________________________________________
565 //________________________________________________________________________________________________________
567 /**_______________________________________________________________________________________________________
580 virtual void SAL_CALL
setPosSize( sal_Int32 nX
,
584 sal_Int16 nFlags
) throw( ::com::sun::star::uno::RuntimeException
);
586 /**_______________________________________________________________________________________________________
599 virtual void SAL_CALL
setVisible( sal_Bool bVisible
) throw( ::com::sun::star::uno::RuntimeException
);
601 /**_______________________________________________________________________________________________________
614 virtual void SAL_CALL
setEnable( sal_Bool bEnable
) throw( ::com::sun::star::uno::RuntimeException
);
616 /**_______________________________________________________________________________________________________
629 virtual void SAL_CALL
setFocus() throw( ::com::sun::star::uno::RuntimeException
);
631 /**_______________________________________________________________________________________________________
644 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getPosSize() throw( ::com::sun::star::uno::RuntimeException
);
646 /**_______________________________________________________________________________________________________
659 virtual void SAL_CALL
addWindowListener(
660 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowListener
>& xListener
661 ) throw( ::com::sun::star::uno::RuntimeException
);
663 /**_______________________________________________________________________________________________________
676 virtual void SAL_CALL
addFocusListener(
677 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFocusListener
>& xListener
678 ) throw( ::com::sun::star::uno::RuntimeException
);
680 /**_______________________________________________________________________________________________________
693 virtual void SAL_CALL
addKeyListener(
694 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XKeyListener
>& xListener
)
695 throw( ::com::sun::star::uno::RuntimeException
);
697 /**_______________________________________________________________________________________________________
710 virtual void SAL_CALL
addMouseListener(
711 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMouseListener
>& xListener
712 ) throw( ::com::sun::star::uno::RuntimeException
);
714 /**_______________________________________________________________________________________________________
727 virtual void SAL_CALL
addMouseMotionListener(
728 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMouseMotionListener
>& xListener
729 ) throw( ::com::sun::star::uno::RuntimeException
);
731 /**_______________________________________________________________________________________________________
744 virtual void SAL_CALL
addPaintListener(
745 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPaintListener
>& xListener
746 ) throw( ::com::sun::star::uno::RuntimeException
);
748 /**_______________________________________________________________________________________________________
761 virtual void SAL_CALL
removeWindowListener(
762 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowListener
>& xListener
763 ) throw( ::com::sun::star::uno::RuntimeException
);
765 /**_______________________________________________________________________________________________________
778 virtual void SAL_CALL
removeFocusListener(
779 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XFocusListener
>& xListener
780 ) throw( ::com::sun::star::uno::RuntimeException
);
782 /**_______________________________________________________________________________________________________
795 virtual void SAL_CALL
removeKeyListener(
796 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XKeyListener
>& xListener
797 ) throw( ::com::sun::star::uno::RuntimeException
);
799 /**_______________________________________________________________________________________________________
812 virtual void SAL_CALL
removeMouseListener(
813 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMouseListener
>& xListener
814 ) throw( ::com::sun::star::uno::RuntimeException
);
816 /**_______________________________________________________________________________________________________
829 virtual void SAL_CALL
removeMouseMotionListener(
830 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XMouseMotionListener
>& xListener
831 ) throw( ::com::sun::star::uno::RuntimeException
);
833 /**_______________________________________________________________________________________________________
846 virtual void SAL_CALL
removePaintListener(
847 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XPaintListener
>& xListener
848 ) throw( ::com::sun::star::uno::RuntimeException
);
850 //________________________________________________________________________________________________________
852 //________________________________________________________________________________________________________
854 /**_______________________________________________________________________________________________________
867 virtual void SAL_CALL
draw( sal_Int32 nX
,
868 sal_Int32 nY
) throw( ::com::sun::star::uno::RuntimeException
);
870 /**_______________________________________________________________________________________________________
883 virtual sal_Bool SAL_CALL
setGraphics(
884 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
>& xDevice
885 ) throw( ::com::sun::star::uno::RuntimeException
);
887 /**_______________________________________________________________________________________________________
900 virtual void SAL_CALL
setZoom( float fZoomX
,
901 float fZoomY
) throw( ::com::sun::star::uno::RuntimeException
);
903 /**_______________________________________________________________________________________________________
916 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> SAL_CALL
getGraphics()
917 throw( ::com::sun::star::uno::RuntimeException
);
919 /**_______________________________________________________________________________________________________
932 virtual ::com::sun::star::awt::Size SAL_CALL
getSize() throw( ::com::sun::star::uno::RuntimeException
);
934 //________________________________________________________________________________________________________
935 // ::com::sun::star::lang::XEventListener
936 //________________________________________________________________________________________________________
938 /**_______________________________________________________________________________________________________
951 virtual void SAL_CALL
disposing(
952 const ::com::sun::star::lang::EventObject
& rSource
953 ) throw( ::com::sun::star::uno::RuntimeException
);
955 //________________________________________________________________________________________________________
957 //________________________________________________________________________________________________________
959 /**_______________________________________________________________________________________________________
972 virtual void SAL_CALL
windowPaint(
973 const ::com::sun::star::awt::PaintEvent
& rEvent
974 ) throw( ::com::sun::star::uno::RuntimeException
);
976 //________________________________________________________________________________________________________
978 //________________________________________________________________________________________________________
980 /**_______________________________________________________________________________________________________
993 virtual void SAL_CALL
windowResized( const ::com::sun::star::awt::WindowEvent
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
994 virtual void SAL_CALL
windowMoved( const ::com::sun::star::awt::WindowEvent
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
995 virtual void SAL_CALL
windowShown( const ::com::sun::star::lang::EventObject
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
996 virtual void SAL_CALL
windowHidden( const ::com::sun::star::lang::EventObject
& aEvent
) throw( ::com::sun::star::uno::RuntimeException
);
998 //________________________________________________________________________________________________________
999 // impl but public method to register service
1000 //________________________________________________________________________________________________________
1002 /**_______________________________________________________________________________________________________
1015 static const ::com::sun::star::uno::Sequence
< OUString
> impl_getStaticSupportedServiceNames();
1017 /**_______________________________________________________________________________________________________
1030 static const OUString
impl_getStaticImplementationName();
1032 //____________________________________________________________________________________________________________
1033 // protected methods
1034 //____________________________________________________________________________________________________________
1037 using OComponentHelper::disposing
;
1039 /**_______________________________________________________________________________________________________
1052 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> impl_getComponentContext();
1054 /**_______________________________________________________________________________________________________
1067 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> impl_getPeerWindow();
1069 /**_______________________________________________________________________________________________________
1082 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> impl_getGraphicsPeer();
1084 /**_______________________________________________________________________________________________________
1097 const sal_Int32
& impl_getWidth();
1099 /**_______________________________________________________________________________________________________
1112 const sal_Int32
& impl_getHeight();
1114 /**_______________________________________________________________________________________________________
1127 virtual ::com::sun::star::awt::WindowDescriptor
* impl_getWindowDescriptor(
1128 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>& xParentPeer
1131 /**_______________________________________________________________________________________________________
1144 virtual void impl_paint( sal_Int32 nX
,
1146 const ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
>& xGraphics
);
1148 /**_______________________________________________________________________________________________________
1161 virtual void impl_recalcLayout( const ::com::sun::star::awt::WindowEvent
& aEvent
);
1163 /**_______________________________________________________________________________________________________
1176 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> impl_getDelegator();
1178 //____________________________________________________________________________________________________________
1180 //____________________________________________________________________________________________________________
1184 /**_______________________________________________________________________________________________________
1197 void impl_releasePeer();
1199 /**_______________________________________________________________________________________________________
1212 OMRCListenerMultiplexerHelper
* impl_getMultiplexer();
1214 //____________________________________________________________________________________________________________
1215 // private variables
1216 //____________________________________________________________________________________________________________
1220 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xComponentContext
;
1221 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xDelegator
;
1222 OMRCListenerMultiplexerHelper
* m_pMultiplexer
; // multiplex events
1223 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xMultiplexer
;
1224 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> m_xContext
;
1225 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
> m_xPeer
;
1226 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> m_xPeerWindow
;
1227 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> m_xGraphicsView
; // graphics for ::com::sun::star::awt::XView-operations
1228 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XGraphics
> m_xGraphicsPeer
; // graphics for painting on a peer
1229 sal_Int32 m_nX
; // Position ...
1231 sal_Int32 m_nWidth
; // ... and size of window
1232 sal_Int32 m_nHeight
;
1233 sal_Bool m_bVisible
; // Some state flags
1234 sal_Bool m_bInDesignMode
;
1235 sal_Bool m_bEnable
;
1237 }; // class BaseControl
1239 } // namespace unocontrols
1241 #endif // ifndef _UNOCONTROLS_BASECONTROL_CTRL_HXX
1243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */