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 &) const
179 InsetMinipage * result = new InsetMinipage;
180 result->inset.init(&inset);
182 result->collapsed = collapsed;
184 result->inner_pos_ = inner_pos_;
185 result->height_ = height_;
186 result->width_ = width_;
191 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
194 return ascent_collapsed(bv->painter(), font);
196 // Take placement into account.
200 i = InsetCollapsable::ascent(bv, font);
203 i = (InsetCollapsable::ascent(bv, font)
204 + InsetCollapsable::descent(bv, font)) / 2;
207 i = InsetCollapsable::descent(bv, font);
215 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
218 return descent_collapsed(bv->painter(), font);
220 // Take placement into account.
224 i = InsetCollapsable::descent(bv, font);
227 i = (InsetCollapsable::ascent(bv, font)
228 + InsetCollapsable::descent(bv, font)) / 2;
231 i = InsetCollapsable::ascent(bv, font);
239 string const InsetMinipage::EditMessage() const
241 return _("Opened Minipage Inset");
245 int InsetMinipage::Latex(Buffer const * buf,
246 ostream & os, bool fragile, bool fp) const
260 os << "\\begin{minipage}[" << s_pos << "]{"
261 << LyXLength(width_).asLatexString() << "}%\n";
263 int i = inset.Latex(buf, os, fragile, fp);
265 os << "\\end{minipage}%\n";
270 bool InsetMinipage::InsertInsetAllowed(Inset * in) const
272 if ((in->LyxCode() == Inset::FLOAT_CODE) ||
273 (in->LyxCode() == Inset::MARGIN_CODE)) {
280 InsetMinipage::Position InsetMinipage::pos() const
286 void InsetMinipage::pos(InsetMinipage::Position p)
292 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
298 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
304 string const & InsetMinipage::height() const
310 void InsetMinipage::height(string const & ll)
316 string const & InsetMinipage::width() const
322 void InsetMinipage::width(string const & ll)
328 bool InsetMinipage::ShowInsetDialog(BufferView * bv) const
330 if (!inset.ShowInsetDialog(bv))
331 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
336 void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
343 InsetCollapsable::InsetButtonRelease(bv, x, y, button);
347 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
351 return VSpace(width_).inPixels(bv);
352 // this should not happen!
353 return InsetCollapsable::getMaxWidth(bv, inset);