3 * Provides a state machine implementation of the various button policies
5 * Author: Allan Rae <rae@lyx.org>
7 * ======================================================
9 * LyX, The Document Processor
11 * Copyright 1995 Matthias Ettrich
12 * Copyright 1995-2000 The LyX Team.
14 * This file Copyright 2000
16 * ======================================================
19 #ifndef BUTTONPOLICIES_H
20 #define BUTTONPOLICIES_H
24 #include "support/utility.hpp"
27 /** An abstract base class for button policies.
28 A state machine implementation of the various button policies used by the
29 dialogs. Only the policy is implemented here. Separate ButtonController
30 classes are needed for each GUI implementation.
32 class ButtonPolicy : public noncopyable
35 /**@name Constructors and Deconstructors */
38 virtual ~ButtonPolicy() {}
43 /** The various possible state names.
44 Not all state-machines have this many states. However, we need
45 to define them all here so we can share the code.
58 /// The various button types.
60 CLOSE = 0, // Not a real button, but effectively !CANCEL
66 /** State machine inputs.
67 All the policies so far have both CANCEL and HIDE always going to
68 INITIAL. This won't necessarily be true for all [future] policies
69 though so I'll leave those two as distinct inputs rather than merge
70 them. For example, a dialog that doesn't update it's input fields
71 when reshown after being hidden needs a policy where CANCEL and
72 HIDE are treated differently.
84 SMI_TOTAL // not a real input
88 /**@name Access Functions */
90 /// Trigger a transition with this input.
91 virtual void input(SMInput) = 0;
92 /// Activation status of OK
93 virtual bool buttonStatus(Button) = 0;
98 /// Transition map of the state machine.
99 typedef std::vector<State> StateArray;
100 typedef std::vector<StateArray> StateMachine;
101 /// The state outputs are the status of the buttons.
102 typedef std::vector<int> StateOutputs;
107 /** Defines the policy used by the Preferences dialog.
108 Four buttons: Ok (Save), Apply, Cancel/Close, Restore.
109 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
110 This is based on the value of the bool state of the Button::CANCEL.
111 true == Cancel, false == Close
113 class PreferencesPolicy : public ButtonPolicy
119 virtual ~PreferencesPolicy() {}
121 /**@name Access Functions */
123 /// Trigger a transition with this input.
124 virtual void input(SMInput);
125 /** Activation status of a button.
126 We assume that we haven't gotten into an undefined state.
127 This is reasonable since we can only reach states defined
128 in the state machine and they should all have been defined in
129 the outputs_ variable. Perhaps we can do something at compile
130 time to check that all the states have corresponding outputs.
132 virtual bool buttonStatus(Button button)
133 { return button & outputs_[state_]; }
136 /**@name Private Data Members */
140 /// Which buttons are active for a given state.
141 StateOutputs outputs_;
143 StateMachine state_machine_;
149 /** Ok and Cancel buttons for dialogs with read-only operation.
150 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
151 This is based on the value of the bool state of the Button::CANCEL.
152 true == Cancel, false == Close
154 class OkCancelPolicy : public ButtonPolicy
160 virtual ~OkCancelPolicy() {}
162 /**@name Access Functions */
164 /// Trigger a transition with this input.
165 virtual void input(SMInput);
166 /// Activation status of a button.
167 virtual bool buttonStatus(Button button)
168 { return button & outputs_[state_]; }
171 /**@name Private Data Members */
175 /// Which buttons are active for a given state.
176 StateOutputs outputs_;
178 StateMachine state_machine_;
183 /** Ok and Cancel buttons for dialogs where read-only operation is blocked.
184 The state machine design for this policy allows changes to occur within
185 the dialog while a file is read-only -- the okay button is disabled until
186 a read-write input is given. When the file is made read-write the dialog
187 will then be in the correct state (as if the file had always been read-write).
188 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
189 This is based on the value of the bool state of the Button::CANCEL.
190 true == Cancel, false == Close
192 class OkCancelReadOnlyPolicy : public ButtonPolicy
196 OkCancelReadOnlyPolicy();
198 virtual ~OkCancelReadOnlyPolicy() {}
200 /**@name Access Functions */
202 /// Trigger a transition with this input.
203 virtual void input(SMInput);
204 /// Activation status of a button.
205 virtual bool buttonStatus(Button button)
206 { return button & outputs_[state_]; }
209 /**@name Private Data Members */
213 /// Which buttons are active for a given state.
214 StateOutputs outputs_;
216 StateMachine state_machine_;
221 /** Ok, Apply and Cancel buttons for dialogs where read-only operation is blocked.
222 Repeated Apply are not allowed. Likewise, Ok cannot follow Apply without
223 some valid input. That is, the dialog contents must change between each Apply
225 The state machine design for this policy allows changes to occur within
226 the dialog while a file is read-only -- the Ok+Apply buttons are disabled
227 until a read-write input is given. When the file is made read-write the
228 dialog will then be in the correct state (as if the file had always been
230 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
231 This is based on the value of the bool state of the Button::CANCEL.
232 true == Cancel, false == Close
234 class NoRepeatedApplyReadOnlyPolicy : public ButtonPolicy
238 NoRepeatedApplyReadOnlyPolicy();
240 virtual ~NoRepeatedApplyReadOnlyPolicy() {}
242 /**@name Access Functions */
244 /// Trigger a transition with this input.
245 virtual void input(SMInput);
246 /// Activation status of a button.
247 virtual bool buttonStatus(Button button)
248 { return button & outputs_[state_]; }
251 /**@name Private Data Members */
255 /// Which buttons are active for a given state.
256 StateOutputs outputs_;
258 StateMachine state_machine_;
263 /** Ok, Apply and Cancel buttons for dialogs where read-only operation is blocked.
264 Repeated Apply is allowed. Likewise, Ok can follow Apply.
265 The state machine design for this policy allows changes to occur within
266 the dialog while a file is read-only -- the Ok+Apply buttons are disabled
267 until a read-write input is given. When the file is made read-write the
268 dialog will then be in the correct state (as if the file had always been
270 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
271 This is based on the value of the bool state of the Button::CANCEL.
272 true == Cancel, false == Close
274 class OkApplyCancelReadOnlyPolicy : public ButtonPolicy
278 OkApplyCancelReadOnlyPolicy();
280 virtual ~OkApplyCancelReadOnlyPolicy() {}
282 /**@name Access Functions */
284 /// Trigger a transition with this input.
285 virtual void input(SMInput);
286 /// Activation status of a button.
287 virtual bool buttonStatus(Button button)
288 { return button & outputs_[state_]; }
291 /**@name Private Data Members */
295 /// Which buttons are active for a given state.
296 StateOutputs outputs_;
298 StateMachine state_machine_;
303 /** Ok, Apply and Cancel buttons for dialogs where repeated Apply is allowed.
304 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
305 This is based on the value of the bool state of the Button::CANCEL.
306 true == Cancel, false == Close
308 class OkApplyCancelPolicy : public ButtonPolicy
312 OkApplyCancelPolicy();
314 virtual ~OkApplyCancelPolicy() {}
316 /**@name Access Functions */
318 /// Trigger a transition with this input.
319 virtual void input(SMInput);
320 /// Activation status of a button.
321 virtual bool buttonStatus(Button button)
322 { return button & outputs_[state_]; }
325 /**@name Private Data Members */
329 /// Which buttons are active for a given state.
330 StateOutputs outputs_;
332 StateMachine state_machine_;
337 /** Ok, Apply and Cancel buttons for dialogs with no repeated Apply.
338 Note: This scheme supports the relabelling of Cancel to Close and vice versa.
339 This is based on the value of the bool state of the Button::CANCEL.
340 true == Cancel, false == Close
342 class NoRepeatedApplyPolicy : public ButtonPolicy
346 NoRepeatedApplyPolicy();
348 virtual ~NoRepeatedApplyPolicy() {}
350 /**@name Access Functions */
352 /// Trigger a transition with this input.
353 virtual void input(SMInput);
354 /// Activation status of a button.
355 virtual bool buttonStatus(Button button)
356 { return button & outputs_[state_]; }
359 /**@name Private Data Members */
363 /// Which buttons are active for a given state.
364 StateOutputs outputs_;
366 StateMachine state_machine_;