]> git.lyx.org Git - lyx.git/blob - src/mathed/math_bigopinset.C
fix pullArg when pressing <Delete> at the end of an cell
[lyx.git] / src / mathed / math_bigopinset.C
1 #include "math_bigopinset.h"
2 #include "Painter.h"
3 #include "mathed/support.h"
4 #include "support/LOstream.h"
5
6
7 using std::ostream;
8
9 MathBigopInset::MathBigopInset(string const & name, int id)
10         : MathUpDownInset(false, false), sym_(id), limits_(0)
11 {
12         SetName(name);
13 }
14
15
16 MathInset * MathBigopInset::clone() const
17 {
18         return new MathBigopInset(*this);
19 }
20
21
22 int MathBigopInset::limits() const 
23 {
24         return limits_; 
25
26
27
28 void MathBigopInset::limits(int limits) 
29 {  
30         limits_ = limits;
31 }
32
33
34 bool MathBigopInset::hasLimits() const
35 {
36         return limits_ == 1 || (limits_ == 0 && size() == LM_ST_DISPLAY);
37 }
38
39
40 void MathBigopInset::Write(ostream & os, bool fragile) const
41 {
42         //bool f = sym_ != LM_int && sym_ != LM_oint && size() == LM_ST_DISPLAY;
43         os << '\\' << name();
44         MathUpDownInset::Write(os, fragile);
45 }
46
47
48 void MathBigopInset::WriteNormal(ostream & os) const
49 {
50         os << "[bigop " << name() << "] ";
51 }
52
53
54 void MathBigopInset::Metrics(MathStyles st, int, int)
55 {
56         //cerr << "\nBigopDraw\n";
57         size(st);
58         
59         if (sym_ < 256 || sym_ == LM_oint) {
60                 ssym_ = string();
61                 ssym_ += (sym_ == LM_oint) ? LM_int : sym_;
62                 code_ = LM_TC_BSYM;
63         } else {
64                 ssym_ = name();
65                 code_ = LM_TC_TEXTRM;
66         }
67
68         int wid;
69         mathed_string_dim(code_, size(), ssym_, ascent_, descent_, wid);
70         if (sym_ == LM_oint)
71                 wid += 2;
72         //cerr << "  asc: " << ascent_ << " des: " << descent_
73         //      << " wid: " << wid << "\n";
74         //cerr << "  hasLimits: " << hasLimits() << " up: "
75         //      << up() << " down: " << down() << "\n";
76         
77         width_ = wid;
78
79         if (hasLimits()) {
80                 xcell(0).Metrics(st);
81                 xcell(1).Metrics(st);
82                 //cerr << "  0: ascent_: " << xcell(0).ascent() << " descent_: " <<
83                 //      xcell(0).descent() << " width_: " << xcell(0).width() << "\n";
84                 //cerr << "  1: ascent_: " << xcell(1).ascent() << " descent_: " <<
85                 //      xcell(1).descent() << " width_: " << xcell(1).width() << "\n";
86                 if (up()) {
87                         ascent_  += xcell(0).height() + 1;
88                         width_   = std::max(width_, xcell(0).width());
89                         dy0_     = - (ascent_ - xcell(0).ascent());
90                 }
91                 if (down()) {
92                         descent_ += xcell(1).height() + 1;
93                         width_   = std::max(width_, xcell(1).width());
94                         dy1_     = descent_ - xcell(1).descent();
95                 }
96                 dxx_  = (width_ - wid) / 2;
97                 dx0_  = (width_ - xcell(0).width()) / 2;
98                 dx1_  = (width_ - xcell(1).width()) / 2;
99                 //cerr << "  ascent_: " << ascent_ << " descent_: "
100                 //      << descent_ << " width_: " << width_ << "\n";
101                 //cerr << "  dx0_: " << dx0_ << " dx1_: " << dx1_
102                 //      << " dxx_: " << dxx_ << "\n";
103                 //cerr << "  dy0_: " << dy0_ << " dy1_: " << dy1_
104                 //      << "\n";
105         } else {
106                 MathUpDownInset::Metrics(st, ascent_, descent_);
107                 width_   += wid;
108                 dx0_     = wid;
109                 dx1_     = wid;
110                 dxx_     = 0;
111         }
112 }
113
114
115 void MathBigopInset::draw(Painter & pain, int x, int y)
116 {  
117         xo(x);
118         yo(y);
119
120         drawStr(pain, code_, size_, x + dxx_, y, ssym_);
121
122         if (up())
123                 xcell(0).draw(pain, x + dx0_, y + dy0_);
124         if (down())
125                 xcell(1).draw(pain, x + dx1_, y + dy1_);
126
127         if (sym_ == LM_oint) {
128                 int xx = x - 1;
129                 int yy = y - (ascent_ - descent_) / 2;
130                 pain.arc(xx, yy, width_, width_, 0, 360 * 64, LColor::mathline);
131         }
132 }
133
134