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"
27 /** General purpose button controller for up to four buttons.
28 Controls the activation of the OK, Apply and Cancel buttons.
29 Actually supports 4 buttons in all and it's up to the user to decide on
30 the activation policy and which buttons correspond to which output of the
33 template <class Policy>
34 class ButtonController : public noncopyable
37 /**@name Constructors and Deconstructors */
40 The cancel/close label entries are _not_ managed within the class
41 thereby allowing you to reassign at will and to use static labels.
42 It also means if you really don't want to have the Cancel button
43 label be different when there is nothing changed in the dialog then
44 you can just assign "Cancel" to both labels. Or even reuse this
45 class for something completely different.
47 ButtonController(char const * cancel, char const * close)
48 : bp_(), okay_(0), apply_(0), cancel_(0), undo_all_(0),
49 read_only_(), cancel_label(cancel), close_label(close) {}
50 /// Somebody else owns the FL_OBJECTs we just manipulate them.
51 ~ButtonController() {}
54 /**@name Initialise Button Functions */
56 /// Call refresh() when finished setting the buttons.
57 void setOK(FL_OBJECT * obj)
60 void setApply(FL_OBJECT * obj)
63 void setCancel(FL_OBJECT * obj)
66 void setUndoAll(FL_OBJECT * obj)
69 void setCancelTrueLabel(char const * c)
72 void setCancelFalseLabel(char const * c)
75 void addReadOnly(FL_OBJECT * obj)
76 { read_only_.push_front(obj); }
79 { read_only_.erase(read_only_.begin(), read_only_.end()); }
82 /**@name Action Functions */
85 void input(ButtonPolicy::SMInput in)
92 { input(ButtonPolicy::SMI_OKAY); }
95 { input(ButtonPolicy::SMI_APPLY); }
98 { input(ButtonPolicy::SMI_CANCEL); }
101 { input(ButtonPolicy::SMI_UNDO_ALL); }
104 { input(ButtonPolicy::SMI_HIDE); }
105 /// Passthrough function -- returns its input value
106 bool read_only(bool ro = true)
109 input(ButtonPolicy::SMI_READ_ONLY);
111 input(ButtonPolicy::SMI_READ_WRITE);
117 { read_only(false); }
118 /// Passthrough function -- returns its input value
119 bool valid(bool v = true)
122 input(ButtonPolicy::SMI_VALID);
124 input(ButtonPolicy::SMI_INVALID);
131 /// force a refresh of the buttons
135 if (bp_.buttonStatus(ButtonPolicy::OKAY)) {
136 fl_activate_object(okay_);
137 fl_set_object_lcol(okay_, FL_BLACK);
139 fl_deactivate_object(okay_);
140 fl_set_object_lcol(okay_, FL_INACTIVE);
144 if (bp_.buttonStatus(ButtonPolicy::APPLY)) {
145 fl_activate_object(apply_);
146 fl_set_object_lcol(apply_, FL_BLACK);
148 fl_deactivate_object(apply_);
149 fl_set_object_lcol(apply_, FL_INACTIVE);
153 if (bp_.buttonStatus(ButtonPolicy::UNDO_ALL)) {
154 fl_activate_object(undo_all_);
155 fl_set_object_lcol(undo_all_, FL_BLACK);
157 fl_deactivate_object(undo_all_);
158 fl_set_object_lcol(undo_all_,
163 if (bp_.buttonStatus(ButtonPolicy::CANCEL)) {
164 fl_set_object_label(cancel_,
167 fl_set_object_label(cancel_,
171 if (!read_only_.empty()) {
172 if (bp_.isReadOnly()) {
173 for (std::list<FL_OBJECT *>::iterator
174 iter = read_only_.begin();
175 iter != read_only_.end();
177 fl_deactivate_object(*iter);
178 fl_set_object_lcol(undo_all_,
182 for (std::list<FL_OBJECT *>::iterator
183 iter = read_only_.begin();
184 iter != read_only_.end();
186 fl_activate_object(undo_all_);
187 fl_set_object_lcol(undo_all_,
197 /**@name Button Widgets */
206 FL_OBJECT * undo_all_;
207 /// List of items to be deactivated when in one of the read-only states
208 std::list<FL_OBJECT *> read_only_;
210 /**@name Cancel/Close Button Labels */
213 char const * cancel_label;
215 char const * close_label;