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"
24 using namespace lyx::support;
26 void addCheckedLyXLength(BCView & bcview,
27 FL_OBJECT * input, FL_OBJECT * label)
29 bcview.addCheckedWidget(new CheckedLyXLength(input, label));
33 void addCheckedGlueLength(BCView & bcview,
34 FL_OBJECT * input, FL_OBJECT * label)
36 bcview.addCheckedWidget(new CheckedGlueLength(input, label));
42 void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
44 // define color to mark invalid input
45 FL_COLOR const alert_col = FL_RED;
47 FL_COLOR const lcol = valid ? FL_COLOR(FL_LCOL) : alert_col;
48 if (label->lcol != lcol && isActive(label)) {
49 fl_set_object_lcol(label, lcol);
51 if (input->lcol != lcol && isActive(input)) {
52 fl_set_object_lcol(input, lcol);
55 // Reflect the validity of the data in the background color of the
56 // input widget only when this widget is not being edited.
57 FL_COLOR const icol1 = valid ? FL_COLOR(FL_COL1) : alert_col;
58 if (input->col1 != icol1) {
59 fl_set_object_color(input, icol1, FL_MCOL);
66 CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
67 : input_(input), label_(label ? label : input)
69 Assert(input && input->objclass == FL_INPUT);
73 bool CheckedLyXLength::check() const
75 string const str = getString(input_);
76 bool const valid = !isActive(input_) || str.empty()
77 || isStrDbl(str) || isValidLength(str);
79 // set the color of label and input widget
80 setWidget(valid, input_, label_);
86 CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
87 : input_(input), label_(label ? label : input)
89 Assert(input && input->objclass == FL_INPUT);
93 bool CheckedGlueLength::check() const
95 string const str = getString(input_);
96 bool const valid = !isActive(input_) || str.empty()
97 || isStrDbl(str) || isValidGlueLength(str);
99 // set the color of label and input widget
100 setWidget(valid, input_, label_);