/*
* File: math_inset.C
* Purpose: Implementation of insets for mathed
- * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+ * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
* Created: January 1996
- * Description:
+ * Description:
*
* Dependencies: Xlib, XForms
*
#pragma implementation
#endif
+#include <config.h>
+
+#include "Lsstream.h"
#include "math_inset.h"
+#include "math_scriptinset.h"
+#include "math_charinset.h"
+#include "math_mathmlstream.h"
+#include "math_cursor.h"
#include "debug.h"
-
-int MathInset::workwidth;
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+#include "BufferView.h"
+#include "formulabase.h"
-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)
-{}
+using std::ostream;
+using std::vector;
-int MathInset::ascent() const
+int MathInset::height() const
{
- return ascent_;
+ return ascent() + descent();
}
-int MathInset::descent() const
+ostream & operator<<(ostream & os, MathAtom const & at)
{
- return descent_;
+ if (at.nucleus())
+ os << *(at.nucleus());
+ else
+ os << "(nil)";
+ return os;
}
-int MathInset::width() const
+ostream & operator<<(ostream & os, MathInset const & inset)
{
- return width_;
+ WriteStream wi(os, false, false);
+ inset.write(wi);
+ return os;
}
-
-int MathInset::height() const
+MathInset::size_type MathInset::nargs() const
{
- return ascent_ + descent_;
+ return 0;
}
-int MathInset::limits() const
+void MathInset::dimensions(int & w, int & a, int & d) const
{
- return false;
+ w = width();
+ a = ascent();
+ d = descent();
}
-void MathInset::limits(int)
-{
-}
+MathXArray dummyCell;
-string const & MathInset::name() const
+MathXArray & MathInset::xcell(idx_type)
{
- return name_;
+ lyxerr << "I don't have a cell 1\n";
+ return dummyCell;
}
-MathInsetTypes MathInset::GetType() const
+MathXArray const & MathInset::xcell(idx_type) const
{
- return objtype;
+ lyxerr << "I don't have a cell 2\n";
+ return dummyCell;
}
-void MathInset::SetType(MathInsetTypes t)
+MathArray & MathInset::cell(idx_type)
{
- objtype = t;
+ lyxerr << "I don't have a cell 3\n";
+ return dummyCell.data();
}
-void MathInset::SetName(string const & n)
+MathArray const & MathInset::cell(idx_type) const
{
- name_ = n;
+ lyxerr << "I don't have a cell 4\n";
+ return dummyCell.data();
}
-MathStyles MathInset::size() const
+MathInset::idx_type MathInset::index(row_type row, col_type col) const
{
- return size_;
+ if (row != 0)
+ lyxerr << "illegal row: " << row << "\n";
+ if (col != 0)
+ lyxerr << "illegal col: " << col << "\n";
+ return 0;
}
+void MathInset::substitute(MathMacro const &)
+{}
-void MathInset::size(MathStyles s)
-{
- size_ = s;
-}
-std::ostream & operator<<(std::ostream & os, MathInset const & inset)
+bool MathInset::idxNext(idx_type &, pos_type &) const
{
- inset.Write(os, false);
- return os;
+ return false;
}
-int MathInset::xo() const
+bool MathInset::idxRight(idx_type &, pos_type &) const
{
- return xo_;
+ return false;
}
-int MathInset::yo() const
+bool MathInset::idxPrev(idx_type &, pos_type &) const
{
- return yo_;
+ return false;
}
-void MathInset::xo(int x)
+bool MathInset::idxLeft(idx_type &, pos_type &) const
{
- xo_ = x;
+ return false;
}
-void MathInset::yo(int y)
+bool MathInset::idxUpDown(idx_type &, bool) 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)
+bool MathInset::idxLast(idx_type &, pos_type &) const
{
- return cells_[i];
-}
-
-MathXArray const & MathInset::xcell(int i) 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, int, int)
-{
- size_ = st;
- for (int i = 0; i < nargs(); ++i)
- xcell(i).Metrics(st);
-}
-void MathInset::draw(Painter & pain, int x, int y)
+void MathInset::normalize(NormalStream & os) const
{
- xo_ = x;
- yo_ = y;
- for (int i = 0; i < nargs(); ++i)
- xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
+ os << "[unknown ";
+ WriteStream wi(os.os(), false, true);
+ write(wi);
+ os << "] ";
}
-bool MathInset::idxNext(int & idx, int & pos) const
+void MathInset::dump() const
{
- if (idx + 1 >= nargs())
- return false;
- ++idx;
- pos = 0;
- return true;
+ lyxerr << "---------------------------------------------\n";
+ WriteStream wi(lyxerr, false, true);
+ write(wi);
+ lyxerr << "\n---------------------------------------------\n";
}
-bool MathInset::idxRight(int & idx, int & pos) const
-{
- return idxNext(idx, pos);
-}
+void MathInset::validate(LaTeXFeatures &) const
+{}
-bool MathInset::idxPrev(int & idx, int & pos) const
+vector<MathInset::idx_type>
+ MathInset::idxBetween(idx_type from, idx_type to) const
{
- if (idx == 0)
- return false;
- --idx;
- pos = cell(idx).size();
- return true;
+ vector<idx_type> res;
+ for (idx_type i = from; i <= to; ++i)
+ res.push_back(i);
+ return res;
}
-bool MathInset::idxLeft(int & idx, int & pos) const
+void MathInset::metrics(MathMetricsInfo &) const
{
- return idxPrev(idx, pos);
+ lyxerr << "MathInset::metrics() called directly!\n";
}
-bool MathInset::idxUp(int &, int &) const
+
+void MathInset::draw(MathPainterInfo &, int, int) const
{
- return false;
+ lyxerr << "MathInset::draw() called directly!\n";
}
-bool MathInset::idxDown(int &, int &) const
+void MathInset::metricsT(TextMetricsInfo const &) const
{
- return false;
+#ifdef WITH_WARNINGS
+ lyxerr << "MathInset::metricsT(Text) called directly!\n";
+#endif
}
-bool MathInset::idxFirst(int & i, int & pos) const
+void MathInset::drawT(TextPainter &, int, int) const
{
- if (nargs() == 0)
- return false;
- i = 0;
- pos = 0;
- return true;
+#ifdef WITH_WARNINGS
+ lyxerr << "MathInset::drawT(Text) called directly!\n";
+#endif
}
-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::write(WriteStream &) const
{
- if (pos == 0)
- return false;
- pos = 0;
- return true;
+ lyxerr << "MathInset::write() called directly!\n";
}
-bool MathInset::idxEnd(int & idx, int & pos) const
+void MathInset::octavize(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::maplize(MapleStream & os) const
{
- return false;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-bool MathInset::idxFirstDown(int &, int &) const
+void MathInset::mathematicize(MathematicaStream & os) const
{
- return false;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
+
+void MathInset::mathmlize(MathMLStream & os) const
{
- popit = false;
- deleteit = false;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-bool MathInset::idxLastUp(int &, int &) const
+int MathInset::ascii(std::ostream &, int) const
{
- return false;
+ return 0;
}
-bool MathInset::idxLastDown(int &, int &) const
+int MathInset::linuxdoc(std::ostream &) const
{
- return false;
+ return 0;
}
-void MathInset::GetXY(int & x, int & y) const
+int MathInset::docbook(std::ostream &, bool) const
{
- x = xo();
- y = yo();
+ return 0;
}
-/*
-void MathInset::UserSetSize(MathStyles sz)
+int MathInset::dispatch(string const &, idx_type, pos_type)
{
- if (sz >= 0) {
- size_ = sz;
- flag = flag & ~LMPF_FIXED_SIZE;
- }
+ return 0; // undispatched
}
-*/
-void MathInset::WriteNormal(std::ostream & os) const
+
+std::vector<string> MathInset::getLabelList() const
{
- os << "[" << name_ << "] ";
+ return std::vector<string>();
}
-void MathInset::dump() const
+string const & MathInset::getType() const
{
- lyxerr << "---------------------------------------------\n";
- Write(lyxerr, false);
- lyxerr << "\n";
- for (int i = 0; i < nargs(); ++i)
- lyxerr << cell(i) << "\n";
- lyxerr << "---------------------------------------------\n";
+ static string t("none");
+ return t;
}
-void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
+string asString(MathArray const & ar)
{
- if (nargs())
- cells_.back().data_.push_back(ch, fcode);
- else
- lyxerr << "can't push without a cell\n";
+ string res;
+ for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it)
+ if ((*it)->getChar())
+ res += (*it)->getChar();
+ return res;
}
-void MathInset::push_back(MathInset * p)
+MathArray asArray(string const & str)
{
- if (nargs())
- cells_.back().data_.push_back(p);
- else
- lyxerr << "can't push without a cell\n";
+ MathArray ar;
+ for (string::const_iterator it = str.begin(); it != str.end(); ++it)
+ ar.push_back(MathAtom(new MathCharInset(*it)));
+ return ar;
}
-bool MathInset::covers(int x, int y) const
+Dialogs * getDialogs()
{
- return
- x >= xo_ &&
- x <= xo_ + width_ &&
- y >= yo_ - ascent_ &&
- y <= yo_ + descent_;
+ return mathcursor->formula()->view()->owner()->getDialogs();
}
-void MathInset::Validate(LaTeXFeatures & features) const
+
+LyXFunc * getLyXFunc()
{
- for (int i = 0; i < nargs(); ++i)
- cell(i).Validate(features);
+ return mathcursor->formula()->view()->owner()->getLyXFunc();
}