]> git.lyx.org Git - lyx.git/blob - src/mathed/math_root.C
small cleanup, doxygen, formatting changes
[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_iter.h"
23 #include "math_root.h"
24 #include "support/LOstream.h"
25
26 using std::ostream;
27
28 MathRootInset::MathRootInset(short st)
29         : MathSqrtInset(st)
30 {
31         idx_ = 1;
32         uroot_ = new MathParInset(LM_ST_TEXT); 
33 }
34
35
36 MathRootInset::~MathRootInset() 
37 {
38         delete uroot_;
39 }
40
41
42 MathedInset * MathRootInset::Clone()
43 {
44         MathRootInset * p = new MathRootInset(GetStyle());
45         MathedIter it(array);
46         MathedIter itr(uroot_->GetData());
47         p->setData(it.Copy());
48         p->setArgumentIdx(0);
49         p->setData(itr.Copy());
50         
51         return p;
52 }
53
54
55 void MathRootInset::setData(MathedArray * d)
56 {
57         if (idx_ == 1)
58                 MathParInset::setData(d);
59         else {
60                 uroot_->setData(d);
61         }
62 }
63
64
65 bool MathRootInset::setArgumentIdx(int i)
66 {
67         if (i == 0 || i == 1) {
68                 idx_ = i;
69                 return true;
70         } else
71                 return false;
72 }
73
74
75 void MathRootInset::GetXY(int & x, int & y) const
76 {
77         if (idx_ == 1)
78                 MathParInset::GetXY(x, y);
79         else
80                 uroot_->GetXY(x, y);
81 }
82
83
84 MathedArray * MathRootInset::GetData()
85 {
86         if (idx_ == 1)
87                 return array;
88         else
89                 return uroot_->GetData();
90 }
91
92
93 bool MathRootInset::Inside(int x, int y)
94 {
95         return (uroot_->Inside(x, y) || MathSqrtInset::Inside(x, y));
96 }
97
98
99 void MathRootInset::Metrics()
100 {
101         int idxp = idx_;
102         
103         idx_ = 1;
104         MathSqrtInset::Metrics();
105         uroot_->Metrics();
106         wroot_ = uroot_->Width();
107         dh_ = Height()/2;
108         width += wroot_;
109         //    if (uroot->Ascent() > dh) 
110         if (uroot_->Height() > dh_) 
111                 ascent += uroot_->Height() - dh_;
112         dh_ -= descent - uroot_->Descent();
113         idx_ = idxp;
114 }
115
116
117 void MathRootInset::draw(Painter & pain, int x, int y)
118 {
119         int idxp = idx_;
120         
121         idx_ = 1;
122         uroot_->draw(pain, x, y - dh_);
123         MathSqrtInset::draw(pain, x + wroot_, y);
124         idx_ = idxp;
125 }
126
127
128 void MathRootInset::SetStyle(short st)
129 {
130         MathSqrtInset::SetStyle(st);
131         
132         uroot_->SetStyle((size() < LM_ST_SCRIPTSCRIPT) ? size() + 1 : size());
133 }
134
135
136 void MathRootInset::SetFocus(int x, int)
137 {  
138         idx_ = (x > xo() + wroot_) ? 1: 0;
139 }
140
141
142 void MathRootInset::Write(ostream & os, bool fragile)
143 {
144         os << '\\' << name << '[';
145         uroot_->Write(os, fragile);  
146         os << "]{";
147         MathParInset::Write(os, fragile);
148         os << '}';
149 }