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(MathMacroTemplate * t)
48 : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate_(t)
50 nargs_ = tmplate_->getNoArgs();
51 tcode_ = tmplate_->getTCode();
53 for (int i = 0; i < nargs_; ++i) {
57 SetName(tmplate_->GetName());
61 MathMacro::MathMacro(MathMacro const & m)
62 : MathParInset(LM_ST_TEXT, m.GetName(), LM_OT_MACRO),
63 tmplate_(m.tmplate_), idx_(0)
65 nargs_ = tmplate_->getNoArgs();
66 tcode_ = tmplate_->getTCode();
67 SetName(tmplate_->GetName());
69 std::vector<MacroArgumentBase>::const_iterator cit = m.args_.begin();
70 std::vector<MacroArgumentBase>::const_iterator end = m.args_.end();
72 //args_.resize(nargs_);
73 //for (int i = 0; i < tmplate_->getNoArgs(); ++i) {
74 // args_[i].row = m->args_[i].row;
75 // args_[i].array = m->args_[i].array;
77 for (; cit != end; ++cit) {
78 args_.push_back(*cit);
83 MathedInset * MathMacro::Clone()
85 return new MathMacro(*this);
89 void MathMacro::Metrics()
92 tmplate_->update(this);
93 tmplate_->SetStyle(size());
95 width = tmplate_->Width();
96 ascent = tmplate_->Ascent();
97 descent = tmplate_->Descent();
101 void MathMacro::draw(Painter & pain, int x, int y)
106 tmplate_->update(this);
107 tmplate_->SetStyle(size());
108 tmplate_->draw(pain, x, y);
109 for (int i = 0; i < nargs_; ++i) {
110 tmplate_->GetMacroXY(i, args_[i].x, args_[i].y);
115 bool MathMacro::setArgumentIdx(int i)
117 if (i >= 0 && i < nargs_) {
125 int MathMacro::getArgumentIdx() const
131 int MathMacro::getMaxArgumentIdx() const
137 MathedArray & MathMacro::GetData()
139 return args_[idx_].array;
143 MathedArray const & MathMacro::GetData() const
145 return args_[idx_].array;
149 int MathMacro::GetColumns() const
151 return tmplate_->getMacroPar(idx_)->GetColumns();
155 void MathMacro::GetXY(int & x, int & y) const
162 bool MathMacro::Permit(short f) const
164 return (nargs_ > 0) ?
165 tmplate_->getMacroPar(idx_)->Permit(f) :
166 MathParInset::Permit(f);
170 void MathMacro::SetFocus(int x, int y)
172 tmplate_->update(this);
173 tmplate_->SetMacroFocus(idx_, x, y);
177 void MathMacro::setData(MathedArray const & a)
179 args_[idx_].array = a;
185 MathedRowSt * MathMacro::getRowSt() const
187 return args_[idx_].row;
191 MathedTextCodes MathMacro::getTCode() const
197 void MathMacro::Write(ostream & os, bool fragile)
199 if (tmplate_->flags() & MMF_Exp) {
200 lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
201 << ' ' << MMF_Exp << endl;
202 tmplate_->update(this);
203 tmplate_->Write(os, fragile);
205 if (tmplate_->flags() & MMF_Env) {
218 if (!(tmplate_->flags() & MMF_Env) && nargs_ > 0)
221 for (int i = 0; i < nargs_; ++i) {
222 array = args_[i].array;
223 MathParInset::Write(os, fragile);
227 if (tmplate_->flags() & MMF_Env) {