Angus Leeming wrote:
On Tuesday 22 October 2002 11:55 am, Rob Lahaye wrote:
Well, then we would totally miss the point of my patch.
I made the non-xforms changes ONLY to support better GUI
Xforms dialogs.
Bear with me and send the new files too.
OK! You've got my full support !
Here you go:
src/frontends/xforms/checkedwidgets.C
src/frontends/xforms/checkedwidgets.h
And
src/frontends/Liason.C
src/frontends/Liason.h
should go completely.
Rob.
/**
* \file checkedwidgets.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "checkedwidgets.h"
#include "xforms_helpers.h"
#include "lyxlength.h"
#include "lyxgluelength.h"
#include "support/LAssert.h"
#include "support/lstrings.h"
#include "LString.h"
#include FORMS_H_LOCATION
void addCheckedLyXLength(ButtonControllerBase & bc,
FL_OBJECT * input, FL_OBJECT * label)
{
bc.addCheckedWidget(new CheckedLyXLength(input, label));
}
void addCheckedGlueLength(ButtonControllerBase & bc,
FL_OBJECT * input, FL_OBJECT * label)
{
bc.addCheckedWidget(new CheckedGlueLength(input, label));
}
void setWidget(bool valid, FL_OBJECT * input, FL_OBJECT * label)
{
// define color to mark invalid input
FL_COLOR const alert_col = FL_RED;
FL_COLOR const lcol = valid ? FL_LCOL : alert_col;
if (label->lcol != lcol && isActive(label)) {
fl_set_object_lcol(label, lcol);
}
if (input->lcol != lcol && isActive(input)) {
fl_set_object_lcol(input, lcol);
}
// set background color of input widget
FL_COLOR const icol1 = valid ? FL_INPUT_COL1 : alert_col;
FL_COLOR const icol2 = valid ? FL_INPUT_COL2 : alert_col;
if (input->col1 != icol1 || input->col2 != icol2) {
fl_set_object_color(input, icol1, icol2);
}
}
CheckedLyXLength::CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label)
: input_(input), label_(label ? label : input)
{
lyx::Assert(input && input->objclass == FL_INPUT);
}
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)
{
lyx::Assert(input && input->objclass == FL_INPUT);
}
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;
}
// -*- C++ -*-
/**
* \file checkedwidgets.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Angus Leeming
*
* Full author contact details are available in file CREDITS
*/
#ifndef CHECKEDWIDGETS_H
#define CHECKEDWIDGETS_H
#ifdef __GNUG__
#pragma interface
#endif
#include "ButtonControllerBase.h"
#include "forms_fwd.h"
void addCheckedLyXLength(ButtonControllerBase & bc,
FL_OBJECT * input, FL_OBJECT * label = 0);
void addCheckedGlueLength(ButtonControllerBase & bc,
FL_OBJECT * input, FL_OBJECT * label = 0);
class CheckedLyXLength : public CheckedWidget {
public:
/** The label widget's label will be turned red if input
* does not make a valid LyXLength.
* If label == 0, then the label of input will be used.
*/
CheckedLyXLength(FL_OBJECT * input, FL_OBJECT * label = 0);
private:
///
virtual bool check() const;
///
FL_OBJECT * input_;
FL_OBJECT * label_;
};
class CheckedGlueLength : public CheckedWidget {
public:
/** The label widget's label will be turned red if input
* does not make a valid LyXGlueLength.
* If label == 0, then the label of input will be used.
*/
CheckedGlueLength(FL_OBJECT * input, FL_OBJECT * label = 0);
private:
///
virtual bool check() const;
///
FL_OBJECT * input_;
FL_OBJECT * label_;
};
#endif // CHECKEDWIDGETS_H