1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
29 #define _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_
31 /** === begin UNO includes === **/
32 #include <com/sun/star/inspection/XPropertyControl.hpp>
33 #include <com/sun/star/lang/DisposedException.hpp>
34 /** === end UNO includes === **/
35 #include <cppuhelper/compbase1.hxx>
36 #include <comphelper/broadcasthelper.hxx>
37 #include <tools/link.hxx>
38 #include <vcl/window.hxx>
41 //............................................................................
44 //............................................................................
47 //========================================================================
49 //========================================================================
50 template< class WINDOW
>
51 class ControlWindow
: public WINDOW
54 typedef WINDOW WindowType
;
57 ControlHelper
* m_pHelper
;
60 ControlWindow( Window
* _pParent
, WinBits _nStyle
)
61 :WindowType( _pParent
, _nStyle
)
66 /// sets a ControlHelper instance which some functionality is delegated to
67 inline virtual void setControlHelper( ControlHelper
& _rControlHelper
);
70 // Window overridables
71 inline virtual long PreNotify( NotifyEvent
& rNEvt
);
74 //========================================================================
76 //========================================================================
77 class SAL_NO_VTABLE IModifyListener
80 virtual void modified() = 0;
83 //========================================================================
85 //========================================================================
86 /** A helper class for implementing the <type scope="com::sun::star::inspection">XPropertyControl</type>
87 or one of its derived interfaces.
89 This class is intended to be held as member of another class which implements the
90 <type scope="com::sun::star::inspection">XPropertyControl</type> interface. The pointer
91 to this interface is to be passed to the ctor.
96 Window
* m_pControlWindow
;
97 sal_Int16 m_nControlType
;
98 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>
100 ::com::sun::star::inspection::XPropertyControl
&
102 IModifyListener
* m_pModifyListener
;
103 sal_Bool m_bModified
;
106 /** creates the instance
107 @param _rControlWindow
108 the window which is associated with the <type scope="com::sun::star::inspection">XPropertyControl</type>.
109 Must not be <NULL/>.<br/>
110 Ownership for this window is taken by the ControlHelper - it will be deleted in <member>disposing</member>.
112 the type of the control - one of the <type scope="com::sun::star::inspection">PropertyControlType</type>
115 Reference to the instance as whose "impl-class" we act. This reference is held during lifetime
116 of the <type>ControlHelper</type> class, within acquiring it. Thus, the owner of the
117 <type>ControlHelper</type> is responsible for assuring the lifetime of the instance
118 pointed to by <arg>_pAntiImpl</arg>.
119 @param _pModifyListener
120 a listener to be modfied when the user modified the control's value. the
121 <member>IModifyListener::modified</member> of this listener is called from within our
122 ModifiedHdl. A default implementation of <member>IModifyListener::modified</member>
123 would just call our <member>setModified</member>.
126 Window
* _pControlWindow
,
127 sal_Int16 _nControlType
,
128 ::com::sun::star::inspection::XPropertyControl
& _rAntiImpl
,
129 IModifyListener
* _pModifyListener
);
131 virtual ~ControlHelper();
133 /** sets our "modified" flag to <TRUE/>
135 inline void setModified() { m_bModified
= sal_True
; }
136 inline Window
* getVclControlWindow() { return m_pControlWindow
; }
137 inline const Window
* getVclControlWindow() const { return m_pControlWindow
; }
141 ::sal_Int16 SAL_CALL
getControlType() throw (::com::sun::star::uno::RuntimeException
);
142 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
> SAL_CALL
getControlContext() throw (::com::sun::star::uno::RuntimeException
);
143 void SAL_CALL
setControlContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>& _controlcontext
) throw (::com::sun::star::uno::RuntimeException
);
144 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
getControlWindow() throw (::com::sun::star::uno::RuntimeException
);
145 ::sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
);
146 void SAL_CALL
notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
);
149 virtual void SAL_CALL
dispose();
151 /** (fail-safe) wrapper around calling our context's activateNextControl
153 inline void activateNextControl() const { impl_activateNextControl_nothrow(); }
156 /// may be used to implement the default handling in PreNotify; returns sal_True if handled
157 bool handlePreNotify(NotifyEvent
& _rNEvt
);
159 /// automatically size the window given in the ctor
160 void autoSizeWindow();
162 /// may be used by derived classes, they forward the event to the PropCtrListener
163 DECL_LINK( ModifiedHdl
, Window
* );
164 DECL_LINK( GetFocusHdl
, Window
* );
165 DECL_LINK( LoseFocusHdl
, Window
* );
168 /** fail-safe wrapper around calling our context's activateNextControl
170 void impl_activateNextControl_nothrow() const;
173 //========================================================================
174 //= CommonBehaviourControl
175 //========================================================================
176 /** implements a base class for <type scope="com::sun::star::inspection">XPropertyControl</type>
177 implementations, which delegates the generic functionality of this interface to a
178 <type>ControlHelper</type> member.
180 @param CONTROL_INTERFACE
181 an interface class which is derived from (or identical to) <type scope="com::sun::star::inspection">XPropertyControl</type>
182 @param CONTROL_WINDOW
183 a class which is derived from ControlWindow
185 template < class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
186 class CommonBehaviourControl
:public ::comphelper::OBaseMutex
187 ,public ::cppu::WeakComponentImplHelper1
< CONTROL_INTERFACE
>
188 ,public IModifyListener
191 typedef CONTROL_INTERFACE InterfaceType
;
192 typedef CONTROL_WINDOW WindowType
;
194 typedef ::comphelper::OBaseMutex MutexBaseClass
;
195 typedef ::cppu::WeakComponentImplHelper1
< CONTROL_INTERFACE
> ComponentBaseClass
;
198 ControlHelper m_aImplControl
;
201 inline CommonBehaviourControl( sal_Int16 _nControlType
, Window
* _pParentWindow
, WinBits _nWindowStyle
, bool _bDoSetHandlers
= true );
203 // XPropertyControl - delegated to ->m_aImplControl
204 inline ::sal_Int16 SAL_CALL
getControlType() throw (::com::sun::star::uno::RuntimeException
);
205 inline ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
> SAL_CALL
getControlContext() throw (::com::sun::star::uno::RuntimeException
);
206 inline void SAL_CALL
setControlContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>& _controlcontext
) throw (::com::sun::star::uno::RuntimeException
);
207 inline ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
getControlWindow() throw (::com::sun::star::uno::RuntimeException
);
208 inline ::sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
);
209 inline void SAL_CALL
notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
);
212 inline virtual void SAL_CALL
disposing();
215 inline virtual void modified();
217 /// returns a typed pointer to our control window
218 WindowType
* getTypedControlWindow() { return static_cast< WindowType
* > ( m_aImplControl
.getVclControlWindow() ); }
219 const WindowType
* getTypedControlWindow() const { return static_cast< const WindowType
* >( m_aImplControl
.getVclControlWindow() ); }
222 /** checks whether the instance is already disposed
223 @throws DisposedException
224 if the instance is already disposed
226 inline void impl_checkDisposed_throw();
229 //========================================================================
230 //= ControlWindow - implementation
231 //========================================================================
232 //------------------------------------------------------------------------
233 template< class WINDOW
>
234 inline void ControlWindow
< WINDOW
>::setControlHelper( ControlHelper
& _rControlHelper
)
236 m_pHelper
= &_rControlHelper
;
239 //------------------------------------------------------------------------
240 template< class WINDOW
>
241 inline long ControlWindow
< WINDOW
>::PreNotify( NotifyEvent
& rNEvt
)
243 if ( m_pHelper
&& m_pHelper
->handlePreNotify( rNEvt
) )
245 return WindowType::PreNotify( rNEvt
);
248 //========================================================================
249 //= CommonBehaviourControl - implementation
250 //========================================================================
251 //------------------------------------------------------------------------
252 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
253 inline CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::CommonBehaviourControl ( sal_Int16 _nControlType
, Window
* _pParentWindow
, WinBits _nWindowStyle
, bool _bDoSetHandlers
)
254 :ComponentBaseClass( m_aMutex
)
255 ,m_aImplControl( new WindowType( _pParentWindow
, _nWindowStyle
), _nControlType
, *this, this )
257 WindowType
* pControlWindow( getTypedControlWindow() );
258 pControlWindow
->setControlHelper( m_aImplControl
);
259 if ( _bDoSetHandlers
)
261 pControlWindow
->SetModifyHdl( LINK( &m_aImplControl
, ControlHelper
, ModifiedHdl
) );
262 pControlWindow
->SetGetFocusHdl( LINK( &m_aImplControl
, ControlHelper
, GetFocusHdl
) );
263 pControlWindow
->SetLoseFocusHdl( LINK( &m_aImplControl
, ControlHelper
, LoseFocusHdl
) );
265 m_aImplControl
.autoSizeWindow();
268 //--------------------------------------------------------------------
269 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
270 inline ::sal_Int16 SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::getControlType() throw (::com::sun::star::uno::RuntimeException
)
272 return m_aImplControl
.getControlType();
275 //--------------------------------------------------------------------
276 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
277 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
)
279 return m_aImplControl
.getControlContext();
282 //--------------------------------------------------------------------
283 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
284 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
)
286 m_aImplControl
.setControlContext( _controlcontext
);
289 //--------------------------------------------------------------------
290 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
291 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
)
293 return m_aImplControl
.getControlWindow();
296 //--------------------------------------------------------------------
297 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
298 inline ::sal_Bool SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::isModified( ) throw (::com::sun::star::uno::RuntimeException
)
300 return m_aImplControl
.isModified();
303 //--------------------------------------------------------------------
304 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
305 inline void SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
)
307 m_aImplControl
.notifyModifiedValue();
310 //--------------------------------------------------------------------
311 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
312 inline void SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::disposing()
314 m_aImplControl
.dispose();
317 //--------------------------------------------------------------------
318 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
319 inline void CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::modified()
321 m_aImplControl
.setModified();
324 //--------------------------------------------------------------------
325 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
326 inline void CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::impl_checkDisposed_throw()
328 if ( ComponentBaseClass::rBHelper
.bDisposed
)
329 throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), *this );
332 //............................................................................
334 //............................................................................
336 #endif // _EXTENSIONS_PROPCTRLR_COMMONCONTROL_HXX_