7 #include "math_macrotemplate.h"
8 #include "math_macro.h"
9 #include "macro_support.h"
10 #include "support/LOstream.h"
15 MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
16 MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
17 flags_(flg), nargs_(na)
20 tcode_ = LM_TC_ACTIVE_INSET;
22 for (int i = 0; i < nargs_; ++i) {
23 args_[i].setNumber(i + 1);
27 // Here is nargs != args_.size()
33 void MathMacroTemplate::setTCode(MathedTextCodes t)
39 MathedTextCodes MathMacroTemplate::getTCode() const
45 int MathMacroTemplate::getNoArgs() const
51 void MathMacroTemplate::setEditMode(bool ed)
55 for (int i = 0; i < nargs_; ++i) {
56 args_[i].setExpand(false);
60 for (int i = 0; i < nargs_; ++i) {
61 args_[i].setExpand(true);
67 void MathMacroTemplate::draw(Painter & pain, int x, int y)
71 bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
72 if (flags_ & MMF_Edit) {
73 for (int i = 0; i < nargs_; ++i) {
74 args_[i].setExpand(false);
79 for (int i = 0; i < nargs_; ++i) {
80 args_[i].setExpand(true);
85 MathParInset::draw(pain, x, y);
89 for (int i = 0; i < nargs_; ++i) {
90 args_[i].setExpand(expnd);
95 void MathMacroTemplate::Metrics()
97 bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
99 if (flags_ & MMF_Edit) {
100 for (int i = 0; i < nargs_; ++i) {
101 args_[i].setExpand(false);
104 for (int i = 0; i < nargs_; ++i) {
105 args_[i].setExpand(true);
108 MathParInset::Metrics();
110 for (int i = 0; i < nargs_; ++i) {
111 args_[i].setExpand(expnd);
116 void MathMacroTemplate::update(MathMacro * macro)
118 int idx = (macro) ? macro->getArgumentIdx() : 0;
119 for (int i = 0; i < nargs_; ++i) {
121 macro->setArgumentIdx(i);
122 args_[i].setData(macro->GetData());
123 MathedRowSt * row = macro->getRowSt();
124 args_[i].setRowSt(row);
128 macro->setArgumentIdx(idx);
132 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
134 os << "\n\\newcommand{\\" << name << "}";
137 os << "[" << nargs_ << "]";
141 for (int i = 0; i < nargs_; ++i) {
142 args_[i].setExpand(false);
149 void MathMacroTemplate::setArgument(MathedArray * a, int i)
151 args_[i].setData(*a);
155 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
157 args_[i].GetXY(x, y);
161 MathParInset * MathMacroTemplate::getMacroPar(int i) const
163 if (i >= 0 && i < nargs_)
164 return const_cast<MathParInset *>
165 (static_cast<MathParInset const *>(&args_[i]));
171 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
173 for (int i = 0; i < nargs_; ++i) {
174 if (args_[i].Inside(x, y)) {