1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #ifndef _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
30 #define _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
32 /** === begin UNO includes === **/
33 #include <com/sun/star/inspection/XPropertyControl.hpp>
34 #include <com/sun/star/lang/DisposedException.hpp>
35 /** === end UNO includes === **/
36 #include <cppuhelper/compbase1.hxx>
37 #include <comphelper/broadcasthelper.hxx>
38 #include <tools/link.hxx>
39 #include <vcl/window.hxx>
42 //............................................................................
45 //............................................................................
48 //========================================================================
50 //========================================================================
51 template< class WINDOW
>
52 class ControlWindow
: public WINDOW
55 typedef WINDOW WindowType
;
58 ControlHelper
* m_pHelper
;
61 ControlWindow( Window
* _pParent
, WinBits _nStyle
)
62 :WindowType( _pParent
, _nStyle
)
67 /// sets a ControlHelper instance which some functionality is delegated to
68 inline virtual void setControlHelper( ControlHelper
& _rControlHelper
);
71 // Window overridables
72 inline virtual long PreNotify( NotifyEvent
& rNEvt
);
75 //========================================================================
77 //========================================================================
78 class SAL_NO_VTABLE IModifyListener
81 virtual void modified() = 0;
84 //========================================================================
86 //========================================================================
87 /** A helper class for implementing the <type scope="com::sun::star::inspection">XPropertyControl</type>
88 or one of its derived interfaces.
90 This class is intended to be held as member of another class which implements the
91 <type scope="com::sun::star::inspection">XPropertyControl</type> interface. The pointer
92 to this interface is to be passed to the ctor.
97 Window
* m_pControlWindow
;
98 sal_Int16 m_nControlType
;
99 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>
101 ::com::sun::star::inspection::XPropertyControl
&
103 IModifyListener
* m_pModifyListener
;
104 sal_Bool m_bModified
;
107 /** creates the instance
108 @param _rControlWindow
109 the window which is associated with the <type scope="com::sun::star::inspection">XPropertyControl</type>.
110 Must not be <NULL/>.<br/>
111 Ownership for this window is taken by the ControlHelper - it will be deleted in <member>disposing</member>.
113 the type of the control - one of the <type scope="com::sun::star::inspection">PropertyControlType</type>
116 Reference to the instance as whose "impl-class" we act. This reference is held during lifetime
117 of the <type>ControlHelper</type> class, within acquiring it. Thus, the owner of the
118 <type>ControlHelper</type> is responsible for assuring the lifetime of the instance
119 pointed to by <arg>_pAntiImpl</arg>.
120 @param _pModifyListener
121 a listener to be modfied when the user modified the control's value. the
122 <member>IModifyListener::modified</member> of this listener is called from within our
123 ModifiedHdl. A default implementation of <member>IModifyListener::modified</member>
124 would just call our <member>setModified</member>.
127 Window
* _pControlWindow
,
128 sal_Int16 _nControlType
,
129 ::com::sun::star::inspection::XPropertyControl
& _rAntiImpl
,
130 IModifyListener
* _pModifyListener
);
132 virtual ~ControlHelper();
134 /** sets our "modified" flag to <TRUE/>
136 inline void setModified() { m_bModified
= sal_True
; }
137 inline Window
* getVclControlWindow() { return m_pControlWindow
; }
138 inline const Window
* getVclControlWindow() const { return m_pControlWindow
; }
142 ::sal_Int16 SAL_CALL
getControlType() throw (::com::sun::star::uno::RuntimeException
);
143 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
> SAL_CALL
getControlContext() throw (::com::sun::star::uno::RuntimeException
);
144 void SAL_CALL
setControlContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>& _controlcontext
) throw (::com::sun::star::uno::RuntimeException
);
145 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
getControlWindow() throw (::com::sun::star::uno::RuntimeException
);
146 ::sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
);
147 void SAL_CALL
notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
);
150 virtual void SAL_CALL
dispose();
152 /** (fail-safe) wrapper around calling our context's activateNextControl
154 inline void activateNextControl() const { impl_activateNextControl_nothrow(); }
157 /// may be used to implement the default handling in PreNotify; returns sal_True if handled
158 bool handlePreNotify(NotifyEvent
& _rNEvt
);
160 /// automatically size the window given in the ctor
161 void autoSizeWindow();
163 /// may be used by derived classes, they forward the event to the PropCtrListener
164 DECL_LINK( ModifiedHdl
, Window
* );
165 DECL_LINK( GetFocusHdl
, Window
* );
166 DECL_LINK( LoseFocusHdl
, Window
* );
169 /** fail-safe wrapper around calling our context's activateNextControl
171 void impl_activateNextControl_nothrow() const;
174 //========================================================================
175 //= CommonBehaviourControl
176 //========================================================================
177 /** implements a base class for <type scope="com::sun::star::inspection">XPropertyControl</type>
178 implementations, which delegates the generic functionality of this interface to a
179 <type>ControlHelper</type> member.
181 @param CONTROL_INTERFACE
182 an interface class which is derived from (or identical to) <type scope="com::sun::star::inspection">XPropertyControl</type>
183 @param CONTROL_WINDOW
184 a class which is derived from ControlWindow
186 template < class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
187 class CommonBehaviourControl
:public ::comphelper::OBaseMutex
188 ,public ::cppu::WeakComponentImplHelper1
< CONTROL_INTERFACE
>
189 ,public IModifyListener
192 typedef CONTROL_INTERFACE InterfaceType
;
193 typedef CONTROL_WINDOW WindowType
;
195 typedef ::comphelper::OBaseMutex MutexBaseClass
;
196 typedef ::cppu::WeakComponentImplHelper1
< CONTROL_INTERFACE
> ComponentBaseClass
;
199 ControlHelper m_aImplControl
;
202 inline CommonBehaviourControl( sal_Int16 _nControlType
, Window
* _pParentWindow
, WinBits _nWindowStyle
, bool _bDoSetHandlers
= true );
204 // XPropertyControl - delegated to ->m_aImplControl
205 inline ::sal_Int16 SAL_CALL
getControlType() throw (::com::sun::star::uno::RuntimeException
);
206 inline ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
> SAL_CALL
getControlContext() throw (::com::sun::star::uno::RuntimeException
);
207 inline void SAL_CALL
setControlContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>& _controlcontext
) throw (::com::sun::star::uno::RuntimeException
);
208 inline ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
getControlWindow() throw (::com::sun::star::uno::RuntimeException
);
209 inline ::sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
);
210 inline void SAL_CALL
notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
);
213 inline virtual void SAL_CALL
disposing();
216 inline virtual void modified();
218 /// returns a typed pointer to our control window
219 WindowType
* getTypedControlWindow() { return static_cast< WindowType
* > ( m_aImplControl
.getVclControlWindow() ); }
220 const WindowType
* getTypedControlWindow() const { return static_cast< const WindowType
* >( m_aImplControl
.getVclControlWindow() ); }
223 /** checks whether the instance is already disposed
224 @throws DisposedException
225 if the instance is already disposed
227 inline void impl_checkDisposed_throw();
230 //========================================================================
231 //= ControlWindow - implementation
232 //========================================================================
233 //------------------------------------------------------------------------
234 template< class WINDOW
>
235 inline void ControlWindow
< WINDOW
>::setControlHelper( ControlHelper
& _rControlHelper
)
237 m_pHelper
= &_rControlHelper
;
240 //------------------------------------------------------------------------
241 template< class WINDOW
>
242 inline long ControlWindow
< WINDOW
>::PreNotify( NotifyEvent
& rNEvt
)
244 if ( m_pHelper
&& m_pHelper
->handlePreNotify( rNEvt
) )
246 return WindowType::PreNotify( rNEvt
);
249 //========================================================================
250 //= CommonBehaviourControl - implementation
251 //========================================================================
252 //------------------------------------------------------------------------
253 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
254 inline CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::CommonBehaviourControl ( sal_Int16 _nControlType
, Window
* _pParentWindow
, WinBits _nWindowStyle
, bool _bDoSetHandlers
)
255 :ComponentBaseClass( m_aMutex
)
256 ,m_aImplControl( new WindowType( _pParentWindow
, _nWindowStyle
), _nControlType
, *this, this )
258 WindowType
* pControlWindow( getTypedControlWindow() );
259 pControlWindow
->setControlHelper( m_aImplControl
);
260 if ( _bDoSetHandlers
)
262 pControlWindow
->SetModifyHdl( LINK( &m_aImplControl
, ControlHelper
, ModifiedHdl
) );
263 pControlWindow
->SetGetFocusHdl( LINK( &m_aImplControl
, ControlHelper
, GetFocusHdl
) );
264 pControlWindow
->SetLoseFocusHdl( LINK( &m_aImplControl
, ControlHelper
, LoseFocusHdl
) );
266 m_aImplControl
.autoSizeWindow();
269 //--------------------------------------------------------------------
270 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
271 inline ::sal_Int16 SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::getControlType() throw (::com::sun::star::uno::RuntimeException
)
273 return m_aImplControl
.getControlType();
276 //--------------------------------------------------------------------
277 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
278 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 return m_aImplControl
.getControlContext();
283 //--------------------------------------------------------------------
284 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
285 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 m_aImplControl
.setControlContext( _controlcontext
);
290 //--------------------------------------------------------------------
291 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
292 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 return m_aImplControl
.getControlWindow();
297 //--------------------------------------------------------------------
298 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
299 inline ::sal_Bool SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::isModified( ) throw (::com::sun::star::uno::RuntimeException
)
301 return m_aImplControl
.isModified();
304 //--------------------------------------------------------------------
305 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
306 inline void SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
)
308 m_aImplControl
.notifyModifiedValue();
311 //--------------------------------------------------------------------
312 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
313 inline void SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::disposing()
315 m_aImplControl
.dispose();
318 //--------------------------------------------------------------------
319 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
320 inline void CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::modified()
322 m_aImplControl
.setModified();
325 //--------------------------------------------------------------------
326 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
327 inline void CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::impl_checkDisposed_throw()
329 if ( ComponentBaseClass::rBHelper
.bDisposed
)
330 throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *this );
333 //............................................................................
335 //............................................................................
337 #endif // _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
339 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */