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.
19 #include FORMS_H_LOCATION
22 #pragma implementation
26 #include "math_macro.h"
28 #include "math_iter.h"
29 #include "math_inset.h"
30 #include "math_accentinset.h"
31 #include "math_deliminset.h"
32 #include "math_fracinset.h"
33 #include "math_rowst.h"
34 #include "support/lstrings.h"
36 #include "mathed/support.h"
37 #include "math_macrotemplate.h"
38 #include "macro_support.h"
43 ostream & operator<<(ostream & o, MathedTextCodes mtc)
49 //extern int mathed_string_width(short type, int style, string const & s);
50 //extern int mathed_string_height(short, int, string const &, int &, int &);
52 MathMacro::MathMacro(MathMacroTemplate * t):
53 MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate(t)
55 nargs = tmplate->getNoArgs();
56 tcode = tmplate->getTCode();
58 for (int i = 0; i < nargs; ++i) {
62 SetName(tmplate->GetName());
66 MathMacro::MathMacro(MathMacro * m):
67 MathParInset(LM_ST_TEXT, m->GetName(), LM_OT_MACRO)
70 nargs = tmplate->getNoArgs();
71 tcode = tmplate->getTCode();
74 SetName(tmplate->GetName());
75 for (int i = 0; i < tmplate->nargs; ++i) {
77 MathedIter it(m->GetData());
78 args_[i].row = m->args_[i].row;
79 args_[i].array = it.Copy();
83 MathMacro::~MathMacro()
85 for (idx = 0; idx < nargs; ++idx) {
86 MathedIter it(args_[idx].array);
88 delete args_[idx].row;
93 MathedInset * MathMacro::Clone()
95 return new MathMacro(this);
99 void MathMacro::Metrics()
102 tmplate->update(this);
103 tmplate->SetStyle(size);
105 width = tmplate->Width();
106 ascent = tmplate->Ascent();
107 descent = tmplate->Descent();
111 void MathMacro::draw(Painter & pain, int x, int y)
115 tmplate->update(this);
116 tmplate->SetStyle(size);
117 tmplate->draw(pain, x, y);
118 for (int i = 0; i < nargs; ++i) {
119 tmplate->GetMacroXY(i, args_[i].x, args_[i].y);
124 bool MathMacro::setArgumentIdx(int i)
126 if (i >= 0 && i < nargs) {
134 int MathMacro::getArgumentIdx() const
140 int MathMacro::getMaxArgumentIdx() const
146 MathedArray * MathMacro::GetData()
148 return args_[idx].array;
152 int MathMacro::GetColumns() const
154 return tmplate->getMacroPar(idx)->GetColumns();
158 void MathMacro::GetXY(int & x, int & y) const
160 x = args_[idx].x; y = args_[idx].y;
164 bool MathMacro::Permit(short f) const
167 tmplate->getMacroPar(idx)->Permit(f) : MathParInset::Permit(f);
171 void MathMacro::SetFocus(int x, int y)
173 tmplate->update(this);
174 tmplate->SetMacroFocus(idx, x, y);
178 void MathMacro::SetData(MathedArray * a)
180 args_[idx].array = a;
186 MathedRowSt * MathMacro::getRowSt() const
188 return args_[idx].row;
192 MathedTextCodes MathMacro::getTCode() const
198 void MathMacro::Write(ostream & os, bool fragile)
200 if (tmplate->flags & MMF_Exp) {
201 lyxerr[Debug::MATHED] << "Expand " << tmplate->flags
202 << ' ' << MMF_Exp << endl;
203 tmplate->update(this);
204 tmplate->Write(os, fragile);
206 if (tmplate->flags & MMF_Env) {
219 if (!(tmplate->flags & MMF_Env) && nargs > 0)
222 for (int i = 0; i < nargs; ++i) {
223 array = args_[i].array;
224 MathParInset::Write(os, fragile);
228 if (tmplate->flags & MMF_Env) {