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>
33 20001001 Switch from template implementation to taking Policy parameter.
34 Allows FormBase to provide a ButtonController for any dialog.
36 class ButtonController : public noncopyable
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(ButtonPolicy * bp, char const * cancel, char const * close)
48 : bp_(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() {}
53 /* Initialise Button Functions */
54 /// Call refresh() when finished setting the buttons.
55 void setOK(FL_OBJECT * obj) {
59 void setApply(FL_OBJECT * obj) {
63 void setCancel(FL_OBJECT * obj) {
67 void setUndoAll(FL_OBJECT * obj) {
71 void setCancelTrueLabel(char const * c) {
75 void setCancelFalseLabel(char const * c) {
79 void addReadOnly(FL_OBJECT * obj) {
80 read_only_.push_front(obj);
83 void eraseReadOnly() {
84 read_only_.erase(read_only_.begin(), read_only_.end());
87 /* Action Functions */
88 /// force a refresh of the buttons
91 if (bp_->buttonStatus(ButtonPolicy::OKAY)) {
92 fl_activate_object(okay_);
93 fl_set_object_lcol(okay_, FL_BLACK);
95 fl_deactivate_object(okay_);
96 fl_set_object_lcol(okay_, FL_INACTIVE);
100 if (bp_->buttonStatus(ButtonPolicy::APPLY)) {
101 fl_activate_object(apply_);
102 fl_set_object_lcol(apply_, FL_BLACK);
104 fl_deactivate_object(apply_);
105 fl_set_object_lcol(apply_, FL_INACTIVE);
109 if (bp_->buttonStatus(ButtonPolicy::UNDO_ALL)) {
110 fl_activate_object(undo_all_);
111 fl_set_object_lcol(undo_all_, FL_BLACK);
113 fl_deactivate_object(undo_all_);
114 fl_set_object_lcol(undo_all_,
119 if (bp_->buttonStatus(ButtonPolicy::CANCEL)) {
120 fl_set_object_label(cancel_,
123 fl_set_object_label(cancel_,
127 if (!read_only_.empty()) {
128 if (bp_->isReadOnly()) {
129 std::list<FL_OBJECT *>::iterator
130 end = read_only_.end();
131 for (std::list<FL_OBJECT *>::iterator
132 iter = read_only_.begin();
135 fl_deactivate_object(*iter);
136 fl_set_object_lcol(*iter,
140 std::list<FL_OBJECT *>::iterator
141 end = read_only_.end();
142 for (std::list<FL_OBJECT *>::iterator
143 iter = read_only_.begin();
146 fl_activate_object(*iter);
147 fl_set_object_lcol(*iter,
154 void input(ButtonPolicy::SMInput in) {
160 input(ButtonPolicy::SMI_OKAY);
164 input(ButtonPolicy::SMI_APPLY);
168 input(ButtonPolicy::SMI_CANCEL);
172 input(ButtonPolicy::SMI_UNDO_ALL);
176 input(ButtonPolicy::SMI_HIDE);
178 /// Passthrough function -- returns its input value
179 bool readOnly(bool ro = true) {
181 input(ButtonPolicy::SMI_READ_ONLY);
183 input(ButtonPolicy::SMI_READ_WRITE);
191 /// Passthrough function -- returns its input value
192 bool valid(bool v = true) {
194 input(ButtonPolicy::SMI_VALID);
196 input(ButtonPolicy::SMI_INVALID);
214 FL_OBJECT * undo_all_;
215 /// List of items to be deactivated when in one of the read-only states
216 std::list<FL_OBJECT *> read_only_;
218 char const * cancel_label;
220 char const * close_label;