4 * Purpose: Implementation of macro class for mathed
5 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6 * Created: November 1996
7 * Description: WYSIWYG math macros
11 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.2, Mathed & Lyx project.
15 * This code is under the GNU General Public Licence version 2 or later.
21 #pragma implementation
24 #include "math_macro.h"
26 #include "math_iter.h"
27 #include "math_inset.h"
28 #include "math_accentinset.h"
29 #include "math_deliminset.h"
30 #include "math_fracinset.h"
31 #include "math_rowst.h"
32 #include "support/lstrings.h"
34 #include "mathed/support.h"
35 #include "math_macrotemplate.h"
36 #include "macro_support.h"
41 ostream & operator<<(ostream & o, MathedTextCodes mtc)
47 MathMacro::MathMacro(boost::shared_ptr<MathMacroTemplate> const & t)
48 : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO),
51 nargs_ = tmplate_->getNoArgs();
52 tcode_ = tmplate_->getTCode();
55 SetName(tmplate_->GetName());
59 MathedInset * MathMacro::Clone()
61 return new MathMacro(*this);
65 void MathMacro::Metrics()
68 tmplate_->update(this);
69 tmplate_->SetStyle(size());
71 width = tmplate_->Width();
72 ascent = tmplate_->Ascent();
73 descent = tmplate_->Descent();
77 void MathMacro::draw(Painter & pain, int x, int y)
82 tmplate_->SetStyle(size());
83 tmplate_->draw(pain, x, y);
87 bool MathMacro::setArgumentIdx(int i)
89 if (i >= 0 && i < nargs_) {
97 int MathMacro::getArgumentIdx() const
103 int MathMacro::getMaxArgumentIdx() const
109 MathedArray & MathMacro::GetData()
111 return args_[idx_].array;
115 MathedArray const & MathMacro::GetData() const
117 return args_[idx_].array;
121 int MathMacro::GetColumns() const
123 return tmplate_->getMacroPar(idx_)->GetColumns();
127 void MathMacro::GetXY(int & x, int & y) const
133 const_cast<MathMacro*>(this)->Metrics();
134 tmplate_->GetMacroXY(idx_, x, y);
139 bool MathMacro::Permit(short f) const
141 return (nargs_ > 0) ?
142 tmplate_->getMacroPar(idx_)->Permit(f) :
143 MathParInset::Permit(f);
147 void MathMacro::SetFocus(int x, int y)
150 tmplate_->SetMacroFocus(idx_, x, y);
154 void MathMacro::setData(MathedArray const & a)
156 args_[idx_].array = a;
160 MathedRowSt * MathMacro::getRowSt() const
162 return args_[idx_].row;
166 MathedTextCodes MathMacro::getTCode() const
172 void MathMacro::Write(ostream & os, bool fragile)
179 for (int i = 0; i < nargs_; ++i) {
180 array = args_[i].array;
181 MathParInset::Write(os, fragile);