4 * Purpose: Implementation of macro class for mathed
5 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
6 * Created: November 1996
7 * Description: WYSIWYG math macros
11 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
13 * Version: 0.2, Mathed & Lyx project.
15 * This code is under the GNU General Public Licence version 2 or later.
21 #pragma implementation
24 #include "math_macro.h"
26 #include "math_iter.h"
27 #include "math_inset.h"
28 #include "math_accentinset.h"
29 #include "math_deliminset.h"
30 #include "math_fracinset.h"
31 #include "math_rowst.h"
32 #include "support/lstrings.h"
34 #include "mathed/support.h"
35 #include "math_macrotemplate.h"
36 #include "macro_support.h"
41 ostream & operator<<(ostream & o, MathedTextCodes mtc)
47 MathMacro::MathMacro(boost::shared_ptr<MathMacroTemplate> const & t)
48 : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO),
51 //nargs_ = tmplate_->getNoArgs();
52 int const n = tmplate_->getNoArgs();
54 tcode_ = tmplate_->getTCode();
56 for (int i = 0; i < n; ++i) {
57 args_.push_back(MathMacroArgument(t->args_[i]));
59 //for (int i = 0; i < nargs_; ++i) {
60 // MathMacroArgument * ma = new MathMacroArgument(*t->args_[i]);
61 // args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
65 SetName(tmplate_->GetName());
69 MathedInset * MathMacro::Clone()
71 return new MathMacro(*this);
75 void MathMacro::Metrics()
77 for (int i = 0; i < args_.size(); ++i)
78 tmplate_->args_[i] = getArg(i);
79 tmplate_->SetStyle(size());
81 width = tmplate_->Width();
82 ascent = tmplate_->Ascent();
83 descent = tmplate_->Descent();
87 void MathMacro::draw(Painter & pain, int x, int y)
92 tmplate_->SetStyle(size());
93 tmplate_->draw(pain, x, y);
97 bool MathMacro::setArgumentIdx(int i)
99 if (i >= 0 && i < args_.size()) {
107 int MathMacro::getArgumentIdx() const
113 int MathMacro::getMaxArgumentIdx() const
115 return args_.size() - 1;
119 MathedArray & MathMacro::GetData()
121 return args_[idx_].GetData();
125 MathedArray const & MathMacro::GetData() const
127 return args_[idx_].GetData();
131 int MathMacro::GetColumns() const
133 return tmplate_->getMacroPar(idx_)->GetColumns();
137 void MathMacro::GetXY(int & x, int & y) const
139 const_cast<MathMacro*>(this)->Metrics();
140 tmplate_->GetMacroXY(idx_, x, y);
144 bool MathMacro::Permit(short f) const
146 return (args_.size() > 0) ?
147 tmplate_->getMacroPar(idx_)->Permit(f) :
148 MathParInset::Permit(f);
152 void MathMacro::SetFocus(int x, int y)
155 tmplate_->SetMacroFocus(idx_, x, y);
159 void MathMacro::setData(MathedArray const & a)
161 args_[idx_].setData(a);
165 MathedTextCodes MathMacro::getTCode() const
171 void MathMacro::Write(ostream & os, bool fragile)
175 int const n = args_.size();
180 for (int i = 0; i < n; ++i) {
181 array = args_[i].GetData();
182 MathParInset::Write(os, fragile);
192 MathMacroArgument const & MathMacro::getArg(int i) const
196 //boost::shared_ptr<MathMacroArgument> MathMacro::getArg(int i)