]> git.lyx.org Git - lyx.git/blob - src/mathed/math_bigopinset.C
mathed67.diff
[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 & nam, int id, short st)
12         : MathedInset(nam, LM_OT_BIGOP, st), lims_(-1), sym_(id)
13 {}
14
15
16 MathedInset * MathBigopInset::Clone()
17 {
18         return new MathBigopInset(name, sym_, GetStyle());
19 }
20
21
22 void MathBigopInset::draw(Painter & pain, int x, int y)
23 {
24         string s;
25         short t;
26         
27         if (sym_ < 256 || sym_ == LM_oint) {
28                 s += (sym_ == LM_oint) ? LM_int : sym_;
29                 t = LM_TC_BSYM;
30         } else {
31                 s = name;
32                 t = LM_TC_TEXTRM;
33         }
34         if (sym_ == LM_oint) {
35                 pain.arc(x, y - 5 * width / 4, width, width, 0, 360 * 64,
36                          LColor::mathline);
37                 ++x;
38         }
39         pain.text(x, y, s, mathed_get_font(t, size()));
40 }
41
42
43 void MathBigopInset::Write(ostream & os, bool /* fragile */)
44 {
45         bool const limp = GetLimits();
46         
47         os << '\\' << name;
48         
49         if (limp && !(sym_ != LM_int && sym_ != LM_oint
50                       && (GetStyle() == LM_ST_DISPLAY)))
51                 os << "\\limits ";
52         else 
53                 if (!limp && (sym_ != LM_int && sym_ != LM_oint
54                               && (GetStyle() == LM_ST_DISPLAY)))
55                         os << "\\nolimits ";
56                 else 
57                         os << ' ';
58 }
59
60
61 void MathBigopInset::WriteNormal(ostream & os)
62 {
63         bool const limp = GetLimits();
64         
65         os << "[bigop " << name;
66         
67         if (limp && !(sym_ != LM_int && sym_ != LM_oint
68                       && (GetStyle() == LM_ST_DISPLAY)))
69                 os << " limits";
70         else 
71                 if (!limp && (sym_ != LM_int && sym_ != LM_oint
72                               && (GetStyle() == LM_ST_DISPLAY)))
73                         os << " nolimits";
74         
75         os << "] ";
76 }
77
78 void MathBigopInset::Metrics()
79 {
80         //char c;
81         string s;
82         short t;
83         
84         if (sym_ < 256 || sym_ == LM_oint) {
85                 char const c = (sym_ == LM_oint) ? LM_int: sym_;
86                 s += c;
87                 t = LM_TC_BSYM;
88         } else {
89                 s = name;
90                 t = LM_TC_TEXTRM;
91         }
92         mathed_string_height(t, size(), s, ascent, descent);
93         width = mathed_string_width(t, size(), s);
94         if (sym_ == LM_oint) width += 2;
95 }
96
97
98 bool MathBigopInset::GetLimits() const 
99 {  
100         // Default case
101         if (lims_ < 0) {
102                 return sym_ != LM_int &&
103                         sym_ != LM_oint &&
104                         GetStyle() == LM_ST_DISPLAY;
105         } 
106         
107         // Custom 
108         return lims_ > 0;
109
110
111
112 void MathBigopInset::SetLimits(bool ls) 
113 {  
114         lims_ = ls ? 1 : 0; 
115 }