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.
{
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;
+}
+
+
#define MATHEDARRAY_H
#include <vector>
+#include <iosfwd>
#include "mathed/support.h"
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_;
{
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);
}
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);
}
Inset * InsetFormula::Clone(Buffer const &) const
{
InsetFormula * f = new InsetFormula(par);
- f->label = label;
+ f->label_ = label_;
return f;
}
{
//#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_);
}
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();
}
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);
}
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())
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);
}
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;
}
}
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;
}
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);
// 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)
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);
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 {
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;
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) {
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("(){}[]./|");
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';
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
// MathMatrixInset *mt = (MathMatrixInset*)par;
// mt->SetLabel(new_label);
} else
- label = new_label;
+ label_ = new_label;
UpdateLocal(bv);
break;
case LFUN_MATH_DISPLAY:
bv->lockedInsetStoreUndo(Undo::EDIT);
- display(!disp_flag);
+ display(!disp_flag_);
UpdateLocal(bv);
break;
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)) {
///
Inset * Clone(Buffer const &) const;
///
- Inset::Code LyxCode() const { return Inset::MATH_CODE; }
- ///
- LyXFont const ConvertFont(LyXFont const & f) const {
- // We have already discussed what was here
- LyXFont font(f);
- font.setLatex(LyXFont::OFF);
- return font;
- }
-
+ Inset::Code LyxCode() const;
+ ///
+ 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 *);
///
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
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
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);
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);
}
+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;
///
MathedArray & GetData();
///
+ MathedArray const & GetData() const;
+ ///
bool setArgumentIdx(int i); // was bool Up/down(void);
///
int getArgumentIdx() const;
{}
-
MathedArray * MathedIter::GetData() const
{
return array;
}
+
short MathedIter::fcode() const
{
return fcode_;
}
+
void MathedIter::fcode(short c) const
{
fcode_ = c;
}
+MathedArray const & MathMacro::GetData() const
+{
+ return args_[idx_].array;
+}
+
+
int MathMacro::GetColumns() const
{
return tmplate_->getMacroPar(idx_)->GetColumns();
///
MathedArray & GetData();
///
+ MathedArray const & GetData() const;
+ ///
MathedRowSt * getRowSt() const;
///
void setData(MathedArray const &);
}
-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);
}
} else
row_ = 0;
- flag = mt->flag;
+ flag = mt.flag;
}
MathedInset * MathMatrixInset::Clone()
{
- return new MathMatrixInset(this);
+ return new MathMatrixInset(*this);
}
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();
///
}
-// This is virtual and needed.
-MathParInset::~MathParInset()
-{
-}
-
-
MathedInset * MathParInset::Clone()
{
return new MathParInset(*this);
}
+MathedArray const & MathParInset::GetData() const
+{
+ return array;
+}
+
+
void MathParInset::setXY(int x, int y)
{
xo_ = x;
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);
virtual void setData(MathedArray const &);
///
virtual MathedArray & GetData();
+ ///
+ virtual MathedArray const & GetData() const;
/// Paragraph position
virtual void GetXY(int &, int &) const;
///
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);
}
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;
}
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");
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
}
+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));
///
MathedArray & GetData();
///
+ MathedArray const & GetData() const;
+ ///
bool setArgumentIdx(int i);
///
int getArgumentIdx() const;