X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_inset.C;h=1a9b26d3e5d3924af921f8105d1240eea70ff8fd;hb=f1ff990de782f1a4c3ae14902f5242bdb012b264;hp=b5980fc019530eeea4bbb7a63ff6fdc26233793b;hpb=9ccefe810b24031894fff8cf3dd39c1bc7f31241;p=lyx.git diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index b5980fc019..1a9b26d3e5 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -1,9 +1,9 @@ /* * File: math_inset.C * Purpose: Implementation of insets for mathed - * Author: Alejandro Aguilar Sierra + * Author: Alejandro Aguilar Sierra * Created: January 1996 - * Description: + * Description: * * Dependencies: Xlib, XForms * @@ -15,362 +15,258 @@ * the GNU General Public Licence version 2 or later. */ -#ifdef __GNUG__ -#pragma implementation -#endif +#include #include "math_inset.h" +#include "math_scriptinset.h" +#include "math_mathmlstream.h" +#include "math_cursor.h" #include "debug.h" +#include "frontends/LyXView.h" +#include "frontends/Dialogs.h" +#include "BufferView.h" +#include "formulabase.h" -int MathInset::workwidth; - - -MathInset::MathInset(int nargs, string const & name, MathInsetTypes ot) - : name_(name), objtype(ot), width_(0), ascent_(0), descent_(0), - size_(LM_ST_DISPLAY), cells_(nargs), xo_(0), yo_(0) -{} - - -int MathInset::ascent() const -{ - return ascent_; -} +using std::ostream; +using std::endl; -int MathInset::descent() const +BufferView * MathInset::view() const { - return descent_; + return mathcursor ? mathcursor->formula()->view() : 0; } -int MathInset::width() const +MathInset::size_type MathInset::nargs() const { - return width_; + return 0; } -int MathInset::height() const -{ - return ascent_ + descent_; -} - - -int MathInset::limits() const -{ - return false; -} - - -void MathInset::limits(int) -{ -} +MathArray dummyCell; -string const & MathInset::name() const +MathArray & MathInset::cell(idx_type) { - return name_; + lyxerr << "I don't have a cell 1" << endl; + return dummyCell; } -MathInsetTypes MathInset::GetType() const +MathArray const & MathInset::cell(idx_type) const { - return objtype; + lyxerr << "I don't have a cell 2" << endl; + return dummyCell; } -void MathInset::SetType(MathInsetTypes t) +MathInset::idx_type MathInset::index(row_type row, col_type col) const { - objtype = t; + if (row != 0) + lyxerr << "illegal row: " << row << endl; + if (col != 0) + lyxerr << "illegal col: " << col << endl; + return 0; } - -void MathInset::SetName(string const & n) -{ - name_ = n; -} +void MathInset::substitute(MathMacro const &) +{} -MathStyles MathInset::size() const +bool MathInset::idxNext(idx_type &, pos_type &) const { - return size_; + return false; } -void MathInset::size(MathStyles s) +bool MathInset::idxRight(idx_type &, pos_type &) const { - size_ = s; -} - -std::ostream & operator<<(std::ostream & os, MathInset const & inset) -{ - inset.Write(os, false); - return os; + return false; } -int MathInset::xo() const +bool MathInset::idxPrev(idx_type &, pos_type &) const { - return xo_; + return false; } -int MathInset::yo() const +bool MathInset::idxLeft(idx_type &, pos_type &) const { - return yo_; + return false; } -void MathInset::xo(int x) +bool MathInset::idxUpDown(idx_type &, pos_type &, bool, int) const { - xo_ = x; + return false; } -void MathInset::yo(int y) +bool MathInset::idxUpDown2(idx_type &, pos_type &, bool, int) const { - yo_ = y; + return false; } -int MathInset::nargs() const +bool MathInset::idxFirst(idx_type &, pos_type &) const { - return cells_.size(); + return false; } - -MathXArray & MathInset::xcell(int i) -{ - return cells_[i]; -} - -MathXArray const & MathInset::xcell(int i) const +bool MathInset::idxLast(idx_type &, pos_type &) const { - return cells_[i]; + return false; } - -MathArray & MathInset::cell(int i) -{ - return cells_[i].data_; -} - -MathArray const & MathInset::cell(int i) const +bool MathInset::idxHome(idx_type &, pos_type &) const { - return cells_[i].data_; + return false; } -void MathInset::substitute(MathArray & array, MathMacro const & m) const +bool MathInset::idxEnd(idx_type &, pos_type &) const { - MathInset * p = clone(); - for (int i = 0; i < nargs(); ++i) - p->cell(i).substitute(m); - array.push_back(p); + return false; } -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) +void MathInset::getPos(idx_type, pos_type, int & x, int & y) const { - xo_ = x; - yo_ = y; - for (int i = 0; i < nargs(); ++i) - xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo()); + lyxerr << "MathInset::getPos() called directly!" << endl; + x = y = 0; } -bool MathInset::idxNext(int & idx, int & pos) const +void MathInset::dump() const { - if (idx + 1 >= nargs()) - return false; - ++idx; - pos = 0; - return true; + lyxerr << "---------------------------------------------" << endl; + WriteStream wi(lyxerr, false, true); + write(wi); + lyxerr << "\n---------------------------------------------" << endl; } -bool MathInset::idxRight(int & idx, int & pos) const +bool MathInset::idxBetween(idx_type idx, idx_type from, idx_type to) const { - return idxNext(idx, pos); + return from <= idx && idx <= to; } -bool MathInset::idxPrev(int & idx, int & pos) const +void MathInset::drawSelection(PainterInfo &, + idx_type, pos_type, idx_type, pos_type) const { - if (idx == 0) - return false; - --idx; - pos = cell(idx).size(); - return true; + lyxerr << "MathInset::drawSelection() called directly!" << endl; } -bool MathInset::idxLeft(int & idx, int & pos) const +void MathInset::metricsT(TextMetricsInfo const &, Dimension &) const { - return idxPrev(idx, pos); -} - -bool MathInset::idxUp(int &, int &) const -{ - return false; +#ifdef WITH_WARNINGS + lyxerr << "MathInset::metricsT(Text) called directly!" << endl; +#endif } -bool MathInset::idxDown(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::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 +void MathInset::write(WriteStream & os) const { - if (nargs() == 0) - return false; - i = nargs() - 1; - pos = cell(i).size(); - return true; + os << '\\' << name().c_str(); + os.pendingSpace(true); } -bool MathInset::idxHome(int & /* idx */, int & pos) const +void MathInset::normalize(NormalStream & os) const { - if (pos == 0) - return false; - pos = 0; - return true; + os << '[' << name().c_str() << "] "; } -bool MathInset::idxEnd(int & idx, int & pos) const +void MathInset::octave(OctaveStream & os) const { - if (pos == cell(idx).size()) - return false; - - pos = cell(idx).size(); - return true; + NormalStream ns(os.os()); + normalize(ns); } -bool MathInset::idxFirstUp(int &, int &) const +void MathInset::maple(MapleStream & os) const { - return false; + NormalStream ns(os.os()); + normalize(ns); } -bool MathInset::idxFirstDown(int &, int &) const +void MathInset::maxima(MaximaStream & os) const { - return false; + MapleStream ns(os.os()); + maple(ns); } -void MathInset::idxDelete(int &, bool & popit, bool & deleteit) -{ - popit = false; - deleteit = false; -} -void MathInset::idxDeleteRange(int, int) -{} - - -bool MathInset::idxLastUp(int &, int &) const +void MathInset::mathematica(MathematicaStream & os) const { - return false; + NormalStream ns(os.os()); + normalize(ns); } -bool MathInset::idxLastDown(int &, int &) const +void MathInset::mathmlize(MathMLStream & os) const { - return false; + NormalStream ns(os.os()); + normalize(ns); } -void MathInset::GetXY(int & x, int & y) const +int MathInset::ascii(std::ostream &, int) const { - x = xo(); - y = yo(); + return 0; } -/* -void MathInset::UserSetSize(MathStyles sz) -{ - if (sz >= 0) { - size_ = sz; - flag = flag & ~LMPF_FIXED_SIZE; - } -} -*/ - -void MathInset::WriteNormal(std::ostream & os) const +int MathInset::linuxdoc(std::ostream &) const { - os << "[" << name_ << "] "; + return 0; } -void MathInset::dump() const +int MathInset::docbook(std::ostream &, bool) const { - lyxerr << "---------------------------------------------\n"; - Write(lyxerr, false); - lyxerr << "\n"; - for (int i = 0; i < nargs(); ++i) - lyxerr << cell(i) << "\n"; - lyxerr << "---------------------------------------------\n"; + return 0; } -void MathInset::push_back(unsigned char ch, MathTextCodes fcode) +string const & MathInset::getType() const { - if (nargs()) - cells_.back().data_.push_back(ch, fcode); - else - lyxerr << "can't push without a cell\n"; + static string const t("none"); + return t; } -void MathInset::push_back(MathInset * p) +string MathInset::name() const { - if (nargs()) - cells_.back().data_.push_back(p); - else - lyxerr << "can't push without a cell\n"; + return "unknown"; } -bool MathInset::covers(int x, int y) const +ostream & operator<<(ostream & os, MathAtom const & at) { - return - x >= xo_ && - x <= xo_ + width_ && - y >= yo_ - ascent_ && - y <= yo_ + descent_; + WriteStream wi(os, false, false); + at->write(wi); + return os; } -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 +string MathInset::fileInsetLabel() const { - std::vector res; - for (int i = from; i <= to; ++i) - res.push_back(i); - return res; + return "Formula"; }