]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rootinset.C
everything is an inset. sizeof(MathInset) == 36 on IA32
[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 "support/LOstream.h"
20 #include "Painter.h"
21
22 MathRootInset::MathRootInset()
23         : MathNestInset(2)
24 {}
25
26
27 MathInset * MathRootInset::clone() const
28 {
29         return new MathRootInset(*this);
30 }
31
32
33 void MathRootInset::metrics(MathStyles st)
34 {
35         MathNestInset::metrics(st);
36         size_    = st;
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)
44 {
45         xo(x);
46         yo(y);
47         int const w = xcell(0).width();
48         xcell(0).draw(pain, x, y - 5 - xcell(0).descent());       // the "exponent"
49         xcell(1).draw(pain, x + w + 8, y);   // the "base"
50         int const a = ascent();
51         int const d = descent();
52         int xp[5];
53         int yp[5];
54         xp[0] = x + width_;   yp[0] = y - a + 1;
55         xp[1] = x + w + 4;    yp[1] = y - a + 1;
56         xp[2] = x + w;        yp[2] = y + d;
57         xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
58         xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
59         pain.lines(xp, yp, 5, LColor::mathline);
60 }
61
62
63 void MathRootInset::write(std::ostream & os, bool fragile) const
64 {
65         os << "\\sqrt[";
66         cell(0).write(os, fragile);  
67         os << "]{";
68         cell(1).write(os, fragile);
69         os << '}';
70 }
71
72
73 void MathRootInset::writeNormal(std::ostream & os) const
74 {
75         os << "[root ";
76         cell(1).writeNormal(os);  
77         os << " ";
78         cell(0).writeNormal(os);
79         os << "] ";
80 }
81
82 bool MathRootInset::idxUp(int & idx, int & pos) const
83 {
84         if (idx == 0)
85                 return false;
86         idx = 0;
87         pos = 0;
88         return true;
89 }
90
91 bool MathRootInset::idxDown(int & idx, int & pos) const
92 {
93         if (idx == 1)
94                 return false;
95         idx = 1;
96         pos = 0;
97         return true;
98 }