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));
26 //for (int i = 0; i < nargs_; ++i) {
27 // MathMacroArgument * ma = new MathMacroArgument(i + 1);
28 // args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
32 // Here is nargs != args_.size()
38 void MathMacroTemplate::setTCode(MathedTextCodes t)
44 MathedTextCodes MathMacroTemplate::getTCode() const
50 int MathMacroTemplate::getNoArgs() const
56 void MathMacroTemplate::setEditMode(bool ed)
60 for (int i = 0; i < nargs_; ++i) {
61 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;
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);
93 for (int i = 0; i < nargs_; ++i) {
94 args_[i].setExpand(expnd);
99 void MathMacroTemplate::Metrics()
101 bool const expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
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();
113 for (int i = 0; i < nargs_; ++i) {
114 args_[i].setExpand(expnd);
119 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
121 os << "\n\\newcommand{\\" << name << "}";
124 os << "[" << nargs_ << "]";
128 for (int i = 0; i < nargs_; ++i) {
129 args_[i].setExpand(false);
137 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
139 args_[i].GetXY(x, y);
143 MathParInset * MathMacroTemplate::getMacroPar(int i) const
145 if (i >= 0 && i < nargs_) {
146 MathParInset * p = const_cast<MathParInset *>
147 (static_cast<MathParInset const *>(&args_[i]));
154 void MathMacroTemplate::setMacroPar(int i, MathedArray const & ar)
156 if (i >= 0 && i < nargs_)
157 args_[i].setData(ar);
162 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
164 for (int i = 0; i < nargs_; ++i) {
165 if (args_[i].Inside(x, y)) {