/*
* 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
*
#endif
#include "math_inset.h"
-#include "mathed/support.h"
-#include "Painter.h"
+#include "Lsstream.h"
+#include "math_scriptinset.h"
+#include "math_mathmlstream.h"
+#include "math_cursor.h"
+#include "math_parser.h"
#include "debug.h"
+#include "frontends/LyXView.h"
+#include "frontends/Dialogs.h"
+#include "BufferView.h"
+#include "formulabase.h"
-int MathInset::workwidth;
+using std::ostream;
-MathInset::MathInset(string const & name, short ot, int nargs)
- : name_(name), objtype(ot), width_(0), ascent_(0), descent_(0),
- size_(LM_ST_TEXT), cells_(nargs), xo_(0), yo_(0)
-{}
+int MathInset::height() const
+{
+ return ascent() + descent();
+}
-int MathInset::ascent() const
+MathInset::size_type MathInset::nargs() const
{
- return ascent_;
+ return 0;
}
-int MathInset::descent() const
+Dimension MathInset::dimensions() const
{
- return descent_;
+ lyxerr << "call MathInset::dimensions()\n";
+ return Dimension(width(), ascent(), descent());
}
-int MathInset::width() const
+MathArray dummyCell;
+
+MathArray & MathInset::cell(idx_type)
{
- return width_;
+ lyxerr << "I don't have a cell 1\n";
+ return dummyCell;
}
-int MathInset::height() const
+MathArray const & MathInset::cell(idx_type) const
{
- return ascent_ + descent_;
+ lyxerr << "I don't have a cell 2\n";
+ return dummyCell;
}
-bool MathInset::GetLimits() const
+MathInset::idx_type MathInset::index(row_type row, col_type col) const
{
- return false;
+ if (row != 0)
+ lyxerr << "illegal row: " << row << "\n";
+ if (col != 0)
+ lyxerr << "illegal col: " << col << "\n";
+ return 0;
}
-
-void MathInset::SetLimits(bool) {}
+void MathInset::substitute(MathMacro const &)
+{}
-string const & MathInset::name() const
+bool MathInset::idxNext(idx_type &, pos_type &) const
{
- return name_;
+ return false;
}
-short MathInset::GetType() const
+bool MathInset::idxRight(idx_type &, pos_type &) const
{
- return objtype;
+ return false;
}
-void MathInset::SetType(short t)
+bool MathInset::idxPrev(idx_type &, pos_type &) const
{
- objtype = t;
+ return false;
}
-void MathInset::SetName(string const & n)
+bool MathInset::idxLeft(idx_type &, pos_type &) const
{
- name_ = n;
+ return false;
}
-MathStyles MathInset::size() const
+bool MathInset::idxUpDown(idx_type &, pos_type &, bool, int) const
{
- return size_;
+ return false;
}
-void MathInset::size(MathStyles s)
+bool MathInset::idxFirst(idx_type &, pos_type &) const
{
- size_ = s;
+ return false;
}
-std::ostream & operator<<(std::ostream & os, MathInset const & inset)
+
+bool MathInset::idxLast(idx_type &, pos_type &) const
{
- inset.Write(os, false);
- return os;
+ return false;
}
-int MathInset::xo() const
+bool MathInset::idxHome(idx_type &, pos_type &) const
{
- return xo_;
+ return false;
}
-int MathInset::yo() const
+bool MathInset::idxEnd(idx_type &, pos_type &) const
{
- return yo_;
+ return false;
}
-void MathInset::xo(int x)
+void MathInset::getPos(idx_type, pos_type, int & x, int & y) const
{
- xo_ = x;
+ lyxerr << "MathInset::getPos() called directly!\n";
+ x = y = 0;
}
-void MathInset::yo(int y)
+void MathInset::dump() const
{
- yo_ = y;
+ lyxerr << "---------------------------------------------\n";
+ WriteStream wi(lyxerr, false, true);
+ write(wi);
+ lyxerr << "\n---------------------------------------------\n";
}
-int MathInset::nargs() const
+bool MathInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
{
- return cells_.size();
+ return from <= idx && idx <= to;
}
-
-MathXArray & MathInset::xcell(int i)
+void MathInset::metrics(MathMetricsInfo &) const
{
- return cells_[i];
+ lyxerr << "MathInset::metrics() called directly!\n";
}
-MathXArray const & MathInset::xcell(int i) const
+
+void MathInset::draw(MathPainterInfo &, int, int) const
{
- return cells_[i];
+ lyxerr << "MathInset::draw() called directly!\n";
}
-
-MathArray & MathInset::cell(int i)
+void MathInset::drawSelection(MathPainterInfo &,
+ idx_type, pos_type, idx_type, pos_type) const
{
- return cells_[i].data_;
+ lyxerr << "MathInset::drawSelection() called directly!\n";
}
-MathArray const & MathInset::cell(int i) const
+
+void MathInset::metricsT(TextMetricsInfo const &) const
{
- return cells_[i].data_;
+#ifdef WITH_WARNINGS
+ lyxerr << "MathInset::metricsT(Text) called directly!\n";
+#endif
}
-void MathInset::setData(MathArray const & a, int idx)
+void MathInset::drawT(TextPainter &, int, int) const
{
- cells_[idx].data_ = a;
+#ifdef WITH_WARNINGS
+ lyxerr << "MathInset::drawT(Text) called directly!\n";
+#endif
}
-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)
+void MathInset::write(WriteStream & os) const
{
- size_ = st;
- for (int i = 0; i < nargs(); ++i)
- xcell(i).Metrics(st);
+ os << '\\' << name().c_str();
+ os.pendingSpace(true);
}
-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 << '[' << name().c_str() << "] ";
}
-bool MathInset::idxRight(int & idx, int & pos) const
+void MathInset::octavize(OctaveStream & os) const
{
- if (idx + 1 >= nargs())
- return false;
- ++idx;
- pos = 0;
- return true;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-bool MathInset::idxLeft(int & idx, int & pos) const
+void MathInset::maplize(MapleStream & os) const
{
- if (idx == 0)
- return false;
- --idx;
- pos = cell(idx).size();
- return true;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-bool MathInset::idxUp(int &, int &) const
+void MathInset::maximize(MaximaStream & os) const
{
- return false;
+ MapleStream ns(os.os());
+ maplize(ns);
}
-bool MathInset::idxDown(int &, int &) const
+void MathInset::mathematicize(MathematicaStream & os) const
{
- return false;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-bool MathInset::idxFirst(int & i, int & pos) const
+void MathInset::mathmlize(MathMLStream & os) const
{
- if (nargs() == 0)
- return false;
- i = 0;
- pos = 0;
- return true;
+ NormalStream ns(os.os());
+ normalize(ns);
}
-bool MathInset::idxLast(int & i, int & pos) const
+
+int MathInset::ascii(std::ostream &, int) const
{
- if (nargs() == 0)
- return false;
- i = nargs() - 1;
- pos = cell(i).size();
- return true;
+ return 0;
}
-bool MathInset::idxHome(int & i, int & pos) const
+int MathInset::linuxdoc(std::ostream &) const
{
- if (pos == 0)
- return false;
- pos = 0;
- return true;
+ return 0;
}
-bool MathInset::idxEnd(int & idx, int & pos) const
+int MathInset::docbook(std::ostream &, bool) const
{
- if (pos == cell(idx).size())
- return false;
-
- pos = cell(idx).size();
- return true;
+ return 0;
}
-void MathInset::GetXY(int & x, int & y) const
+MathInset::result_type
+ MathInset::dispatch(FuncRequest const &, idx_type &, pos_type &)
{
- x = xo();
- y = yo();
+ return UNDISPATCHED;
}
-/*
-void MathInset::UserSetSize(MathStyles sz)
+string const & MathInset::getType() const
{
- if (sz >= 0) {
- size_ = sz;
- flag = flag & ~LMPF_FIXED_SIZE;
- }
+ static string t("none");
+ return t;
}
-*/
-void MathInset::WriteNormal(std::ostream & os) const
+
+string MathInset::name() const
{
- os << "[" << name_ << "] ";
+ return "unknown";
}
-void MathInset::dump() const
+string asString(MathArray const & ar)
{
- lyxerr << "---------------------------------------------\n";
- Write(lyxerr, false);
- lyxerr << "\n";
- for (int i = 0; i < nargs(); ++i)
- lyxerr << cell(i) << "\n";
- lyxerr << "---------------------------------------------\n";
+ std::ostringstream os;
+ WriteStream ws(os);
+ ws << ar;
+ return STRCONV(os.str());
}
-void MathInset::push_back(byte ch, MathTextCodes fcode)
+MathArray asArray(string const & str)
{
- if (nargs())
- cells_.back().data_.push_back(ch, fcode);
- else
- lyxerr << "can't push without a cell\n";
+ MathArray ar;
+ mathed_parse_cell(ar, str);
+ return ar;
}
-void MathInset::push_back(MathInset * p)
+ostream & operator<<(ostream & os, MathAtom const & at)
{
- if (nargs())
- cells_.back().data_.push_back(p);
- else
- lyxerr << "can't push without a cell\n";
+ WriteStream wi(os, false, false);
+ at->write(wi);
+ return os;
}
-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();
}
-