diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index ce2806a3c7..305d381406 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,20 @@ +2002-01-15 Jürgen Spitzmüller + + * xforms_helpers.C: modify getLengthFromWidgets to ignore the unit + choice if the input field contains a LyXGlueLength. + + * FormParagraph.C: Allow to insert and display gluelengths in VSpace + + * FormParagraph.C + * FormDocument.C + * FormTabular.C: Change input filter to allow inserting + gluelengths/lyxlength or numbers with unit choices. + + * FormMinipage.C: Use getLengthFromWidgets instead of the code there, + which was more or less duplicated. + + * FormGraphics.C: set default units, dependent on US/other paper. + 2002-01-16 Angus Leeming * Dialogs.C: no longer need to #include the Controller classes, as this diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index f531cbb2ee..95b711e7f6 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -119,26 +119,6 @@ void FormDocument::build() fl_set_input_return(paper_->input_head_sep, FL_RETURN_CHANGED); fl_set_input_return(paper_->input_foot_skip, FL_RETURN_CHANGED); - // Set input filters on width and height to make them accept only - // unsigned numbers. - fl_set_input_filter(paper_->input_custom_width, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_custom_height, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_top_margin, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_bottom_margin, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_inner_margin, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_outer_margin, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_head_height, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_head_sep, - fl_unsigned_float_filter); - fl_set_input_filter(paper_->input_foot_skip, - fl_unsigned_float_filter); // Create the contents of the unit choices // Don't include the "%" terms... @@ -210,10 +190,9 @@ void FormDocument::build() fl_set_input_return(class_->input_doc_skip, FL_RETURN_CHANGED); fl_set_input_return(class_->input_doc_spacing, FL_RETURN_CHANGED); - // Set input filters on doc skip to make it accept only + // Set input filters on doc spacing to make it accept only // unsigned numbers. - fl_set_input_filter(class_->input_doc_skip, - fl_unsigned_float_filter); + fl_set_input_filter(class_->input_doc_spacing, fl_unsigned_float_filter); bc().addReadOnly (class_->radio_doc_indent); bc().addReadOnly (class_->radio_doc_skip); @@ -1223,12 +1202,58 @@ void FormDocument::checkReadOnly() } -bool FormDocument::CheckDocumentInput(FL_OBJECT *, long) +bool FormDocument::CheckDocumentInput(FL_OBJECT * ob, long) { string str; bool ok = true; char const * input; + // this has to be all out of if/elseif because it has to deactivate + // the document buttons and so the whole stuff has to be tested again. + // disable OK/Apply if input is not valid + str = fl_get_input(class_->input_doc_skip); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_custom_width); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_custom_height); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_outer_margin); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_inner_margin); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_top_margin); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_bottom_margin); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_head_height); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_head_sep); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + str = fl_get_input(paper_->input_foot_skip); + ok = ok && (str.empty() || isValidLength(str) || isStrDbl(str)); + + //display warning if input is not valid + if (ob == class_->input_doc_skip + || ob == paper_->input_custom_width + || ob == paper_->input_custom_height + || ob == paper_->input_outer_margin + || ob == paper_->input_inner_margin + || ob == paper_->input_top_margin + || ob == paper_->input_bottom_margin + || ob == paper_->input_head_height + || 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); + return false; + } else { + fl_hide_object(dialog_->text_warning); + return true; + } + } + // "Synchronize" the choice and the input field, so that it // is impossible to commit senseless data. input = fl_get_input (class_->input_doc_skip); diff --git a/src/frontends/xforms/FormGraphics.C b/src/frontends/xforms/FormGraphics.C index 66de72a4bd..936c19bdcd 100644 --- a/src/frontends/xforms/FormGraphics.C +++ b/src/frontends/xforms/FormGraphics.C @@ -262,7 +262,13 @@ void FormGraphics::update() fl_set_input(dialog_->input_width, number.c_str()); int pos = 1; + //use inch as default with US papersizes in lyxrc + if (lyxrc.default_papersize < 3) + pos = 2; switch (igp.widthResize) { + case InsetGraphicsParams::CM: + pos = 1; break; + case InsetGraphicsParams::INCH: pos = 2; break; @@ -284,7 +290,13 @@ void FormGraphics::update() fl_set_input(dialog_->input_height, number.c_str()); pos = 1; + //use inch as default with US papersizes in lyxrc + if (lyxrc.default_papersize < 3) + pos = 2; switch (igp.heightResize) { + case InsetGraphicsParams::CM: + pos = 1; break; + case InsetGraphicsParams::INCH: pos = 2; break; diff --git a/src/frontends/xforms/FormMinipage.C b/src/frontends/xforms/FormMinipage.C index 5ca5c4a347..b06603c76b 100644 --- a/src/frontends/xforms/FormMinipage.C +++ b/src/frontends/xforms/FormMinipage.C @@ -24,6 +24,7 @@ #include "support/lstrings.h" #include "helper_funcs.h" #include "debug.h" +#include "xforms_helpers.h" typedef FormCB > base_class; @@ -58,11 +59,9 @@ void FormMinipage::build() void FormMinipage::apply() { - string const units = fl_get_choice_text(dialog_->choice_width_units); - double const val = strToDbl(fl_get_input(dialog_->input_width)); - controller().params().pageWidth = - tostr(val) + frontStrip(strip(subst(units,"%%","%"))); + getLengthFromWidgets(dialog_->input_width, + dialog_->choice_width_units); if (fl_get_button(dialog_->radio_top)) controller().params().pos = InsetMinipage::top; diff --git a/src/frontends/xforms/FormParagraph.C b/src/frontends/xforms/FormParagraph.C index 0fc651e5c3..91943ac01b 100644 --- a/src/frontends/xforms/FormParagraph.C +++ b/src/frontends/xforms/FormParagraph.C @@ -33,7 +33,7 @@ #include "input_validators.h" #include "helper_funcs.h" -#include "support/lstrings.h" +#include "support/lstrings.h" using Liason::setMinibuffer; using SigC::slot; @@ -123,8 +123,6 @@ void FormParagraph::build() 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); - fl_set_input_filter(dialog_->input_space_above, fl_float_filter); - fl_set_input_filter(dialog_->input_space_below, fl_float_filter); // Create the contents of the unit choices // Don't include the "%" terms... @@ -249,7 +247,7 @@ void FormParagraph::apply() case 7: string const length = getLengthFromWidgets(dialog_->input_space_below, - dialog_->choice_value_space_below); + dialog_->choice_value_space_below); space_bottom = VSpace(LyXGlueLength(length)); break; } @@ -414,10 +412,15 @@ void FormParagraph::update() 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; + //check if there's a stretch or shrink factor + if (!isValidLength(length) && !isStrDbl(length)) + fl_set_input(dialog_->input_space_above, length.c_str()); + else { + updateWidgetsFromLengthString(dialog_->input_space_above, + dialog_->choice_value_space_above, + length, default_unit); + } + break; } } @@ -455,10 +458,15 @@ void FormParagraph::update() 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; + //check if there's a stretch or shrink factor + if (!isValidLength(length) && !isStrDbl(length)) + fl_set_input(dialog_->input_space_below, length.c_str()); + else { + updateWidgetsFromLengthString(dialog_->input_space_below, + dialog_->choice_value_space_below, + length, default_unit); + } + break; } } @@ -512,6 +520,33 @@ bool FormParagraph::input(FL_OBJECT * ob, long) } } + // + // warnings if input is senseless + // + string input = fl_get_input (dialog_->input_space_above); + bool invalid = false; + + 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 (fl_get_choice (dialog_->choice_linespacing) == 5) setEnabled (dialog_->input_linespacing, true); else { diff --git a/src/frontends/xforms/FormTabular.C b/src/frontends/xforms/FormTabular.C index 999a7d4724..0848acfca0 100644 --- a/src/frontends/xforms/FormTabular.C +++ b/src/frontends/xforms/FormTabular.C @@ -24,6 +24,7 @@ #include "insets/insettabular.h" #include "buffer.h" #include "xforms_helpers.h" +#include "lyxrc.h" // to set the default length values #include "helper_funcs.h" #include "input_validators.h" #include "support/lstrings.h" @@ -220,7 +221,8 @@ void FormTabular::update() setEnabled(cell_options_->radio_valign_center, true); special = tabular->GetAlignSpecial(cell, LyXTabular::SET_SPECIAL_MULTI); fl_set_input(cell_options_->input_special_multialign, special.c_str()); - string const default_unit = "cm"; + bool const metric = lyxrc.default_papersize > 3; + string const default_unit = metric ? "cm" : "in"; updateWidgetsFromLength(cell_options_->input_mcolumn_width, cell_options_->choice_value_mcolumn_width, pwidth, default_unit); @@ -305,7 +307,8 @@ void FormTabular::update() setEnabled(column_options_->input_special_alignment, !isReadonly); pwidth = tabular->GetColumnPWidth(cell); - string const default_unit = "cm"; + bool const metric = lyxrc.default_papersize > 3; + string const default_unit = metric ? "cm" : "in"; updateWidgetsFromLength(column_options_->input_column_width, column_options_->choice_value_column_width, pwidth, default_unit); @@ -512,20 +515,40 @@ bool FormTabular::input(FL_OBJECT * ob, long) if ((ob == column_options_->input_column_width) || (ob == column_options_->choice_value_column_width)) { - string const str = - getLengthFromWidgets(column_options_->input_column_width, - column_options_->choice_value_column_width); - inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str); + string const str = + getLengthFromWidgets(column_options_->input_column_width, + column_options_->choice_value_column_width); + inset_->tabularFeatures(lv_->view(), LyXTabular::SET_PWIDTH, str); + + //check if the input is valid + 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); + return false; + } update(); // update for alignment return true; } if ((ob == cell_options_->input_mcolumn_width) || (ob == cell_options_->choice_value_mcolumn_width)) { - string const str = - getLengthFromWidgets(cell_options_->input_mcolumn_width, - cell_options_->choice_value_mcolumn_width); - inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str); + string const str = + getLengthFromWidgets(cell_options_->input_mcolumn_width, + cell_options_->choice_value_mcolumn_width); + inset_->tabularFeatures(lv_->view(), LyXTabular::SET_MPWIDTH, str); + + //check if the input is valid + 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); + return false; + } update(); // update for alignment return true; } diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index ca4229fbfc..4525e09148 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -20,6 +20,7 @@ #include "gettext.h" #include "support/LAssert.h" #include "lyxlength.h" +#include "lyxgluelength.h" using std::ofstream; using std::pair; @@ -158,6 +159,10 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) if (length.empty()) return string(); + //don't return unit-from-choice if the input(field) contains a unit + if (isValidGlueLength(length)) + return length; + string unit = strip(frontStrip(fl_get_choice_text(choice))); unit = subst(unit, "%%", "%");