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"
26 using support::isStrDbl;
31 void addCheckedLyXLength(BCView & bcview,
32 FL_OBJECT * input, FL_OBJECT * label)
34 bcview.addCheckedWidget(new CheckedLyXLength(input, label));
38 void addCheckedGlueLength(BCView & bcview,
39 FL_OBJECT * input, FL_OBJECT * label)
41 bcview.addCheckedWidget(new CheckedGlueLength(input, label));
47 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
49 // define color to mark invalid input
50 FL_COLOR const alert_col = FL_RED;
52 FL_COLOR const lcol = valid ? FL_COLOR(FL_LCOL) : alert_col;
53 if (label->lcol != lcol && isActive(label)) {
54 fl_set_object_lcol(label, lcol);
56 if (input->lcol != lcol && isActive(input)) {
57 fl_set_object_lcol(input, lcol);
60 // Reflect the validity of the data in the background color of the
61 // input widget only when this widget is not being edited.
62 FL_COLOR const icol1 = valid ? FL_COLOR(FL_COL1) : alert_col;
63 if (input->col1 != icol1) {
64 fl_set_object_color(input, icol1, FL_MCOL);
71 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
72 : input_(input), label_(label ? label : input)
74 BOOST_ASSERT(input && input->objclass == FL_INPUT);
78 bool CheckedLyXLength::check() const
80 string const str = getString(input_);
81 bool const valid = !isActive(input_) || str.empty()
82 || isStrDbl(str) || isValidLength(str);
84 // set the color of label and input widget
85 setWidget(valid, input_, label_);
91 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
92 : input_(input), label_(label ? label : input)
94 BOOST_ASSERT(input && input->objclass == FL_INPUT);
98 bool CheckedGlueLength::check() const
100 string const str = getString(input_);
101 bool const valid = !isActive(input_) || str.empty()
102 || isStrDbl(str) || isValidGlueLength(str);
104 // set the color of label and input widget
105 setWidget(valid, input_, label_);
110 } // namespace frontend