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),
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)
76 bool expnd = (nargs > 0) ? args_[0].getExpand(): false;
77 if (flags & MMF_Edit) {
78 for (int i = 0; i < nargs; ++i) {
79 args_[i].setExpand(false);
83 for (int i = 0; i < nargs; ++i) {
84 args_[i].setExpand(true);
88 MathParInset::draw(pain, x, y);
91 for (int i = 0; i < nargs; ++i) {
92 args_[i].setExpand(expnd);
97 void MathMacroTemplate::Metrics()
99 bool expnd = (nargs > 0) ? args_[0].getExpand(): false;
101 if (flags & MMF_Edit) {
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)
120 int idx = (macro) ? macro->getArgumentIdx() : 0;
121 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);
130 macro->setArgumentIdx(idx);
134 void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
136 os << "\n\\newcommand{\\" << name << "}";
139 os << "[" << nargs << "]";
143 for (int i = 0; i < nargs; ++i) {
144 args_[i].setExpand(false);
151 void MathMacroTemplate::setArgument(MathedArray * a, int i)
157 void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
159 args_[i].GetXY(x, y);
163 MathParInset * MathMacroTemplate::getMacroPar(int i) const
165 if (i >= 0 && i < nargs)
166 return const_cast<MathParInset *>
167 (static_cast<MathParInset const *>(&args_[i]));
173 void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
175 for (int i = 0; i < nargs; ++i) {
176 if (args_[i].Inside(x, y)) {