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 //MathMacroTemplate::~MathMacroTemplate()
37 void MathMacroTemplate::setTCode(MathedTextCodes t)
43 MathedTextCodes MathMacroTemplate::getTCode() const
49 int MathMacroTemplate::getNoArgs() const
55 void MathMacroTemplate::setEditMode(bool ed)
59 for (int i = 0; i < nargs_; ++i) {
60 args_[i].setExpand(false);
65 for (int i = 0; i < nargs_; ++i) {
66 args_[i].setExpand(true);
72 void MathMacroTemplate::draw(Painter & pain, int x, int y)
76 bool expnd = (nargs_ > 0) ? args_[0].getExpand(): false;
77 if (flags_ & MMF_Edit) {
78 for (int i = 0; i < nargs_; ++i) {
79 args_[i].setExpand(false);
84 for (int i = 0; i < nargs_; ++i) {
85 args_[i].setExpand(true);
90 MathParInset::draw(pain, x, y);
94 for (int i = 0; i < nargs_; ++i) {
95 args_[i].setExpand(expnd);
100 void MathMacroTemplate::Metrics()
102 bool expnd = (nargs_ > 0) ? args_[0].getExpand(): false;
104 if (flags_ & MMF_Edit) {
105 for (int i = 0; i < nargs_; ++i) {
106 args_[i].setExpand(false);
109 for (int i = 0; i < nargs_; ++i) {
110 args_[i].setExpand(true);
113 MathParInset::Metrics();
115 for (int i = 0; i < nargs_; ++i) {
116 args_[i].setExpand(expnd);
121 void MathMacroTemplate::update(MathMacro * macro)
123 int idx = (macro) ? macro->getArgumentIdx() : 0;
124 for (int i = 0; i < nargs_; ++i) {
126 macro->setArgumentIdx(i);
127 args_[i].setData(macro->GetData());
128 MathedRowSt * row = macro->getRowSt();
129 args_[i].setRowSt(row);
133 macro->setArgumentIdx(idx);
137 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
139 os << "\n\\newcommand{\\" << name << "}";
142 os << "[" << nargs_ << "]";
146 for (int i = 0; i < nargs_; ++i) {
147 args_[i].setExpand(false);
154 void MathMacroTemplate::setArgument(MathedArray * a, int i)
156 args_[i].setData(*a);
160 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
162 args_[i].GetXY(x, y);
166 MathParInset * MathMacroTemplate::getMacroPar(int i) const
168 if (i >= 0 && i < nargs_)
169 return const_cast<MathParInset *>
170 (static_cast<MathParInset const *>(&args_[i]));
176 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
178 for (int i = 0; i < nargs_; ++i) {
179 if (args_[i].Inside(x, y)) {