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
This commit is contained in:
Angus Leeming 2001-10-15 10:28:31 +00:00
parent 5135dd2ae9
commit d7f6dcbd71
9 changed files with 116 additions and 46 deletions

View File

@ -1,3 +1,9 @@
2001-10-15 Angus Leeming <a.leeming@ic.ac.uk>
* ControlMinipage.[Ch] (getUnits): moved to helper_funcs.
* helper_funcs.[Ch] (getLatexUnits): see above.
2001-10-12 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr> 2001-10-12 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* ControlTexinfo.C (getContents): use the right file for .sty files * ControlTexinfo.C (getContents): use the right file for .sty files

View File

@ -24,12 +24,11 @@
#include "LyXView.h" #include "LyXView.h"
#include "buffer.h" #include "buffer.h"
#include "BufferView.h" #include "BufferView.h"
#include "helper_funcs.h"
using std::vector; using std::vector;
using SigC::slot; 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) ControlMinipage::ControlMinipage(LyXView & lv, Dialogs & d)
: ControlInset<InsetMinipage, MinipageParams>(lv, d) : ControlInset<InsetMinipage, MinipageParams>(lv, d)
@ -82,17 +81,3 @@ bool operator!=(MinipageParams const & p1, MinipageParams const & p2)
{ {
return !(p1 == p2); return !(p1 == p2);
} }
namespace minipage {
vector<string> const getUnits()
{
vector<string> units;
const char * str;
for(int i=0; (str = stringFromUnit(i)); ++i)
units.push_back(str);
return units;
}
} // namespace minipage

View File

@ -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<string> const getLatexUnits()
{
vector<string> units;
const char * str;
for(int i=0; (str = stringFromUnit(i)); ++i)
units.push_back(str);
return units;
}

View File

@ -45,6 +45,11 @@ string const browseFile(LyXView *lv, string const & filename,
std::pair<string,string> const & dir1, std::pair<string,string> const & dir1,
std::pair<string,string> const & dir2); std::pair<string,string> const & dir2);
/// Returns a vector of units that can be used to create a valid LaTeX length.
std::vector<string> const getLatexUnits();
/** Functions to extract vectors of the first and second elems from a /** Functions to extract vectors of the first and second elems from a
vector<pair<A,B> > vector<pair<A,B> >
*/ */

View File

@ -1,3 +1,10 @@
2001-10-15 Angus Leeming <a.leeming@ic.ac.uk>
* 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 <a.leeming@ic.ac.uk> 2001-10-12 Angus Leeming <a.leeming@ic.ac.uk>
* FormDocument.C (input): one more tweak... * FormDocument.C (input): one more tweak...

View File

@ -44,6 +44,7 @@
#include "xforms_helpers.h" #include "xforms_helpers.h"
#include "debug.h" #include "debug.h"
#include "input_validators.h" // fl_unsigned_float_filter #include "input_validators.h" // fl_unsigned_float_filter
#include "helper_funcs.h"
using Liason::setMinibuffer; using Liason::setMinibuffer;
using SigC::slot; using SigC::slot;
@ -138,7 +139,14 @@ void FormDocument::build()
fl_unsigned_float_filter); fl_unsigned_float_filter);
// Create the contents of the unit choices // Create the contents of the unit choices
string const units = " cm | inch "; // Don't include the "%" terms...
std::vector<string> units_vec = getLatexUnits();
for (std::vector<string>::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_width_units, units.c_str());
fl_addto_choice(paper_->choice_custom_height_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); BufferParams::PACKAGE_NONE + 1);
if (ob == paper_->choice_papersize) { if (ob == paper_->choice_papersize) {
bool const custom = int const paperchoice = fl_get_choice(paper_->choice_papersize);
fl_get_choice(paper_->choice_papersize) == 2; bool const custom = paperchoice == 2;
bool const a3size = bool const a3size = paperchoice == 6;
fl_get_choice(paper_->choice_papersize) == 6; bool const b3size = paperchoice == 9;
bool const b3size = bool const b4size = paperchoice == 10;
fl_get_choice(paper_->choice_papersize) == 9;
bool const b4size =
fl_get_choice(paper_->choice_papersize) == 10;
if (custom) if (custom)
fl_set_button(paper_->radio_portrait, 1); 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_->choice_custom_height_units, custom);
setEnabled(paper_->radio_portrait, !custom); setEnabled(paper_->radio_portrait, !custom);
setEnabled(paper_->radio_landscape, !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 || if (ob == paper_->choice_papersize ||
@ -687,6 +723,7 @@ void FormDocument::paper_apply()
params.leftmargin = params.leftmargin =
getLengthFromWidgets(paper_->input_left_margin, getLengthFromWidgets(paper_->input_left_margin,
paper_->choice_left_margin_units); paper_->choice_left_margin_units);
std::cerr << params.leftmargin << std::endl;
params.topmargin = params.topmargin =
getLengthFromWidgets(paper_->input_top_margin, 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_choice(paper_->choice_paperpackage, params.paperpackage + 1);
fl_set_button(paper_->check_use_geometry, params.use_geometry); 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); bool const useGeom = fl_get_button(paper_->check_use_geometry);
fl_set_button(paper_->radio_portrait, 0); fl_set_button(paper_->radio_portrait, 0);
@ -958,62 +996,64 @@ void FormDocument::paper_update(BufferParams const & params)
setEnabled(paper_->choice_paperpackage, setEnabled(paper_->choice_paperpackage,
//either default papersize (preferences) //either default papersize (preferences)
//or document papersize has to be A4 //or document papersize has to be A4
(fl_get_choice(paper_->choice_papersize) == 7 (paperchoice == 7
|| fl_get_choice(paper_->choice_papersize) == 1 || paperchoice == 1 && lyxrc.default_papersize == 5)
&& lyxrc.default_papersize == 5)
&& fl_get_button(paper_->radio_portrait)); && 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, updateWidgetsFromLengthString(paper_->input_custom_width,
paper_->choice_custom_width_units, paper_->choice_custom_width_units,
params.paperwidth); params.paperwidth, default_unit);
setEnabled(paper_->input_custom_width, useCustom); setEnabled(paper_->input_custom_width, useCustom);
setEnabled(paper_->choice_custom_width_units, useCustom); setEnabled(paper_->choice_custom_width_units, useCustom);
updateWidgetsFromLengthString(paper_->input_custom_height, updateWidgetsFromLengthString(paper_->input_custom_height,
paper_->choice_custom_height_units, paper_->choice_custom_height_units,
params.paperheight); params.paperheight, default_unit);
setEnabled(paper_->input_custom_height, useCustom); setEnabled(paper_->input_custom_height, useCustom);
setEnabled(paper_->choice_custom_height_units, useCustom); setEnabled(paper_->choice_custom_height_units, useCustom);
updateWidgetsFromLengthString(paper_->input_left_margin, updateWidgetsFromLengthString(paper_->input_left_margin,
paper_->choice_left_margin_units, paper_->choice_left_margin_units,
params.leftmargin); params.leftmargin, default_unit);
setEnabled(paper_->input_left_margin, useGeom); setEnabled(paper_->input_left_margin, useGeom);
setEnabled(paper_->choice_left_margin_units, useGeom); setEnabled(paper_->choice_left_margin_units, useGeom);
updateWidgetsFromLengthString(paper_->input_top_margin, updateWidgetsFromLengthString(paper_->input_top_margin,
paper_->choice_top_margin_units, paper_->choice_top_margin_units,
params.topmargin); params.topmargin, default_unit);
setEnabled(paper_->input_top_margin, useGeom); setEnabled(paper_->input_top_margin, useGeom);
setEnabled(paper_->choice_top_margin_units, useGeom); setEnabled(paper_->choice_top_margin_units, useGeom);
updateWidgetsFromLengthString(paper_->input_right_margin, updateWidgetsFromLengthString(paper_->input_right_margin,
paper_->choice_right_margin_units, paper_->choice_right_margin_units,
params.rightmargin); params.rightmargin, default_unit);
setEnabled(paper_->input_right_margin, useGeom); setEnabled(paper_->input_right_margin, useGeom);
setEnabled(paper_->choice_right_margin_units, useGeom); setEnabled(paper_->choice_right_margin_units, useGeom);
updateWidgetsFromLengthString(paper_->input_bottom_margin, updateWidgetsFromLengthString(paper_->input_bottom_margin,
paper_->choice_bottom_margin_units, paper_->choice_bottom_margin_units,
params.bottommargin); params.bottommargin, default_unit);
setEnabled(paper_->input_bottom_margin, useGeom); setEnabled(paper_->input_bottom_margin, useGeom);
setEnabled(paper_->choice_bottom_margin_units, useGeom); setEnabled(paper_->choice_bottom_margin_units, useGeom);
updateWidgetsFromLengthString(paper_->input_head_height, updateWidgetsFromLengthString(paper_->input_head_height,
paper_->choice_head_height_units, paper_->choice_head_height_units,
params.headheight); params.headheight, default_unit);
setEnabled(paper_->input_head_height, useGeom); setEnabled(paper_->input_head_height, useGeom);
setEnabled(paper_->choice_head_height_units, useGeom); setEnabled(paper_->choice_head_height_units, useGeom);
updateWidgetsFromLengthString(paper_->input_head_sep, updateWidgetsFromLengthString(paper_->input_head_sep,
paper_->choice_head_sep_units, paper_->choice_head_sep_units,
params.headsep); params.headsep, default_unit);
setEnabled(paper_->input_head_sep, useGeom); setEnabled(paper_->input_head_sep, useGeom);
setEnabled(paper_->choice_head_sep_units, useGeom); setEnabled(paper_->choice_head_sep_units, useGeom);
updateWidgetsFromLengthString(paper_->input_foot_skip, updateWidgetsFromLengthString(paper_->input_foot_skip,
paper_->choice_foot_skip_units, paper_->choice_foot_skip_units,
params.footskip); params.footskip, default_unit);
setEnabled(paper_->input_foot_skip, useGeom); setEnabled(paper_->input_foot_skip, useGeom);
setEnabled(paper_->choice_foot_skip_units, useGeom); setEnabled(paper_->choice_foot_skip_units, useGeom);

View File

@ -38,7 +38,7 @@ void FormMinipage::build()
fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED); 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()); fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str());
// Manage the ok, apply and cancel/close buttons // Manage the ok, apply and cancel/close buttons

View File

@ -79,14 +79,16 @@ string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice)
if (length.empty()) if (length.empty())
return string(); 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, void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
string const & str) string const & str,
string const & default_unit)
{ {
// Paranoia check // Paranoia check
lyx::Assert(input && input->objclass == FL_INPUT && lyx::Assert(input && input->objclass == FL_INPUT &&
@ -94,7 +96,16 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
if (str.empty()) { if (str.empty()) {
fl_set_input(input, ""); 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; return;
} }
@ -118,7 +129,8 @@ void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
string tmplen = string(tmp.begin(), p); string tmplen = string(tmp.begin(), p);
if (isStrDbl(tmplen)) if (isStrDbl(tmplen))
len = 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) { for(int i = 0; i < fl_get_choice_maxitems(choice); ++i) {
string const text = fl_get_choice_item_text(choice,i+1); string const text = fl_get_choice_item_text(choice,i+1);

View File

@ -25,9 +25,12 @@ std::vector<string> const getVectorFromBrowser(FL_OBJECT *);
/// Given input and choice widgets, create a string such as "1cm" /// Given input and choice widgets, create a string such as "1cm"
string getLengthFromWidgets(FL_OBJECT * input, FL_OBJECT * choice); 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, void updateWidgetsFromLengthString(FL_OBJECT * input, FL_OBJECT * choice,
string const & str); string const & str,
string const & default_unit);
/// struct holding xform-specific colors /// struct holding xform-specific colors
struct XformsColor : public NamedColor { struct XformsColor : public NamedColor {