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