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