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"
34 // Some information about Minipages in LaTeX:
35 // A minipage is a complete miniversion of a page and can contain
36 // its own footnotes, paragraphs, and array, tabular, and multicols
37 // environments. However it cannot contain floats or \marginpar's,
38 // but it can appear inside floats.
40 // The minipage environment is defined like this:
42 // \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
45 // pos [opt] = is the vertical placement of the box with respect
46 // to the text baseline, [c], [t] and [b].
47 // height [opt] = the height of the box
48 // inner-pos [opt] = the position of the text within the box.
49 // It can be t, c, b or s, if unspecified the value
51 // width = the width of the box
53 // In LyX we should try to support all these parameters, settable in a
55 // In this pop-up diallog it should also be possible to set all margin
56 // values that is usable in the minipage.
57 // With regard to different formats (like DocBook) I guess a minipage
58 // can be used there also. Perhaps not in the latex way, but we do not
59 // have to output "" for minipages.
62 InsetMinipage::InsetMinipage()
63 : InsetCollapsable(), pos_(center),
64 inner_pos_(inner_center)
66 setLabel(_("minipage"));
67 LyXFont font(LyXFont::ALL_SANE);
70 font.setColor(LColor::collapsable);
73 setAutoCollapse(false);
75 // just for experimentation :)
76 setBackgroundColor(LColor::red);
77 setInsetName("Minipage");
78 width_ = "100%"; // set default to 100% of column_width
82 InsetMinipage::InsetMinipage(InsetMinipage const & in, bool same_id)
83 : InsetCollapsable(in, same_id),
84 pos_(in.pos_), inner_pos_(in.inner_pos_),
85 height_(in.height_), width_(in.width_)
89 Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
91 return new InsetMinipage(*const_cast<InsetMinipage *>(this), same_id);
95 InsetMinipage::~InsetMinipage()
101 void InsetMinipage::write(Buffer const * buf, ostream & os) const
103 os << getInsetName() << "\n"
104 << "position " << pos_ << "\n"
105 << "inner_position " << inner_pos_ << "\n"
106 << "height \"" << height_ << "\"\n"
107 << "width \"" << width_ << "\"\n";
108 InsetCollapsable::write(buf, os);
112 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
116 string const token = lex.GetString();
117 if (token == "position") {
119 pos_ = static_cast<Position>(lex.GetInteger());
121 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
123 // take countermeasures
124 lex.pushToken(token);
129 string const token = lex.GetString();
130 if (token == "inner_position") {
132 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
134 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
136 // take countermeasures
137 lex.pushToken(token);
142 string const token = lex.GetString();
143 if (token == "height") {
145 height_ = lex.GetString();
147 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
149 // take countermeasures
150 lex.pushToken(token);
155 string const token = lex.GetString();
156 if (token == "width") {
158 width_ = lex.GetString();
160 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
162 // take countermeasures
163 lex.pushToken(token);
166 InsetCollapsable::read(buf, lex);
170 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
173 return ascent_collapsed();
175 // Take placement into account.
179 i = InsetCollapsable::ascent(bv, font);
182 i = (InsetCollapsable::ascent(bv, font)
183 + InsetCollapsable::descent(bv, font)) / 2;
186 i = InsetCollapsable::descent(bv, font);
194 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
197 return descent_collapsed();
199 // Take placement into account.
203 i = InsetCollapsable::descent(bv, font);
206 i = (InsetCollapsable::ascent(bv, font)
207 + InsetCollapsable::descent(bv, font)) / 2;
210 i = InsetCollapsable::ascent(bv, font);
218 string const InsetMinipage::editMessage() const
220 return _("Opened Minipage Inset");
224 int InsetMinipage::latex(Buffer const * buf,
225 ostream & os, bool fragile, bool fp) const
239 os << "\\begin{minipage}[" << s_pos << "]{"
240 << LyXLength(width_).asLatexString() << "}%\n";
242 int i = inset.latex(buf, os, fragile, fp);
244 os << "\\end{minipage}%\n";
249 bool InsetMinipage::insetAllowed(Inset::Code code) const
251 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
254 return InsetCollapsable::insetAllowed(code);
258 InsetMinipage::Position InsetMinipage::pos() const
264 void InsetMinipage::pos(InsetMinipage::Position p)
270 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
276 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
282 string const & InsetMinipage::height() const
288 void InsetMinipage::height(string const & ll)
294 string const & InsetMinipage::width() const
300 void InsetMinipage::width(string const & ll)
306 bool InsetMinipage::showInsetDialog(BufferView * bv) const
308 if (!inset.showInsetDialog(bv))
309 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
314 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
321 InsetCollapsable::insetButtonRelease(bv, x, y, button);
325 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
329 return VSpace(width_).inPixels(bv);
330 // this should not happen!
331 return InsetCollapsable::getMaxWidth(bv, inset);