From: Jürgen Vigna Date: Thu, 29 Mar 2001 15:00:20 +0000 (+0000) Subject: Added %x support in vspace.C (LyXLenght) and use it for the minipages. X-Git-Tag: 1.6.10~21375 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=f284f1c8bc45e7a7c9162a3df0a8e748a5d0a717;p=features.git Added %x support in vspace.C (LyXLenght) and use it for the minipages. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1853 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/po/POTFILES.in b/po/POTFILES.in index 53ffdc22a4..9514d916d1 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -10,9 +10,11 @@ src/CutAndPaste.C src/debug.C src/exporter.C src/ext_l10n.h +src/figure_form.C +src/figureForm.C src/FontLoader.C -src/form1.C src/frontends/controllers/ButtonController.h +src/frontends/controllers/character.C src/frontends/controllers/ControlCharacter.C src/frontends/controllers/ControlCopyright.C src/frontends/controllers/ControlCredits.C @@ -26,7 +28,6 @@ src/frontends/gnome/FormIndex.C src/frontends/gnome/FormPrint.C src/frontends/gnome/FormRef.C src/frontends/gnome/FormToc.C -src/frontends/gnome/FormUrl.C src/frontends/gnome/Menubar_pimpl.C src/frontends/kde/citationdlg.C src/frontends/kde/dlg/copyrightdlgdata.C @@ -181,7 +182,6 @@ src/LaTeX.C src/layout.C src/LColor.C src/LyXAction.C -src/lyx.C src/lyx_cb.C src/lyxfind.C src/lyxfont.C diff --git a/src/ChangeLog b/src/ChangeLog index 191291e70b..fce7eaf50c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2001-03-29 Juergen Vigna + + * vspace.C: added support for %, c%, p%, l%. + (stringFromUnit): added helper function. + (asLatexString): changed to give right results for the %-values. + + * buffer.C: convert the widthp in a width%. + 2001-03-28 Angus Leeming * Makefile.am: removed form1.[Ch], lyx.[Ch] and added figure_form.[Ch], diff --git a/src/buffer.C b/src/buffer.C index f13af04fe5..0a6f45d5f6 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1153,7 +1153,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par, InsetMinipage * mini = new InsetMinipage; mini->pos(static_cast(par->params.pextraAlignment())); mini->width(par->params.pextraWidth()); - mini->widthp(par->params.pextraWidthp()); + if (!par->params.pextraWidthp().empty()) { + lyxerr << "WP:" << mini->width() << endl; + mini->width(tostr(par->params.pextraWidthp())+"%"); + } mini->inset->par = par; // Insert the minipage last in the // previous paragraph. @@ -1220,7 +1223,10 @@ Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par, InsetMinipage * mini = new InsetMinipage; mini->pos(static_cast(minipar->params.pextraAlignment())); mini->width(minipar->params.pextraWidth()); - mini->widthp(minipar->params.pextraWidthp()); + if (!par->params.pextraWidthp().empty()) { + lyxerr << "WP:" << mini->width() << endl; + mini->width(tostr(par->params.pextraWidthp())+"%"); + } mini->inset->par = minipar; // Insert the minipage last in the diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 5c43d0ecc6..3fbf3fc315 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,8 @@ +2001-03-29 Juergen Vigna + + * ControlMinipage.C: removed widthp_ and all it's functions and changed + to use new %-lengths of LyXLength. + 2001-03-29 Angus Leeming * ControlCitation.C (bibkeysInfo): removed Assert. diff --git a/src/frontends/controllers/ControlMinipage.C b/src/frontends/controllers/ControlMinipage.C index f9ce97d034..54802e7420 100644 --- a/src/frontends/controllers/ControlMinipage.C +++ b/src/frontends/controllers/ControlMinipage.C @@ -7,7 +7,7 @@ * * ====================================================== * - * \author Juergen Vigna, jug@sad.it + * \author Jürgen Vigna, jug@sad.it * \author Angus Leeming, a.leeming@ic.ac.uk */ @@ -25,6 +25,9 @@ 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) { @@ -40,7 +43,6 @@ ControlMinipage::ControlMinipage(LyXView & lv, Dialogs & d) void ControlMinipage::applyParamsToInset() { inset()->width(params().width); - inset()->widthp(params().widthp); inset()->pos(params().pos); lv_.view()->updateInset(inset(), true); @@ -59,16 +61,16 @@ MinipageParams const ControlMinipage::getParams(InsetMinipage const & inset) MinipageParams::MinipageParams() - : widthp(0), pos(InsetMinipage::top) + : pos(InsetMinipage::top) {} MinipageParams::MinipageParams(InsetMinipage const & inset) - : width(inset.width()), widthp(inset.widthp()), pos(inset.pos()) + : width(inset.width()), pos(inset.pos()) {} bool MinipageParams::operator==(MinipageParams const & o) const { - return (width == o.width && widthp == o.widthp && pos == o.pos); + return (width == o.width && pos == o.pos); } bool MinipageParams::operator!=(MinipageParams const & o) const @@ -81,16 +83,11 @@ namespace minipage { vector const getUnits() { vector units; - units.push_back("mm"); - units.push_back("in"); - units.push_back("em"); - units.push_back("%%"); - units.push_back("%%c"); - units.push_back("%%l"); - units.push_back("%%p"); + 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/ControlMinipage.h b/src/frontends/controllers/ControlMinipage.h index b5ef4fdca5..344f5fd53b 100644 --- a/src/frontends/controllers/ControlMinipage.h +++ b/src/frontends/controllers/ControlMinipage.h @@ -40,8 +40,6 @@ struct MinipageParams { /// string width; /// - int widthp; - /// InsetMinipage::Position pos; }; diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 67554e2360..c108e5c24c 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,8 @@ +2001-03-29 Juergen Vigna + + * FormMinipage.C: removed widthp_ and all it's functions and changed + to use new %-lengths of LyXLength. + 2001-03-28 Angus Leeming * FormGraphics.C: diff --git a/src/frontends/xforms/FormMinipage.C b/src/frontends/xforms/FormMinipage.C index 7ca95f30f7..bf31c4f7c8 100644 --- a/src/frontends/xforms/FormMinipage.C +++ b/src/frontends/xforms/FormMinipage.C @@ -22,6 +22,8 @@ #include "FormMinipage.h" #include "form_minipage.h" #include "support/lstrings.h" +#include "helper_funcs.h" +#include "debug.h" typedef FormCB > base_class; @@ -35,7 +37,9 @@ void FormMinipage::build() dialog_.reset(build_minipage()); fl_set_input_return(dialog_->input_width, FL_RETURN_CHANGED); - fl_set_input_return(dialog_->input_widthp, FL_RETURN_CHANGED); + + string const choice = getStringFromVector(minipage::getUnits(), "|"); + fl_addto_choice(dialog_->choice_width_units, subst(choice, "%", "%%").c_str()); // Manage the ok, apply and cancel/close buttons bc().setOK(dialog_->button_ok); @@ -44,7 +48,7 @@ void FormMinipage::build() bc().setUndoAll(dialog_->button_restore); bc().addReadOnly(dialog_->input_width); - bc().addReadOnly(dialog_->input_widthp); + bc().addReadOnly(dialog_->choice_width_units); bc().addReadOnly(dialog_->radio_top); bc().addReadOnly(dialog_->radio_middle); bc().addReadOnly(dialog_->radio_bottom); @@ -55,9 +59,11 @@ void FormMinipage::build() void FormMinipage::apply() { - controller().params().width = fl_get_input(dialog_->input_width); - controller().params().widthp = - strToInt(fl_get_input(dialog_->input_widthp)); + string const units = fl_get_choice_text(dialog_->choice_width_units); + double const val = strToDbl(fl_get_input(dialog_->input_width)); + + controller().params().width = + tostr(val) + frontStrip(strip(subst(units,"%%","%"))); if (fl_get_button(dialog_->radio_top)) controller().params().pos = InsetMinipage::top; @@ -70,11 +76,10 @@ void FormMinipage::apply() void FormMinipage::update() { - fl_set_input(dialog_->input_width, - controller().params().width.c_str()); - fl_set_input(dialog_->input_widthp, - tostr(controller().params().widthp).c_str()); - + LyXLength len(controller().params().width.c_str()); + 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); diff --git a/src/frontends/xforms/form_minipage.C b/src/frontends/xforms/form_minipage.C index ed97867bec..a4cc039bba 100644 --- a/src/frontends/xforms/form_minipage.C +++ b/src/frontends/xforms/form_minipage.C @@ -25,33 +25,17 @@ FD_form_minipage * FormMinipage::build_minipage() fdui->form = fl_bgn_form(FL_NO_BOX, 430, 170); fdui->form->u_vdata = this; obj = fl_add_box(FL_FLAT_BOX, 0, 0, 430, 170, ""); - obj = fl_add_frame(FL_ENGRAVED_FRAME, 230, 20, 190, 100, ""); - fl_set_object_color(obj, FL_COL1, FL_COL1); - obj = fl_add_frame(FL_ENGRAVED_FRAME, 20, 20, 200, 100, ""); - fl_set_object_color(obj, FL_COL1, FL_COL1); - { - char const * const dummy = N_("Length|#L"); - fdui->input_width = obj = fl_add_input(FL_NORMAL_INPUT, 100, 30, 110, 30, idex(_(dummy))); - fl_set_button_shortcut(obj, scex(_(dummy)), 1); - } + obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 20, 20, 200, 60, _("Width")); fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_callback(obj, C_FormBaseInputCB, 0); - { - // xgettext:no-c-format - char const * const dummy = N_("or %|#o"); - fdui->input_widthp = obj = fl_add_input(FL_INT_INPUT, 100, 70, 110, 30, idex(_(dummy))); - fl_set_button_shortcut(obj, scex(_(dummy)), 1); - } - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_callback(obj, C_FormBaseInputCB, 0); - obj = fl_add_text(FL_NORMAL_TEXT, 30, 10, 100, 20, _("Width")); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE); fl_set_object_lstyle(obj, FL_BOLD_STYLE); - obj = fl_add_text(FL_NORMAL_TEXT, 240, 10, 140, 20, _("Alignment")); + obj = fl_add_labelframe(FL_ENGRAVED_FRAME, 240, 20, 180, 100, _("Alignment")); fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_lalign(obj, FL_ALIGN_LEFT|FL_ALIGN_INSIDE); fl_set_object_lstyle(obj, FL_BOLD_STYLE); + fdui->input_width = obj = fl_add_input(FL_NORMAL_INPUT, 30, 30, 110, 30, ""); + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + fdui->choice_width_units = obj = fl_add_choice(FL_NORMAL_CHOICE2, 150, 30, 60, 30, ""); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); fdui->group_alignment = fl_bgn_group(); { diff --git a/src/frontends/xforms/form_minipage.h b/src/frontends/xforms/form_minipage.h index bf386ac471..9598da08ca 100644 --- a/src/frontends/xforms/form_minipage.h +++ b/src/frontends/xforms/form_minipage.h @@ -18,7 +18,7 @@ struct FD_form_minipage { FL_FORM *form; FL_OBJECT *input_width; - FL_OBJECT *input_widthp; + FL_OBJECT *choice_width_units; FL_OBJECT *group_alignment; FL_OBJECT *radio_top; FL_OBJECT *radio_middle; diff --git a/src/frontends/xforms/forms/form_minipage.fd b/src/frontends/xforms/forms/form_minipage.fd index 5a3e22e25b..c0bad20f0f 100644 --- a/src/frontends/xforms/forms/form_minipage.fd +++ b/src/frontends/xforms/forms/form_minipage.fd @@ -10,7 +10,7 @@ Unit of measure: FL_COORD_PIXEL Name: form_minipage Width: 430 Height: 170 -Number of Objects: 16 +Number of Objects: 14 -------------------- class: FL_BOX @@ -31,16 +31,16 @@ callback: argument: -------------------- -class: FL_FRAME +class: FL_LABELFRAME type: ENGRAVED_FRAME -box: 230 20 190 100 +box: 20 20 200 60 boxtype: FL_NO_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE +colors: FL_BLACK FL_COL1 +alignment: FL_ALIGN_TOP_LEFT +style: FL_BOLD_STYLE +size: FL_NORMAL_SIZE lcol: FL_BLACK -label: +label: Width shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity @@ -49,16 +49,16 @@ callback: argument: -------------------- -class: FL_FRAME +class: FL_LABELFRAME type: ENGRAVED_FRAME -box: 20 20 200 100 +box: 240 20 180 100 boxtype: FL_NO_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE +colors: FL_BLACK FL_COL1 +alignment: FL_ALIGN_TOP_LEFT +style: FL_BOLD_STYLE +size: FL_NORMAL_SIZE lcol: FL_BLACK -label: +label: Alignment shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity @@ -69,14 +69,14 @@ argument: -------------------- class: FL_INPUT type: NORMAL_INPUT -box: 100 30 110 30 +box: 30 30 110 30 boxtype: FL_DOWN_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_LEFT style: FL_NORMAL_STYLE size: FL_NORMAL_SIZE lcol: FL_BLACK -label: Length|#L +label: shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity @@ -85,63 +85,27 @@ callback: C_FormBaseInputCB argument: 0 -------------------- -class: FL_INPUT -type: INT_INPUT -box: 100 70 110 30 -boxtype: FL_DOWN_BOX -colors: FL_COL1 FL_MCOL +class: FL_CHOICE +type: NORMAL_CHOICE2 +box: 150 30 60 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_BLACK alignment: FL_ALIGN_LEFT style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE +size: FL_DEFAULT_SIZE lcol: FL_BLACK -label: or %|#o +label: shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: input_widthp +name: choice_width_units callback: C_FormBaseInputCB argument: 0 --------------------- -class: FL_TEXT -type: NORMAL_TEXT -box: 30 10 100 20 -boxtype: FL_FLAT_BOX -colors: FL_COL1 FL_MCOL -alignment: FL_ALIGN_LEFT|FL_ALIGN_INSIDE -style: FL_BOLD_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Width -shortcut: -resize: FL_RESIZE_ALL -gravity: FL_NoGravity FL_NoGravity -name: -callback: -argument: - --------------------- -class: FL_TEXT -type: NORMAL_TEXT -box: 240 10 140 20 -boxtype: FL_FLAT_BOX -colors: FL_COL1 FL_MCOL -alignment: FL_ALIGN_LEFT|FL_ALIGN_INSIDE -style: FL_BOLD_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Alignment -shortcut: -resize: FL_RESIZE_ALL -gravity: FL_NoGravity FL_NoGravity -name: -callback: -argument: - -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 0 0 0 +box: 0 10 10 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index e8469158e9..848f352cbc 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2001-03-29 Juergen Vigna + + * insetminipage.C: removed widthp_ and all it's functions and changed + to use new %-lengths of LyXLength. + 2001-03-28 Angus Leeming * insets/figinset.[Ch]: changed headers lyx.h, form1.h -> figure_form.h. diff --git a/src/insets/inset.C b/src/insets/inset.C index 95e69d2682..73211ba25a 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -229,9 +229,9 @@ UpdatableInset::LocalDispatch(BufferView * bv, } -int UpdatableInset::getMaxWidth(Painter & pain, UpdatableInset const *) const +int UpdatableInset::getMaxWidth(BufferView * bv, UpdatableInset const *) const { if (owner()) - return static_cast(owner())->getMaxWidth(pain, this); - return pain.paperWidth(); + return static_cast(owner())->getMaxWidth(bv, this); + return bv->workWidth(); } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 7d7e92c855..6bb4d92bb1 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -299,10 +299,10 @@ int InsetCollapsable::Latex(Buffer const * buf, ostream & os, } -int InsetCollapsable::getMaxWidth(Painter & pain, +int InsetCollapsable::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const { - int const w = UpdatableInset::getMaxWidth(pain, inset); + int const w = UpdatableInset::getMaxWidth(bv, inset); if (w < 0) { // What does a negative max width signify? (Lgb) diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index f7bb4258f4..9674eb2882 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -121,7 +121,7 @@ public: /// void setAutoCollapse(bool f) { autocollapse = f; } /// - int getMaxWidth(Painter & pain, UpdatableInset const *) const; + int getMaxWidth(BufferView *, UpdatableInset const *) const; /// LyXText * getLyXText(BufferView const *, bool const recursive) const; /// diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index cc096f24e2..9a2f1e2739 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -69,7 +69,7 @@ InsetMinipage::InsetMinipage() setLabelFont(font); setAutoCollapse(false); setInsetName("Minipage"); - widthp_ = 100; // set default to 100% of column_width + width_ = "100%"; // set default to 100% of column_width } @@ -85,8 +85,7 @@ void InsetMinipage::Write(Buffer const * buf, ostream & os) const << "position " << pos_ << "\n" << "inner_position " << inner_pos_ << "\n" << "height \"" << height_ << "\"\n" - << "width \"" << width_ << "\"\n" - << "widthp " << widthp_ << "\n"; + << "width \"" << width_ << "\"\n"; InsetCollapsable::Write(buf, os); } @@ -149,6 +148,9 @@ void InsetMinipage::Read(Buffer const * buf, LyXLex & lex) << endl; } } +#warning Remove me before final 1.2.0 (Jug) + // this is only for compatibility to the intermediate format and should + // vanish till the final 1.2.0! if (lex.IsOK()) { if (token.empty()) { lex.next(); @@ -156,13 +158,17 @@ void InsetMinipage::Read(Buffer const * buf, LyXLex & lex) } if (token == "widthp") { lex.next(); - widthp_ = lex.GetInteger(); + // only do this if the width_-string was not already set! + if (width_.empty()) + width_ = lex.GetString() + "%"; token = string(); } else { lyxerr << "InsetMinipage::Read: Missing 'widthp_'-tag!" << endl; } } + if (!token.empty()) + lex.pushToken(token); InsetCollapsable::Read(buf, lex); } @@ -177,7 +183,6 @@ Inset * InsetMinipage::Clone(Buffer const &) const result->inner_pos_ = inner_pos_; result->height_ = height_; result->width_ = width_; - result->widthp_ = widthp_; return result; } @@ -251,18 +256,12 @@ int InsetMinipage::Latex(Buffer const * buf, s_pos += "b"; break; } - - if (width_.empty()) { - os << "\\begin{minipage}[" << s_pos << "]{." - << widthp_ << "\\columnwidth}%\n"; - } else { - os << "\\begin{minipage}[" << s_pos << "]{" - << width_ << "}%\n"; - } + os << "\\begin{minipage}[" << s_pos << "]{" + << LyXLength(width_).asLatexString() << "}%\n"; int i = inset->Latex(buf, os, fragile, fp); + os << "\\end{minipage}%\n"; - return i + 2; } @@ -324,23 +323,6 @@ void InsetMinipage::width(string const & ll) width_ = ll; } -int InsetMinipage::widthp() const -{ - return widthp_; -} - - -void InsetMinipage::widthp(int ll) -{ - widthp_ = ll; -} - - -void InsetMinipage::widthp(string const & ll) -{ - widthp_ = strToInt(ll); -} - bool InsetMinipage::ShowInsetDialog(BufferView * bv) const { @@ -361,10 +343,11 @@ void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y, } -int InsetMinipage::getMaxWidth(Painter & pain, UpdatableInset const * inset) +int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const { if (!width_.empty()) - return VSpace(width_).inPixels(0, 0); - return InsetCollapsable::getMaxWidth(pain, inset) / 100 * widthp_; + return VSpace(width_).inPixels(bv); + // this should not happen! + return InsetCollapsable::getMaxWidth(bv, inset); } diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index e324f27a3e..01880f1da7 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -77,17 +77,11 @@ public: /// void width(string const &); /// - int widthp() const; - /// - void widthp(int); - /// - void widthp(string const &); - /// SigC::Signal0 hideDialog; /// void InsetButtonRelease(BufferView * bv, int x, int y, int button); /// - int getMaxWidth(Painter &, UpdatableInset const *) const; + int getMaxWidth(BufferView *, UpdatableInset const *) const; /// bool needFullRow() const { return false; } /// @@ -101,8 +95,6 @@ private: string height_; /// string width_; - /// - int widthp_; }; #endif diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index cce5b9affc..143f1d3bea 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1812,17 +1812,17 @@ bool InsetTabular::InsetHit(BufferView *, int x, int) const // This returns paperWidth() if the cell-width is unlimited or the width // in pixels if we have a pwidth for this cell. -int InsetTabular::GetMaxWidthOfCell(Painter &, int cell) const +int InsetTabular::GetMaxWidthOfCell(BufferView * bv, int cell) const { string const s = tabular->GetPWidth(cell); if (s.empty()) return -1; - return VSpace(s).inPixels(0, 0); + return VSpace(s).inPixels(bv); } -int InsetTabular::getMaxWidth(Painter & pain, +int InsetTabular::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const { int const n = tabular->GetNumberOfCells(); @@ -1833,7 +1833,7 @@ int InsetTabular::getMaxWidth(Painter & pain, } if (cell >= n) return -1; - int w = GetMaxWidthOfCell(pain, cell); + int w = GetMaxWidthOfCell(bv, cell); if (w > 0) // because the inset then subtracts it's top_x and owner->x() w += (inset->x() - top_x); diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index da12246a22..e6ac44f7b1 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -159,7 +159,7 @@ public: /// void SetFont(BufferView *, LyXFont const &, bool toggleall = false); /// - int getMaxWidth(Painter & pain, UpdatableInset const *) const; + int getMaxWidth(BufferView *, UpdatableInset const *) const; /// Buffer * BufferOwner() const { return const_cast(buffer); } /// @@ -232,7 +232,7 @@ private: /// bool InsetHit(BufferView * bv, int x, int y) const; /// - int GetMaxWidthOfCell(Painter &, int cell) const; + int GetMaxWidthOfCell(BufferView * bv, int cell) const; /// bool hasPasteBuffer() const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 833eb64c62..1fdad5dc02 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -288,15 +288,15 @@ int InsetText::descent(BufferView * bv, LyXFont const &) const int InsetText::width(BufferView * bv, LyXFont const &) const { - insetWidth = max(textWidth(bv->painter()), + insetWidth = max(textWidth(bv), (int)TEXT(bv)->width + (2 * TEXT_TO_INSET_OFFSET)); return insetWidth; } -int InsetText::textWidth(Painter & pain) const +int InsetText::textWidth(BufferView * bv) const { - int const w = getMaxWidth(pain, this); + int const w = getMaxWidth(bv, this); return w; } @@ -470,7 +470,7 @@ void InsetText::update(BufferView * bv, LyXFont const & font, bool reinit) // static_cast(TEXT(bv)->width) + drawTextXOffset) + // (2 * TEXT_TO_INSET_OFFSET); #else - insetWidth = textWidth(bv->painter()); + insetWidth = textWidth(bv); if (insetWidth < 0) insetWidth = static_cast(TEXT(bv)->width); #endif @@ -1517,9 +1517,9 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y, } -int InsetText::getMaxWidth(Painter & pain, UpdatableInset const * inset) const +int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const { - int w = UpdatableInset::getMaxWidth(pain, inset); + int w = UpdatableInset::getMaxWidth(bv, inset); if (w < 0) { return w; } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index e464507de0..934781980e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -93,7 +93,7 @@ public: /// int width(BufferView *, LyXFont const & f) const; /// - int textWidth(Painter &) const; + int textWidth(BufferView *) const; /// void draw(BufferView *, LyXFont const &, int , float &, bool) const; /// @@ -154,7 +154,7 @@ public: /// void SetFont(BufferView *, LyXFont const &, bool toggleall = false); /// - int getMaxWidth(Painter &, UpdatableInset const *) const; + int getMaxWidth(BufferView *, UpdatableInset const *) const; /// void init(InsetText const * ins = 0); /// diff --git a/src/insets/lyxinset.h b/src/insets/lyxinset.h index 240b08841e..86321f977c 100644 --- a/src/insets/lyxinset.h +++ b/src/insets/lyxinset.h @@ -361,7 +361,7 @@ public: /// virtual bool isCursorVisible() const { return cursor_visible; } /// - virtual int getMaxWidth(Painter & pain, UpdatableInset const *) const; + virtual int getMaxWidth(BufferView * bv, UpdatableInset const *) const; /// int scroll() const { return scx; } /// diff --git a/src/tabular.C b/src/tabular.C index 5f149ce266..ab3b4d8d14 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -1993,7 +1993,6 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const if (LeftLine(cell)) os << '|'; if (!GetPWidth(cell).empty()) { -#warning Jürgen, are these alignments correct? (Lgb) switch (GetVAlignment(cell)) { case LYX_VALIGN_TOP: os << "p"; @@ -2044,7 +2043,6 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const } else if (GetUsebox(cell) == BOX_MINIPAGE) { os << "\\begin{minipage}["; switch (GetVAlignment(cell)) { -#warning Jürgen, are these alignments correct? (Lgb) case LYX_VALIGN_TOP: os << "t"; break; @@ -2109,7 +2107,6 @@ int LyXTabular::Latex(Buffer const * buf, os << column_info[i].align_special; } else if (!column_info[i].p_width.empty()) { switch (column_info[i].valignment) { -#warning Jürgen, are these alignments correct? (Lgb) case LYX_VALIGN_TOP: os << "p"; break; diff --git a/src/text.C b/src/text.C index 42def16a19..adfd49e924 100644 --- a/src/text.C +++ b/src/text.C @@ -52,7 +52,7 @@ extern int bibitemMaxWidth(BufferView *, LyXFont const &); int LyXText::workWidth(BufferView * bview) const { if (inset_owner) { - return inset_owner->textWidth(bview->painter()); + return inset_owner->textWidth(bview); } return bview->workWidth(); } diff --git a/src/vspace.C b/src/vspace.C index 03e6128aff..a3b94aa054 100644 --- a/src/vspace.C +++ b/src/vspace.C @@ -34,7 +34,8 @@ int const num_units = LyXLength::UNIT_NONE; // I am not sure if "mu" should be possible to select (Lgb) char const * unit_name[num_units] = { "sp", "pt", "bp", "dd", "mm", "pc", "cc", "cm", - "in", "ex", "em", "mu" }; + "in", "ex", "em", "mu", + "%", "c%", "p%", "l%" }; /* The following static items form a simple scanner for @@ -104,7 +105,7 @@ char nextToken(string & data) } else return 'E'; } - i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz"); + i = data.find_first_not_of("abcdefghijklmnopqrstuvwxyz%"); if (i != 0) { if (unit_index > 3) return 'E'; @@ -162,6 +163,13 @@ LaTeXLength table[] = { } // namespace anon +const char * stringFromUnit(int unit) +{ + if (unit < 0 || unit >= num_units) + return 0; + return unit_name[unit]; +} + LyXLength::UNIT unitFromString (string const & data) { @@ -323,6 +331,28 @@ string const LyXLength::asString() const } +string const LyXLength::asLatexString() const +{ + std::ostringstream buffer; + switch(uni) { + case PW: + case PE: + buffer << "." << abs(static_cast(val)) << "\\columnwidth"; + break; + case PP: + buffer << "." << abs(static_cast(val)) << "\\pagewidth"; + break; + case PL: + buffer << "." << abs(static_cast(val)) << "\\linewidth"; + break; + default: + buffer << val << unit_name[uni]; // setw? + break; + } + return buffer.str().c_str(); +} + + /* LyXGlueLength class */ @@ -521,13 +551,15 @@ int VSpace::inPixels(BufferView * bv) const // Height of a normal line in pixels (zoom factor considered) int height = bv->text->DefaultHeight(); // [pixels] int skip = 0; + int width = bv->workWidth(); + if (kin == DEFSKIP) skip = bv->buffer()->params.getDefSkip().inPixels(bv); - return inPixels(height, skip); + return inPixels(height, skip, width); } -int VSpace::inPixels(int default_height, int default_skip) const +int VSpace::inPixels(int default_height, int default_skip, int default_width) const { // Height of a normal line in pixels (zoom factor considered) int height = default_height; // [pixels] @@ -623,6 +655,12 @@ int VSpace::inPixels(int default_height, int default_skip) const // math mode result = zoom * value * height; break; + case LyXLength::PW: // Always % of workarea + case LyXLength::PE: + case LyXLength::PP: + case LyXLength::PL: + result = value * default_width / 100; + break; case LyXLength::UNIT_NONE: result = 0; // this cannot happen break; diff --git a/src/vspace.h b/src/vspace.h index f3c8f5072d..fec4083b68 100644 --- a/src/vspace.h +++ b/src/vspace.h @@ -50,6 +50,13 @@ public: EM, /// Math unit (18mu = 1em) for positioning in math mode MU, + /// Percent of columnwidth both "%" or "%c" + PW, + PE, + /// Percent of pagewidth + PP, + /// Percent of linewidth + PL, /// no unit UNIT_NONE }; @@ -71,9 +78,7 @@ public: /// conversion virtual string const asString() const; /// - virtual string const asLatexString() const { - return this->asString(); - } + virtual string const asLatexString() const; /** If "data" is valid, the length represented by it is stored into "result", if that is not 0. */ @@ -99,6 +104,8 @@ bool operator==(LyXLength const & l1, LyXLength const & l2) extern LyXLength::UNIT unitFromString (string const & data); /// extern bool isValidLength(string const & data, LyXLength * result); +/// +extern const char * stringFromUnit(int unit); /// LyXGlueLength class class LyXGlueLength : public LyXLength { @@ -239,7 +246,7 @@ public: /// int inPixels(BufferView * bv) const; /// - int inPixels(int default_height, int default_skip) const; + int inPixels(int default_height, int default_skip, int default_width=0) const; private: /// This VSpace kind vspace_kind kin;