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