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::update(MathMacro const & macro)
121 for (int i = 0; i < nargs_; ++i) {
122 args_[i] = macro.getArg(i);
127 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
129 os << "\n\\newcommand{\\" << name << "}";
132 os << "[" << nargs_ << "]";
136 for (int i = 0; i < nargs_; ++i) {
137 args_[i].setExpand(false);
145 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
147 args_[i].GetXY(x, y);
151 MathParInset * MathMacroTemplate::getMacroPar(int i) const
153 if (i >= 0 && i < nargs_) {
154 MathParInset * p = const_cast<MathParInset *>
155 (static_cast<MathParInset const *>(&args_[i]));
163 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
165 for (int i = 0; i < nargs_; ++i) {
166 if (args_[i].Inside(x, y)) {