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