#include "font.h"
#include "Lsstream.h"
#include "math_arrayinset.h"
+#include "math_charinset.h"
#include "math_cursor.h"
#include "math_factory.h"
#include "math_hullinset.h"
#include "math_pos.h"
#include "math_spaceinset.h"
#include "undo_funcs.h"
+#include "textpainter.h"
+#include "frontends/Dialogs.h"
#include "intl.h"
using std::endl;
int hack_button;
-void handleFont(BufferView * bv, string const & arg, MathTextCodes t)
+void handleFont(BufferView * bv, string const & arg, MathTextCodes t)
{
if (mathcursor->selection())
bv->lockedInsetStoreUndo(Undo::EDIT);
// This is needed as long the math parser is not re-entrant
MathMacroTable::builtinMacros();
//lyxerr << "sizeof MathInset: " << sizeof(MathInset) << "\n";
+ //lyxerr << "sizeof(MathMetricsInfo): " << sizeof(MathMetricsInfo) << "\n";
+ //lyxerr << "sizeof(MathCharInset): " << sizeof(MathCharInset) << "\n";
}
{}
-void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
+void InsetFormulaBase::metrics(BufferView * bv, LyXFont const & f) const
{
font_ = f;
metrics(bv);
}
-void InsetFormulaBase::metrics(BufferView * bv) const
+void InsetFormulaBase::metrics(BufferView * bv) const
{
if (bv)
view_ = bv;
y -= yo_;
int asc = 0;
int des = 0;
- MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
- math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
+ math_font_max_dim(font_, asc, des);
bv->showLockedInsetCursor(x, y, asc, des);
//lyxerr << "toggleInsetCursor: " << x << " " << y << "\n";
}
y -= yo_;
int asc = 0;
int des = 0;
- MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT);
- math_font_max_dim(LM_TC_TEXTRM, mi, asc, des);
+ math_font_max_dim(font_, asc, des);
bv->fitLockedInsetCursor(x, y, asc, des);
//lyxerr << "showInsetCursor: x: " << x << " y: " << y << " yo: " << yo_ << "\n";
}
vector<string> const InsetFormulaBase::getLabelList() const
{
- return std::vector<string>();
+ return vector<string>();
}
bool InsetFormulaBase::insetButtonRelease(BufferView * bv,
- int /*x*/, int /*y*/, int /*button*/)
+ int /*x*/, int /*y*/, int /*button*/)
{
if (!mathcursor)
return false;
bv->getLyXText()->selectionAsString(bv->buffer(), false);
mathed_parse_cell(ar, sel);
mathcursor->insert(ar);
- }
+ }
break;
*/
+ case 3:
+ // launch math panel for right mouse button
+ bv->owner()->getDialogs()->showMathPanel();
+ break;
}
bv->updateInset(this, false);
}
first_x = x;
first_y = y;
- if (!mathcursor->selection())
+ if (!mathcursor->selection())
mathcursor->selStart();
-
+
//lyxerr << "insetMotionNotify: " << x + xo_ << ' ' << y + yo_
// << ' ' << button << "\n";
hideInsetCursor(bv);
//lyxerr << "InsetFormulaBase::localDispatch: act: " << action
// << " arg: '" << arg << "' cursor: " << mathcursor << "\n";
- if (!mathcursor)
+ if (!mathcursor)
return UNDISPATCHED;
if (mathcursor->asHyperActiveInset()) {
hideInsetCursor(bv);
mathcursor->normalize();
+ mathcursor->touch();
+
switch (action) {
// --- Cursor Movements ---------------------------------------------
case LFUN_RIGHT:
result = mathcursor->right(sel) ? DISPATCHED : FINISHED_RIGHT;
+ //lyxerr << "calling scroll 20\n";
+ //scroll(bv, 20);
updateLocal(bv, false);
// write something to the minibuffer
//bv->owner()->message(mathcursor->info());
case LFUN_WORDLEFTSEL:
break;
- // --- accented characters ------------------------------
-
- case LFUN_UMLAUT: handleAccent(bv, arg, "ddot"); break;
- case LFUN_CIRCUMFLEX: handleAccent(bv, arg, "hat"); break;
- case LFUN_GRAVE: handleAccent(bv, arg, "grave"); break;
- case LFUN_ACUTE: handleAccent(bv, arg, "acute"); break;
- case LFUN_TILDE: handleAccent(bv, arg, "tilde"); break;
- case LFUN_MACRON: handleAccent(bv, arg, "bar"); break;
- case LFUN_DOT: handleAccent(bv, arg, "dot"); break;
- case LFUN_CARON: handleAccent(bv, arg, "check"); break;
- case LFUN_BREVE: handleAccent(bv, arg, "breve"); break;
- case LFUN_VECTOR: handleAccent(bv, arg, "vec"); break;
- case LFUN_UNDERBAR: handleAccent(bv, arg, "underbar"); break;
+ // Special casing for superscript in case of LyX handling
+ // dead-keys:
+ case LFUN_CIRCUMFLEX:
+ if (arg.empty()) {
+ // do superscript if LyX handles
+ // deadkeys
+ bv->lockedInsetStoreUndo(Undo::EDIT);
+ mathcursor->script(true);
+ updateLocal(bv, true);
+ }
+ break;
+ case LFUN_UMLAUT:
+ case LFUN_ACUTE:
+ case LFUN_GRAVE:
+ case LFUN_BREVE:
+ case LFUN_DOT:
+ case LFUN_MACRON:
+ case LFUN_CARON:
+ case LFUN_TILDE:
+ case LFUN_CEDILLA:
+ case LFUN_CIRCLE:
+ case LFUN_UNDERDOT:
+ case LFUN_TIE:
+ case LFUN_OGONEK:
+ case LFUN_HUNG_UMLAUT:
+ break;
// Math fonts
case LFUN_GREEK_TOGGLE: handleFont(bv, arg, LM_TC_GREEK); break;
case LFUN_DEFAULT: handleFont(bv, arg, LM_TC_VAR); break;
case LFUN_FREE: handleFont(bv, arg, LM_TC_TEXTRM); break;
- case LFUN_GREEK:
+ case LFUN_GREEK:
handleFont(bv, arg, LM_TC_GREEK1);
if (arg.size())
mathcursor->interpret(arg);
break;
case LFUN_MATH_MODE:
- //handleFont(bv, arg, LM_TC_TEXTRM);
+#if 1
+ handleFont(bv, arg, LM_TC_TEXTRM);
+#endif
- //mathcursor->niceInsert(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
- //updateLocal(bv, true);
+#if 0
+ mathcursor->niceInsert(MathAtom(new MathHullInset(LM_OT_SIMPLE)));
+ updateLocal(bv, true);
+#endif
//bv->owner()->message(_("math text mode toggled"));
break;
updateLocal(bv, true);
break;
}
-
+
case LFUN_SUPERSCRIPT:
case LFUN_SUBSCRIPT:
{
updateLocal(bv, true);
break;
}
-
+
case LFUN_MATH_DELIM:
{
lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'\n";
MathInset::idx_type idx = 0;
MathGridInset * p = mathcursor ? mathcursor->enclosingGrid(idx) : 0;
if (p) {
+ mathcursor->popToEnclosingGrid();
bv->lockedInsetStoreUndo(Undo::EDIT);
- char al = arg.size() ? arg[0] : 'c';
+ char align = arg.size() ? arg[0] : 'c';
switch (action) {
- case LFUN_MATH_HALIGN: p->halign(al, p->col(idx)); break;
- case LFUN_MATH_VALIGN: p->valign(al); break;
+ case LFUN_MATH_HALIGN: p->halign(align, p->col(idx)); break;
+ case LFUN_MATH_VALIGN: p->valign(align); break;
case LFUN_MATH_ROW_INSERT: p->addRow(p->row(idx)); break;
case LFUN_MATH_ROW_DELETE: p->delRow(p->row(idx)); break;
case LFUN_MATH_COLUMN_INSERT: p->addCol(p->col(idx)); break;
}
mathcursor->normalize();
+ mathcursor->touch();
lyx::Assert(mathcursor);
else
bv->unlockInset(this);
+ revealCodes(bv);
+
return result; // original version
}
+void InsetFormulaBase::revealCodes(BufferView * /*bv*/) const
+{
+ if (!mathcursor)
+ return;
+#if 0
+ // write something to the minibuffer
+ // translate to latex
+ mathcursor->markInsert();
+ ostringstream os;
+ write(NULL, os);
+ string str = os.str();
+ mathcursor->markErase();
+ string::size_type pos = 0;
+ string res;
+ for (string::iterator it = str.begin(); it != str.end(); ++it) {
+ if (*it == '\n')
+ res += ' ';
+ else if (*it == '\0') {
+ res += " -X- ";
+ pos = it - str.begin();
+ }
+ else
+ res += *it;
+ }
+ if (pos > 30)
+ res = res.substr(pos - 30);
+ if (res.size() > 60)
+ res = res.substr(0, 60);
+ bv->owner()->message(res);
+#endif
+}
+
+
Inset::Code InsetFormulaBase::lyxCode() const
{
return Inset::MATH_CODE;
//lyxerr << "reset lastformula to " << this << "\n";
lastformula = this;
laststr = str;
- current = ibegin(par().nucleus());
+ current = ibegin(par().nucleus());
ar.clear();
mathed_parse_cell(ar, str);
} else {
}
-
-void InsetFormulaBase::handleAccent(BufferView * bv,
- string const & arg, string const & name)
-{
- bv->lockedInsetStoreUndo(Undo::EDIT);
- MathAtom at = createMathInset(name);
- mathed_parse_cell(at->cell(0), arg);
- mathcursor->insert(at);
- updateLocal(bv, true);
-}
-
-
/////////////////////////////////////////////////////////////////////
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise
- if (sel.find("\\newcommand") == string::npos)
+ if (sel.find("\\newcommand") == string::npos &&
+ sel.find("\\def") == string::npos)
f = new InsetFormula(sel);
else {
string name;
mathDispatchCreation(bv, arg, true);
}
-
+
void mathDispatchMathMode(BufferView * bv, string const & arg)
{
mathDispatchCreation(bv, arg, false);
if (arg.empty())
bv->owner()->getLyXFunc()->setErrorMessage(N_("Missing argument"));
else {
- string s(arg);
+ string s = arg;
string const s1 = token(s, ' ', 1);
int const na = s1.empty() ? 0 : lyx::atoi(s1);
openNewInset(bv, new InsetFormulaMacro(token(s, ' ', 0), na));
void mathDispatchMathDelim(BufferView * bv, string const & arg)
{
- if (bv->available()) {
+ if (bv->available()) {
if (openNewInset(bv, new InsetFormula))
bv->theLockingInset()->localDispatch(bv, LFUN_MATH_DELIM, arg);
}
-}
+}
void mathDispatchInsertMatrix(BufferView * bv, string const & arg)
-{
- if (bv->available()) {
+{
+ if (bv->available()) {
if (openNewInset(bv, new InsetFormula))
bv->theLockingInset()->localDispatch(bv, LFUN_INSERT_MATRIX, arg);
}
-}
+}
void mathDispatchInsertMath(BufferView * bv, string const & arg)
void mathDispatchGreek(BufferView * bv, string const & arg)
-{
- if (bv->available()) {
+{
+ if (bv->available()) {
InsetFormula * f = new InsetFormula;
if (openNewInset(bv, f)) {
bv->theLockingInset()->localDispatch(bv, LFUN_GREEK, arg);
bv->unlockInset(f);
}
}
-}
+}
void mathDispatch(BufferView *, kb_action, string const &)
-{}
+{}