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.
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 "lyxgluelength.h"
18 #include "support/lstrings.h"
20 #include "lyx_forms.h"
22 using lyx::support::isStrDbl;
27 void addCheckedLyXLength(BCView & bcview,
28 FL_OBJECT * input, FL_OBJECT * label)
30 bcview.addCheckedWidget(new CheckedLyXLength(input, label));
34 void addCheckedGlueLength(BCView & bcview,
35 FL_OBJECT * input, FL_OBJECT * label)
37 bcview.addCheckedWidget(new CheckedGlueLength(input, label));
43 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
45 // define color to mark invalid input
46 FL_COLOR const alert_col = FL_RED;
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);
52 if (input->lcol != lcol && isActive(input)) {
53 fl_set_object_lcol(input, lcol);
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);
67 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
68 : input_(input), label_(label ? label : input)
70 BOOST_ASSERT(input && input->objclass == FL_INPUT);
74 bool CheckedLyXLength::check() const
76 string const str = getString(input_);
77 bool const valid = !isActive(input_) || str.empty()
78 || isStrDbl(str) || isValidLength(str);
80 // set the color of label and input widget
81 setWidget(valid, input_, label_);
87 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
88 : input_(input), label_(label ? label : input)
90 BOOST_ASSERT(input && input->objclass == FL_INPUT);
94 bool CheckedGlueLength::check() const
96 string const str = getString(input_);
97 bool const valid = !isActive(input_) || str.empty()
98 || isStrDbl(str) || isValidGlueLength(str);
100 // set the color of label and input widget
101 setWidget(valid, input_, label_);