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