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 args_[i].row = m->args_[i].row;
73 args_[i].array = *(m->GetData());
78 MathMacro::~MathMacro()
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 int MathMacro::GetColumns() const
145 return tmplate_->getMacroPar(idx_)->GetColumns();
149 void MathMacro::GetXY(int & x, int & y) const
156 bool MathMacro::Permit(short f) const
158 return (nargs_ > 0) ?
159 tmplate_->getMacroPar(idx_)->Permit(f) : MathParInset::Permit(f);
163 void MathMacro::SetFocus(int x, int y)
165 tmplate_->update(this);
166 tmplate_->SetMacroFocus(idx_, x, y);
170 void MathMacro::setData(MathedArray * a)
172 args_[idx_].array = *a;
178 MathedRowSt * MathMacro::getRowSt() const
180 return args_[idx_].row;
184 MathedTextCodes MathMacro::getTCode() const
190 void MathMacro::Write(ostream & os, bool fragile)
192 if (tmplate_->flags() & MMF_Exp) {
193 lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
194 << ' ' << MMF_Exp << endl;
195 tmplate_->update(this);
196 tmplate_->Write(os, fragile);
198 if (tmplate_->flags() & MMF_Env) {
211 if (!(tmplate_->flags() & MMF_Env) && nargs_ > 0)
214 for (int i = 0; i < nargs_; ++i) {
215 array = args_[i].array;
216 MathParInset::Write(os, fragile);
220 if (tmplate_->flags() & MMF_Env) {