]> git.lyx.org Git - lyx.git/blob - src/mathed/math_fracinset.C
mathed cleanup, change mask for tmpdir
[lyx.git] / src / mathed / math_fracinset.C
1 #include <config.h>
2
3 #ifdef __GNUG__
4 #pragma implementation
5 #endif
6
7 #include "math_fracinset.h"
8 #include "math_iter.h"
9 #include "LColor.h"
10 #include "Painter.h"
11 #include "mathed/support.h"
12 #include "support/LOstream.h"
13
14 using std::ostream;
15
16
17 MathFracInset::MathFracInset(short ot)
18         : MathParInset(LM_ST_TEXT, "frac", ot),
19           idx_(0), den_(LM_ST_TEXT), dh_(0)
20 {
21         if (objtype == LM_OT_STACKREL) {
22                 flag |= LMPF_SCRIPT;
23                 SetName("stackrel");
24         }
25 }
26
27
28 MathedInset * MathFracInset::Clone()
29 {   
30         MathFracInset * p = new MathFracInset(*this);
31         return p;
32 }
33
34
35 bool MathFracInset::setArgumentIdx(int i)
36 {
37         if (i == 0 || i == 1) {
38                 idx_ = i;
39                 return true;
40         } else 
41                 return false;
42 }
43
44
45 void MathFracInset::SetStyle(short st)
46 {
47         MathParInset::SetStyle(st);
48         dh_ = 0;
49         den_.SetStyle((size() == LM_ST_DISPLAY) ?
50                       static_cast<short>(LM_ST_TEXT)
51                       : size());
52 }
53
54
55 void MathFracInset::SetData(MathedArray const & n, MathedArray const & d)
56 {
57         den_.setData(d);
58         MathParInset::setData(n);
59 }
60
61
62 void MathFracInset::setData(MathedArray const & d)
63 {
64         if (idx_ == 0)
65                 MathParInset::setData(d);
66         else {
67                 den_.setData(d);
68         }
69 }
70
71
72 void MathFracInset::GetXY(int & x, int & y) const
73 {  
74         if (idx_ == 0)
75                 MathParInset::GetXY(x, y);
76         else
77                 den_.GetXY(x, y);
78 }
79
80
81 MathedArray & MathFracInset::GetData()
82 {
83         if (idx_ == 0)
84                 return array;
85         else
86                 return den_.GetData();
87 }
88
89
90 bool MathFracInset::Inside(int x, int y) 
91 {
92         int const xx = xo() - (width - w0_) / 2;
93         
94         return x >= xx
95                 && x <= xx + width
96                 && y <= yo() + descent
97                 && y >= yo() - ascent;
98 }
99
100
101 void MathFracInset::SetFocus(int /*x*/, int y)
102 {  
103         // lyxerr << "y " << y << " " << yo << " " << den_->yo << " ";
104         idx_ = (y > yo()) ? 1 : 0;
105 }
106
107
108 void
109 MathFracInset::draw(Painter & pain, int x, int y)
110
111         int const idxp = idx_;
112         int const sizex = size();
113         
114         idx_ = 0;
115         if (size() == LM_ST_DISPLAY) incSize();
116         MathParInset::draw(pain, x + (width - w0_) / 2, y - des0_);
117         den_.draw(pain, x + (width - w1_) / 2, y + den_.Ascent() + 2 - dh_);
118         size(sizex);
119         if (objtype == LM_OT_FRAC)
120                 pain.line(x + 2, y - dh_,
121                           x + width - 4, y - dh_, LColor::mathline);
122         idx_ = idxp;
123 }
124
125
126 void
127 MathFracInset::Metrics()
128 {
129         if (!dh_) {
130                 int a;
131                 int b;
132                 dh_ = mathed_char_height(LM_TC_CONST, size(), 'I', a, b) / 2;
133         }
134         int const idxp = idx_;
135         int const sizex = size();
136         idx_ = 0;
137         if (size() == LM_ST_DISPLAY) incSize(); 
138         MathParInset::Metrics();
139         size(sizex);
140         w0_ = width;
141         int const as = Height() + 2 + dh_;
142         des0_ = Descent() + 2 + dh_;
143         den_.Metrics();  
144         w1_ = den_.Width();   
145         width = ((w0_ > w1_) ? w0_: w1_) + 12;
146         ascent = as; 
147         descent = den_.Height()+ 2 - dh_;
148         idx_ = idxp;
149 }
150
151
152 void MathFracInset::Write(ostream & os, bool fragile)
153 {
154         os << '\\' << name << '{';
155         MathParInset::Write(os, fragile);
156         os << "}{";
157         den_.Write(os, fragile);
158         os << '}';
159 }