1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* File: math_inset.C
|
|
|
|
* Purpose: Implementation of insets for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: January 1996
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
* Dependencies: Xlib, XForms
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, 1997 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* Version: 0.8beta.
|
|
|
|
*
|
|
|
|
* You are free to use and modify this code under the terms of
|
|
|
|
* the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2001-02-13 13:28:32 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_inset.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "debug.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2001-02-28 11:56:36 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathInset::workwidth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-07-09 10:19:50 +00:00
|
|
|
MathInset::MathInset(int nargs, string const & name, MathInsetTypes ot)
|
2001-06-25 00:06:33 +00:00
|
|
|
: name_(name), objtype(ot), width_(0), ascent_(0), descent_(0),
|
2001-07-06 12:09:32 +00:00
|
|
|
size_(LM_ST_DISPLAY), cells_(nargs), xo_(0), yo_(0)
|
2001-02-28 11:56:36 +00:00
|
|
|
{}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathInset::ascent() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return ascent_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
int MathInset::descent() const
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return descent_;
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathInset::width() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return width_;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathInset::height() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return ascent_ + descent_;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
int MathInset::limits() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
void MathInset::limits(int)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
string const & MathInset::name() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return name_;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
MathInsetTypes MathInset::GetType() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return objtype;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
void MathInset::SetType(MathInsetTypes t)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
objtype = t;
|
|
|
|
}
|
2001-02-15 12:22:01 +00:00
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathInset::SetName(string const & n)
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
name_ = n;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathStyles MathInset::size() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return size_;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathInset::size(MathStyles s)
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
size_ = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream & operator<<(std::ostream & os, MathInset const & inset)
|
|
|
|
{
|
|
|
|
inset.Write(os, false);
|
|
|
|
return os;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathInset::xo() const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return xo_;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
int MathInset::yo() const
|
|
|
|
{
|
|
|
|
return yo_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathInset::xo(int x)
|
|
|
|
{
|
|
|
|
xo_ = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathInset::yo(int y)
|
|
|
|
{
|
|
|
|
yo_ = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int MathInset::nargs() const
|
|
|
|
{
|
|
|
|
return cells_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathXArray & MathInset::xcell(int i)
|
|
|
|
{
|
|
|
|
return cells_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
MathXArray const & MathInset::xcell(int i) const
|
|
|
|
{
|
|
|
|
return cells_[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathArray & MathInset::cell(int i)
|
|
|
|
{
|
|
|
|
return cells_[i].data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
MathArray const & MathInset::cell(int i) const
|
|
|
|
{
|
|
|
|
return cells_[i].data_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathInset::substitute(MathArray & array, MathMacro const & m) const
|
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
MathInset * p = clone();
|
2001-06-25 00:06:33 +00:00
|
|
|
for (int i = 0; i < nargs(); ++i)
|
|
|
|
p->cell(i).substitute(m);
|
|
|
|
array.push_back(p);
|
|
|
|
}
|
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
void MathInset::Metrics(MathStyles st, int, int)
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
|
|
|
size_ = st;
|
2001-06-25 00:06:33 +00:00
|
|
|
for (int i = 0; i < nargs(); ++i)
|
|
|
|
xcell(i).Metrics(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathInset::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
|
|
|
xo_ = x;
|
|
|
|
yo_ = y;
|
|
|
|
for (int i = 0; i < nargs(); ++i)
|
|
|
|
xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
bool MathInset::idxNext(int & idx, int & pos) const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (idx + 1 >= nargs())
|
|
|
|
return false;
|
|
|
|
++idx;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
bool MathInset::idxRight(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
return idxNext(idx, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathInset::idxPrev(int & idx, int & pos) const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (idx == 0)
|
|
|
|
return false;
|
|
|
|
--idx;
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-06 12:09:32 +00:00
|
|
|
bool MathInset::idxLeft(int & idx, int & pos) const
|
|
|
|
{
|
|
|
|
return idxPrev(idx, pos);
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathInset::idxUp(int &, int &) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathInset::idxDown(int &, int &) const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
return false;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathInset::idxFirst(int & i, int & pos) const
|
|
|
|
{
|
|
|
|
if (nargs() == 0)
|
|
|
|
return false;
|
|
|
|
i = 0;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MathInset::idxLast(int & i, int & pos) const
|
2001-02-15 12:22:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (nargs() == 0)
|
|
|
|
return false;
|
|
|
|
i = nargs() - 1;
|
|
|
|
pos = cell(i).size();
|
|
|
|
return true;
|
2001-02-15 12:22:01 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 19:57:01 +00:00
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
bool MathInset::idxHome(int & /* idx */, int & pos) const
|
2001-03-01 19:57:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (pos == 0)
|
|
|
|
return false;
|
|
|
|
pos = 0;
|
|
|
|
return true;
|
2001-03-01 19:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
bool MathInset::idxEnd(int & idx, int & pos) const
|
2001-03-01 19:57:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (pos == cell(idx).size())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
pos = cell(idx).size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
bool MathInset::idxFirstUp(int &, int &) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathInset::idxFirstDown(int &, int &) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-07-09 16:59:57 +00:00
|
|
|
void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
2001-07-09 16:59:57 +00:00
|
|
|
popit = false;
|
|
|
|
deleteit = false;
|
2001-06-27 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathInset::idxLastUp(int &, int &) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathInset::idxLastDown(int &, int &) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathInset::GetXY(int & x, int & y) const
|
|
|
|
{
|
|
|
|
x = xo();
|
|
|
|
y = yo();
|
2001-03-01 19:57:01 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
void MathInset::UserSetSize(MathStyles sz)
|
2001-03-01 19:57:01 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
if (sz >= 0) {
|
|
|
|
size_ = sz;
|
|
|
|
flag = flag & ~LMPF_FIXED_SIZE;
|
|
|
|
}
|
2001-03-01 19:57:01 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
void MathInset::WriteNormal(std::ostream & os) const
|
|
|
|
{
|
|
|
|
os << "[" << name_ << "] ";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathInset::dump() const
|
|
|
|
{
|
|
|
|
lyxerr << "---------------------------------------------\n";
|
|
|
|
Write(lyxerr, false);
|
|
|
|
lyxerr << "\n";
|
|
|
|
for (int i = 0; i < nargs(); ++i)
|
|
|
|
lyxerr << cell(i) << "\n";
|
|
|
|
lyxerr << "---------------------------------------------\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-13 11:32:22 +00:00
|
|
|
void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
if (nargs())
|
|
|
|
cells_.back().data_.push_back(ch, fcode);
|
|
|
|
else
|
|
|
|
lyxerr << "can't push without a cell\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathInset::push_back(MathInset * p)
|
|
|
|
{
|
|
|
|
if (nargs())
|
|
|
|
cells_.back().data_.push_back(p);
|
|
|
|
else
|
|
|
|
lyxerr << "can't push without a cell\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathInset::covers(int x, int y) const
|
|
|
|
{
|
|
|
|
return
|
|
|
|
x >= xo_ &&
|
|
|
|
x <= xo_ + width_ &&
|
|
|
|
y >= yo_ - ascent_ &&
|
|
|
|
y <= yo_ + descent_;
|
|
|
|
}
|