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 INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_COMMONCONTROL_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_COMMONCONTROL_HXX
23 #include <com/sun/star/inspection/XPropertyControl.hpp>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <cppuhelper/compbase1.hxx>
26 #include <comphelper/broadcasthelper.hxx>
27 #include <tools/link.hxx>
28 #include <vcl/window.hxx>
38 template< class WINDOW
>
39 class ControlWindow
: public WINDOW
42 typedef WINDOW WindowType
;
45 ControlHelper
* m_pHelper
;
48 ControlWindow( vcl::Window
* _pParent
, WinBits _nStyle
)
49 :WindowType( _pParent
, _nStyle
)
54 /// sets a ControlHelper instance which some functionality is delegated to
55 inline virtual void setControlHelper( ControlHelper
& _rControlHelper
);
58 // Window overridables
59 inline virtual bool PreNotify( NotifyEvent
& rNEvt
);
65 class SAL_NO_VTABLE IModifyListener
68 virtual void modified() = 0;
77 /** A helper class for implementing the <type scope="com::sun::star::inspection">XPropertyControl</type>
78 or one of its derived interfaces.
80 This class is intended to be held as member of another class which implements the
81 <type scope="com::sun::star::inspection">XPropertyControl</type> interface. The pointer
82 to this interface is to be passed to the ctor.
87 VclPtr
<vcl::Window
> m_pControlWindow
;
88 sal_Int16 m_nControlType
;
89 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>
91 ::com::sun::star::inspection::XPropertyControl
&
93 IModifyListener
* m_pModifyListener
;
97 /** creates the instance
98 @param _rControlWindow
99 the window which is associated with the <type scope="com::sun::star::inspection">XPropertyControl</type>.
100 Must not be <NULL/>.<br/>
101 Ownership for this window is taken by the ControlHelper - it will be deleted in <member>disposing</member>.
103 the type of the control - one of the <type scope="com::sun::star::inspection">PropertyControlType</type>
106 Reference to the instance as whose "impl-class" we act. This reference is held during lifetime
107 of the <type>ControlHelper</type> class, within acquiring it. Thus, the owner of the
108 <type>ControlHelper</type> is responsible for assuring the lifetime of the instance
109 pointed to by <arg>_pAntiImpl</arg>.
110 @param _pModifyListener
111 a listener to be modfied when the user modified the control's value. the
112 <member>IModifyListener::modified</member> of this listener is called from within our
113 ModifiedHdl. A default implementation of <member>IModifyListener::modified</member>
114 would just call our <member>setModified</member>.
117 vcl::Window
* _pControlWindow
,
118 sal_Int16 _nControlType
,
119 ::com::sun::star::inspection::XPropertyControl
& _rAntiImpl
,
120 IModifyListener
* _pModifyListener
);
122 virtual ~ControlHelper();
124 /** sets our "modified" flag to <TRUE/>
126 inline void setModified() { m_bModified
= true; }
127 inline vcl::Window
* getVclControlWindow() { return m_pControlWindow
; }
128 inline const vcl::Window
* getVclControlWindow() const { return m_pControlWindow
; }
132 ::sal_Int16 SAL_CALL
getControlType() throw (::com::sun::star::uno::RuntimeException
) { return m_nControlType
; }
133 ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
> SAL_CALL
getControlContext() throw (::com::sun::star::uno::RuntimeException
) { return m_xContext
; }
134 void SAL_CALL
setControlContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>& _controlcontext
) throw (::com::sun::star::uno::RuntimeException
);
135 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
getControlWindow() throw (::com::sun::star::uno::RuntimeException
);
136 bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
) { return m_bModified
; }
137 void SAL_CALL
notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
);
140 virtual void SAL_CALL
dispose();
142 /** (fail-safe) wrapper around calling our context's activateNextControl
144 inline void activateNextControl() const { impl_activateNextControl_nothrow(); }
147 /// may be used to implement the default handling in PreNotify; returns sal_True if handled
148 bool handlePreNotify(NotifyEvent
& _rNEvt
);
150 /// automatically size the window given in the ctor
151 void autoSizeWindow();
153 /// may be used by derived classes, they forward the event to the PropCtrListener
154 DECL_LINK( ModifiedHdl
, vcl::Window
* );
155 DECL_LINK( GetFocusHdl
, vcl::Window
* );
156 DECL_LINK( LoseFocusHdl
, vcl::Window
* );
159 /** fail-safe wrapper around calling our context's activateNextControl
161 void impl_activateNextControl_nothrow() const;
165 //= CommonBehaviourControl
167 /** implements a base class for <type scope="com::sun::star::inspection">XPropertyControl</type>
168 implementations, which delegates the generic functionality of this interface to a
169 <type>ControlHelper</type> member.
171 @param CONTROL_INTERFACE
172 an interface class which is derived from (or identical to) <type scope="com::sun::star::inspection">XPropertyControl</type>
173 @param CONTROL_WINDOW
174 a class which is derived from ControlWindow
176 template < class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
177 class CommonBehaviourControl
:public ::comphelper::OBaseMutex
178 ,public ::cppu::WeakComponentImplHelper1
< CONTROL_INTERFACE
>
179 ,public IModifyListener
182 typedef CONTROL_INTERFACE InterfaceType
;
183 typedef CONTROL_WINDOW WindowType
;
185 typedef ::comphelper::OBaseMutex MutexBaseClass
;
186 typedef ::cppu::WeakComponentImplHelper1
< CONTROL_INTERFACE
> ComponentBaseClass
;
189 ControlHelper m_aImplControl
;
192 inline CommonBehaviourControl( sal_Int16 _nControlType
, vcl::Window
* _pParentWindow
, WinBits _nWindowStyle
, bool _bDoSetHandlers
= true );
194 // XPropertyControl - delegated to ->m_aImplControl
195 virtual ::sal_Int16 SAL_CALL
getControlType() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
196 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
> SAL_CALL
getControlContext() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
197 virtual void SAL_CALL
setControlContext( const ::com::sun::star::uno::Reference
< ::com::sun::star::inspection::XPropertyControlContext
>& _controlcontext
) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
198 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
getControlWindow() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
199 virtual sal_Bool SAL_CALL
isModified( ) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
200 virtual void SAL_CALL
notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
203 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
206 virtual void modified() SAL_OVERRIDE
207 { m_aImplControl
.setModified(); }
209 /// returns a typed pointer to our control window
210 WindowType
* getTypedControlWindow() { return static_cast< WindowType
* > ( m_aImplControl
.getVclControlWindow() ); }
211 const WindowType
* getTypedControlWindow() const { return static_cast< const WindowType
* >( m_aImplControl
.getVclControlWindow() ); }
214 /** checks whether the instance is already disposed
215 @throws DisposedException
216 if the instance is already disposed
218 inline void impl_checkDisposed_throw();
222 //= ControlWindow - implementation
225 template< class WINDOW
>
226 inline void ControlWindow
< WINDOW
>::setControlHelper( ControlHelper
& _rControlHelper
)
228 m_pHelper
= &_rControlHelper
;
232 template< class WINDOW
>
233 inline bool ControlWindow
< WINDOW
>::PreNotify( NotifyEvent
& rNEvt
)
235 if ( m_pHelper
&& m_pHelper
->handlePreNotify( rNEvt
) )
237 return WindowType::PreNotify( rNEvt
);
241 //= CommonBehaviourControl - implementation
244 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
245 inline CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::CommonBehaviourControl ( sal_Int16 _nControlType
, vcl::Window
* _pParentWindow
, WinBits _nWindowStyle
, bool _bDoSetHandlers
)
246 :ComponentBaseClass( m_aMutex
)
247 ,m_aImplControl( new WindowType( _pParentWindow
, _nWindowStyle
), _nControlType
, *this, this )
249 WindowType
* pControlWindow( getTypedControlWindow() );
250 pControlWindow
->setControlHelper( m_aImplControl
);
251 if ( _bDoSetHandlers
)
253 pControlWindow
->SetModifyHdl( LINK( &m_aImplControl
, ControlHelper
, ModifiedHdl
) );
254 pControlWindow
->SetGetFocusHdl( LINK( &m_aImplControl
, ControlHelper
, GetFocusHdl
) );
255 pControlWindow
->SetLoseFocusHdl( LINK( &m_aImplControl
, ControlHelper
, LoseFocusHdl
) );
257 m_aImplControl
.autoSizeWindow();
261 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
262 inline ::sal_Int16 SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::getControlType() throw (::com::sun::star::uno::RuntimeException
)
264 return m_aImplControl
.getControlType();
268 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
269 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
)
271 return m_aImplControl
.getControlContext();
275 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
276 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
)
278 m_aImplControl
.setControlContext( _controlcontext
);
282 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
283 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
)
285 return m_aImplControl
.getControlWindow();
289 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
290 inline sal_Bool SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::isModified( ) throw (::com::sun::star::uno::RuntimeException
)
292 return m_aImplControl
.isModified();
296 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
297 inline void SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::notifyModifiedValue( ) throw (::com::sun::star::uno::RuntimeException
)
299 m_aImplControl
.notifyModifiedValue();
303 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
304 inline void SAL_CALL CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::disposing()
306 m_aImplControl
.dispose();
310 template< class CONTROL_INTERFACE
, class CONTROL_WINDOW
>
311 inline void CommonBehaviourControl
< CONTROL_INTERFACE
, CONTROL_WINDOW
>::impl_checkDisposed_throw()
313 if ( ComponentBaseClass::rBHelper
.bDisposed
)
314 throw ::com::sun::star::lang::DisposedException( OUString(), *this );
321 #endif // INCLUDED_EXTENSIONS_SOURCE_PROPCTRLR_COMMONCONTROL_HXX
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */