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
|
|
|
|
*
|
|
|
|
* Copyright: (c) 1999 Alejandro Aguilar Sierra
|
|
|
|
*
|
|
|
|
* 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_iter.h"
|
|
|
|
#include "math_root.h"
|
|
|
|
|
|
|
|
MathRootInset::MathRootInset(short st): MathSqrtInset(st)
|
|
|
|
{
|
|
|
|
idx = 1;
|
|
|
|
uroot = new MathParInset(LM_ST_TEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathRootInset::~MathRootInset()
|
|
|
|
{
|
|
|
|
delete uroot;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * MathRootInset::Clone()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-23 14:39:02 +00:00
|
|
|
MathRootInset * p = new MathRootInset(GetStyle());
|
1999-09-27 18:44:28 +00:00
|
|
|
MathedIter it(array), itr(uroot->GetData());
|
|
|
|
p->SetData(it.Copy());
|
|
|
|
p->setArgumentIdx(0);
|
|
|
|
p->SetData(itr.Copy());
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathRootInset::SetData(LyxArrayBase * d)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (idx == 1)
|
1999-09-27 18:44:28 +00:00
|
|
|
MathParInset::SetData(d);
|
|
|
|
else {
|
|
|
|
uroot->SetData(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathRootInset::setArgumentIdx(int i)
|
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (i == 0 || i == 1) {
|
1999-09-27 18:44:28 +00:00
|
|
|
idx = i;
|
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathRootInset::GetXY(int & x, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (idx == 1)
|
1999-09-27 18:44:28 +00:00
|
|
|
MathParInset::GetXY(x, y);
|
|
|
|
else
|
|
|
|
uroot->GetXY(x, y);
|
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
|
|
LyxArrayBase * MathRootInset::GetData()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-11-15 11:06:41 +00:00
|
|
|
if (idx == 1)
|
1999-09-27 18:44:28 +00:00
|
|
|
return array;
|
|
|
|
else
|
|
|
|
return uroot->GetData();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathRootInset::Inside(int x, int y)
|
|
|
|
{
|
|
|
|
return (uroot->Inside(x, y) || MathSqrtInset::Inside(x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::Metrics()
|
|
|
|
{
|
|
|
|
int idxp = idx;
|
|
|
|
|
|
|
|
idx = 1;
|
|
|
|
MathSqrtInset::Metrics();
|
|
|
|
uroot->Metrics();
|
|
|
|
wroot = uroot->Width();
|
|
|
|
dh = Height()/2;
|
|
|
|
width += wroot;
|
|
|
|
// if (uroot->Ascent() > dh)
|
|
|
|
if (uroot->Height() > dh)
|
|
|
|
ascent += uroot->Height() - dh;
|
|
|
|
dh -= descent - uroot->Descent();
|
|
|
|
idx = idxp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::Draw(int x, int y)
|
|
|
|
{
|
|
|
|
int idxp = idx;
|
|
|
|
|
|
|
|
idx = 1;
|
|
|
|
uroot->Draw(x, y - dh);
|
|
|
|
MathSqrtInset::Draw(x+wroot, y);
|
|
|
|
XFlush(fl_display);
|
|
|
|
idx = idxp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::SetStyle(short st)
|
|
|
|
{
|
|
|
|
MathSqrtInset::SetStyle(st);
|
|
|
|
|
|
|
|
uroot->SetStyle((size<LM_ST_SCRIPTSCRIPT) ? size+1: size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathRootInset::SetFocus(int x, int)
|
|
|
|
{
|
|
|
|
idx = (x > xo + wroot) ? 1: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
void MathRootInset::Write(ostream & os)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string output;
|
1999-12-07 00:44:53 +00:00
|
|
|
MathRootInset::Write(output);
|
|
|
|
os << output;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
void MathRootInset::Write(string &outf)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
outf += '\\';
|
|
|
|
outf += name;
|
|
|
|
outf += '[';
|
|
|
|
uroot->Write(outf);
|
|
|
|
outf += "]{";
|
|
|
|
MathParInset::Write(outf);
|
|
|
|
outf += '}';
|
|
|
|
}
|