]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathBig.C
BUG 686: delete empty math box with delete/backspace key
[lyx.git] / src / mathed / InsetMathBig.C
1 /**
2  * \file InsetMathBig.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathBig.h"
14 #include "MathSupport.h"
15 #include "MathStream.h"
16 #include "MathStream.h"
17
18 #include "frontends/FontMetrics.h"
19
20 #include "support/lstrings.h"
21
22
23 namespace lyx {
24
25 using std::auto_ptr;
26
27
28 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
29         : name_(name), delim_(delim)
30 {}
31
32
33 docstring InsetMathBig::name() const
34 {
35         return name_;
36 }
37
38
39 auto_ptr<InsetBase> InsetMathBig::doClone() const
40 {
41         return auto_ptr<InsetBase>(new InsetMathBig(*this));
42 }
43
44
45 InsetMathBig::size_type InsetMathBig::size() const
46 {
47         // order: big Big bigg Bigg biggg Biggg
48         //        0   1   2    3    4     5
49         return name_[0] == 'B' ?
50                 2 * (name_.size() - 4) + 1:
51                 2 * (name_.size() - 4);
52 }
53
54
55 double InsetMathBig::increase() const
56 {
57         // The formula used in amsmath.sty is
58         // 1.2 * (1.0 + size() * 0.5) - 1.0.
59         // We use a smaller step and a bigger offset because our base size
60         // is different.
61         return (size() + 1) * 0.3;
62 }
63
64
65 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
66 {
67         double const h = theFontMetrics(mi.base.font).ascent('I');
68         double const f = increase();
69         dim_.wid = 6;
70         dim_.asc = int(h + f * h);
71         dim_.des = int(f * h);
72         dim = dim_;
73 }
74
75
76 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
77 {
78         // mathed_draw_deco does not use the leading backslash, so remove it.
79         // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
80         // would treat it as |.
81         docstring const delim = 
82                 (delim_ == "\\|") ?  from_ascii("Vert") : support::ltrim(delim_, "\\");
83         mathed_draw_deco(pi, x + 1, y - dim_.ascent(), 4, dim_.height(),
84                          delim);
85         setPosCache(pi, x, y);
86 }
87
88
89 void InsetMathBig::write(WriteStream & os) const
90 {
91         os << '\\' << name_ << delim_;
92         if (delim_[0] == '\\')
93                 os.pendingSpace(true);
94 }
95
96
97 void InsetMathBig::normalize(NormalStream & os) const
98 {
99         os << '[' << name_ << ' ' << delim_ << ']';
100 }
101
102
103 void InsetMathBig::infoize2(odocstream & os) const
104 {
105         os << name_;
106 }
107
108
109 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
110 {
111         // mathed_draw_deco must handle these
112         static char const * const delimiters[] = {
113                 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
114                 "|", "/", "\\|", "\\vert", "\\Vert", "'", "\\backslash",
115                 "\\langle", "\\lceil", "\\lfloor",
116                 "\\rangle", "\\rceil", "\\rfloor",
117                 "\\downarrow", "\\Downarrow",
118                 "\\uparrow", "\\Uparrow",
119                 "\\updownarrow", "\\Updownarrow", ""
120         };
121         return support::findToken(delimiters, to_utf8(delim)) >= 0;
122 }
123
124
125 } // namespace lyx