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 #pragma implementation
17 #include "checkedwidgets.h"
18 #include "xforms_helpers.h"
19 #include "lyxlength.h"
20 #include "lyxgluelength.h"
21 #include "support/LAssert.h"
22 #include "support/lstrings.h"
25 #include FORMS_H_LOCATION
28 void addCheckedLyXLength(ButtonControllerBase & bc,
29 FL_OBJECT * input, FL_OBJECT * label)
31 bc.addCheckedWidget(new CheckedLyXLength(input, label));
35 void addCheckedGlueLength(ButtonControllerBase & bc,
36 FL_OBJECT * input, FL_OBJECT * label)
38 bc.addCheckedWidget(new CheckedGlueLength(input, label));
44 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
46 // define color to mark invalid input
47 FL_COLOR const alert_col = FL_RED;
49 FL_COLOR const lcol = valid ? FL_LCOL : alert_col;
50 if (label->lcol != lcol && isActive(label)) {
51 fl_set_object_lcol(label, lcol);
53 if (input->lcol != lcol && isActive(input)) {
54 fl_set_object_lcol(input, lcol);
57 // Reflect the validity of the data in the background color of the
58 // input widget only when this widget is not being edited.
59 FL_COLOR const icol1 = valid ? FL_COL1 : alert_col;
60 if (input->col1 != icol1) {
61 fl_set_object_color(input, icol1, FL_MCOL);
68 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
69 : input_(input), label_(label ? label : input)
71 lyx::Assert(input && input->objclass == FL_INPUT);
75 bool CheckedLyXLength::check() const
77 string const str = getString(input_);
78 bool const valid = !isActive(input_) || str.empty()
79 || isStrDbl(str) || isValidLength(str);
81 // set the color of label and input widget
82 setWidget(valid, input_, label_);
88 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
89 : input_(input), label_(label ? label : input)
91 lyx::Assert(input && input->objclass == FL_INPUT);
95 bool CheckedGlueLength::check() const
97 string const str = getString(input_);
98 bool const valid = !isActive(input_) || str.empty()
99 || isStrDbl(str) || isValidGlueLength(str);
101 // set the color of label and input widget
102 setWidget(valid, input_, label_);