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 MathedInset * MathMacro::Clone()
80 return new MathMacro(this);
84 void MathMacro::Metrics()
87 tmplate_->update(this);
88 tmplate_->SetStyle(size());
90 width = tmplate_->Width();
91 ascent = tmplate_->Ascent();
92 descent = tmplate_->Descent();
96 void MathMacro::draw(Painter & pain, int x, int y)
101 tmplate_->update(this);
102 tmplate_->SetStyle(size());
103 tmplate_->draw(pain, x, y);
104 for (int i = 0; i < nargs_; ++i) {
105 tmplate_->GetMacroXY(i, args_[i].x, args_[i].y);
110 bool MathMacro::setArgumentIdx(int i)
112 if (i >= 0 && i < nargs_) {
120 int MathMacro::getArgumentIdx() const
126 int MathMacro::getMaxArgumentIdx() const
132 MathedArray & MathMacro::GetData()
134 return args_[idx_].array;
138 int MathMacro::GetColumns() const
140 return tmplate_->getMacroPar(idx_)->GetColumns();
144 void MathMacro::GetXY(int & x, int & y) const
151 bool MathMacro::Permit(short f) const
153 return (nargs_ > 0) ?
154 tmplate_->getMacroPar(idx_)->Permit(f) : MathParInset::Permit(f);
158 void MathMacro::SetFocus(int x, int y)
160 tmplate_->update(this);
161 tmplate_->SetMacroFocus(idx_, x, y);
165 void MathMacro::setData(MathedArray const & a)
167 args_[idx_].array = a;
173 MathedRowSt * MathMacro::getRowSt() const
175 return args_[idx_].row;
179 MathedTextCodes MathMacro::getTCode() const
185 void MathMacro::Write(ostream & os, bool fragile)
187 if (tmplate_->flags() & MMF_Exp) {
188 lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
189 << ' ' << MMF_Exp << endl;
190 tmplate_->update(this);
191 tmplate_->Write(os, fragile);
193 if (tmplate_->flags() & MMF_Env) {
206 if (!(tmplate_->flags() & MMF_Env) && nargs_ > 0)
209 for (int i = 0; i < nargs_; ++i) {
210 array = args_[i].array;
211 MathParInset::Write(os, fragile);
215 if (tmplate_->flags() & MMF_Env) {