7 #include "math_macrotemplate.h"
8 #include "math_macro.h"
9 #include "macro_support.h"
10 #include "support/LOstream.h"
11 #include "support/LAssert.h"
16 MathMacroTemplate::MathMacroTemplate(string const & nm, int na):
17 MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
22 tcode_ = LM_TC_ACTIVE_INSET;
23 for (int i = 0; i < nargs_; ++i) {
24 args_.push_back(MathMacroArgument(i + 1));
28 // Here is nargs != args_.size()
34 void MathMacroTemplate::setTCode(MathedTextCodes t)
40 MathedTextCodes MathMacroTemplate::getTCode() const
46 int MathMacroTemplate::getNoArgs() const
52 void MathMacroTemplate::setEditMode(bool ed)
56 for (int i = 0; i < nargs_; ++i) {
57 args_[i].setExpand(false);
61 for (int i = 0; i < nargs_; ++i) {
62 args_[i].setExpand(true);
68 void MathMacroTemplate::draw(Painter & pain, int x, int y)
72 bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
74 for (int i = 0; i < nargs_; ++i) {
75 args_[i].setExpand(false);
80 for (int i = 0; i < nargs_; ++i) {
81 args_[i].setExpand(true);
86 MathParInset::draw(pain, x, y);
90 for (int i = 0; i < nargs_; ++i) {
91 args_[i].setExpand(expnd);
96 void MathMacroTemplate::Metrics()
98 bool const expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
101 for (int i = 0; i < nargs_; ++i) {
102 args_[i].setExpand(false);
105 for (int i = 0; i < nargs_; ++i) {
106 args_[i].setExpand(true);
109 MathParInset::Metrics();
111 for (int i = 0; i < nargs_; ++i) {
112 args_[i].setExpand(expnd);
117 void MathMacroTemplate::update(MathMacro * macro)
120 int const idx = macro->getArgumentIdx();
121 for (int i = 0; i < nargs_; ++i) {
122 macro->setArgumentIdx(i);
123 args_[i].setData(macro->GetData());
124 MathedRowSt * row = macro->getRowSt();
125 args_[i].setRowSt(row);
127 macro->setArgumentIdx(idx);
131 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
133 os << "\n\\newcommand{\\" << name << "}";
136 os << "[" << nargs_ << "]";
140 for (int i = 0; i < nargs_; ++i) {
141 args_[i].setExpand(false);
148 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
150 args_[i].GetXY(x, y);
154 MathParInset * MathMacroTemplate::getMacroPar(int i) const
156 if (i >= 0 && i < nargs_)
157 return const_cast<MathParInset *>
158 (static_cast<MathParInset const *>(&args_[i]));
164 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
166 for (int i = 0; i < nargs_; ++i) {
167 if (args_[i].Inside(x, y)) {