#pragma implementation
#endif
+#include "debug.h"
#include "array.h"
#include "math_iter.h"
#include "math_inset.h"
+#include "math_macro.h"
#include "support/LOstream.h"
}
}
+void MathedArray::substitute(MathMacro * m)
+{
+ if (m->nargs() == 0)
+ return;
+
+ MathedIter it(this);
+ while (it.OK()) {
+ if (it.IsInset()) {
+ MathedInset * inset = it.GetInset();
+ if (inset->GetType() == LM_OT_MACRO_ARG) {
+ int n = static_cast<MathMacroArgument *>(inset)->number() - 1;
+ //lyxerr << "substituting an argument inset: " << n << "\n";
+ inset = m->arg(n)->Clone();
+ } else {
+ inset->substitute(m);
+ //lyxerr << "substituting in an ordinary inset\n";
+ }
+ raw_pointer_insert(inset, it.getPos() + 1);
+ }
+ it.Next();
+ }
+}
+
MathedArray & MathedArray::operator=(MathedArray const & array)
{
}
-void MathedArray::dump(ostream & os) const
+void MathedArray::dump2(ostream & os) const
{
buffer_type::const_iterator cit = bf_.begin();
buffer_type::const_iterator end = bf_.end();
os << endl;
}
+void MathedArray::dump(ostream & os) const
+{
+ MathedIter it( const_cast<MathedArray*>(this) );
+ while (it.OK()) {
+ if (it.IsInset()) {
+ MathedInset * inset = it.GetInset();
+ os << "<inset: " << inset << ">";
+ }
+ else if (it.IsTab())
+ os << "<tab>";
+ else if (it.IsCR())
+ os << "<cr>";
+ else if (it.IsScript())
+ os << "<script>";
+ else if (it.IsFont())
+ os << "<font: " << int(it.at()) << ">";
+ else if (it.at() >= 32 && it.at() < 127)
+ os << it.at();
+ else
+ os << "<unknown: " << int(it.at()) << ">";
+ it.Next();
+ }
+}
+
#include "mathed/support.h"
class MathedInset;
+class MathMacro;
#ifdef __GNUG__
#pragma interface
void need_size(int needed);
///
void dump(std::ostream &) const;
+ ///
+ void dump2(std::ostream &) const;
/// creates copies of all embedded insets
void deep_copy();
+ ///
+ void substitute(MathMacro *);
private:
/// Buffer
buffer_type bf_;
/// Last position inserted.
int last_;
};
+
+inline
+ostream & operator<<(ostream & os, MathedArray const & ar)
+{
+ ar.dump(os);
+ return os;
+}
+
#endif
// this is only used by Whichfont and mathed_init_fonts (Lgb)
LyXFont * Math_Fonts = 0;
+
+MathedCursor * mathcursor = 0;
+
+
namespace {
LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL;
} // namespaces
-MathedCursor * InsetFormula::mathcursor = 0;
-
LyXFont WhichFont(short type, int size)
{
new MathParInset(*p);
// mathcursor = 0;
- disp_flag_ = (par->GetType()>0);
+ disp_flag_ = par->GetType() > 0;
}
InsetFormula::~InsetFormula()
{
- delete par;
+#ifdef WITH_WARNINGS
+#warning leak this for a while...
+#endif
+ //delete par;
}
Inset * InsetFormula::Clone(Buffer const &) const
{
- InsetFormula * f = new InsetFormula(par);
- f->label_ = label_;
- return f;
+ return new InsetFormula(par);
}
int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const
{
- //#ifdef WITH_WARNINGS
- //#warning Alejandro, the number of lines is not returned in this case
- // This problem will disapear at 0.13.
- //#endif
- return mathed_write(par, os, fragile, label_);
+ return mathed_write(par, os, fragile, par->label());
}
mathed_parser_file(is, lex.GetLineNo());
- // Silly hack to read labels.
- mathed_label.erase();
-
MathedArray ar;
- mathed_parse(ar, 0, &par);
+ mathed_parse(ar, par, 0);
+ if (par->isMatrix()) {
+ //lyxerr << "################## InsetFormula::Read: IsMatrix\n";
+ static_cast<MathMatrixInset*>(par)->setData(ar);
+ }
+ else {
+ par->setData(ar);
+ //lyxerr << "################## InsetFormula::Read: keine Matrix\n";
+ }
+
+ //lyxerr << "InsetFormula::Read: par: " << par << " " << par->GetData() << endl;
+
par->Metrics();
disp_flag_ = (par->GetType() > 0);
// Update line number
lex.setLineNo(mathed_parser_lineno());
- if (!mathed_label.empty()) {
- label_ = mathed_label;
- mathed_label.erase();
- }
-
// reading of end_inset in the inset!!!
while (lex.IsOK()) {
lex.nextToken();
if (is_singlely_numbered(par->GetType())) {
string str;
- if (!label_.empty())
- str = string("(") + label_ + ")";
+ if (!par->label().empty())
+ str = string("(") + par->label() + ")";
else
str = string("(#)");
pain.text(int(x + 20), baseline, str, wfont);
} else {
- MathMatrixInset * mt =
- static_cast<MathMatrixInset*>(par);
- MathedRowContainer::iterator crow = mt->getRowSt().begin();
+ MathedRowContainer::iterator crow = par->getRowSt().begin();
while (crow) {
int const y = baseline + crow->getBaseline();
if (crow->isNumbered()) {
// Now a symbol can be inserted only if the inset is locked
-void InsetFormula::InsertSymbol(BufferView * bv, string const & s)
+void InsetFormula::InsertSymbol(BufferView *, string const & s)
{
if (s.empty() || !mathcursor)
return;
mathcursor->Interpret(s);
- UpdateLocal(bv);
+ // Andre: UpdateLocal(bv);
}
}
par->SetType(LM_OT_MIN);
par->SetStyle(LM_ST_TEXT);
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
if (!label_.empty()) {
label_.erase();
}
+*/
}
disp_flag_ = dspf;
}
vector<string> const InsetFormula::getLabelList() const
{
- //#ifdef WITH_WARNINGS
- //#warning This is dirty, I know. Ill clean it at 0.11
- // Correction, the only way to clean this is with a new kernel: 0.13.
- //#endif
-
vector<string> label_list;
-
- if (is_multi_numbered(par->GetType())) {
- MathMatrixInset * mt = static_cast<MathMatrixInset*>(par);
- MathedRowContainer::iterator crow = mt->getRowSt().begin();
- while (crow) {
- if (!crow->getLabel().empty())
- label_list.push_back(crow->getLabel());
- ++crow;
- }
- } else if (!label_.empty())
- label_list.push_back(label_);
+ MathedRowContainer::iterator crow = par->getRowSt().begin();
+ for ( ; crow; ++crow)
+ label_list.push_back(crow->getLabel());
return label_list;
}
InsetFormula::LocalDispatch(BufferView * bv, kb_action action,
string const & arg)
{
+ //lyxerr << "InsetFormula::LocalDispatch: act: " << action
+ // << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
// extern char *dispatch_result;
+
+ if (!mathcursor) {
+ return UNDISPATCHED;
+ }
+
MathedTextCodes varcode = LM_TC_MIN;
bool was_macro = mathcursor->InMacroMode();
bool sel = false;
result = DISPATCH_RESULT(mathcursor->Right(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
result = DISPATCH_RESULT(mathcursor->Left(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
result = DISPATCH_RESULT(mathcursor->Up(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
result = DISPATCH_RESULT(mathcursor->Down(sel));
if (!sel && (result == DISPATCHED))
result = DISPATCHED_NOUPDATE;
+ UpdateLocal(bv);
break;
case LFUN_DELETE_LINE_FORWARD:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->DelLine();
+ // Andre:
UpdateLocal(bv);
break;
bv->lockedInsetStoreUndo(Undo::INSERT);
byte c = arg.empty() ? '1' : arg[0];
mathcursor->Insert(c, LM_TC_CR);
- if (!label_.empty()) {
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
+ if (!par->label().empty()) {
mathcursor->setLabel(label_);
label_.erase();
}
+*/
par = mathcursor->GetPar();
+ // Andre:
UpdateLocal(bv);
}
break;
case LFUN_TABINSERT:
bv->lockedInsetStoreUndo(Undo::INSERT);
mathcursor->Insert('T', LM_TC_TAB);
+ // Andre:
UpdateLocal(bv);
break;
mathcursor->MacroModeClose();
bv->lockedInsetStoreUndo(Undo::INSERT);
mathcursor->SelPaste();
+ // Andre:
UpdateLocal(bv);
break;
case LFUN_CUT:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->SelCut();
+ // Andre:
UpdateLocal(bv);
break;
short type = par->GetType();
if (is_numbered(type)) {
--type;
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
if (!label_.empty()) {
label_.erase();
}
+*/
bv->owner()->getLyXFunc()->Dispatch(LFUN_MESSAGE, _("No number"));
} else {
++type;
bv->owner()->getLyXFunc()->Dispatch(LFUN_MESSAGE, _("Number"));
}
par->SetType(type);
+ // Andre:
UpdateLocal(bv);
}
break;
case LFUN_MATH_NONUMBER:
if (is_multi_numbered(par->GetType())) {
- // MathMatrixInset *mt = (MathMatrixInset*)par;
//BUG
- // mt->SetNumbered(!mt->IsNumbered());
+ // par->SetNumbered(!par->IsNumbered());
#ifdef WITH_WARNINGS
#warning This is a terrible hack! We should find a better solution.
return DISPATCHED;
}
mathcursor->setNumbered();
+ // Andre:
UpdateLocal(bv);
}
break;
case LFUN_MATH_LIMITS:
bv->lockedInsetStoreUndo(Undo::INSERT);
if (mathcursor->Limits())
+ // Andre:
UpdateLocal(bv);
// fall through!
case LFUN_MATH_SIZE:
if (!arg.empty()) {
latexkeys const * l = in_word_set(arg);
- int const sz = (l) ? l->id: -1;
+ int const sz = l ? l->id : -1;
mathcursor->SetSize(sz);
+ // Andre:
UpdateLocal(bv);
break;
}
n = 1;
}
- MathMatrixInset * p = new MathMatrixInset(m, n);
- if (mathcursor && p) {
+ if (mathcursor) {
+ MathMatrixInset * p = new MathMatrixInset(m, n);
if (k > 2 && int(strlen(s)) > m)
p->SetAlign(s[0], &s[1]);
mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
+ // Andre:
UpdateLocal(bv);
}
break;
MathDelimInset * p = new MathDelimInset(ilf, irg);
mathcursor->insertInset(p, LM_TC_ACTIVE_INSET);
+ // Andre:
UpdateLocal(bv);
break;
}
sp = new MathSpaceInset(1);
mathcursor->insertInset(sp, LM_TC_INSET);
space_on = true;
+ // Andre:
UpdateLocal(bv);
break;
break;
string old_label = is_multiline(par->GetType())
- ? mathcursor->getLabel() : label_;
+ ? mathcursor->getLabel() : par->label();
#ifdef WITH_WARNINGS
#warning This is a terrible hack! We should find a better solution.
if (!new_label.empty() && bv->ChangeRefsIfUnique(old_label, new_label))
bv->redraw();
+#ifdef WITH_WARNINGS
+#warning Labels
+#endif
+/*
if (is_multi_numbered(par->GetType())) {
mathcursor->setLabel(new_label);
- // MathMatrixInset *mt = (MathMatrixInset*)par;
- // mt->SetLabel(new_label);
+ // par->SetLabel(new_label);
} else
label_ = new_label;
+*/
+ // Andre:
UpdateLocal(bv);
break;
}
case LFUN_MATH_DISPLAY:
bv->lockedInsetStoreUndo(Undo::EDIT);
display(!disp_flag_);
+ // Andre:
UpdateLocal(bv);
break;
} else if (c == '\\') {
if (was_macro)
mathcursor->MacroModeClose();
- bv->owner()->getLyXFunc()
- ->Dispatch(LFUN_MESSAGE,
- _("TeX mode"));
+ // This line nukes the mathcursor. Why?
+ //bv->owner()->getLyXFunc()->Dispatch(LFUN_MESSAGE, _("TeX mode"));
mathcursor->setLastCode(LM_TC_TEX);
}
+ // Andre:
UpdateLocal(bv);
} else if (action == LFUN_MATH_PANEL) {
result = UNDISPATCHED;
}
}
- if (was_macro != mathcursor->InMacroMode()
+ //UpdateLocal(bv);
+
+ // Andre:
+ if ((mathcursor && was_macro != mathcursor->InMacroMode())
&& action >= 0
&& action != LFUN_BACKSPACE)
- UpdateLocal(bv);
+ UpdateLocal(bv);
if (sp && !space_on)
sp = 0;
- if (mathcursor->Selection() || was_selection)
+ if (mathcursor && (mathcursor->Selection() || was_selection))
ToggleInsetSelection(bv);
- if ((result == DISPATCHED) || (result == DISPATCHED_NOUPDATE) ||
- (result == UNDISPATCHED))
+ if (result == DISPATCHED || result == DISPATCHED_NOUPDATE ||
+ result == UNDISPATCHED)
ShowInsetCursor(bv);
else
bv->unlockInset(this);
- return result;
+ return result; // original version
}
#include <iosfwd>
#include "insets/lyxinset.h"
+#include <boost/smart_ptr.hpp>
class MathParInset;
-class MathedCursor;
class Buffer;
///
///
void UpdateLocal(BufferView * bv);
///
- MathParInset * par;
- ///
- static MathedCursor * mathcursor;
+ //boost::shared_ptr<MathParInset> par;
+ MathParInset * par;
private:
///
bool disp_flag_;
- ///
- string label_;
};
inline
bool InsetFormula::display() const
{
- return (disp_flag_) ? true : false;
+ return disp_flag_;
}
#endif
#include "math_cursor.h"
#include "math_parser.h"
#include "math_macro.h"
+#include "math_macroarg.h"
#include "math_macrotable.h"
#include "math_macrotemplate.h"
#include "lyx_main.h"
using std::ostream;
using std::istream;
+extern MathedCursor * mathcursor;
+
InsetFormulaMacro::InsetFormulaMacro()
: InsetFormula(true)
{
- opened_ = false;
+ par = &MathMacroTable::provideTemplate("unknown", 0);
}
InsetFormulaMacro::InsetFormulaMacro(string nm, int na)
- : InsetFormula(true), name_(nm)
-{
- tmacro_ = MathMacroTable::mathMTable.getTemplate(name_);
- if (!tmacro_.get()) {
- tmacro_.reset(new MathMacroTemplate(name_, na));
- MathMacroTable::mathMTable.addTemplate(tmacro_);
- }
- opened_ = false;
-}
-
-
-InsetFormulaMacro::~InsetFormulaMacro()
+ : InsetFormula(true)
{
- // We do not want the InsetFormula destructor to
- // delete this. That is taken care of elsewhere (Lgb)
- par = 0;
+ par = &MathMacroTable::provideTemplate(nm, na);
}
Inset * InsetFormulaMacro::Clone(Buffer const &) const
{
- // This should really use a proper copy constructor
- return new InsetFormulaMacro(name_, 0);
+ return new InsetFormulaMacro(*this);
}
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;
}
{
istream & is = lex.getStream();
mathed_parser_file(is, lex.GetLineNo());
+
+ MathParInset * tmp = new MathParInset;
MathedArray ar;
-
- mathed_parse(ar, 0, reinterpret_cast<MathParInset **>(&tmacro_));
- // Since tmacro_ == 0 when mathed_parse is called we need to set
- // its contents explicitly afterwards (Lgb)
- tmacro_->setData(ar);
+ mathed_parse(ar, tmp, 0);
+ par = &MathMacroTable::provideTemplate(tmp->GetName(), tmp->xo());
+ par->setData(ar);
+ //cerr << "## InsetFormulaMacro::Read name: " << tmp->GetName() << endl;
+ //cerr << "## InsetFormulaMacro::Read nargs: " << tmp->xo() << endl;
+ //cerr << "## InsetFormulaMacro::Read 1: " << ar << endl;
// Update line number
lex.setLineNo(mathed_parser_lineno());
- MathMacroTable::mathMTable.addTemplate(tmacro_);
- name_ = tmacro_->GetName();
- par = tmacro_.get();
-
// reading of end_inset in the inset!!!
while (lex.IsOK()) {
lex.nextToken();
}
}
-
int InsetFormulaMacro::ascent(BufferView * pain, LyXFont const & f) const
{
- if (opened_) {
- return InsetFormula::ascent(pain, f);
- }
- return lyxfont::maxAscent(f) + 3;
+ return InsetFormula::ascent(pain, f);
}
int InsetFormulaMacro::descent(BufferView * pain, LyXFont const & f) const
{
- if (opened_) {
- return InsetFormula::descent(pain, f);
- }
- return lyxfont::maxDescent(f) + 1;
+ return InsetFormula::descent(pain, f);
}
+string InsetFormulaMacro::prefix() const
+{
+ return string(" ") + _("Macro: ") + par->GetName() + ": ";
+}
+
int InsetFormulaMacro::width(BufferView * bv, LyXFont const & f) const
{
- if (opened_) {
- return InsetFormula::width(bv, f);
- }
- string ilabel(_("Macro: "));
- ilabel += name_;
- return 6 + lyxfont::width(ilabel, f);
+ return 10 + lyxfont::width(prefix(), f) + InsetFormula::width(bv, f);
}
{
Painter & pain = bv->painter();
LyXFont font(f);
- if (opened_) {
- tmacro_->setEditMode(true);
- InsetFormula::draw(bv, font, baseline, x, cleared);
- tmacro_->setEditMode(false);
- } else {
- font.setColor(LColor::math);
-
- int const y = baseline - ascent(bv, font) + 1;
- int const w = width(bv, font) - 2;
- int const h = (ascent(bv, font) + descent(bv, font) - 2);
+
+ // label
+ font.setColor(LColor::math);
- pain.fillRectangle(int(x), y, w, h, LColor::mathbg);
- pain.rectangle(int(x), y, w, h, LColor::mathframe);
-
- string s(_("Macro: "));
- s += name_;
- pain.text(int(x + 2), baseline, s, font);
- x += width(bv, font) - 1;
- }
-}
+ int const y = baseline - ascent(bv, font) + 1;
+ int const w = width(bv, font) - 2;
+ int const h = (ascent(bv, font) + descent(bv, font) - 2);
+ pain.fillRectangle(int(x), y, w, h, LColor::mathbg);
+ pain.rectangle(int(x), y, w, h, LColor::mathframe);
+
+ pain.text(int(x + 2), baseline, prefix(), font);
+ x += width(bv, font);
-string const InsetFormulaMacro::EditMessage() const
-{
- return _("Math macro editor mode");
+ // formula
+ float t = InsetFormula::width(bv, f) + 5;
+ x -= t;
+ InsetFormula::draw(bv, font, baseline, x, cleared);
+ x += t;
}
-void InsetFormulaMacro::Edit(BufferView * bv, int x, int y,unsigned int button)
-{
- opened_ = true;
- par = static_cast<MathParInset*>(tmacro_->Clone());
- InsetFormula::Edit(bv, x, y, button);
-}
-
-
-void InsetFormulaMacro::InsetUnlock(BufferView * bv)
+string const InsetFormulaMacro::EditMessage() const
{
- opened_ = false;
- tmacro_->setData(par->GetData());
- tmacro_->setEditMode(false);
- InsetFormula::InsetUnlock(bv);
+ return _("Math macro editor mode");
}
kb_action action, string const & arg)
{
if (action == LFUN_MATH_MACROARG) {
- int const i = lyx::atoi(arg) - 1;
- if (i >= 0 && i < tmacro_->getNoArgs()) {
- mathcursor->insertInset(tmacro_->getMacroPar(i),
- LM_TC_INSET);
+ int const i = lyx::atoi(arg);
+ if (i > 0 && i <= tmacro()->nargs()) {
+ mathcursor->insertInset(new MathMacroArgument(i), LM_TC_INSET);
InsetFormula::UpdateLocal(bv);
}
return DISPATCHED;
}
- tmacro_->setEditMode(true);
- tmacro_->Metrics();
- RESULT result = InsetFormula::LocalDispatch(bv, action, arg);
- tmacro_->setEditMode(false);
-
- return result;
+ par->Metrics();
+ return InsetFormula::LocalDispatch(bv, action, arg);
+}
+
+MathMacroTemplate * InsetFormulaMacro::tmacro() const
+{
+ return static_cast<MathMacroTemplate *>(par);
}
#ifndef INSET_FORMULA_MACRO_H
#define INSET_FORMULA_MACRO_H
-#include <boost/smart_ptr.hpp>
-
#include "formula.h"
#ifdef __GNUG__
class MathMacroTemplate;
+// InsetFormulaMacro's ParInset is the ParInset of the macro definition
+// which in turn is stored in the global MathMacroTable.
+// No copying/updating needed anymore...
///
class InsetFormulaMacro: public InsetFormula {
explicit
InsetFormulaMacro(string name, int na);
///
- ~InsetFormulaMacro();
- ///
int ascent(BufferView *, LyXFont const &) const;
///
int descent(BufferView *, LyXFont const &) const;
void draw(BufferView *,LyXFont const &, int, float &, bool) const;
///
void Read(Buffer const *, LyXLex & lex);
- ///
+ ///
void Write(Buffer const *, std::ostream & os) const;
///
int Latex(Buffer const *, std::ostream & os, bool fragile,
/// what appears in the minibuffer when opening
string const EditMessage() const;
///
- void Edit(BufferView *, int x, int y, unsigned int button);
- ///
- void InsetUnlock(BufferView *);
- ///
RESULT LocalDispatch(BufferView *, kb_action, string const &);
-
private:
+ /// prefix in inset
+ string prefix() const;
///
- bool opened_;
- ///
- string name_;
- ///
- boost::shared_ptr<MathMacroTemplate> tmacro_;
+ MathMacroTemplate * tmacro() const;
};
-
-inline
-Inset::Code InsetFormulaMacro::LyxCode() const
+inline Inset::Code InsetFormulaMacro::LyxCode() const
{
return Inset::MATHMACRO_CODE;
}
#include <iosfwd>
enum MathedMacroFlag {
- MMF_Env = 1,
- MMF_Exp = 2,
+ MMF_Env = 1,
+ MMF_Exp = 2,
MMF_Edit = 4
};
-extern
std::ostream & operator<<(std::ostream & o, MathedMacroFlag mmf);
#endif
/*
-* File: math_cursor.C
-* Purpose: Interaction for mathed
-* Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
-* Created: January 1996
-* Description: Math interaction for a WYSIWYG math editor.
-*
-* Dependencies: Xlib, XForms
-*
-* Copyright: 1996, Alejandro Aguilar Sierra
-*
-* Version: 0.8beta, Mathed & Lyx project.
-*
-* You are free to use and modify this code under the terms of
-* the GNU General Public Licence version 2 or later.
-*/
+ * File: math_cursor.C
+ * Purpose: Interaction for mathed
+ * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
+ * Created: January 1996
+ * Description: Math interaction for a WYSIWYG math editor.
+ *
+ * Dependencies: Xlib, XForms
+ *
+ * Copyright: 1996, Alejandro Aguilar Sierra
+ *
+ * Version: 0.8beta, Mathed & Lyx project.
+ *
+ * You are free to use and modify this code under the terms of
+ * the GNU General Public Licence version 2 or later.
+ */
#ifdef __GNUG__
#pragma implementation
#include "math_parser.h"
#include "math_cursor.h"
#include "math_macro.h"
+#include "math_macroarg.h"
#include "math_macrotable.h"
#include "math_root.h"
#include "support/lstrings.h"
#include "math_macrotemplate.h"
#include "mathed/support.h"
+
+
+
using std::endl;
namespace {
int const MAX_STACK_ITEMS = 32;
struct MathStackXIter {
+public:
+ enum type {MATHSTK, SELSTK};
+
+private:
std::vector<MathedXIter> item;
- int i;
+ int pos_;
+ type id_;
+
- MathStackXIter(int n = MAX_STACK_ITEMS)
- : item(n), i(0) {
+public:
+
+ MathStackXIter(type id)
+ : item(MAX_STACK_ITEMS), pos_(-1), id_(id) {
}
MathedXIter * push() {
- return &item[i++];
+ //dump();
+ ++pos_;
+ return &item[pos_];
}
MathedXIter * pop() {
- --i;
- return &item[i - 1];
+ //dump();
+ item[pos_] = MathedXIter();
+ --pos_;
+ return &item[pos_];
}
MathedXIter * Item(int idx) {
- if (idx + 1 > i)
- lyxerr << "Wrong index: " << idx << " i: " << i << endl;
- return &item[i - idx - 1];
+ if (idx > pos_)
+ lyxerr << "Wrong index: " << idx << " pos_: " << pos_ << endl;
+ return &item[pos_ - idx];
}
void Reset() {
- i = 0;
+ pos_ = -1;
}
bool Full() {
- return i >= MAX_STACK_ITEMS;
+ return pos_ >= MAX_STACK_ITEMS - 2;
+ }
+
+ bool empty() {
+ return pos_ <= 0;
+ }
+
+ MathParInset * outer() {
+ return empty() ? 0 : item[0].getPar();
}
- bool Empty() {
- return i <= 1;
+ int Level() {
+ return pos_;
}
- int Level() { return i; }
+ MathParInset * parInset(int i) {
+ return pos_ < 0 ? 0 : item[i].getPar();
+ }
+
+
+ void dump() {
+ lyxerr << "\n------------- MathStack ------------\n";
+ for (int i = 0; i < pos_ + 3; ++i) {
+ lyxerr << "pos: " << i << " par: "
+ << item[i].getPar() << " data: '"
+ << *item[i].GetData() << "'" << endl;
+ }
+ lyxerr << "------------- MathStack ------------\n";
+ }
-} mathstk, selstk;
+};
+
+MathStackXIter mathstk = MathStackXIter(MathStackXIter::MATHSTK);
+MathStackXIter selstk = MathStackXIter(MathStackXIter::SELSTK);
} // namespace anon
+extern MathedCursor * mathcursor;
+
+bool is_mathcursor_inside(MathParInset * p)
+{
+ //lyxerr << "called is_mathcursor_inside: " << p << endl;
+
+ if (!mathcursor) {
+ //lyxerr << " mathcursor not set" << endl;
+ return false;
+ }
+
+ for (int i = 0; i < mathstk.Level(); ++i) {
+ //lyxerr << " level: " << i << " " << mathstk.parInset(i) << endl;
+ if (mathstk.parInset(i) == p) {
+ //lyxerr << " found!" << endl;
+ return true;
+ }
+ }
+
+ //lyxerr << " cursor: " << mathcursor->cursor->getPar() << endl;
+ if (mathcursor->cursor->getPar() == p) {
+ //lyxerr << " found!" << endl;
+ return true;
+ }
+ //lyxerr << " not found" << endl;
+ return false;
+}
+
+
+
/***---------------- Mathed Cursor ---------------------------***/
+
MathedCursor::MathedCursor(MathParInset * p) // : par(p)
{
- accent = 0;
- anchor = 0;
- lastcode = LM_TC_MIN;
+ accent = 0;
+ anchor = 0;
+ lastcode = LM_TC_MIN;
SetPar(p);
- if (!MathMacroTable::built)
- MathMacroTable::mathMTable.builtinMacros();
}
-
void MathedCursor::SetPar(MathParInset * p)
{
- macro_mode = false;
- selection = false; // not SelClear() ?
- mathstk.Reset();
- cursor = mathstk.push();
- par = p;
- cursor->SetData(par);
+ macro_mode = false;
+ selection = false; // not SelClear() ?
+ mathstk.Reset();
+ cursor = mathstk.push();
+ par = p;
+ SetCursorData(par);
+}
+
+
+void MathedCursor::SetCursorData(MathParInset * p)
+{
+ //lyxerr << "SetCursorData: " << p << endl;
+ cursor->SetData(p);
}
void MathedCursor::draw(Painter & pain, int x, int y)
{
// lyxerr << "Cursor[" << x << " " << y << "] ";
- //win = pm; // win = (mathedCanvas) ? mathedCanvas: pm;
+ //lyxerr << "MathedCursor::draw: par: " << par << endl;
par->Metrics();
int w = par->Width() + 2;
h += 8;
}
- pain.rectangle(x - 1, y - a, w, h, LColor::mathframe);
+ pain.rectangle(x - 1, y - a, w, h, LColor::green);
par->draw(pain, x, y);
cursor->Adjust();
par->GetXY(x, y);
//mathed_set_font(LM_TC_VAR, 1);
pain.fillRectangle(x, y - par->Ascent(),
- x + w, y - par->Ascent() + h,
- LColor::mathbg);
+ x + w, y - par->Ascent() + h, LColor::mathbg);
+
+ lyxerr << "MathedCursor::Redraw: par: " << par << endl;
par->draw(pain, x, y);
}
bool MathedCursor::Left(bool sel)
{
+ //par->GetData().dump(cerr);
if (macro_mode) {
// was MacroModeBack()
if (!imacro->GetName().empty()) {
bool result = cursor->Prev();
- if (!result && !mathstk.Empty()) {
+ if (!result && !mathstk.empty()) {
cursor = mathstk.pop();
cursor->Adjust();
result = true;
if (!p)
return result;
+ //lyxerr << "\nInset, max arg # " << p->getMaxArgumentIdx() << endl;
p->setArgumentIdx(p->getMaxArgumentIdx());
cursor = mathstk.push();
- cursor->SetData(p);
+ SetCursorData(p);
cursor->GoLast();
}
}
// Leave the inset
bool MathedCursor::Pop()
{
- if (!mathstk.Empty()) {
+ if (!mathstk.empty()) {
cursor = mathstk.pop();
cursor->Next();
return true;
if (!p)
return false;
cursor = mathstk.push();
- cursor->SetData(p);
+ SetCursorData(p);
return true;
}
return false;
}
if (!selection) {
- MathParInset *p = cursor->GetActiveInset();
+ MathParInset * p = cursor->GetActiveInset();
if (!p) {
- lyxerr << "Math error: Inset expected." << endl;
- return cursor->Next();
+ lyxerr << "Math error: Inset expected." << endl;
+ return cursor->Next();
}
p->setArgumentIdx(0);
cursor = mathstk.push();
- cursor->SetData(p);
+ SetCursorData(p);
result = true;
} else
result = cursor->Next();
} else {
- if (cursor->GetChar()!= LM_TC_CR)
- result = cursor->Next();
- if (!result && !mathstk.Empty()) {
+ if (cursor->GetChar() != LM_TC_CR)
+ result = cursor->Next();
+ if (!result && !mathstk.empty()) {
cursor = mathstk.pop();
cursor->Next();
cursor->Adjust();
lastcode = LM_TC_MIN;
mathstk.Reset();
cursor = mathstk.push();
- cursor->SetData(par);
+ SetCursorData(par);
cursor->fitCoord(x, y);
- while (cursor->GetX()<x && cursor->OK()) {
+ while (cursor->GetX() < x && cursor->OK()) {
if (cursor->IsActive()) {
MathParInset * p = cursor->GetActiveInset();
if (p->Inside(x, y)) {
p->SetFocus(x, y);
cursor = mathstk.push();
- cursor->SetData(p);
+ SetCursorData(p);
cursor->fitCoord(x, y);
continue;
}
}
-MathMatrixInset * create_multiline(short int type, int cols)
+MathMatrixInset create_multiline(short int type, int cols)
{
int columns;
string align;
break;
}
- MathMatrixInset * mt = new MathMatrixInset(columns, -1);
- mt->SetAlign(' ', align);
+ MathMatrixInset mt(columns, -1);
+ mt.SetAlign(' ', align);
return mt;
}
if (t == LM_TC_CR) {
MathParInset * p = cursor->getPar();
- if (p == par && p->GetType()<LM_OT_MPAR && p->GetType()>LM_OT_MIN) {
+ if (p == par && p->GetType() < LM_OT_MPAR && p->GetType() > LM_OT_MIN) {
short int type = LM_OT_MPAR;
int cols = 1;
if (c >= '1' && c <= '9') {
if (p->GetType() == LM_OT_PARN)
++type;
- MathMatrixInset * mt = create_multiline(type, cols);
+ MathMatrixInset * mt =
+ new MathMatrixInset(create_multiline(type, cols));
mt->SetStyle(LM_ST_DISPLAY);
mt->SetType(type);
mt->setData(p->GetData());
p = mt;
p->Metrics();
int pos = cursor->getPos();
- cursor->SetData(par);
+ SetCursorData(par);
cursor->goPosAbs(pos);
}
- if (p && p->Permit(LMPF_ALLOW_CR)) {
+ if (p && p->Permit(LMPF_ALLOW_CR)) {
cursor->addRow();
}
} else if (t == LM_TC_TAB) {
MathParInset * p = cursor->getPar();
- if (p && p->Permit(LMPF_ALLOW_TAB)) {
+ if (p && p->Permit(LMPF_ALLOW_TAB)) {
if (c) {
cursor->insert(c, t);
cursor->checkTabs();
} else
cursor->goNextColumn();
- } else // Navigate between arguments
- if (p && p->GetType() == LM_OT_MACRO) {
- if (p->getArgumentIdx() < p->getMaxArgumentIdx()) {
- p->setArgumentIdx(p->getArgumentIdx() + 1);
- cursor->SetData(p);
- return;
+ } else {
+ // Navigate between arguments
+ if (p && p->GetType() == LM_OT_MACRO) {
+ if (p->getArgumentIdx() < p->getMaxArgumentIdx()) {
+ p->setArgumentIdx(p->getArgumentIdx() + 1);
+ SetCursorData(p);
+ return;
+ }
}
}
} else {
}
}
- if (accent) {
+ if (accent)
doAccent(c, t);
- } else
+ else
cursor->insert(c, t);
lastcode = t;
SelDel();
}
- if (mathstk.i < MAX_STACK_ITEMS - 1) {
+ if (!mathstk.Full()) {
if (accent && !MathIsActive(t)) {
doAccent(p);
} else {
return;
}
- if (cursor->Empty() && !mathstk.Empty())
+ if (cursor->Empty() && !mathstk.empty())
cursor = mathstk.pop();
- // if (cursor->GetChar()!= LM_TC_TAB)
+ // if (cursor->GetChar() != LM_TC_TAB)
cursor->Delete();
cursor->checkTabs();
}
MathParInset * p = cursor->getPar();
- if (p && p->GetType() <= LM_OT_MATRIX && p->GetType() >= LM_OT_MPAR) {
+ if (p && p->GetType() <= LM_OT_MATRIX && p->GetType() >= LM_OT_MPAR)
cursor->delRow();
- }
}
if (MathIsUp(cd)) {
Push();
return true;
- } else {
- // A subscript may be followed by a superscript
- cursor->ipush();
- cursor->Next();
- if (MathIsUp(cursor->GetChar())) {
- Push();
- return true;
- } else // return to the previous state
- cursor->ipop();
}
+
+ // A subscript may be followed by a superscript
+ cursor->ipush();
+ cursor->Next();
+ if (MathIsUp(cursor->GetChar())) {
+ Push();
+ return true;
+ }
+
+ // return to the previous state
+ cursor->ipop();
}
result = cursor->Up();
bool is_down = (cx->GetChar() == LM_TC_DOWN);
cursor = mathstk.pop();
cursor->Next();
- result = (is_down) ? true: Up();
+ result = is_down ? true : Up();
} else {
- result = (p->getArgumentIdx() > 0);
+ result = p->getArgumentIdx() > 0;
if (result) {
p->setArgumentIdx(p->getArgumentIdx() - 1);
- cursor->SetData(p);
+ SetCursorData(p);
}
}
- if (!result && !mathstk.Empty()) {
+ if (!result && !mathstk.empty()) {
cursor = mathstk.pop();
return Up();
}
if (MathIsDown(cd)) {
Push();
return true;
- } else {
+ }
// A superscript may be followed by a subscript
cursor->ipush();
cursor->Next();
if (MathIsDown(cursor->GetChar())) {
Push();
return true;
- } else
- cursor->ipop();
}
+
+ // return to the previous state
+ cursor->ipop();
}
result = cursor->Down();
bool is_up = (cx->GetChar() == LM_TC_UP);
cursor = mathstk.pop();
cursor->Next();
- result = (is_up) ? true : Down();
+ result = is_up ? true : Down();
} else {
- result = (p->getArgumentIdx() < p->getMaxArgumentIdx());
+ result = p->getArgumentIdx() < p->getMaxArgumentIdx();
if (result) {
p->setArgumentIdx(p->getArgumentIdx() + 1);
- cursor->SetData(p);
+ SetCursorData(p);
}
}
- if (!result && !mathstk.Empty()) {
+ if (!result && !mathstk.empty()) {
cursor = mathstk.pop();
return Down(sel);
}
{
MathParInset * p = cursor->getPar();
p->UserSetSize(size);
- cursor->SetData(p);
+ SetCursorData(p);
}
l = in_word_set(s);
if (!l) {
- p = MathMacroTable::mathMTable.createMacro(s);
+ p = new MathMacro(MathMacroTable::provideTemplate(s));
if (!p) {
- lyxerr[Debug::MATHED] << "Macro2 " << s << ' ' << tcode << endl;
- if (s == "root") {
- p = new MathRootInset;
- tcode = LM_TC_ACTIVE_INSET;
- } else
- p = new MathFuncInset(s, LM_OT_UNDEF);
+ lyxerr[Debug::MATHED] << "Macro2 " << s << ' ' << tcode << endl;
+ if (s == "root") {
+ p = new MathRootInset;
+ tcode = LM_TC_ACTIVE_INSET;
+ } else
+ p = new MathFuncInset(s, LM_OT_UNDEF);
} else {
tcode = static_cast<MathMacro*>(p)->getTCode();
lyxerr[Debug::MATHED] << "Macro2 " << s << ' ' << tcode << endl;
break;
case LM_TK_MACRO:
- p = MathMacroTable::mathMTable.createMacro(s);
+ p = new MathMacro(MathMacroTable::provideTemplate(s));
tcode = static_cast<MathMacro*>(p)->getTCode();
lyxerr[Debug::MATHED] << "Macro " << s << ' ' << tcode << endl;
break;
macro_mode = false;
latexkeys const * l = in_word_set(imacro->GetName());
if (!imacro->GetName().empty()
- && (!l || (l && IsMacro(l->token, l->id))) &&
- !MathMacroTable::mathMTable.createMacro(imacro->GetName())) {
+ && (!l || (l && IsMacro(l->token, l->id))) &&
+ !MathMacroTable::hasTemplate(imacro->GetName()))
+ {
if (!l) {
//imacro->SetName(macrobf);
// This guarantees that the string will be removed by destructor
static_cast<MathAccentInset*>(cursor->GetInset())->getAccentCode());
}
cursor->Delete();
- if (l || MathMacroTable::mathMTable.createMacro(imacro->GetName())) {
+ if (l || MathMacroTable::hasTemplate(imacro->GetName())) {
Interpret(imacro->GetName());
}
imacro->SetName("");
void MathedCursor::setAccent(int ac)
{
- if (ac > 0 && accent < 8) {
+ if (ac > 0 && accent < 8)
nestaccent[accent++] = ac;
- } else
+ else
accent = 0; // consumed!
}
int MathedCursor::getAccent() const
{
- return (accent > 0) ? nestaccent[accent - 1]: 0;
+ return (accent > 0) ? nestaccent[accent - 1] : 0;
}
{
return lastcode;
}
+
+
+bool MathedCursor::hasData(MathedArray const & ar)
+{
+ lyxerr << "hasData: ar: " << &ar << " cursor: " << cursor->GetData() <<
+endl;
+ return &ar == cursor->GetData();
+}
///
MathParInset * getCurrentPar() const;
///
+ void SetCursorData(MathParInset *);
+ ///
void SetPar(MathParInset *);
///
void Interpret(string const &);
void toggleLastCode(MathedTextCodes t);
///
MathedTextCodes getLastCode() const;
+
+ /// true iff cursor points to data
+ bool hasData(MathedArray const &);
-protected:
+//protected:
///
bool macro_mode;
#pragma implementation
#endif
+#include "debug.h"
#include "math_iter.h"
#include "math_inset.h"
#include "symbol_def.h"
MathedInset::MathedInset(string const & nm, short ot, short st)
- : name(nm), objtype(ot), width(0), ascent(0), descent(0), size_(st)
+ : name(nm), objtype(ot), width(0), ascent(0), descent(0),
+ size_(st)
{}
pain.text(x, y, st, mf);
}
+void MathedInset::substitute(MathMacro *)
+{
+}
+
int MathedInset::Ascent() const
{
size_ = s;
}
-
void MathedInset::incSize()
{
++size_;
#include "symbol_def.h"
class Painter;
+class MathMacro;
/** Abstract base class for all math objects.
A math insets is for use of the math editor only, it isn't a
virtual void Write(std::ostream &, bool fragile) = 0;
/// Reproduces itself
virtual MathedInset * Clone() = 0;
+ /// Reproduces itself with macro arguments substituted
+ virtual void substitute(MathMacro * macro);
/// Compute the size of the object
virtual void Metrics() = 0;
///
fcode_ = c;
}
+byte MathedIter::at() const
+{
+ return (*array)[pos];
+}
+
byte MathedIter::at(int p) const
{
return (*array)[p];
///
MathedArray * GetData() const;
///
+ byte at() const;
+ ///
byte & at(int pos);
///
byte at(int pos) const;
#include "mathed/support.h"
#include "math_macrotemplate.h"
#include "macro_support.h"
+#include "Painter.h"
-using std::ostream;
-using std::endl;
+using namespace std;
ostream & operator<<(ostream & o, MathedTextCodes mtc)
{
}
-MathMacro::MathMacro(boost::shared_ptr<MathMacroTemplate> const & t)
- : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO),
- tmplate_(t)
+MathMacro::MathMacro(MathMacroTemplate const & t)
+ : MathParInset(LM_ST_TEXT, t.GetName(), LM_OT_MACRO),
+ tmplate_(const_cast<MathMacroTemplate *>(&t)),
+ args_(t.nargs()),
+ idx_(-1)
{
- //nargs_ = tmplate_->getNoArgs();
- int const n = tmplate_->getNoArgs();
-
- tcode_ = tmplate_->getTCode();
-
- for (int i = 0; i < n; ++i) {
- args_.push_back(MathMacroArgument(t->args_[i]));
- }
- //for (int i = 0; i < nargs_; ++i) {
- // MathMacroArgument * ma = new MathMacroArgument(*t->args_[i]);
- // args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
- //}
-
- idx_ = 0;
- SetName(tmplate_->GetName());
+ array = tmplate_->GetData();
+ for (int i = 0; i < nargs(); ++i)
+ args_[i].reset(new MathParInset);
}
}
+void MathMacro::expand()
+{
+ expanded_.reset(static_cast<MathParInset *>(tmplate_->Clone()));
+ expanded_->substitute(this);
+}
+
+
+
+MathParInset const * MathMacro::arg(int i) const
+{
+ if (i < 0 || i >= nargs()) {
+ lyxerr << "Illegal index " << i << " max: " << nargs() << endl;
+ lyx::Assert(0);
+ return 0;
+ }
+
+ return i >= 0 ? args_[i].get() : static_cast<MathParInset const *>(this);
+}
+
+MathParInset * MathMacro::arg(int i)
+{
+ if (i < 0 || i >= nargs()) {
+ lyxerr << "Illegal index " << i << " max: " << nargs() << endl;
+ lyx::Assert(0);
+ return 0;
+ }
+
+ return i >= 0 ? args_[i].get() : static_cast<MathParInset *>(this);
+}
+
+
+MathMacroTemplate * MathMacro::tmplate() const
+{
+ return const_cast<MathMacroTemplate *>(tmplate_);
+}
+
+
+extern bool is_mathcursor_inside(MathParInset *);
+
+
void MathMacro::Metrics()
{
- for (unsigned int i = 0; i < args_.size(); ++i)
- tmplate_->args_[i] = getArg(i);
- tmplate_->SetStyle(size());
- tmplate_->Metrics();
- width = tmplate_->Width();
- ascent = tmplate_->Ascent();
- descent = tmplate_->Descent();
+
+ if (is_mathcursor_inside(this)) {
+
+ tmplate_->Metrics();
+ width = tmplate_->Width() + 4;
+ ascent = tmplate_->Ascent() + 2;
+ descent = tmplate_->Descent() + 2;
+
+ width += mathed_string_width(LM_TC_TEXTRM, size(), GetName()) + 10;
+
+ for (int i = 0; i < nargs(); ++i) {
+ MathParInset * p = arg(i);
+ p->Metrics();
+ if (p->Width() + 30 > width)
+ width = p->Width() + 30;
+ descent += p->Height() + 10;
+ }
+ } else {
+ expand();
+ expanded_->Metrics();
+ width = expanded_->Width() + 4;
+ ascent = expanded_->Ascent() + 2;
+ descent = expanded_->Descent() + 2;
+
+ }
}
void MathMacro::draw(Painter & pain, int x, int y)
{
- xo(x);
- yo(y);
- Metrics();
- tmplate_->SetStyle(size());
- tmplate_->draw(pain, x, y);
+ LColor::color col;
+
+ if (is_mathcursor_inside(this)) {
+ int h = y + Descent() - 2;
+ for (int i = nargs() - 1; i >= 0; --i) {
+ MathParInset * p = arg(i);
+ h -= p->Descent() + 5;
+ p->draw(pain, x + 30, h);
+ char str[] = "#1:";
+ str[1] += i;
+ drawStr(pain, LM_TC_TEX, size(), x + 1, h, str);
+ h -= p->Ascent() + 5;
+ }
+
+ h -= tmplate_->Descent();
+ int w = mathed_string_width(LM_TC_TEXTRM, size(), GetName());
+ drawStr(pain, LM_TC_TEXTRM, size(), x + 2, h, GetName());
+ tmplate_->draw(pain, x + w + 12, h);
+
+ col = LColor::red;
+ } else {
+ expanded_->draw(pain, x + 2, y - 1);
+ col = LColor::black;
+ }
+
+ int w = Width();
+ int a = Ascent();
+ int h = Height();
+ pain.rectangle(x, y - a, w, h, col);
}
bool MathMacro::setArgumentIdx(int i)
{
- if (i >= 0 && 0 < (args_.size() - i)) {
+ if (i >= 0 && 0 < (nargs() - i)) {
idx_ = i;
return true;
} else
return false;
+ idx_ = i;
+ return true;
}
int MathMacro::getArgumentIdx() const
{
+ //lyxerr << "MathMacro::getArgumentIdx: res: " << idx_ << endl;
return idx_;
}
int MathMacro::getMaxArgumentIdx() const
{
- return args_.size() - 1;
+ return nargs() - 1;
+}
+
+
+
+int MathMacro::nargs() const
+{
+ return args_.size();
}
MathedArray & MathMacro::GetData()
{
- return args_[idx_].GetData();
+ //lyxerr << "MathMacro::GetData: " << *this << endl;
+ return idx_ >= 0 ? arg(idx_)->GetData() : MathParInset::GetData();
}
MathedArray const & MathMacro::GetData() const
{
- return args_[idx_].GetData();
+ //lyxerr << "MathMacro::GetData: " << *this << endl;
+ return idx_ >= 0 ? arg(idx_)->GetData() : MathParInset::GetData();
}
int MathMacro::GetColumns() const
{
- return tmplate_->getMacroPar(idx_)->GetColumns();
+ return idx_ >= 0 ? arg(idx_)->GetColumns() : MathParInset::GetColumns();
}
void MathMacro::GetXY(int & x, int & y) const
{
- const_cast<MathMacro*>(this)->Metrics();
- tmplate_->GetMacroXY(idx_, x, y);
+ if (idx_ >= 0)
+ arg(idx_)->GetXY(x, y);
+ else
+ MathParInset::GetXY(x, y);
}
bool MathMacro::Permit(short f) const
{
- return (args_.size() > 0) ?
- tmplate_->getMacroPar(idx_)->Permit(f) :
- MathParInset::Permit(f);
+ return idx_ >= 0 ? arg(idx_)->Permit(f) : MathParInset::Permit(f);
}
void MathMacro::SetFocus(int x, int y)
{
- Metrics();
- tmplate_->SetMacroFocus(idx_, x, y);
+ idx_ = -1;
+ for (int i = 0; i < nargs(); ++i) {
+ if (arg(i)->Inside(x, y)) {
+ idx_ = i;
+ break;
+ }
+ }
+}
+
+void MathMacro::setData(MathedArray const & a, int i)
+{
+ arg(i)->setData(a);
}
void MathMacro::setData(MathedArray const & a)
{
- args_[idx_].setData(a);
+ if (idx_ >= 0)
+ arg(idx_)->setData(a);
+ else
+ array = a;
}
MathedTextCodes MathMacro::getTCode() const
{
- return tcode_;
+ return nargs() ? LM_TC_ACTIVE_INSET : LM_TC_INSET;
+ //return LM_TC_INSET;
}
+void MathMacro::dump(ostream & os) const
+{
+ os << "\n macro: '" << this << "'\n";
+ os << " name: '" << name << "'\n";
+ os << " idx: '" << idx_ << "'\n";
+ os << " data: '" << array << "'\n";
+ os << " nargs: '" << nargs() << "'\n";
+ for (int i = 0; i < nargs(); ++i)
+ os << " " << arg(i) << ": " << arg(i)->GetData() << endl;
+ os << endl;
+}
void MathMacro::Write(ostream & os, bool fragile)
{
os << '\\' << name;
-
- int const n = args_.size();
-
- if (n > 0) {
+ for (int i = 0; i < nargs(); ++i) {
os << '{';
-
- for (int i = 0; i < n; ++i) {
- array = args_[i].GetData();
- MathParInset::Write(os, fragile);
- if (i < n - 1)
- os << "}{";
- }
+ arg(i)->Write(os, fragile);
os << '}';
- } else
+ }
+ if (nargs() == 0)
os << ' ';
}
-
-
-MathMacroArgument const & MathMacro::getArg(int i) const
-{
- return args_[i];
-}
-//boost::shared_ptr<MathMacroArgument> MathMacro::getArg(int i)
-//{
-// return args_[i];
-//}
-
#endif
#include <vector>
+#include <iosfwd>
#include <boost/smart_ptr.hpp>
#include "math_parinset.h"
*/
class MathMacro : public MathParInset {
public:
- /// A macro can only be built from an existing template
- explicit
- MathMacro(boost::shared_ptr<MathMacroTemplate> const &);
+ /// A macro can be built from an existing template
+ explicit MathMacro(MathMacroTemplate const &);
///
void draw(Painter &, int, int);
///
MathedInset * Clone();
///
void Write(std::ostream &, bool fragile);
- ///
+ /// Index 0 is the template, index 1..nargs() are the parameters
bool setArgumentIdx(int);
///
int getArgumentIdx() const;
///
int getMaxArgumentIdx() const;
///
+ int nargs() const;
+ ///
int GetColumns() const;
///
void GetXY(int &, int &) const;
///
void setData(MathedArray const &);
///
+ void setData(MathedArray const &, int);
+ ///
MathedTextCodes getTCode() const;
///
bool Permit(short) const;
///
- MathMacroArgument const & getArg(int i) const;
- //boost::shared_ptr<MathMacroArgument> getArg(int i);
-private:
+ void expand();
///
- boost::shared_ptr<MathMacroTemplate> tmplate_;
+ void dump(ostream & os) const;
///
- //std::vector<boost::shared_ptr<MathMacroArgument> > args_;
- std::vector<MathMacroArgument> args_;
+ MathParInset const * arg(int) const;
///
- int idx_;
+ MathParInset * arg(int);
///
- //int nargs_;
+ MathMacroTemplate * tmplate() const;
+private:
+ ///
+ MathMacroTemplate * tmplate_;
+ /// our arguments
+ std::vector< boost::shared_ptr<MathParInset> > args_;
+ /// the expanded version fror drawing
+ boost::shared_ptr<MathParInset> expanded_;
///
- MathedTextCodes tcode_;
+ int idx_;
+
+ /// unimplemented
+ void operator=(MathMacro const &);
};
+
+inline ostream & operator<<(ostream & os, MathMacro const & m)
+{
+ m.dump(os);
+ return os;
+}
#endif
#pragma implementation
#endif
+#include "math_macro.h"
#include "math_macroarg.h"
#include "mathed/support.h"
#include "Lsstream.h"
+#include "debug.h"
-MathMacroArgument::MathMacroArgument(int n)
- : MathParInset(LM_ST_TEXT, "", LM_OT_MACRO_ARG),
- expnd_mode_(false), number_(n)
-{}
+using namespace std;
+MathMacroArgument::MathMacroArgument(int n)
+ : MathedInset(string(), LM_OT_MACRO_ARG, LM_ST_TEXT),
+ number_(n)
+{
+ if (n < 1 || n > 9) {
+ lyxerr << "MathMacroArgument::MathMacroArgument: wrong Argument id: "
+ << n << endl;
+ lyx::Assert(0);
+ }
+}
MathedInset * MathMacroArgument::Clone()
{
+ //return new MathMacroArgument(*this);
return this;
}
-
-void MathMacroArgument::setExpand(bool e)
+int MathMacroArgument::number() const
{
- expnd_mode_ = e;
+ return number_;
}
-
-bool MathMacroArgument::getExpand() const
+void MathMacroArgument::substitute(MathMacro * /*m*/)
{
- return expnd_mode_;
+ lyxerr << "Calling MathMacroArgument::substitute!\n";
+ //return m->arg(number_)->Clone();
}
-void MathMacroArgument::draw(Painter & pain, int x, int baseline)
+void MathMacroArgument::draw(Painter & pain, int x, int y)
{
- if (expnd_mode_) {
- MathParInset::draw(pain, x, baseline);
- } else {
- std::ostringstream ost;
- ost << '#' << number_;
- drawStr(pain, LM_TC_TEX, size(), x, baseline, ost.str().c_str());
- }
+ char str[] = "#0";
+ str[1] += number_;
+ drawStr(pain, LM_TC_TEX, size(), x, y, str);
}
+
void MathMacroArgument::Metrics()
{
- if (expnd_mode_) {
- MathParInset::Metrics();
- } else {
- std::ostringstream ost;
- ost << '#' << number_;
- width = mathed_string_width(LM_TC_TEX, size(),
- ost.str().c_str());
- mathed_string_height(LM_TC_TEX, size(), ost.str().c_str(),
- ascent, descent);
- }
+ char str[] = "#0";
+ str[1] += number_;
+ width = mathed_string_width(LM_TC_TEX, size(), str);
+ mathed_string_height(LM_TC_TEX, size(), str, ascent, descent);
}
-void MathMacroArgument::Write(std::ostream & os, bool fragile)
+void MathMacroArgument::Write(std::ostream & os, bool /*fragile*/)
{
- if (expnd_mode_) {
- MathParInset::Write(os, fragile);
- } else {
- os << '#' << number_ << ' ';
- }
+ os << '#' << number_ << ' ';
}
+
#ifndef MATHMACROARGUMENT_H
#define MATHMACROARGUMENT_H
-#include "math_parinset.h"
+#include "math_inset.h"
#ifdef __GNUG__
#pragma interface
/** A macro argument
\author Alejandro Aguilar Sierra
*/
-class MathMacroArgument : public MathParInset {
+class MathMacroArgument : public MathedInset {
public:
///
- explicit
- MathMacroArgument(int);
+ explicit MathMacroArgument(int);
///
MathedInset * Clone();
///
+ void substitute(MathMacro *);
+ ///
void Metrics();
///
void draw(Painter &, int x, int baseline);
///
void Write(std::ostream &, bool fragile);
- /// Is expanded or not
- void setExpand(bool e);
- /// Is expanded or not
- bool getExpand() const;
-private:
- ///
- bool expnd_mode_;
///
+ int number() const;
+
+
+private:
+ /// A number between 1 and 9
int number_;
};
+
#endif
using std::endl;
-MathMacroTable MathMacroTable::mathMTable;
+MathMacroTable::table_type MathMacroTable::macro_table;
bool MathMacroTable::built = false;
-MathMacro * MathMacroTable::createMacro(string const & name) const
+void MathMacroTable::dump()
{
- boost::shared_ptr<MathMacroTemplate> mt = getTemplate(name);
- return (mt.get()) ? new MathMacro(mt) : 0;
+ cerr << "\n------------------------------------------\n";
+ table_type::const_iterator it;
+ for (it = macro_table.begin(); it != macro_table.end(); ++it)
+ cerr << it->first << ": " << it->second->GetData() << endl;
+ cerr << "------------------------------------------\n";
}
-boost::shared_ptr<MathMacroTemplate> const
-MathMacroTable::getTemplate(string const & name) const
+MathMacroTemplate &
+MathMacroTable::provideTemplate(string const & name, int na)
{
- table_type::const_iterator cit = macro_table.find(name);
- if (cit != macro_table.end()) return (*cit).second;
- return boost::shared_ptr<MathMacroTemplate>();
+ if (!built)
+ builtinMacros();
+
+ if (macro_table.find(name) == macro_table.end())
+ macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
+
+ return *(macro_table.find(name)->second);
}
-void
-MathMacroTable::addTemplate(boost::shared_ptr<MathMacroTemplate> const & m)
+MathMacroTemplate &
+MathMacroTable::provideTemplate(string const & name)
{
- lyx::Assert(m.get());
- macro_table[m->GetName()] = m;
+ if (!built)
+ builtinMacros();
+
+ return *macro_table[name];
+}
+
+
+bool MathMacroTable::hasTemplate(string const & name)
+{
+ if (!built)
+ builtinMacros();
+
+ return macro_table.find(name) != macro_table.end();
+}
+
+
+MathMacro * MathMacroTable::cloneTemplate(string const & name)
+{
+ return new MathMacro(provideTemplate(name));
}
// This macro doesn't have arguments
{
- boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("notin", 0));
- addTemplate(m);
- MathedArray array;
- MathedIter iter(&array);
+ MathMacroTemplate & m = provideTemplate("notin", 0);
+ MathedIter iter(&m.GetData());
iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
LM_TC_INSET);
- m->setData(array);
}
-
+
// These two are only while we are still with LyX 2.x
{
- boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("emptyset", 0));
- addTemplate(m);
- MathedArray array;
- MathedIter iter(&array);
- iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
+ MathMacroTemplate & m = provideTemplate("emptyset", 0);
+ MathedIter iter(&m.GetData());
+ iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
LM_TC_INSET);
- m->setData(array);
}
-
+
+ {
+ MathMacroTemplate & m = provideTemplate("perp", 0);
+ MathedIter iter(&m.GetData());
+ iter.insert(LM_bot, LM_TC_BOP);
+ }
+
+ // binom has two arguments
+ {
+ MathMacroTemplate & m = provideTemplate("binom", 2);
+ MathedIter iter(&m.GetData());
+
+ MathParInset * inset = new MathDelimInset('(', ')');
+ iter.insertInset(inset, LM_TC_ACTIVE_INSET);
+
+ MathedArray array2;
+ MathedIter iter2(&array2);
+ MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
+ iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
+ frac->setData(array2);
+
+ MathedArray array3;
+ MathedIter iter3(&array3);
+ iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
+
+ MathedArray array4;
+ MathedIter iter4(&array4);
+ iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
+
+ frac->SetData(array3, array4);
+ }
+
+/*
{
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
addTemplate(m);
iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
frac->SetData(array, array2);
}
+*/
}
#include <map>
#include "LString.h"
-#include <boost/utility.hpp>
-#include <boost/smart_ptr.hpp>
-
#ifdef __GNUG__
#pragma interface
#endif
-class MathMacroTemplate;
+
class MathMacro;
+class MathMacroTemplate;
///
-class MathMacroTable : boost::noncopyable {
+struct MathMacroTable {
public:
///
- void addTemplate(boost::shared_ptr<MathMacroTemplate> const &);
+ static MathMacroTemplate & provideTemplate(string const &, int);
///
- MathMacro * createMacro(string const &) const;
+ static MathMacroTemplate & provideTemplate(string const &);
///
- boost::shared_ptr<MathMacroTemplate> const
- getTemplate(string const &) const;
+ static bool hasTemplate(string const &);
///
- void builtinMacros();
+ static MathMacro * cloneTemplate(string const &);
+private:
///
- static MathMacroTable mathMTable;
+ static void builtinMacros();
///
static bool built;
-private:
///
- typedef std::map<string, boost::shared_ptr<MathMacroTemplate> > table_type;
+ typedef std::map<string, MathMacroTemplate *> table_type;
+ //
+ static table_type macro_table;
///
- table_type macro_table;
+ static void dump();
};
#endif
#include "macro_support.h"
#include "support/LOstream.h"
#include "support/LAssert.h"
+#include "debug.h"
+#include "Painter.h"
-using std::ostream;
+using namespace std;
+MathMacroTemplate::MathMacroTemplate() :
+ MathParInset(LM_ST_TEXT, "undefined", LM_OT_MACRO),
+ na_(0), users_()
+{}
-MathMacroTemplate::MathMacroTemplate(string const & nm, int na):
- MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
- edit_(false),
- nargs_(na)
-{
- if (nargs_ > 0) {
- tcode_ = LM_TC_ACTIVE_INSET;
- for (int i = 0; i < nargs_; ++i) {
- args_.push_back(MathMacroArgument(i + 1));
- }
- //for (int i = 0; i < nargs_; ++i) {
- // MathMacroArgument * ma = new MathMacroArgument(i + 1);
- // args_.push_back(boost::shared_ptr<MathMacroArgument>(ma));
- //}
- } else {
- tcode_ = LM_TC_INSET;
- // Here is nargs != args_.size()
- //args = 0;
- }
-}
-
-
-void MathMacroTemplate::setTCode(MathedTextCodes t)
-{
- tcode_ = t;
-}
-
-
-MathedTextCodes MathMacroTemplate::getTCode() const
-{
- return tcode_;
-}
+MathMacroTemplate::MathMacroTemplate(string const & nm, int na) :
+ MathParInset(LM_ST_TEXT, nm, LM_OT_MACRO),
+ na_(na), users_()
+{}
-int MathMacroTemplate::getNoArgs() const
+int MathMacroTemplate::nargs() const
{
- return nargs_;
+ return na_;
}
-void MathMacroTemplate::setEditMode(bool ed)
-{
- if (ed) {
- edit_ = true;
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(false);
- }
- } else {
- edit_ = false;
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(true);
- }
- }
-}
-
-
-void MathMacroTemplate::draw(Painter & pain, int x, int y)
-{
- int x2;
- int y2;
- bool expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
- if (edit_) {
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(false);
- }
- x2 = x;
- y2 = y;
- } else {
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(true);
- }
- x2 = xo();
- y2 = yo();
- }
- MathParInset::draw(pain, x, y);
- xo(x2);
- yo(y2);
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(expnd);
- }
-}
-
-
-void MathMacroTemplate::Metrics()
-{
- bool const expnd = (nargs_ > 0) ? args_[0].getExpand() : false;
-
- if (edit_) {
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(false);
- }
- } else {
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(true);
- }
- }
- MathParInset::Metrics();
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(expnd);
- }
-}
-
-
-void MathMacroTemplate::WriteDef(ostream & os, bool fragile)
+void MathMacroTemplate::WriteDef(ostream & os, bool fragile) const
{
os << "\n\\newcommand{\\" << name << "}";
- if (nargs_ > 0 )
- os << "[" << nargs_ << "]";
+ if (na_ > 0 )
+ os << "[" << na_ << "]";
os << "{";
-
- for (int i = 0; i < nargs_; ++i) {
- args_[i].setExpand(false);
- }
-
- Write(os, fragile);
+#ifdef WITH_WARNINGS
+#warning stupid cast
+#endif
+ const_cast<MathMacroTemplate *>(this)->Write(os, fragile);
os << "}\n";
}
-void MathMacroTemplate::GetMacroXY(int i, int & x, int & y) const
-{
- args_[i].GetXY(x, y);
-}
-
-
-MathParInset * MathMacroTemplate::getMacroPar(int i) const
-{
- if (i >= 0 && i < nargs_) {
- MathParInset * p = const_cast<MathParInset *>
- (static_cast<MathParInset const *>(&args_[i]));
- lyx::Assert(p);
- return p;
- } else
- return 0;
-}
-
-void MathMacroTemplate::setMacroPar(int i, MathedArray const & ar)
+void MathMacroTemplate::Metrics()
{
- if (i >= 0 && i < nargs_)
- args_[i].setData(ar);
+ MathParInset::Metrics();
+ width += 4;
+ ascent += 2;
+ descent += 2;
}
-
-void MathMacroTemplate::SetMacroFocus(int &idx, int x, int y)
+void MathMacroTemplate::draw(Painter & pain, int x, int y)
{
- for (int i = 0; i < nargs_; ++i) {
- if (args_[i].Inside(x, y)) {
- idx = i;
- break;
- }
- }
+ MathParInset::draw(pain, x + 2, y + 1);
+ int w = Width();
+ int a = Ascent();
+ int h = Height();
+ pain.rectangle(x, y - a, w, h, LColor::blue);
}
#ifndef MATHMACROTEMPLATE
#define MATHMACROTEMPLATE
-#include <vector>
-
-#include <boost/utility.hpp>
-//#include <boost/smart_ptr.hpp>
+#include <set>
#include "math_parinset.h"
-#include "math_macroarg.h"
#ifdef __GNUG__
#pragma interface
/** This class contains the macro definition
\author Alejandro Aguilar Sierra
*/
-class MathMacroTemplate : public MathParInset, boost::noncopyable {
+//class MathMacroTemplate : public MathParInset, boost::noncopyable
+
+class MathMacroTemplate : public MathParInset {
public:
- friend class MathMacro;
-
- /// A template constructor needs all the data
- explicit
- MathMacroTemplate(string const &, int na);
///
- void draw(Painter &, int, int);
+ MathMacroTemplate();
///
- void Metrics();
+ MathMacroTemplate(std::string const & name, int nargs);
///
- void WriteDef(std::ostream &, bool fragile);
- /// useful for special insets
- void setTCode(MathedTextCodes t);
- ///
- MathedTextCodes getTCode() const;
+ void WriteDef(std::ostream &, bool fragile) const;
/// Number of arguments
- int getNoArgs() const;
- ///
- void GetMacroXY(int, int &, int &) const;
- ///
- MathParInset * getMacroPar(int) const;
+ int nargs() const;
///
- void setMacroPar(int, MathedArray const &);
- ///
- void SetMacroFocus(int &, int, int);
+ void draw(Painter &, int, int);
///
- void setEditMode(bool);
+ void Metrics();
private:
- /// Are we in edit mode or not?
- bool edit_;
///
- MathedTextCodes tcode_;
+ int na_;
///
- //std::vector<boost::shared_ptr<MathMacroArgument> > args_;
- std::vector<MathMacroArgument> args_;
- ///
- int nargs_;
+ std::set<MathMacro *> users_;
+
+ /// unimplemented
+ void operator=(MathMacroTemplate const &);
+ /// unimplemented
+ MathMacroTemplate(MathMacroTemplate const &);
};
+
#endif
#include "math_iter.h"
#include "array.h"
#include "math_xiter.h"
+#include "math_parser.h"
#include "LColor.h"
#include "mathed/support.h"
#include "Painter.h"
-#include "math_parser.h"
#include "math_rowst.h"
#include "math_parinset.h"
#include "debug.h"
return row_;
}
+string MathParInset::label() const
+{
+ if (row_.size() == 0) {
+ lyxerr << "Warning: Empty rowst when accessing label!\n";
+ return string();
+ }
+ return row_.back().getLabel();
+}
+
MathParInset::MathParInset(short st, string const & nm, short ot)
: MathedInset(nm, ot, st)
{
- ascent = 8;
- width = 4;
+ ascent = 8;
+ width = 4;
descent = 0;
- flag = 1;
+ flag = 1;
if (objtype == LM_OT_SCRIPT)
flag |= LMPF_SCRIPT;
}
return new MathParInset(*this);
}
+void MathParInset::substitute(MathMacro * m)
+{
+ //lyxerr << "called: MathParInset::substitute, m: " << m << endl;
+ array.substitute(m);
+}
+
+
void MathParInset::setData(MathedArray const & a)
{
}
-void
-MathParInset::draw(Painter & pain, int x, int y)
+void MathParInset::draw(Painter & pain, int x, int y)
{
byte cxp = 0;
- int xp = 0;
- int asc = df_asc;
- int des = 0;
+ int xp = 0;
+ int asc = df_asc;
+ int des = 0;
bool limits = false;
xo_ = x;
yo_ = y;
MathedXIter data(this);
if (array.empty()) {
- //MathedXIter data(this);
data.GetPos(x, y);
pain.rectangle(x, y - df_asc, df_width, df_asc,
LColor::mathline);
return;
}
- //MathedXIter data(this);
+
data.GoBegin();
while (data.OK()) {
data.GetPos(x, y);
}
-void
-MathParInset::Metrics()
+void MathParInset::Metrics()
{
byte cx;
byte cxp = 0;
int ls;
int asc = df_asc;
int des = 0;
- int tb = 0;
+ int tb = 0;
int tab = 0;
bool limits = false;
ascent = df_asc;//mathed_char_height(LM_TC_VAR, size, 'I', asc, des);
- width = df_width;
+ width = df_width;
descent = 0;
- if (array.empty()) return;
+ if (array.empty())
+ return;
ascent = 0;
MathedXIter data(this);
string const s = data.GetString();
mathed_string_height(data.fcode(),
size(), s, asc, des);
- if (asc > ascent) ascent = asc;
- if (des > descent) descent = des;
+ if (asc > ascent)
+ ascent = asc;
+ if (des > descent)
+ descent = des;
limits = false;
mathed_char_height(LM_TC_CONST, size(), 'y', asc, des);
} else if (MathIsInset(cx)) {
asc = p->Ascent();
des = p->Descent();
}
- if (asc > ascent) ascent = asc;
- if (des > descent) descent = des;
+ if (asc > ascent)
+ ascent = asc;
+ if (des > descent)
+ descent = des;
if (cx!= LM_TC_UP && cx!= LM_TC_DOWN)
limits = p->GetLimits();
data.Next();
int y;
data.GetIncPos(x, y);
if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
- if (ascent < df_asc) ascent = df_asc;
+ if (ascent < df_asc)
+ ascent = df_asc;
tb = x;
}
data.setTab(x - tb, tab);
int y;
data.GetIncPos(x, y);
if (data.IsFirst() || cxp == LM_TC_TAB || cxp == LM_TC_CR) {
- if (ascent < df_asc) ascent = df_asc;
+ if (ascent < df_asc)
+ ascent = df_asc;
tb = x;
}
data.setTab(x - tb, tab);
int y;
data.GetIncPos(x, y);
data.setTab(x, tab);
- if (ascent < df_asc) ascent = df_asc;
+ if (ascent < df_asc)
+ ascent = df_asc;
}
tb = tab = 0;
data.subMetrics(ascent, descent);
// No matter how simple is a matrix, it is NOT a subparagraph
if (isMatrix()) {
if (cxp == LM_TC_TAB) {
- if (ascent<df_asc) ascent = df_asc;
+ if (ascent < df_asc)
+ ascent = df_asc;
data.setTab(0, tab);
} else {
data.setTab(width - tb, tab);
void MathParInset::Write(ostream & os, bool fragile)
{
- if (array.empty()) return;
+ if (array.empty())
+ return;
+
int brace = 0;
latexkeys const * l;
MathedIter data(&array);
if (!Permit(LMPF_FIXED_SIZE)) {
l = lm_get_key_by_id(size(), LM_TK_STY);
- if (l) {
+ if (l)
os << '\\' << l->name << ' ';
- }
}
while (data.OK()) {
byte cx = data.GetChar();
(data.fcode() == LM_TC_SPECIAL))
os << '\\';
else {
- if (c == '{') ++brace;
- if (c == '}') --brace;
+ if (c == '{')
+ ++brace;
+ if (c == '}')
+ --brace;
}
if (c == '}' && data.fcode() == LM_TC_TEX && brace < 0)
lyxerr <<"Math warning: Unexpected closing brace."
}
if (data.fcode()>= LM_TC_RM && data.fcode()<= LM_TC_TEXTRM)
os << '}';
- } else
+ } else {
if (MathIsInset(cx)) {
MathedInset * p = data.GetInset();
if (cx == LM_TC_UP)
if (cx == LM_TC_UP || cx == LM_TC_DOWN)
os << '}';
data.Next();
- } else
+ } else {
switch (cx) {
case LM_TC_TAB:
{
lyxerr << "WMath Error: unrecognized code[" << cx << "]";
return;
}
+ }
+ }
}
if (crow) {
void MathParInset::UserSetSize(short sz)
{
- if (sz >= 0) {
- size(sz);
- flag = flag & ~LMPF_FIXED_SIZE;
- }
+ if (sz >= 0) {
+ size(sz);
+ flag = flag & ~LMPF_FIXED_SIZE;
+ }
}
void MathParInset::SetStyle(short sz)
{
- if (Permit(LMPF_FIXED_SIZE)) {
- if (Permit(LMPF_SCRIPT))
- sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
- if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT) {
- ++sz;
- }
- MathedInset::SetStyle(sz);
- }
+ if (Permit(LMPF_FIXED_SIZE)) {
+ if (Permit(LMPF_SCRIPT))
+ sz = (sz < LM_ST_SCRIPT) ? LM_ST_SCRIPT: LM_ST_SCRIPTSCRIPT;
+ if (Permit(LMPF_SMALLER) && sz < LM_ST_SCRIPTSCRIPT)
+ ++sz;
+ MathedInset::SetStyle(sz);
+ }
}
short ot = LM_OT_MIN);
///
virtual MathedInset * Clone();
+ ///
+ virtual void substitute(MathMacro *);
/// Draw the object on a drawable
virtual void draw(Painter &, int x, int baseline);
/// Write LaTeX code
int yo() const;
///
void clear();
-protected:
+ ///
+ string label() const;
+//protected:
/// Paragraph data is stored here
MathedArray array;
///
using std::endl;
-extern MathMatrixInset * create_multiline(short int type, int cols);
+extern MathMatrixInset create_multiline(short int type, int cols);
namespace {
enum {
- FLAG_BRACE = 1, // A { needed
- FLAG_BRACE_ARG = 2, // Next { is argument
- FLAG_BRACE_OPT = 4, // Optional {
- FLAG_BRACE_LAST = 8, // Last } ends the parsing process
- FLAG_BRACK_ARG = 16, // Optional [
- FLAG_RIGHT = 32, // Next right ends the parsing process
- FLAG_END = 64, // Next end ends the parsing process
- FLAG_BRACE_FONT = 128, // Next } closes a font
- FLAG_BRACK_END = 256 // Next ] ends the parsing process
+ FLAG_BRACE = 1, // A { needed
+ FLAG_BRACE_ARG = 2, // Next { is argument
+ FLAG_BRACE_OPT = 4, // Optional {
+ FLAG_BRACE_LAST = 8, // Last } ends the parsing process
+ FLAG_BRACK_ARG = 16, // Optional [
+ FLAG_RIGHT = 32, // Next right ends the parsing process
+ FLAG_END = 64, // Next end ends the parsing process
+ FLAG_BRACE_FONT = 128, // Next } closes a font
+ FLAG_BRACK_END = 256 // Next ] ends the parsing process
};
} // namespace anon
-string mathed_label;
-
-
int const latex_mathenv_num = 12;
char const * latex_mathenv[latex_mathenv_num] = {
"math",
inline
void mathPrintError(string const & msg)
{
- lyxerr << "Line ~" << yylineno << ": Math parse error: "
- << msg << endl;
+ lyxerr << "Line ~" << yylineno << ": Math parse error: " << msg << endl;
}
void LexInitCodes()
{
- for (int i = 0; i <= 255; ++i) {
+ for (int i = 0; i <= 255; ++i) {
if (isalpha(i))
lexcode[i] = LexAlpha;
else if (isdigit(i))
if (!lf)
lf = c;
else if (c != lf) {
- lyxerr << "Math parse error: unexpected '"
- << c << "'" << endl;
+ lyxerr << "Math parse error: unexpected '" << c << "'" << endl;
return '\0';
}
break;
((lf == '[') ? ']'
: ((lf == '(') ? ')' : 0));
if (!rg) {
- lyxerr << "Math parse error: unknown bracket '"
- << lf << "'" << endl;
+ lyxerr << "Math parse error: unknown bracket '" << lf << "'" << endl;
return '\0';
}
char * p = &yytext[0];
++p;
}
*p = '\0';
- if (yyis->good()) yyis->putback(c);
+ if (yyis->good())
+ yyis->putback(c);
+ //lyxerr << "reading: '" << yytext.data() << "'\n";
latexkeys const * l = in_word_set (yytext.data(), strlen(yytext.data()));
if (l) {
if (l->token == LM_TK_BEGIN || l->token == LM_TK_END) {
inline
void setAccent(int ac)
{
- if (ac > 0 && accent < 8) {
+ if (ac > 0 && accent < 8)
nestaccent[accent++] = ac;
- } else
+ else
accent = 0; // consumed!
}
return ac;
}
+
+void do_insert(MathedIter & it, MathedInset * m, MathedTextCodes t)
+{
+ if (accent)
+ it.insertInset(doAccent(m), t);
+ else
+ it.insertInset(m, t);
+}
+
} // namespace anon
/**
*/
-void mathed_parse(MathedArray & array, unsigned flags = 0,
- MathParInset ** mtx = 0)
+void mathed_parse(MathedArray & array, MathParInset * & par, unsigned flags)
{
int t = yylex();
int tprev = 0;
static int size = LM_ST_TEXT;
MathedTextCodes varcode = LM_TC_VAR;
MathedInset * binset = 0;
- static MathMacroTemplate * macro = 0;
+ string last_label; // last label seen
+ bool last_numbered = true; // have we seen '\nonumber' lately?
+
int brace = 0;
int acc_brace = 0;
int acc_braces[8];
- MathParInset * mt = (mtx) ? *mtx : 0;
++plevel;
MathedIter data(&array);
while (t) {
+ //lyxerr << "t: " << t << " par: " << par << " flags: " << flags;
+ //lyxerr << "label: '" << last_label << "' ";
+ //array.dump(lyxerr);
+ //lyxerr << "\n";
+
if ((flags & FLAG_BRACE) && t != LM_TK_OPEN) {
if ((flags & FLAG_BRACK_ARG) && t == '[') {
} else {
switch (t) {
case LM_TK_ALPHA:
- if (accent) {
- data.insertInset(doAccent(yylval.i, varcode),
- LM_TC_INSET);
- } else
+ if (accent)
+ data.insertInset(doAccent(yylval.i, varcode), LM_TC_INSET);
+ else
data.insert(yylval.i, varcode); //LM_TC_VAR);
break;
case LM_TK_ARGUMENT:
- if (macro) {
- data.insertInset(macro
- ->getMacroPar(yylval.i - 1),
- LM_TC_INSET);
- } else {
- lyxerr[Debug::MATHED] << "mathed_parse: macro arg outside macro def." << endl;
- }
-
+ {
+ data.insertInset(new MathMacroArgument(yylval.i), LM_TC_INSET);
break;
+ }
case LM_TK_NEWCOMMAND:
{
int na = 0;
LexGetArg('{');
- string const name(&yytext[1]);
+ string name = &yytext[1];
- // ugly trick to be removed soon (lyx3)
char const c = yyis->peek();
if (c == '[') {
LexGetArg('[');
na = lyx::atoi(yytext.data());
}
- macro = new MathMacroTemplate(name, na);
+ //lyxerr << "LM_TK_NEWCOMMAND: name: " << name << " " << na << endl;
+#ifdef WITH_WARNINGS
+#warning dirty
+#endif
+ par->SetName(name);
+ par->xo(na); // abuse xo
flags = FLAG_BRACE|FLAG_BRACE_LAST;
- *mtx = macro;
- macro->setData(array);
break;
}
}
if (brace == 0 && (flags & FLAG_BRACE_LAST)) {
--plevel;
- return;
- } else {
- data.insert('}', LM_TC_TEX);
+ goto clean_up;
}
+ data.insert('}', LM_TC_TEX);
break;
case '[':
case ']':
if (flags & FLAG_BRACK_END) {
--plevel;
- return;
- } else
- data.insert(']', LM_TC_CONST);
+ goto clean_up;
+ }
+ data.insert(']', LM_TC_CONST);
break;
case '^':
{
- MathParInset * p = new MathParInset(size, "",
- LM_OT_SCRIPT);
+ MathParInset * p = new MathParInset(size, "", LM_OT_SCRIPT);
MathedArray ar;
- mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
+ mathed_parse(ar, par, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar);
// lyxerr << "UP[" << p->GetStyle() << "]" << endl;
data.insertInset(p, LM_TC_UP);
MathParInset * p = new MathParInset(size, "",
LM_OT_SCRIPT);
MathedArray ar;
- mathed_parse(ar, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
+ mathed_parse(ar, par, FLAG_BRACE_OPT|FLAG_BRACE_LAST);
p->setData(ar);
data.insertInset(p, LM_TC_DOWN);
break;
break;
case '&': // Tab
- if ((flags & FLAG_END) && mt
- && data.getCol()<mt->GetColumns() - 1) {
- data.setNumCols(mt->GetColumns());
- data.insert('T', LM_TC_TAB);
- } else
- mathPrintError("Unexpected tab");
- // debug info. [made that conditional -JMarc]
- if (lyxerr.debugging(Debug::MATHED))
- lyxerr << data.getCol() << " "
- << mt->GetColumns() << endl;
+ data.insert('T', LM_TC_TAB);
+#ifdef WITH_WARNINGS
+#warning look here
+#endif
+ data.setNumCols(par->GetColumns());
break;
case LM_TK_NEWLINE:
- if (mt && (flags & FLAG_END)) {
- if (mt->Permit(LMPF_ALLOW_CR)) {
- mt->getRowSt().push_back();
+ //lyxerr << "reading line " << par->getRowSt().size() << "\n";
+ if (flags & FLAG_END) {
+ if (par->Permit(LMPF_ALLOW_CR)) {
+ par->getRowSt().push_back();
+ if (last_numbered) {
+ //lyxerr << "line " << par->getRowSt().size() << " not numbered\n";
+ par->getRowSt().back().setNumbered(false);
+ last_numbered = true;
+ }
+ if (last_label.size()) {
+ //lyxerr << "line " << par->getRowSt().size() << " labeled: "
+ // << last_label << endl;
+ par->getRowSt().back().setLabel(last_label);
+ last_label.erase();
+ }
data.insert('K', LM_TC_CR);
} else
mathPrintError("Unexpected newline");
break;
case LM_TK_BOP:
- if (accent) {
+ if (accent)
data.insertInset(doAccent(yylval.i, LM_TC_BOP), LM_TC_INSET);
- } else
+ else
data.insert(yylval.i, LM_TC_BOP);
break;
case LM_TK_STY:
- if (mt) {
- mt->UserSetSize(yylval.l->id);
- }
+ par->UserSetSize(yylval.l->id);
break;
case LM_TK_SPACE:
// fallthru
case LM_TK_FRAC:
{
- MathFracInset * fc = new MathFracInset(fractype);
+ MathFracInset fc(fractype);
MathedArray num;
- mathed_parse(num, FLAG_BRACE|FLAG_BRACE_LAST);
+ mathed_parse(num, par, FLAG_BRACE|FLAG_BRACE_LAST);
MathedArray den;
- mathed_parse(den, FLAG_BRACE|FLAG_BRACE_LAST);
- fc->SetData(num, den);
- data.insertInset(fc, LM_TC_ACTIVE_INSET);
+ mathed_parse(den, par, FLAG_BRACE|FLAG_BRACE_LAST);
+ fc.SetData(num, den);
+ data.insertInset(fc.Clone(), LM_TC_ACTIVE_INSET);
break;
}
case LM_TK_SQRT:
{
- MathParInset * rt;
-
char c;
yyis->get(c);
if (c == '[') {
- rt = new MathRootInset(size);
- rt->setArgumentIdx(0);
- MathedArray ar;
- mathed_parse(ar, FLAG_BRACK_END, &rt);
- rt->setData(ar); // I belive that line is not needed (Lgb)
- rt->setArgumentIdx(1);
+ MathRootInset rt(size);
+
+ MathedArray ar1;
+ mathed_parse(ar1, par, FLAG_BRACK_END);
+ rt.setArgumentIdx(0);
+ rt.setData(ar1); // I belive that line is not needed (Lgb)
+
+ MathedArray ar2;
+ mathed_parse(ar2, par, FLAG_BRACE|FLAG_BRACE_LAST);
+
+ rt.setArgumentIdx(1);
+ rt.setData(ar2); // I belive that this line is not needed (Lgb)
+
+ data.insertInset(rt.Clone(), LM_TC_ACTIVE_INSET);
} else {
yyis->putback(c);
- rt = new MathSqrtInset(size);
+ MathSqrtInset rt(size);
+ MathedArray ar;
+ mathed_parse(ar, par, FLAG_BRACE|FLAG_BRACE_LAST);
+ rt.setData(ar); // I belive that this line is not needed (Lgb)
+ data.insertInset(rt.Clone(), LM_TC_ACTIVE_INSET);
}
- MathedArray ar;
- mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST, &rt);
- rt->setData(ar); // I belive that this line is not needed (Lgb)
- data.insertInset(rt, LM_TC_ACTIVE_INSET);
break;
}
lfd = (lfd == LM_TK_SYM) ? yylval.l->id: yylval.i;
// lyxerr << "L[" << lfd << " " << lfd << "]";
MathedArray ar;
- mathed_parse(ar, FLAG_RIGHT);
+ mathed_parse(ar, par, FLAG_RIGHT);
int rgd = yylex();
// lyxerr << "R[" << rgd << "]";
if (rgd == LM_TK_SYM || rgd == LM_TK_STR || rgd == LM_TK_BOP || rgd == LM_TK_SPECIAL)
case LM_TK_RIGHT:
if (flags & FLAG_RIGHT) {
--plevel;
- return;
- } else {
- mathPrintError("Unmatched right delimiter");
-// panic = true;
+ goto clean_up;
}
+ mathPrintError("Unmatched right delimiter");
+// panic = true;
break;
case LM_TK_FONT:
MathDecorationInset * sq = new MathDecorationInset(yylval.l->id,
size);
MathedArray ar;
- mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST);
+ mathed_parse(ar, par, FLAG_BRACE|FLAG_BRACE_LAST);
sq->setData(ar);
data.insertInset(sq, LM_TC_ACTIVE_INSET);
break;
break;
case LM_TK_NONUM:
- if (mt) {
- if (!mt->getRowSt().size())
- mt->getRowSt().push_back();
- mt->getRowSt().back().setNumbered(false);
- }
+ //lyxerr << "prepare line " << par->getRowSt().size()
+ // << " not numbered\n";
+ last_numbered = false;
break;
case LM_TK_PMOD:
case LM_TK_UNDEF:
{
-
- MathMacro * p =
- MathMacroTable::mathMTable.createMacro(yylval.s);
- if (p) {
- if (accent)
- data.insertInset(doAccent(p), p->getTCode());
- else
- data.insertInset(p, p->getTCode());
- for (int i = 0; p->setArgumentIdx(i); ++i) {
+ // save this value, yylval.s might get overwritten soon
+ const string name = yylval.s;
+ //lyxerr << "LM_TK_UNDEF: str = " << name << endl;
+ if (MathMacroTable::hasTemplate(name)) {
+ MathMacro * m = MathMacroTable::cloneTemplate(name);
+ //lyxerr << "Macro: " << m->GetData() << endl;
+ for (int i = 0; i < m->nargs(); ++i) {
MathedArray ar;
- mathed_parse(ar, FLAG_BRACE|FLAG_BRACE_LAST);
- p->setData(ar);
+ mathed_parse(ar, par, FLAG_BRACE|FLAG_BRACE_LAST);
+ m->setData(ar, i);
}
+ do_insert(data, m, m->getTCode());
} else {
- MathedInset * q = new MathFuncInset(yylval.s, LM_OT_UNDEF);
- if (accent) {
- data.insertInset(doAccent(q), LM_TC_INSET);
- } else {
- data.insertInset(q, LM_TC_INSET);
- }
+ MathedInset * q = new MathFuncInset(name, LM_OT_UNDEF);
+ do_insert(data, q, LM_TC_INSET);
}
break;
}
if (lyxerr.debugging(Debug::MATHED))
lyxerr << "[" << yylval.i << "]" << endl;
--plevel;
- if (mt) { // && (flags & FLAG_END)) {
- mt->setData(array);
- array.clear();
- }
- return;
+
+ //if (mt) { // && (flags & FLAG_END)) {
+ // par.setData(array);
+ // array.clear();
+ //}
+#ifdef WITH_WARNINGS
+#warning Look here
+#endif
+ goto clean_up;
case LM_TK_BEGIN:
if (yylval.i == LM_OT_MATRIX) {
+ //lyxerr << "###### Reading LM_OT_MATRIX \n";
char ar[120];
char ar2[8];
ar[0] = ar2[0] = '\0';
}
strcpy(ar, yytext.data());
int const nc = parse_align(ar, ar2);
+
MathParInset * mm = new MathMatrixInset(nc, 0);
mm->SetAlign(ar2[0], ar);
- data.insertInset(mm, LM_TC_ACTIVE_INSET);
MathedArray dat;
- mathed_parse(dat, FLAG_END, &mm);
+ mathed_parse(dat, mm, FLAG_END);
+ data.insertInset(mm, LM_TC_ACTIVE_INSET);
+ mm->setData(dat);
+
} else if (is_eqn_type(yylval.i)) {
+ //lyxerr << "###### Reading is_eqn_type \n";
if (plevel!= 0) {
mathPrintError("Misplaced environment");
break;
}
- if (!mt) {
- mathPrintError("0 paragraph.");
- panic = true;
- }
mathed_env = static_cast<MathedInsetTypes>(yylval.i);
if (mathed_env != LM_OT_MIN) {
+ //lyxerr << "###### Reading mathed_env != LM_OT_MIN \n";
size = LM_ST_DISPLAY;
if (is_multiline(mathed_env)) {
+ //lyxerr << "###### Reading is_multiline(mathed_env) \n";
int cols = 1;
if (is_multicolumn(mathed_env)) {
+ //lyxerr << "###### Reading is_multicolumn(mathed_env) \n";
if (mathed_env != LM_OT_ALIGNAT &&
mathed_env != LM_OT_ALIGNATN &&
yyis->good()) {
+ //lyxerr << "###### Reading is !align\n";
char c;
yyis->get(c);
if (c != '%')
LexGetArg('{');
cols = strToInt(string(yytext.data()));
}
- mt = create_multiline(mathed_env, cols);
- if (mtx) *mtx = mt;
+#ifdef WITH_WARNINGS
+#warning look here
+#endif
+ //mt = create_multiline(mathed_env, cols);
+ //if (mtx) *mtx = mt;
+
+ //MathMatrixInset mat = create_multiline(mathed_env, cols);
+ //data.insertInset(mat.Clone(), LM_TC_ACTIVE_INSET);
+
+ par = new MathMatrixInset(create_multiline(mathed_env, cols));
flags |= FLAG_END;
-// data.Insert(' ', LM_TC_TAB);
-// data.Insert(' ', LM_TC_TAB);
-// data.Reset();
}
- mt->SetStyle(size);
- mt->SetType(mathed_env);
+ par->SetStyle(size);
+ par->SetType(mathed_env);
}
lyxerr[Debug::MATHED] << "MATH BEGIN[" << mathed_env << "]" << endl;
} else {
-// lyxerr << "MATHCRO[" << yytext << "]";
- MathMacro * p =
- MathMacroTable::mathMTable.createMacro(yytext.data());
- if (p) {
- data.insertInset(p, p->getTCode());
- p->setArgumentIdx(0);
- //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
- mathPrintError("Unrecognized environment");
+ MathMacro * m = MathMacroTable::cloneTemplate(yytext.data());
+ data.insertInset(m, m->getTCode());
+ MathedArray dat;
+ mathed_parse(dat, par, FLAG_END);
}
break;
case LM_TK_MACRO:
{
- MathedInset * p =
- MathMacroTable::mathMTable.createMacro(yylval.l->name);
-
- if (p) {
- if (accent) {
- data.insertInset(doAccent(p), LM_TC_INSET);
- } else
- data.insertInset(p, static_cast<MathMacro*>(p)->getTCode());
- }
+ MathMacro * m = MathMacroTable::cloneTemplate(yylval.l->name);
+ do_insert(data, m, m->getTCode());
break;
}
panic = true;
break;
}
- if (mt) {
- if (!mt->getRowSt().size())
- mt->getRowSt().push_back();
- mt->getRowSt().back().setLabel(yytext.data());
- } else {
- mathed_label = yytext.data();
- }
- lyxerr[Debug::MATHED] << "Label[" << mathed_label << "]" << endl;
+ last_label = yytext.data();
+ //lyxerr << "prepare line " << par->getRowSt().size()
+ // << " label: " << last_label << endl;
break;
}
if ((flags & FLAG_BRACE_OPT)/* && t!= '^' && t!= '_'*/) {
flags &= ~FLAG_BRACE_OPT;
- //data.Insert (LM_TC_CLOSE);
break;
}
}
--plevel;
+
+clean_up:
+
+ if (last_numbered == false) {
+ //lyxerr << "last line " << par->getRowSt().size() << " not numbered\n";
+ if (par->getRowSt().size() == 0)
+ par->getRowSt().push_back();
+ par->getRowSt().back().setNumbered(false);
+ }
+ if (last_label.size()) {
+ //lyxerr << "last line " << par->getRowSt().size() << " labeled: "
+ // << last_label << endl;
+ if (par->getRowSt().size() == 0)
+ par->getRowSt().push_back();
+ par->getRowSt().back().setLabel(last_label);
+ }
}
{
yyis = &is;
yylineno = lineno;
- if (!MathMacroTable::built)
- MathMacroTable::mathMTable.builtinMacros();
}
: asc_(0), desc_(0), y_(0), numbered_(true)
{}
+
string const & MathedRowStruct::getLabel() const
{
return label_;
}
+
bool MathedRowStruct::isNumbered() const
{
return numbered_;
}
+
int MathedRowStruct::getBaseline() const
{
return y_;
}
+
void MathedRowStruct::setBaseline(int b)
{
y_ = b;
}
+
int MathedRowStruct::ascent() const
{
return asc_;
}
+
int MathedRowStruct::descent() const
{
return desc_;
}
+
void MathedRowStruct::ascent(int a)
{
asc_ = a;
}
+
void MathedRowStruct::descent(int d)
{
desc_ = d;
}
+
int MathedRowStruct::getTab(unsigned int i) const
{
return i < widths_.size() ? widths_[i] : 0;
}
+
void MathedRowStruct::setLabel(string const & l)
{
label_ = l;
}
+
void MathedRowStruct::setNumbered(bool nf)
{
numbered_ = nf;
}
+
void MathedRowStruct::setTab(unsigned int i, int t)
{
if (i >= widths_.size())
return iterator(this);
}
+
MathedRowContainer::iterator MathedRowContainer::end()
{
iterator it(this);
return it;
}
+
bool MathedRowContainer::empty() const
{
return data_.size() == 0;
}
+
void MathedRowContainer::insert(iterator const & it)
{
lyx::Assert(it.st_ == this);
data_.insert(data_.begin() + it.pos_, MathedRowStruct());
}
-
+
+
void MathedRowContainer::erase(iterator & it)
{
lyx::Assert(it.st_ == this);
data_.erase(data_.begin() + it.pos_);
}
+
MathedRowStruct & MathedRowContainer::back()
{
lyx::Assert(data_.size());
return data_.back();
}
+
+MathedRowStruct const & MathedRowContainer::back() const
+{
+ lyx::Assert(data_.size());
+ return data_.back();
+}
+
+
void MathedRowContainer::push_back()
{
data_.push_back(MathedRowStruct());
: st_(0), pos_(0)
{}
+
MathedRowContainer::iterator::iterator(MathedRowContainer * m)
: st_(m), pos_(0)
{}
+
MathedRowContainer::iterator::operator void *() const
{
return (void *)(st_ && pos_ < st_->size());
}
+
MathedRowStruct * MathedRowContainer::iterator::operator->()
{
lyx::Assert(st_);
return &st_->data_[pos_];
}
+
MathedRowStruct const * MathedRowContainer::iterator::operator->() const
{
lyx::Assert(st_);
return &st_->data_[pos_];
}
+
void MathedRowContainer::iterator::operator++()
{
lyx::Assert(st_);
++pos_;
}
+
bool MathedRowContainer::iterator::is_last() const
{
lyx::Assert(st_);
return pos_ == st_->size() - 1;
}
+
bool MathedRowContainer::iterator::operator==(const iterator & it) const
{
return st_ == it.st_ && pos_ == it.pos_;
void erase(iterator & it);
/// access to last row
MathedRowStruct & back();
+ /// access to last row
+ MathedRowStruct const & back() const;
/// append empty element
void push_back();
///
}
-void
-MathSqrtInset::draw(Painter & pain, int x, int y)
+void MathSqrtInset::draw(Painter & pain, int x, int y)
{
MathParInset::draw(pain, x + hmax_ + 2, y);
int const h = ascent;
}
-void
-MathSqrtInset::Metrics()
+void MathSqrtInset::Metrics()
{
MathParInset::Metrics();
- ascent += 4;
+ ascent += 4;
descent += 2;
int a;
int b;
hmax_ = mathed_char_height(LM_TC_VAR, size(), 'I', a, b);
- if (hmax_ < 10) hmax_ = 10;
+ if (hmax_ < 10)
+ hmax_ = 10;
wbody_ = width + 4;
width += hmax_ + 4;
}
void MathedXIter::SetData(MathParInset * pp)
{
+ //if (p_ && pp != p_) {
+ // lyxerr << "MathedXIter::SetData: " << p_ << " " << pp << endl;
+ //}
p_ = pp;
x_ = y_ = 0;
array = &p_->GetData();
+ //lyxerr << "MathedXIter::SetData: " << p_ << " " << *array << endl;
ncols = p_->GetColumns();
crow_ = container().begin();
if (p_->Permit(LMPF_ALLOW_CR))
do {
ipush();
Next();
- } while (pos<pos2);
+ } while (pos < pos2);
ipop();
- return (!IsCR());
+ return !IsCR();
}
bool MathedXIter::Down()
{
- int xp = x_;
- int colp= col;
+ int xp = x_;
+ int colp = col;
// int rowp = row
bool res = (IsCR()) ? true : goNextCode(LM_TC_CR);
ipush();
// while (Next()) {
do {
- if (IsCR()) {
+ if (IsCR())
break;
- } else if (!IsTab()) {
+
+ if (!IsTab())
line_empty = false;
- }
} while (Next());
int const p1 = getPos();
void MathedXIter::setTab(int tx, int tab)
{
- if (crow_ && tab <= ncols) {
+ if (crow_ && tab <= ncols)
crow_->setTab(tab, tx);
- } else
+ else
lyxerr << "MathErr: No tabs allowed here" << endl;
}
bool limit = false;
descent = ascent = width = 0;
- if (!array) return;
- if (array->empty()) return;
+ if (!array)
+ return;
+ if (array->empty())
+ return;
// if (pos2 > array->last) return;
x1 = x_;
while (pos < pos2) {
int sx_;
///
int sw_;
- /// true= center, false= left align (default)
+ /// true == center, false == left align (default)
bool limits_;
///
MathedRowContainer::iterator crow_;
/// math_parser.C
extern
-void mathed_parse(MathedArray & data, unsigned flags, MathParInset ** mt);
+void mathed_parse(MathedArray & data, MathParInset * & par, unsigned flags);
/// math_parser.C
extern