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 MathMacro::MathMacro(MathMacro const & m)
60 : MathParInset(LM_ST_TEXT, m.GetName(), LM_OT_MACRO),
61 tmplate_(m.tmplate_), idx_(0)
63 nargs_ = tmplate_->getNoArgs();
64 tcode_ = tmplate_->getTCode();
65 SetName(tmplate_->GetName());
67 std::vector<MacroArgumentBase>::const_iterator cit = m.args_.begin();
68 std::vector<MacroArgumentBase>::const_iterator end = m.args_.end();
70 //args_.resize(nargs_);
71 //for (int i = 0; i < tmplate_->getNoArgs(); ++i) {
72 // args_[i].row = m->args_[i].row;
73 // args_[i].array = m->args_[i].array;
75 for (; cit != end; ++cit) {
76 args_.push_back(*cit);
81 MathedInset * MathMacro::Clone()
83 return new MathMacro(*this);
87 void MathMacro::Metrics()
90 tmplate_->update(this);
91 tmplate_->SetStyle(size());
93 width = tmplate_->Width();
94 ascent = tmplate_->Ascent();
95 descent = tmplate_->Descent();
99 void MathMacro::draw(Painter & pain, int x, int y)
104 tmplate_->SetStyle(size());
105 tmplate_->draw(pain, x, y);
109 bool MathMacro::setArgumentIdx(int i)
111 if (i >= 0 && i < nargs_) {
119 int MathMacro::getArgumentIdx() const
125 int MathMacro::getMaxArgumentIdx() const
131 MathedArray & MathMacro::GetData()
133 return args_[idx_].array;
137 MathedArray const & MathMacro::GetData() const
139 return args_[idx_].array;
143 int MathMacro::GetColumns() const
145 return tmplate_->getMacroPar(idx_)->GetColumns();
149 void MathMacro::GetXY(int & x, int & y) const
155 const_cast<MathMacro*>(this)->Metrics();
156 tmplate_->GetMacroXY(idx_, x, y);
161 bool MathMacro::Permit(short f) const
163 return (nargs_ > 0) ?
164 tmplate_->getMacroPar(idx_)->Permit(f) :
165 MathParInset::Permit(f);
169 void MathMacro::SetFocus(int x, int y)
172 tmplate_->SetMacroFocus(idx_, x, y);
176 void MathMacro::setData(MathedArray const & a)
178 args_[idx_].array = a;
182 MathedRowSt * MathMacro::getRowSt() const
184 return args_[idx_].row;
188 MathedTextCodes MathMacro::getTCode() const
194 void MathMacro::Write(ostream & os, bool fragile)
201 for (int i = 0; i < nargs_; ++i) {
202 array = args_[i].array;
203 MathParInset::Write(os, fragile);