]> git.lyx.org Git - lyx.git/blob - src/mathed/math_root.C
In for a penny, in for a pound. Consistent use of // -*- C++ -*-
[lyx.git] / src / mathed / math_root.C
1 /*
2  *  File:        math_root.C
3  *  Purpose:     Implementation of the root object 
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
5  *  Created:     January 1999
6  *  Description: Root math object
7  *
8  *  Copyright: 1999 Alejandro Aguilar Sierra
9  *
10  *   You are free to use and modify this code under the terms of
11  *   the GNU General Public Licence version 2 or later.
12  */
13
14 #include <config.h>
15 #include FORMS_H_LOCATION
16
17 #ifdef __GNUG__
18 #pragma implementation
19 #endif
20
21 #include "math_root.h"
22 #include "math_iter.h"
23 #include "support/LOstream.h"
24
25 using std::ostream;
26
27 MathRootInset::MathRootInset(short st)
28         : MathSqrtInset(st), idx_(1), uroot_(LM_ST_TEXT)
29 {}
30
31
32 MathedInset * MathRootInset::Clone()
33 {
34         MathRootInset * p = new MathRootInset(*this);
35         p->setArgumentIdx(0);
36         return p;
37 }
38
39
40 void MathRootInset::setData(MathedArray const & d)
41 {
42         if (idx_ == 1)
43                 MathParInset::setData(d);
44         else
45                 uroot_.setData(d);
46 }
47
48
49 bool MathRootInset::setArgumentIdx(int i)
50 {
51         if (i == 0 || i == 1) {
52                 idx_ = i;
53                 return true;
54         } else
55                 return false;
56 }
57
58
59 int MathRootInset::getArgumentIdx() const
60 {
61         return idx_;
62 }
63
64
65 int MathRootInset::getMaxArgumentIdx() const
66 {
67         return 1;
68 }
69
70
71 void MathRootInset::GetXY(int & x, int & y) const
72 {
73         if (idx_ == 1)
74                 MathParInset::GetXY(x, y);
75         else
76                 uroot_.GetXY(x, y);
77 }
78
79
80 MathedArray & MathRootInset::GetData()
81 {
82         if (idx_ == 1)
83                 return array;
84         else
85                 return uroot_.GetData();
86 }
87
88
89 MathedArray const & MathRootInset::GetData() const
90 {
91         if (idx_ == 1)
92                 return array;
93         else
94                 return uroot_.GetData();
95 }
96
97
98 bool MathRootInset::Inside(int x, int y)
99 {
100         return (uroot_.Inside(x, y) || MathSqrtInset::Inside(x, y));
101 }
102
103
104 void MathRootInset::Metrics()
105 {
106         int const idxp = idx_;
107         
108         idx_ = 1;
109         MathSqrtInset::Metrics();
110         uroot_.Metrics();
111         wroot_ = uroot_.Width();
112         dh_ = Height() / 2;
113         width += wroot_;
114         //    if (uroot_.Ascent() > dh) 
115         if (uroot_.Height() > dh_) 
116                 ascent += uroot_.Height() - dh_;
117         dh_ -= descent - uroot_.Descent();
118         idx_ = idxp;
119 }
120
121
122 void MathRootInset::draw(Painter & pain, int x, int y)
123 {
124         int const idxp = idx_;
125         
126         idx_ = 1;
127         uroot_.draw(pain, x, y - dh_);
128         MathSqrtInset::draw(pain, x + wroot_, y);
129         idx_ = idxp;
130 }
131
132
133 void MathRootInset::SetStyle(short st)
134 {
135         MathSqrtInset::SetStyle(st);
136         
137         uroot_.SetStyle((size() < LM_ST_SCRIPTSCRIPT) ? size() + 1 : size());
138 }
139
140
141 void MathRootInset::SetFocus(int x, int)
142 {  
143         idx_ = (x > xo() + wroot_) ? 1: 0;
144 }
145
146
147 void MathRootInset::Write(ostream & os, bool fragile)
148 {
149         os << '\\' << name << '[';
150         uroot_.Write(os, fragile);  
151         os << "]{";
152         MathParInset::Write(os, fragile);
153         os << '}';
154 }
155
156
157 void MathRootInset::WriteNormal(ostream & os)
158 {
159         os << "[root ";
160         uroot_.WriteNormal(os);  
161         os << " ";
162         MathParInset::WriteNormal(os);
163         os << "] ";
164 }