1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998 The LyX Team.
8 *======================================================*/
13 #pragma implementation
16 #include "insetminipage.h"
19 #include "BufferView.h"
21 #include "frontends/Dialogs.h"
23 #include "insets/insettext.h"
24 #include "support/LOstream.h"
25 #include "support/lstrings.h"
33 // Some information about Minipages in LaTeX:
34 // A minipage is a complete miniversion of a page and can contain
35 // its own footnotes, paragraphs, and array, tabular, and multicols
36 // environments. However it cannot contain floats or \marginpar's,
37 // but it can appear inside floats.
39 // The minipage environment is defined like this:
41 // \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
44 // pos [opt] = is the vertical placement of the box with respect
45 // to the text baseline, [c], [t] and [b].
46 // height [opt] = the height of the box
47 // inner-pos [opt] = the position of the text within the box.
48 // It can be t, c, b or s, if unspecified the value
50 // width = the width of the box
52 // In LyX we should try to support all these parameters, settable in a
54 // In this pop-up diallog it should also be possible to set all margin
55 // values that is usable in the minipage.
56 // With regard to different formats (like DocBook) I guess a minipage
57 // can be used there also. Perhaps not in the latex way, but we do not
58 // have to output "" for minipages.
61 InsetMinipage::InsetMinipage()
62 : InsetCollapsable(), pos_(center),
63 inner_pos_(inner_center)
65 setLabel(_("minipage"));
66 LyXFont font(LyXFont::ALL_SANE);
69 font.setColor(LColor::collapsable);
72 setAutoCollapse(false);
74 // just for experimentation :)
75 setBackgroundColor(LColor::red);
76 setInsetName("Minipage");
77 width_ = "100%"; // set default to 100% of column_width
81 InsetMinipage::InsetMinipage(InsetMinipage const & in, bool same_id)
82 : InsetCollapsable(in, same_id),
83 pos_(in.pos_), inner_pos_(in.inner_pos_),
84 height_(in.height_), width_(in.width_)
88 Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
90 return new InsetMinipage(*const_cast<InsetMinipage *>(this), same_id);
94 InsetMinipage::~InsetMinipage()
100 void InsetMinipage::write(Buffer const * buf, ostream & os) const
102 os << getInsetName() << "\n"
103 << "position " << pos_ << "\n"
104 << "inner_position " << inner_pos_ << "\n"
105 << "height \"" << height_ << "\"\n"
106 << "width \"" << width_ << "\"\n";
107 InsetCollapsable::write(buf, os);
111 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
117 token = lex.GetString();
118 if (token == "position") {
120 pos_ = static_cast<Position>(lex.GetInteger());
123 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
130 token = lex.GetString();
132 if (token == "inner_position") {
134 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
137 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
144 token = lex.GetString();
146 if (token == "height") {
148 height_ = lex.GetString();
151 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
158 token = lex.GetString();
160 if (token == "width") {
162 width_ = lex.GetString();
165 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
170 lex.pushToken(token);
171 InsetCollapsable::read(buf, lex);
175 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
178 return ascent_collapsed();
180 // Take placement into account.
184 i = InsetCollapsable::ascent(bv, font);
187 i = (InsetCollapsable::ascent(bv, font)
188 + InsetCollapsable::descent(bv, font)) / 2;
191 i = InsetCollapsable::descent(bv, font);
199 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
202 return descent_collapsed();
204 // Take placement into account.
208 i = InsetCollapsable::descent(bv, font);
211 i = (InsetCollapsable::ascent(bv, font)
212 + InsetCollapsable::descent(bv, font)) / 2;
215 i = InsetCollapsable::ascent(bv, font);
223 string const InsetMinipage::editMessage() const
225 return _("Opened Minipage Inset");
229 int InsetMinipage::latex(Buffer const * buf,
230 ostream & os, bool fragile, bool fp) const
244 os << "\\begin{minipage}[" << s_pos << "]{"
245 << LyXLength(width_).asLatexString() << "}%\n";
247 int i = inset.latex(buf, os, fragile, fp);
249 os << "\\end{minipage}%\n";
254 bool InsetMinipage::insetAllowed(Inset::Code code) const
256 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
259 return InsetCollapsable::insetAllowed(code);
263 InsetMinipage::Position InsetMinipage::pos() const
269 void InsetMinipage::pos(InsetMinipage::Position p)
275 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
281 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
287 string const & InsetMinipage::height() const
293 void InsetMinipage::height(string const & ll)
299 string const & InsetMinipage::width() const
305 void InsetMinipage::width(string const & ll)
311 bool InsetMinipage::showInsetDialog(BufferView * bv) const
313 if (!inset.showInsetDialog(bv))
314 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
319 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
326 InsetCollapsable::insetButtonRelease(bv, x, y, button);
330 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
334 return VSpace(width_).inPixels(bv);
335 // this should not happen!
336 return InsetCollapsable::getMaxWidth(bv, inset);