]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/ButtonController.C
try this for distinguishing inner and outer tabs
[lyx.git] / src / frontends / xforms / ButtonController.C
1 #include <config.h>
2
3 #include <algorithm>
4
5 #include FORMS_H_LOCATION
6
7 #ifdef __GNUG__
8 #pragma implementation
9 #endif
10
11 #include "ButtonController.h"
12 #include "support/LAssert.h"
13 #include "gettext.h" // _()
14 //#include "debug.h"
15
16 using std::find;
17 using std::vector;
18
19 ButtonController::ButtonController(ButtonPolicy * bp,
20                                    char const * cancel, char const * close)
21         : bp_(bp), okay_(0), apply_(0), cancel_(0), undo_all_(0),
22           read_only_(), dont_trigger_change_(),
23           cancel_label(cancel), close_label(close)
24 {
25         Assert(bp);
26 }
27
28
29 void ButtonController::refresh()
30 {
31         if (okay_) {
32                 if (bp_->buttonStatus(ButtonPolicy::OKAY)) {
33                         fl_activate_object(okay_);
34                         fl_set_object_lcol(okay_, FL_BLACK);
35                 } else {
36                         fl_deactivate_object(okay_);
37                         fl_set_object_lcol(okay_, FL_INACTIVE);
38                 }
39         }
40         if (apply_) {
41                 if (bp_->buttonStatus(ButtonPolicy::APPLY)) {
42                         fl_activate_object(apply_);
43                         fl_set_object_lcol(apply_, FL_BLACK);
44                 } else {
45                         fl_deactivate_object(apply_);
46                         fl_set_object_lcol(apply_, FL_INACTIVE);
47                 }
48         }
49         if (undo_all_) {
50                 if (bp_->buttonStatus(ButtonPolicy::UNDO_ALL)) {
51                         fl_activate_object(undo_all_);
52                         fl_set_object_lcol(undo_all_, FL_BLACK);
53                 } else {
54                         fl_deactivate_object(undo_all_);
55                         fl_set_object_lcol(undo_all_,
56                                            FL_INACTIVE);
57                 }
58         }
59         if (cancel_) {
60                 if (bp_->buttonStatus(ButtonPolicy::CANCEL)) {
61                         fl_set_object_label(cancel_,
62                                             _(cancel_label));
63                 } else {
64                         fl_set_object_label(cancel_,
65                                             _(close_label));
66                 }
67         }
68         if (!read_only_.empty()) {
69                 if (bp_->isReadOnly()) {
70                         std::list<FL_OBJECT *>::iterator
71                                 end = read_only_.end();
72                         for (std::list<FL_OBJECT *>::iterator
73                                      iter = read_only_.begin();
74                              iter != end;
75                              ++iter) {
76                                 fl_deactivate_object(*iter);
77                                 fl_set_object_lcol(*iter,
78                                                    FL_INACTIVE);
79                         }
80                 } else {
81                         std::list<FL_OBJECT *>::iterator
82                                 end = read_only_.end();
83                         for (std::list<FL_OBJECT *>::iterator
84                                      iter = read_only_.begin();
85                              iter != end;
86                              ++iter) {
87                                 fl_activate_object(*iter);
88                                 fl_set_object_lcol(*iter,
89                                                    FL_BLACK);
90                         }
91                 }
92         }
93 }
94
95
96 void ButtonController::input(ButtonPolicy::SMInput in)
97 {
98         //lyxerr << "ButtonController::input: bp_[" << bp_ << "]" << endl;
99         bp_->input(in);
100         refresh();
101 }
102
103
104 void ButtonController::ok()
105 {
106         input(ButtonPolicy::SMI_OKAY);
107 }
108
109
110 void ButtonController::apply()
111 {
112         input(ButtonPolicy::SMI_APPLY);
113 }
114
115
116 void ButtonController::cancel()
117 {
118         input(ButtonPolicy::SMI_CANCEL);
119 }
120
121
122 void ButtonController::undoAll()
123 {
124         input(ButtonPolicy::SMI_UNDO_ALL);
125 }
126
127
128 void ButtonController::hide()
129 {
130         input(ButtonPolicy::SMI_HIDE);
131 }
132
133
134 bool ButtonController::readOnly(bool ro)
135 {
136         if (ro) {
137                 input(ButtonPolicy::SMI_READ_ONLY);
138         } else {
139                 input(ButtonPolicy::SMI_READ_WRITE);
140         }
141         return ro;
142 }
143
144
145 void ButtonController::readWrite()
146 {
147         readOnly(false);
148 }
149
150
151 bool ButtonController::valid(bool v, FL_OBJECT * obj)
152
153         if (obj && !dont_trigger_change_.empty()) {
154                 vector<FL_OBJECT *>::const_iterator cit =
155                         find(dont_trigger_change_.begin(),
156                              dont_trigger_change_.end(),
157                              obj);
158
159                 // Only trigger a change if the obj is not in the list
160                 if (cit == dont_trigger_change_.end()) {
161                         if (v) {
162                                 input(ButtonPolicy::SMI_VALID);
163                         } else {
164                                 input(ButtonPolicy::SMI_INVALID);
165                         }
166                 }
167         } else {
168                 if (v) {
169                         input(ButtonPolicy::SMI_VALID);
170                 } else {
171                         input(ButtonPolicy::SMI_INVALID);
172                 }
173         }
174         
175         return v;
176 }
177
178
179 void ButtonController::invalid()
180 {
181         valid(false);
182 }