X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetminipage.C;h=9d194680131eb4296f0b88d486e4d04e0250aa81;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=8ab1df6a96523380ef40a5c186c113ea59a148e2;hpb=de3b5aab16e517258d6bebb6122697adf8999ae5;p=lyx.git diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 8ab1df6a96..9d19468013 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -61,7 +61,7 @@ using std::endl; InsetMinipage::InsetMinipage() : InsetCollapsable(), pos_(center), - inner_pos_(inner_center) + inner_pos_(inner_center), width_(100, LyXLength::PW) { setLabel(_("minipage")); LyXFont font(LyXFont::ALL_SANE); @@ -79,7 +79,6 @@ InsetMinipage::InsetMinipage() setBackgroundColor(LColor::green); inset.setFrameColor(0, LColor::blue); setInsetName("Minipage"); - width_ = "100%"; // set default to 100% of column_width } @@ -107,8 +106,8 @@ void InsetMinipage::write(Buffer const * buf, ostream & os) const os << getInsetName() << "\n" << "position " << pos_ << "\n" << "inner_position " << inner_pos_ << "\n" - << "height \"" << height_ << "\"\n" - << "width \"" << width_ << "\"\n"; + << "height \"" << height_.asString() << "\"\n" + << "width \"" << width_.asString() << "\"\n"; InsetCollapsable::write(buf, os); } @@ -146,7 +145,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); if (token == "height") { lex.next(); - height_ = lex.getString(); + height_ = LyXLength(lex.getString()); } else { lyxerr << "InsetMinipage::Read: Missing 'height'-tag!" << endl; @@ -159,7 +158,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); if (token == "width") { lex.next(); - width_ = lex.getString(); + width_ = LyXLength(lex.getString()); } else { lyxerr << "InsetMinipage::Read: Missing 'width'-tag!" << endl; @@ -241,7 +240,7 @@ int InsetMinipage::latex(Buffer const * buf, break; } os << "\\begin{minipage}[" << s_pos << "]{" - << LyXLength(width_).asLatexString() << "}%\n"; + << width_.asLatexString() << "}%\n"; int i = inset.latex(buf, os, fragile, fp); @@ -286,13 +285,13 @@ void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip) } -string const & InsetMinipage::pageHeight() const +LyXLength const & InsetMinipage::pageHeight() const { return height_; } -void InsetMinipage::pageHeight(string const & ll) +void InsetMinipage::pageHeight(LyXLength const & ll) { if (height_ != ll) { height_ = ll; @@ -301,13 +300,13 @@ void InsetMinipage::pageHeight(string const & ll) } -string const & InsetMinipage::pageWidth() const +LyXLength const & InsetMinipage::pageWidth() const { return width_; } -void InsetMinipage::pageWidth(string const & ll) +void InsetMinipage::pageWidth(LyXLength const & ll) { if (ll != width_) { width_ = ll; @@ -328,29 +327,24 @@ int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const { if (owner() && - (static_cast(owner())->getMaxWidth(bv, inset) < 0)) - { + static_cast(owner())->getMaxWidth(bv, inset) < 0) { return -1; } - if (!width_.empty()) { - LyXLength len(width_); - switch(len.unit()) { - case LyXLength::PW: // Always % of workarea - case LyXLength::PE: - case LyXLength::PP: - case LyXLength::PL: - return (InsetCollapsable::getMaxWidth(bv, inset) * (int)len.value()) / 100; - default: - { - int ww1 = VSpace(width_).inPixels(bv); - int ww2 = InsetCollapsable::getMaxWidth(bv, inset); - if (ww2 > 0 && ww2 < ww1) { - return ww2; - } - return ww1; - } + if (!width_.zero()) { + int ww1 = latexTextWidth(bv); + int ww2 = InsetCollapsable::getMaxWidth(bv, inset); + if (ww2 > 0 && ww2 < ww1) { + return ww2; } + return ww1; } // this should not happen! return InsetCollapsable::getMaxWidth(bv, inset); } + + +int InsetMinipage::latexTextWidth(BufferView * bv) const +{ + return width_.inPixels(InsetCollapsable::latexTextWidth(bv), + bv->text->defaultHeight()); +}