3 #include "math_macrotemplate.h"
4 #include "math_macro.h"
5 #include "macro_support.h"
8 void MathMacroTemplate::setTCode(MathedTextCodes t)
14 MathedTextCodes MathMacroTemplate::getTCode() const
20 int MathMacroTemplate::getNoArgs() const
26 MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
27 MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
31 tcode = LM_TC_ACTIVE_INSET;
33 for (int i = 0; i < nargs; ++i) {
34 args_[i].setNumber(i + 1);
38 // Here is nargs != args_.size()
44 MathMacroTemplate::~MathMacroTemplate()
46 // prevent to delete already deleted objects
47 for (int i = 0; i < nargs; ++i) {
53 void MathMacroTemplate::setEditMode(bool ed)
57 for (int i = 0; i < nargs; ++i) {
58 args_[i].setExpand(false);
63 for (int i = 0; i < nargs; ++i) {
64 args_[i].setExpand(true);
70 void MathMacroTemplate::draw(Painter & pain, int x, int y)
73 bool expnd = (nargs > 0) ? args_[0].getExpand(): false;
74 if (flags & MMF_Edit) {
75 for (int i = 0; i < nargs; ++i) {
76 args_[i].setExpand(false);
80 for (int i = 0; i < nargs; ++i) {
81 args_[i].setExpand(true);
85 MathParInset::draw(pain, x, y);
88 for (int i = 0; i < nargs; ++i) {
89 args_[i].setExpand(expnd);
94 void MathMacroTemplate::Metrics()
96 bool expnd = (nargs > 0) ? args_[0].getExpand(): false;
98 if (flags & MMF_Edit) {
99 for (int i = 0; i < nargs; ++i) {
100 args_[i].setExpand(false);
103 for (int i = 0; i < nargs; ++i) {
104 args_[i].setExpand(true);
107 MathParInset::Metrics();
109 for (int i = 0; i < nargs; ++i) {
110 args_[i].setExpand(expnd);
115 void MathMacroTemplate::update(MathMacro * macro)
117 int idx = (macro) ? macro->getArgumentIdx() : 0;
118 for (int i = 0; i < nargs; ++i) {
120 macro->setArgumentIdx(i);
121 args_[i].SetData(macro->GetData());
122 MathedRowSt * row = macro->getRowSt();
123 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::setArgument(MathedArray * a, int i)
154 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
156 args_[i].GetXY(x, y);
160 MathParInset * MathMacroTemplate::getMacroPar(int i) const
162 if (i >= 0 && i < nargs)
163 return const_cast<MathParInset *>
164 (static_cast<MathParInset const *>(&args_[i]));
170 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
172 for (int i = 0; i < nargs; ++i) {
173 if (args_[i].Inside(x, y)) {