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);
64 for (int i = 0; i < nargs_; ++i) {
65 args_[i].setExpand(true);
71 void MathMacroTemplate::draw(Painter & pain, int x, int y)
75 bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
76 if (flags_ & MMF_Edit) {
77 for (int i = 0; i < nargs_; ++i) {
78 args_[i].setExpand(false);
83 for (int i = 0; i < nargs_; ++i) {
84 args_[i].setExpand(true);
89 MathParInset::draw(pain, x, y);
93 for (int i = 0; i < nargs_; ++i) {
94 args_[i].setExpand(expnd);
99 void MathMacroTemplate::Metrics()
101 bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
103 if (flags_ & MMF_Edit) {
104 for (int i = 0; i < nargs_; ++i) {
105 args_[i].setExpand(false);
108 for (int i = 0; i < nargs_; ++i) {
109 args_[i].setExpand(true);
112 MathParInset::Metrics();
114 for (int i = 0; i < nargs_; ++i) {
115 args_[i].setExpand(expnd);
120 void MathMacroTemplate::update(MathMacro * macro)
122 int idx = (macro) ? macro->getArgumentIdx() : 0;
123 for (int i = 0; i < nargs_; ++i) {
125 macro->setArgumentIdx(i);
126 args_[i].setData(macro->GetData());
127 MathedRowSt * row = macro->getRowSt();
128 args_[i].setRowSt(row);
132 macro->setArgumentIdx(idx);
136 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
138 os << "\n\\newcommand{\\" << name << "}";
141 os << "[" << nargs_ << "]";
145 for (int i = 0; i < nargs_; ++i) {
146 args_[i].setExpand(false);
153 void MathMacroTemplate::setArgument(MathedArray * a, int i)
155 args_[i].setData(*a);
159 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
161 args_[i].GetXY(x, y);
165 MathParInset * MathMacroTemplate::getMacroPar(int i) const
167 if (i >= 0 && i < nargs_)
168 return const_cast<MathParInset *>
169 (static_cast<MathParInset const *>(&args_[i]));
175 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
177 for (int i = 0; i < nargs_; ++i) {
178 if (args_[i].Inside(x, y)) {