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