X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetminipage.C;h=c763d727a161ec9c8ce4e2d10a9e623d1a4399de;hb=26f1a5bfcae4b7fd7b946a1884c396d842b24925;hp=bb1ef5bfb2cd78b5f390952bd153d56857577a85;hpb=c10dfd15cd79499dd23f161d8f1716c00a143e09;p=lyx.git diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index bb1ef5bfb2..c763d727a1 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -1,31 +1,33 @@ -/* This file is part of - * ====================================================== +/** + * \file insetminipage.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor + * \author Jürgen Vigna + * \author Lars Gullik Bjønnes * - * Copyright 1998 The LyX Team. - * - *======================================================*/ + * Full author contact details are available in file CREDITS + */ #include -#ifdef __GNUG__ -#pragma implementation -#endif #include "insetminipage.h" +#include "insettext.h" + +#include "BufferView.h" +#include "debug.h" +#include "funcrequest.h" #include "gettext.h" #include "lyxfont.h" -#include "BufferView.h" +#include "lyxlex.h" +#include "lyxtext.h" + #include "frontends/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; @@ -60,8 +62,7 @@ using std::endl; // (Lgb) InsetMinipage::InsetMinipage(BufferParams const & bp) - : InsetCollapsable(bp), pos_(center), - inner_pos_(inner_center), width_(100, LyXLength::PW) + : InsetCollapsable(bp) { setLabel(_("minipage")); LyXFont font(LyXFont::ALL_SANE); @@ -87,9 +88,7 @@ InsetMinipage::InsetMinipage(BufferParams const & bp) 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_) + : InsetCollapsable(in, same_id), params_(in.params_) {} @@ -101,29 +100,62 @@ Inset * InsetMinipage::clone(Buffer const &, bool same_id) const InsetMinipage::~InsetMinipage() { - hideDialog(); + InsetMinipageMailer mailer(*this); + mailer.hideDialog(); } -void InsetMinipage::write(Buffer const * buf, ostream & os) const +dispatch_result InsetMinipage::localDispatch(FuncRequest const & cmd) { - os << getInsetName() << "\n" - << "position " << pos_ << "\n" - << "inner_position " << inner_pos_ << "\n" - << "height \"" << height_.asString() << "\"\n" - << "width \"" << width_.asString() << "\"\n"; - InsetCollapsable::write(buf, os); + Inset::RESULT result = UNDISPATCHED; + + switch (cmd.action) { + case LFUN_INSET_MODIFY: { + InsetMinipage::Params params; + InsetMinipageMailer::string2params(cmd.argument, params); + + params_.pos = params.pos; + params_.width = params.width; + + // FIXME: what magical mysterious commands are actually + // needed here to update the bloody size of the inset !!! + cmd.view()->updateInset(this); + result = DISPATCHED; + } + break; + + case LFUN_INSET_DIALOG_UPDATE: { + InsetMinipageMailer mailer(*this); + mailer.updateDialog(cmd.view()); + } + break; + + default: + result = InsetCollapsable::localDispatch(cmd); + } + + return result; } -void InsetMinipage::read(Buffer const * buf, LyXLex & lex) +void InsetMinipage::Params::write(ostream & os) const +{ + os << "Minipage" << '\n' + << "position " << pos << '\n' + << "inner_position " << inner_pos << '\n' + << "height \"" << height.asString() << "\"\n" + << "width \"" << width.asString() << "\"\n"; +} + + +void InsetMinipage::Params::read(LyXLex & lex) { if (lex.isOK()) { lex.next(); string const token = lex.getString(); if (token == "position") { lex.next(); - pos_ = static_cast(lex.getInteger()); + pos = static_cast(lex.getInteger()); } else { lyxerr << "InsetMinipage::Read: Missing 'position'-tag!" << endl; @@ -136,7 +168,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); if (token == "inner_position") { lex.next(); - inner_pos_ = static_cast(lex.getInteger()); + inner_pos = static_cast(lex.getInteger()); } else { lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!" << endl; @@ -149,7 +181,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); if (token == "height") { lex.next(); - height_ = LyXLength(lex.getString()); + height = LyXLength(lex.getString()); } else { lyxerr << "InsetMinipage::Read: Missing 'height'-tag!" << endl; @@ -162,7 +194,7 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) string const token = lex.getString(); if (token == "width") { lex.next(); - width_ = LyXLength(lex.getString()); + width = LyXLength(lex.getString()); } else { lyxerr << "InsetMinipage::Read: Missing 'width'-tag!" << endl; @@ -170,6 +202,19 @@ void InsetMinipage::read(Buffer const * buf, LyXLex & lex) lex.pushToken(token); } } +} + + +void InsetMinipage::write(Buffer const * buf, ostream & os) const +{ + params_.write(os); + InsetCollapsable::write(buf, os); +} + + +void InsetMinipage::read(Buffer const * buf, LyXLex & lex) +{ + params_.read(lex); InsetCollapsable::read(buf, lex); } @@ -181,7 +226,7 @@ int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const else { // Take placement into account. int i = 0; - switch (pos_) { + switch (params_.pos) { case top: i = InsetCollapsable::ascent(bv, font); break; @@ -205,7 +250,7 @@ int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const else { // Take placement into account. int i = 0; - switch (pos_) { + switch (params_.pos) { case top: i = InsetCollapsable::descent(bv, font); break; @@ -232,19 +277,19 @@ int InsetMinipage::latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const { string s_pos; - switch (pos_) { + switch (params_.pos) { case top: - s_pos += "t"; + s_pos += 't'; break; case center: - s_pos += "c"; + s_pos += 'c'; break; case bottom: - s_pos += "b"; + s_pos += 'b'; break; } os << "\\begin{minipage}[" << s_pos << "]{" - << width_.asLatexString() << "}%\n"; + << params_.width.asLatexString() << "}%\n"; int i = inset.latex(buf, os, fragile, fp); @@ -262,93 +307,101 @@ bool InsetMinipage::insetAllowed(Inset::Code code) const } -InsetMinipage::Position InsetMinipage::pos() const +bool InsetMinipage::showInsetDialog(BufferView * bv) const { - return pos_; + if (!inset.showInsetDialog(bv)) { + InsetMinipage * tmp = const_cast(this); + InsetMinipageMailer mailer(*tmp); + mailer.showDialog(bv); + } + + return true; } -void InsetMinipage::pos(InsetMinipage::Position p) +int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) + const { - if (pos_ != p) { - pos_ = p; - need_update = FULL; + if (owner() && + static_cast(owner())->getMaxWidth(bv, inset) < 0) { + return -1; + } + if (!params_.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); } -InsetMinipage::InnerPosition InsetMinipage::innerPos() const +int InsetMinipage::latexTextWidth(BufferView * bv) const { - return inner_pos_; + return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv)); } -void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip) -{ - inner_pos_ = ip; -} - +InsetMinipage::Params::Params() + : pos(center), + inner_pos(inner_center), + width(100, LyXLength::PCW) +{} -LyXLength const & InsetMinipage::pageHeight() const -{ - return height_; -} +string const InsetMinipageMailer:: name_("minipage"); -void InsetMinipage::pageHeight(LyXLength const & ll) -{ - if (height_ != ll) { - height_ = ll; - need_update = FULL; - } -} +InsetMinipageMailer::InsetMinipageMailer(InsetMinipage & inset) + : inset_(inset) +{} -LyXLength const & InsetMinipage::pageWidth() const +string const InsetMinipageMailer::inset2string() const { - return width_; + return params2string(inset_.params()); } -void InsetMinipage::pageWidth(LyXLength const & ll) +void InsetMinipageMailer::string2params(string const & in, + InsetMinipage::Params & params) { - if (ll != width_) { - width_ = ll; - need_update = FULL; - } -} - + params = InsetMinipage::Params(); -bool InsetMinipage::showInsetDialog(BufferView * bv) const -{ - if (!inset.showInsetDialog(bv)) - bv->owner()->getDialogs().showMinipage(const_cast(this)); - return true; -} + istringstream data(in); + LyXLex lex(0,0); + lex.setStream(data); + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token != "minipage") + return; + } -int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset) - const -{ - if (owner() && - static_cast(owner())->getMaxWidth(bv, inset) < 0) { - return -1; + // This is part of the inset proper that is usually swallowed + // by Buffer::readInset + if (lex.isOK()) { + lex.next(); + string const token = lex.getString(); + if (token != "Minipage") + return; } - if (!width_.zero()) { - int ww1 = latexTextWidth(bv); - int ww2 = InsetCollapsable::getMaxWidth(bv, inset); - if (ww2 > 0 && ww2 < ww1) { - return ww2; - } - return ww1; + + if (lex.isOK()) { + params.read(lex); } - // this should not happen! - return InsetCollapsable::getMaxWidth(bv, inset); } -int InsetMinipage::latexTextWidth(BufferView * bv) const +string const +InsetMinipageMailer::params2string(InsetMinipage::Params const & params) { - return width_.inPixels(InsetCollapsable::latexTextWidth(bv), - bv->text->defaultHeight()); + ostringstream data; + data << name_ << ' '; + params.write(data); + + return data.str(); }