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