#include "gettext.h"
#include "LaTeXFeatures.h"
#include "debug.h"
-#include "support/LOstream.h"
+#include "support/lstrings.h"
#include "LyXView.h"
#include "Painter.h"
#include "font.h"
extern char const * latex_special_chars;
-int greek_kb_flag = 0;
extern char const * latex_mathenv[];
MathCursor * mathcursor = 0;
}
-} // namespaces
-
-
-
-namespace {
-
-
-// returns the nearest enclosing matrix
+// returns the nearest enclosing grid
MathArrayInset * matrixpar(int & idx)
{
idx = 0;
- return
- static_cast<MathArrayInset *>
- (mathcursor ? mathcursor->enclosing(LM_OT_MATRIX, idx) : 0);
+ return (mathcursor ? mathcursor->enclosingArray(idx) : 0);
}
} // namespace anon
-InsetFormulaBase::InsetFormulaBase(MathInset * par)
- : par_(par)
+
+InsetFormulaBase::InsetFormulaBase()
{
#ifdef WITH_WARNINGS
#warning This is needed as long the math parser is not re-entrant
#endif
MathMacroTable::builtinMacros();
-}
-
-
-InsetFormulaBase::InsetFormulaBase(InsetFormulaBase const & f)
- : UpdatableInset(f), par_(static_cast<MathInset *>(f.par_->clone()))
-{}
-
-
-InsetFormulaBase::~InsetFormulaBase()
-{
- delete par_;
+ //lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
}
read(lex);
}
+
void InsetFormulaBase::write(Buffer const *, ostream & os) const
{
write(os);
void InsetFormulaBase::edit(BufferView * bv, bool front)
{
-#warning Please have a look if this is right (Jug)
edit(bv, front ? 0 : 1, 0, 0);
}
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
{
mathcursor->getPos(x, y);
- x -= par_->xo();
- y -= par_->yo();
+ x -= par()->xo();
+ y -= par()->yo();
}
int x;
int y;
mathcursor->getPos(x, y);
- //x -= par_->xo();
- y -= par_->yo();
+ //x -= par()->xo();
+ y -= par()->yo();
int asc;
int desc;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
int x;
int y;
mathcursor->getPos(x, y);
- x -= par_->xo();
- y -= par_->yo();
+ x -= par()->xo();
+ y -= par()->yo();
int asc;
int desc;
math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, desc);
}
-void InsetFormulaBase::metrics() const
-{
- const_cast<MathInset *>(par_)->metrics(LM_ST_TEXT);
-}
-
-
void InsetFormulaBase::insetButtonRelease(BufferView * bv,
int x, int y, int /*button*/)
{
if (mathcursor) {
hideInsetCursor(bv);
- x += par_->xo();
- y += par_->yo();
+ x += par()->xo();
+ y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
if (sel_flag) {
if (sel_x && sel_y && abs(x-sel_x) > 4 && !sel_flag) {
sel_flag = true;
hideInsetCursor(bv);
- mathcursor->setPos(sel_x + par_->xo(), sel_y + par_->yo());
+ mathcursor->setPos(sel_x + par()->xo(), sel_y + par()->yo());
mathcursor->selStart();
showInsetCursor(bv);
mathcursor->getPos(sel_x, sel_y);
} else if (sel_flag) {
hideInsetCursor(bv);
- x += par_->xo();
- y += par_->yo();
+ x += par()->xo();
+ y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
mathcursor->getPos(x, y);
//lyxerr << "InsetFormulaBase::LocalDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
+ static int greek_kb_flag = 0;
+
if (!mathcursor)
return UNDISPATCHED;
break;
case LFUN_BACKSPACE:
- // if (!mathcursor->inMacroMode() && mathcursor->pos() == 0)
- if (mathcursor->pos() == 0) {
- bv->lockedInsetStoreUndo(Undo::DELETE);
- mathcursor->pullArg(false);
- bv->updateInset(this, true);
- break;
- }
- if (mathcursor->inMacroMode())
- mathcursor->left();
- else
- mathcursor->plainLeft();
- // fall through...
+ bv->lockedInsetStoreUndo(Undo::DELETE);
+ mathcursor->backspace();
+ bv->updateInset(this, true);
+ break;
case LFUN_DELETE:
bv->lockedInsetStoreUndo(Undo::DELETE);
- if (mathcursor->pos() == mathcursor->array().size())
- mathcursor->pullArg(true);
- else
- mathcursor->erase();
+ mathcursor->erase();
bv->updateInset(this, true);
break;
int y1;
istringstream is(arg.c_str());
is >> x >> y;
- par_->getXY(x1, y1);
+ par()->getXY(x1, y1);
mathcursor->setPos(x1 + x, y1 + y);
updateLocal(bv, false);
}
//bv->owner()->message(_("math text mode toggled"));
break;
-#ifndef NO_LATEX
- case LFUN_TEX:
- if (!mathcursor->selection()) {
- mathcursor->handleFont(LM_TC_TEX);
- //bv->owner()->message(_("TeX mode toggled"));
- }
- break;
-#endif
-
case LFUN_MATH_LIMITS:
bv->lockedInsetStoreUndo(Undo::INSERT);
if (mathcursor->toggleLimits())
char greek[26] =
{'A', 'B', 'X', 0 , 'E', 0 , 0 , 'H', 'I', 0 ,
'K', 0 , 'M', 'N', 'O', 0 , 0 , 'P', 0 , 'T',
- 'Y', 0, 0, 0, 0 , 'Z' };
+ 0, 0, 0, 0, 0 , 'Z' };
if ('A' <= c && c <= 'Z' && greek[c - 'A']) {
char_code = LM_TC_RM;
mathcursor->insert(c, char_code);
- if (greek_kb_flag && char_code == LM_TC_RM )
+ if (greek_kb_flag && char_code == LM_TC_RM)
mathcursor->setLastCode(LM_TC_VAR);
varcode = LM_TC_MIN;
}
-
-/* FIXME: math-greek-toggle seems to work OK, but math-greek doesn't turn
- * on greek mode */
-bool math_insert_greek(BufferView * bv, char c)
-{
- if (!bv->available())
- return false;
-
- if (!isalpha(c))
- return false;
-
- string tmp;
- tmp = c;
- if (!bv->theLockingInset() || bv->theLockingInset()->isTextInset()) {
- int greek_kb_flag_save = greek_kb_flag;
- InsetFormula * new_inset = new InsetFormula();
- bv->beforeChange(bv->text);
- if (!bv->insertInset(new_inset)) {
- delete new_inset;
- return false;
- }
- //Update(1);//BUG
- new_inset->edit(bv, 0, 0, 0);
- new_inset->localDispatch(bv, LFUN_SELFINSERT, tmp);
- if (greek_kb_flag_save < 2) {
- bv->unlockInset(new_inset); // bv->theLockingInset());
- bv->text->cursorRight(bv, true);
- }
- } else
- if (bv->theLockingInset()->lyxCode() == Inset::MATH_CODE ||
- bv->theLockingInset()->lyxCode() == Inset::MATHMACRO_CODE)
- static_cast<InsetFormula*>(bv->theLockingInset())->localDispatch(bv, LFUN_SELFINSERT, tmp);
- else
- lyxerr << "Math error: attempt to write on a wrong "
- "class of inset." << endl;
- return true;
-}
-
-
-
Inset::Code InsetFormulaBase::lyxCode() const
{
return Inset::MATH_CODE;
}
-LyXFont const InsetFormulaBase::convertFont(LyXFont const & f) const
-{
- // We have already discussed what was here
- LyXFont font(f);
-#ifndef NO_LATEX
- font.setLatex(LyXFont::OFF);
-#endif
- return font;
-}
-
-MathInset * InsetFormulaBase::par() const
-{
- return par_;
-}
-
-
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {