3 * Controls the activation of the OK, Apply and Cancel buttons.
4 * Actually supports 4 buttons in all and it's up to the user to decide on
5 * the activation policy and which buttons correspond to which output of the
7 * Author: Allan Rae <rae@lyx.org>
9 * ======================================================
11 * LyX, The Document Processor
13 * Copyright 1995 Matthias Ettrich
14 * Copyright 1995-2000 The LyX Team.
16 * This file Copyright 2000
18 * ======================================================
21 #ifndef BUTTONCONTROLLER_H
22 #define BUTTONCONTROLLER_H
24 #include "ButtonPolicies.h"
26 /** General purpose button controller for up to four buttons.
27 Controls the activation of the OK, Apply and Cancel buttons.
28 Actually supports 4 buttons in all and it's up to the user to decide on
29 the activation policy and which buttons correspond to which output of the
32 template <class Policy>
33 class ButtonController : public noncopyable
36 /**@name Constructors and Deconstructors */
39 The cancel/close label entries are _not_ managed within the class
40 thereby allowing you to reassign at will and to use static labels.
41 It also means if you really don't want to have the Cancel button
42 label be different when there is nothing changed in the dialog then
43 you can just assign "Cancel" to both labels. Or even reuse this
44 class for something completely different.
46 ButtonController(char const * cancel, char const * close)
47 : bp_(), okay_(0), apply_(0), cancel_(0), undo_all_(0),
48 cancel_label(cancel), close_label(close) {}
49 /// Somebody else owns the FL_OBJECTs we just manipulate them.
50 ~ButtonController() {}
53 /**@name Initialise Button Functions */
55 /// Call refresh() when finished setting the buttons.
56 void setOkay(FL_OBJECT * obj)
59 void setApply(FL_OBJECT * obj)
62 void setCancel(FL_OBJECT * obj)
65 void setUndoAll(FL_OBJECT * obj)
68 void setCancelTrueLabel(char const * c)
71 void setCancelFalseLabel(char const * c)
75 /**@name Action Functions */
78 void input(ButtonPolicy::SMInput in)
85 { input(ButtonPolicy::SMI_OKAY); }
88 { input(ButtonPolicy::SMI_APPLY); }
91 { input(ButtonPolicy::SMI_CANCEL); }
94 { input(ButtonPolicy::SMI_UNDO_ALL); }
97 { input(ButtonPolicy::SMI_HIDE); }
98 /// Passthrough function -- returns its input value
99 bool read_only(bool ro = true)
102 input(ButtonPolicy::SMI_READ_ONLY);
104 input(ButtonPolicy::SMI_READ_WRITE);
110 { read_only(false); }
111 /// Passthrough function -- returns its input value
112 bool valid(bool v = true)
115 input(ButtonPolicy::SMI_VALID);
117 input(ButtonPolicy::SMI_INVALID);
124 /// force a refresh of the buttons
128 if (bp_.buttonStatus(ButtonPolicy::OKAY)) {
129 fl_activate_object(okay_);
130 fl_set_object_lcol(okay_, FL_BLACK);
132 fl_deactivate_object(okay_);
133 fl_set_object_lcol(okay_, FL_INACTIVE);
137 if (bp_.buttonStatus(ButtonPolicy::APPLY)) {
138 fl_activate_object(apply_);
139 fl_set_object_lcol(apply_, FL_BLACK);
141 fl_deactivate_object(apply_);
142 fl_set_object_lcol(apply_, FL_INACTIVE);
146 if (bp_.buttonStatus(ButtonPolicy::UNDO_ALL)) {
147 fl_activate_object(undo_all_);
148 fl_set_object_lcol(undo_all_, FL_BLACK);
150 fl_deactivate_object(undo_all_);
151 fl_set_object_lcol(undo_all_,
156 if (bp_.buttonStatus(ButtonPolicy::CANCEL)) {
157 fl_set_object_label(cancel_,
160 fl_set_object_label(cancel_,
169 /**@name Button Widgets */
178 FL_OBJECT * undo_all_;
180 /**@name Cancel/Close Button Labels */
183 char const * cancel_label;
185 char const * close_label;