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
32 @author Allan Rae <rae@lyx.org>
34 template <class Policy>
35 class ButtonController : public noncopyable
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 read_only_(), cancel_label(cancel), close_label(close) {}
49 /// Somebody else owns the FL_OBJECTs we just manipulate them.
50 ~ButtonController() {}
52 /* Initialise Button Functions */
53 /// Call refresh() when finished setting the buttons.
54 void setOK(FL_OBJECT * obj) {
58 void setApply(FL_OBJECT * obj) {
62 void setCancel(FL_OBJECT * obj) {
66 void setUndoAll(FL_OBJECT * obj) {
70 void setCancelTrueLabel(char const * c) {
74 void setCancelFalseLabel(char const * c) {
78 void addReadOnly(FL_OBJECT * obj) {
79 read_only_.push_front(obj);
82 void eraseReadOnly() {
83 read_only_.erase(read_only_.begin(), read_only_.end());
86 /* Action Functions */
88 void input(ButtonPolicy::SMInput in) {
94 input(ButtonPolicy::SMI_OKAY);
98 input(ButtonPolicy::SMI_APPLY);
102 input(ButtonPolicy::SMI_CANCEL);
106 input(ButtonPolicy::SMI_UNDO_ALL);
110 input(ButtonPolicy::SMI_HIDE);
112 /// Passthrough function -- returns its input value
113 bool readOnly(bool ro = true) {
115 input(ButtonPolicy::SMI_READ_ONLY);
117 input(ButtonPolicy::SMI_READ_WRITE);
125 /// Passthrough function -- returns its input value
126 bool valid(bool v = true) {
128 input(ButtonPolicy::SMI_VALID);
130 input(ButtonPolicy::SMI_INVALID);
138 /// force a refresh of the buttons
141 if (bp_.buttonStatus(ButtonPolicy::OKAY)) {
142 fl_activate_object(okay_);
143 fl_set_object_lcol(okay_, FL_BLACK);
145 fl_deactivate_object(okay_);
146 fl_set_object_lcol(okay_, FL_INACTIVE);
150 if (bp_.buttonStatus(ButtonPolicy::APPLY)) {
151 fl_activate_object(apply_);
152 fl_set_object_lcol(apply_, FL_BLACK);
154 fl_deactivate_object(apply_);
155 fl_set_object_lcol(apply_, FL_INACTIVE);
159 if (bp_.buttonStatus(ButtonPolicy::UNDO_ALL)) {
160 fl_activate_object(undo_all_);
161 fl_set_object_lcol(undo_all_, FL_BLACK);
163 fl_deactivate_object(undo_all_);
164 fl_set_object_lcol(undo_all_,
169 if (bp_.buttonStatus(ButtonPolicy::CANCEL)) {
170 fl_set_object_label(cancel_,
173 fl_set_object_label(cancel_,
177 if (!read_only_.empty()) {
178 if (bp_.isReadOnly()) {
179 std::list<FL_OBJECT *>::iterator
180 end = read_only_.end();
181 for (std::list<FL_OBJECT *>::iterator
182 iter = read_only_.begin();
185 fl_deactivate_object(*iter);
186 fl_set_object_lcol(*iter,
190 std::list<FL_OBJECT *>::iterator
191 end = read_only_.end();
192 for (std::list<FL_OBJECT *>::iterator
193 iter = read_only_.begin();
196 fl_activate_object(*iter);
197 fl_set_object_lcol(*iter,
213 FL_OBJECT * undo_all_;
214 /// List of items to be deactivated when in one of the read-only states
215 std::list<FL_OBJECT *> read_only_;
217 char const * cancel_label;
219 char const * close_label;