mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-03 08:28:25 +00:00
Rob's patch, part 1: the checked widget stuff.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5467 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4768f36a2f
commit
649e3fee9a
@ -29,17 +29,22 @@ template <class Button, class Widget>
|
|||||||
void GuiBC<Button, Widget>::refresh()
|
void GuiBC<Button, Widget>::refresh()
|
||||||
{
|
{
|
||||||
lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
|
lyxerr[Debug::GUI] << "Calling BC refresh()" << std::endl;
|
||||||
|
|
||||||
|
bool const all_valid = checkWidgets();
|
||||||
|
|
||||||
if (okay_) {
|
if (okay_) {
|
||||||
bool const enabled = bp().buttonStatus(ButtonPolicy::OKAY);
|
bool const enabled =
|
||||||
|
all_valid && bp().buttonStatus(ButtonPolicy::OKAY);
|
||||||
setButtonEnabled(okay_, enabled);
|
setButtonEnabled(okay_, enabled);
|
||||||
}
|
}
|
||||||
if (apply_) {
|
if (apply_) {
|
||||||
bool const enabled = bp().buttonStatus(ButtonPolicy::APPLY);
|
bool const enabled =
|
||||||
|
all_valid && bp().buttonStatus(ButtonPolicy::APPLY);
|
||||||
setButtonEnabled(apply_, enabled);
|
setButtonEnabled(apply_, enabled);
|
||||||
}
|
}
|
||||||
if (restore_) {
|
if (restore_) {
|
||||||
bool const enabled = bp().buttonStatus(ButtonPolicy::RESTORE);
|
bool const enabled =
|
||||||
|
all_valid && bp().buttonStatus(ButtonPolicy::RESTORE);
|
||||||
setButtonEnabled(restore_, enabled);
|
setButtonEnabled(restore_, enabled);
|
||||||
}
|
}
|
||||||
if (cancel_) {
|
if (cancel_) {
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
CheckedWidget::~CheckedWidget()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
ButtonControllerBase::ButtonControllerBase(string const & cancel,
|
ButtonControllerBase::ButtonControllerBase(string const & cancel,
|
||||||
string const & close)
|
string const & close)
|
||||||
: cancel_label_(cancel), close_label_(close)
|
: cancel_label_(cancel), close_label_(close)
|
||||||
@ -98,3 +102,27 @@ void ButtonControllerBase::readWrite()
|
|||||||
{
|
{
|
||||||
readOnly(false);
|
readOnly(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ButtonControllerBase::addCheckedWidget(CheckedWidget * ptr)
|
||||||
|
{
|
||||||
|
if (ptr)
|
||||||
|
checked_widgets.push_back(checked_widget_ptr(ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ButtonControllerBase::checkWidgets()
|
||||||
|
{
|
||||||
|
bool valid = true;
|
||||||
|
|
||||||
|
checked_widget_list::const_iterator it = checked_widgets.begin();
|
||||||
|
checked_widget_list::const_iterator end = checked_widgets.end();
|
||||||
|
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
valid &= (*it)->check();
|
||||||
|
}
|
||||||
|
|
||||||
|
// return valid status after checking ALL widgets
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,21 @@
|
|||||||
#include "ButtonPolicies.h"
|
#include "ButtonPolicies.h"
|
||||||
#include "LString.h"
|
#include "LString.h"
|
||||||
|
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
struct CheckedWidget {
|
||||||
|
///
|
||||||
|
virtual ~CheckedWidget();
|
||||||
|
|
||||||
|
/** Returns true if the widget is in a valid state.
|
||||||
|
* Might also change the visual appearance of the widget,
|
||||||
|
* to reflect this state.
|
||||||
|
*/
|
||||||
|
virtual bool check() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/** Abstract base class for a ButtonController
|
/** Abstract base class for a ButtonController
|
||||||
|
|
||||||
* Controls the activation of the OK, Apply and Cancel buttons.
|
* Controls the activation of the OK, Apply and Cancel buttons.
|
||||||
@ -69,11 +84,23 @@ public:
|
|||||||
void valid(bool = true);
|
void valid(bool = true);
|
||||||
///
|
///
|
||||||
void invalid();
|
void invalid();
|
||||||
|
///
|
||||||
|
void addCheckedWidget(CheckedWidget * ptr);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
string cancel_label_;
|
string cancel_label_;
|
||||||
///
|
///
|
||||||
string close_label_;
|
string close_label_;
|
||||||
|
///
|
||||||
|
bool checkWidgets();
|
||||||
|
|
||||||
|
private:
|
||||||
|
///
|
||||||
|
typedef boost::shared_ptr<CheckedWidget> checked_widget_ptr;
|
||||||
|
typedef std::list<checked_widget_ptr> checked_widget_list;
|
||||||
|
///
|
||||||
|
checked_widget_list checked_widgets;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BUTTONCONTROLLERBASE_H
|
#endif // BUTTONCONTROLLERBASE_H
|
||||||
|
@ -1,3 +1,21 @@
|
|||||||
|
2002-10-22 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* Makefile.am (libcontrollers_la_SOURCES): arrange list into
|
||||||
|
alphabetical order once again.
|
||||||
|
|
||||||
|
* ButtonControllerBase.[Ch]: define an abstract base class CheckedWidget
|
||||||
|
Add a list of CheckedWidget ptrs to ButtonControllerBase
|
||||||
|
together with methods addCheckedWidget and checkWidgets to use it.
|
||||||
|
|
||||||
|
* ButtonController.tmpl (refresh): use the return value of
|
||||||
|
checkWidgets to control the activation state of the Ok, Apply, Restore
|
||||||
|
buttons.
|
||||||
|
|
||||||
|
* ControlDialog.tmpl (show, update):
|
||||||
|
* ControlInset.tmpl (showInset, update):
|
||||||
|
invoke ButtonController::refresh to ensure that the activation state of
|
||||||
|
the Ok, Apply buttons reflects the valid-state of the widgets.
|
||||||
|
|
||||||
2002-10-21 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
2002-10-21 Lars Gullik Bjønnes <larsbj@birdstep.com>
|
||||||
|
|
||||||
* tex_helpers.C (rescanTexStyles): don't pop p
|
* tex_helpers.C (rescanTexStyles): don't pop p
|
||||||
|
@ -45,6 +45,9 @@ void ControlDialog<Base>::show()
|
|||||||
|
|
||||||
bc().readOnly(bufferIsReadonly());
|
bc().readOnly(bufferIsReadonly());
|
||||||
view().show();
|
view().show();
|
||||||
|
|
||||||
|
// The widgets may not be valid, so refresh the button controller
|
||||||
|
bc().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Base>
|
template <class Base>
|
||||||
@ -61,6 +64,9 @@ void ControlDialog<Base>::update()
|
|||||||
|
|
||||||
bc().readOnly(bufferIsReadonly());
|
bc().readOnly(bufferIsReadonly());
|
||||||
view().update();
|
view().update();
|
||||||
|
|
||||||
|
// The widgets may not be valid, so refresh the button controller
|
||||||
|
bc().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Base>
|
template <class Base>
|
||||||
|
@ -34,6 +34,9 @@ void ControlInset<Inset, Params>::showInset(Inset * inset)
|
|||||||
|
|
||||||
connectInset(inset);
|
connectInset(inset);
|
||||||
show(getParams(*inset));
|
show(getParams(*inset));
|
||||||
|
|
||||||
|
// The widgets may not be valid, so refresh the button controller
|
||||||
|
bc().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,6 +94,9 @@ void ControlInset<Inset, Params>::update()
|
|||||||
|
|
||||||
bc().readOnly(bufferIsReadonly());
|
bc().readOnly(bufferIsReadonly());
|
||||||
view().update();
|
view().update();
|
||||||
|
|
||||||
|
// The widgets may not be valid, so refresh the button controller
|
||||||
|
bc().refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,8 +52,6 @@ libcontrollers_la_SOURCES= \
|
|||||||
ControlExternal.h \
|
ControlExternal.h \
|
||||||
ControlFloat.C \
|
ControlFloat.C \
|
||||||
ControlFloat.h \
|
ControlFloat.h \
|
||||||
ControlWrap.C \
|
|
||||||
ControlWrap.h \
|
|
||||||
ControlForks.C \
|
ControlForks.C \
|
||||||
ControlForks.h \
|
ControlForks.h \
|
||||||
ControlGraphics.C \
|
ControlGraphics.C \
|
||||||
@ -97,6 +95,8 @@ libcontrollers_la_SOURCES= \
|
|||||||
ControlUrl.h \
|
ControlUrl.h \
|
||||||
ControlVCLog.C \
|
ControlVCLog.C \
|
||||||
ControlVCLog.h \
|
ControlVCLog.h \
|
||||||
|
ControlWrap.C \
|
||||||
|
ControlWrap.h \
|
||||||
GUI.h \
|
GUI.h \
|
||||||
ViewBase.h \
|
ViewBase.h \
|
||||||
helper_funcs.C \
|
helper_funcs.C \
|
||||||
|
@ -1,3 +1,14 @@
|
|||||||
|
2002-10-22 Angus Leeming <leeming@lyx.org>
|
||||||
|
|
||||||
|
* Makefile.am (libxforms_la_SOURCES): arrange list into alphabetical
|
||||||
|
order once again.
|
||||||
|
Add checkedwidgets.[Ch].
|
||||||
|
|
||||||
|
* checkedwidgets.[Ch]: new files, defining CheckedLyXLength and
|
||||||
|
CheckedGlueLength.
|
||||||
|
|
||||||
|
* xforms_helpers.[Ch] (isActive): new helper function.
|
||||||
|
|
||||||
2002-10-21 Lars Gullik Bjønnes <larsbj@gullik.net>
|
2002-10-21 Lars Gullik Bjønnes <larsbj@gullik.net>
|
||||||
|
|
||||||
* xfont_loader.C (doLoad): typo
|
* xfont_loader.C (doLoad): typo
|
||||||
|
@ -23,6 +23,8 @@ libxforms_la_SOURCES = \
|
|||||||
forms_gettext.h \
|
forms_gettext.h \
|
||||||
bmtable.c \
|
bmtable.c \
|
||||||
bmtable.h \
|
bmtable.h \
|
||||||
|
checkedwidgets.C \
|
||||||
|
checkedwidgets.h \
|
||||||
combox.C \
|
combox.C \
|
||||||
combox.h \
|
combox.h \
|
||||||
input_validators.C \
|
input_validators.C \
|
||||||
@ -85,8 +87,6 @@ libxforms_la_SOURCES = \
|
|||||||
FormExternal.h \
|
FormExternal.h \
|
||||||
FormFloat.C \
|
FormFloat.C \
|
||||||
FormFloat.h \
|
FormFloat.h \
|
||||||
FormWrap.C \
|
|
||||||
FormWrap.h \
|
|
||||||
FormForks.C \
|
FormForks.C \
|
||||||
FormForks.h \
|
FormForks.h \
|
||||||
FormGraphics.C \
|
FormGraphics.C \
|
||||||
@ -147,6 +147,8 @@ libxforms_la_SOURCES = \
|
|||||||
FormUrl.h \
|
FormUrl.h \
|
||||||
FormVCLog.C \
|
FormVCLog.C \
|
||||||
FormVCLog.h \
|
FormVCLog.h \
|
||||||
|
FormWrap.C \
|
||||||
|
FormWrap.h \
|
||||||
LyXKeySymFactory.C \
|
LyXKeySymFactory.C \
|
||||||
LyXScreenFactory.C \
|
LyXScreenFactory.C \
|
||||||
MathsCallbacks.h \
|
MathsCallbacks.h \
|
||||||
|
105
src/frontends/xforms/checkedwidgets.C
Normal file
105
src/frontends/xforms/checkedwidgets.C
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
/**
|
||||||
|
* \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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace anon
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
63
src/frontends/xforms/checkedwidgets.h
Normal file
63
src/frontends/xforms/checkedwidgets.h
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// -*- 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
|
@ -35,6 +35,12 @@ using std::ofstream;
|
|||||||
using std::pair;
|
using std::pair;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
|
bool isActive(FL_OBJECT * ob)
|
||||||
|
{
|
||||||
|
return ob && ob->active > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set an FL_OBJECT to activated or deactivated
|
// Set an FL_OBJECT to activated or deactivated
|
||||||
void setEnabled(FL_OBJECT * ob, bool enable)
|
void setEnabled(FL_OBJECT * ob, bool enable)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,9 @@ string const choice_Length_All =
|
|||||||
string const choice_Length_WithUnit =
|
string const choice_Length_WithUnit =
|
||||||
"cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu"; // all with a Unit
|
"cm|mm|in|ex|em|pt|sp|bp|dd|pc|cc|mu"; // all with a Unit
|
||||||
|
|
||||||
|
/// return the (in)active state of the object
|
||||||
|
bool isActive(FL_OBJECT * ob);
|
||||||
|
|
||||||
/// Set an FL_OBJECT to activated or deactivated
|
/// Set an FL_OBJECT to activated or deactivated
|
||||||
void setEnabled(FL_OBJECT *, bool enable);
|
void setEnabled(FL_OBJECT *, bool enable);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user