]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetFormulaMacro.C
make it compile again (hopefully)
[lyx.git] / src / mathed / InsetFormulaMacro.C
1 /**
2  * \file InsetFormulaMacro.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 "InsetFormulaMacro.h"
15 #include "MathMacroTable.h"
16 #include "MathMacroTemplate.h"
17 #include "MathMLStream.h"
18
19 #include "BufferView.h"
20 #include "cursor.h"
21 #include "debug.h"
22 #include "gettext.h"
23 #include "LColor.h"
24 #include "lyxlex.h"
25 #include "outputparams.h"
26
27 #include "frontends/FontMetrics.h"
28 #include "frontends/Painter.h"
29
30 #include "support/lstrings.h"
31
32 #include <sstream>
33
34 using lyx::odocstream;
35 using lyx::support::bformat;
36
37 using std::string;
38 using std::auto_ptr;
39 using std::ostream;
40 using std::endl;
41
42
43
44 InsetFormulaMacro::InsetFormulaMacro()
45         : InsetMathNest(2), name_("unknownA")
46 {}
47
48
49 InsetFormulaMacro::InsetFormulaMacro
50                 (string const & name, int nargs, string const & type)
51         : InsetMathNest(2), name_(name)
52 {
53         MathMacroTable::create(MathAtom(new MathMacroTemplate(name, nargs, type)));
54 }
55
56
57 InsetFormulaMacro::InsetFormulaMacro(string const & s)
58         : InsetMathNest(2), name_("unknownB")
59 {
60         std::istringstream is(s);
61         read(is);
62 }
63
64
65 auto_ptr<InsetBase> InsetFormulaMacro::clone() const
66 {
67         return auto_ptr<InsetBase>(new InsetFormulaMacro(*this));
68 }
69
70
71 void InsetFormulaMacro::write(Buffer const &, ostream & os) const
72 {
73         os << "FormulaMacro\n";
74         WriteStream wi(os, false, false);
75         tmpl()->write(wi);
76 }
77
78
79 int InsetFormulaMacro::latex(Buffer const &, odocstream & os,
80                              OutputParams const & runparams) const
81 {
82         //lyxerr << "InsetFormulaMacro::latex" << endl;
83         WriteStream wi(os, runparams.moving_arg, true);
84         tmpl()->write(wi);
85         return 2;
86 }
87
88
89 int InsetFormulaMacro::plaintext(Buffer const &, odocstream & os,
90                              OutputParams const &) const
91 {
92         WriteStream wi(os, false, true);
93         tmpl()->write(wi);
94         return 0;
95 }
96
97
98 int InsetFormulaMacro::docbook(Buffer const & buf, ostream & os,
99                                OutputParams const & runparams) const
100 {
101         return plaintext(buf, os, runparams);
102 }
103
104
105 void InsetFormulaMacro::read(Buffer const &, LyXLex & lex)
106 {
107         read(lex.getStream());
108 }
109
110
111 void InsetFormulaMacro::read(std::istream & is)
112 {
113         auto_ptr<MathMacroTemplate> p(new MathMacroTemplate(is));
114         name_ = p->name();
115         MathMacroTable::create(MathAtom(p.release()));
116 }
117
118
119 string InsetFormulaMacro::prefix() const
120 {
121         return lyx::to_utf8(bformat(_(" Macro: %1$s: "), lyx::from_utf8(name_)));
122 }
123
124
125 void InsetFormulaMacro::metrics(MetricsInfo & mi, Dimension & dim) const
126 {
127         //lyxerr << "InsetFormulaMacro: " << this << " -- " << &tmpl() << endl;
128         tmpl()->metrics(mi, dim);
129         dim.asc += 5;
130         dim.des += 5;
131         dim.wid += 10 + theFontMetrics(mi.base.font).width(prefix());
132         dim_ = dim;
133 }
134
135
136 void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const
137 {
138         // label
139         LyXFont font = p.base.font;
140         font.setColor(LColor::math);
141
142         PainterInfo pi(p.base.bv, p.pain);
143         pi.base.style = LM_ST_TEXT;
144         pi.base.font  = font;
145
146         int const a = y - dim_.asc + 1;
147         int const w = dim_.wid - 2;
148         int const h = dim_.height() - 2;
149
150         // LColor::mathbg used to be "AntiqueWhite" but is "linen" now, too
151         pi.pain.fillRectangle(x, a, w, h, LColor::mathmacrobg);
152         pi.pain.rectangle(x, a, w, h, LColor::mathframe);
153
154 #ifdef WITH_WARNINGS
155 #warning FIXME
156 #endif
157 #if 0
158         LCursor & cur = p.base.bv->cursor();
159         if (cur.isInside(this))
160                 cur.drawSelection(pi);
161 #endif
162
163         pi.pain.text(x + 2, y, prefix(), font);
164
165         // body
166         tmpl()->draw(pi,
167                 x + theFontMetrics(p.base.font).width(prefix()) + 5,
168                 y);
169
170         setPosCache(pi, x, y);
171 }
172
173
174 MathAtom & InsetFormulaMacro::tmpl() const
175 {
176         return MathMacroTable::provide(name_);
177 }