2 * \file checkedwidgets.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
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"
22 #include "lyx_forms.h"
25 void addCheckedLyXLength(BCView & bcview,
26 FL_OBJECT * input, FL_OBJECT * label)
28 bcview.addCheckedWidget(new CheckedLyXLength(input, label));
32 void addCheckedGlueLength(BCView & bcview,
33 FL_OBJECT * input, FL_OBJECT * label)
35 bcview.addCheckedWidget(new CheckedGlueLength(input, label));
41 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
43 // define color to mark invalid input
44 FL_COLOR const alert_col = FL_RED;
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);
50 if (input->lcol != lcol && isActive(input)) {
51 fl_set_object_lcol(input, lcol);
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);
65 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
66 : input_(input), label_(label ? label : input)
68 lyx::Assert(input && input->objclass == FL_INPUT);
72 bool CheckedLyXLength::check() const
74 string const str = getString(input_);
75 bool const valid = !isActive(input_) || str.empty()
76 || isStrDbl(str) || isValidLength(str);
78 // set the color of label and input widget
79 setWidget(valid, input_, label_);
85 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
86 : input_(input), label_(label ? label : input)
88 lyx::Assert(input && input->objclass == FL_INPUT);
92 bool CheckedGlueLength::check() const
94 string const str = getString(input_);
95 bool const valid = !isActive(input_) || str.empty()
96 || isStrDbl(str) || isValidGlueLength(str);
98 // set the color of label and input widget
99 setWidget(valid, input_, label_);