1999-09-27 18:44:28 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/*
|
|
|
|
* File: math_macro.C
|
|
|
|
* Purpose: Implementation of macro class for mathed
|
|
|
|
* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
|
|
|
|
* Created: November 1996
|
|
|
|
* Description: WYSIWYG math macros
|
|
|
|
*
|
|
|
|
* Dependencies: Mathed
|
|
|
|
*
|
2000-03-09 03:36:48 +00:00
|
|
|
* Copyright: 1996, 1997 Alejandro Aguilar Sierra
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
|
|
|
* Version: 0.2, Mathed & Lyx project.
|
|
|
|
*
|
|
|
|
* This code is under the GNU General Public Licence version 2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
2001-02-13 13:28:32 +00:00
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "math_macro.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "array.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_iter.h"
|
|
|
|
#include "math_inset.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
#include "math_accentinset.h"
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_rowst.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/lstrings.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "mathed/support.h"
|
|
|
|
#include "math_macrotemplate.h"
|
|
|
|
#include "macro_support.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
ostream & operator<<(ostream & o, MathedTextCodes mtc)
|
|
|
|
{
|
|
|
|
return o << int(mtc);
|
|
|
|
}
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
MathMacro::MathMacro(boost::shared_ptr<MathMacroTemplate> const & t)
|
|
|
|
: MathParInset(LM_ST_TEXT, "", LM_OT_MACRO),
|
|
|
|
tmplate_(t)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-03-05 10:18:36 +00:00
|
|
|
//nargs_ = tmplate_->getNoArgs();
|
|
|
|
int const n = tmplate_->getNoArgs();
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
tcode_ = tmplate_->getTCode();
|
2001-03-05 10:18:36 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
args_.push_back(MathMacroArgument(t->args_[i]));
|
|
|
|
}
|
|
|
|
//for (int i = 0; i < nargs_; ++i) {
|
|
|
|
// MathMacroArgument * ma = new MathMacroArgument(*t->args_[i]);
|
|
|
|
// args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
|
|
|
|
//}
|
|
|
|
|
2001-02-15 12:22:01 +00:00
|
|
|
idx_ = 0;
|
|
|
|
SetName(tmplate_->GetName());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-11-25 13:15:52 +00:00
|
|
|
MathedInset * MathMacro::Clone()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-28 11:56:36 +00:00
|
|
|
return new MathMacro(*this);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacro::Metrics()
|
|
|
|
{
|
2001-04-17 14:20:21 +00:00
|
|
|
for (unsigned int i = 0; i < args_.size(); ++i)
|
|
|
|
tmplate_->args_[i] = getArg(i);
|
2001-02-15 12:22:01 +00:00
|
|
|
tmplate_->SetStyle(size());
|
|
|
|
tmplate_->Metrics();
|
|
|
|
width = tmplate_->Width();
|
|
|
|
ascent = tmplate_->Ascent();
|
|
|
|
descent = tmplate_->Descent();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
void MathMacro::draw(Painter & pain, int x, int y)
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
xo(x);
|
|
|
|
yo(y);
|
2001-02-13 17:08:51 +00:00
|
|
|
Metrics();
|
2001-02-15 12:22:01 +00:00
|
|
|
tmplate_->SetStyle(size());
|
|
|
|
tmplate_->draw(pain, x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
bool MathMacro::setArgumentIdx(int i)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-04-17 14:20:21 +00:00
|
|
|
if (i >= 0 && 0 < (args_.size() - i)) {
|
2001-02-15 12:22:01 +00:00
|
|
|
idx_ = i;
|
2001-02-13 17:08:51 +00:00
|
|
|
return true;
|
|
|
|
} else
|
|
|
|
return false;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
int MathMacro::getArgumentIdx() const
|
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
return idx_;
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
int MathMacro::getMaxArgumentIdx() const
|
|
|
|
{
|
2001-03-05 10:18:36 +00:00
|
|
|
return args_.size() - 1;
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray & MathMacro::GetData()
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-03-05 10:18:36 +00:00
|
|
|
return args_[idx_].GetData();
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-28 17:21:16 +00:00
|
|
|
MathedArray const & MathMacro::GetData() const
|
|
|
|
{
|
2001-03-05 10:18:36 +00:00
|
|
|
return args_[idx_].GetData();
|
2001-02-28 17:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
int MathMacro::GetColumns() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
return tmplate_->getMacroPar(idx_)->GetColumns();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
void MathMacro::GetXY(int & x, int & y) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
const_cast<MathMacro*>(this)->Metrics();
|
|
|
|
tmplate_->GetMacroXY(idx_, x, y);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
bool MathMacro::Permit(short f) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
2001-03-05 10:18:36 +00:00
|
|
|
return (args_.size() > 0) ?
|
2001-02-26 15:17:19 +00:00
|
|
|
tmplate_->getMacroPar(idx_)->Permit(f) :
|
|
|
|
MathParInset::Permit(f);
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
void MathMacro::SetFocus(int x, int y)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
Metrics();
|
2001-02-15 12:22:01 +00:00
|
|
|
tmplate_->SetMacroFocus(idx_, 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
|
|
|
void MathMacro::setData(MathedArray const & a)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-03-05 10:18:36 +00:00
|
|
|
args_[idx_].setData(a);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
MathedTextCodes MathMacro::getTCode() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-02-15 12:22:01 +00:00
|
|
|
return tcode_;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
void MathMacro::Write(ostream & os, bool fragile)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
os << '\\' << name;
|
|
|
|
|
2001-03-05 10:18:36 +00:00
|
|
|
int const n = args_.size();
|
|
|
|
|
|
|
|
if (n > 0) {
|
2001-03-01 14:07:43 +00:00
|
|
|
os << '{';
|
|
|
|
|
2001-03-05 10:18:36 +00:00
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
array = args_[i].GetData();
|
2001-02-13 17:08:51 +00:00
|
|
|
MathParInset::Write(os, fragile);
|
2001-03-05 10:18:36 +00:00
|
|
|
if (i < n - 1)
|
2001-02-13 17:08:51 +00:00
|
|
|
os << "}{";
|
2001-02-12 15:55:40 +00:00
|
|
|
}
|
2001-03-01 14:07:43 +00:00
|
|
|
os << '}';
|
|
|
|
} else
|
|
|
|
os << ' ';
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2001-03-05 10:18:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
MathMacroArgument const & MathMacro::getArg(int i) const
|
|
|
|
{
|
|
|
|
return args_[i];
|
|
|
|
}
|
|
|
|
//boost::shared_ptr<MathMacroArgument> MathMacro::getArg(int i)
|
|
|
|
//{
|
|
|
|
// return args_[i];
|
|
|
|
//}
|
|
|
|
|