]> git.lyx.org Git - lyx.git/blob - src/mathed/math_root.C
c40f005e2f206fbff57c74476167ec753f2d70c2
[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 LyxArrayBase *MathRootInset::GetData()
79 {
80    if (idx == 1)
81      return array;
82    else
83      return uroot->GetData();
84 }
85
86
87 bool MathRootInset::Inside(int x, int y)
88 {
89     return (uroot->Inside(x, y) || MathSqrtInset::Inside(x, y));
90 }
91
92
93 void MathRootInset::Metrics()
94 {
95     int idxp = idx;
96
97     idx = 1;
98     MathSqrtInset::Metrics();
99     uroot->Metrics();
100     wroot = uroot->Width();
101     dh = Height()/2;
102     width += wroot;
103     //    if (uroot->Ascent() > dh) 
104     if (uroot->Height() > dh) 
105       ascent += uroot->Height() - dh;
106     dh -= descent - uroot->Descent();
107     idx = idxp;
108 }
109
110
111 void MathRootInset::Draw(int x, int y)
112 {
113     int idxp = idx;
114
115     idx = 1;
116     uroot->Draw(x, y - dh);
117     MathSqrtInset::Draw(x+wroot, y);
118     XFlush(fl_display);
119     idx = idxp;
120 }
121
122
123 void MathRootInset::SetStyle(short st)
124 {
125     MathSqrtInset::SetStyle(st);
126     
127     uroot->SetStyle((size<LM_ST_SCRIPTSCRIPT) ? size+1: size);
128 }
129
130
131 void MathRootInset::SetFocus(int x, int)
132 {  
133     idx = (x > xo + wroot) ? 1: 0;
134 }
135
136
137 void MathRootInset::Write(FILE *outf)
138
139    string output;
140    MathRootInset::Write(output);  
141    fprintf(outf, "%s", output.c_str());
142 }
143
144
145 void MathRootInset::Write(string &outf)
146
147    outf += '\\';
148    outf += name;
149    outf += '[';
150    uroot->Write(outf);  
151    outf += "]{";
152    MathParInset::Write(outf);
153    outf += '}';
154 }