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>
* formula.C (LocalDispatch): changed action to be a kb_action (as it

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,9 @@
#include <config.h>
#ifdef __GNUG__
#pragma implementation
#endif
#include "math_macrotemplate.h"
#include "math_macro.h"
#include "macro_support.h"
@ -8,24 +12,6 @@
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):
MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
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)

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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