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