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"
32 // Some information about Minipages in LaTeX:
33 // A minipage is a complete miniversion of a page and can contain
34 // its own footnotes, paragraphs, and array, tabular, and multicols
35 // environments. However it cannot contain floats or \marginpar's,
36 // but it can appear inside floats.
38 // The minipage environment is defined like this:
40 // \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
43 // pos [opt] = is the vertical placement of the box with respect
44 // to the text baseline, [c], [t] and [b].
45 // height [opt] = the height of the box
46 // inner-pos [opt] = the position of the text within the box.
47 // It can be t, c, b or s, if unspecified the value
49 // width = the width of the box
51 // In LyX we should try to support all these parameters, settable in a
53 // In this pop-up diallog it should also be possible to set all margin
54 // values that is usable in the minipage.
55 // With regard to different formats (like DocBook) I guess a minipage
56 // can be used there also. Perhaps not in the latex way, but we do not
57 // have to output "" for minipages.
60 InsetMinipage::InsetMinipage()
61 : InsetCollapsable(), pos_(center),
62 inner_pos_(inner_center)
64 setLabel(_("minipage"));
65 LyXFont font(LyXFont::ALL_SANE);
68 font.setColor(LColor::footnote);
70 setAutoCollapse(false);
71 setInsetName("Minipage");
72 widthp_ = 100; // set default to 100% of column_width
76 InsetMinipage::~InsetMinipage()
82 void InsetMinipage::Write(Buffer const * buf, ostream & os) const
84 os << getInsetName() << "\n"
85 << "position " << pos_ << "\n"
86 << "inner_position " << inner_pos_ << "\n"
87 << "height \"" << height_ << "\"\n"
88 << "width \"" << width_ << "\"\n"
89 << "widthp " << widthp_ << "\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!"
155 token = lex.GetString();
157 if (token == "widthp") {
159 widthp_ = lex.GetInteger();
162 lyxerr << "InsetMinipage::Read: Missing 'widthp_'-tag!"
166 InsetCollapsable::Read(buf, lex);
170 Inset * InsetMinipage::Clone(Buffer const &) const
172 InsetMinipage * result = new InsetMinipage;
173 result->inset->init(inset);
175 result->collapsed = collapsed;
177 result->inner_pos_ = inner_pos_;
178 result->height_ = height_;
179 result->width_ = width_;
180 result->widthp_ = widthp_;
185 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
188 return ascent_collapsed(bv->painter(), font);
190 // Take placement into account.
194 i = InsetCollapsable::ascent(bv, font);
197 i = (InsetCollapsable::ascent(bv, font)
198 + InsetCollapsable::descent(bv, font)) / 2;
201 i = InsetCollapsable::descent(bv, font);
209 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
212 return descent_collapsed(bv->painter(), font);
214 // Take placement into account.
218 i = InsetCollapsable::descent(bv, font);
221 i = (InsetCollapsable::ascent(bv, font)
222 + InsetCollapsable::descent(bv, font)) / 2;
225 i = InsetCollapsable::ascent(bv, font);
233 string const InsetMinipage::EditMessage() const
235 return _("Opened Minipage Inset");
239 int InsetMinipage::Latex(Buffer const * buf,
240 ostream & os, bool fragile, bool fp) const
255 if (width_.empty()) {
256 os << "\\begin{minipage}[" << s_pos << "]{."
257 << widthp_ << "\\columnwidth}%\n";
259 os << "\\begin{minipage}[" << s_pos << "]{"
263 int i = inset->Latex(buf, os, fragile, fp);
264 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)
327 int InsetMinipage::widthp() const
333 void InsetMinipage::widthp(int ll)
339 void InsetMinipage::widthp(string const & ll)
341 widthp_ = strToInt(ll);
345 bool InsetMinipage::ShowInsetDialog(BufferView * bv) const
347 if (!inset->ShowInsetDialog(bv))
348 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
353 void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
360 InsetCollapsable::InsetButtonRelease(bv, x, y, button);
364 int InsetMinipage::getMaxWidth(Painter & pain, UpdatableInset const * inset)
368 return VSpace(width_).inPixels(0, 0);
369 return InsetCollapsable::getMaxWidth(pain, inset) / 100 * widthp_;