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 setInsetName("Minipage");
73 width_ = "100%"; // set default to 100% of column_width
77 InsetMinipage::~InsetMinipage()
83 void InsetMinipage::write(Buffer const * buf, ostream & os) const
85 os << getInsetName() << "\n"
86 << "position " << pos_ << "\n"
87 << "inner_position " << inner_pos_ << "\n"
88 << "height \"" << height_ << "\"\n"
89 << "width \"" << width_ << "\"\n";
90 InsetCollapsable::write(buf, os);
94 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
100 token = lex.GetString();
101 if (token == "position") {
103 pos_ = static_cast<Position>(lex.GetInteger());
106 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
113 token = lex.GetString();
115 if (token == "inner_position") {
117 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
120 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
127 token = lex.GetString();
129 if (token == "height") {
131 height_ = lex.GetString();
134 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
141 token = lex.GetString();
143 if (token == "width") {
145 width_ = lex.GetString();
148 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
153 #warning Remove me before final 1.2.0 (Jug)
154 #warning Can we please remove this as soon as possible? (Lgb)
156 // this is only for compatibility to the intermediate format and should
157 // vanish till the final 1.2.0!
161 token = lex.GetString();
163 if (token == "widthp") {
165 // only do this if the width_-string was not already set!
167 width_ = lex.GetString() + "%";
172 lex.pushToken(token);
173 InsetCollapsable::read(buf, lex);
177 Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
179 InsetMinipage * result = new InsetMinipage;
180 result->inset.init(&inset, same_id);
182 result->collapsed_ = collapsed_;
184 result->inner_pos_ = inner_pos_;
185 result->height_ = height_;
186 result->width_ = width_;
193 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
196 return ascent_collapsed(bv->painter(), font);
198 // Take placement into account.
202 i = InsetCollapsable::ascent(bv, font);
205 i = (InsetCollapsable::ascent(bv, font)
206 + InsetCollapsable::descent(bv, font)) / 2;
209 i = InsetCollapsable::descent(bv, font);
217 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
220 return descent_collapsed(bv->painter(), font);
222 // Take placement into account.
226 i = InsetCollapsable::descent(bv, font);
229 i = (InsetCollapsable::ascent(bv, font)
230 + InsetCollapsable::descent(bv, font)) / 2;
233 i = InsetCollapsable::ascent(bv, font);
241 string const InsetMinipage::editMessage() const
243 return _("Opened Minipage Inset");
247 int InsetMinipage::latex(Buffer const * buf,
248 ostream & os, bool fragile, bool fp) const
262 os << "\\begin{minipage}[" << s_pos << "]{"
263 << LyXLength(width_).asLatexString() << "}%\n";
265 int i = inset.latex(buf, os, fragile, fp);
267 os << "\\end{minipage}%\n";
272 bool InsetMinipage::insertInsetAllowed(Inset * in) const
274 return insertInsetAllowed(in->lyxCode());
277 bool InsetMinipage::insertInsetAllowed(Inset::Code code) const
279 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
282 return InsetCollapsable::insertInsetAllowed(code);
286 InsetMinipage::Position InsetMinipage::pos() const
292 void InsetMinipage::pos(InsetMinipage::Position p)
298 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
304 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
310 string const & InsetMinipage::height() const
316 void InsetMinipage::height(string const & ll)
322 string const & InsetMinipage::width() const
328 void InsetMinipage::width(string const & ll)
334 bool InsetMinipage::showInsetDialog(BufferView * bv) const
336 if (!inset.showInsetDialog(bv))
337 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
342 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
349 InsetCollapsable::insetButtonRelease(bv, x, y, button);
353 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
357 return VSpace(width_).inPixels(bv);
358 // this should not happen!
359 return InsetCollapsable::getMaxWidth(bv, inset);