X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetminipage.C;h=b01bd3b858a104f5d033dd3db0b4894f62c26783;hb=b9288969ec06caa3d7b1e9d4eb7937c1e029b44f;hp=f425b2be1d174bd8e1c79f47ed499b7d335a9fc6;hpb=487f6eb3b43746460d090f643cd1e39f2d93a74b;p=lyx.git diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index f425b2be1d..b01bd3b858 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -25,6 +25,7 @@ #include "support/lstrings.h" #include "debug.h" #include "gettext.h" +#include "lyxlex.h" using std::ostream; using std::endl; @@ -58,9 +59,9 @@ using std::endl; // have to output "" for minipages. // (Lgb) -InsetMinipage::InsetMinipage() - : InsetCollapsable(), pos_(center), - inner_pos_(inner_center) +InsetMinipage::InsetMinipage(BufferParams const & bp) + : InsetCollapsable(bp), pos_(center), + inner_pos_(inner_center), width_(100, LyXLength::PW) { setLabel(_("minipage")); LyXFont font(LyXFont::ALL_SANE); @@ -68,9 +69,29 @@ InsetMinipage::InsetMinipage() font.decSize(); font.setColor(LColor::collapsable); setLabelFont(font); +#if 0 setAutoCollapse(false); +#endif +#ifdef WITH_WARNINGS +#warning Remove this color definitions before 1.2.0 final! +#endif + // just for experimentation :) + setBackgroundColor(LColor::green); + inset.setFrameColor(0, LColor::blue); setInsetName("Minipage"); - width_ = "100%"; // set default to 100% of column_width +} + + +InsetMinipage::InsetMinipage(InsetMinipage const & in, bool same_id) + : InsetCollapsable(in, same_id), + pos_(in.pos_), inner_pos_(in.inner_pos_), + height_(in.height_), width_(in.width_) +{} + + +Inset * InsetMinipage::clone(Buffer const &, bool same_id) const +{ + return new InsetMinipage(*const_cast(this), same_id); } @@ -85,115 +106,74 @@ 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); } void InsetMinipage::read(Buffer const * buf, LyXLex & lex) { - string token; - - if (lex.IsOK()) { + if (lex.isOK()) { lex.next(); - token = lex.GetString(); + string const token = lex.getString(); if (token == "position") { lex.next(); - pos_ = static_cast(lex.GetInteger()); - token = string(); + pos_ = static_cast(lex.getInteger()); } else { lyxerr << "InsetMinipage::Read: Missing 'position'-tag!" << endl; + // take countermeasures + lex.pushToken(token); } } - if (lex.IsOK()) { - if (token.empty()) { - lex.next(); - token = lex.GetString(); - } + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); if (token == "inner_position") { lex.next(); - inner_pos_ = static_cast(lex.GetInteger()); - token = string(); + inner_pos_ = static_cast(lex.getInteger()); } else { lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!" << endl; + // take countermeasures + lex.pushToken(token); } } - if (lex.IsOK()) { - if (token.empty()) { - lex.next(); - token = lex.GetString(); - } + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); if (token == "height") { lex.next(); - height_ = lex.GetString(); - token = string(); + height_ = LyXLength(lex.getString()); } else { lyxerr << "InsetMinipage::Read: Missing 'height'-tag!" << endl; + // take countermeasures + lex.pushToken(token); } } - if (lex.IsOK()) { - if (token.empty()) { - lex.next(); - token = lex.GetString(); - } + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); if (token == "width") { lex.next(); - width_ = lex.GetString(); - token = string(); + width_ = LyXLength(lex.getString()); } else { lyxerr << "InsetMinipage::Read: Missing 'width'-tag!" << endl; + // take countermeasures + lex.pushToken(token); } } -#ifdef WITH_WARNINGS -#warning Remove me before final 1.2.0 (Jug) -#warning Can we please remove this as soon as possible? (Lgb) -#endif - // 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(); - token = lex.GetString(); - } - if (token == "widthp") { - lex.next(); - // only do this if the width_-string was not already set! - if (width_.empty()) - width_ = lex.GetString() + "%"; - token = string(); - } - } - if (!token.empty()) - lex.pushToken(token); InsetCollapsable::read(buf, lex); } -Inset * InsetMinipage::clone(Buffer const &, bool same_id) const -{ - InsetMinipage * result = new InsetMinipage; - result->inset.init(&inset, same_id); - - result->collapsed_ = collapsed_; - result->pos_ = pos_; - result->inner_pos_ = inner_pos_; - result->height_ = height_; - result->width_ = width_; - if (same_id) - result->id_ = id_; - return result; -} - - int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const { if (collapsed_) - return ascent_collapsed(bv->painter(), font); + return ascent_collapsed(); else { // Take placement into account. int i = 0; @@ -217,7 +197,7 @@ int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const { if (collapsed_) - return descent_collapsed(bv->painter(), font); + return descent_collapsed(); else { // Take placement into account. int i = 0; @@ -260,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); @@ -269,17 +249,12 @@ int InsetMinipage::latex(Buffer const * buf, } -bool InsetMinipage::insertInsetAllowed(Inset * in) const -{ - return insertInsetAllowed(in->lyxCode()); -} - -bool InsetMinipage::insertInsetAllowed(Inset::Code code) const +bool InsetMinipage::insetAllowed(Inset::Code code) const { if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE)) return false; - return InsetCollapsable::insertInsetAllowed(code); + return InsetCollapsable::insetAllowed(code); } @@ -291,7 +266,10 @@ InsetMinipage::Position InsetMinipage::pos() const void InsetMinipage::pos(InsetMinipage::Position p) { - pos_ = p; + if (pos_ != p) { + pos_ = p; + need_update = FULL; + } } @@ -307,54 +285,66 @@ void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip) } -string const & InsetMinipage::height() const +LyXLength const & InsetMinipage::pageHeight() const { return height_; } -void InsetMinipage::height(string const & ll) +void InsetMinipage::pageHeight(LyXLength const & ll) { - height_ = ll; + if (height_ != ll) { + height_ = ll; + need_update = FULL; + } } -string const & InsetMinipage::width() const +LyXLength const & InsetMinipage::pageWidth() const { return width_; } -void InsetMinipage::width(string const & ll) +void InsetMinipage::pageWidth(LyXLength const & ll) { - width_ = ll; + if (ll != width_) { + width_ = ll; + need_update = FULL; + } } bool InsetMinipage::showInsetDialog(BufferView * bv) const { if (!inset.showInsetDialog(bv)) - bv->owner()->getDialogs()->showMinipage(const_cast(this)); + bv->owner()->getDialogs()->showMinipage(const_cast(this)); return true; } -void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y, - int button) +int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) + const { - if (button == 3) { - showInsetDialog(bv); - return; + if (owner() && + static_cast(owner())->getMaxWidth(bv, inset) < 0) { + return -1; + } + if (!width_.zero()) { + int ww1 = latexTextWidth(bv); + int ww2 = InsetCollapsable::getMaxWidth(bv, inset); + if (ww2 > 0 && ww2 < ww1) { + return ww2; + } + return ww1; } - InsetCollapsable::insetButtonRelease(bv, x, y, button); + // this should not happen! + return InsetCollapsable::getMaxWidth(bv, inset); } -int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) - const +int InsetMinipage::latexTextWidth(BufferView * bv) const { - if (!width_.empty()) - return VSpace(width_).inPixels(bv); - // this should not happen! - return InsetCollapsable::getMaxWidth(bv, inset); + return width_.inPixels(InsetCollapsable::latexTextWidth(bv), + bv->text->defaultHeight()); }