]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/checkedwidgets.C
get rid of broken_header.h and some unneeded tests
[lyx.git] / src / frontends / xforms / checkedwidgets.C
1 /**
2  * \file xforms/checkedwidgets.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13
14 #include "checkedwidgets.h"
15 #include "xforms_helpers.h"
16 #include "lyxgluelength.h"
17
18 #include "support/lstrings.h"
19
20 #include "lyx_forms.h"
21
22 using std::string;
23
24 namespace lyx {
25
26 using support::isStrDbl;
27
28 namespace frontend {
29
30
31 void addCheckedLyXLength(BCView & bcview,
32                          FL_OBJECT * input, FL_OBJECT * label)
33 {
34         bcview.addCheckedWidget(new CheckedLyXLength(input, label));
35 }
36
37
38 void addCheckedGlueLength(BCView & bcview,
39                           FL_OBJECT * input, FL_OBJECT * label)
40 {
41         bcview.addCheckedWidget(new CheckedGlueLength(input, label));
42 }
43
44
45 namespace {
46
47 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
48 {
49         // define color to mark invalid input
50         FL_COLOR const alert_col = FL_RED;
51
52         FL_COLOR const lcol = valid ? FL_COLOR(FL_LCOL) : alert_col;
53         if (label->lcol != lcol && isActive(label)) {
54                 fl_set_object_lcol(label, lcol);
55         }
56         if (input->lcol != lcol && isActive(input)) {
57                 fl_set_object_lcol(input, lcol);
58         }
59
60         // Reflect the validity of the data in the background color of the
61         // input widget only when this widget is not being edited.
62         FL_COLOR const icol1 = valid ? FL_COLOR(FL_COL1) : alert_col;
63         if (input->col1 != icol1) {
64                 fl_set_object_color(input, icol1, FL_MCOL);
65         }
66 }
67
68 } // namespace anon
69
70
71 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
72         : input_(input), label_(label ? label : input)
73 {
74         BOOST_ASSERT(input && input->objclass == FL_INPUT);
75 }
76
77
78 bool CheckedLyXLength::check() const
79 {
80         string const str = getString(input_);
81         bool const valid = !isActive(input_) || str.empty()
82                 || isStrDbl(str) || isValidLength(str);
83
84         // set the color of label and input widget
85         setWidget(valid, input_, label_);
86
87         return valid;
88 }
89
90
91 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
92         : input_(input), label_(label ? label : input)
93 {
94         BOOST_ASSERT(input && input->objclass == FL_INPUT);
95 }
96
97
98 bool CheckedGlueLength::check() const
99 {
100         string const str = getString(input_);
101         bool const valid = !isActive(input_) || str.empty()
102                 || isStrDbl(str) || isValidGlueLength(str);
103
104         // set the color of label and input widget
105         setWidget(valid, input_, label_);
106
107         return valid;
108 }
109
110 } // namespace frontend
111 } // namespace lyx