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) {
71 //m->setArgumentIdx(i);
72 args_[i].row = m->args_[i].row;
73 //args_[i].array = m->GetData();
74 args_[i].array = m->args_[i].array;
79 MathedInset * MathMacro::Clone()
81 return new MathMacro(this);
85 void MathMacro::Metrics()
88 tmplate_->update(this);
89 tmplate_->SetStyle(size());
91 width = tmplate_->Width();
92 ascent = tmplate_->Ascent();
93 descent = tmplate_->Descent();
97 void MathMacro::draw(Painter & pain, int x, int y)
102 tmplate_->update(this);
103 tmplate_->SetStyle(size());
104 tmplate_->draw(pain, x, y);
105 for (int i = 0; i < nargs_; ++i) {
106 tmplate_->GetMacroXY(i, args_[i].x, args_[i].y);
111 bool MathMacro::setArgumentIdx(int i)
113 if (i >= 0 && i < nargs_) {
121 int MathMacro::getArgumentIdx() const
127 int MathMacro::getMaxArgumentIdx() const
133 MathedArray & MathMacro::GetData()
135 return args_[idx_].array;
139 int MathMacro::GetColumns() const
141 return tmplate_->getMacroPar(idx_)->GetColumns();
145 void MathMacro::GetXY(int & x, int & y) const
152 bool MathMacro::Permit(short f) const
154 return (nargs_ > 0) ?
155 tmplate_->getMacroPar(idx_)->Permit(f) :
156 MathParInset::Permit(f);
160 void MathMacro::SetFocus(int x, int y)
162 tmplate_->update(this);
163 tmplate_->SetMacroFocus(idx_, x, y);
167 void MathMacro::setData(MathedArray const & a)
169 args_[idx_].array = a;
175 MathedRowSt * MathMacro::getRowSt() const
177 return args_[idx_].row;
181 MathedTextCodes MathMacro::getTCode() const
187 void MathMacro::Write(ostream & os, bool fragile)
189 if (tmplate_->flags() & MMF_Exp) {
190 lyxerr[Debug::MATHED] << "Expand " << tmplate_->flags()
191 << ' ' << MMF_Exp << endl;
192 tmplate_->update(this);
193 tmplate_->Write(os, fragile);
195 if (tmplate_->flags() & MMF_Env) {
208 if (!(tmplate_->flags() & MMF_Env) && nargs_ > 0)
211 for (int i = 0; i < nargs_; ++i) {
212 array = args_[i].array;
213 MathParInset::Write(os, fragile);
217 if (tmplate_->flags() & MMF_Env) {