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()
85 void InsetMinipage::write(Buffer const * buf, ostream & os) const
87 os << getInsetName() << "\n"
88 << "position " << pos_ << "\n"
89 << "inner_position " << inner_pos_ << "\n"
90 << "height \"" << height_ << "\"\n"
91 << "width \"" << width_ << "\"\n";
92 InsetCollapsable::write(buf, os);
96 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
102 token = lex.GetString();
103 if (token == "position") {
105 pos_ = static_cast<Position>(lex.GetInteger());
108 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
115 token = lex.GetString();
117 if (token == "inner_position") {
119 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
122 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
129 token = lex.GetString();
131 if (token == "height") {
133 height_ = lex.GetString();
136 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
143 token = lex.GetString();
145 if (token == "width") {
147 width_ = lex.GetString();
150 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
155 #warning Remove me before final 1.2.0 (Jug)
156 #warning Can we please remove this as soon as possible? (Lgb)
158 // this is only for compatibility to the intermediate format and should
159 // vanish till the final 1.2.0!
163 token = lex.GetString();
165 if (token == "widthp") {
167 // only do this if the width_-string was not already set!
169 width_ = lex.GetString() + "%";
174 lex.pushToken(token);
175 InsetCollapsable::read(buf, lex);
179 Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
181 InsetMinipage * result = new InsetMinipage;
182 result->inset.init(&inset, same_id);
184 result->collapsed_ = collapsed_;
186 result->inner_pos_ = inner_pos_;
187 result->height_ = height_;
188 result->width_ = width_;
195 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
198 return ascent_collapsed(bv->painter());
200 // Take placement into account.
204 i = InsetCollapsable::ascent(bv, font);
207 i = (InsetCollapsable::ascent(bv, font)
208 + InsetCollapsable::descent(bv, font)) / 2;
211 i = InsetCollapsable::descent(bv, font);
219 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
222 return descent_collapsed(bv->painter());
224 // Take placement into account.
228 i = InsetCollapsable::descent(bv, font);
231 i = (InsetCollapsable::ascent(bv, font)
232 + InsetCollapsable::descent(bv, font)) / 2;
235 i = InsetCollapsable::ascent(bv, font);
243 string const InsetMinipage::editMessage() const
245 return _("Opened Minipage Inset");
249 int InsetMinipage::latex(Buffer const * buf,
250 ostream & os, bool fragile, bool fp) const
264 os << "\\begin{minipage}[" << s_pos << "]{"
265 << LyXLength(width_).asLatexString() << "}%\n";
267 int i = inset.latex(buf, os, fragile, fp);
269 os << "\\end{minipage}%\n";
274 bool InsetMinipage::insetAllowed(Inset::Code code) const
276 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
279 return InsetCollapsable::insetAllowed(code);
283 InsetMinipage::Position InsetMinipage::pos() const
289 void InsetMinipage::pos(InsetMinipage::Position p)
295 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
301 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
307 string const & InsetMinipage::height() const
313 void InsetMinipage::height(string const & ll)
319 string const & InsetMinipage::width() const
325 void InsetMinipage::width(string const & ll)
331 bool InsetMinipage::showInsetDialog(BufferView * bv) const
333 if (!inset.showInsetDialog(bv))
334 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
339 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
346 InsetCollapsable::insetButtonRelease(bv, x, y, button);
350 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
354 return VSpace(width_).inPixels(bv);
355 // this should not happen!
356 return InsetCollapsable::getMaxWidth(bv, inset);