3 #include "math_macrotemplate.h"
4 #include "math_macro.h"
5 #include "macro_support.h"
6 #include "support/LOstream.h"
11 void MathMacroTemplate::setTCode(MathedTextCodes t)
17 MathedTextCodes MathMacroTemplate::getTCode() const
23 int MathMacroTemplate::getNoArgs() const
29 MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
30 MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
31 flags_(flg), nargs_(na)
34 tcode_ = LM_TC_ACTIVE_INSET;
36 for (int i = 0; i < nargs_; ++i) {
37 args_[i].setNumber(i + 1);
41 // Here is nargs != args_.size()
47 MathMacroTemplate::~MathMacroTemplate()
49 // prevent to delete already deleted objects
50 for (int i = 0; i < nargs_; ++i) {
56 void MathMacroTemplate::setEditMode(bool ed)
60 for (int i = 0; i < nargs_; ++i) {
61 args_[i].setExpand(false);
66 for (int i = 0; i < nargs_; ++i) {
67 args_[i].setExpand(true);
73 void MathMacroTemplate::draw(Painter & pain, int x, int y)
77 bool expnd = (nargs_ > 0) ? args_[0].getExpand(): false;
78 if (flags_ & MMF_Edit) {
79 for (int i = 0; i < nargs_; ++i) {
80 args_[i].setExpand(false);
85 for (int i = 0; i < nargs_; ++i) {
86 args_[i].setExpand(true);
91 MathParInset::draw(pain, x, y);
95 for (int i = 0; i < nargs_; ++i) {
96 args_[i].setExpand(expnd);
101 void MathMacroTemplate::Metrics()
103 bool expnd = (nargs_ > 0) ? args_[0].getExpand(): false;
105 if (flags_ & MMF_Edit) {
106 for (int i = 0; i < nargs_; ++i) {
107 args_[i].setExpand(false);
110 for (int i = 0; i < nargs_; ++i) {
111 args_[i].setExpand(true);
114 MathParInset::Metrics();
116 for (int i = 0; i < nargs_; ++i) {
117 args_[i].setExpand(expnd);
122 void MathMacroTemplate::update(MathMacro * macro)
124 int idx = (macro) ? macro->getArgumentIdx() : 0;
125 for (int i = 0; i < nargs_; ++i) {
127 macro->setArgumentIdx(i);
128 args_[i].SetData(macro->GetData());
129 MathedRowSt * row = macro->getRowSt();
130 args_[i].setRowSt(row);
134 macro->setArgumentIdx(idx);
138 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
140 os << "\n\\newcommand{\\" << name << "}";
143 os << "[" << nargs_ << "]";
147 for (int i = 0; i < nargs_; ++i) {
148 args_[i].setExpand(false);
155 void MathMacroTemplate::setArgument(MathedArray * a, int i)
161 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
163 args_[i].GetXY(x, y);
167 MathParInset * MathMacroTemplate::getMacroPar(int i) const
169 if (i >= 0 && i < nargs_)
170 return const_cast<MathParInset *>
171 (static_cast<MathParInset const *>(&args_[i]));
177 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
179 for (int i = 0; i < nargs_; ++i) {
180 if (args_[i].Inside(x, y)) {