]> git.lyx.org Git - lyx.git/blob - src/insets/insetminipage.C
606648bcb9da111cae6bcbc6e4943c72529a7387
[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 "Painter.h"
21 #include "lyxtext.h"
22 #include "support/LOstream.h"
23
24 using std::ostream;
25 using std::endl;
26
27
28 // Some information about Minipages in LaTeX:
29 // A minipage is a complete miniversion of a page and can contain
30 // its own footnotes, paragraphs, and array, tabular, and multicols
31 // environments. However it cannot contain floats or \marginpar's,
32 // but it can appear inside floats.
33 //
34 // The minipage environment is defined like this:
35 //
36 // \begin{minipage}[pos][height][inner-pos]{width} <text> \end{minipage}
37 //
38 // Where:
39 //     pos [opt] = is the vertical placement of the box with respect
40 //                 to the text baseline, [c], [t] and [b].
41 //     height [opt] = the height of the box
42 //     inner-pos [opt] = the position of the text within the box.
43 //                 It can be t, c, b or s, if unspecified the value
44 //                 of pos is used.
45 //     width = the width of the box
46 //
47 // In LyX we should try to support all these parameters, settable in a
48 // pop-up dialog.
49 // In this pop-up diallog it should also be possible to set all margin
50 // values that is usable in the minipage.
51 // With regard to different formats (like DocBook) I guess a minipage
52 // can be used there also. Perhaps not in the latex way, but we do not
53 // have to output "" for minipages.
54 // (Lgb)
55
56 InsetMinipage::InsetMinipage()
57         : InsetCollapsable()
58 {
59         setLabel(_("minipage"));
60         LyXFont font(LyXFont::ALL_SANE);
61         font.decSize();
62         font.decSize();
63         font.setColor(LColor::footnote);
64         setLabelFont(font);
65         setAutoCollapse(false);
66         setInsetName("Minipage");
67 }
68
69
70 void InsetMinipage::Write(Buffer const * buf, ostream & os) const 
71 {
72         os << getInsetName() << "\n";
73         InsetCollapsable::Write(buf, os);
74 }
75
76
77 Inset * InsetMinipage::Clone() const
78 {
79         InsetMinipage * result = new InsetMinipage;
80         result->init(this);
81         
82         result->collapsed = collapsed;
83         return result;
84 }
85
86
87 char const * InsetMinipage::EditMessage() const
88 {
89         return _("Opened Minipage Inset");
90 }
91
92
93 int InsetMinipage::Latex(Buffer const * buf,
94                          ostream & os, bool fragile, bool fp) const
95 {
96         os << "\\begin{minipage}{\\columnwidth}%\n";
97         
98         int i = InsetText::Latex(buf, os, fragile, fp);
99         os << "\\end{minipage}%\n";
100         
101         return i + 2;
102 }
103
104
105 bool InsetMinipage::InsertInset(BufferView * bv, Inset * inset)
106 {
107         if (!InsertInsetAllowed(inset))
108                 return false;
109         
110         return InsetText::InsertInset(bv, inset);
111 }
112
113
114 bool InsetMinipage::InsertInsetAllowed(Inset * inset) const
115 {
116         if ((inset->LyxCode() == Inset::FLOAT_CODE) ||
117             (inset->LyxCode() == Inset::MARGIN_CODE)) {
118                 return false;
119         }
120         return true;
121 }
122
123
124 LyXFont InsetMinipage::GetDrawFont(BufferView * bv,
125                                    LyXParagraph * p, int pos) const
126 {
127         LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
128         fn.decSize().decSize();
129         return fn;
130 }