fix the matrix reading other small cleanup

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1642 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2001-02-28 17:21:16 +00:00
parent 7f6bd7f12d
commit 4203d759ad
19 changed files with 192 additions and 84 deletions

View File

@ -1,5 +1,37 @@
2001-02-28 Lars Gullik Bjønnes <larsbj@trylle.birdstep.com>
* formulamacro.C (Read): add comment.
* math_parser.C (mathed_parse): fix another potential problem by
passing a freestanding mathedarray.
* math_root.C (GetData): add const version
* math_parinset.C (~MathParInset): delete
(GetData): add const version
* math_matrixinset.C (MathMatrixInset): delete pointer version,
make it a proper copy constructor instead
(Clone): change acc.
(MathMatrixInset): remvoe default val for m and n
* math_macro.C (GetData): add const version
* math_fracinset.C (GetData): add const version
* math_cursor.C (SelCopy): make p1 and p2 const
(SelCut): make p1 and p2 const
* formula.h: add '_' on priv vars. Cnages in formula.C acc. to this
(LyxCode): move inline out of class
(ConvertFont): ditto
(display): ditto
* array.[Ch] (dump): method added for debugging purposes
* math_parser.C (mathed_parse): pass a freestanding mathedarray to
mathed_parse when reading a matrix.
* math_spaceinset.[Ch]: add pragma, make variables private add
'_', change order of method definitions.

View File

@ -280,3 +280,16 @@ byte & MathedArray::operator[](int i)
{
return bf_[i];
}
void MathedArray::dump(ostream & os) const
{
buffer_type::const_iterator cit = bf_.begin();
buffer_type::const_iterator end = bf_.end();
for (; cit != end; ++cit) {
os << (*cit);
}
os << endl;
}

View File

@ -17,6 +17,7 @@
#define MATHEDARRAY_H
#include <vector>
#include <iosfwd>
#include "mathed/support.h"
@ -110,6 +111,8 @@ public:
void resize(int newsize);
/// Make sure we can access at least \a needed elements
void need_size(int needed);
///
void dump(ostream &) const;
private:
/// Buffer
buffer_type bf_;

View File

@ -211,9 +211,8 @@ InsetFormula::InsetFormula(bool display)
{
par = new MathParInset; // this leaks
// mathcursor = 0;
disp_flag = display;
//label = 0;
if (disp_flag) {
disp_flag_ = display;
if (disp_flag_) {
par->SetType(LM_OT_PAR);
par->SetStyle(LM_ST_DISPLAY);
}
@ -226,12 +225,11 @@ InsetFormula::InsetFormula(MathParInset * p)
lyxerr << "InsetFormula::InsetFormula: This shouldn't happen" << endl;
par = is_multiline(p->GetType()) ?
new MathMatrixInset(static_cast<MathMatrixInset*>(p)):
new MathMatrixInset(*static_cast<MathMatrixInset*>(p)):
new MathParInset(*p);
// mathcursor = 0;
disp_flag = (par->GetType()>0);
//label = 0;
disp_flag_ = (par->GetType()>0);
}
@ -244,7 +242,7 @@ InsetFormula::~InsetFormula()
Inset * InsetFormula::Clone(Buffer const &) const
{
InsetFormula * f = new InsetFormula(par);
f->label = label;
f->label_ = label_;
return f;
}
@ -260,7 +258,7 @@ int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
{
//#warning Alejandro, the number of lines is not returned in this case
// This problem will disapear at 0.13.
return mathed_write(par, os, fragile, label);
return mathed_write(par, os, fragile, label_);
}
@ -308,13 +306,13 @@ void InsetFormula::Read(Buffer const *, LyXLex & lex)
MathedArray ar;
mathed_parse(ar, 0, &par);
par->Metrics();
disp_flag = (par->GetType() > 0);
disp_flag_ = (par->GetType() > 0);
// Update line number
lex.setLineNo(mathed_parser_lineno());
if (!mathed_label.empty()) {
label = mathed_label;
label_ = mathed_label;
mathed_label.erase();
}
@ -335,13 +333,13 @@ void InsetFormula::Read(Buffer const *, LyXLex & lex)
int InsetFormula::ascent(BufferView *, LyXFont const &) const
{
return par->Ascent() + (disp_flag ? 8 : 1);
return par->Ascent() + (disp_flag_ ? 8 : 1);
}
int InsetFormula::descent(BufferView *, LyXFont const &) const
{
return par->Descent() + (disp_flag ? 8 : 1);
return par->Descent() + (disp_flag_ ? 8 : 1);
}
@ -388,18 +386,17 @@ void InsetFormula::draw(BufferView * bv, LyXFont const & f,
if (is_singlely_numbered(par->GetType())) {
string str;
if (!label.empty())
str = string("(") + label + ")";
if (!label_.empty())
str = string("(") + label_ + ")";
else
str = string("(#)");
pain.text(int(x + 20), baseline, str, wfont);
} else {
MathMatrixInset * mt =
static_cast<MathMatrixInset*>(par);
int y;
MathedRowSt const * crow = mt->getRowSt();
while (crow) {
y = baseline + crow->getBaseline();
int const y = baseline + crow->getBaseline();
if (crow->isNumbered()) {
string str;
if (!crow->getLabel().empty())
@ -532,7 +529,7 @@ void InsetFormula::ToggleInsetSelection(BufferView * bv)
void InsetFormula::display(bool dspf)
{
if (dspf != disp_flag) {
if (dspf != disp_flag_) {
if (dspf) {
par->SetType(LM_OT_PAR);
par->SetStyle(LM_ST_DISPLAY);
@ -543,11 +540,11 @@ void InsetFormula::display(bool dspf)
}
par->SetType(LM_OT_MIN);
par->SetStyle(LM_ST_TEXT);
if (!label.empty()) {
label.erase();
if (!label_.empty()) {
label_.erase();
}
}
disp_flag = dspf;
disp_flag_ = dspf;
}
}
@ -567,8 +564,8 @@ vector<string> const InsetFormula::getLabelList() const
label_list.push_back(crow->getLabel());
crow = crow->getNext();
}
} else if (!label.empty())
label_list.push_back(label);
} else if (!label_.empty())
label_list.push_back(label_);
return label_list;
}
@ -604,7 +601,8 @@ void InsetFormula::InsetButtonPress(BufferView * bv, int x, int y,
int /*button*/)
{
sel_flag = false;
sel_x = x; sel_y = y;
sel_x = x;
sel_y = y;
if (mathcursor && mathcursor->Selection()) {
mathcursor->SelClear();
bv->updateInset(this, false);
@ -646,7 +644,7 @@ void InsetFormula::InsetKeyPress(XKeyEvent *)
// Special Mathed functions
bool InsetFormula::SetNumber(bool numbf)
{
if (disp_flag) {
if (disp_flag_) {
short type = par->GetType();
bool const oldf = is_numbered(type);
if (numbf && !oldf)
@ -742,9 +740,9 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
bv->lockedInsetStoreUndo(Undo::INSERT);
byte c = arg.empty() ? '1' : arg[0];
mathcursor->Insert(c, LM_TC_CR);
if (!label.empty()) {
mathcursor->setLabel(label);
label.erase();
if (!label_.empty()) {
mathcursor->setLabel(label_);
label_.erase();
}
par = mathcursor->GetPar();
UpdateLocal(bv);
@ -869,12 +867,12 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_NUMBER:
bv->lockedInsetStoreUndo(Undo::INSERT);
if (disp_flag) {
if (disp_flag_) {
short type = par->GetType();
if (is_numbered(type)) {
--type;
if (!label.empty()) {
label.erase();
if (!label_.empty()) {
label_.erase();
}
bv->owner()->getMiniBuffer()->Set(_("No number"));
} else {
@ -911,7 +909,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_SIZE:
if (!arg.empty()) {
latexkeys const * l = in_word_set(arg);
int sz = (l) ? l->id: -1;
int const sz = (l) ? l->id: -1;
mathcursor->SetSize(sz);
UpdateLocal(bv);
break;
@ -927,11 +925,14 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
case LFUN_INSERT_MATRIX:
{
bv->lockedInsetStoreUndo(Undo::INSERT);
int k, m, n;
char s[80], arg2[80];
// This is just so that too long args won't ooze out of s.
strncpy(arg2, arg.c_str(), 80); arg2[79]= '\0';
k = sscanf(arg2, "%d %d %s", &m, &n, s);
char s[80];
char arg2[80];
// This is just so that too long args won't ooze out of s.
strncpy(arg2, arg.c_str(), 80);
arg2[79]= '\0';
int m;
int n;
int const k = sscanf(arg2, "%d %d %s", &m, &n, s);
s[79] = '\0';
if (k < 1) {
@ -953,8 +954,11 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_DELIM:
{
bv->lockedInsetStoreUndo(Undo::INSERT);
char lf[40], rg[40], arg2[40];
int ilf = '(', irg = '.';
char lf[40];
char rg[40];
char arg2[40];
int ilf = '(';
int irg = '.';
latexkeys const * l;
string vdelim("(){}[]./|");
@ -962,7 +966,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
break;
::strncpy(arg2, arg.c_str(), 40);
arg2[39]= '\0';
int n = sscanf(arg2, "%s %s", lf, rg);
int const n = sscanf(arg2, "%s %s", lf, rg);
lf[39] = '\0';
rg[39] = '\0';
@ -1012,7 +1016,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
break;
string old_label = is_multiline(par->GetType())
? mathcursor->getLabel() : label;
? mathcursor->getLabel() : label_;
#warning This is a terrible hack! We should find a better solution.
// This is needed because in some positions
@ -1051,7 +1055,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
// MathMatrixInset *mt = (MathMatrixInset*)par;
// mt->SetLabel(new_label);
} else
label = new_label;
label_ = new_label;
UpdateLocal(bv);
break;
@ -1059,7 +1063,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
case LFUN_MATH_DISPLAY:
bv->lockedInsetStoreUndo(Undo::EDIT);
display(!disp_flag);
display(!disp_flag_);
UpdateLocal(bv);
break;
@ -1134,7 +1138,7 @@ InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
varcode = LM_TC_MIN;
if (greek_kb_flag<2)
if (greek_kb_flag < 2)
greek_kb_flag = 0;
} else if (strchr("!,:;{}", c) && (varcode == LM_TC_TEX||was_macro)) {

View File

@ -66,27 +66,21 @@ public:
///
Inset * Clone(Buffer const &) const;
///
Inset::Code LyxCode() const { return Inset::MATH_CODE; }
Inset::Code LyxCode() const;
///
LyXFont const ConvertFont(LyXFont const & f) const {
// We have already discussed what was here
LyXFont font(f);
font.setLatex(LyXFont::OFF);
return font;
}
LyXFont const ConvertFont(LyXFont const & f) const;
/// what appears in the minibuffer when opening
string const EditMessage() const;
///
void Edit(BufferView *, int x, int y, unsigned int button);
///
bool display() const { return (disp_flag) ? true: false; }
bool display() const;
///
void display(bool);
///
void ToggleInsetCursor(BufferView *);
///
void ShowInsetCursor(BufferView *, bool show=true);
void ShowInsetCursor(BufferView *, bool show = true);
///
void HideInsetCursor(BufferView *);
///
@ -124,8 +118,32 @@ protected:
private:
///
bool disp_flag;
bool disp_flag_;
///
string label;
string label_;
};
inline
Inset::Code InsetFormula::LyxCode() const
{
return Inset::MATH_CODE;
}
inline
LyXFont const InsetFormula::ConvertFont(LyXFont const & f) const
{
// We have already discussed what was here
LyXFont font(f);
font.setLatex(LyXFont::OFF);
return font;
}
inline
bool InsetFormula::display() const
{
return (disp_flag_) ? true : false;
}
#endif

View File

@ -105,7 +105,8 @@ void InsetFormulaMacro::Read(Buffer const *, LyXLex & lex)
MathedArray ar;
mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_));
// since tmacro_ == 0 when mathed_parse is called we need to sett
// its contents explicitly afterwards (Lgb)
tmacro_->setData(ar);
// Update line number

View File

@ -899,8 +899,9 @@ void MathedCursor::MacroModeClose()
void MathedCursor::SelCopy()
{
if (selection) {
int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
int p2 = (cursor->getPos() > selpos) ?
int const p1 = (cursor->getPos() < selpos) ?
cursor->getPos() : selpos;
int const p2 = (cursor->getPos() > selpos) ?
cursor->getPos() : selpos;
selarray = *(cursor->GetData());
selarray.shrink(p1, p2);
@ -916,8 +917,10 @@ void MathedCursor::SelCut()
if (cursor->getPos() == selpos)
return;
int p1 = (cursor->getPos() < selpos) ? cursor->getPos() : selpos;
int p2 = (cursor->getPos() > selpos) ? cursor->getPos() : selpos;
int const p1 = (cursor->getPos() < selpos) ?
cursor->getPos() : selpos;
int const p2 = (cursor->getPos() > selpos) ?
cursor->getPos() : selpos;
selarray = *(cursor->GetData());
selarray.shrink(p1, p2);
cursor->Clean(selpos);

View File

@ -87,6 +87,15 @@ MathedArray & MathFracInset::GetData()
}
MathedArray const & MathFracInset::GetData() const
{
if (idx_ == 0)
return array;
else
return den_.GetData();
}
bool MathFracInset::Inside(int x, int y)
{
int const xx = xo() - (width - w0_) / 2;

View File

@ -39,6 +39,8 @@ public:
///
MathedArray & GetData();
///
MathedArray const & GetData() const;
///
bool setArgumentIdx(int i); // was bool Up/down(void);
///
int getArgumentIdx() const;

View File

@ -43,17 +43,18 @@ MathedIter::MathedIter()
{}
MathedArray * MathedIter::GetData() const
{
return array;
}
short MathedIter::fcode() const
{
return fcode_;
}
void MathedIter::fcode(short c) const
{
fcode_ = c;

View File

@ -140,6 +140,12 @@ MathedArray & MathMacro::GetData()
}
MathedArray const & MathMacro::GetData() const
{
return args_[idx_].array;
}
int MathMacro::GetColumns() const
{
return tmplate_->getMacroPar(idx_)->GetColumns();

View File

@ -62,6 +62,8 @@ public:
///
MathedArray & GetData();
///
MathedArray const & GetData() const;
///
MathedRowSt * getRowSt() const;
///
void setData(MathedArray const &);

View File

@ -34,15 +34,15 @@ MathMatrixInset::MathMatrixInset(int m, int n, short st)
}
MathMatrixInset::MathMatrixInset(MathMatrixInset * mt)
: MathParInset(mt->GetStyle(), mt->GetName(), mt->GetType()),
nc_(mt->nc_), nr_(0), ws_(mt->nc_),
v_align_(mt->v_align_), h_align_(mt->h_align_)
MathMatrixInset::MathMatrixInset(MathMatrixInset const & mt)
: MathParInset(mt.GetStyle(), mt.GetName(), mt.GetType()),
nc_(mt.nc_), nr_(0), ws_(mt.nc_),
v_align_(mt.v_align_), h_align_(mt.h_align_)
{
array = mt->GetData();
if (mt->row_ != 0) {
array = mt.GetData();
if (mt.row_ != 0) {
MathedRowSt * ro = 0;
MathedRowSt * mrow = mt->row_;
MathedRowSt * mrow = mt.row_;
while (mrow) {
MathedRowSt * r = new MathedRowSt(nc_ + 1);
@ -59,7 +59,7 @@ MathMatrixInset::MathMatrixInset(MathMatrixInset * mt)
}
} else
row_ = 0;
flag = mt->flag;
flag = mt.flag;
}
@ -76,7 +76,7 @@ MathMatrixInset::~MathMatrixInset()
MathedInset * MathMatrixInset::Clone()
{
return new MathMatrixInset(this);
return new MathMatrixInset(*this);
}

View File

@ -19,10 +19,10 @@ class MathMatrixInset : public MathParInset {
public:
///
explicit
MathMatrixInset(int m = 1, int n = 1, short st = LM_ST_TEXT);
MathMatrixInset(int m, int n, short st = LM_ST_TEXT);
///
explicit
MathMatrixInset(MathMatrixInset *);
MathMatrixInset(MathMatrixInset const &);
///
~MathMatrixInset();
///

View File

@ -35,12 +35,6 @@ MathParInset::MathParInset(short st, string const & nm, short ot)
}
// This is virtual and needed.
MathParInset::~MathParInset()
{
}
MathedInset * MathParInset::Clone()
{
return new MathParInset(*this);
@ -436,6 +430,12 @@ MathedArray & MathParInset::GetData()
}
MathedArray const & MathParInset::GetData() const
{
return array;
}
void MathParInset::setXY(int x, int y)
{
xo_ = x;

View File

@ -19,8 +19,6 @@ public:
MathParInset(short st = LM_ST_TEXT, string const & nm = string(),
short ot = LM_OT_MIN);
///
virtual ~MathParInset();
///
virtual MathedInset * Clone();
/// Draw the object on a drawable
virtual void draw(Painter &, int x, int baseline);
@ -34,6 +32,8 @@ public:
virtual void setData(MathedArray const &);
///
virtual MathedArray & GetData();
///
virtual MathedArray const & GetData() const;
/// Paragraph position
virtual void GetXY(int &, int &) const;
///

View File

@ -693,7 +693,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
rt->setArgumentIdx(0);
MathedArray ar;
mathed_parse(ar, FLAG_BRACK_END, &rt);
rt->setData(ar);
rt->setData(ar); // I belive that line is not needed (Lgb)
rt->setArgumentIdx(1);
} else {
yyis->putback(c);
@ -701,7 +701,7 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
}
MathedArray ar;
mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST, &rt);
rt->setData(ar);
rt->setData(ar); // I belive that this line is not needed (Lgb)
data.insertInset(rt, LM_TC_ACTIVE_INSET);
break;
}
@ -833,7 +833,8 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
MathParInset * mm = new MathMatrixInset(nc, 0);
mm->SetAlign(ar2[0], ar);
data.insertInset(mm, LM_TC_ACTIVE_INSET);
mathed_parse(mm->GetData(), FLAG_END, &mm);
MathedArray dat;
mathed_parse(dat, FLAG_END, &mm);
} else if (is_eqn_type(yylval.i)) {
if (plevel!= 0) {
mathPrintError("Misplaced environment");
@ -884,7 +885,9 @@ void mathed_parse(MathedArray & array, unsigned flags = 0,
if (p) {
data.insertInset(p, p->getTCode());
p->setArgumentIdx(0);
mathed_parse(p->GetData(), FLAG_END, reinterpret_cast<MathParInset**>(&p));
//mathed_parse(p->GetData(), FLAG_END, reinterpret_cast<MathParInset**>(&p));
MathedArray dat;
mathed_parse(dat, FLAG_END, reinterpret_cast<MathParInset**>(&p));
// for (int i = 0; p->setArgumentIdx(i); ++i)
// p->SetData(mathed_parse(FLAG_BRACE|FLAG_BRACE_LAST));
} else

View File

@ -75,6 +75,15 @@ MathedArray & MathRootInset::GetData()
}
MathedArray const & MathRootInset::GetData() const
{
if (idx_ == 1)
return array;
else
return uroot_.GetData();
}
bool MathRootInset::Inside(int x, int y)
{
return (uroot_.Inside(x, y) || MathSqrtInset::Inside(x, y));

View File

@ -50,6 +50,8 @@ public:
///
MathedArray & GetData();
///
MathedArray const & GetData() const;
///
bool setArgumentIdx(int i);
///
int getArgumentIdx() const;