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