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 * m):
62 MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO)
64 tmplate_ = m->tmplate_;
65 nargs_ = tmplate_->getNoArgs();
66 tcode_ = tmplate_->getTCode();
69 SetName(tmplate_->GetName());
70 for (int i = 0; i < tmplate_->getNoArgs(); ++i) {
72 MathedIter it(m->GetData());
73 args_[i].row = m->args_[i].row;
74 args_[i].array = it.Copy();
79 MathMacro::~MathMacro()
81 for (idx_ = 0; idx_ < nargs_; ++idx_) {
82 MathedIter it(args_[idx_].array);
84 delete args_[idx_].row;
89 MathedInset * MathMacro::Clone()
91 return new MathMacro(this);
95 void MathMacro::Metrics()
98 tmplate_->update(this);
99 tmplate_->SetStyle(size());
101 width = tmplate_->Width();
102 ascent = tmplate_->Ascent();
103 descent = tmplate_->Descent();
107 void MathMacro::draw(Painter & pain, int x, int y)
112 tmplate_->update(this);
113 tmplate_->SetStyle(size());
114 tmplate_->draw(pain, x, y);
115 for (int i = 0; i < nargs_; ++i) {
116 tmplate_->GetMacroXY(i, args_[i].x, args_[i].y);
121 bool MathMacro::setArgumentIdx(int i)
123 if (i >= 0 && i < nargs_) {
131 int MathMacro::getArgumentIdx() const
137 int MathMacro::getMaxArgumentIdx() const
143 MathedArray * MathMacro::GetData()
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) : MathParInset::Permit(f);
169 void MathMacro::SetFocus(int x, int y)
171 tmplate_->update(this);
172 tmplate_->SetMacroFocus(idx_, x, y);
176 void MathMacro::SetData(MathedArray * a)
178 args_[idx_].array = a;
184 MathedRowSt * MathMacro::getRowSt() const
186 return args_[idx_].row;
190 MathedTextCodes MathMacro::getTCode() const
196 void MathMacro::Write(ostream & os, bool fragile)
198 if (tmplate_->flags() & MMF_Exp) {
199 lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
200 << ' ' << MMF_Exp << endl;
201 tmplate_->update(this);
202 tmplate_->Write(os, fragile);
204 if (tmplate_->flags() & MMF_Env) {
217 if (!(tmplate_->flags() & MMF_Env) && nargs_ > 0)
220 for (int i = 0; i < nargs_; ++i) {
221 array = args_[i].array;
222 MathParInset::Write(os, fragile);
226 if (tmplate_->flags() & MMF_Env) {