]> git.lyx.org Git - lyx.git/blob - src/mathed/math_bigopinset.C
Small bugfixes and cosmetic changes
[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(false, true), lims_(0), 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                 int wid;
105                 int asc;
106                 int des;
107                 mathed_char_dim(t, size(), LM_int, asc, des, wid);
108                 wid += 2;
109                 pain.arc(x - 1, y - (asc - des) / 2, wid, wid, 0, 360 * 64, LColor::mathline);
110         }
111
112         int asc, des, wid;
113         mathed_string_dim(t, size(), s, asc, des, wid);
114
115         if (hasLimits()) {
116                 int w = width();
117                 pain.text(x + (w - wid)/2, y, s, mathed_get_font(t, size()));
118                 xcell(0).draw
119                         (pain, x + (w - xcell(0).width())/2, y - asc - xcell(0).descent() - 1);
120                 xcell(1).draw
121                         (pain, x + (w - xcell(1).width())/2, y + des + xcell(1).ascent()  + 1);
122         } else {
123                 pain.text(x, y, s, mathed_get_font(t, size()));
124                 MathScriptInset::draw(pain, x + wid, y);
125         }
126 }
127
128
129 int MathBigopInset::limits() const 
130 {
131         return lims_;   
132
133
134
135 void MathBigopInset::limits(int limit) 
136 {  
137         lims_ = limit;
138 }
139
140 bool MathBigopInset::hasLimits() const
141 {
142         return limits() == 1 || (limits() == 0 && size() == LM_ST_DISPLAY);
143 }
144
145
146 bool MathBigopInset::idxDelete(int idx)
147 {
148         // ignore the return value, we do not want the inset to be deleted
149         MathScriptInset::idxDelete(idx);
150         return false;
151 }