Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
30 : : #define _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
31 : :
32 : : #include <com/sun/star/inspection/XPropertyControl.hpp>
33 : : #include <com/sun/star/lang/DisposedException.hpp>
34 : : #include <cppuhelper/compbase1.hxx>
35 : : #include <comphelper/broadcasthelper.hxx>
36 : : #include <tools/link.hxx>
37 : : #include <vcl/window.hxx>
38 : :
39 : : class NotifyEvent;
40 : : //............................................................................
41 : : namespace pcr
42 : : {
43 : : //............................................................................
44 : :
45 : : class ControlHelper;
46 : : //========================================================================
47 : : //= ControlWindow
48 : : //========================================================================
49 : : template< class WINDOW >
50 : 0 : class ControlWindow : public WINDOW
51 : : {
52 : : protected:
53 : : typedef WINDOW WindowType;
54 : :
55 : : protected:
56 : : ControlHelper* m_pHelper;
57 : :
58 : : public:
59 : 0 : ControlWindow( Window* _pParent, WinBits _nStyle )
60 : : :WindowType( _pParent, _nStyle )
61 : 0 : ,m_pHelper( NULL )
62 : : {
63 : 0 : }
64 : :
65 : : /// sets a ControlHelper instance which some functionality is delegated to
66 : : inline virtual void setControlHelper( ControlHelper& _rControlHelper );
67 : :
68 : : protected:
69 : : // Window overridables
70 : : inline virtual long PreNotify( NotifyEvent& rNEvt );
71 : : };
72 : :
73 : : //========================================================================
74 : : //= IModifyListener
75 : : //========================================================================
76 : 0 : class SAL_NO_VTABLE IModifyListener
77 : : {
78 : : public:
79 : : virtual void modified() = 0;
80 : :
81 : : protected:
82 : 0 : ~IModifyListener() {}
83 : : };
84 : :
85 : : //========================================================================
86 : : //= ControlHelper
87 : : //========================================================================
88 : : /** A helper class for implementing the <type scope="com::sun::star::inspection">XPropertyControl</type>
89 : : or one of its derived interfaces.
90 : :
91 : : This class is intended to be held as member of another class which implements the
92 : : <type scope="com::sun::star::inspection">XPropertyControl</type> interface. The pointer
93 : : to this interface is to be passed to the ctor.
94 : : */
95 : : class ControlHelper
96 : : {
97 : : private:
98 : : Window* m_pControlWindow;
99 : : sal_Int16 m_nControlType;
100 : : ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >
101 : : m_xContext;
102 : : ::com::sun::star::inspection::XPropertyControl&
103 : : m_rAntiImpl;
104 : : IModifyListener* m_pModifyListener;
105 : : sal_Bool m_bModified;
106 : :
107 : : public:
108 : : /** creates the instance
109 : : @param _rControlWindow
110 : : the window which is associated with the <type scope="com::sun::star::inspection">XPropertyControl</type>.
111 : : Must not be <NULL/>.<br/>
112 : : Ownership for this window is taken by the ControlHelper - it will be deleted in <member>disposing</member>.
113 : : @param _nControlType
114 : : the type of the control - one of the <type scope="com::sun::star::inspection">PropertyControlType</type>
115 : : constants
116 : : @param _pAntiImpl
117 : : Reference to the instance as whose "impl-class" we act. This reference is held during lifetime
118 : : of the <type>ControlHelper</type> class, within acquiring it. Thus, the owner of the
119 : : <type>ControlHelper</type> is responsible for assuring the lifetime of the instance
120 : : pointed to by <arg>_pAntiImpl</arg>.
121 : : @param _pModifyListener
122 : : a listener to be modfied when the user modified the control's value. the
123 : : <member>IModifyListener::modified</member> of this listener is called from within our
124 : : ModifiedHdl. A default implementation of <member>IModifyListener::modified</member>
125 : : would just call our <member>setModified</member>.
126 : : */
127 : : ControlHelper(
128 : : Window* _pControlWindow,
129 : : sal_Int16 _nControlType,
130 : : ::com::sun::star::inspection::XPropertyControl& _rAntiImpl,
131 : : IModifyListener* _pModifyListener );
132 : :
133 : : virtual ~ControlHelper();
134 : :
135 : : /** sets our "modified" flag to <TRUE/>
136 : : */
137 : 0 : inline void setModified() { m_bModified = sal_True; }
138 : 0 : inline Window* getVclControlWindow() { return m_pControlWindow; }
139 : 0 : inline const Window* getVclControlWindow() const { return m_pControlWindow; }
140 : :
141 : : public:
142 : : // XPropertyControl
143 : : ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException);
144 : : ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL getControlContext() throw (::com::sun::star::uno::RuntimeException);
145 : : void SAL_CALL setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException);
146 : : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getControlWindow() throw (::com::sun::star::uno::RuntimeException);
147 : : ::sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException);
148 : : void SAL_CALL notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException);
149 : :
150 : : // XComponent
151 : : virtual void SAL_CALL dispose();
152 : :
153 : : /** (fail-safe) wrapper around calling our context's activateNextControl
154 : : */
155 : 0 : inline void activateNextControl() const { impl_activateNextControl_nothrow(); }
156 : :
157 : : public:
158 : : /// may be used to implement the default handling in PreNotify; returns sal_True if handled
159 : : bool handlePreNotify(NotifyEvent& _rNEvt);
160 : :
161 : : /// automatically size the window given in the ctor
162 : : void autoSizeWindow();
163 : :
164 : : /// may be used by derived classes, they forward the event to the PropCtrListener
165 : : DECL_LINK( ModifiedHdl, Window* );
166 : : DECL_LINK( GetFocusHdl, Window* );
167 : : DECL_LINK( LoseFocusHdl, Window* );
168 : :
169 : : private:
170 : : /** fail-safe wrapper around calling our context's activateNextControl
171 : : */
172 : : void impl_activateNextControl_nothrow() const;
173 : : };
174 : :
175 : : //========================================================================
176 : : //= CommonBehaviourControl
177 : : //========================================================================
178 : : /** implements a base class for <type scope="com::sun::star::inspection">XPropertyControl</type>
179 : : implementations, which delegates the generic functionality of this interface to a
180 : : <type>ControlHelper</type> member.
181 : :
182 : : @param CONTROL_INTERFACE
183 : : an interface class which is derived from (or identical to) <type scope="com::sun::star::inspection">XPropertyControl</type>
184 : : @param CONTROL_WINDOW
185 : : a class which is derived from ControlWindow
186 : : */
187 : : template < class CONTROL_INTERFACE, class CONTROL_WINDOW >
188 : 0 : class CommonBehaviourControl :public ::comphelper::OBaseMutex
189 : : ,public ::cppu::WeakComponentImplHelper1< CONTROL_INTERFACE >
190 : : ,public IModifyListener
191 : : {
192 : : protected:
193 : : typedef CONTROL_INTERFACE InterfaceType;
194 : : typedef CONTROL_WINDOW WindowType;
195 : :
196 : : typedef ::comphelper::OBaseMutex MutexBaseClass;
197 : : typedef ::cppu::WeakComponentImplHelper1< CONTROL_INTERFACE > ComponentBaseClass;
198 : :
199 : : protected:
200 : : ControlHelper m_aImplControl;
201 : :
202 : : protected:
203 : : inline CommonBehaviourControl( sal_Int16 _nControlType, Window* _pParentWindow, WinBits _nWindowStyle, bool _bDoSetHandlers = true );
204 : :
205 : : // XPropertyControl - delegated to ->m_aImplControl
206 : : inline ::sal_Int16 SAL_CALL getControlType() throw (::com::sun::star::uno::RuntimeException);
207 : : inline ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL getControlContext() throw (::com::sun::star::uno::RuntimeException);
208 : : inline void SAL_CALL setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException);
209 : : inline ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL getControlWindow() throw (::com::sun::star::uno::RuntimeException);
210 : : inline ::sal_Bool SAL_CALL isModified( ) throw (::com::sun::star::uno::RuntimeException);
211 : : inline void SAL_CALL notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException);
212 : :
213 : : // XComponent
214 : : inline virtual void SAL_CALL disposing();
215 : :
216 : : // IModifyListener
217 : : inline virtual void modified();
218 : :
219 : : /// returns a typed pointer to our control window
220 : 0 : WindowType* getTypedControlWindow() { return static_cast< WindowType* > ( m_aImplControl.getVclControlWindow() ); }
221 : 0 : const WindowType* getTypedControlWindow() const { return static_cast< const WindowType* >( m_aImplControl.getVclControlWindow() ); }
222 : :
223 : : protected:
224 : : /** checks whether the instance is already disposed
225 : : @throws DisposedException
226 : : if the instance is already disposed
227 : : */
228 : : inline void impl_checkDisposed_throw();
229 : : };
230 : :
231 : : //========================================================================
232 : : //= ControlWindow - implementation
233 : : //========================================================================
234 : : //------------------------------------------------------------------------
235 : : template< class WINDOW >
236 : 0 : inline void ControlWindow< WINDOW >::setControlHelper( ControlHelper& _rControlHelper )
237 : : {
238 : 0 : m_pHelper = &_rControlHelper;
239 : 0 : }
240 : :
241 : : //------------------------------------------------------------------------
242 : : template< class WINDOW >
243 : 0 : inline long ControlWindow< WINDOW >::PreNotify( NotifyEvent& rNEvt )
244 : : {
245 : 0 : if ( m_pHelper && m_pHelper->handlePreNotify( rNEvt ) )
246 : 0 : return 1;
247 : 0 : return WindowType::PreNotify( rNEvt );
248 : : }
249 : :
250 : : //========================================================================
251 : : //= CommonBehaviourControl - implementation
252 : : //========================================================================
253 : : //------------------------------------------------------------------------
254 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
255 : 0 : inline CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::CommonBehaviourControl ( sal_Int16 _nControlType, Window* _pParentWindow, WinBits _nWindowStyle, bool _bDoSetHandlers )
256 : : :ComponentBaseClass( m_aMutex )
257 : 0 : ,m_aImplControl( new WindowType( _pParentWindow, _nWindowStyle ), _nControlType, *this, this )
258 : : {
259 : 0 : WindowType* pControlWindow( getTypedControlWindow() );
260 : 0 : pControlWindow->setControlHelper( m_aImplControl );
261 : 0 : if ( _bDoSetHandlers )
262 : : {
263 : 0 : pControlWindow->SetModifyHdl( LINK( &m_aImplControl, ControlHelper, ModifiedHdl ) );
264 : 0 : pControlWindow->SetGetFocusHdl( LINK( &m_aImplControl, ControlHelper, GetFocusHdl ) );
265 : 0 : pControlWindow->SetLoseFocusHdl( LINK( &m_aImplControl, ControlHelper, LoseFocusHdl ) );
266 : : }
267 : 0 : m_aImplControl.autoSizeWindow();
268 : 0 : }
269 : :
270 : : //--------------------------------------------------------------------
271 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
272 : 0 : inline ::sal_Int16 SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlType() throw (::com::sun::star::uno::RuntimeException)
273 : : {
274 : 0 : return m_aImplControl.getControlType();
275 : : }
276 : :
277 : : //--------------------------------------------------------------------
278 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
279 : 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext > SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlContext() throw (::com::sun::star::uno::RuntimeException)
280 : : {
281 : 0 : return m_aImplControl.getControlContext();
282 : : }
283 : :
284 : : //--------------------------------------------------------------------
285 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
286 : 0 : inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::setControlContext( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControlContext >& _controlcontext ) throw (::com::sun::star::uno::RuntimeException)
287 : : {
288 : 0 : m_aImplControl.setControlContext( _controlcontext );
289 : 0 : }
290 : :
291 : : //--------------------------------------------------------------------
292 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
293 : 0 : inline ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::getControlWindow() throw (::com::sun::star::uno::RuntimeException)
294 : : {
295 : 0 : return m_aImplControl.getControlWindow();
296 : : }
297 : :
298 : : //--------------------------------------------------------------------
299 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
300 : 0 : inline ::sal_Bool SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::isModified( ) throw (::com::sun::star::uno::RuntimeException)
301 : : {
302 : 0 : return m_aImplControl.isModified();
303 : : }
304 : :
305 : : //--------------------------------------------------------------------
306 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
307 : 0 : inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException)
308 : : {
309 : 0 : m_aImplControl.notifyModifiedValue();
310 : 0 : }
311 : :
312 : : //--------------------------------------------------------------------
313 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
314 : 0 : inline void SAL_CALL CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::disposing()
315 : : {
316 : 0 : m_aImplControl.dispose();
317 : 0 : }
318 : :
319 : : //--------------------------------------------------------------------
320 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
321 : 0 : inline void CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::modified()
322 : : {
323 : 0 : m_aImplControl.setModified();
324 : 0 : }
325 : :
326 : : //--------------------------------------------------------------------
327 : : template< class CONTROL_INTERFACE, class CONTROL_WINDOW >
328 : 0 : inline void CommonBehaviourControl< CONTROL_INTERFACE, CONTROL_WINDOW >::impl_checkDisposed_throw()
329 : : {
330 : 0 : if ( ComponentBaseClass::rBHelper.bDisposed )
331 : 0 : throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *this );
332 : 0 : }
333 : :
334 : : //............................................................................
335 : : } // namespace pcr
336 : : //............................................................................
337 : :
338 : : #endif // _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
339 : :
340 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|