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");
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 " << widthp_ << "\n";
89 InsetCollapsable::Write(buf, os);
93 void InsetMinipage::Read(Buffer const * buf, LyXLex & lex)
95 #warning Read and set args correctly. (Lgb)
97 string token = lex.GetString();
98 lyxerr << "minipage token: " << token << endl;
99 lex.next(); lex.next();
103 token = lex.GetString();
104 lyxerr << "minipage token: " << token << endl;
106 InsetCollapsable::Read(buf, lex);
110 Inset * InsetMinipage::Clone(Buffer const &) const
112 InsetMinipage * result = new InsetMinipage;
113 result->inset->init(inset);
115 result->collapsed = collapsed;
120 string const InsetMinipage::EditMessage() const
122 return _("Opened Minipage Inset");
126 int InsetMinipage::Latex(Buffer const * buf,
127 ostream & os, bool fragile, bool fp) const
142 os << "\\begin{minipage}[" << s_pos << "]{."
143 << widthp_ << "\\columnwidth}%\n";
145 int i = inset->Latex(buf, os, fragile, fp);
146 os << "\\end{minipage}%\n";
152 bool InsetMinipage::InsertInsetAllowed(Inset * in) const
154 if ((in->LyxCode() == Inset::FLOAT_CODE) ||
155 (in->LyxCode() == Inset::MARGIN_CODE)) {
162 InsetMinipage::Position InsetMinipage::pos() const
168 void InsetMinipage::pos(InsetMinipage::Position p)
174 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
180 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
186 LyXLength const & InsetMinipage::height() const
192 void InsetMinipage::height(LyXLength const & ll)
198 string const & InsetMinipage::width() const
204 void InsetMinipage::width(string const & ll)
209 int InsetMinipage::widthp() const
215 void InsetMinipage::widthp(int ll)
221 void InsetMinipage::widthp(string const & ll)
223 widthp_ = strToInt(ll);
227 void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
232 // we have to check first if we have a locking inset and if this locking inset
233 // has a popup menu with the 3rd button
234 if (the_locking_inset) {
236 if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
237 i->InsetButtonRelease(bv, x, y, button);
242 bv->owner()->getDialogs()->showMinipage(this);
245 InsetCollapsable::InsetButtonRelease(bv, x, y, button);