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