1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_root.C
|
|
|
|
* Purpose: Implementation of the root object
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1999
|
|
|
|
* Description: Root math object
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1999 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_root.h"
|
2001-02-26 12:53:35 +00:00
|
|
|
#include "math_iter.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
#include "support/LOstream.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
MathRootInset::MathRootInset(short st)
|
|
|
|
: MathSqrtInset(st)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = 1;
|
|
|
|
uroot_ = new MathParInset(LM_ST_TEXT);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathRootInset::~MathRootInset()
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
delete uroot_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * MathRootInset::Clone()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-20 10:49:48 +00:00
|
|
|
MathRootInset * p = new MathRootInset(*this);
|
2001-02-20 14:00:34 +00:00
|
|
|
p->uroot_ = static_cast<MathParInset *>(p->uroot_->Clone());
|
2001-02-15 12:22:01 +00:00
|
|
|
p->setArgumentIdx(0);
|
|
|
|
return p;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-20 16:00:22 +00:00
|
|
|
void MathRootInset::setData(MathedArray const & d)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 1)
|
|
|
|
MathParInset::setData(d);
|
2001-02-15 12:22:01 +00:00
|
|
|
else {
|
2001-02-16 09:25:43 +00:00
|
|
|
uroot_->setData(d);
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathRootInset::setArgumentIdx(int i)
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
if (i == 0 || i == 1) {
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = i;
|
2001-02-15 12:22:01 +00:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathRootInset::GetXY(int & x, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 1)
|
2001-02-15 12:22:01 +00:00
|
|
|
MathParInset::GetXY(x, y);
|
|
|
|
else
|
2001-02-16 09:25:43 +00:00
|
|
|
uroot_->GetXY(x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray & MathRootInset::GetData()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
if (idx_ == 1)
|
2001-02-20 16:00:22 +00:00
|
|
|
return array;
|
2001-02-15 12:22:01 +00:00
|
|
|
else
|
2001-02-16 09:25:43 +00:00
|
|
|
return uroot_->GetData();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathRootInset::Inside(int x, int y)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
return (uroot_->Inside(x, y) || MathSqrtInset::Inside(x, y));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::Metrics()
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
int idxp = idx_;
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = 1;
|
2001-02-15 12:22:01 +00:00
|
|
|
MathSqrtInset::Metrics();
|
2001-02-16 09:25:43 +00:00
|
|
|
uroot_->Metrics();
|
|
|
|
wroot_ = uroot_->Width();
|
|
|
|
dh_ = Height()/2;
|
|
|
|
width += wroot_;
|
2001-02-15 12:22:01 +00:00
|
|
|
// if (uroot->Ascent() > dh)
|
2001-02-16 09:25:43 +00:00
|
|
|
if (uroot_->Height() > dh_)
|
|
|
|
ascent += uroot_->Height() - dh_;
|
|
|
|
dh_ -= descent - uroot_->Descent();
|
|
|
|
idx_ = idxp;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void MathRootInset::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
int idxp = idx_;
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = 1;
|
|
|
|
uroot_->draw(pain, x, y - dh_);
|
|
|
|
MathSqrtInset::draw(pain, x + wroot_, y);
|
|
|
|
idx_ = idxp;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::SetStyle(short st)
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
MathSqrtInset::SetStyle(st);
|
|
|
|
|
2001-02-16 09:25:43 +00:00
|
|
|
uroot_->SetStyle((size() < LM_ST_SCRIPTSCRIPT) ? size() + 1 : size());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::SetFocus(int x, int)
|
|
|
|
{
|
2001-02-16 09:25:43 +00:00
|
|
|
idx_ = (x > xo() + wroot_) ? 1: 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-19 01:42:55 +00:00
|
|
|
void MathRootInset::Write(ostream & os, bool fragile)
|
2000-03-07 01:14:37 +00:00
|
|
|
{
|
|
|
|
os << '\\' << name << '[';
|
2001-02-16 09:25:43 +00:00
|
|
|
uroot_->Write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
os << "]{";
|
2000-04-17 14:00:18 +00:00
|
|
|
MathParInset::Write(os, fragile);
|
2000-03-07 01:14:37 +00:00
|
|
|
os << '}';
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|