From d7f6dcbd710f1d8a9c9a01d13eb4494306dc00db Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Mon, 15 Oct 2001 10:28:31 +0000 Subject: [PATCH] Address most (if not all?) of the problems raised by Garst about the Document->Paper tab. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2881 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 6 ++ src/frontends/controllers/ControlMinipage.C | 17 +---- src/frontends/controllers/helper_funcs.C | 12 +++ src/frontends/controllers/helper_funcs.h | 5 ++ src/frontends/xforms/ChangeLog | 7 ++ src/frontends/xforms/FormDocument.C | 84 +++++++++++++++------ src/frontends/xforms/FormMinipage.C | 2 +- src/frontends/xforms/xforms_helpers.C | 22 ++++-- src/frontends/xforms/xforms_helpers.h | 7 +- 9 files changed, 116 insertions(+), 46 deletions(-) diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 83fccaa9d9..88f072d55c 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,9 @@ +2001-10-15 Angus Leeming + + * ControlMinipage.[Ch] (getUnits): moved to helper_funcs. + + * helper_funcs.[Ch] (getLatexUnits): see above. + 2001-10-12 Jean-Marc Lasgouttes * ControlTexinfo.C (getContents): use the right file for .sty files diff --git a/src/frontends/controllers/ControlMinipage.C b/src/frontends/controllers/ControlMinipage.C index 7c7f2ee940..4071ae975f 100644 --- a/src/frontends/controllers/ControlMinipage.C +++ b/src/frontends/controllers/ControlMinipage.C @@ -24,12 +24,11 @@ #include "LyXView.h" #include "buffer.h" #include "BufferView.h" +#include "helper_funcs.h" using std::vector; using SigC::slot; -// sorry this is just a temporary hack we should include vspace.h! (Jug) -extern const char * stringFromUnit(int); ControlMinipage::ControlMinipage(LyXView & lv, Dialogs & d) : ControlInset(lv, d) @@ -82,17 +81,3 @@ bool operator!=(MinipageParams const & p1, MinipageParams const & p2) { return !(p1 == p2); } - -namespace minipage { - -vector const getUnits() -{ - vector units; - const char * str; - for(int i=0; (str = stringFromUnit(i)); ++i) - units.push_back(str); - - return units; -} - -} // namespace minipage diff --git a/src/frontends/controllers/helper_funcs.C b/src/frontends/controllers/helper_funcs.C index 60601b48c8..91b07996c2 100644 --- a/src/frontends/controllers/helper_funcs.C +++ b/src/frontends/controllers/helper_funcs.C @@ -108,3 +108,15 @@ string const browseFile(LyXView * lv, string const & filename, } +// sorry this is just a temporary hack we should include vspace.h! (Jug) +extern const char * stringFromUnit(int); + +vector const getLatexUnits() +{ + vector units; + const char * str; + for(int i=0; (str = stringFromUnit(i)); ++i) + units.push_back(str); + + return units; +} diff --git a/src/frontends/controllers/helper_funcs.h b/src/frontends/controllers/helper_funcs.h index daadcdaa33..d2af6683b4 100644 --- a/src/frontends/controllers/helper_funcs.h +++ b/src/frontends/controllers/helper_funcs.h @@ -45,6 +45,11 @@ string const browseFile(LyXView *lv, string const & filename, std::pair const & dir1, std::pair const & dir2); + +/// Returns a vector of units that can be used to create a valid LaTeX length. +std::vector const getLatexUnits(); + + /** Functions to extract vectors of the first and second elems from a vector > */ diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index b55f3ab4d0..ab34a22f8d 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,10 @@ +2001-10-15 Angus Leeming + + * FormDocument.C: fixed some bugs in the Paper tab. + + * xforms_helpers.[Ch] (updateWidgetsFromLengthString): add argument + specifying default unit for choice if input string is empty. + 2001-10-12 Angus Leeming * FormDocument.C (input): one more tweak... diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index 738e25e531..75f9092d6f 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -44,6 +44,7 @@ #include "xforms_helpers.h" #include "debug.h" #include "input_validators.h" // fl_unsigned_float_filter +#include "helper_funcs.h" using Liason::setMinibuffer; using SigC::slot; @@ -138,7 +139,14 @@ void FormDocument::build() fl_unsigned_float_filter); // Create the contents of the unit choices - string const units = " cm | inch "; + // Don't include the "%" terms... + std::vector units_vec = getLatexUnits(); + for (std::vector::iterator it = units_vec.begin(); + it != units_vec.end(); ++it) { + if (contains(*it, "%")) + it = units_vec.erase(it, it+1) - 1; + } + string units = getStringFromVector(units_vec, "|"); fl_addto_choice(paper_->choice_custom_width_units, units.c_str()); fl_addto_choice(paper_->choice_custom_height_units, units.c_str()); @@ -412,14 +420,11 @@ bool FormDocument::input( FL_OBJECT * ob, long data ) BufferParams::PACKAGE_NONE + 1); if (ob == paper_->choice_papersize) { - bool const custom = - fl_get_choice(paper_->choice_papersize) == 2; - bool const a3size = - fl_get_choice(paper_->choice_papersize) == 6; - bool const b3size = - fl_get_choice(paper_->choice_papersize) == 9; - bool const b4size = - fl_get_choice(paper_->choice_papersize) == 10; + int const paperchoice = fl_get_choice(paper_->choice_papersize); + bool const custom = paperchoice == 2; + bool const a3size = paperchoice == 6; + bool const b3size = paperchoice == 9; + bool const b4size = paperchoice == 10; if (custom) fl_set_button(paper_->radio_portrait, 1); @@ -451,6 +456,37 @@ bool FormDocument::input( FL_OBJECT * ob, long data ) setEnabled(paper_->choice_custom_height_units, custom); setEnabled(paper_->radio_portrait, !custom); setEnabled(paper_->radio_landscape, !custom); + + // Default unit choice is cm if metric, inches if US paper. + bool const metric = paperchoice < 3 || paperchoice > 5; + int const default_unit = metric ? 8 : 9; + if (strip(fl_get_input(paper_->input_custom_width)).empty()) + fl_set_choice(paper_->choice_custom_width_units, + default_unit); + if (strip(fl_get_input(paper_->input_custom_height)).empty()) + fl_set_choice(paper_->choice_custom_height_units, + default_unit); + if (strip(fl_get_input(paper_->input_top_margin)).empty()) + fl_set_choice(paper_->choice_top_margin_units, + default_unit); + if (strip(fl_get_input(paper_->input_bottom_margin)).empty()) + fl_set_choice(paper_->choice_bottom_margin_units, + default_unit); + if (strip(fl_get_input(paper_->input_left_margin)).empty()) + fl_set_choice(paper_->choice_left_margin_units, + default_unit); + if (strip(fl_get_input(paper_->input_right_margin)).empty()) + fl_set_choice(paper_->choice_right_margin_units, + default_unit); + if (strip(fl_get_input(paper_->input_head_height)).empty()) + fl_set_choice(paper_->choice_head_height_units, + default_unit); + if (strip(fl_get_input(paper_->input_head_sep)).empty()) + fl_set_choice(paper_->choice_head_sep_units, + default_unit); + if (strip(fl_get_input(paper_->input_foot_skip)).empty()) + fl_set_choice(paper_->choice_foot_skip_units, + default_unit); } if (ob == paper_->choice_papersize || @@ -687,6 +723,7 @@ void FormDocument::paper_apply() params.leftmargin = getLengthFromWidgets(paper_->input_left_margin, paper_->choice_left_margin_units); + std::cerr << params.leftmargin << std::endl; params.topmargin = getLengthFromWidgets(paper_->input_top_margin, @@ -943,7 +980,8 @@ void FormDocument::paper_update(BufferParams const & params) fl_set_choice(paper_->choice_paperpackage, params.paperpackage + 1); fl_set_button(paper_->check_use_geometry, params.use_geometry); - bool const useCustom = fl_get_choice(paper_->choice_papersize) == 2; + int const paperchoice = fl_get_choice(paper_->choice_papersize); + bool const useCustom = paperchoice == 2; bool const useGeom = fl_get_button(paper_->check_use_geometry); fl_set_button(paper_->radio_portrait, 0); @@ -958,62 +996,64 @@ void FormDocument::paper_update(BufferParams const & params) setEnabled(paper_->choice_paperpackage, //either default papersize (preferences) //or document papersize has to be A4 - (fl_get_choice(paper_->choice_papersize) == 7 - || fl_get_choice(paper_->choice_papersize) == 1 - && lyxrc.default_papersize == 5) + (paperchoice == 7 + || paperchoice == 1 && lyxrc.default_papersize == 5) && fl_get_button(paper_->radio_portrait)); + // Default unit choice is cm if metric, inches if US paper. + bool const metric = paperchoice < 3 || paperchoice > 5; + string const default_unit = metric ? "cm" : "in"; updateWidgetsFromLengthString(paper_->input_custom_width, paper_->choice_custom_width_units, - params.paperwidth); + params.paperwidth, default_unit); setEnabled(paper_->input_custom_width, useCustom); setEnabled(paper_->choice_custom_width_units, useCustom); updateWidgetsFromLengthString(paper_->input_custom_height, paper_->choice_custom_height_units, - params.paperheight); + params.paperheight, default_unit); setEnabled(paper_->input_custom_height, useCustom); setEnabled(paper_->choice_custom_height_units, useCustom); updateWidgetsFromLengthString(paper_->input_left_margin, paper_->choice_left_margin_units, - params.leftmargin); + params.leftmargin, default_unit); setEnabled(paper_->input_left_margin, useGeom); setEnabled(paper_->choice_left_margin_units, useGeom); updateWidgetsFromLengthString(paper_->input_top_margin, paper_->choice_top_margin_units, - params.topmargin); + params.topmargin, default_unit); setEnabled(paper_->input_top_margin, useGeom); setEnabled(paper_->choice_top_margin_units, useGeom); updateWidgetsFromLengthString(paper_->input_right_margin, paper_->choice_right_margin_units, - params.rightmargin); + params.rightmargin, default_unit); setEnabled(paper_->input_right_margin, useGeom); setEnabled(paper_->choice_right_margin_units, useGeom); updateWidgetsFromLengthString(paper_->input_bottom_margin, paper_->choice_bottom_margin_units, - params.bottommargin); + params.bottommargin, default_unit); setEnabled(paper_->input_bottom_margin, useGeom); setEnabled(paper_->choice_bottom_margin_units, useGeom); updateWidgetsFromLengthString(paper_->input_head_height, paper_->choice_head_height_units, - params.headheight); + params.headheight, default_unit); setEnabled(paper_->input_head_height, useGeom); setEnabled(paper_->choice_head_height_units, useGeom); updateWidgetsFromLengthString(paper_->input_head_sep, paper_->choice_head_sep_units, - params.headsep); + params.headsep, default_unit); setEnabled(paper_->input_head_sep, useGeom); setEnabled(paper_->choice_head_sep_units, useGeom); updateWidgetsFromLengthString(paper_->input_foot_skip, paper_->choice_foot_skip_units, - params.footskip); + params.footskip, default_unit); setEnabled(paper_->input_foot_skip, useGeom); setEnabled(paper_->choice_foot_skip_units, useGeom); diff --git a/src/frontends/xforms/FormMinipage.C b/src/frontends/xforms/FormMinipage.C index a591e18c44..4c051dfedb 100644 --- a/src/frontends/xforms/FormMinipage.C +++ b/src/frontends/xforms/FormMinipage.C @@ -38,7 +38,7 @@ void FormMinipage::build() fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED); - string const choice = getStringFromVector(minipage::getUnits(), "|"); + string const choice = getStringFromVector(getLatexUnits(), "|"); fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str()); // Manage the ok, apply and cancel/close buttons diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 3aa0260d67..5a0271c9b4 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -79,14 +79,16 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice) if (length.empty()) return string(); - string const units = strip(frontStrip(fl_get_choice_text(choice))); + string unit = strip(frontStrip(fl_get_choice_text(choice))); + unit = subst(unit, "%%", "%"); - return length + units; + return length + unit; } void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice, - string const & str) + string const & str, + string const & default_unit) { // Paranoia check lyx::Assert(input && input->objclass == FL_INPUT && @@ -94,7 +96,16 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice, if (str.empty()) { fl_set_input(input, ""); - fl_set_choice(choice, 1); + int unitpos = 1; // xforms has Fortran-style indexing + for(int i = 0; i < fl_get_choice_maxitems(choice); ++i) { + string const text = fl_get_choice_item_text(choice,i+1); + if (default_unit == + lowercase(strip(frontStrip(text)))) { + unitpos = i+1; + break; + } + } + fl_set_choice(choice, unitpos); return; } @@ -118,7 +129,8 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice, string tmplen = string(tmp.begin(), p); if (isStrDbl(tmplen)) len = tmplen; - string unit = string(p+1, tmp.end()); + string unit = string(p, tmp.end()); + unit = subst(unit, "%", "%%"); for(int i = 0; i < fl_get_choice_maxitems(choice); ++i) { string const text = fl_get_choice_item_text(choice,i+1); diff --git a/src/frontends/xforms/xforms_helpers.h b/src/frontends/xforms/xforms_helpers.h index d6aec88799..8604faa9c7 100644 --- a/src/frontends/xforms/xforms_helpers.h +++ b/src/frontends/xforms/xforms_helpers.h @@ -25,9 +25,12 @@ std::vector const getVectorFromBrowser(FL_OBJECT *); /// Given input and choice widgets, create a string such as "1cm" string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice); -/// Given a string such as "1cm", set the input and choice widgets. +/** Given a string such as "1cm", set the input and choice widgets. + If the string is empty, the choice will be set to default_unit. + */ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice, - string const & str); + string const & str, + string const & default_unit); /// struct holding xform-specific colors struct XformsColor : public NamedColor { -- 2.39.2