+2001-08-08 André Pönitz <poenitz@gmx.net>
+
+ * math_fracbase.[Ch]:
+ * math_fracinset.[Ch]: new hierarchy
+
+ * math_stackrelbase.[Ch]: native \stackrel support
+
+ * math_inset.[Ch]: removal of the name_ member
+
2001-08-06 André Pönitz <poenitz@gmx.net>
* formulamacro.C: fix nasty bug due to missing copy constructor
math_dotsinset.h \
math_fracinset.C \
math_fracinset.h \
+ math_fracbase.C \
+ math_fracbase.h \
math_funcinset.C \
math_funcinset.h \
math_funcliminset.C \
math_spaceinset.h \
math_sqrtinset.C \
math_sqrtinset.h \
+ math_stackrelinset.C \
+ math_stackrelinset.h \
math_symbolinset.C \
math_symbolinset.h \
support.C \
}
-/*
-string MathArray::getString(int & pos) const
-{
- string s;
- if (isInset(pos))
- return s;
-
- MathTextCodes const fcode = getCode(pos);
- do {
- s += getChar(pos);
- ++pos;
- } while (pos < size() && !isInset(pos) && getCode(pos) == fcode);
-
- return s;
-}
-*/
-
-
MathTextCodes MathArray::getCode(int pos) const
{
return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;
#include "mathed/support.h"
#include "math_defs.h"
-#include "LString.h"
class MathInset;
class MathMacro;
MathInset const * nextInset(int pos) const;
///
unsigned char getChar(int pos) const;
- /// read subsequent chars of the same kind.
- // pos is afterwards one behind the last char belonging to the string
- string getString(int & pos) const;
///
MathTextCodes getCode(int pos) const;
///
MathArrayInset::MathArrayInset(int m, int n)
- : MathGridInset(m, n, "array")
+ : MathGridInset(m, n)
{}
#include "math_rootinset.h"
#include "math_spaceinset.h"
#include "math_sqrtinset.h"
+#include "math_stackrelinset.h"
#include "support/lstrings.h"
#include "math_scriptinset.h"
#include "math_parser.h"
break;
case LM_TK_STACK:
- p = new MathFracInset("stackrel");
+ p = new MathStackrelInset;
break;
case LM_TK_FRAC:
- p = new MathFracInset("frac");
+ p = new MathFracInset;
break;
case LM_TK_SQRT:
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_fracbase.h"
+
+
+MathFracbaseInset::MathFracbaseInset()
+ : MathNestInset(2)
+{}
+
+
+bool MathFracbaseInset::idxRight(int &, int &) const
+{
+ return false;
+}
+
+
+bool MathFracbaseInset::idxLeft(int &, int &) const
+{
+ return false;
+}
+
+
+bool MathFracbaseInset::idxUp(int & idx, int &) const
+{
+ if (idx == 0)
+ return false;
+ idx = 0;
+ return true;
+}
+
+
+bool MathFracbaseInset::idxDown(int & idx, int &) const
+{
+ if (idx == 1)
+ return false;
+ idx = 1;
+ return true;
+}
+
+
+bool MathFracbaseInset::idxFirstUp(int & idx, int & pos) const
+{
+ idx = 0;
+ pos = 0;
+ return true;
+}
+
+
+bool MathFracbaseInset::idxFirstDown(int & idx, int & pos) const
+{
+ idx = 1;
+ pos = 0;
+ return true;
+}
+
+
+bool MathFracbaseInset::idxLastUp(int & idx, int & pos) const
+{
+ idx = 0;
+ pos = cell(idx).size();
+ return true;
+}
+
+
+bool MathFracbaseInset::idxLastDown(int & idx, int & pos) const
+{
+ idx = 1;
+ pos = cell(idx).size();
+ return true;
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_FRACBASE_H
+#define MATH_FRACBASE_H
+
+#include "math_nestinset.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+class MathFracbaseInset : public MathNestInset {
+public:
+ ///
+ MathFracbaseInset();
+ ///
+ bool idxUp(int &, int &) const;
+ ///
+ bool idxDown(int &, int &) const;
+ ///
+ bool idxLeft(int &, int &) const;
+ ///
+ bool idxRight(int &, int &) const;
+ ///
+ bool idxFirstUp(int & idx, int & pos) const;
+ ///
+ bool idxFirstDown(int & idx, int & pos) const;
+ ///
+ bool idxLastUp(int & idx, int & pos) const;
+ ///
+ bool idxLastDown(int & idx, int & pos) const;
+};
+
+#endif
#include "support/LOstream.h"
-MathFracInset::MathFracInset(string const & name)
- : MathNestInset(2, name)
+MathFracInset::MathFracInset()
{}
int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5);
xcell(1).draw(pain, m - xcell(1).width() / 2, y + xcell(1).ascent() + 3 - 5);
-
- if (name() == "frac")
- pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
+ pain.line(x + 2, y - 5, x + width() - 4, y - 5, LColor::mathline);
}
void MathFracInset::write(std::ostream & os, bool fragile) const
{
- os << '\\' << name() << '{';
+ os << "\\frac{";
cell(0).write(os, fragile);
os << "}{";
cell(1).write(os, fragile);
void MathFracInset::writeNormal(std::ostream & os) const
{
- os << '[' << name() << ' ';
+ os << "[frac ";
cell(0).writeNormal(os);
os << " ";
cell(1).writeNormal(os);
os << "] ";
}
-
-
-bool MathFracInset::idxRight(int &, int &) const
-{
- return false;
-}
-
-bool MathFracInset::idxLeft(int &, int &) const
-{
- return false;
-}
-
-
-bool MathFracInset::idxUp(int & idx, int &) const
-{
- if (idx == 0)
- return false;
- idx = 0;
- return true;
-}
-
-bool MathFracInset::idxDown(int & idx, int &) const
-{
- if (idx == 1)
- return false;
- idx = 1;
- return true;
-}
-
-bool MathFracInset::idxFirstUp(int & idx, int & pos) const
-{
- idx = 0;
- pos = 0;
- return true;
-}
-
-bool MathFracInset::idxFirstDown(int & idx, int & pos) const
-{
- idx = 1;
- pos = 0;
- return true;
-}
-
-bool MathFracInset::idxLastUp(int & idx, int & pos) const
-{
- idx = 0;
- pos = cell(idx).size();
- return true;
-}
-
-bool MathFracInset::idxLastDown(int & idx, int & pos) const
-{
- idx = 1;
- pos = cell(idx).size();
- return true;
-}
-
#ifndef MATH_FRACINSET_H
#define MATH_FRACINSET_H
-#include "math_nestinset.h"
+#include "math_fracbase.h"
#ifdef __GNUG__
#pragma interface
#endif
-/** Fraction like objects (frac, stackrel, binom)
+/** Fraction like objects (frac, binom)
\author Alejandro Aguilar Sierra
*/
-class MathFracInset : public MathNestInset {
+class MathFracInset : public MathFracbaseInset {
public:
///
- explicit MathFracInset(const string & name);
+ MathFracInset();
///
MathInset * clone() const;
///
void metrics(MathStyles st) const;
///
void draw(Painter &, int x, int y) const;
- ///
- bool idxUp(int &, int &) const;
- ///
- bool idxDown(int &, int &) const;
- ///
- bool idxLeft(int &, int &) const;
- ///
- bool idxRight(int &, int &) const;
- ///
- bool idxFirstUp(int & idx, int & pos) const;
- ///
- bool idxFirstDown(int & idx, int & pos) const;
- ///
- bool idxLastUp(int & idx, int & pos) const;
- ///
- bool idxLastDown(int & idx, int & pos) const;
};
#endif
MathFuncInset::MathFuncInset(string const & nm)
-{
- name_ = nm;
-}
+ : name_(nm)
+{}
MathInset * MathFuncInset::clone() const
}
+string const & MathFuncInset::name() const
+{
+ return name_;
+}
+
+
+void MathFuncInset::setName(string const & n)
+{
+ name_ = n;
+}
+
+
void MathFuncInset::write(std::ostream & os, bool /* fragile */) const
{
os << "\\" << name_ << ' ';
void write(std::ostream &, bool fragile) const;
///
void writeNormal(std::ostream &) const;
+ ///
+ string const & name() const;
+ ///
+ void setName(string const & n);
+private:
+ ///
+ string name_;
};
#endif
{}
-MathGridInset::MathGridInset(int m, int n, string const & nm)
- : MathNestInset(m * n, nm), rowinfo_(n), colinfo_(m), v_align_('c')
+MathGridInset::MathGridInset(int m, int n)
+ : MathNestInset(m * n), rowinfo_(n), colinfo_(m), v_align_('c')
{
if (m <= 0)
lyxerr << "positve number of columns expected\n";
public:
///
- MathGridInset(int m, int n, string const & nm);
+ MathGridInset(int m, int n);
///
void write(std::ostream &, bool fragile) const;
///
int MathInset::workwidth;
-MathInset::MathInset(string const & name)
- : name_(name), size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0)
+MathInset::MathInset()
+ : size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0)
{}
}
-string const & MathInset::name() const
-{
- return name_;
-}
-
-
-void MathInset::setName(string const & n)
-{
- name_ = n;
-}
-
-
MathStyles MathInset::size() const
{
return size_;
void MathInset::writeNormal(std::ostream & os) const
{
- os << "[" << name_ << "] ";
+ os << "[unknown] ";
}
#pragma interface
#endif
-#include "LString.h"
#include "symbol_def.h"
#include "xarray.h"
class MathInset {
public:
///
- explicit MathInset(string const & nm = string());
+ MathInset();
/// the virtual base destructor
virtual ~MathInset() {}
///
virtual int height() const;
///
- virtual string const & name() const;
- ///
- virtual void setName(string const & n);
- ///
virtual MathStyles size() const;
/// Where should we go when we press the up cursor key?
virtual void code(MathTextCodes t);
protected:
- /// usually the LaTeX name of the thingy
- string name_;
/// _sets_ style
void size(MathStyles s) const;
/// the used font size
using std::endl;
MathMacro::MathMacro(MathMacroTemplate const & t)
- : MathNestInset(t.numargs(), t.name()), tmplate_(&t)
+ : MathNestInset(t.numargs()), tmplate_(&t)
{}
return new MathMacro(*this);
}
+string const & MathMacro::name() const
+{
+ return tmplate_->name();
+}
void MathMacro::metrics(MathStyles st) const
{
ascent_ = expanded_.ascent() + 2;
descent_ = expanded_.descent() + 2;
- width_ += mathed_string_width(LM_TC_TEXTRM, size_, name_) + 10;
+ width_ += mathed_string_width(LM_TC_TEXTRM, size_, name()) + 10;
int lasc;
int ldes;
if (mathcursor && mathcursor->isInside(this)) {
int h = y - ascent() + 2 + expanded_.ascent();
- drawStr(pain, LM_TC_TEXTRM, size(), x + 3, h, name_);
+ drawStr(pain, LM_TC_TEXTRM, size(), x + 3, h, name());
- int const w = mathed_string_width(LM_TC_TEXTRM, size(), name_);
+ int const w = mathed_string_width(LM_TC_TEXTRM, size(), name());
expanded_.draw(pain, x + w + 12, h);
h += expanded_.descent();
{
MathMacroTable::dump();
os << "\n macro: '" << this << "'\n";
- os << " name: '" << name_ << "'\n";
+ os << " name: '" << name() << "'\n";
os << " template: '" << tmplate_ << "'\n";
os << " template: '" << *tmplate_ << "'\n";
os << endl;
void MathMacro::write(std::ostream & os, bool fragile) const
{
- os << '\\' << name_;
+ os << '\\' << name();
for (int i = 0; i < nargs(); ++i) {
os << '{';
cell(i).write(os, fragile);
void MathMacro::writeNormal(std::ostream & os) const
{
- os << "[macro " << name_ << " ";
+ os << "[macro " << name() << " ";
for (int i = 0; i < nargs(); ++i) {
cell(i).writeNormal(os);
os << ' ';
void MathMacro::validate(LaTeXFeatures & features) const
{
- if (name_ == "binom")
+ if (name() == "binom")
features.binom = true;
//MathInset::validate(features);
}
void validate(LaTeXFeatures &) const;
private:
+ ///
+ void operator=(MathMacro const &);
+ ///
+ string const & name() const;
+
///
MathMacroTemplate const * const tmplate_;
///
mutable MathXArray expanded_;
- ///
- void operator=(MathMacro const &);
};
// binom has two arguments
{
- MathFracInset * frac = new MathFracInset("atop");
+ MathFracInset * frac = new MathFracInset;
frac->cell(0).push_back(new MathMacroArgument(1));
frac->cell(1).push_back(new MathMacroArgument(2));
MathMacroTemplate::MathMacroTemplate()
- : MathNestInset(1), numargs_(0)
+ : MathNestInset(1), numargs_(0), name_()
{}
MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
- : MathNestInset(1, nm), numargs_(numargs)
+ : MathNestInset(1), numargs_(numargs), name_(nm)
{}
}
+string const & MathMacroTemplate::name() const
+{
+ return name_;
+}
+
+
void MathMacroTemplate::write(std::ostream & os, bool fragile) const
{
os << "\n\\newcommand{\\" << name_ << "}";
///
void numargs(int);
///
+ string const & name() const;
+ ///
void draw(Painter &, int x, int y) const;
///
void metrics(MathStyles st) const;
private:
///
int numargs_;
+ ///
+ string name_;
};
#endif
}
MathMatrixInset::MathMatrixInset(MathInsetTypes t)
- : MathGridInset(getCols(t), 1, "formula"), objtype_(t), nonum_(1), label_(1)
+ : MathGridInset(getCols(t), 1), objtype_(t), nonum_(1), label_(1)
{
halign(getAlign(t, ncols()));
}
MathMatrixInset::MathMatrixInset()
- : MathGridInset(1, 1, "formula"), objtype_(LM_OT_SIMPLE), nonum_(1), label_(1)
+ : MathGridInset(1, 1), objtype_(LM_OT_SIMPLE), nonum_(1), label_(1)
{}
MathInset * MathMatrixInset::clone() const
#include "debug.h"
-MathNestInset::MathNestInset(int nargs, string const & name)
+MathNestInset::MathNestInset(int nargs)
: MathDimInset(), cells_(nargs)
-{
- name_ = name;
-}
+{}
int MathNestInset::nargs() const
class MathNestInset : public MathDimInset {
public:
///
- explicit MathNestInset(int na = 0, string const & nm = string());
+ explicit MathNestInset(int ncells);
///
void metrics(MathStyles st) const;
#include "math_sizeinset.h"
#include "math_spaceinset.h"
#include "math_sqrtinset.h"
+#include "math_stackrelinset.h"
#include "math_symbolinset.h"
#include "debug.h"
#include "mathed/support.h"
static bool curr_num;
static string curr_label;
-void mathed_parse_lines(MathInset * inset, int col,
- bool numbered, bool outmost)
+void mathed_parse_lines(MathGridInset * p, int col, bool numbered, bool outmost)
{
// save global variables
bool const saved_num = curr_num;
string const saved_label = curr_label;
- MathGridInset * p = static_cast<MathGridInset *>(inset);
for (int row = 0; true; ++row) {
// reset global variables
curr_num = numbered;
MathInsetTypes typ = latex_mathenv[i].typ;
p = new MathMatrixInset(typ);
- MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
+
switch (typ) {
case LM_OT_SIMPLE: {
curr_num = latex_mathenv[i].numbered;
curr_label.erase();
- mathed_parse_into(m->cell(0), 0);
- m->numbered(0, curr_num);
- m->label(0, curr_label);
+ mathed_parse_into(p->cell(0), 0);
+ p->numbered(0, curr_num);
+ p->label(0, curr_label);
break;
}
case LM_OT_EQUATION: {
curr_num = latex_mathenv[i].numbered;
curr_label.erase();
- mathed_parse_into(m->cell(0), FLAG_END);
- m->numbered(0, curr_num);
- m->label(0, curr_label);
+ mathed_parse_into(p->cell(0), FLAG_END);
+ p->numbered(0, curr_num);
+ p->label(0, curr_label);
break;
}
case LM_OT_EQNARRAY: {
- mathed_parse_lines(m, 3, latex_mathenv[i].numbered, true);
+ mathed_parse_lines(p, 3, latex_mathenv[i].numbered, true);
break;
}
case LM_OT_ALIGN: {
- m->halign(lexArg('{'));
- mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
+ p->halign(lexArg('{'));
+ mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true);
break;
}
case LM_OT_ALIGNAT: {
- m->halign(lexArg('{'));
- mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true);
+ p->halign(lexArg('{'));
+ mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true);
break;
}
<< "1: unknown math environment: " << typ << "\n";
}
- p->setName(latex_mathenv[i].basename);
-
break;
}
}
-void handle_frac(MathArray & array, string const & name)
-{
- MathFracInset * p = new MathFracInset(name);
- mathed_parse_into(p->cell(0), FLAG_ITEM);
- mathed_parse_into(p->cell(1), FLAG_ITEM);
- array.push_back(p);
-}
-
-
void mathed_parse_into(MathArray & array, unsigned flags)
{
static int plevel = -1;
array.push_back(new MathDotsInset(yylval.l));
break;
- case LM_TK_CHOOSE:
- handle_frac(array, "atop");
- break;
-
case LM_TK_STACK:
- handle_frac(array, "stackrel");
+ {
+ MathStackrelInset * p = new MathStackrelInset;
+ mathed_parse_into(p->cell(0), FLAG_ITEM);
+ mathed_parse_into(p->cell(1), FLAG_ITEM);
+ array.push_back(p);
break;
+ }
case LM_TK_FRAC:
- handle_frac(array, "frac");
+ {
+ MathFracInset * p = new MathFracInset;
+ mathed_parse_into(p->cell(0), FLAG_ITEM);
+ mathed_parse_into(p->cell(1), FLAG_ITEM);
+ array.push_back(p);
break;
+ }
case LM_TK_SQRT:
{
///
LM_TK_FRAC,
///
- LM_TK_CHOOSE,
- ///
LM_TK_SQRT,
///
LM_TK_BEGIN,
MathSizeInset::MathSizeInset(MathStyles st)
: MathNestInset(1), style_(st)
-{
- name_ = verbose();
-}
+{}
-char const * MathSizeInset::verbose() const
+char const * MathSizeInset::name() const
{
switch (style_) {
case LM_ST_DISPLAY:
private:
///
- char const * verbose() const;
+ char const * name() const;
///
MathStyles style_;
};
--- /dev/null
+#ifdef __GNUG__
+#pragma implementation
+#endif
+
+#include "math_stackrelinset.h"
+#include "mathed/support.h"
+#include "support/LOstream.h"
+
+
+MathStackrelInset::MathStackrelInset()
+{}
+
+
+MathInset * MathStackrelInset::clone() const
+{
+ return new MathStackrelInset(*this);
+}
+
+
+void MathStackrelInset::metrics(MathStyles st) const
+{
+ size_ = smallerStyleFrac(st);
+ xcell(0).metrics(size_);
+ xcell(1).metrics(st);
+ width_ = std::max(xcell(0).width(), xcell(1).width()) + 4;
+ ascent_ = xcell(1).ascent() + xcell(0).height() + 4;
+ descent_ = xcell(1).descent();
+}
+
+
+void MathStackrelInset::draw(Painter & pain, int x, int y) const
+{
+ xo(x);
+ yo(y);
+ int m = x + width() / 2;
+ xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).height() - 4);
+ xcell(1).draw(pain, m - xcell(1).width() / 2, y);
+}
+
+
+void MathStackrelInset::write(std::ostream & os, bool fragile) const
+{
+ os << "\\stackrel{";
+ cell(0).write(os, fragile);
+ os << "}{";
+ cell(1).write(os, fragile);
+ os << '}';
+}
+
+
+void MathStackrelInset::writeNormal(std::ostream & os) const
+{
+ os << "[stackrel ";
+ cell(0).writeNormal(os);
+ os << " ";
+ cell(1).writeNormal(os);
+ os << "] ";
+}
--- /dev/null
+// -*- C++ -*-
+#ifndef MATH_STACKRELINSET_H
+#define MATH_STACKRELINSET_H
+
+#include "math_fracbase.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/** Stackrel objects
+ \author André Pönitz
+ */
+class MathStackrelInset : public MathFracbaseInset {
+public:
+ ///
+ MathStackrelInset();
+ ///
+ MathInset * clone() const;
+ ///
+ void write(std::ostream &, bool fragile) const;
+ ///
+ void writeNormal(std::ostream &) const;
+ ///
+ void metrics(MathStyles st) const;
+ ///
+ void draw(Painter &, int x, int y) const;
+};
+
+#endif