]> git.lyx.org Git - lyx.git/blob - src/mathed/math_root.C
LyX Drinkers Union: patch 1
[lyx.git] / src / mathed / math_root.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 #include <config.h>
15
16 #ifdef __GNUG__
17 #pragma implementation
18 #endif
19
20 #include "math_root.h"
21 #include "support/LOstream.h"
22 #include "Painter.h"
23
24 MathRootInset::MathRootInset()
25         : MathInset("sqrt", LM_OT_SQRT, 2)
26 {}
27
28
29 MathInset * MathRootInset::Clone() const
30 {
31         return new MathRootInset(*this);
32 }
33
34
35 void MathRootInset::Metrics(MathStyles st)
36 {
37         MathInset::Metrics(st);
38         size_    = st;
39         ascent_  = max(xcell(0).ascent()  + 5, xcell(1).ascent())  + 2;
40         descent_ = max(xcell(1).descent() + 5, xcell(0).descent()) + 2;
41         width_   = xcell(0).width() + xcell(1).width() + 10;
42 }
43
44
45 void MathRootInset::draw(Painter & pain, int x, int y)
46 {
47         xo(x);
48         yo(y);
49         int const w = xcell(0).width();
50         xcell(0).draw(pain, x, y - 5 - xcell(0).descent());       // the "exponent"
51         xcell(1).draw(pain, x + w + 8, y);   // the "base"
52         int const a = ascent();
53         int const d = descent();
54         int xp[5];
55         int yp[5];
56         xp[0] = x + width_;   yp[0] = y - a + 1;
57         xp[1] = x + w + 4;    yp[1] = y - a + 1;
58         xp[2] = x + w;        yp[2] = y + d;
59         xp[3] = x + w - 2;    yp[3] = y + (d - a)/2 + 2;
60         xp[4] = x;            yp[4] = y + (d - a)/2 + 2;
61         pain.lines(xp, yp, 5, LColor::mathline);
62 }
63
64
65 void MathRootInset::Write(ostream & os, bool fragile) const
66 {
67         os << "\\sqrt[";
68         cell(0).Write(os, fragile);  
69         os << "]{";
70         cell(1).Write(os, fragile);
71         os << '}';
72 }
73
74
75 void MathRootInset::WriteNormal(ostream & os) const
76 {
77         os << "[root ";
78         cell(1).WriteNormal(os);  
79         os << " ";
80         cell(0).WriteNormal(os);
81         os << "] ";
82 }
83
84 bool MathRootInset::idxUp(int & idx, int & pos) const
85 {
86         if (idx == 0)
87                 return false;
88         idx = 0;
89         pos = 0;
90         return true;
91 }
92
93 bool MathRootInset::idxDown(int & idx, int & pos) const
94 {
95         if (idx == 1)
96                 return false;
97         idx = 1;
98         pos = 0;
99         return true;
100 }