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"
34 // Some information about Minipages in LaTeX:
35 // A minipage is a complete miniversion of a page and can contain
36 // its own footnotes, paragraphs, and array, tabular, and multicols
37 // environments. However it cannot contain floats or \marginpar's,
38 // but it can appear inside floats.
40 // The minipage environment is defined like this:
42 // \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
45 // pos [opt] = is the vertical placement of the box with respect
46 // to the text baseline, [c], [t] and [b].
47 // height [opt] = the height of the box
48 // inner-pos [opt] = the position of the text within the box.
49 // It can be t, c, b or s, if unspecified the value
51 // width = the width of the box
53 // In LyX we should try to support all these parameters, settable in a
55 // In this pop-up diallog it should also be possible to set all margin
56 // values that is usable in the minipage.
57 // With regard to different formats (like DocBook) I guess a minipage
58 // can be used there also. Perhaps not in the latex way, but we do not
59 // have to output "" for minipages.
62 InsetMinipage::InsetMinipage()
63 : InsetCollapsable(), pos_(center),
64 inner_pos_(inner_center)
66 setLabel(_("minipage"));
67 LyXFont font(LyXFont::ALL_SANE);
70 font.setColor(LColor::collapsable);
73 setAutoCollapse(false);
75 // just for experimentation :)
76 setBackgroundColor(LColor::red);
77 setInsetName("Minipage");
78 width_ = "100%"; // set default to 100% of column_width
82 InsetMinipage::InsetMinipage(InsetMinipage const & in, bool same_id)
83 : InsetCollapsable(in, same_id),
84 pos_(in.pos_), inner_pos_(in.inner_pos_),
85 height_(in.height_), width_(in.width_)
89 Inset * InsetMinipage::clone(Buffer const &, bool same_id) const
91 return new InsetMinipage(*const_cast<InsetMinipage *>(this), same_id);
95 InsetMinipage::~InsetMinipage()
101 void InsetMinipage::write(Buffer const * buf, ostream & os) const
103 os << getInsetName() << "\n"
104 << "position " << pos_ << "\n"
105 << "inner_position " << inner_pos_ << "\n"
106 << "height \"" << height_ << "\"\n"
107 << "width \"" << width_ << "\"\n";
108 InsetCollapsable::write(buf, os);
112 void InsetMinipage::read(Buffer const * buf, LyXLex & lex)
118 string const token = lex.GetString();
119 if (token == "position") {
121 pos_ = static_cast<Position>(lex.GetInteger());
124 lyxerr << "InsetMinipage::Read: Missing 'position'-tag!"
126 // take countermeasures
127 lex.pushToken(token);
131 //if (token.empty()) {
133 string const token = lex.GetString();
135 if (token == "inner_position") {
137 inner_pos_ = static_cast<InnerPosition>(lex.GetInteger());
140 lyxerr << "InsetMinipage::Read: Missing 'inner_position'-tag!"
142 // take countermeasures
143 lex.pushToken(token);
147 //if (token.empty()) {
149 string const token = lex.GetString();
151 if (token == "height") {
153 height_ = lex.GetString();
156 lyxerr << "InsetMinipage::Read: Missing 'height'-tag!"
158 // take countermeasures
159 lex.pushToken(token);
163 //if (token.empty()) {
165 string const token = lex.GetString();
167 if (token == "width") {
169 width_ = lex.GetString();
172 lyxerr << "InsetMinipage::Read: Missing 'width'-tag!"
174 // take countermeasures
175 lex.pushToken(token);
178 //if (!token.empty())
179 // lex.pushToken(token);
180 InsetCollapsable::read(buf, lex);
184 int InsetMinipage::ascent(BufferView * bv, LyXFont const & font) const
187 return ascent_collapsed();
189 // Take placement into account.
193 i = InsetCollapsable::ascent(bv, font);
196 i = (InsetCollapsable::ascent(bv, font)
197 + InsetCollapsable::descent(bv, font)) / 2;
200 i = InsetCollapsable::descent(bv, font);
208 int InsetMinipage::descent(BufferView * bv, LyXFont const & font) const
211 return descent_collapsed();
213 // Take placement into account.
217 i = InsetCollapsable::descent(bv, font);
220 i = (InsetCollapsable::ascent(bv, font)
221 + InsetCollapsable::descent(bv, font)) / 2;
224 i = InsetCollapsable::ascent(bv, font);
232 string const InsetMinipage::editMessage() const
234 return _("Opened Minipage Inset");
238 int InsetMinipage::latex(Buffer const * buf,
239 ostream & os, bool fragile, bool fp) const
253 os << "\\begin{minipage}[" << s_pos << "]{"
254 << LyXLength(width_).asLatexString() << "}%\n";
256 int i = inset.latex(buf, os, fragile, fp);
258 os << "\\end{minipage}%\n";
263 bool InsetMinipage::insetAllowed(Inset::Code code) const
265 if ((code == Inset::FLOAT_CODE) || (code == Inset::MARGIN_CODE))
268 return InsetCollapsable::insetAllowed(code);
272 InsetMinipage::Position InsetMinipage::pos() const
278 void InsetMinipage::pos(InsetMinipage::Position p)
284 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
290 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
296 string const & InsetMinipage::height() const
302 void InsetMinipage::height(string const & ll)
308 string const & InsetMinipage::width() const
314 void InsetMinipage::width(string const & ll)
320 bool InsetMinipage::showInsetDialog(BufferView * bv) const
322 if (!inset.showInsetDialog(bv))
323 bv->owner()->getDialogs()->showMinipage(const_cast<InsetMinipage *>(this));
328 void InsetMinipage::insetButtonRelease(BufferView * bv, int x, int y,
335 InsetCollapsable::insetButtonRelease(bv, x, y, button);
339 int InsetMinipage::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
343 return VSpace(width_).inPixels(bv);
344 // this should not happen!
345 return InsetCollapsable::getMaxWidth(bv, inset);