#include "formulamacro.h"
#include "commandtags.h"
#include "math_cursor.h"
-#include "math_parser.h"
#include "BufferView.h"
#include "lyxtext.h"
#include "lyxfunc.h"
MathArrayInset * matrixpar(MathInset::idx_type & idx)
{
idx = 0;
- return (mathcursor ? mathcursor->enclosingArray(idx) : 0);
+ return mathcursor ? mathcursor->enclosingArray(idx) : 0;
}
InsetFormulaBase::InsetFormulaBase()
+ : view_(0), font_(), xo_(0), yo_(0)
{
// This is needed as long the math parser is not re-entrant
MathMacroTable::builtinMacros();
{}
+void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
+{
+ if (bv)
+ view_ = bv;
+ font_ = f;
+ MathMetricsInfo mi(view_, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
+ par()->metrics(mi);
+}
+
+
string const InsetFormulaBase::editMessage() const
{
return _("Math editor mode");
lyxerr[Debug::MATHED] << "Cannot lock inset!!!" << endl;
mathcursor = new MathCursor(this, x == 0);
- metrics();
+ metrics(bv);
// if that is removed, we won't get the magenta box when entering an
// inset for the first time
bv->updateInset(this, false);
void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const
{
mathcursor->getPos(x, y);
- x -= par()->xo();
- y -= par()->yo();
- y -= 3;
+ x += xo_;
+ y += yo_ - 3;
+ //lyxerr << "getCursorPos: " << x << " " << y << "\n";
}
if (isCursorVisible())
bv->hideLockedInsetCursor();
else {
+ metrics(bv);
int x;
int y;
mathcursor->getPos(x, y);
- //x -= par()->xo();
- y -= par()->yo();
y -= 3;
- int asc;
- int des;
- math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
+ y -= yo_;
+ int asc = 0;
+ int des = 0;
+ MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
+ math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
bv->showLockedInsetCursor(x, y, asc, des);
+ //lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
}
toggleCursorVisible();
int x;
int y;
mathcursor->getPos(x, y);
- x -= par()->xo();
- y -= par()->yo();
- int asc;
- int des;
- math_font_max_dim(LM_TC_TEXTRM, LM_ST_TEXT, asc, des);
- bv->fitLockedInsetCursor(x, y, asc, des);
+ int asc = 0;
+ int des = 0;
+ MathMetricsInfo mi(bv, font_, LM_ST_TEXT);
+ math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
+ //bv->fitLockedInsetCursor(x, y, asc, des);
+ //metrics(bv);
+ //lyxerr << "showInsetCursor: " << x << " " << y << "\n";
}
toggleInsetCursor(bv);
}
void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty)
{
- metrics();
+ metrics(bv);
bv->updateInset(this, dirty);
}
{
if (mathcursor) {
hideInsetCursor(bv);
- x += par()->xo();
- y += par()->yo();
- mathcursor->setPos(x, y);
+ mathcursor->setPos(x + xo_, y + yo_);
+ //lyxerr << "insetButtonRelease: " << x + xo_ << " " << y + yo_ << "\n";
showInsetCursor(bv);
if (sel_flag) {
sel_flag = false;
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, sel_y);
mathcursor->selStart();
showInsetCursor(bv);
mathcursor->getPos(sel_x, sel_y);
} else if (sel_flag) {
hideInsetCursor(bv);
- x += par()->xo();
- y += par()->yo();
mathcursor->setPos(x, y);
showInsetCursor(bv);
mathcursor->getPos(x, y);
if (!mathcursor)
return UNDISPATCHED;
+ if (mathcursor->asHyperActiveInset()) {
+ lyxerr << " uurr.... getting dificult now\n";
+ return mathcursor->asHyperActiveInset()->localDispatch(bv, action, arg);
+ }
+
RESULT result = DISPATCHED;
bool sel = false;
bool was_macro = mathcursor->inMacroMode();
updateLocal(bv, true);
break;
+ case LFUN_DELETE_WORD_BACKWARD:
case LFUN_BACKSPACE:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->backspace();
bv->updateInset(this, true);
break;
+ case LFUN_DELETE_WORD_FORWARD:
case LFUN_DELETE:
bv->lockedInsetStoreUndo(Undo::DELETE);
mathcursor->erase();
// break;
case LFUN_SETXY: {
lyxerr << "LFUN_SETXY broken!\n";
- int x;
- int y;
- int x1;
- int y1;
+ int x = 0;
+ int y = 0;
istringstream is(arg.c_str());
is >> x >> y;
- par()->getXY(x1, y1);
- mathcursor->setPos(x1 + x, y1 + y);
+ mathcursor->setPos(x, y);
updateLocal(bv, false);
break;
}
case LFUN_GREEK:
handleFont(bv, LM_TC_GREEK1);
if (arg.size())
- mathcursor->interpret(arg[0]);
+ mathcursor->interpret(arg);
break;
case LFUN_MATH_MODE:
break;
case LFUN_MATH_SIZE:
+#if 0
if (!arg.empty()) {
bv->lockedInsetStoreUndo(Undo::INSERT);
- latexkeys const * l = in_word_set(arg);
- mathcursor->setSize(MathStyles(l ? l->id : static_cast<unsigned int>(-1)));
+ mathcursor->setSize(arg);
updateLocal(bv, true);
}
+#endif
break;
case LFUN_INSERT_MATRIX:
result = UNDISPATCHED;
break;
+ case LFUN_BREAKPARAGRAPH:
+ case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
+ //lyxerr << "LFUN ignored\n";
+ break;
+
case -1:
case LFUN_INSERT_MATH:
case LFUN_SELFINSERT:
}
+int InsetFormulaBase::upperY() const
+{
+ return yo_ - ascent(view_, font_);
+}
+
+
+int InsetFormulaBase::lowerY() const
+{
+ return yo_ + descent(view_, font_);
+}
+
+
+/////////////////////////////////////////////////////////////////////
+
+
void mathDispatchCreation(BufferView * bv, string const & arg, bool display)
{
if (bv->available()) {
// sel = "";
//else
- string sel = bv->getLyXText()->selectionAsString(bv->buffer(),
- false);
+ string sel = bv->getLyXText()->selectionAsString(bv->buffer(), false);
InsetFormulaBase * f;
if (sel.empty()) {
}
}
+