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