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