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 SVTOOLS_DIALOGCONTROLLING_HXX
21 #define SVTOOLS_DIALOGCONTROLLING_HXX
23 #include <svtools/svtdllapi.h>
25 #include <tools/link.hxx>
26 #include <vcl/button.hxx>
29 #include <boost/shared_ptr.hpp>
31 //........................................................................
34 //........................................................................
36 //=====================================================================
38 //=====================================================================
39 /** an abstract interface for operating on a ->Window
41 class SVT_DLLPUBLIC SAL_NO_VTABLE IWindowOperator
44 /** called when an event happened which should be reacted to
47 the event which triggered the call. If the Id of the event is 0, then this is the initial
48 call which is made when ->_rOperateOn is added to the responsibility of the DialogController.
50 the window on which to operate
52 virtual void operateOn( const VclWindowEvent
& _rTrigger
, Window
& _rOperateOn
) const = 0;
54 virtual ~IWindowOperator();
56 typedef ::boost::shared_ptr
< IWindowOperator
> PWindowOperator
;
58 //=====================================================================
59 //= IWindowEventFilter
60 //=====================================================================
61 /** an abstract interface for deciding whether a ->VclWindowEvent
62 is worth paying attention to
64 class SVT_DLLPUBLIC SAL_NO_VTABLE IWindowEventFilter
67 virtual bool payAttentionTo( const VclWindowEvent
& _rEvent
) const = 0;
69 virtual ~IWindowEventFilter();
71 typedef ::boost::shared_ptr
< IWindowEventFilter
> PWindowEventFilter
;
73 //=====================================================================
75 //=====================================================================
76 struct DialogController_Data
;
77 /** a class controlling interactions between dialog controls
79 An instance of this class listens to all events fired by a certain
80 ->Control (more precise, a ->Window), the so-called instigator.
82 Additionally, the ->DialogController maintains a list of windows which
83 are affected by changes in the instigator window. Let's call those the
86 Now, by help of an owner-provided ->IWindowEventFilter, the ->DialogController
87 decides which events are worth attention. By help of an owner-provided
88 ->IWindowOperator, it handles those events for all dependent windows.
90 class SVT_DLLPUBLIC DialogController
93 ::std::auto_ptr
< DialogController_Data
> m_pImpl
;
96 DialogController( Window
& _rInstigator
, const PWindowEventFilter
& _pEventFilter
, const PWindowOperator
& _pOperator
);
97 virtual ~DialogController();
99 /** adds a window to the list of dependent windows
102 The window to add to the list of dependent windows.
104 The caller is responsible for life-time control: The given window
105 must live at least as long as the ->DialogController instance does.
107 void addDependentWindow( Window
& _rWindow
);
109 /** resets the controller so that no actions happened anymore.
111 The instances is disfunctional after this method has been called.
117 void impl_updateAll( const VclWindowEvent
& _rTriggerEvent
);
118 void impl_update( const VclWindowEvent
& _rTriggerEvent
, Window
& _rWindow
);
120 DECL_LINK( OnWindowEvent
, const VclWindowEvent
* );
123 DialogController( const DialogController
& ); // never implemented
124 DialogController
& operator=( const DialogController
& ); // never implemented
126 typedef ::boost::shared_ptr
< DialogController
> PDialogController
;
128 //=====================================================================
129 //= ControlDependencyManager
130 //=====================================================================
131 struct ControlDependencyManager_Data
;
132 /** helper class for managing control dependencies
134 Instances of this class are intended to be held as members of a dialog/tabpage/whatever
135 class, with easy administration of inter-control dependencies (such as "Enable
136 control X if and only if checkbox Y is checked).
138 class SVT_DLLPUBLIC ControlDependencyManager
141 ::std::auto_ptr
< ControlDependencyManager_Data
> m_pImpl
;
144 ControlDependencyManager();
145 ~ControlDependencyManager();
147 /** clears all dialog controllers previously added to the manager
151 /** ensures that a given window is enabled or disabled, according to the check state
152 of a given radio button
154 denotes the radio button whose check state is to observe
155 @param _rDependentWindow
156 denotes the window which should be enabled when ->_rRadio is checked, and
157 disabled when it's unchecked
159 void enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow
);
160 void enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
);
161 void enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
, Window
& _rDependentWindow5
);
163 /** ensures that a given window is enabled or disabled, according to the mark state
166 denotes the check box whose mark state is to observe
167 @param _rDependentWindow
168 denotes the window which should be enabled when ->_rBox is marked, and
169 disabled when it's unmarked
171 void enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow
);
172 void enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
);
173 void enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
);
175 /** adds a non-standard controller whose functionality is not covered by the other methods
178 the controller to add to the manager. Must not be <NULL/>.
180 void addController( const PDialogController
& _pController
);
183 ControlDependencyManager( const ControlDependencyManager
& ); // never implemented
184 ControlDependencyManager
& operator=( const ControlDependencyManager
& ); // never implemented
187 //=====================================================================
189 //=====================================================================
190 /** a helper class implementing the ->IWindowOperator interface,
191 which enables a dependent window depending on the check state of
192 an instigator window.
194 @see DialogController
196 template< class CHECKABLE
>
197 class SVT_DLLPUBLIC EnableOnCheck
: public IWindowOperator
200 typedef CHECKABLE SourceType
;
203 SourceType
& m_rCheckable
;
206 /** constructs the instance
209 a ->Window instance which supports a boolean method IsChecked. Usually
210 a ->RadioButton or ->CheckBox
212 EnableOnCheck( SourceType
& _rCheckable
)
213 :m_rCheckable( _rCheckable
)
217 virtual void operateOn( const VclWindowEvent
& /*_rTrigger*/, Window
& _rOperateOn
) const
219 _rOperateOn
.Enable( m_rCheckable
.IsChecked() );
223 //=====================================================================
224 //= FilterForRadioOrCheckToggle
225 //=====================================================================
226 /** a helper class implementing the ->IWindowEventFilter interface,
227 which filters for radio buttons or check boxes being toggled.
229 Technically, the class simply filters for the ->VCLEVENT_RADIOBUTTON_TOGGLE
230 and the ->VCLEVENT_CHECKBOX_TOGGLE event.
232 class SVT_DLLPUBLIC FilterForRadioOrCheckToggle
: public IWindowEventFilter
234 const Window
& m_rWindow
;
236 FilterForRadioOrCheckToggle( const Window
& _rWindow
)
237 :m_rWindow( _rWindow
)
241 bool payAttentionTo( const VclWindowEvent
& _rEvent
) const
243 if ( ( _rEvent
.GetWindow() == &m_rWindow
)
244 && ( ( _rEvent
.GetId() == VCLEVENT_RADIOBUTTON_TOGGLE
)
245 || ( _rEvent
.GetId() == VCLEVENT_CHECKBOX_TOGGLE
)
253 //=====================================================================
254 //= RadioDependentEnabler
255 //=====================================================================
256 /** a ->DialogController derivee which enables or disables its dependent windows,
257 depending on the check state of a radio button.
259 The usage of this class is as simple as
261 pController = new RadioDependentEnabler( m_aOptionSelectSomething );
262 pController->addDependentWindow( m_aLabelSelection );
263 pController->addDependentWindow( m_aListSelection );
266 With this, both <code>m_aLabelSelection</code> and <code>m_aListSelection</code> will
267 be disabled if and only <code>m_aOptionSelectSomething</code> is checked.
269 class SVT_DLLPUBLIC RadioDependentEnabler
: public DialogController
272 RadioDependentEnabler( RadioButton
& _rButton
)
273 :DialogController( _rButton
,
274 PWindowEventFilter( new FilterForRadioOrCheckToggle( _rButton
) ),
275 PWindowOperator( new EnableOnCheck
< RadioButton
>( _rButton
) ) )
279 RadioDependentEnabler( CheckBox
& _rBox
)
280 :DialogController( _rBox
,
281 PWindowEventFilter( new FilterForRadioOrCheckToggle( _rBox
) ),
282 PWindowOperator( new EnableOnCheck
< CheckBox
>( _rBox
) ) )
287 //........................................................................
289 //........................................................................
291 #endif // SVTOOLS_DIALOGCONTROLLING_HXX
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */