]> git.lyx.org Git - lyx.git/blob - src/insets/insetminipage.C
Added Minipage-Dialog, small fix in LyXTabular::l_getline (removing \r).
[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 }
73
74
75 InsetMinipage::~InsetMinipage()
76 {
77         hideDialog();
78 }
79
80
81 void InsetMinipage::Write(Buffer const * buf, ostream & os) const 
82 {
83         os << getInsetName() << "\n";
84         InsetCollapsable::Write(buf, os);
85 }
86
87
88 Inset * InsetMinipage::Clone(Buffer const &) const
89 {
90         InsetMinipage * result = new InsetMinipage;
91         result->inset->init(inset);
92         
93         result->collapsed = collapsed;
94         return result;
95 }
96
97
98 string const InsetMinipage::EditMessage() const
99 {
100         return _("Opened Minipage Inset");
101 }
102
103
104 int InsetMinipage::Latex(Buffer const * buf,
105                          ostream & os, bool fragile, bool fp) const
106 {
107         os << "\\begin{minipage}{\\columnwidth}%\n";
108         
109         int i = inset->Latex(buf, os, fragile, fp);
110         os << "\\end{minipage}%\n";
111         
112         return i + 2;
113 }
114
115
116 bool InsetMinipage::InsertInsetAllowed(Inset * in) const
117 {
118         if ((in->LyxCode() == Inset::FLOAT_CODE) ||
119             (in->LyxCode() == Inset::MARGIN_CODE)) {
120                 return false;
121         }
122         return true;
123 }
124
125
126 InsetMinipage::Position InsetMinipage::pos() const 
127 {
128         return pos_;
129 }
130
131
132 void InsetMinipage::pos(InsetMinipage::Position p)
133 {
134         pos_ = p;
135 }
136
137
138 InsetMinipage::InnerPosition InsetMinipage::innerPos() const
139 {
140         return inner_pos_;
141 }
142
143
144 void InsetMinipage::innerPos(InsetMinipage::InnerPosition ip)
145 {
146         inner_pos_ = ip;
147 }
148
149
150 LyXLength const & InsetMinipage::height() const
151 {
152         return height_;
153 }
154
155
156 void InsetMinipage::height(LyXLength const & ll)
157 {
158         height_ = ll;
159 }
160
161
162 string const & InsetMinipage::width() const
163 {
164         return width_;
165 }
166
167
168 void InsetMinipage::width(string const & ll)
169 {
170         width_ = ll;
171 }
172
173 int InsetMinipage::widthp() const
174 {
175         return widthp_;
176 }
177
178
179 void InsetMinipage::widthp(int ll)
180 {
181         widthp_ = ll;
182 }
183
184
185 void InsetMinipage::widthp(string const & ll)
186 {
187         widthp_ = strToInt(ll);
188 }
189
190
191 void InsetMinipage::InsetButtonRelease(BufferView * bv, int x, int y,
192                                        int button)
193 {
194     if (button == 3) {
195 #if 0
196 // we have to check first if we have a locking inset and if this locking inset
197 // has a popup menu with the 3rd button
198         if (the_locking_inset) {
199             UpdatableInset * i;
200             if ((i=the_locking_inset->GetFirstLockingInsetOfType(TABULAR_CODE))) {
201                 i->InsetButtonRelease(bv, x, y, button);
202                 return;
203             }
204         }
205 #endif
206         bv->owner()->getDialogs()->showMinipage(this);
207         return;
208     }
209     InsetCollapsable::InsetButtonRelease(bv, x, y, button);
210 }