new hierarchy for frac-like things

'native' \stackrel support
remove MathInset::name_ member (sizeof(MathInset) == 20 on IA32 now);


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2457 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-08-08 17:26:30 +00:00
parent 252b1e560c
commit cbf29c8fdc
30 changed files with 310 additions and 197 deletions

View File

@ -1,4 +1,13 @@
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> 2001-08-06 André Pönitz <poenitz@gmx.net>
* formulamacro.C: fix nasty bug due to missing copy constructor * formulamacro.C: fix nasty bug due to missing copy constructor

View File

@ -39,6 +39,8 @@ libmathed_la_SOURCES = \
math_dotsinset.h \ math_dotsinset.h \
math_fracinset.C \ math_fracinset.C \
math_fracinset.h \ math_fracinset.h \
math_fracbase.C \
math_fracbase.h \
math_funcinset.C \ math_funcinset.C \
math_funcinset.h \ math_funcinset.h \
math_funcliminset.C \ math_funcliminset.C \
@ -72,6 +74,8 @@ libmathed_la_SOURCES = \
math_spaceinset.h \ math_spaceinset.h \
math_sqrtinset.C \ math_sqrtinset.C \
math_sqrtinset.h \ math_sqrtinset.h \
math_stackrelinset.C \
math_stackrelinset.h \
math_symbolinset.C \ math_symbolinset.C \
math_symbolinset.h \ math_symbolinset.h \
support.C \ support.C \

View File

@ -87,24 +87,6 @@ unsigned char MathArray::getChar(int pos) const
} }
/*
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 MathTextCodes MathArray::getCode(int pos) const
{ {
return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN; return pos < size() ? (bf_[pos]->code()) : LM_TC_MIN;

View File

@ -21,7 +21,6 @@
#include "mathed/support.h" #include "mathed/support.h"
#include "math_defs.h" #include "math_defs.h"
#include "LString.h"
class MathInset; class MathInset;
class MathMacro; class MathMacro;
@ -104,9 +103,6 @@ public:
MathInset const * nextInset(int pos) const; MathInset const * nextInset(int pos) const;
/// ///
unsigned char getChar(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; MathTextCodes getCode(int pos) const;
/// ///

View File

@ -7,7 +7,7 @@
MathArrayInset::MathArrayInset(int m, int n) MathArrayInset::MathArrayInset(int m, int n)
: MathGridInset(m, n, "array") : MathGridInset(m, n)
{} {}

View File

@ -47,6 +47,7 @@
#include "math_rootinset.h" #include "math_rootinset.h"
#include "math_spaceinset.h" #include "math_spaceinset.h"
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "math_stackrelinset.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "math_scriptinset.h" #include "math_scriptinset.h"
#include "math_parser.h" #include "math_parser.h"
@ -686,11 +687,11 @@ void MathCursor::interpret(string const & s)
break; break;
case LM_TK_STACK: case LM_TK_STACK:
p = new MathFracInset("stackrel"); p = new MathStackrelInset;
break; break;
case LM_TK_FRAC: case LM_TK_FRAC:
p = new MathFracInset("frac"); p = new MathFracInset;
break; break;
case LM_TK_SQRT: case LM_TK_SQRT:

View File

@ -0,0 +1,72 @@
#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;
}

View File

@ -0,0 +1,33 @@
// -*- 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

View File

@ -8,8 +8,7 @@
#include "support/LOstream.h" #include "support/LOstream.h"
MathFracInset::MathFracInset(string const & name) MathFracInset::MathFracInset()
: MathNestInset(2, name)
{} {}
@ -37,15 +36,13 @@ void MathFracInset::draw(Painter & pain, int x, int y) const
int m = x + width() / 2; int m = x + width() / 2;
xcell(0).draw(pain, m - xcell(0).width() / 2, y - xcell(0).descent() - 3 - 5); 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); 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 void MathFracInset::write(std::ostream & os, bool fragile) const
{ {
os << '\\' << name() << '{'; os << "\\frac{";
cell(0).write(os, fragile); cell(0).write(os, fragile);
os << "}{"; os << "}{";
cell(1).write(os, fragile); cell(1).write(os, fragile);
@ -55,66 +52,9 @@ void MathFracInset::write(std::ostream & os, bool fragile) const
void MathFracInset::writeNormal(std::ostream & os) const void MathFracInset::writeNormal(std::ostream & os) const
{ {
os << '[' << name() << ' '; os << "[frac ";
cell(0).writeNormal(os); cell(0).writeNormal(os);
os << " "; os << " ";
cell(1).writeNormal(os); cell(1).writeNormal(os);
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;
}

View File

@ -2,19 +2,19 @@
#ifndef MATH_FRACINSET_H #ifndef MATH_FRACINSET_H
#define MATH_FRACINSET_H #define MATH_FRACINSET_H
#include "math_nestinset.h" #include "math_fracbase.h"
#ifdef __GNUG__ #ifdef __GNUG__
#pragma interface #pragma interface
#endif #endif
/** Fraction like objects (frac, stackrel, binom) /** Fraction like objects (frac, binom)
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
class MathFracInset : public MathNestInset { class MathFracInset : public MathFracbaseInset {
public: public:
/// ///
explicit MathFracInset(const string & name); MathFracInset();
/// ///
MathInset * clone() const; MathInset * clone() const;
/// ///
@ -25,22 +25,6 @@ public:
void metrics(MathStyles st) const; void metrics(MathStyles st) const;
/// ///
void draw(Painter &, int x, int y) 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 #endif

View File

@ -15,9 +15,8 @@ extern LyXFont WhichFont(short type, int size);
MathFuncInset::MathFuncInset(string const & nm) MathFuncInset::MathFuncInset(string const & nm)
{ : name_(nm)
name_ = nm; {}
}
MathInset * MathFuncInset::clone() const MathInset * MathFuncInset::clone() const
@ -26,6 +25,18 @@ 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 void MathFuncInset::write(std::ostream & os, bool /* fragile */) const
{ {
os << "\\" << name_ << ' '; os << "\\" << name_ << ' ';

View File

@ -26,5 +26,12 @@ public:
void write(std::ostream &, bool fragile) const; void write(std::ostream &, bool fragile) const;
/// ///
void writeNormal(std::ostream &) const; void writeNormal(std::ostream &) const;
///
string const & name() const;
///
void setName(string const & n);
private:
///
string name_;
}; };
#endif #endif

View File

@ -29,8 +29,8 @@ MathGridInset::ColInfo::ColInfo()
{} {}
MathGridInset::MathGridInset(int m, int n, string const & nm) MathGridInset::MathGridInset(int m, int n)
: MathNestInset(m * n, nm), rowinfo_(n), colinfo_(m), v_align_('c') : MathNestInset(m * n), rowinfo_(n), colinfo_(m), v_align_('c')
{ {
if (m <= 0) if (m <= 0)
lyxerr << "positve number of columns expected\n"; lyxerr << "positve number of columns expected\n";

View File

@ -52,7 +52,7 @@ class MathGridInset : public MathNestInset {
public: public:
/// ///
MathGridInset(int m, int n, string const & nm); MathGridInset(int m, int n);
/// ///
void write(std::ostream &, bool fragile) const; void write(std::ostream &, bool fragile) const;
/// ///

View File

@ -26,8 +26,8 @@
int MathInset::workwidth; int MathInset::workwidth;
MathInset::MathInset(string const & name) MathInset::MathInset()
: name_(name), size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0) : size_(LM_ST_DISPLAY), code_(LM_TC_MIN), xo_(0), yo_(0)
{} {}
@ -37,18 +37,6 @@ int MathInset::height() const
} }
string const & MathInset::name() const
{
return name_;
}
void MathInset::setName(string const & n)
{
name_ = n;
}
MathStyles MathInset::size() const MathStyles MathInset::size() const
{ {
return size_; return size_;
@ -248,7 +236,7 @@ void MathInset::userSetSize(MathStyles sz)
void MathInset::writeNormal(std::ostream & os) const void MathInset::writeNormal(std::ostream & os) const
{ {
os << "[" << name_ << "] "; os << "[unknown] ";
} }

View File

@ -28,7 +28,6 @@
#pragma interface #pragma interface
#endif #endif
#include "LString.h"
#include "symbol_def.h" #include "symbol_def.h"
#include "xarray.h" #include "xarray.h"
@ -44,7 +43,7 @@ class LaTeXFeatures;
class MathInset { class MathInset {
public: public:
/// ///
explicit MathInset(string const & nm = string()); MathInset();
/// the virtual base destructor /// the virtual base destructor
virtual ~MathInset() {} virtual ~MathInset() {}
@ -70,10 +69,6 @@ public:
/// ///
virtual int height() const; virtual int height() const;
/// ///
virtual string const & name() const;
///
virtual void setName(string const & n);
///
virtual MathStyles size() const; virtual MathStyles size() const;
/// Where should we go when we press the up cursor key? /// Where should we go when we press the up cursor key?
@ -205,8 +200,6 @@ public:
virtual void code(MathTextCodes t); virtual void code(MathTextCodes t);
protected: protected:
/// usually the LaTeX name of the thingy
string name_;
/// _sets_ style /// _sets_ style
void size(MathStyles s) const; void size(MathStyles s) const;
/// the used font size /// the used font size

View File

@ -33,7 +33,7 @@
using std::endl; using std::endl;
MathMacro::MathMacro(MathMacroTemplate const & t) MathMacro::MathMacro(MathMacroTemplate const & t)
: MathNestInset(t.numargs(), t.name()), tmplate_(&t) : MathNestInset(t.numargs()), tmplate_(&t)
{} {}
@ -48,6 +48,10 @@ MathInset * MathMacro::clone() const
return new MathMacro(*this); return new MathMacro(*this);
} }
string const & MathMacro::name() const
{
return tmplate_->name();
}
void MathMacro::metrics(MathStyles st) const void MathMacro::metrics(MathStyles st) const
{ {
@ -59,7 +63,7 @@ void MathMacro::metrics(MathStyles st) const
ascent_ = expanded_.ascent() + 2; ascent_ = expanded_.ascent() + 2;
descent_ = expanded_.descent() + 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 lasc;
int ldes; int ldes;
@ -97,9 +101,9 @@ void MathMacro::draw(Painter & pain, int x, int y) const
if (mathcursor && mathcursor->isInside(this)) { if (mathcursor && mathcursor->isInside(this)) {
int h = y - ascent() + 2 + expanded_.ascent(); 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); expanded_.draw(pain, x + w + 12, h);
h += expanded_.descent(); h += expanded_.descent();
@ -132,7 +136,7 @@ void MathMacro::dump(std::ostream & os) const
{ {
MathMacroTable::dump(); MathMacroTable::dump();
os << "\n macro: '" << this << "'\n"; os << "\n macro: '" << this << "'\n";
os << " name: '" << name_ << "'\n"; os << " name: '" << name() << "'\n";
os << " template: '" << tmplate_ << "'\n"; os << " template: '" << tmplate_ << "'\n";
os << " template: '" << *tmplate_ << "'\n"; os << " template: '" << *tmplate_ << "'\n";
os << endl; os << endl;
@ -140,7 +144,7 @@ void MathMacro::dump(std::ostream & os) const
void MathMacro::write(std::ostream & os, bool fragile) const void MathMacro::write(std::ostream & os, bool fragile) const
{ {
os << '\\' << name_; os << '\\' << name();
for (int i = 0; i < nargs(); ++i) { for (int i = 0; i < nargs(); ++i) {
os << '{'; os << '{';
cell(i).write(os, fragile); cell(i).write(os, fragile);
@ -153,7 +157,7 @@ void MathMacro::write(std::ostream & os, bool fragile) const
void MathMacro::writeNormal(std::ostream & os) const void MathMacro::writeNormal(std::ostream & os) const
{ {
os << "[macro " << name_ << " "; os << "[macro " << name() << " ";
for (int i = 0; i < nargs(); ++i) { for (int i = 0; i < nargs(); ++i) {
cell(i).writeNormal(os); cell(i).writeNormal(os);
os << ' '; os << ' ';
@ -188,7 +192,7 @@ bool MathMacro::idxRight(int &, int &) const
void MathMacro::validate(LaTeXFeatures & features) const void MathMacro::validate(LaTeXFeatures & features) const
{ {
if (name_ == "binom") if (name() == "binom")
features.binom = true; features.binom = true;
//MathInset::validate(features); //MathInset::validate(features);
} }

View File

@ -66,12 +66,15 @@ public:
void validate(LaTeXFeatures &) const; void validate(LaTeXFeatures &) const;
private: private:
///
void operator=(MathMacro const &);
///
string const & name() const;
/// ///
MathMacroTemplate const * const tmplate_; MathMacroTemplate const * const tmplate_;
/// ///
mutable MathXArray expanded_; mutable MathXArray expanded_;
///
void operator=(MathMacro const &);
}; };

View File

@ -102,7 +102,7 @@ void MathMacroTable::builtinMacros()
// binom has two arguments // binom has two arguments
{ {
MathFracInset * frac = new MathFracInset("atop"); MathFracInset * frac = new MathFracInset;
frac->cell(0).push_back(new MathMacroArgument(1)); frac->cell(0).push_back(new MathMacroArgument(1));
frac->cell(1).push_back(new MathMacroArgument(2)); frac->cell(1).push_back(new MathMacroArgument(2));

View File

@ -8,12 +8,12 @@
MathMacroTemplate::MathMacroTemplate() MathMacroTemplate::MathMacroTemplate()
: MathNestInset(1), numargs_(0) : MathNestInset(1), numargs_(0), name_()
{} {}
MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs) MathMacroTemplate::MathMacroTemplate(string const & nm, int numargs)
: MathNestInset(1, nm), numargs_(numargs) : MathNestInset(1), numargs_(numargs), name_(nm)
{} {}
@ -36,6 +36,12 @@ void MathMacroTemplate::numargs(int numargs)
} }
string const & MathMacroTemplate::name() const
{
return name_;
}
void MathMacroTemplate::write(std::ostream & os, bool fragile) const void MathMacroTemplate::write(std::ostream & os, bool fragile) const
{ {
os << "\n\\newcommand{\\" << name_ << "}"; os << "\n\\newcommand{\\" << name_ << "}";

View File

@ -30,12 +30,16 @@ public:
/// ///
void numargs(int); void numargs(int);
/// ///
string const & name() const;
///
void draw(Painter &, int x, int y) const; void draw(Painter &, int x, int y) const;
/// ///
void metrics(MathStyles st) const; void metrics(MathStyles st) const;
private: private:
/// ///
int numargs_; int numargs_;
///
string name_;
}; };
#endif #endif

View File

@ -77,14 +77,14 @@ int firstRelOp(MathArray const & array)
} }
MathMatrixInset::MathMatrixInset(MathInsetTypes t) 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())); halign(getAlign(t, ncols()));
} }
MathMatrixInset::MathMatrixInset() 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 MathInset * MathMatrixInset::clone() const

View File

@ -6,11 +6,9 @@
#include "debug.h" #include "debug.h"
MathNestInset::MathNestInset(int nargs, string const & name) MathNestInset::MathNestInset(int nargs)
: MathDimInset(), cells_(nargs) : MathDimInset(), cells_(nargs)
{ {}
name_ = name;
}
int MathNestInset::nargs() const int MathNestInset::nargs() const

View File

@ -16,7 +16,7 @@ class LaTeXFeatures;
class MathNestInset : public MathDimInset { class MathNestInset : public MathDimInset {
public: public:
/// ///
explicit MathNestInset(int na = 0, string const & nm = string()); explicit MathNestInset(int ncells);
/// ///
void metrics(MathStyles st) const; void metrics(MathStyles st) const;

View File

@ -45,6 +45,7 @@
#include "math_sizeinset.h" #include "math_sizeinset.h"
#include "math_spaceinset.h" #include "math_spaceinset.h"
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "math_stackrelinset.h"
#include "math_symbolinset.h" #include "math_symbolinset.h"
#include "debug.h" #include "debug.h"
#include "mathed/support.h" #include "mathed/support.h"
@ -386,14 +387,12 @@ MathInset * lastScriptInset(MathArray & array, bool up, bool down, int limits)
static bool curr_num; static bool curr_num;
static string curr_label; static string curr_label;
void mathed_parse_lines(MathInset * inset, int col, void mathed_parse_lines(MathGridInset * p, int col, bool numbered, bool outmost)
bool numbered, bool outmost)
{ {
// save global variables // save global variables
bool const saved_num = curr_num; bool const saved_num = curr_num;
string const saved_label = curr_label; string const saved_label = curr_label;
MathGridInset * p = static_cast<MathGridInset *>(inset);
for (int row = 0; true; ++row) { for (int row = 0; true; ++row) {
// reset global variables // reset global variables
curr_num = numbered; curr_num = numbered;
@ -456,41 +455,41 @@ MathMatrixInset * mathed_parse_normal()
MathInsetTypes typ = latex_mathenv[i].typ; MathInsetTypes typ = latex_mathenv[i].typ;
p = new MathMatrixInset(typ); p = new MathMatrixInset(typ);
MathMatrixInset * m = static_cast<MathMatrixInset *>(p);
switch (typ) { switch (typ) {
case LM_OT_SIMPLE: { case LM_OT_SIMPLE: {
curr_num = latex_mathenv[i].numbered; curr_num = latex_mathenv[i].numbered;
curr_label.erase(); curr_label.erase();
mathed_parse_into(m->cell(0), 0); mathed_parse_into(p->cell(0), 0);
m->numbered(0, curr_num); p->numbered(0, curr_num);
m->label(0, curr_label); p->label(0, curr_label);
break; break;
} }
case LM_OT_EQUATION: { case LM_OT_EQUATION: {
curr_num = latex_mathenv[i].numbered; curr_num = latex_mathenv[i].numbered;
curr_label.erase(); curr_label.erase();
mathed_parse_into(m->cell(0), FLAG_END); mathed_parse_into(p->cell(0), FLAG_END);
m->numbered(0, curr_num); p->numbered(0, curr_num);
m->label(0, curr_label); p->label(0, curr_label);
break; break;
} }
case LM_OT_EQNARRAY: { 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; break;
} }
case LM_OT_ALIGN: { case LM_OT_ALIGN: {
m->halign(lexArg('{')); p->halign(lexArg('{'));
mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true); mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true);
break; break;
} }
case LM_OT_ALIGNAT: { case LM_OT_ALIGNAT: {
m->halign(lexArg('{')); p->halign(lexArg('{'));
mathed_parse_lines(m, 2, latex_mathenv[i].numbered, true); mathed_parse_lines(p, 2, latex_mathenv[i].numbered, true);
break; break;
} }
@ -499,8 +498,6 @@ MathMatrixInset * mathed_parse_normal()
<< "1: unknown math environment: " << typ << "\n"; << "1: unknown math environment: " << typ << "\n";
} }
p->setName(latex_mathenv[i].basename);
break; break;
} }
@ -513,15 +510,6 @@ MathMatrixInset * mathed_parse_normal()
} }
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) void mathed_parse_into(MathArray & array, unsigned flags)
{ {
static int plevel = -1; static int plevel = -1;
@ -686,17 +674,23 @@ void mathed_parse_into(MathArray & array, unsigned flags)
array.push_back(new MathDotsInset(yylval.l)); array.push_back(new MathDotsInset(yylval.l));
break; break;
case LM_TK_CHOOSE:
handle_frac(array, "atop");
break;
case LM_TK_STACK: 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; break;
}
case LM_TK_FRAC: 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; break;
}
case LM_TK_SQRT: case LM_TK_SQRT:
{ {

View File

@ -47,8 +47,6 @@ enum MathTokenEnum
/// ///
LM_TK_FRAC, LM_TK_FRAC,
/// ///
LM_TK_CHOOSE,
///
LM_TK_SQRT, LM_TK_SQRT,
/// ///
LM_TK_BEGIN, LM_TK_BEGIN,

View File

@ -8,12 +8,10 @@
MathSizeInset::MathSizeInset(MathStyles st) MathSizeInset::MathSizeInset(MathStyles st)
: MathNestInset(1), style_(st) : MathNestInset(1), style_(st)
{ {}
name_ = verbose();
}
char const * MathSizeInset::verbose() const char const * MathSizeInset::name() const
{ {
switch (style_) { switch (style_) {
case LM_ST_DISPLAY: case LM_ST_DISPLAY:

View File

@ -30,7 +30,7 @@ public:
private: private:
/// ///
char const * verbose() const; char const * name() const;
/// ///
MathStyles style_; MathStyles style_;
}; };

View File

@ -0,0 +1,58 @@
#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 << "] ";
}

View File

@ -0,0 +1,30 @@
// -*- 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