]> git.lyx.org Git - lyx.git/blob - src/mathed/math_root.C
mathed cleanup, change mask for tmpdir
[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: 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_root.h"
23 #include "math_iter.h"
24 #include "support/LOstream.h"
25
26 using std::ostream;
27
28 MathRootInset::MathRootInset(short st)
29         : MathSqrtInset(st), idx_(1), uroot_(LM_ST_TEXT)
30 {}
31
32
33 MathedInset * MathRootInset::Clone()
34 {
35         MathRootInset * p = new MathRootInset(*this);
36         p->setArgumentIdx(0);
37         return p;
38 }
39
40
41 void MathRootInset::setData(MathedArray const & d)
42 {
43         if (idx_ == 1)
44                 MathParInset::setData(d);
45         else
46                 uroot_.setData(d);
47 }
48
49
50 bool MathRootInset::setArgumentIdx(int i)
51 {
52         if (i == 0 || i == 1) {
53                 idx_ = i;
54                 return true;
55         } else
56                 return false;
57 }
58
59
60 void MathRootInset::GetXY(int & x, int & y) const
61 {
62         if (idx_ == 1)
63                 MathParInset::GetXY(x, y);
64         else
65                 uroot_.GetXY(x, y);
66 }
67
68
69 MathedArray & MathRootInset::GetData()
70 {
71         if (idx_ == 1)
72                 return array;
73         else
74                 return uroot_.GetData();
75 }
76
77
78 bool MathRootInset::Inside(int x, int y)
79 {
80         return (uroot_.Inside(x, y) || MathSqrtInset::Inside(x, y));
81 }
82
83
84 void MathRootInset::Metrics()
85 {
86         int const idxp = idx_;
87         
88         idx_ = 1;
89         MathSqrtInset::Metrics();
90         uroot_.Metrics();
91         wroot_ = uroot_.Width();
92         dh_ = Height() / 2;
93         width += wroot_;
94         //    if (uroot_.Ascent() > dh) 
95         if (uroot_.Height() > dh_) 
96                 ascent += uroot_.Height() - dh_;
97         dh_ -= descent - uroot_.Descent();
98         idx_ = idxp;
99 }
100
101
102 void MathRootInset::draw(Painter & pain, int x, int y)
103 {
104         int const idxp = idx_;
105         
106         idx_ = 1;
107         uroot_.draw(pain, x, y - dh_);
108         MathSqrtInset::draw(pain, x + wroot_, y);
109         idx_ = idxp;
110 }
111
112
113 void MathRootInset::SetStyle(short st)
114 {
115         MathSqrtInset::SetStyle(st);
116         
117         uroot_.SetStyle((size() < LM_ST_SCRIPTSCRIPT) ? size() + 1 : size());
118 }
119
120
121 void MathRootInset::SetFocus(int x, int)
122 {  
123         idx_ = (x > xo() + wroot_) ? 1: 0;
124 }
125
126
127 void MathRootInset::Write(ostream & os, bool fragile)
128 {
129         os << '\\' << name << '[';
130         uroot_.Write(os, fragile);  
131         os << "]{";
132         MathParInset::Write(os, fragile);
133         os << '}';
134 }