X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetminipage.C;h=9d194680131eb4296f0b88d486e4d04e0250aa81;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=3424835567afcf4082e2007c02ea3f66666da368;hpb=93dda00aac4957bda8590e6cad2716081c8eee7b;p=lyx.git diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 3424835567..9d19468013 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -24,6 +24,8 @@ #include "support/LOstream.h" #include "support/lstrings.h" #include "debug.h" +#include "gettext.h" +#include "lyxlex.h" using std::ostream; using std::endl; @@ -59,17 +61,37 @@ 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); font.decSize(); font.decSize(); - font.setColor(LColor::footnote); + 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"); - widthp_ = 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); } @@ -79,110 +101,79 @@ InsetMinipage::~InsetMinipage() } -void InsetMinipage::Write(Buffer const * buf, ostream & os) const +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" - << "widthp " << widthp_ << "\n"; - InsetCollapsable::Write(buf, os); + << "height \"" << height_.asString() << "\"\n" + << "width \"" << width_.asString() << "\"\n"; + InsetCollapsable::write(buf, os); } -void InsetMinipage::Read(Buffer const * buf, LyXLex & lex) +void InsetMinipage::read(Buffer const * buf, LyXLex & lex) { - string token; - - if (lex.IsOK()) { - lex.next(); - token = lex.GetString(); - if (token == "position") { - lex.next(); - pos_ = static_cast(lex.GetInteger()); - token = string(); - } else { - lyxerr << "InsetMinipage::Read: Missing 'position'-tag!" - << endl; - } - } - if (lex.IsOK()) { - if (token.empty()) { - lex.next(); - token = lex.GetString(); - } - if (token == "inner_position") { - lex.next(); - inner_pos_ = static_cast(lex.GetInteger()); - token = string(); - } else { - lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!" - << endl; - } - } - if (lex.IsOK()) { - if (token.empty()) { - lex.next(); - token = lex.GetString(); - } - if (token == "height") { - lex.next(); - height_ = lex.GetString(); - token = string(); - } else { - lyxerr << "InsetMinipage::Read: Missing 'height'-tag!" - << endl; - } - } - if (lex.IsOK()) { - if (token.empty()) { - lex.next(); - token = lex.GetString(); + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token == "position") { + lex.next(); + pos_ = static_cast(lex.getInteger()); + } else { + lyxerr << "InsetMinipage::Read: Missing 'position'-tag!" + << endl; + // take countermeasures + lex.pushToken(token); + } } - if (token == "width") { - lex.next(); - width_ = lex.GetString(); - token = string(); - } else { - lyxerr << "InsetMinipage::Read: Missing 'width'-tag!" - << endl; + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token == "inner_position") { + lex.next(); + 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_ = LyXLength(lex.getString()); + } else { + lyxerr << "InsetMinipage::Read: Missing 'height'-tag!" + << endl; + // take countermeasures + lex.pushToken(token); + } } - if (token == "widthp") { - lex.next(); - widthp_ = lex.GetInteger(); - token = string(); - } else { - lyxerr << "InsetMinipage::Read: Missing 'widthp_'-tag!" - << endl; + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token == "width") { + lex.next(); + width_ = LyXLength(lex.getString()); + } else { + lyxerr << "InsetMinipage::Read: Missing 'width'-tag!" + << endl; + // take countermeasures + lex.pushToken(token); + } } - } - InsetCollapsable::Read(buf, lex); -} - - -Inset * InsetMinipage::Clone(Buffer const &) const -{ - InsetMinipage * result = new InsetMinipage; - result->inset->init(inset); - - result->collapsed = collapsed; - return result; + InsetCollapsable::read(buf, lex); } int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const { - lyxerr << "InsetMinipage::ascent" << endl; - - if (collapsed) - return ascent_collapsed(bv->painter(), font); + if (collapsed_) + return ascent_collapsed(); else { // Take placement into account. int i = 0; @@ -205,8 +196,8 @@ 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); + if (collapsed_) + return descent_collapsed(); else { // Take placement into account. int i = 0; @@ -227,13 +218,13 @@ int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const } -string const InsetMinipage::EditMessage() const +string const InsetMinipage::editMessage() const { return _("Opened Minipage Inset"); } -int InsetMinipage::Latex(Buffer const * buf, +int InsetMinipage::latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const { string s_pos; @@ -248,29 +239,22 @@ int InsetMinipage::Latex(Buffer const * buf, s_pos += "b"; break; } + os << "\\begin{minipage}[" << s_pos << "]{" + << width_.asLatexString() << "}%\n"; - if (width_.empty()) { - os << "\\begin{minipage}[" << s_pos << "]{." - << widthp_ << "\\columnwidth}%\n"; - } else { - os << "\\begin{minipage}[" << s_pos << "]{" - << width_ << "}%\n"; - } - - int i = inset->Latex(buf, os, fragile, fp); + int i = inset.latex(buf, os, fragile, fp); + os << "\\end{minipage}%\n"; - return i + 2; } -bool InsetMinipage::InsertInsetAllowed(Inset * in) const +bool InsetMinipage::insetAllowed(Inset::Code code) const { - if ((in->LyxCode() == Inset::FLOAT_CODE) || - (in->LyxCode() == Inset::MARGIN_CODE)) { + if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE)) return false; - } - return true; + + return InsetCollapsable::insetAllowed(code); } @@ -282,7 +266,10 @@ InsetMinipage::Position InsetMinipage::pos() const void InsetMinipage::pos(InsetMinipage::Position p) { - pos_ = p; + if (pos_ != p) { + pos_ = p; + need_update = FULL; + } } @@ -298,72 +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) -{ - width_ = ll; -} - -int InsetMinipage::widthp() const -{ - return widthp_; -} - - -void InsetMinipage::widthp(int ll) +void InsetMinipage::pageWidth(LyXLength const & ll) { - widthp_ = ll; + if (ll != width_) { + width_ = ll; + need_update = FULL; + } } -void InsetMinipage::widthp(string const & ll) +bool InsetMinipage::showInsetDialog(BufferView * bv) const { - widthp_ = strToInt(ll); + if (!inset.showInsetDialog(bv)) + 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) { -#if 0 -// we have to check first if we have a locking inset and if this locking inset -// has a popup menu with the 3rd button - if (the_locking_inset) { - UpdatableInset * i; - if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) { - i->InsetButtonRelease(bv, x, y, button); - return; - } + if (owner() && + static_cast(owner())->getMaxWidth(bv, inset) < 0) { + return -1; } -#endif - bv->owner()->getDialogs()->showMinipage(this); - return; - } - InsetCollapsable::InsetButtonRelease(bv, x, y, button); + 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::getMaxWidth(Painter & pain, UpdatableInset const * inset) - const + +int InsetMinipage::latexTextWidth(BufferView * bv) const { - if (!width_.empty()) - return VSpace(width_).inPixels(0, 0); - return InsetCollapsable::getMaxWidth(pain, inset) / 100 * widthp_; + return width_.inPixels(InsetCollapsable::latexTextWidth(bv), + bv->text->defaultHeight()); }