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 string const token = lex.GetString();
118 if (token == "position") {
120 pos_ = static_cast<Position>(lex.GetInteger());
123 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
125 // take countermeasures
126 lex.pushToken(token);
130 //if (token.empty()) {
132 string const token = lex.GetString();
134 if (token == "inner_position") {
136 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
139 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
141 // take countermeasures
142 lex.pushToken(token);
146 //if (token.empty()) {
148 string const token = lex.GetString();
150 if (token == "height") {
152 height_ = lex.GetString();
155 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
157 // take countermeasures
158 lex.pushToken(token);
162 //if (token.empty()) {
164 string const token = lex.GetString();
166 if (token == "width") {
168 width_ = lex.GetString();
171 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
173 // take countermeasures
174 lex.pushToken(token);
177 //if (!token.empty())
178 // lex.pushToken(token);
179 InsetCollapsable::read(buf, lex);
183 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
186 return ascent_collapsed();
188 // Take placement into account.
192 i = InsetCollapsable::ascent(bv, font);
195 i = (InsetCollapsable::ascent(bv, font)
196 + InsetCollapsable::descent(bv, font)) / 2;
199 i = InsetCollapsable::descent(bv, font);
207 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
210 return descent_collapsed();
212 // Take placement into account.
216 i = InsetCollapsable::descent(bv, font);
219 i = (InsetCollapsable::ascent(bv, font)
220 + InsetCollapsable::descent(bv, font)) / 2;
223 i = InsetCollapsable::ascent(bv, font);
231 string const InsetMinipage::editMessage() const
233 return _("Opened Minipage Inset");
237 int InsetMinipage::latex(Buffer const * buf,
238 ostream & os, bool fragile, bool fp) const
252 os << "\\begin{minipage}[" << s_pos << "]{"
253 << LyXLength(width_).asLatexString() << "}%\n";
255 int i = inset.latex(buf, os, fragile, fp);
257 os << "\\end{minipage}%\n";
262 bool InsetMinipage::insetAllowed(Inset::Code code) const
264 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
267 return InsetCollapsable::insetAllowed(code);
271 InsetMinipage::Position InsetMinipage::pos() const
277 void InsetMinipage::pos(InsetMinipage::Position p)
283 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
289 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
295 string const & InsetMinipage::height() const
301 void InsetMinipage::height(string const & ll)
307 string const & InsetMinipage::width() const
313 void InsetMinipage::width(string const & ll)
319 bool InsetMinipage::showInsetDialog(BufferView * bv) const
321 if (!inset.showInsetDialog(bv))
322 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
327 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
334 InsetCollapsable::insetButtonRelease(bv, x, y, button);
338 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
342 return VSpace(width_).inPixels(bv);
343 // this should not happen!
344 return InsetCollapsable::getMaxWidth(bv, inset);