]> git.lyx.org Git - lyx.git/blob - src/mathed/formulamacro.C
bug + spped fixes + small stuff
[lyx.git] / src / mathed / formulamacro.C
1 /**
2  * \file formulamacro.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "formulamacro.h"
15 #include "math_macrotable.h"
16 #include "math_macrotemplate.h"
17 #include "math_mathmlstream.h"
18
19 #include "BufferView.h"
20 #include "cursor.h"
21 #include "gettext.h"
22 #include "LColor.h"
23 #include "lyxlex.h"
24 #include "outputparams.h"
25
26 #include "frontends/Painter.h"
27 #include "frontends/font_metrics.h"
28
29 #include "support/lstrings.h"
30 #include "support/std_sstream.h"
31
32 using lyx::support::bformat;
33
34 using std::string;
35 using std::auto_ptr;
36 using std::ostream;
37
38
39
40 InsetFormulaMacro::InsetFormulaMacro()
41         : MathNestInset(2), name_("unknown")
42 {}
43
44
45 InsetFormulaMacro::InsetFormulaMacro
46                 (string const & name, int nargs, string const & type)
47         : MathNestInset(2), name_(name)
48 {
49         MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
50 }
51
52
53 InsetFormulaMacro::InsetFormulaMacro(string const & s)
54         : MathNestInset(2), name_("unknown")
55 {
56         std::istringstream is(s);
57         read(is);
58 }
59
60
61 auto_ptr<InsetBase> InsetFormulaMacro::clone() const
62 {
63         return auto_ptr<InsetBase>(new InsetFormulaMacro(*this));
64 }
65
66
67 void InsetFormulaMacro::write(Buffer const &, ostream & os) const
68 {
69         os << "FormulaMacro ";
70         WriteStream wi(os, false, false);
71         MathNestInset::write(wi);
72 }
73
74
75 int InsetFormulaMacro::latex(Buffer const &, ostream & os,
76                              OutputParams const & runparams) const
77 {
78         WriteStream wi(os, runparams.moving_arg, true);
79         MathNestInset::write(wi);
80         return 2;
81 }
82
83
84 int InsetFormulaMacro::plaintext(Buffer const &, ostream & os,
85                              OutputParams const &) const
86 {
87         WriteStream wi(os, false, true);
88         MathNestInset::write(wi);
89         return 0;
90 }
91
92
93 int InsetFormulaMacro::linuxdoc(Buffer const & buf, ostream & os,
94                                 OutputParams const & runparams) const
95 {
96         return plaintext(buf, os, runparams);
97 }
98
99
100 int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os,
101                                OutputParams const & runparams) const
102 {
103         return plaintext(buf, os, runparams);
104 }
105
106
107 void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
108 {
109         read(lex.getStream());
110 }
111
112
113 void InsetFormulaMacro::read(std::istream & is)
114 {
115         auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
116         name_ = p->name();
117         MathMacroTable::create(MathAtom(p.release()));
118         //metrics();
119 }
120
121
122 string InsetFormulaMacro::prefix() const
123 {
124         return bformat(_(" Macro: %1$s: "), name_);
125 }
126
127
128 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
129 {
130         MathNestInset::metrics(mi);
131         dim = cell(0).dim();
132         dim += cell(1).dim();
133         dim.asc += 5;
134         dim.des += 5;
135         dim.wid += 10 + font_metrics::width(prefix(), mi.base.font);
136         dim = dim_;
137 }
138
139
140 #warning FIXME
141 #if 0
142 MathAtom const & InsetFormulaMacro::par() const
143 {
144         return MathMacroTable::provide(getInsetName());
145 }
146
147
148 MathAtom & InsetFormulaMacro::par()
149 {
150         return MathMacroTable::provide(getInsetName());
151 }
152 #endif
153
154
155 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
156 {
157         // label
158         LyXFont font = p.base.font;
159         font.setColor(LColor::math);
160
161         PainterInfo pi(p.base.bv);
162         pi.base.style = LM_ST_TEXT;
163         pi.base.font  = font;
164
165         int const a = y - dim_.asc + 1;
166         int const w = dim_.wid - 2;
167         int const h = dim_.height() - 2;
168
169         // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
170         pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
171         pi.pain.rectangle(x, a, w, h, LColor::mathframe);
172
173 #warning FIXME
174 #if 0
175         LCursor & cur = p.base.bv->cursor();
176         if (cur.isInside(this))
177                 cur.drawSelection(pi);
178 #endif
179
180         pi.pain.text(x + 2, y, prefix(), font);
181
182         // formula
183 #warning FIXME
184 #if 0
185         par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y);
186 #endif
187         setPosCache(pi, x, y);
188 }