]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/checkedwidgets.C
Strip out another 180 #includes.
[lyx.git] / src / frontends / xforms / checkedwidgets.C
1 /**
2  * \file 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/LAssert.h"
19 #include "support/lstrings.h"
20
21 #include "lyx_forms.h"
22
23 using namespace lyx::support;
24
25
26 void addCheckedLyXLength(BCView & bcview,
27                          FL_OBJECT * input, FL_OBJECT * label)
28 {
29         bcview.addCheckedWidget(new CheckedLyXLength(input, label));
30 }
31
32
33 void addCheckedGlueLength(BCView & bcview,
34                           FL_OBJECT * input, FL_OBJECT * label)
35 {
36         bcview.addCheckedWidget(new CheckedGlueLength(input, label));
37 }
38
39
40 namespace {
41
42 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
43 {
44         // define color to mark invalid input
45         FL_COLOR const alert_col = FL_RED;
46
47         FL_COLOR const lcol = valid ? FL_COLOR(FL_LCOL) : alert_col;
48         if (label->lcol != lcol && isActive(label)) {
49                 fl_set_object_lcol(label, lcol);
50         }
51         if (input->lcol != lcol && isActive(input)) {
52                 fl_set_object_lcol(input, lcol);
53         }
54
55         // Reflect the validity of the data in the background color of the
56         // input widget only when this widget is not being edited.
57         FL_COLOR const icol1 = valid ? FL_COLOR(FL_COL1) : alert_col;
58         if (input->col1 != icol1) {
59                 fl_set_object_color(input, icol1, FL_MCOL);
60         }
61 }
62
63 } // namespace anon
64
65
66 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
67         : input_(input), label_(label ? label : input)
68 {
69         Assert(input && input->objclass == FL_INPUT);
70 }
71
72
73 bool CheckedLyXLength::check() const
74 {
75         string const str = getString(input_);
76         bool const valid = !isActive(input_) || str.empty()
77                 || isStrDbl(str) || isValidLength(str);
78
79         // set the color of label and input widget
80         setWidget(valid, input_, label_);
81
82         return valid;
83 }
84
85
86 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
87         : input_(input), label_(label ? label : input)
88 {
89         Assert(input && input->objclass == FL_INPUT);
90 }
91
92
93 bool CheckedGlueLength::check() const
94 {
95         string const str = getString(input_);
96         bool const valid = !isActive(input_) || str.empty()
97                 || isStrDbl(str) || isValidGlueLength(str);
98
99         // set the color of label and input widget
100         setWidget(valid, input_, label_);
101
102         return valid;
103 }