]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rootinset.C
don't #include too much stuff in .h
[lyx.git] / src / mathed / math_rootinset.C
1 /*
2  *  File:        math_root.C
3  *  Purpose:     Implementation of the root object 
4  *  Author:      Alejandro Aguilar Sierra <asierra@servidor.unam.mx> 
5  *  Created:     January 1999
6  *  Description: Root math object
7  *
8  *  Copyright: 1999 Alejandro Aguilar Sierra
9  *
10  *   You are free to use and modify this code under the terms of
11  *   the GNU General Public Licence version 2 or later.
12  */
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "math_rootinset.h"
19 #include "math_mathmlstream.h"
20 #include "Painter.h"
21
22
23 MathRootInset::MathRootInset()
24         : MathNestInset(2)
25 {}
26
27
28 MathInset * MathRootInset::clone() const
29 {
30         return new MathRootInset(*this);
31 }
32
33
34 void MathRootInset::metrics(MathMetricsInfo const & mi) const
35 {
36         MathNestInset::metrics(mi);
37         ascent_  = std::max(xcell(0).ascent()  + 5, xcell(1).ascent())  + 2;
38         descent_ = std::max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
39         width_   = xcell(0).width() + xcell(1).width() + 10;
40 }
41
42
43 void MathRootInset::draw(Painter & pain, int x, int y) const
44 {
45         int const w = xcell(0).width();
46         xcell(0).draw(pain, x, y - 5 - xcell(0).descent());       // the "exponent"
47         xcell(1).draw(pain, x + w + 8, y);   // the "base"
48         int const a = ascent();
49         int const d = descent();
50         int xp[5];
51         int yp[5];
52         xp[0] = x + width_;   yp[0] = y - a + 1;
53         xp[1] = x + w + 4;    yp[1] = y - a + 1;
54         xp[2] = x + w;        yp[2] = y + d;
55         xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
56         xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
57         pain.lines(xp, yp, 5, LColor::mathline);
58 }
59
60
61 void MathRootInset::write(MathWriteInfo & os) const
62 {
63         os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
64 }
65
66
67 void MathRootInset::writeNormal(NormalStream & os) const
68 {
69         os << "[root ";
70         cell(1).writeNormal(os);  
71         os << " ";
72         cell(0).writeNormal(os);
73         os << "]";
74 }
75
76
77 bool MathRootInset::idxUp(int & idx, int & pos) const
78 {
79         if (idx == 0)
80                 return false;
81         idx = 0;
82         pos = cell(0).size();
83         return true;
84 }
85
86
87 bool MathRootInset::idxDown(int & idx, int & pos) const
88 {
89         if (idx == 1)
90                 return false;
91         idx = 1;
92         pos = 0;
93         return true;
94 }
95
96
97 void MathRootInset::octavize(OctaveStream & os) const
98 {
99         os << "root(" << cell(1) << ',' << cell(0) <<')';
100 }
101
102
103 void MathRootInset::mathmlize(MathMLStream & os) const
104 {
105         os << "<mroot>" << cell(1) << cell(0) << "</mroot>";
106 }