X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_inset.C;h=00f9c90124c2306a2641963cde4bc8d9b5e67311;hb=a8a1f10e765512b40f6942e5594363fe16542c1c;hp=36362c28b31bfd33f8d4fec6a494714620f1ff24;hpb=a36dbaf607629596e6506f9f55de803d0831dbf8;p=lyx.git diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 36362c28b3..00f9c90124 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -1,364 +1,137 @@ -/* - * File: math_inset.C - * Purpose: Implementation of insets for mathed - * Author: Alejandro Aguilar Sierra - * Created: January 1996 - * Description: +/** + * \file math_inset.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * Dependencies: Xlib, XForms + * \author Alejandro Aguilar Sierra + * \author André Pönitz * - * Copyright: 1996, 1997 Alejandro Aguilar Sierra - * - * Version: 0.8beta. - * - * You are free to use and modify this code under the terms of - * the GNU General Public Licence version 2 or later. + * Full author contact details are available in file CREDITS. */ -#ifdef __GNUG__ -#pragma implementation -#endif +#include #include "math_inset.h" +#include "math_data.h" +#include "math_mathmlstream.h" #include "debug.h" +using std::string; +using std::ostream; +using std::endl; -int MathInset::workwidth; - - -MathInset::MathInset(int nargs, string const & name) - : name_(name), width_(0), ascent_(0), descent_(0), - size_(LM_ST_DISPLAY), cells_(nargs), xo_(0), yo_(0) -{} - - -int MathInset::ascent() const -{ - return ascent_; -} - - -int MathInset::descent() const -{ - return descent_; -} - - -int MathInset::width() const -{ - return width_; -} +MathArray dummyCell; -int MathInset::height() const +MathArray & MathInset::cell(idx_type) { - return ascent_ + descent_; + lyxerr << "I don't have a cell 1" << endl; + return dummyCell; } -int MathInset::limits() const +MathArray const & MathInset::cell(idx_type) const { - return false; + lyxerr << "I don't have a cell 2" << endl; + return dummyCell; } -void MathInset::limits(int) +void MathInset::substitute(MathMacro const &) {} -string const & MathInset::name() const -{ - return name_; -} - - -void MathInset::setName(string const & n) -{ - name_ = n; -} - - -MathStyles MathInset::size() const -{ - return size_; -} - - -void MathInset::size(MathStyles s) -{ - size_ = s; -} - -std::ostream & operator<<(std::ostream & os, MathInset const & inset) -{ - inset.write(os, false); - return os; -} - - -int MathInset::xo() const -{ - return xo_; -} - - -int MathInset::yo() const -{ - return yo_; -} - - -void MathInset::xo(int x) -{ - xo_ = x; -} - - -void MathInset::yo(int y) -{ - yo_ = y; -} - - -int MathInset::nargs() const -{ - return cells_.size(); -} - - - -MathXArray & MathInset::xcell(int i) -{ - return cells_[i]; -} - -MathXArray const & MathInset::xcell(int i) const -{ - return cells_[i]; -} - - - -MathArray & MathInset::cell(int i) -{ - return cells_[i].data_; -} - -MathArray const & MathInset::cell(int i) const -{ - return cells_[i].data_; -} - - -void MathInset::substitute(MathArray & array, MathMacro const & m) const -{ - MathInset * p = clone(); - for (int i = 0; i < nargs(); ++i) - p->cell(i).substitute(m); - array.push_back(p); -} - -void MathInset::metrics(MathStyles st) -{ - size_ = st; - for (int i = 0; i < nargs(); ++i) - xcell(i).metrics(st); -} - -void MathInset::draw(Painter & pain, int x, int y) -{ - xo_ = x; - yo_ = y; - for (int i = 0; i < nargs(); ++i) - xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo()); -} - - -bool MathInset::idxNext(int & idx, int & pos) const -{ - if (idx + 1 >= nargs()) - return false; - ++idx; - pos = 0; - return true; -} - - -bool MathInset::idxRight(int & idx, int & pos) const -{ - return idxNext(idx, pos); -} - - -bool MathInset::idxPrev(int & idx, int & pos) const -{ - if (idx == 0) - return false; - --idx; - pos = cell(idx).size(); - return true; -} - - -bool MathInset::idxLeft(int & idx, int & pos) const -{ - return idxPrev(idx, pos); -} - -bool MathInset::idxUp(int &, int &) const -{ - return false; -} - - -bool MathInset::idxDown(int &, int &) const -{ - return false; -} - - -bool MathInset::idxFirst(int & i, int & pos) const -{ - if (nargs() == 0) - return false; - i = 0; - pos = 0; - return true; -} - -bool MathInset::idxLast(int & i, int & pos) const -{ - if (nargs() == 0) - return false; - i = nargs() - 1; - pos = cell(i).size(); - return true; -} - -bool MathInset::idxHome(int & /* idx */, int & pos) const +void MathInset::dump() const { - if (pos == 0) - return false; - pos = 0; - return true; + lyxerr << "---------------------------------------------" << endl; + WriteStream wi(lyxerr, false, true); + write(wi); + lyxerr << "\n---------------------------------------------" << endl; } -bool MathInset::idxEnd(int & idx, int & pos) const +void MathInset::metricsT(TextMetricsInfo const &, Dimension &) const { - if (pos == cell(idx).size()) - return false; - - pos = cell(idx).size(); - return true; +#ifdef WITH_WARNINGS + lyxerr << "MathInset::metricsT(Text) called directly!" << endl; +#endif } -bool MathInset::idxFirstUp(int &, int &) const +void MathInset::drawT(TextPainter &, int, int) const { - return false; +#ifdef WITH_WARNINGS + lyxerr << "MathInset::drawT(Text) called directly!" << endl; +#endif } -bool MathInset::idxFirstDown(int &, int &) const -{ - return false; -} -void MathInset::idxDelete(int &, bool & popit, bool & deleteit) +void MathInset::write(WriteStream & os) const { - popit = false; - deleteit = false; + os << '\\' << name().c_str(); + os.pendingSpace(true); } -void MathInset::idxDeleteRange(int, int) -{} - -bool MathInset::idxLastUp(int &, int &) const +void MathInset::normalize(NormalStream & os) const { - return false; + os << '[' << name().c_str() << "] "; } -bool MathInset::idxLastDown(int &, int &) const +void MathInset::octave(OctaveStream & os) const { - return false; + NormalStream ns(os.os()); + normalize(ns); } -void MathInset::getXY(int & x, int & y) const +void MathInset::maple(MapleStream & os) const { - x = xo(); - y = yo(); + NormalStream ns(os.os()); + normalize(ns); } -/* -void MathInset::userSetSize(MathStyles sz) -{ - if (sz >= 0) { - size_ = sz; - flag = flag & ~LMPF_FIXED_SIZE; - } -} -*/ - -void MathInset::writeNormal(std::ostream & os) const +void MathInset::maxima(MaximaStream & os) const { - os << "[" << name_ << "] "; + MapleStream ns(os.os()); + maple(ns); } -void MathInset::dump() const +void MathInset::mathematica(MathematicaStream & os) const { - lyxerr << "---------------------------------------------\n"; - write(lyxerr, false); - lyxerr << "\n"; - for (int i = 0; i < nargs(); ++i) - lyxerr << cell(i) << "\n"; - lyxerr << "---------------------------------------------\n"; + NormalStream ns(os.os()); + normalize(ns); } -void MathInset::push_back(unsigned char ch, MathTextCodes fcode) +void MathInset::mathmlize(MathMLStream & os) const { - if (nargs()) - cells_.back().data_.push_back(ch, fcode); - else - lyxerr << "can't push without a cell\n"; + NormalStream ns(os.os()); + normalize(ns); } -void MathInset::push_back(MathInset * p) +string const & MathInset::getType() const { - if (nargs()) - cells_.back().data_.push_back(p); - else - lyxerr << "can't push without a cell\n"; + static string const t("none"); + return t; } -bool MathInset::covers(int x, int y) const +string MathInset::name() const { - return - x >= xo_ && - x <= xo_ + width_ && - y >= yo_ - ascent_ && - y <= yo_ + descent_; + return "unknown"; } -void MathInset::validate(LaTeXFeatures & features) const -{ - for (int i = 0; i < nargs(); ++i) - cell(i).validate(features); -} -std::vector MathInset::idxBetween(int from, int to) const +ostream & operator<<(ostream & os, MathAtom const & at) { - std::vector res; - for (int i = from; i <= to; ++i) - res.push_back(i); - return res; + WriteStream wi(os, false, false); + at->write(wi); + return os; }