]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_inset.C
mathed108.diff
[lyx.git] / src / mathed / math_inset.C
index 87bb14e34d3cee39fa17acc770a3a4a7ce181a77..b5980fc019530eeea4bbb7a63ff6fdc26233793b 100644 (file)
  *   the GNU General Public Licence version 2 or later.
  */
 
-#include <config.h>
-
 #ifdef __GNUG__
 #pragma implementation
 #endif
 
-#include "math_iter.h"
 #include "math_inset.h"
-#include "symbol_def.h"
-#include "lyxfont.h"
-#include "mathed/support.h"
-#include "Painter.h"
-
-int MathedInset::df_asc;
-int MathedInset::df_des;
-int MathedInset::df_width;
-int MathedInset::workWidth;
-
-
-MathedInset::MathedInset(MathedInset * inset) 
-{
-       if (inset) {
-               name = inset->GetName();
-               objtype = inset->GetType();
-               size_ = inset->GetStyle();
-               width = inset->Width();
-               ascent = inset->Ascent();
-               descent = inset->Descent();
-       } else {
-               objtype = LM_OT_UNDEF;
-               size_ = LM_ST_TEXT;
-               width = ascent = descent = 0;
-               //name = 0;
-       }
+#include "debug.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_;
 }
 
 
-MathedInset::MathedInset(string const & nm, short ot, short st)
-       : name(nm), objtype(ot), size_(st) 
+int MathInset::descent() const
 {
-       width = ascent = descent = 0;
+       return descent_;
 }
 
 
-// In a near future maybe we use a better fonts renderer
-void MathedInset::drawStr(Painter & pain, short type, int siz,
-                         int x, int y, string const & s)
+int MathInset::width() const
 {
-       string st;
-       if (MathIsBinary(type))
-               for (string::const_iterator it = s.begin();
-                    it != s.end(); ++it) {
-                       st += ' ';
-                       st += *it;
-                       st += ' ';
-               }
-       else
-               st = s;
-       
-       LyXFont const mf = mathed_get_font(type, siz);
-       pain.text(x, y, st, mf);
+       return width_;
 }
 
 
-int MathedInset::Ascent() const
+int MathInset::height() const
 {
-       return ascent;
+       return ascent_ + descent_;
 }
 
 
-int MathedInset::Descent() const
+int MathInset::limits() const
 {
-       return descent;
+       return false;
 }
 
 
-int MathedInset::Width() const
+void MathInset::limits(int)
+{
+}
+
+string const & MathInset::name() const
 {
-       return width;
+       return name_;
 }
 
 
-int MathedInset::Height() const
+MathInsetTypes MathInset::GetType() const
 {
-       return ascent + descent;
+       return objtype;
 }
 
 
-bool MathedInset::GetLimits() const
+void MathInset::SetType(MathInsetTypes t)
 {
-       return false;
+       objtype = t;
+}
+
+
+void MathInset::SetName(string const & n)
+{
+       name_ = n;
 }
 
 
-void MathedInset::SetLimits(bool) {}   
+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;
+}
 
 
-string const & MathedInset::GetName() const
+int MathInset::xo() const
 {
-       return name;
+       return xo_;
 }
 
 
-short MathedInset::GetType() const
+int MathInset::yo() const
 {
-       return objtype;
+       return yo_;
 }
 
 
-short MathedInset::GetStyle() const
+void MathInset::xo(int x)
 {
-       return size_;
+       xo_ = x;
 }
 
 
-void  MathedInset::SetType(short t)
+void MathInset::yo(int y)
 {
-       objtype = t;
+       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  MathedInset::SetStyle(short st)
+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;
 }
 
 
-void MathedInset::SetName(string const & n)
+bool MathInset::idxLeft(int & idx, int & pos) const
 {
-       name = n;
+       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
+{
+       if (pos == 0)
+               return false;
+       pos = 0;
+       return true;
+}
+
+
+bool MathInset::idxEnd(int & idx, int & pos) const
+{
+       if (pos == cell(idx).size())
+               return false;
+
+       pos = cell(idx).size();
+       return true;
+}
+
+
+bool MathInset::idxFirstUp(int &, int &) const
+{
+       return false;
+}
+
+
+bool MathInset::idxFirstDown(int &, int &) const
+{
+       return false;
+}
+
+void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
+{
+       popit    = false;
+       deleteit = false;
+}
+
+void MathInset::idxDeleteRange(int, int)
+{}
+
+
+bool MathInset::idxLastUp(int &, int &) const
+{
+       return false;
+}
+
+
+bool MathInset::idxLastDown(int &, int &) const
+{
+       return false;
+}
+
+
+void MathInset::GetXY(int & x, int & y) const
+{
+   x = xo();
+   y = yo();
+}
+
+
+/*
+void MathInset::UserSetSize(MathStyles sz)
+{
+       if (sz >= 0) {
+               size_ = sz;      
+               flag = flag & ~LMPF_FIXED_SIZE;
+       }
+}
+*/
 
-void MathedInset::defaultAscent(int da)
+void MathInset::WriteNormal(std::ostream & os) const
 {
-       df_asc = da;
+       os << "[" << name_ << "] ";
 }
 
 
+void MathInset::dump() const
+{
+       lyxerr << "---------------------------------------------\n";
+       Write(lyxerr, false);
+       lyxerr << "\n";
+       for (int i = 0; i < nargs(); ++i)
+               lyxerr << cell(i) << "\n";
+       lyxerr << "---------------------------------------------\n";
+}
+
+
+void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
+{
+       if (nargs())
+               cells_.back().data_.push_back(ch, fcode);
+       else
+               lyxerr << "can't push without a cell\n";
+}
+
 
-void MathedInset::defaultDescent(int dd)
+void MathInset::push_back(MathInset * p)
 {
-       df_des = dd;
+       if (nargs())
+               cells_.back().data_.push_back(p);
+       else
+               lyxerr << "can't push without a cell\n";
 }
 
 
-void MathedInset::defaultWidth(int dw)
+bool MathInset::covers(int x, int y) const
 {
-       df_width = dw;
+       return
+               x >= xo_ &&
+               x <= xo_ + width_ &&
+               y >= yo_ - ascent_ &&
+               y <= yo_ + descent_;
 }
 
+void MathInset::Validate(LaTeXFeatures & features) const
+{
+       for (int i = 0; i < nargs(); ++i)
+               cell(i).Validate(features);
+}
+
+std::vector<int> MathInset::idxBetween(int from, int to) const
+{
+       std::vector<int> res;
+       for (int i = from; i <= to; ++i)
+               res.push_back(i);
+       return res;
+}