Make more use of the feedback controller routines.

Reduce the amount of repeated code in FormParagraph.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3790 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2002-03-20 17:53:39 +00:00
parent 8eeed19540
commit 293a38272a
8 changed files with 337 additions and 280 deletions

View File

@ -3,6 +3,20 @@
* xforms_helpers.C (setCursorColor):
* Tooltips.C (set): remove XC_question_arrow code.
* FeedbackController.[Ch] (clearMessage): new method.
* FeedbackController.C (postMessage): the warning message is now
displayed in red!
* FormParagraph.C: define some helper functions to minimise the amount
of repeated code.
* FormDocument.C:
* FormGraphics.C:
* FormMinipage.C:
* FormTabular.C: use the FeedbackController to post the warning
messages.
2002-03-19 André Pönitz <poenitz@gmx.net>
* FormParagraph.C: whitespace changes

View File

@ -23,6 +23,7 @@
#include "xforms_helpers.h" // formatted
#include "support/LAssert.h"
FeedbackController::FeedbackController()
: warning_posted_(false), message_widget_(0)
{}
@ -34,8 +35,9 @@ FeedbackController::~FeedbackController()
void FeedbackController::setMessageWidget(FL_OBJECT * ob)
{
lyx::Assert(ob && ob->objclass == FL_TEXT);
lyx::Assert(ob && ob->objclass == FL_TEXT);
message_widget_ = ob;
fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
}
@ -45,14 +47,20 @@ void FeedbackController::MessageCB(FL_OBJECT * ob, int event)
lyx::Assert(ob);
switch (event) {
case FL_ENTER:
case FL_ENTER:
{
string const feedback = getFeedback(ob);
if (feedback.empty() && warning_posted_)
break;
warning_posted_ = false;
postMessage(getFeedback(ob));
break;
}
case FL_LEAVE:
if (!warning_posted_)
fl_set_object_label(message_widget_, "");
clearMessage();
break;
default:
@ -86,6 +94,24 @@ void FeedbackController::postWarning(string const & warning)
}
void FeedbackController::clearMessage()
{
lyx::Assert(message_widget_);
warning_posted_ = false;
string const existing = message_widget_->label
? message_widget_->label : string();
if (existing.empty())
return;
// This trick is needed to get xforms to clear the label...
fl_hide_object(message_widget_);
fl_set_object_label(message_widget_, "");
fl_show_object(message_widget_);
}
void FeedbackController::postMessage(string const & message)
{
lyx::Assert(message_widget_);
@ -94,5 +120,6 @@ void FeedbackController::postMessage(string const & message)
message_widget_->w-10, FL_SMALL_SIZE);
fl_set_object_label(message_widget_, str.c_str());
fl_set_object_lsize(message_widget_, FL_SMALL_SIZE);
FL_COLOR const label_color = warning_posted_ ? FL_TOMATO : FL_BLACK;
fl_set_object_lcol(message_widget_, label_color);
}

View File

@ -52,6 +52,8 @@ protected:
message_widget direct. The message will persist till the mouse
movesto a new object. */
void postWarning(string const & warning);
/// Reset the message_widget_
void clearMessage();
private:
/** Get the feedback message for ob.

View File

@ -92,6 +92,9 @@ void FormDocument::build()
// the tabbed folder
dialog_.reset(build_tabbed_document());
// Allow the base class to control messages
setMessageWidget(dialog_->text_warning);
// Manage the restore, ok, apply, restore and cancel/close buttons
bc().setOK(dialog_->button_ok);
bc().setApply(dialog_->button_apply);
@ -1224,14 +1227,12 @@ void FormDocument::checkReadOnly()
if (bc().readOnly(lv_->buffer()->isReadonly())) {
combo_doc_class->deactivate();
combo_language->deactivate();
fl_set_object_label(dialog_->text_warning,
_("Document is read-only."
" No changes to layout permitted."));
fl_show_object(dialog_->text_warning);
postWarning(_("Document is read-only."
" No changes to layout permitted."));
} else {
combo_doc_class->activate();
combo_language->activate();
fl_hide_object(dialog_->text_warning);
clearMessage();
}
}
@ -1278,12 +1279,10 @@ bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long)
|| ob == paper_->input_head_sep
|| ob == paper_->input_foot_skip) {
if (!ok) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length (valid example: 10mm)"));
fl_show_object(dialog_->text_warning);
postWarning(_("Invalid Length (valid example: 10mm)"));
return false;
} else {
fl_hide_object(dialog_->text_warning);
clearMessage();
return true;
}
}

View File

@ -65,6 +65,9 @@ void FormGraphics::build()
{
dialog_.reset(build_graphics());
// Allow the base class to control messages
setMessageWidget(dialog_->text_warning);
// Manage the ok, apply, restore and cancel/close buttons
bc().setOK(dialog_->button_ok);
bc().setApply(dialog_->button_apply);
@ -642,12 +645,10 @@ ButtonPolicy::SMInput FormGraphics::input(FL_OBJECT * ob, long)
ob == size_->input_width || ob == size_->input_height ||
ob == lyxview_->input_lyxwidth || ob == lyxview_->input_lyxheight) {
if (invalid) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length!"));
fl_show_object(dialog_->text_warning);
postWarning(_("Invalid Length!"));
return ButtonPolicy::SMI_INVALID;
} else {
fl_hide_object(dialog_->text_warning);
clearMessage();
}
}

View File

@ -32,6 +32,9 @@ void FormMinipage::build()
{
dialog_.reset(build_minipage());
// Allow the base class to control messages
setMessageWidget(dialog_->text_warning);
fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED);
setPrehandler(dialog_->input_width);
@ -56,7 +59,7 @@ void FormMinipage::apply()
{
controller().params().pageWidth =
LyXLength(getLengthFromWidgets(dialog_->input_width,
dialog_->choice_width_units));
dialog_->choice_width_units));
if (fl_get_button(dialog_->radio_top))
controller().params().pos = InsetMinipage::top;
@ -69,31 +72,34 @@ void FormMinipage::apply()
void FormMinipage::update()
{
LyXLength len(controller().params().pageWidth);
fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
LyXLength len(controller().params().pageWidth);
fl_set_input(dialog_->input_width, tostr(len.value()).c_str());
fl_set_choice(dialog_->choice_width_units, len.unit() + 1);
switch (controller().params().pos) {
case InsetMinipage::top:
fl_set_button(dialog_->radio_top, 1);
break;
case InsetMinipage::center:
fl_set_button(dialog_->radio_middle, 1);
break;
case InsetMinipage::bottom:
fl_set_button(dialog_->radio_bottom, 1);
break;
}
switch (controller().params().pos) {
case InsetMinipage::top:
fl_set_button(dialog_->radio_top, 1);
break;
case InsetMinipage::center:
fl_set_button(dialog_->radio_middle, 1);
break;
case InsetMinipage::bottom:
fl_set_button(dialog_->radio_bottom, 1);
break;
}
}
ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
{
clearMessage();
ButtonPolicy::SMInput action = ButtonPolicy::SMI_NOOP;
if (ob == dialog_->radio_top ||
ob == dialog_->radio_middle ||
ob == dialog_->radio_bottom ||
ob == dialog_->choice_width_units)
ob == dialog_->radio_middle ||
ob == dialog_->radio_bottom ||
ob == dialog_->choice_width_units)
return ButtonPolicy::SMI_VALID;
// disallow senseless data
@ -102,12 +108,9 @@ ButtonPolicy::SMInput FormMinipage::input(FL_OBJECT * ob, long)
string const input = getStringFromInput(dialog_->input_width);
bool const invalid = !isValidLength(input) && !isStrDbl(input);
if (invalid) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length!"));
fl_show_object(dialog_->text_warning);
postWarning(_("Invalid Length!"));
action = ButtonPolicy::SMI_INVALID;
} else {
fl_hide_object(dialog_->text_warning);
action = ButtonPolicy::SMI_VALID;
}
}

View File

@ -31,6 +31,7 @@
#include "helper_funcs.h"
#include "support/lstrings.h"
#include "support/LAssert.h"
#include <functional>
@ -44,10 +45,10 @@ using std::remove_if;
FormParagraph::FormParagraph(LyXView * lv, Dialogs * d)
: FormBaseBD(lv, d, _("Paragraph Layout")), par_(0)
{
// let the dialog be shown
// This is a permanent connection so we won't bother
// storing a copy because we won't be disconnecting.
d->showParagraph.connect(slot(this, &FormParagraph::show));
// let the dialog be shown
// This is a permanent connection so we won't bother
// storing a copy because we won't be disconnecting.
d->showParagraph.connect(slot(this, &FormParagraph::show));
}
@ -111,6 +112,9 @@ void FormParagraph::build()
// the tabbed folder
dialog_.reset(build_paragraph());
// Allow the base class to control messages
setMessageWidget(dialog_->text_warning);
fl_addto_choice(dialog_->choice_space_above,
_(" None | Defskip | Smallskip "
"| Medskip | Bigskip | VFill | Length "));
@ -123,7 +127,7 @@ void FormParagraph::build()
fl_set_input_return(dialog_->input_space_above, FL_RETURN_CHANGED);
fl_set_input_return(dialog_->input_space_below, FL_RETURN_CHANGED);
fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
fl_set_input_return(dialog_->input_labelwidth, FL_RETURN_CHANGED);
fl_set_input_return(dialog_->input_linespacing, FL_RETURN_CHANGED);
fl_set_input_filter(dialog_->input_linespacing, fl_unsigned_float_filter);
@ -151,7 +155,7 @@ void FormParagraph::build()
string units = getStringFromVector(units_vec, "|");
fl_addto_choice(dialog_->choice_value_space_above, units.c_str());
fl_addto_choice(dialog_->choice_value_space_above, units.c_str());
fl_addto_choice(dialog_->choice_value_space_below, units.c_str());
// Manage the ok, apply, restore and cancel/close buttons
@ -181,17 +185,63 @@ void FormParagraph::build()
}
namespace {
VSpace setVSpaceFromWidgets(FL_OBJECT * choice_type,
FL_OBJECT * input_length,
FL_OBJECT * choice_length,
FL_OBJECT * check_keep)
{
// Paranoia check!
lyx::Assert(choice_type && choice_type->objclass == FL_CHOICE &&
input_length && input_length->objclass == FL_INPUT &&
choice_length && choice_length->objclass == FL_CHOICE &&
check_keep && check_keep->objclass == FL_CHECKBUTTON);
VSpace space;
switch (fl_get_choice(choice_type)) {
case 1:
space = VSpace(VSpace::NONE);
break;
case 2:
space = VSpace(VSpace::DEFSKIP);
break;
case 3:
space = VSpace(VSpace::SMALLSKIP);
break;
case 4:
space = VSpace(VSpace::MEDSKIP);
break;
case 5:
space = VSpace(VSpace::BIGSKIP);
break;
case 6:
space = VSpace(VSpace::VFILL);
break;
case 7:
{
string const length =
getLengthFromWidgets(input_length, choice_length);
space = VSpace(LyXGlueLength(length));
break;
}
}
if (fl_get_button(check_keep))
space.setKeep(true);
return space;
}
} // namespace anon
void FormParagraph::apply()
{
if (!lv_->view()->available() || !dialog_.get())
return;
VSpace space_top;
VSpace space_bottom;
LyXAlignment align;
string labelwidthstring;
bool noindent;
// If a vspace kind is "Length" but there's no text in
// the input field, reset the kind to "None".
if ((fl_get_choice(dialog_->choice_space_above) == 7) &&
@ -206,70 +256,24 @@ void FormParagraph::apply()
fl_set_choice(dialog_->choice_space_below, 1);
}
bool line_top = fl_get_button(dialog_->check_lines_top);
bool line_bottom = fl_get_button(dialog_->check_lines_bottom);
bool pagebreak_top = fl_get_button(dialog_->check_pagebreaks_top);
bool pagebreak_bottom = fl_get_button(dialog_->check_pagebreaks_bottom);
bool const line_top = fl_get_button(dialog_->check_lines_top);
bool const line_bottom = fl_get_button(dialog_->check_lines_bottom);
bool const pagebreak_top = fl_get_button(dialog_->check_pagebreaks_top);
bool const pagebreak_bottom = fl_get_button(dialog_->check_pagebreaks_bottom);
switch (fl_get_choice(dialog_->choice_space_above)) {
case 1:
space_top = VSpace(VSpace::NONE);
break;
case 2:
space_top = VSpace(VSpace::DEFSKIP);
break;
case 3:
space_top = VSpace(VSpace::SMALLSKIP);
break;
case 4:
space_top = VSpace(VSpace::MEDSKIP);
break;
case 5:
space_top = VSpace(VSpace::BIGSKIP);
break;
case 6:
space_top = VSpace(VSpace::VFILL);
break;
case 7: {
string const length =
getLengthFromWidgets(dialog_->input_space_above,
dialog_->choice_value_space_above);
space_top = VSpace(LyXGlueLength(length));
break;
}
}
VSpace const space_top =
setVSpaceFromWidgets(dialog_->choice_space_above,
dialog_->input_space_above,
dialog_->choice_value_space_above,
dialog_->check_space_above);
if (fl_get_button(dialog_->check_space_above))
space_top.setKeep(true);
switch (fl_get_choice(dialog_->choice_space_below)) {
case 1:
space_bottom = VSpace(VSpace::NONE);
break;
case 2:
space_bottom = VSpace(VSpace::DEFSKIP);
break;
case 3:
space_bottom = VSpace(VSpace::SMALLSKIP);
break;
case 4:
space_bottom = VSpace(VSpace::MEDSKIP);
break;
case 5:
space_bottom = VSpace(VSpace::BIGSKIP);
break;
case 6:
space_bottom = VSpace(VSpace::VFILL);
break;
case 7:
string const length =
getLengthFromWidgets(dialog_->input_space_below,
dialog_->choice_value_space_below);
space_bottom = VSpace(LyXGlueLength(length));
break;
}
if (fl_get_button (dialog_->check_space_below))
space_bottom.setKeep (true);
VSpace const space_bottom =
setVSpaceFromWidgets(dialog_->choice_space_below,
dialog_->input_space_below,
dialog_->choice_value_space_below,
dialog_->check_space_below);
LyXAlignment align;
if (fl_get_button(dialog_->radio_align_left))
align = LYX_ALIGN_LEFT;
else if (fl_get_button(dialog_->radio_align_right))
@ -279,8 +283,11 @@ void FormParagraph::apply()
else
align = LYX_ALIGN_BLOCK;
labelwidthstring = fl_get_input(dialog_->input_labelwidth);
noindent = fl_get_button(dialog_->check_noindent);
string const labelwidthstring =
getStringFromInput(dialog_->input_labelwidth);
bool const noindent = fl_get_button(dialog_->check_noindent);
Spacing::Space linespacing = Spacing::Default;
string other_linespacing;
switch (fl_get_choice(dialog_->choice_linespacing)) {
@ -295,11 +302,11 @@ void FormParagraph::apply()
}
Spacing const spacing(linespacing, other_linespacing);
LyXText * text(lv_->view()->getLyXText());
text->setParagraph(lv_->view(), line_top, line_bottom, pagebreak_top,
pagebreak_bottom, space_top, space_bottom, spacing,
align, labelwidthstring, noindent);
pagebreak_bottom, space_top, space_bottom, spacing,
align, labelwidthstring, noindent);
// Actually apply these settings
lv_->view()->update(text,
@ -309,6 +316,66 @@ void FormParagraph::apply()
}
namespace {
void setWidgetsFromVSpace(VSpace const & space,
FL_OBJECT * choice_type,
FL_OBJECT * input_length,
FL_OBJECT * choice_length,
FL_OBJECT * check_keep)
{
// Paranoia check!
lyx::Assert(choice_type && choice_type->objclass == FL_CHOICE &&
input_length && input_length->objclass == FL_INPUT &&
choice_length && choice_length->objclass == FL_CHOICE &&
check_keep && check_keep->objclass == FL_CHECKBUTTON);
fl_set_input(input_length, "");
setEnabled(input_length, false);
setEnabled(choice_length, false);
switch (space.kind()) {
case VSpace::NONE:
fl_set_choice(choice_type, 1);
break;
case VSpace::DEFSKIP:
fl_set_choice(choice_type, 2);
break;
case VSpace::SMALLSKIP:
fl_set_choice(choice_type, 3);
break;
case VSpace::MEDSKIP:
fl_set_choice(choice_type, 4);
break;
case VSpace::BIGSKIP:
fl_set_choice(choice_type, 5);
break;
case VSpace::VFILL:
fl_set_choice(choice_type, 6);
break;
case VSpace::LENGTH:
{
fl_set_choice(choice_type, 7);
setEnabled(input_length, true);
setEnabled(choice_length, true);
bool const metric = lyxrc.default_papersize > 3;
string const default_unit = metric ? "cm" : "in";
string const length = space.length().asString();
updateWidgetsFromLengthString(input_length, choice_length,
length, default_unit);
break;
}
}
fl_set_button(check_keep, space.keep());
}
} // namespace anon
void FormParagraph::update()
{
if (!dialog_.get())
@ -317,22 +384,21 @@ void FormParagraph::update()
// Do this first; some objects may be de/activated subsequently.
bc_.readOnly(lv_->buffer()->isReadonly());
Buffer * buf = lv_->view()->buffer();
/// Record the paragraph
par_ = getCurrentParagraph();
fl_set_input(dialog_->input_labelwidth,
par_->getLabelWidthString().c_str());
par_->getLabelWidthString().c_str());
setEnabled(dialog_->input_labelwidth,
(par_->getLabelWidthString() != _("Senseless with this layout!")));
(par_->getLabelWidthString() != _("Senseless with this layout!")));
fl_set_button(dialog_->radio_align_right, 0);
fl_set_button(dialog_->radio_align_left, 0);
fl_set_button(dialog_->radio_align_center, 0);
fl_set_button(dialog_->radio_align_block, 0);
LyXTextClass const & tclass = textclasslist[buf->params.textclass];
LyXTextClass const & tclass =
textclasslist[lv_->view()->buffer()->params.textclass];
int align = par_->getAlign();
if (align == LYX_ALIGN_LAYOUT)
@ -365,15 +431,15 @@ void FormParagraph::update()
setEnabled(dialog_->check_pagebreaks_bottom, !par_->inInset());
fl_set_button(dialog_->check_lines_top,
par_->params().lineTop());
par_->params().lineTop());
fl_set_button(dialog_->check_lines_bottom,
par_->params().lineBottom());
par_->params().lineBottom());
fl_set_button(dialog_->check_pagebreaks_top,
par_->params().pagebreakTop());
par_->params().pagebreakTop());
fl_set_button(dialog_->check_pagebreaks_bottom,
par_->params().pagebreakBottom());
par_->params().pagebreakBottom());
fl_set_button(dialog_->check_noindent,
par_->params().noindent());
par_->params().noindent());
int linespacing;
Spacing const space = par_->params().spacing();
@ -396,95 +462,76 @@ void FormParagraph::update()
setEnabled(dialog_->input_linespacing, false);
}
fl_set_input (dialog_->input_space_above, "");
setEnabled(dialog_->input_space_above, false);
setEnabled(dialog_->choice_value_space_above, false);
switch (par_->params().spaceTop().kind()) {
case VSpace::NONE:
fl_set_choice (dialog_->choice_space_above, 1);
break;
case VSpace::DEFSKIP:
fl_set_choice (dialog_->choice_space_above, 2);
break;
case VSpace::SMALLSKIP:
fl_set_choice (dialog_->choice_space_above, 3);
break;
case VSpace::MEDSKIP:
fl_set_choice (dialog_->choice_space_above, 4);
break;
case VSpace::BIGSKIP:
fl_set_choice (dialog_->choice_space_above, 5);
break;
case VSpace::VFILL:
fl_set_choice (dialog_->choice_space_above, 6);
break;
case VSpace::LENGTH: {
fl_set_choice (dialog_->choice_space_above, 7);
setEnabled(dialog_->input_space_above, true);
setEnabled(dialog_->choice_value_space_above, true);
bool const metric = lyxrc.default_papersize > 3;
string const default_unit = metric ? "cm" : "in";
string const length = par_->params().spaceTop().length().asString();
updateWidgetsFromLengthString(dialog_->input_space_above,
dialog_->choice_value_space_above,
length, default_unit);
break;
}
}
fl_set_button (dialog_->check_space_above,
par_->params().spaceTop().keep());
fl_set_input (dialog_->input_space_below, "");
setEnabled(dialog_->input_space_below, false);
setEnabled(dialog_->choice_value_space_below, false);
switch (par_->params().spaceBottom().kind()) {
case VSpace::NONE:
fl_set_choice(dialog_->choice_space_below, 1);
break;
case VSpace::DEFSKIP:
fl_set_choice(dialog_->choice_space_below, 2);
break;
case VSpace::SMALLSKIP:
fl_set_choice(dialog_->choice_space_below, 3);
break;
case VSpace::MEDSKIP:
fl_set_choice(dialog_->choice_space_below, 4);
break;
case VSpace::BIGSKIP:
fl_set_choice(dialog_->choice_space_below, 5);
break;
case VSpace::VFILL:
fl_set_choice(dialog_->choice_space_below, 6);
break;
case VSpace::LENGTH: {
fl_set_choice(dialog_->choice_space_below, 7);
setEnabled(dialog_->input_space_below, true);
setEnabled(dialog_->choice_value_space_below, true);
bool const metric = lyxrc.default_papersize > 3;
string const default_unit = metric ? "cm" : "in";
string const length =
par_->params().spaceBottom().length().asString();
updateWidgetsFromLengthString(dialog_->input_space_below,
dialog_->choice_value_space_below,
length, default_unit);
break;
}
}
fl_set_button(dialog_->check_space_below,
par_->params().spaceBottom().keep());
setWidgetsFromVSpace(par_->params().spaceTop(),
dialog_->choice_space_above,
dialog_->input_space_above,
dialog_->choice_value_space_above,
dialog_->check_space_above);
setWidgetsFromVSpace(par_->params().spaceBottom(),
dialog_->choice_space_below,
dialog_->input_space_below,
dialog_->choice_value_space_below,
dialog_->check_space_below);
fl_set_button(dialog_->check_noindent,
par_->params().noindent());
par_->params().noindent());
}
namespace {
void synchronizeSpaceWidgets(FL_OBJECT * choice_type,
FL_OBJECT * input_length,
FL_OBJECT * choice_length,
bool readonly)
{
// Paranoia check!
lyx::Assert(choice_type && choice_type->objclass == FL_CHOICE &&
input_length && input_length->objclass == FL_INPUT &&
choice_length && choice_length->objclass == FL_CHOICE);
if (fl_get_choice(choice_type) != 7) {
fl_set_input(input_length, "");
setEnabled(input_length, false);
setEnabled(choice_length, false);
} else {
setEnabled(input_length, !readonly);
setEnabled(choice_length, !readonly);
string const length = getStringFromInput(input_length);
if (strip(length).empty()) {
bool const metric = lyxrc.default_papersize > 3;
int const default_unit = metric ? 8 : 9;
fl_set_choice(choice_length, default_unit);
}
}
}
bool validSpaceWidgets(FL_OBJECT * choice_type, FL_OBJECT * input_length)
{
// Paranoia check!
lyx::Assert(choice_type && choice_type->objclass == FL_CHOICE &&
input_length && input_length->objclass == FL_INPUT);
if (fl_get_choice(choice_type) != 7)
return true;
string const input = getStringFromInput(input_length);
return (input.empty() ||
isValidGlueLength(input) ||
isStrDbl(input));
}
} // namespace anon
bool FormParagraph::input(FL_OBJECT * ob, long)
{
bool valid = true;
fl_hide_object(dialog_->text_warning);
clearMessage();
// First check the buttons which are exclusive and you have to
// check only the actuall de/activated button.
@ -493,77 +540,42 @@ bool FormParagraph::input(FL_OBJECT * ob, long)
// impossible to commit senseless data.
if (ob == dialog_->choice_space_above) {
if (fl_get_choice (dialog_->choice_space_above) != 7) {
fl_set_input(dialog_->input_space_above, "");
setEnabled(dialog_->input_space_above, false);
setEnabled(dialog_->choice_value_space_above, false);
} else {
setEnabled(dialog_->input_space_above,
!lv_->buffer()->isReadonly());
setEnabled(dialog_->choice_value_space_above,
!lv_->buffer()->isReadonly());
bool const metric = lyxrc.default_papersize > 3;
int const default_unit = metric ? 8 : 9;
if (strip(fl_get_input(dialog_->input_space_above)).empty())
fl_set_choice(dialog_->choice_value_space_above, default_unit);
}
synchronizeSpaceWidgets(dialog_->choice_space_above,
dialog_->input_space_above,
dialog_->choice_value_space_above,
lv_->buffer()->isReadonly());
}
if (ob == dialog_->choice_space_below) {
if (fl_get_choice (dialog_->choice_space_below) != 7) {
fl_set_input(dialog_->input_space_below, "");
setEnabled(dialog_->input_space_below, false);
setEnabled(dialog_->choice_value_space_below, false);
} else {
setEnabled(dialog_->input_space_below,
!lv_->buffer()->isReadonly());
setEnabled(dialog_->choice_value_space_below,
!lv_->buffer()->isReadonly());
bool const metric = lyxrc.default_papersize > 3;
int const default_unit = metric ? 8 : 9;
if (strip(fl_get_input(dialog_->input_space_below)).empty())
fl_set_choice(dialog_->choice_value_space_below, default_unit);
}
synchronizeSpaceWidgets(dialog_->choice_space_below,
dialog_->input_space_below,
dialog_->choice_value_space_below,
lv_->buffer()->isReadonly());
}
//
// warnings if input is senseless
//
string input = fl_get_input(dialog_->input_space_above);
bool invalid = false;
// Display a warning if the input is senseless
bool valid = (validSpaceWidgets(dialog_->choice_space_above,
dialog_->input_space_above) &&
validSpaceWidgets(dialog_->choice_space_below,
dialog_->input_space_below));
if (fl_get_choice(dialog_->choice_space_above) == 7)
invalid = !input.empty() &&
!isValidGlueLength(input) &&
!isStrDbl(input);
input = fl_get_input(dialog_->input_space_below);
if (fl_get_choice(dialog_->choice_space_below) == 7)
invalid = invalid ||
(!input.empty() && !isValidGlueLength(input) && !isStrDbl(input));
if (ob == dialog_->input_space_above || ob == dialog_->input_space_below) {
if (invalid) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length (valid example: 10mm)"));
fl_show_object(dialog_->text_warning);
return false;
} else {
fl_hide_object(dialog_->text_warning);
return true;
}
if (!valid) {
postWarning(_("Invalid Length (valid example: 10mm)"));
}
if (fl_get_choice (dialog_->choice_linespacing) == 5)
int const choice_spacing = fl_get_choice(dialog_->choice_linespacing);
if (choice_spacing == 5)
setEnabled(dialog_->input_linespacing, true);
else {
fl_set_input(dialog_->input_linespacing, "");
setEnabled(dialog_->input_linespacing, false);
fl_set_input (dialog_->input_linespacing, "");
}
double spacing(strToDbl(fl_get_input(dialog_->input_linespacing)));
double const spacing =
strToDbl(getStringFromInput(dialog_->input_linespacing));
if (fl_get_choice(dialog_->choice_linespacing) == 5 && int(spacing) == 0)
if (choice_spacing == 5 && int(spacing) == 0)
valid = false;
return valid;

View File

@ -111,6 +111,9 @@ void FormTabular::build()
{
dialog_.reset(build_tabular());
// Allow the base class to control messages
setMessageWidget(dialog_->text_warning);
setPrehandler(dialog_->input_tabular_column);
setPrehandler(dialog_->input_tabular_row);
@ -187,7 +190,7 @@ void FormTabular::update()
int cell = inset_->getActCell();
actCell_ = cell;
int column = tabular->column_of_cell(cell) + 1;
fl_set_object_label(dialog_->text_warning, "");
clearMessage();
fl_activate_object(column_options_->input_special_alignment);
fl_activate_object(cell_options_->input_special_multialign);
fl_activate_object(column_options_->input_column_width);
@ -555,9 +558,7 @@ bool FormTabular::input(FL_OBJECT * ob, long)
if (actCell_ != cell) {
update();
fl_set_object_label(dialog_->text_warning,
_("Warning: Wrong Cursor position, updated window"));
fl_show_object(dialog_->text_warning);
postWarning(_("Wrong Cursor position, updated window"));
return false;
}
// No point in processing directives that you can't do anything with
@ -578,14 +579,14 @@ bool FormTabular::input(FL_OBJECT * ob, long)
string const input =
fl_get_input(column_options_->input_column_width);
if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length (valid example: 10mm)"));
fl_show_object(dialog_->text_warning);
postWarning(_("Invalid Length (valid example: 10mm)"));
return false;
}
update(); // update for alignment
return true;
update(); // update for alignment
return true;
}
if ((ob == cell_options_->input_mcolumn_width) ||
(ob == cell_options_->choice_value_mcolumn_width))
{
@ -598,9 +599,7 @@ bool FormTabular::input(FL_OBJECT * ob, long)
string const input =
fl_get_input(cell_options_->input_mcolumn_width);
if (!input.empty() && !isValidLength(input) && !isStrDbl(input)) {
fl_set_object_label(dialog_->text_warning,
_("Warning: Invalid Length (valid example: 10mm)"));
fl_show_object(dialog_->text_warning);
postWarning(_("Invalid Length (valid example: 10mm)"));
return false;
}
update(); // update for alignment