// -*- C++ -*- /* * File: math_macro.C * Purpose: Implementation of macro class for mathed * Author: Alejandro Aguilar Sierra * Created: November 1996 * Description: WYSIWYG math macros * * Dependencies: Mathed * * Copyright: 1996, 1997 Alejandro Aguilar Sierra * * Version: 0.2, Mathed & Lyx project. * * This code is under the GNU General Public Licence version 2 or later. */ #include #ifdef __GNUG__ #pragma implementation #endif #include "math_macro.h" #include "array.h" #include "math_iter.h" #include "math_inset.h" #include "math_accentinset.h" #include "math_deliminset.h" #include "math_fracinset.h" #include "math_rowst.h" #include "support/lstrings.h" #include "debug.h" #include "mathed/support.h" #include "math_macrotemplate.h" #include "macro_support.h" using std::ostream; using std::endl; ostream & operator<<(ostream & o, MathedTextCodes mtc) { return o << int(mtc); } MathMacro::MathMacro(boost::shared_ptr const & t) : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO), tmplate_(t) { nargs_ = tmplate_->getNoArgs(); tcode_ = tmplate_->getTCode(); args_.resize(nargs_); idx_ = 0; SetName(tmplate_->GetName()); } MathMacro::MathMacro(MathMacro const & m) : MathParInset(LM_ST_TEXT, m.GetName(), LM_OT_MACRO), tmplate_(m.tmplate_), idx_(0) { nargs_ = tmplate_->getNoArgs(); tcode_ = tmplate_->getTCode(); SetName(tmplate_->GetName()); std::vector::const_iterator cit = m.args_.begin(); std::vector::const_iterator end = m.args_.end(); //args_.resize(nargs_); //for (int i = 0; i < tmplate_->getNoArgs(); ++i) { // args_[i].row = m->args_[i].row; // args_[i].array = m->args_[i].array; //} for (; cit != end; ++cit) { args_.push_back(*cit); } } MathedInset * MathMacro::Clone() { return new MathMacro(*this); } void MathMacro::Metrics() { if (nargs_ > 0) tmplate_->update(this); tmplate_->SetStyle(size()); tmplate_->Metrics(); width = tmplate_->Width(); ascent = tmplate_->Ascent(); descent = tmplate_->Descent(); } void MathMacro::draw(Painter & pain, int x, int y) { xo(x); yo(y); Metrics(); tmplate_->SetStyle(size()); tmplate_->draw(pain, x, y); } bool MathMacro::setArgumentIdx(int i) { if (i >= 0 && i < nargs_) { idx_ = i; return true; } else return false; } int MathMacro::getArgumentIdx() const { return idx_; } int MathMacro::getMaxArgumentIdx() const { return nargs_ - 1; } MathedArray & MathMacro::GetData() { return args_[idx_].array; } MathedArray const & MathMacro::GetData() const { return args_[idx_].array; } int MathMacro::GetColumns() const { return tmplate_->getMacroPar(idx_)->GetColumns(); } void MathMacro::GetXY(int & x, int & y) const { #if 0 x = args_[idx_].x_; y = args_[idx_].y_; #else const_cast(this)->Metrics(); tmplate_->GetMacroXY(idx_, x, y); #endif } bool MathMacro::Permit(short f) const { return (nargs_ > 0) ? tmplate_->getMacroPar(idx_)->Permit(f) : MathParInset::Permit(f); } void MathMacro::SetFocus(int x, int y) { Metrics(); tmplate_->SetMacroFocus(idx_, x, y); } void MathMacro::setData(MathedArray const & a) { args_[idx_].array = a; } MathedRowSt * MathMacro::getRowSt() const { return args_[idx_].row; } MathedTextCodes MathMacro::getTCode() const { return tcode_; } void MathMacro::Write(ostream & os, bool fragile) { os << '\\' << name; if (nargs_ > 0) { os << '{'; for (int i = 0; i < nargs_; ++i) { array = args_[i].array; MathParInset::Write(os, fragile); if (i < nargs_ - 1) os << "}{"; } os << '}'; } else os << ' '; }