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
9 * Copyright: 1999 Alejandro Aguilar Sierra
11 * You are free to use and modify this code under the terms of
12 * the GNU General Public Licence version 2 or later.
16 #include FORMS_H_LOCATION
19 #pragma implementation
22 #include "math_iter.h"
23 #include "math_root.h"
24 #include "support/LOstream.h"
28 MathRootInset::MathRootInset(short st)
32 uroot = new MathParInset(LM_ST_TEXT);
36 MathRootInset::~MathRootInset()
42 MathedInset * MathRootInset::Clone()
44 MathRootInset * p = new MathRootInset(GetStyle());
45 MathedIter it(array), itr(uroot->GetData());
46 p->SetData(it.Copy());
48 p->SetData(itr.Copy());
54 void MathRootInset::SetData(MathedArray * d)
57 MathParInset::SetData(d);
64 bool MathRootInset::setArgumentIdx(int i)
66 if (i == 0 || i == 1) {
74 void MathRootInset::GetXY(int & x, int & y) const
77 MathParInset::GetXY(x, y);
83 MathedArray * MathRootInset::GetData()
88 return uroot->GetData();
92 bool MathRootInset::Inside(int x, int y)
94 return (uroot->Inside(x, y) || MathSqrtInset::Inside(x, y));
98 void MathRootInset::Metrics()
103 MathSqrtInset::Metrics();
105 wroot = uroot->Width();
108 // if (uroot->Ascent() > dh)
109 if (uroot->Height() > dh)
110 ascent += uroot->Height() - dh;
111 dh -= descent - uroot->Descent();
116 void MathRootInset::draw(Painter & pain, int x, int y)
121 uroot->draw(pain, x, y - dh);
122 MathSqrtInset::draw(pain, x + wroot, y);
127 void MathRootInset::SetStyle(short st)
129 MathSqrtInset::SetStyle(st);
131 uroot->SetStyle((size<LM_ST_SCRIPTSCRIPT) ? size+1: size);
135 void MathRootInset::SetFocus(int x, int)
137 idx = (x > xo + wroot) ? 1: 0;
141 void MathRootInset::Write(ostream & os, bool fragile)
143 os << '\\' << name << '[';
144 uroot->Write(os, fragile);
146 MathParInset::Write(os, fragile);