]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathDecoration.cpp
* dynamic macros as described in http://1stein.org/download/dynmacro.pdf
[lyx.git] / src / mathed / InsetMathDecoration.cpp
1 /**
2  * \file InsetMathDecoration.cpp
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 "InsetMathDecoration.h"
15 #include "MathData.h"
16 #include "MathParser.h"
17 #include "MathSupport.h"
18 #include "MathStream.h"
19
20 #include "LaTeXFeatures.h"
21 #include "debug.h"
22
23 #include "support/std_ostream.h"
24
25
26 namespace lyx {
27
28
29 InsetMathDecoration::InsetMathDecoration(latexkeys const * key)
30         : InsetMathNest(1), key_(key)
31 {
32 //      lyxerr << " creating deco " << key->name << std::endl;
33 }
34
35
36 Inset * InsetMathDecoration::clone() const
37 {
38         return new InsetMathDecoration(*this);
39 }
40
41
42 bool InsetMathDecoration::upper() const
43 {
44         return key_->name.substr(0, 5) != "under";
45 }
46
47
48 bool InsetMathDecoration::isScriptable() const
49 {
50         return
51                         key_->name == "overbrace" ||
52                         key_->name == "underbrace" ||
53                         key_->name == "overleftarrow" ||
54                         key_->name == "overrightarrow" ||
55                         key_->name == "overleftrightarrow" ||
56                         key_->name == "underleftarrow" ||
57                         key_->name == "underrightarrow" ||
58                         key_->name == "underleftrightarrow";
59 }
60
61
62 bool InsetMathDecoration::protect() const
63 {
64         return
65                         key_->name == "overbrace" ||
66                         key_->name == "underbrace" ||
67                         key_->name == "overleftarrow" ||
68                         key_->name == "overrightarrow" ||
69                         key_->name == "overleftrightarrow" ||
70                         key_->name == "underleftarrow" ||
71                         key_->name == "underrightarrow" ||
72                         key_->name == "underleftrightarrow";
73 }
74
75
76 bool InsetMathDecoration::wide() const
77 {
78         return
79                         key_->name == "overline" ||
80                         key_->name == "underline" ||
81                         key_->name == "overbrace" ||
82                         key_->name == "underbrace" ||
83                         key_->name == "overleftarrow" ||
84                         key_->name == "overrightarrow" ||
85                         key_->name == "overleftrightarrow" ||
86                         key_->name == "widehat" ||
87                         key_->name == "widetilde" ||
88                         key_->name == "underleftarrow" ||
89                         key_->name == "underrightarrow" ||
90                         key_->name == "underleftrightarrow";
91 }
92
93
94 bool InsetMathDecoration::ams() const
95 {
96         return
97                         key_->name == "overleftrightarrow" ||
98                         key_->name == "underleftarrow" ||
99                         key_->name == "underrightarrow" ||
100                         key_->name == "underleftrightarrow";
101 }
102
103
104 void InsetMathDecoration::metrics(MetricsInfo & mi, Dimension & dim) const
105 {
106         cell(0).metrics(mi, dim);
107
108         dh_  = 6; //mathed_char_height(LM_TC_VAR, mi, 'I', ascent_, descent_);
109         dw_  = 6; //mathed_char_width(LM_TC_VAR, mi, 'x');
110
111         if (upper()) {
112                 dy_ = -dim.asc - dh_;
113                 dim.asc += dh_ + 1;
114         } else {
115                 dy_ = dim.des + 1;
116                 dim.des += dh_ + 2;
117         }
118
119         metricsMarkers(dim);
120         // Cache the inset dimension. 
121         setDimCache(mi, dim);
122 }
123
124
125 void InsetMathDecoration::draw(PainterInfo & pi, int x, int y) const
126 {
127         cell(0).draw(pi, x + 1, y);
128         Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
129         if (wide())
130                 mathed_draw_deco(pi, x + 1, y + dy_, dim0.wid, dh_, key_->name);
131         else
132                 mathed_draw_deco(pi, x + 1 + (dim0.wid - dw_) / 2,
133                         y + dy_, dw_, dh_, key_->name);
134         drawMarkers(pi, x, y);
135         setPosCache(pi, x, y);
136 }
137
138
139 void InsetMathDecoration::write(WriteStream & os) const
140 {
141         if (os.fragile() && protect())
142                 os << "\\protect";
143         os << '\\' << key_->name << '{' << cell(0) << '}';
144 }
145
146
147 void InsetMathDecoration::normalize(NormalStream & os) const
148 {
149         os << "[deco " << key_->name << ' ' <<  cell(0) << ']';
150 }
151
152
153 void InsetMathDecoration::infoize(odocstream & os) const
154 {
155         os << "Deco: " << key_->name;
156 }
157
158
159 void InsetMathDecoration::validate(LaTeXFeatures & features) const
160 {
161         if (ams())
162                 features.require("amsmath");
163         InsetMathNest::validate(features);
164 }
165
166
167 } // namespace lyx