fix macro, small cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1623 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-26 12:53:35 +00:00
parent b6cff00278
commit 2be247f6ef
23 changed files with 964 additions and 891 deletions

View File

@ -1,3 +1,21 @@
2001-02-26 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* math_macroarg.C (MathMacroArgument): delete
* math_macro.C (~MathMacro): delete
* math_macrotemplate.C (~MathMacroTemplate): delete
* math_decorationinset.[Ch]: add pragma
* math_deliminset.[Ch]: likewise
* math_fracinset.[Ch]: likewise
* math_macroarg.[Ch]: likewise
* math_macrotemplate.[Ch]: likewise
* math_matrixinset.[Ch]: likewise
* formulamacro.C (Read): set contents of tmacro_ to ar.
* formulamacro.h: add '_' to private variables.
* formalamacro.C: changes because of this.
2001-02-23 Juergen Vigna <jug@sad.it> 2001-02-23 Juergen Vigna <jug@sad.it>
* formula.C (LocalDispatch): changed action to be a kb_action (as it * formula.C (LocalDispatch): changed action to be a kb_action (as it

View File

@ -34,6 +34,7 @@
#include "support/lyxlib.h" #include "support/lyxlib.h"
#include "mathed/support.h" #include "mathed/support.h"
#include "support/LOstream.h" #include "support/LOstream.h"
#include "debug.h"
using std::ostream; using std::ostream;
using std::istream; using std::istream;
@ -41,20 +42,20 @@ using std::istream;
InsetFormulaMacro::InsetFormulaMacro() InsetFormulaMacro::InsetFormulaMacro()
: InsetFormula(true) : InsetFormula(true)
{ {
tmacro = 0; tmacro_ = 0;
opened = false; opened_ = false;
} }
InsetFormulaMacro::InsetFormulaMacro(string nm, int na, bool /*e*/) InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
: InsetFormula(true), name(nm) : InsetFormula(true), name_(nm)
{ {
tmacro = MathMacroTable::mathMTable.getTemplate(name); tmacro_ = MathMacroTable::mathMTable.getTemplate(name_);
if (!tmacro) { if (!tmacro_) {
tmacro = new MathMacroTemplate(name.c_str(), na); tmacro_ = new MathMacroTemplate(name_, na);
MathMacroTable::mathMTable.addTemplate(tmacro); MathMacroTable::mathMTable.addTemplate(tmacro_);
} }
opened = false; opened_ = false;
} }
@ -66,21 +67,21 @@ InsetFormulaMacro::~InsetFormulaMacro()
Inset * InsetFormulaMacro::Clone(Buffer const &) const Inset * InsetFormulaMacro::Clone(Buffer const &) const
{ {
return new InsetFormulaMacro(name); return new InsetFormulaMacro(name_);
} }
void InsetFormulaMacro::Write(Buffer const *, ostream & os) const void InsetFormulaMacro::Write(Buffer const *, ostream & os) const
{ {
os << "FormulaMacro "; os << "FormulaMacro ";
tmacro->WriteDef(os, false); tmacro_->WriteDef(os, false);
} }
int InsetFormulaMacro::Latex(Buffer const *, ostream & os, bool /*fragile*/, int InsetFormulaMacro::Latex(Buffer const *, ostream & os, bool /*fragile*/,
bool /*free_spacing*/) const bool /*free_spacing*/) const
{ {
tmacro->WriteDef(os, true); // or false? tmacro_->WriteDef(os, true); // or false?
return 2; return 2;
} }
@ -102,14 +103,18 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
istream & is = lex.getStream(); istream & is = lex.getStream();
mathed_parser_file(is, lex.GetLineNo()); mathed_parser_file(is, lex.GetLineNo());
MathedArray ar; MathedArray ar;
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro));
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_));
tmacro_->setData(ar);
// Update line number // Update line number
lex.setLineNo(mathed_parser_lineno()); lex.setLineNo(mathed_parser_lineno());
MathMacroTable::mathMTable.addTemplate(tmacro); MathMacroTable::mathMTable.addTemplate(tmacro_);
name = tmacro->GetName(); name_ = tmacro_->GetName();
par = tmacro; par = tmacro_;
// reading of end_inset in the inset!!! // reading of end_inset in the inset!!!
while (lex.IsOK()) { while (lex.IsOK()) {
lex.nextToken(); lex.nextToken();
@ -121,8 +126,8 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
{ {
if (opened) { if (opened_) {
tmacro->update(); tmacro_->update();
return InsetFormula::ascent(pain, f); return InsetFormula::ascent(pain, f);
} }
return lyxfont::maxAscent(f) + 3; return lyxfont::maxAscent(f) + 3;
@ -131,8 +136,8 @@ int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
{ {
if (opened) { if (opened_) {
tmacro->update(); tmacro_->update();
return InsetFormula::descent(pain, f); return InsetFormula::descent(pain, f);
} }
return lyxfont::maxDescent(f) + 1; return lyxfont::maxDescent(f) + 1;
@ -141,12 +146,12 @@ int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
{ {
if (opened) { if (opened_) {
tmacro->update(); tmacro_->update();
return InsetFormula::width(bv, f); return InsetFormula::width(bv, f);
} }
string ilabel(_("Macro: ")); string ilabel(_("Macro: "));
ilabel += name; ilabel += name_;
return 6 + lyxfont::width(ilabel, f); return 6 + lyxfont::width(ilabel, f);
} }
@ -156,11 +161,11 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
{ {
Painter & pain = bv->painter(); Painter & pain = bv->painter();
LyXFont font(f); LyXFont font(f);
tmacro->update(); tmacro_->update();
if (opened) { if (opened_) {
tmacro->setEditMode(true); tmacro_->setEditMode(true);
InsetFormula::draw(bv, font, baseline, x, cleared); InsetFormula::draw(bv, font, baseline, x, cleared);
tmacro->setEditMode(false); tmacro_->setEditMode(false);
} else { } else {
font.setColor(LColor::math); font.setColor(LColor::math);
@ -172,7 +177,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f,
pain.rectangle(int(x), y, w, h, LColor::mathframe); pain.rectangle(int(x), y, w, h, LColor::mathframe);
string s(_("Macro: ")); string s(_("Macro: "));
s += name; s += name_;
pain.text(int(x + 2), baseline, s, font); pain.text(int(x + 2), baseline, s, font);
x += width(bv, font) - 1; x += width(bv, font) - 1;
} }
@ -187,17 +192,17 @@ string const InsetFormulaMacro::EditMessage() const
void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button) void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
{ {
opened = true; opened_ = true;
par = static_cast<MathParInset*>(tmacro->Clone()); par = static_cast<MathParInset*>(tmacro_->Clone());
InsetFormula::Edit(bv, x, y, button); InsetFormula::Edit(bv, x, y, button);
} }
void InsetFormulaMacro::InsetUnlock(BufferView * bv) void InsetFormulaMacro::InsetUnlock(BufferView * bv)
{ {
opened = false; opened_ = false;
tmacro->setData(par->GetData()); tmacro_->setData(par->GetData());
tmacro->setEditMode(false); tmacro_->setEditMode(false);
InsetFormula::InsetUnlock(bv); InsetFormula::InsetUnlock(bv);
} }
@ -207,19 +212,19 @@ InsetFormulaMacro::LocalDispatch(BufferView * bv,
kb_action action, string const & arg) kb_action action, string const & arg)
{ {
if (action == LFUN_MATH_MACROARG) { if (action == LFUN_MATH_MACROARG) {
int i = lyx::atoi(arg) - 1; int const i = lyx::atoi(arg) - 1;
if (i >= 0 && i < tmacro->getNoArgs()) { if (i >= 0 && i < tmacro_->getNoArgs()) {
mathcursor->insertInset(tmacro->getMacroPar(i), mathcursor->insertInset(tmacro_->getMacroPar(i),
LM_TC_INSET); LM_TC_INSET);
InsetFormula::UpdateLocal(bv); InsetFormula::UpdateLocal(bv);
} }
return DISPATCHED; return DISPATCHED;
} }
tmacro->setEditMode(true); tmacro_->setEditMode(true);
tmacro->Metrics(); tmacro_->Metrics();
RESULT result = InsetFormula::LocalDispatch(bv, action, arg); RESULT result = InsetFormula::LocalDispatch(bv, action, arg);
tmacro->setEditMode(false); tmacro_->setEditMode(false);
return result; return result;
} }

View File

@ -33,7 +33,7 @@ public:
InsetFormulaMacro(); InsetFormulaMacro();
/// ///
explicit explicit
InsetFormulaMacro(string name, int na = 0, bool env = false); InsetFormulaMacro(string name, int na = 0);
/// ///
~InsetFormulaMacro(); ~InsetFormulaMacro();
/// ///
@ -58,7 +58,7 @@ public:
/// ///
Inset * Clone(Buffer const &) const; Inset * Clone(Buffer const &) const;
/// ///
Inset::Code LyxCode() const { return Inset::MATHMACRO_CODE; } Inset::Code LyxCode() const;
/// what appears in the minibuffer when opening /// what appears in the minibuffer when opening
string const EditMessage() const; string const EditMessage() const;
/// ///
@ -70,11 +70,17 @@ public:
private: private:
/// ///
bool opened; bool opened_;
/// ///
string name; string name_;
/// ///
MathMacroTemplate * tmacro; MathMacroTemplate * tmacro_;
}; };
inline
Inset::Code InsetFormulaMacro::LyxCode() const
{
return Inset::MATHMACRO_CODE;
}
#endif #endif

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_decorationinset.h" #include "math_decorationinset.h"
#include "math_iter.h" #include "math_iter.h"
#include "mathed/support.h" #include "mathed/support.h"
@ -39,8 +43,8 @@ MathDecorationInset::draw(Painter & pain, int x, int y)
void void
MathDecorationInset::Metrics() MathDecorationInset::Metrics()
{ {
int h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I', int const h = 2 * mathed_char_height(LM_TC_VAR, size(), 'I',
ascent, descent); ascent, descent);
MathParInset::Metrics(); MathParInset::Metrics();
int w = Width() + 4; int w = Width() + 4;
if (w < 16) w = 16; if (w < 16) w = 16;

View File

@ -1,12 +1,17 @@
// -*- C++ -*-
#ifndef MATH_DECORATIONINSET_H #ifndef MATH_DECORATIONINSET_H
#define MATH_DECORATIONINSET_H #define MATH_DECORATIONINSET_H
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Decorations over (below) a math object /** Decorations over (below) a math object
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
class MathDecorationInset: public MathParInset { class MathDecorationInset : public MathParInset {
public: public:
/// ///
MathDecorationInset(int, short st = LM_ST_TEXT); MathDecorationInset(int, short st = LM_ST_TEXT);

View File

@ -120,7 +120,7 @@ enum MathedTextCodes {
LM_TC_MAX LM_TC_MAX
}; };
/// /// Defined in math_macro.C
std::ostream & operator<<(std::ostream &, MathedTextCodes mtc); std::ostream & operator<<(std::ostream &, MathedTextCodes mtc);

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_deliminset.h" #include "math_deliminset.h"
#include "math_iter.h" #include "math_iter.h"
#include "math_parser.h" #include "math_parser.h"
@ -78,8 +82,8 @@ void
MathDelimInset::Metrics() MathDelimInset::Metrics()
{ {
MathParInset::Metrics(); MathParInset::Metrics();
int d;
int d;
mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_); mathed_char_height(LM_TC_CONST, size(), 'I', d, dh_);
dh_ /= 2; dh_ /= 2;
ascent += 2 + dh_; ascent += 2 + dh_;

View File

@ -4,6 +4,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** A delimiter /** A delimiter
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_fracinset.h" #include "math_fracinset.h"
#include "math_iter.h" #include "math_iter.h"
#include "LColor.h" #include "LColor.h"
@ -96,7 +100,7 @@ MathedArray & MathFracInset::GetData()
bool MathFracInset::Inside(int x, int y) bool MathFracInset::Inside(int x, int y)
{ {
int xx = xo() - (width - w0_) / 2; int const xx = xo() - (width - w0_) / 2;
return x >= xx return x >= xx
&& x <= xx + width && x <= xx + width

View File

@ -4,6 +4,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Fraction like objects (frac, stackrel, binom) /** Fraction like objects (frac, stackrel, binom)
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */

View File

@ -75,11 +75,6 @@ MathMacro::MathMacro(MathMacro * m):
} }
MathMacro::~MathMacro()
{
}
MathedInset * MathMacro::Clone() MathedInset * MathMacro::Clone()
{ {
return new MathMacro(this); return new MathMacro(this);

View File

@ -41,8 +41,6 @@ public:
explicit explicit
MathMacro(MathMacro *); MathMacro(MathMacro *);
/// ///
~MathMacro();
///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
void Metrics(); void Metrics();

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macroarg.h" #include "math_macroarg.h"
#include "mathed/support.h" #include "mathed/support.h"
#include "debug.h" #include "debug.h"
@ -19,12 +23,6 @@ MathMacroArgument::MathMacroArgument(int n)
} }
MathMacroArgument::~MathMacroArgument()
{
lyxerr << "help, destroyme!" << std::endl;
}
MathedInset * MathMacroArgument::Clone() MathedInset * MathMacroArgument::Clone()
{ {
return this; return this;

View File

@ -4,36 +4,38 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** A macro argument /** A macro argument
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra
*/ */
class MathMacroArgument: public MathParInset { class MathMacroArgument: public MathParInset {
public: public:
/// ///
MathMacroArgument(); MathMacroArgument();
/// ///
explicit explicit
MathMacroArgument(int); MathMacroArgument(int);
/// ///
~MathMacroArgument(); MathedInset * Clone();
/// ///
MathedInset * Clone(); void Metrics();
/// ///
void Metrics(); void draw(Painter &, int x, int baseline);
/// ///
void draw(Painter &, int x, int baseline); void Write(std::ostream &, bool fragile);
/// ///
void Write(std::ostream &, bool fragile); void setNumber(int n);
/// /// Is expanded or not
void setNumber(int n); void setExpand(bool e);
/// Is expanded or not /// Is expanded or not
void setExpand(bool e); bool getExpand() const;
/// Is expanded or not
bool getExpand() const;
private: private:
/// ///
bool expnd_mode_; bool expnd_mode_;
/// ///
int number_; int number_;
}; };
#endif #endif

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macrotemplate.h" #include "math_macrotemplate.h"
#include "math_macro.h" #include "math_macro.h"
#include "macro_support.h" #include "macro_support.h"
@ -8,24 +12,6 @@
using std::ostream; using std::ostream;
void MathMacroTemplate::setTCode(MathedTextCodes t)
{
tcode_ = t;
}
MathedTextCodes MathMacroTemplate::getTCode() const
{
return tcode_;
}
int MathMacroTemplate::getNoArgs() const
{
return nargs_;
}
MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg): MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO), MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
flags_(flg), nargs_(na) flags_(flg), nargs_(na)
@ -44,8 +30,26 @@ MathMacroTemplate::MathMacroTemplate(string const & nm, int na, int flg):
} }
MathMacroTemplate::~MathMacroTemplate() //MathMacroTemplate::~MathMacroTemplate()
{} //{}
void MathMacroTemplate::setTCode(MathedTextCodes t)
{
tcode_ = t;
}
MathedTextCodes MathMacroTemplate::getTCode() const
{
return tcode_;
}
int MathMacroTemplate::getNoArgs() const
{
return nargs_;
}
void MathMacroTemplate::setEditMode(bool ed) void MathMacroTemplate::setEditMode(bool ed)

View File

@ -7,6 +7,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#include "math_macroarg.h" #include "math_macroarg.h"
#ifdef __GNUG__
#pragma interface
#endif
class MathMacro; class MathMacro;
/** This class contains the macro definition /** This class contains the macro definition
@ -18,7 +22,7 @@ public:
explicit explicit
MathMacroTemplate(string const &, int na = 0, int f = 0); MathMacroTemplate(string const &, int na = 0, int f = 0);
/// ///
~MathMacroTemplate(); //~MathMacroTemplate();
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///
@ -45,9 +49,7 @@ public:
/// Replace the appropriate arguments with a specific macro's data /// Replace the appropriate arguments with a specific macro's data
void update(MathMacro * m = 0); void update(MathMacro * m = 0);
/// ///
short flags() const { short flags() const;
return flags_;
}
private: private:
/// ///
short flags_; short flags_;
@ -58,4 +60,10 @@ private:
/// ///
int nargs_; int nargs_;
}; };
inline
short MathMacroTemplate::flags() const {
return flags_;
}
#endif #endif

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_matrixinset.h" #include "math_matrixinset.h"
#include "math_rowst.h" #include "math_rowst.h"
#include "math_xiter.h" #include "math_xiter.h"
@ -171,7 +175,7 @@ void MathMatrixInset::Metrics()
cxrow = cxrow->getNext(); cxrow = cxrow->getNext();
} }
int hl = Descent(); int const hl = Descent();
h -= MATH_ROWSEP; h -= MATH_ROWSEP;
// Compute vertical align // Compute vertical align
@ -229,7 +233,7 @@ void MathMatrixInset::Metrics()
lf = (ws_[i] - cxrow->getTab(i))/2; lf = (ws_[i] - cxrow->getTab(i))/2;
break; break;
} }
int ww = (isvoid) ? lf : lf + cxrow->getTab(i); int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
cxrow->setTab(i, lf + rg); cxrow->setTab(i, lf + rg);
rg = ws_[i] - ww + MATH_COLSEP; rg = ws_[i] - ww + MATH_COLSEP;
if (cxrow == row_) if (cxrow == row_)

View File

@ -6,6 +6,10 @@
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** Multiline math paragraph base class. /** Multiline math paragraph base class.
This is the base to all multiline editable math objects This is the base to all multiline editable math objects
like array and eqnarray. like array and eqnarray.
@ -20,9 +24,9 @@ public:
explicit explicit
MathMatrixInset(MathMatrixInset *); MathMatrixInset(MathMatrixInset *);
/// ///
MathedInset * Clone(); ~MathMatrixInset();
/// ///
virtual ~MathMatrixInset(); MathedInset * Clone();
/// ///
void draw(Painter &, int, int); void draw(Painter &, int, int);
/// ///

File diff suppressed because it is too large Load Diff

View File

@ -19,8 +19,8 @@
#pragma implementation #pragma implementation
#endif #endif
#include "math_iter.h"
#include "math_root.h" #include "math_root.h"
#include "math_iter.h"
#include "support/LOstream.h" #include "support/LOstream.h"
using std::ostream; using std::ostream;

View File

@ -15,13 +15,12 @@
#ifndef MATH_ROOT #ifndef MATH_ROOT
#define MATH_ROOT #define MATH_ROOT
#ifdef __GNUG__
#pragma interface
#endif
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "symbol_def.h" #include "symbol_def.h"
#ifdef __GNUG__
#pragma interface
#endif
/** The general n-th root inset. /** The general n-th root inset.
\author Alejandro Aguilar Sierra \author Alejandro Aguilar Sierra

View File

@ -1,5 +1,9 @@
#include <config.h> #include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_sqrtinset.h" #include "math_sqrtinset.h"
#include "math_iter.h" #include "math_iter.h"
#include "LColor.h" #include "LColor.h"
@ -9,6 +13,7 @@
using std::ostream; using std::ostream;
MathSqrtInset::MathSqrtInset(short st) MathSqrtInset::MathSqrtInset(short st)
: MathParInset(st, "sqrt", LM_OT_SQRT) {} : MathParInset(st, "sqrt", LM_OT_SQRT) {}

View File

@ -1,9 +1,13 @@
// -*- C++ -*-
#ifndef MATH_SQRTINSET_H #ifndef MATH_SQRTINSET_H
#define MATH_SQRTINSET_H #define MATH_SQRTINSET_H
#include "math_parinset.h" #include "math_parinset.h"
#ifdef __GNUG__
#pragma interface
#endif
/** The square root inset. /** The square root inset.
\author Alejandro Aguilar Siearra \author Alejandro Aguilar Siearra
*/ */