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;
24 for (int i = 0; i < nargs_; ++i) {
25 args_[i].setNumber(i + 1);
29 // Here is nargs != args_.size()
35 void MathMacroTemplate::setTCode(MathedTextCodes t)
41 MathedTextCodes MathMacroTemplate::getTCode() const
47 int MathMacroTemplate::getNoArgs() const
53 void MathMacroTemplate::setEditMode(bool ed)
57 for (int i = 0; i < nargs_; ++i) {
58 args_[i].setExpand(false);
62 for (int i = 0; i < nargs_; ++i) {
63 args_[i].setExpand(true);
69 void MathMacroTemplate::draw(Painter & pain, int x, int y)
73 bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
75 for (int i = 0; i < nargs_; ++i) {
76 args_[i].setExpand(false);
81 for (int i = 0; i < nargs_; ++i) {
82 args_[i].setExpand(true);
87 MathParInset::draw(pain, x, y);
91 for (int i = 0; i < nargs_; ++i) {
92 args_[i].setExpand(expnd);
97 void MathMacroTemplate::Metrics()
99 bool const expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
102 for (int i = 0; i < nargs_; ++i) {
103 args_[i].setExpand(false);
106 for (int i = 0; i < nargs_; ++i) {
107 args_[i].setExpand(true);
110 MathParInset::Metrics();
112 for (int i = 0; i < nargs_; ++i) {
113 args_[i].setExpand(expnd);
118 void MathMacroTemplate::update(MathMacro * macro)
121 int const idx = macro->getArgumentIdx();
122 for (int i = 0; i < nargs_; ++i) {
123 macro->setArgumentIdx(i);
124 args_[i].setData(macro->GetData());
125 MathedRowSt * row = macro->getRowSt();
126 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::GetMacroXY(int i, int & x, int & y) const
151 args_[i].GetXY(x, y);
155 MathParInset * MathMacroTemplate::getMacroPar(int i) const
157 if (i >= 0 && i < nargs_)
158 return const_cast<MathParInset *>
159 (static_cast<MathParInset const *>(&args_[i]));
165 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
167 for (int i = 0; i < nargs_; ++i) {
168 if (args_[i].Inside(x, y)) {