X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetminipage.C;h=9d194680131eb4296f0b88d486e4d04e0250aa81;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=606648bcb9da111cae6bcbc6e4943c72529a7387;hpb=ee72ce87743857b4317da00e6e09cb6842095664;p=lyx.git diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index 606648bcb9..9d19468013 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -17,9 +17,15 @@ #include "gettext.h" #include "lyxfont.h" #include "BufferView.h" -#include "Painter.h" +#include "LyXView.h" +#include "frontends/Dialogs.h" #include "lyxtext.h" +#include "insets/insettext.h" #include "support/LOstream.h" +#include "support/lstrings.h" +#include "debug.h" +#include "gettext.h" +#include "lyxlex.h" using std::ostream; using std::endl; @@ -54,77 +60,291 @@ using std::endl; // (Lgb) InsetMinipage::InsetMinipage() - : InsetCollapsable() + : InsetCollapsable(), pos_(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"); } -void InsetMinipage::Write(Buffer const * buf, ostream & os) const +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); +} + + +InsetMinipage::~InsetMinipage() { - os << getInsetName() << "\n"; - InsetCollapsable::Write(buf, os); + hideDialog(); } -Inset * InsetMinipage::Clone() const +void InsetMinipage::write(Buffer const * buf, ostream & os) const { - InsetMinipage * result = new InsetMinipage; - result->init(this); - - result->collapsed = collapsed; - return result; + os << getInsetName() << "\n" + << "position " << pos_ << "\n" + << "inner_position " << inner_pos_ << "\n" + << "height \"" << height_.asString() << "\"\n" + << "width \"" << width_.asString() << "\"\n"; + InsetCollapsable::write(buf, os); } -char const * InsetMinipage::EditMessage() const +void InsetMinipage::read(Buffer const * buf, LyXLex & lex) +{ + 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 (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()) { + 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 (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); +} + + +int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const +{ + if (collapsed_) + return ascent_collapsed(); + else { + // Take placement into account. + int i = 0; + switch (pos_) { + case top: + i = InsetCollapsable::ascent(bv, font); + break; + case center: + i = (InsetCollapsable::ascent(bv, font) + + InsetCollapsable::descent(bv, font)) / 2; + break; + case bottom: + i = InsetCollapsable::descent(bv, font); + break; + } + return i; + } +} + + +int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const +{ + if (collapsed_) + return descent_collapsed(); + else { + // Take placement into account. + int i = 0; + switch (pos_) { + case top: + i = InsetCollapsable::descent(bv, font); + break; + case center: + i = (InsetCollapsable::ascent(bv, font) + + InsetCollapsable::descent(bv, font)) / 2; + break; + case bottom: + i = InsetCollapsable::ascent(bv, font); + break; + } + return i; + } +} + + +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 { - os << "\\begin{minipage}{\\columnwidth}%\n"; + string s_pos; + switch (pos_) { + case top: + s_pos += "t"; + break; + case center: + s_pos += "c"; + break; + case bottom: + s_pos += "b"; + break; + } + os << "\\begin{minipage}[" << s_pos << "]{" + << width_.asLatexString() << "}%\n"; - int i = InsetText::Latex(buf, os, fragile, fp); + int i = inset.latex(buf, os, fragile, fp); + os << "\\end{minipage}%\n"; - return i + 2; } -bool InsetMinipage::InsertInset(BufferView * bv, Inset * inset) +bool InsetMinipage::insetAllowed(Inset::Code code) const { - if (!InsertInsetAllowed(inset)) + if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE)) return false; - - return InsetText::InsertInset(bv, inset); + + return InsetCollapsable::insetAllowed(code); } -bool InsetMinipage::InsertInsetAllowed(Inset * inset) const +InsetMinipage::Position InsetMinipage::pos() const { - if ((inset->LyxCode() == Inset::FLOAT_CODE) || - (inset->LyxCode() == Inset::MARGIN_CODE)) { - return false; + return pos_; +} + + +void InsetMinipage::pos(InsetMinipage::Position p) +{ + if (pos_ != p) { + pos_ = p; + need_update = FULL; } +} + + +InsetMinipage::InnerPosition InsetMinipage::innerPos() const +{ + return inner_pos_; +} + + +void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip) +{ + inner_pos_ = ip; +} + + +LyXLength const & InsetMinipage::pageHeight() const +{ + return height_; +} + + +void InsetMinipage::pageHeight(LyXLength const & ll) +{ + if (height_ != ll) { + height_ = ll; + need_update = FULL; + } +} + + +LyXLength const & InsetMinipage::pageWidth() const +{ + return width_; +} + + +void InsetMinipage::pageWidth(LyXLength const & 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)); return true; } -LyXFont InsetMinipage::GetDrawFont(BufferView * bv, - LyXParagraph * p, int pos) const +int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) + const +{ + 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; + } + // this should not happen! + return InsetCollapsable::getMaxWidth(bv, inset); +} + + +int InsetMinipage::latexTextWidth(BufferView * bv) const { - LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos); - fn.decSize().decSize(); - return fn; + return width_.inPixels(InsetCollapsable::latexTextWidth(bv), + bv->text->defaultHeight()); }