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