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