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