X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmathed%2Fformula.C;h=5b10679fb142b219f6d7a2125bc00f4a90453ebd;hb=d597ece5e7efac2a25251034d89fa761759d28f7;hp=e4a457621da4f653a34a0ceba347a3a24085ac46;hpb=d6665cba427b04ae37f42c846398cad518d2be0f;p=lyx.git diff --git a/src/mathed/formula.C b/src/mathed/formula.C index e4a457621d..5b10679fb1 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -37,6 +37,7 @@ #include "LyXView.h" #include "Painter.h" #include "font.h" +#include "support/lyxlib.h" using std::ostream; using std::istream; @@ -56,9 +57,11 @@ LyXFont * Math_Fonts = 0; // this is only used by Whichfont and mathed_init_font static LyXFont::FONT_SIZE lfont_size = LyXFont::SIZE_NORMAL; -// local global -static int sel_x, sel_y; +// local global +static int sel_x; +static int sel_y; static bool sel_flag; + MathedCursor * InsetFormula::mathcursor = 0; @@ -67,14 +70,6 @@ int MathedInset::df_des; int MathedInset::df_width; -inline -bool IsMacro(short token, int id) -{ - return (token != LM_TK_FRAC && token != LM_TK_SQRT && - !((token == LM_TK_SYM || token == LM_TC_BSYM) && id < 255)); -} - - static void mathedValidate(LaTeXFeatures & features, MathParInset * par); @@ -196,21 +191,18 @@ LyXFont mathed_get_font(short type, int size) int mathed_string_width(short type, int size, byte const * s, int ls) { - LyXFont f = WhichFont(type, size); - - byte sx[80]; - if (MathIsBinary(type)) { - byte * ps = &sx[0]; - for (int i = 0; i < ls && i < 75; ++i) { - *(ps++) = ' '; - *(ps++) = s[i]; - *(ps++) = ' '; - } - *(ps++) = '\0'; - ls *= 3; - s = &sx[0]; - } - return lyxfont::width(reinterpret_cast(s), ls, f); + string st; + if (MathIsBinary(type)) + for (int i = 0; i < ls; ++i) { + st += ' '; + st += s[i]; + st += ' '; + } + else + st = string(reinterpret_cast(s), ls); + + LyXFont const f = WhichFont(type, size); + return lyxfont::width(st, f); } int mathed_string_width(short type, int size, string const & str) @@ -263,13 +255,15 @@ void MathedInset::drawStr(Painter & pain, short type, int siz, int x, int y, byte const * s, int ls) { string st; - if (MathIsBinary(type)) { + if (MathIsBinary(type)) for (int i = 0; i < ls; ++i) { - st += string(" ") + char(s[i]) + ' '; + st += ' '; + st += char(s[i]); + st += ' '; } - } else { + else st = string(reinterpret_cast(s), ls); - } + LyXFont const mf = mathed_get_font(type, siz); pain.text(x, y, st, mf); } @@ -306,7 +300,7 @@ InsetFormula::~InsetFormula() } -Inset * InsetFormula::Clone() const +Inset * InsetFormula::Clone(Buffer const &) const { InsetFormula * f = new InsetFormula(par); f->label = label; @@ -331,7 +325,7 @@ int InsetFormula::Latex(Buffer const *, ostream & os, bool fragile, bool) const } -int InsetFormula::Ascii(Buffer const *, ostream & os) const +int InsetFormula::Ascii(Buffer const *, ostream & os, int) const { par->Write(os, false); return 0; @@ -340,13 +334,13 @@ int InsetFormula::Ascii(Buffer const *, ostream & os) const int InsetFormula::Linuxdoc(Buffer const * buf, ostream & os) const { - return Ascii(buf, os); + return Ascii(buf, os, 0); } int InsetFormula::DocBook(Buffer const * buf, ostream & os) const { - return Ascii(buf, os); + return Ascii(buf, os, 0); } @@ -536,7 +530,8 @@ void InsetFormula::ToggleInsetCursor(BufferView * bv) if (!mathcursor) return; - int x, y; + int x; + int y; mathcursor->GetPos(x, y); // x -= par->xo; y -= par->yo; @@ -552,11 +547,12 @@ void InsetFormula::ToggleInsetCursor(BufferView * bv) } -void InsetFormula::ShowInsetCursor(BufferView * bv) +void InsetFormula::ShowInsetCursor(BufferView * bv, bool) { if (!cursor_visible) { if (mathcursor) { - int x, y; + int x; + int y; mathcursor->GetPos(x, y); // x -= par->xo; y -= par->yo; @@ -586,7 +582,7 @@ void InsetFormula::ToggleInsetSelection(BufferView * bv) //int n; //XPoint * p = //mathcursor->SelGetArea(n); -// XFillPolygon(fl_display, pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin); +// XFillPolygon(fl_get_display(), pm, LyXGetSelectionGC(), p, n, Nonconvex, CoordModeOrigin); // x -= par->xo; // y -= par->yo; @@ -690,8 +686,7 @@ void InsetFormula::InsetMotionNotify(BufferView * bv, mathcursor->SelStart(); ShowInsetCursor(bv); mathcursor->GetPos(sel_x, sel_y); - } else - if (sel_flag) { + } else if (sel_flag) { HideInsetCursor(bv); x += par->xo; y += par->yo; @@ -785,8 +780,7 @@ InsetFormula::LocalDispatch(BufferView * bv, result = DISPATCHED_NOUPDATE; break; case LFUN_DELETE_LINE_FORWARD: - //current_view->lockedInsetStoreUndo(Undo::INSERT); - bv->lockedInsetStoreUndo(Undo::DELETE); + bv->lockedInsetStoreUndo(Undo::DELETE); mathcursor->DelLine(); UpdateLocal(bv); break; @@ -816,8 +810,7 @@ InsetFormula::LocalDispatch(BufferView * bv, } case LFUN_DELETE: - //current_view->lockedInsetStoreUndo(Undo::INSERT); - bv->lockedInsetStoreUndo(Undo::DELETE); + bv->lockedInsetStoreUndo(Undo::DELETE); mathcursor->Delete(); bv->updateInset(this, true); break; @@ -827,7 +820,10 @@ InsetFormula::LocalDispatch(BufferView * bv, // break; case LFUN_SETXY: { - int x, y, x1, y1; + int x; + int y; + int x1; + int y1; istringstream ist(arg.c_str()); ist >> x >> y; par->GetXY(x1, y1); @@ -996,7 +992,7 @@ InsetFormula::LocalDispatch(BufferView * bv, if (arg.empty()) break; - strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0'; + ::strncpy(arg2, arg.c_str(), 40); arg2[39]= '\0'; int n = sscanf(arg2, "%s %s", lf, rg); lf[39] = '\0'; rg[39] = '\0'; @@ -1070,8 +1066,7 @@ InsetFormula::LocalDispatch(BufferView * bv, } case LFUN_MATH_DISPLAY: - //current_view->lockedInsetStoreUndo(Undo::INSERT); - bv->lockedInsetStoreUndo(Undo::EDIT); + bv->lockedInsetStoreUndo(Undo::EDIT); display(!disp_flag); UpdateLocal(bv); break; @@ -1094,7 +1089,7 @@ InsetFormula::LocalDispatch(BufferView * bv, //------- dummy actions case LFUN_EXEC_COMMAND: - bv->owner()->getMiniBuffer()->ExecCommand(); + bv->owner()->getMiniBuffer()->PrepareForCommand(); break; default: @@ -1203,7 +1198,7 @@ InsetFormula::LocalDispatch(BufferView * bv, result = FINISHED; } } else - if (c == '\'') { + if (c == '\'' || c == '@') { mathcursor->Insert (c, LM_TC_VAR); } else if (c == '\\') {