-/* This file is part of
- * ======================================================
- *
- * LyX, The Document Processor
- *
- * Copyright 1998 The LyX Team.
+/**
+ * \file insetminipage.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- *======================================================*/
+ * \author Jürgen Vigna
+ * \author Lars Gullik Bjønnes
+ *
+ * Full author contact details are available in file CREDITS
+ */
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "insetminipage.h"
-#include "gettext.h"
-#include "lyxfont.h"
+#include "insettext.h"
+
#include "BufferView.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 "dimension.h"
+#include "funcrequest.h"
#include "gettext.h"
+#include "Lsstream.h"
+#include "lyxfont.h"
#include "lyxlex.h"
+#include "lyxtext.h"
+#include "Lsstream.h"
+#include "metricsinfo.h"
+
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+
+#include "support/LOstream.h"
using std::ostream;
using std::endl;
+using std::auto_ptr;
// Some information about Minipages in LaTeX:
// have to output "" for minipages.
// (Lgb)
-InsetMinipage::InsetMinipage()
- : InsetCollapsable(), pos_(center),
- inner_pos_(inner_center)
+InsetMinipage::InsetMinipage(BufferParams const & bp)
+ : InsetCollapsable(bp)
{
setLabel(_("minipage"));
LyXFont font(LyXFont::ALL_SANE);
setLabelFont(font);
#if 0
setAutoCollapse(false);
+#endif
+
+#if 0
+#ifdef WITH_WARNINGS
+#warning Remove this color definitions before 1.2.0 final!
#endif
// just for experimentation :)
- setBackgroundColor(LColor::red);
+ setBackgroundColor(LColor::green);
+#endif
+
+ 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_)
+InsetMinipage::InsetMinipage(InsetMinipage const & in)
+ : InsetCollapsable(in), params_(in.params_)
{}
-Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
+auto_ptr<InsetBase> InsetMinipage::clone() const
{
- return new InsetMinipage(*const_cast<InsetMinipage *>(this), same_id);
+ return auto_ptr<InsetBase>(new InsetMinipage(*this));
}
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_ << "\"\n"
- << "width \"" << width_ << "\"\n";
- InsetCollapsable::write(buf, os);
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+ InsetMinipage::Params params;
+ InsetMinipageMailer::string2params(cmd.argument, params);
+
+ params_.pos = params.pos;
+ params_.width = params.width;
+
+ /* FIXME: I refuse to believe we have to live
+ * with ugliness like this ... */
+ inset.getLyXText(cmd.view())->fullRebreak();
+ cmd.view()->updateInset(this);
+ return DISPATCHED;
+ }
+
+ case LFUN_INSET_DIALOG_UPDATE:
+ InsetMinipageMailer(*this).updateDialog(cmd.view());
+ return DISPATCHED;
+
+ default:
+ return InsetCollapsable::localDispatch(cmd);
+ }
}
-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()) {
+ if (lex.isOK()) {
lex.next();
- string const token = lex.GetString();
+ string const token = lex.getString();
if (token == "position") {
lex.next();
- pos_ = static_cast<Position>(lex.GetInteger());
+ pos = static_cast<Position>(lex.getInteger());
} else {
lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
<< endl;
lex.pushToken(token);
}
}
- if (lex.IsOK()) {
+ if (lex.isOK()) {
lex.next();
- string const token = lex.GetString();
+ string const token = lex.getString();
if (token == "inner_position") {
lex.next();
- inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
+ inner_pos = static_cast<InnerPosition>(lex.getInteger());
} else {
lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
<< endl;
lex.pushToken(token);
}
}
- if (lex.IsOK()) {
+ if (lex.isOK()) {
lex.next();
- string const token = lex.GetString();
+ 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;
lex.pushToken(token);
}
}
- if (lex.IsOK()) {
+ if (lex.isOK()) {
lex.next();
- string const token = lex.GetString();
+ 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;
lex.pushToken(token);
}
}
- InsetCollapsable::read(buf, lex);
}
-int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
+void InsetMinipage::write(Buffer const * buf, ostream & os) 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;
- }
+ params_.write(os);
+ InsetCollapsable::write(buf, os);
+}
+
+
+void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
+{
+ params_.read(lex);
+ InsetCollapsable::read(buf, lex);
}
-int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
+void InsetMinipage::metrics(MetricsInfo & mi, Dimension & dim) const
{
if (collapsed_)
- return descent_collapsed();
+ dimension_collapsed(dim);
else {
- // Take placement into account.
- int i = 0;
- switch (pos_) {
+ Dimension d;
+ MetricsInfo m = mi;
+ m.base.textwidth = params_.width.inPixels(mi.base.textwidth);
+ InsetCollapsable::metrics(m, d);
+ switch (params_.pos) {
case top:
- i = InsetCollapsable::descent(bv, font);
+ dim.asc = d.asc;
+ dim.des = d.des;
break;
case center:
- i = (InsetCollapsable::ascent(bv, font)
- + InsetCollapsable::descent(bv, font)) / 2;
+ dim.asc = d.ascent() + d.descent() / 2;
+ dim.des = dim.asc;
break;
case bottom:
- i = InsetCollapsable::ascent(bv, font);
+ dim.asc = d.des;
+ dim.des = d.asc;
break;
}
- return i;
+ dim.wid = d.wid;
}
+ dim_ = dim;
}
}
-int InsetMinipage::latex(Buffer const * buf,
- ostream & os, bool fragile, bool fp) const
+int InsetMinipage::latex(Buffer const * buf, ostream & os,
+ LatexRunParams const & runparams) 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 << "]{"
- << LyXLength(width_).asLatexString() << "}%\n";
-
- int i = inset.latex(buf, os, fragile, fp);
+ << params_.width.asLatexString() << "}%\n";
+
+ int i = inset.latex(buf, os, runparams);
os << "\\end{minipage}%\n";
return i + 2;
}
-bool InsetMinipage::insetAllowed(Inset::Code code) const
+bool InsetMinipage::insetAllowed(InsetOld::Code code) const
{
- if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
+ if (code == InsetOld::FLOAT_CODE || code == InsetOld::MARGIN_CODE)
return false;
return InsetCollapsable::insetAllowed(code);
}
-InsetMinipage::Position InsetMinipage::pos() const
-{
- return pos_;
-}
-
-
-void InsetMinipage::pos(InsetMinipage::Position p)
+bool InsetMinipage::showInsetDialog(BufferView * bv) const
{
- if (pos_ != p) {
- pos_ = p;
- need_update = FULL;
+ if (!inset.showInsetDialog(bv)) {
+ InsetMinipage * tmp = const_cast<InsetMinipage *>(this);
+ InsetMinipageMailer mailer(*tmp);
+ mailer.showDialog(bv);
}
-}
-
-InsetMinipage::InnerPosition InsetMinipage::innerPos() const
-{
- return inner_pos_;
+ return true;
}
-void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
+int InsetMinipage::latexTextWidth(BufferView * bv) const
{
- inner_pos_ = ip;
+ return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv));
}
-string const & InsetMinipage::height() const
-{
- return height_;
-}
+InsetMinipage::Params::Params()
+ : pos(center),
+ inner_pos(inner_center),
+ width(100, LyXLength::PCW)
+{}
-void InsetMinipage::height(string const & ll)
-{
- if (height_ != ll) {
- height_ = ll;
- need_update = FULL;
- }
-}
+string const InsetMinipageMailer:: name_("minipage");
+
+InsetMinipageMailer::InsetMinipageMailer(InsetMinipage & inset)
+ : inset_(inset)
+{}
-string const & InsetMinipage::width() const
+string const InsetMinipageMailer::inset2string(Buffer const &) const
{
- return width_;
+ return params2string(inset_.params());
}
-void InsetMinipage::width(string const & ll)
+void InsetMinipageMailer::string2params(string const & in,
+ InsetMinipage::Params & params)
{
- if (ll != width_) {
- width_ = ll;
- need_update = FULL;
- }
-}
+ params = InsetMinipage::Params();
+ if (in.empty())
+ return;
-bool InsetMinipage::showInsetDialog(BufferView * bv) const
-{
- if (!inset.showInsetDialog(bv))
- bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
- return true;
-}
+ istringstream data(STRCONV(in));
+ LyXLex lex(0, 0);
+ lex.setStream(data);
+
+ if (lex.isOK()) {
+ lex.next();
+ string const token = lex.getString();
+ if (token != "minipage")
+ return;
+ }
+ // 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;
+ }
-void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
- int button)
-{
- if (button == 3) {
- showInsetDialog(bv);
- return;
+ if (lex.isOK()) {
+ params.read(lex);
}
- InsetCollapsable::insetButtonRelease(bv, x, y, button);
}
-int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
- const
+string const
+InsetMinipageMailer::params2string(InsetMinipage::Params const & params)
{
- if (!width_.empty())
- return VSpace(width_).inPixels(bv);
- // this should not happen!
- return InsetCollapsable::getMaxWidth(bv, inset);
+ ostringstream data;
+ data << name_ << ' ';
+ params.write(data);
+ return STRCONV(data.str());
}