]> git.lyx.org Git - lyx.git/blob - src/mathed/math_bigopinset.C
change a lot of methods to begin with small char
[lyx.git] / src / mathed / math_bigopinset.C
1 #include <config.h>
2
3 #include <functional>
4
5 #include "math_bigopinset.h"
6 #include "LColor.h"
7 #include "Painter.h"
8 #include "mathed/support.h"
9 #include "support/LOstream.h"
10
11 using std::ostream;
12
13 MathBigopInset::MathBigopInset(string const & name, int id)
14         : MathScriptInset(true, false), lims_(-1), sym_(id)
15 {
16         SetName(name);
17 }
18
19
20 MathInset * MathBigopInset::clone() const
21 {
22         return new MathBigopInset(*this);
23 }
24
25
26
27 void MathBigopInset::Write(ostream & os, bool fragile) const
28 {
29         //bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY;
30         os << '\\' << name();
31         if (limits() == 1)
32                 os << "\\limits ";
33         else if (limits() == -1)
34                 os << "\\nolimits ";
35         else 
36                 os << ' ';
37         MathScriptInset::Write(os, fragile);
38 }
39
40
41 void MathBigopInset::WriteNormal(ostream & os) const
42 {
43         os << "[bigop " << name();
44         if (limits() == 1)
45                 os << "\\limits ";
46         else if (limits() == -1)
47                 os << "\\nolimits ";
48         else 
49                 os << ' ';
50         MathScriptInset::WriteNormal(os);
51         os << "] ";
52 }
53
54 void MathBigopInset::Metrics(MathStyles st)
55 {
56         MathScriptInset::Metrics(st);
57         size(st);
58         string s;
59         short t;
60         
61         if (sym_ < 256 || sym_ == LM_oint) {
62                 char const c = (sym_ == LM_oint) ? LM_int : sym_;
63                 s += c;
64                 t = LM_TC_BSYM;
65         } else {
66                 s = name();
67                 t = LM_TC_TEXTRM;
68         }
69
70         int asc, des, wid;
71         mathed_string_dim(t, size(), s, asc, des, wid);
72         if (sym_ == LM_oint)
73                 wid += 2;
74
75         if (hasLimits()) {
76                 ascent_  = asc + xcell(0).height() + 2;
77                 descent_ = des + xcell(1).height() + 2;
78                 width_   = std::max(width_, wid);
79         } else {
80                 ascent_  = std::max(ascent_, asc);
81                 descent_ = std::max(descent_, des);
82                 width_  += wid;
83         }
84
85 }
86
87
88 void MathBigopInset::draw(Painter & pain, int x, int y)
89 {
90         xo(x);
91         yo(y);
92
93         string s;
94         short t;
95         
96         if (sym_ < 256 || sym_ == LM_oint) {
97                 s += (sym_ == LM_oint) ? LM_int : sym_;
98                 t = LM_TC_BSYM;
99         } else {
100                 s = name();
101                 t = LM_TC_TEXTRM;
102         }
103         if (sym_ == LM_oint) {
104                 pain.arc(x, y - 5 * width_ / 4, width_, width_, 0, 360 * 64,
105                          LColor::mathline);
106                 ++x;
107         }
108
109         int asc, des, wid;
110         mathed_string_dim(t, size(), s, asc, des, wid);
111
112         if (hasLimits()) {
113                 int w = width();
114                 pain.text(x + (w - wid)/2, y, s, mathed_get_font(t, size()));
115                 xcell(0).draw
116                         (pain, x + (w - xcell(0).width())/2, y - asc - xcell(0).descent() - 1);
117                 xcell(1).draw
118                         (pain, x + (w - xcell(1).width())/2, y + des + xcell(1).ascent()  + 1);
119         } else {
120                 pain.text(x, y, s, mathed_get_font(t, size()));
121                 MathScriptInset::draw(pain, x + wid, y);
122         }
123 }
124
125
126 int MathBigopInset::limits() const 
127 {
128         return lims_;   
129
130
131
132 void MathBigopInset::limits(int limit) 
133 {  
134         lims_ = limit;
135 }
136
137 bool MathBigopInset::hasLimits() const
138 {
139         return limits() == 1 || (limits() == 0 && size() == LM_ST_DISPLAY);
140 }
141
142
143 bool MathBigopInset::idxDelete(int idx)
144 {
145         // ignore the return value, we do not want the inset to be deleted
146         MathScriptInset::idxDelete(idx);
147         return false;
148 }