]> git.lyx.org Git - lyx.git/blob - src/insets/insetminipage.C
bd5e6ba1ad2545709a3f72f4f55df325f5eb7c5a
[lyx.git] / src / insets / insetminipage.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998 The LyX Team.
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "insetminipage.h"
17 #include "gettext.h"
18 #include "lyxfont.h"
19 #include "BufferView.h"
20 #include "LyXView.h"
21 #include "frontends/Dialogs.h"
22 #include "lyxtext.h"
23 #include "insets/insettext.h"
24 #include "support/LOstream.h"
25 #include "support/lstrings.h"
26 #include "debug.h"
27
28 using std::ostream;
29 using std::endl;
30
31
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.
37 //
38 // The minipage environment is defined like this:
39 //
40 // \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
41 //
42 // Where:
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
48 //                 of pos is used.
49 //     width = the width of the box
50 //
51 // In LyX we should try to support all these parameters, settable in a
52 // pop-up dialog.
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.
58 // (Lgb)
59
60 InsetMinipage::InsetMinipage()
61         : InsetCollapsable(), pos_(center),
62           inner_pos_(inner_center)
63 {
64         setLabel(_("minipage"));
65         LyXFont font(LyXFont::ALL_SANE);
66         font.decSize();
67         font.decSize();
68         font.setColor(LColor::footnote);
69         setLabelFont(font);
70         setAutoCollapse(false);
71         setInsetName("Minipage");
72         collapsed = false;
73 }
74
75
76 InsetMinipage::~InsetMinipage()
77 {
78         hideDialog();
79 }
80
81
82 void InsetMinipage::Write(Buffer const * buf, ostream & os) const 
83 {
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);
90 }
91
92
93 void InsetMinipage::Read(Buffer const * buf, LyXLex & lex)
94 {
95         #warning Read and set args correctly. (Lgb)
96         lex.next();
97         string token = lex.GetString();
98         lyxerr << "minipage token: " << token << endl;
99         lex.next(); lex.next();
100         lex.next();
101         lex.next();
102         lex.next();
103         token = lex.GetString();
104         lyxerr << "minipage token: " << token << endl;
105         
106         InsetCollapsable::Read(buf, lex);
107 }
108
109
110 Inset * InsetMinipage::Clone(Buffer const &) const
111 {
112         InsetMinipage * result = new InsetMinipage;
113         result->inset->init(inset);
114         
115         result->collapsed = collapsed;
116         return result;
117 }
118
119
120 string const InsetMinipage::EditMessage() const
121 {
122         return _("Opened Minipage Inset");
123 }
124
125
126 int InsetMinipage::Latex(Buffer const * buf,
127                          ostream & os, bool fragile, bool fp) const
128 {
129         string s_pos;
130         switch (pos_) {
131         case top:
132                 s_pos += "t";
133                 break;
134         case center:
135                 s_pos += "c";
136                 break;
137         case bottom:
138                 s_pos += "b";
139                 break;
140         }
141         
142         os << "\\begin{minipage}[" << s_pos << "]{."
143            << widthp_ << "\\columnwidth}%\n";
144         
145         int i = inset->Latex(buf, os, fragile, fp);
146         os << "\\end{minipage}%\n";
147         
148         return i + 2;
149 }
150
151
152 bool InsetMinipage::InsertInsetAllowed(Inset * in) const
153 {
154         if ((in->LyxCode() == Inset::FLOAT_CODE) ||
155             (in->LyxCode() == Inset::MARGIN_CODE)) {
156                 return false;
157         }
158         return true;
159 }
160
161
162 InsetMinipage::Position InsetMinipage::pos() const 
163 {
164         return pos_;
165 }
166
167
168 void InsetMinipage::pos(InsetMinipage::Position p)
169 {
170         pos_ = p;
171 }
172
173
174 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
175 {
176         return inner_pos_;
177 }
178
179
180 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
181 {
182         inner_pos_ = ip;
183 }
184
185
186 LyXLength const & InsetMinipage::height() const
187 {
188         return height_;
189 }
190
191
192 void InsetMinipage::height(LyXLength const & ll)
193 {
194         height_ = ll;
195 }
196
197
198 string const & InsetMinipage::width() const
199 {
200         return width_;
201 }
202
203
204 void InsetMinipage::width(string const & ll)
205 {
206         width_ = ll;
207 }
208
209 int InsetMinipage::widthp() const
210 {
211         return widthp_;
212 }
213
214
215 void InsetMinipage::widthp(int ll)
216 {
217         widthp_ = ll;
218 }
219
220
221 void InsetMinipage::widthp(string const & ll)
222 {
223         widthp_ = strToInt(ll);
224 }
225
226
227 void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
228                                        int button)
229 {
230     if (button == 3) {
231 #if 0
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) {
235             UpdatableInset * i;
236             if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
237                 i->InsetButtonRelease(bv, x, y, button);
238                 return;
239             }
240         }
241 #endif
242         bv->owner()->getDialogs()->showMinipage(this);
243         return;
244     }
245     InsetCollapsable::InsetButtonRelease(bv, x, y, button);
246 }