From f51395af6810f66adfae90812ce7be694f8dd67e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 15 Aug 2001 05:50:39 +0000 Subject: [PATCH] deco drawing bug fix move more stuff to math_factory cosmetics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2513 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 5 ++-- src/mathed/formulabase.h | 1 + src/mathed/math_cursor.C | 51 ++++++++++++--------------------------- src/mathed/math_cursor.h | 4 --- src/mathed/math_factory.C | 13 ++++++++++ src/mathed/math_factory.h | 3 +++ src/mathed/support.C | 33 ++++++++++++------------- 7 files changed, 51 insertions(+), 59 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 4fee6ab5d3..46a60f9055 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -33,6 +33,7 @@ #include "gettext.h" #include "LaTeXFeatures.h" #include "debug.h" +#include "support.h" #include "support/lstrings.h" #include "LyXView.h" #include "Painter.h" @@ -41,8 +42,8 @@ #include "math_spaceinset.h" #include "math_scopeinset.h" #include "math_macrotable.h" +#include "math_factory.h" #include "support/lyxlib.h" -#include "mathed/support.h" #include "undo_funcs.h" using std::endl; @@ -79,7 +80,7 @@ void handleFont(BufferView * bv, MathTextCodes t) void handleAccent(BufferView * bv, string const & name) { bv->lockedInsetStoreUndo(Undo::EDIT); - mathcursor->handleAccent(name); + mathcursor->insert(createMathInset(name)); } diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index cd80d0e92d..81b36fb66b 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -86,6 +86,7 @@ public: virtual string const editMessage() const; /// virtual void edit(BufferView *, int x, int y, unsigned int button); + /// virtual void edit(BufferView *, bool front = true); /// virtual void toggleInsetCursor(BufferView *); diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index ac332723b8..2b4f3f1158 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -31,13 +31,9 @@ #include "formulabase.h" #include "math_cursor.h" #include "math_factory.h" -#include "math_funcinset.h" #include "math_arrayinset.h" #include "math_charinset.h" -#include "math_decorationinset.h" #include "math_deliminset.h" -#include "math_macro.h" -#include "math_macrotable.h" #include "math_matrixinset.h" #include "math_scopeinset.h" #include "math_scriptinset.h" @@ -74,9 +70,9 @@ struct Selection MathCursorPos i1; MathCursorPos i2; cursor.getSelection(i1, i2); - if (i1.idx_ == i2.idx_) { + if (i1.idx_ == i2.idx_) i1.cell().erase(i1.pos_, i2.pos_); - } else { + else { std::vector indices = i1.par_->idxBetween(i1.idx_, i2.idx_); for (unsigned i = 0; i < indices.size(); ++i) i1.cell(indices[i]).erase(); @@ -127,10 +123,6 @@ MathCursor::MathCursor(InsetFormulaBase * formula) } -MathCursor::~MathCursor() -{} - - void MathCursor::pushLeft(MathInset * par) { MathCursorPos p; @@ -260,6 +252,7 @@ bool MathCursor::left(bool sel) dump("Left 1"); if (inMacroMode()) { macroModeClose(); + lastcode_ = LM_TC_VAR; return true; } selHandle(sel); @@ -280,6 +273,7 @@ bool MathCursor::right(bool sel) dump("Right 1"); if (inMacroMode()) { macroModeClose(); + lastcode_ = LM_TC_VAR; return true; } selHandle(sel); @@ -600,9 +594,9 @@ void MathCursor::macroModeClose() pos() = pos() - s.size(); for (unsigned i = 0; i < s.size(); ++i) plainErase(); + lastcode_ = LM_TC_VAR; interpret("\\" + s); } - lastcode_ = LM_TC_VAR; } @@ -745,14 +739,6 @@ void MathCursor::handleFont(MathTextCodes t) } -void MathCursor::handleAccent(string const & name) -{ - latexkeys const * l = in_word_set(name); - if (l) - handleNest(new MathDecorationInset(l)); -} - - void MathCursor::handleDelim(latexkeys const * l, latexkeys const * r) { handleNest(new MathDelimInset(l, r)); @@ -1208,24 +1194,13 @@ void MathCursor::interpret(string const & s) p->cell(0).swap(array()); pos() = 0; niceInsert(p); - down(); - return; - } - - latexkeys const * l = in_word_set(s.substr(1)); - if (l) { - lastcode_ = LM_TC_VAR; - niceInsert(createMathInset(l)); - return; - } - - if (MathMacroTable::hasTemplate(s.substr(1))) { - niceInsert(new MathMacro(MathMacroTable::provideTemplate(s.substr(1)))); + popRight(); + left(); return; } if (s.size() > 1) { - niceInsert(new MathFuncInset(s.substr(1))); + niceInsert(createMathInset(s.substr(1))); return; } @@ -1287,13 +1262,17 @@ void MathCursor::interpret(string const & s) if (lastcode_ == LM_TC_TEX) { if (macroName().empty()) { insert(c, LM_TC_TEX); - if (!isalpha(c)) + if (!isalpha(c)) { macroModeClose(); + lastcode_ = LM_TC_VAR; + } } else { if (isalpha(c)) insert(c, LM_TC_TEX); - else + else { macroModeClose(); + lastcode_ = LM_TC_VAR; + } } return; } @@ -1321,8 +1300,8 @@ void MathCursor::interpret(string const & s) if (c == ' ') { if (inMacroMode()) { - lastcode_ = LM_TC_VAR; macroModeClose(); + lastcode_ = LM_TC_VAR; return; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 8fa6d16fd4..523ec48dc7 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -65,8 +65,6 @@ public: /// explicit MathCursor(InsetFormulaBase *); /// - ~MathCursor(); - /// void insert(MathInset *); /// void insert(MathArray const &); @@ -164,8 +162,6 @@ public: /// void handleFont(MathTextCodes t); /// - void handleAccent(string const & name); - /// void handleDelim(latexkeys const * l, latexkeys const * r); /// void handleNest(MathInset * p); diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index 57e160b241..832d5ae026 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -51,3 +51,16 @@ MathInset * createMathInset(latexkeys const * l) } return new MathFuncInset(l->name); } + + +MathInset * createMathInset(string const & s) +{ + latexkeys const * l = in_word_set(s); + if (l) + return createMathInset(l); + + if (MathMacroTable::hasTemplate(s)) + return new MathMacro(MathMacroTable::provideTemplate(s)); + + return new MathFuncInset(s); +} diff --git a/src/mathed/math_factory.h b/src/mathed/math_factory.h index 8ed810fd04..0123b5845c 100644 --- a/src/mathed/math_factory.h +++ b/src/mathed/math_factory.h @@ -1,9 +1,12 @@ #ifndef MATH_FACTORY_H #define MATH_FACTORY_H +#include "LString.h" + class MathInset; class latexkeys; +MathInset * createMathInset(string const &); MathInset * createMathInset(latexkeys const *); #endif diff --git a/src/mathed/support.C b/src/mathed/support.C index 2f4b1f9102..3e2ca3b04e 100644 --- a/src/mathed/support.C +++ b/src/mathed/support.C @@ -387,13 +387,13 @@ float const tilde[] = { }; -struct math_deco_struct { +struct deco_struct { int code; float const * data; int angle; }; -math_deco_struct math_deco_table[] = { +deco_struct deco_table[] = { // Decorations { LM_widehat, &angle[0], 3 }, { LM_widetilde, &tilde[0], 0 }, @@ -449,40 +449,39 @@ math_deco_struct math_deco_table[] = { }; -struct math_deco_compare { +struct deco_compare { /// for use by sort and lower_bound - int operator()(math_deco_struct const & a, math_deco_struct const & b) const + int operator()(deco_struct const & a, deco_struct const & b) const { return a.code < b.code; } }; -int const math_deco_table_size = - sizeof(math_deco_table) / sizeof(math_deco_struct); +int const deco_table_size = + sizeof(deco_table) / sizeof(deco_struct); // sort the table on startup struct init_deco_table { init_deco_table() { - std::sort(math_deco_table, - math_deco_table + math_deco_table_size, - math_deco_compare()); + std::sort(deco_table, + deco_table + deco_table_size, + deco_compare()); } }; static init_deco_table dummy; -math_deco_struct const * search_deco(int code) +deco_struct const * search_deco(int code) { - static const math_deco_struct search_elem = { code, 0, 0 }; + const deco_struct search_elem = { code, 0, 0 }; - math_deco_struct const * res = - lower_bound(math_deco_table, - math_deco_table + math_deco_table_size, - search_elem, math_deco_compare()); - if (res != math_deco_table + math_deco_table_size && + deco_struct const * res = + lower_bound(deco_table, deco_table + deco_table_size, search_elem, + deco_compare()); + if (res != deco_table + deco_table_size && res->code == code) return res; return 0; @@ -575,7 +574,7 @@ void mathed_draw_deco(Painter & pain, int x, int y, int w, int h, string name = l->name; int code = (name.size() > 1) ? l->id : name[0]; - math_deco_struct const * mds = search_deco(code); + deco_struct const * mds = search_deco(code); if (!mds) { lyxerr << "Deco was not found. Programming error?\n"; lyxerr << "name: '" << l->name << "', code: " << code << "\n"; -- 2.39.5