2002-10-22 12:39:05 +00:00
|
|
|
/**
|
2003-12-04 16:56:49 +00:00
|
|
|
* \file xforms/checkedwidgets.C
|
2002-10-22 12:39:05 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Angus Leeming
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-10-22 12:39:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include "checkedwidgets.h"
|
|
|
|
#include "xforms_helpers.h"
|
|
|
|
#include "lyxgluelength.h"
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2002-10-22 12:39:05 +00:00
|
|
|
#include "support/lstrings.h"
|
|
|
|
|
2003-05-14 09:17:22 +00:00
|
|
|
#include "lyx_forms.h"
|
2002-10-22 12:39:05 +00:00
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
using lyx::support::isStrDbl;
|
2002-10-22 12:39:05 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
|
|
|
|
2003-09-05 13:15:43 +00:00
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
void addCheckedLyXLength(BCView & bcview,
|
2002-10-22 12:39:05 +00:00
|
|
|
FL_OBJECT * input, FL_OBJECT * label)
|
|
|
|
{
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview.addCheckedWidget(new CheckedLyXLength(input, label));
|
2002-10-22 12:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-10 03:13:28 +00:00
|
|
|
void addCheckedGlueLength(BCView & bcview,
|
2002-10-22 12:39:05 +00:00
|
|
|
FL_OBJECT * input, FL_OBJECT * label)
|
|
|
|
{
|
2003-03-10 03:13:28 +00:00
|
|
|
bcview.addCheckedWidget(new CheckedGlueLength(input, label));
|
2002-10-22 12:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
|
|
|
|
{
|
|
|
|
// define color to mark invalid input
|
|
|
|
FL_COLOR const alert_col = FL_RED;
|
2002-11-24 15:20:31 +00:00
|
|
|
|
2002-12-01 21:10:37 +00:00
|
|
|
FL_COLOR const lcol = valid ? FL_COLOR(FL_LCOL) : alert_col;
|
2002-10-22 12:39:05 +00:00
|
|
|
if (label->lcol != lcol && isActive(label)) {
|
|
|
|
fl_set_object_lcol(label, lcol);
|
|
|
|
}
|
|
|
|
if (input->lcol != lcol && isActive(input)) {
|
|
|
|
fl_set_object_lcol(input, lcol);
|
|
|
|
}
|
|
|
|
|
2002-10-23 13:15:32 +00:00
|
|
|
// Reflect the validity of the data in the background color of the
|
|
|
|
// input widget only when this widget is not being edited.
|
2002-12-01 21:10:37 +00:00
|
|
|
FL_COLOR const icol1 = valid ? FL_COLOR(FL_COL1) : alert_col;
|
2002-10-23 13:15:32 +00:00
|
|
|
if (input->col1 != icol1) {
|
|
|
|
fl_set_object_color(input, icol1, FL_MCOL);
|
2002-10-22 12:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
2002-11-24 15:20:31 +00:00
|
|
|
|
2002-10-22 12:39:05 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
|
CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
|
|
|
|
: input_(input), label_(label ? label : input)
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(input && input->objclass == FL_INPUT);
|
2002-10-22 12:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CheckedLyXLength::check() const
|
|
|
|
{
|
|
|
|
string const str = getString(input_);
|
|
|
|
bool const valid = !isActive(input_) || str.empty()
|
|
|
|
|| isStrDbl(str) || isValidLength(str);
|
|
|
|
|
|
|
|
// set the color of label and input widget
|
|
|
|
setWidget(valid, input_, label_);
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CheckedGlueLength::CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label)
|
|
|
|
: input_(input), label_(label ? label : input)
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(input && input->objclass == FL_INPUT);
|
2002-10-22 12:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CheckedGlueLength::check() const
|
|
|
|
{
|
|
|
|
string const str = getString(input_);
|
|
|
|
bool const valid = !isActive(input_) || str.empty()
|
|
|
|
|| isStrDbl(str) || isValidGlueLength(str);
|
|
|
|
|
|
|
|
// set the color of label and input widget
|
|
|
|
setWidget(valid, input_, label_);
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
}
|