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);
71 setAutoCollapse(false);
72 // just for experimentation :)
73 setBackgroundColor(LColor::red);
74 setInsetName("Minipage");
75 width_ = "100%"; // set default to 100% of column_width
79 InsetMinipage::InsetMinipage(InsetMinipage const & in, bool same_id)
80 : InsetCollapsable(in, same_id),
81 pos_(in.pos_), inner_pos_(in.inner_pos_),
82 height_(in.height_), width_(in.width_)
86 Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
88 return new InsetMinipage(*const_cast<InsetMinipage *>(this), same_id);
92 InsetMinipage::~InsetMinipage()
98 void InsetMinipage::write(Buffer const * buf, ostream & os) const
100 os << getInsetName() << "\n"
101 << "position " << pos_ << "\n"
102 << "inner_position " << inner_pos_ << "\n"
103 << "height \"" << height_ << "\"\n"
104 << "width \"" << width_ << "\"\n";
105 InsetCollapsable::write(buf, os);
109 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
115 token = lex.GetString();
116 if (token == "position") {
118 pos_ = static_cast<Position>(lex.GetInteger());
121 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
128 token = lex.GetString();
130 if (token == "inner_position") {
132 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
135 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
142 token = lex.GetString();
144 if (token == "height") {
146 height_ = lex.GetString();
149 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
156 token = lex.GetString();
158 if (token == "width") {
160 width_ = lex.GetString();
163 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
168 lex.pushToken(token);
169 InsetCollapsable::read(buf, lex);
173 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
176 return ascent_collapsed(bv->painter());
178 // Take placement into account.
182 i = InsetCollapsable::ascent(bv, font);
185 i = (InsetCollapsable::ascent(bv, font)
186 + InsetCollapsable::descent(bv, font)) / 2;
189 i = InsetCollapsable::descent(bv, font);
197 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
200 return descent_collapsed(bv->painter());
202 // Take placement into account.
206 i = InsetCollapsable::descent(bv, font);
209 i = (InsetCollapsable::ascent(bv, font)
210 + InsetCollapsable::descent(bv, font)) / 2;
213 i = InsetCollapsable::ascent(bv, font);
221 string const InsetMinipage::editMessage() const
223 return _("Opened Minipage Inset");
227 int InsetMinipage::latex(Buffer const * buf,
228 ostream & os, bool fragile, bool fp) const
242 os << "\\begin{minipage}[" << s_pos << "]{"
243 << LyXLength(width_).asLatexString() << "}%\n";
245 int i = inset.latex(buf, os, fragile, fp);
247 os << "\\end{minipage}%\n";
252 bool InsetMinipage::insetAllowed(Inset::Code code) const
254 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
257 return InsetCollapsable::insetAllowed(code);
261 InsetMinipage::Position InsetMinipage::pos() const
267 void InsetMinipage::pos(InsetMinipage::Position p)
273 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
279 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
285 string const & InsetMinipage::height() const
291 void InsetMinipage::height(string const & ll)
297 string const & InsetMinipage::width() const
303 void InsetMinipage::width(string const & ll)
309 bool InsetMinipage::showInsetDialog(BufferView * bv) const
311 if (!inset.showInsetDialog(bv))
312 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
317 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
324 InsetCollapsable::insetButtonRelease(bv, x, y, button);
328 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
332 return VSpace(width_).inPixels(bv);
333 // this should not happen!
334 return InsetCollapsable::getMaxWidth(bv, inset);