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