From f84e3d1296962e861c92c1ee75a091e7d3fde8eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 14 Aug 2002 16:43:16 +0000 Subject: [PATCH] more lfun shuffling git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4972 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formula.C | 23 --------- src/mathed/formula.h | 6 --- src/mathed/formulabase.C | 1 + src/mathed/math_cursor.C | 97 ------------------------------------- src/mathed/math_cursor.h | 6 +-- src/mathed/math_hullinset.C | 82 +++++++++++++++++++++++++++++++ src/mathed/math_hullinset.h | 2 + 7 files changed, 86 insertions(+), 131 deletions(-) diff --git a/src/mathed/formula.C b/src/mathed/formula.C index acc8ac788d..dc1d45e8e0 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -271,16 +271,6 @@ InsetFormula::localDispatch(FuncRequest const & ev) break; } - case LFUN_MATH_EXTERN: - { - bv->lockedInsetStoreUndo(Undo::EDIT); - if (mathcursor) - mathcursor->handleExtern(ev.argument); - // re-compute inset dimension - metrics(bv); - updateLocal(bv, true); - break; - } case LFUN_MATH_DISPLAY: { @@ -319,19 +309,6 @@ bool InsetFormula::display() const } -MathHullInset const * InsetFormula::hull() const -{ - lyx::Assert(par_->asHullInset()); - return par_->asHullInset(); -} - - -MathHullInset * InsetFormula::hull() -{ - lyx::Assert(par_->asHullInset()); - return par_.nucleus()->asHullInset(); -} - Inset::Code InsetFormula::lyxCode() const { return Inset::MATH_CODE; diff --git a/src/mathed/formula.h b/src/mathed/formula.h index 1f90b6a1b7..846ade741b 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -93,12 +93,6 @@ private: bool display() const; /// available in AMS only? bool ams() const; - /// access to hull - MathHullInset const * hull() const; - /// access to hull - MathHullInset * hull(); - /// - void handleExtern(string const & arg); /// contents MathAtom par_; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index f19c00cec1..63c46f9de5 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -428,6 +428,7 @@ InsetFormulaBase::localDispatch(FuncRequest const & ev) case LFUN_BREAKLINE: case LFUN_DELETE_LINE_FORWARD: case LFUN_INSERT_LABEL: + case LFUN_MATH_EXTERN: bv->lockedInsetStoreUndo(Undo::EDIT); mathcursor->dispatch(ev); updateLocal(bv, true); diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index ea9cfc5d4a..b021bf8f9b 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -750,19 +750,6 @@ MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const } -MathHullInset * MathCursor::enclosingHull(MathCursor::idx_type & idx) const -{ - for (MathInset::difference_type i = depth() - 1; i >= 0; --i) { - MathHullInset * p = Cursor_[i].par_->asHullInset(); - if (p) { - idx = Cursor_[i].idx_; - return p; - } - } - return 0; -} - - void MathCursor::popToHere(MathInset const * p) { while (depth() && Cursor_.back().par_ != p) @@ -1077,14 +1064,6 @@ bool MathCursor::bruteFind } -bool MathCursor::idxLineFirst() -{ - idx() -= idx() % par()->ncols(); - pos() = 0; - return true; -} - - bool MathCursor::idxLineLast() { idx() -= idx() % par()->ncols(); @@ -1514,82 +1493,6 @@ MathCursorPos MathCursor::normalAnchor() const } - -void MathCursor::handleExtern(const string & arg) -{ - string lang; - string extra; - istringstream iss(arg.c_str()); - iss >> lang >> extra; - if (extra.empty()) - extra = "noextra"; - - if (selection()) { - MathArray ar; - selGet(ar); - lyxerr << "use selection: " << ar << "\n"; - insert(pipeThroughExtern(lang, extra, ar)); - return; - } - - MathArray eq; - eq.push_back(MathAtom(new MathCharInset('='))); - - popToEnclosingHull(); - - idx_type idx = 0; - MathHullInset * hull = enclosingHull(idx); - lyx::Assert(hull); - idxLineFirst(); - - if (hull->getType() == "simple") { - MathArray::size_type pos = cursor().cell().find_last(eq); - MathArray ar; - if (pos == size()) { - ar = array(); - lyxerr << "use whole cell: " << ar << "\n"; - } else { - ar = MathArray(array().begin() + pos + 1, array().end()); - lyxerr << "use partial cell form pos: " << pos << "\n"; - } - end(); - insert(eq); - insert(pipeThroughExtern(lang, extra, ar)); - return; - } - - if (hull->getType() == "equation") { - lyxerr << "use equation inset\n"; - hull->mutate("eqnarray"); - MathArray & ar = cursor().cell(); - lyxerr << "use cell: " << ar << "\n"; - idxRight(); - cursor().cell() = eq; - idxRight(); - cursor().cell() = pipeThroughExtern(lang, extra, ar); - idxLineLast(); - return; - } - - { - lyxerr << "use eqnarray\n"; - idxLineLast(); - MathArray ar = cursor().cell(); - lyxerr << "use cell: " << ar << "\n"; -#ifdef WITH_WARNINGS -#warning temporarily disabled -#endif - //breakLine(); - //idxRight(); - cursor().cell() = eq; - //idxRight(); - cursor().cell() = pipeThroughExtern(lang, extra, ar); - idxLineLast(); - } - -} - - MathInset::result_type MathCursor::dispatch(FuncRequest const & cmd) { // try to dispatch to adajcent items if they are not editable diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 5fad2e14b5..bd2da28ad7 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -107,8 +107,6 @@ public: MathInset * par() const; /// return the next enclosing grid inset and the cursor's index in it MathGridInset * enclosingGrid(idx_type & idx) const; - /// return the next enclosing hull inset and the cursor's index in it - MathHullInset * enclosingHull(idx_type & idx) const; /// go up to enclosing grid void popToEnclosingGrid(); /// go up to the hull inset @@ -243,7 +241,7 @@ public: /// hack for reveal codes void markInsert(); void markErase(); - void handleExtern(string const & arg); + //void handleExtern(string const & arg); /// friend class Selection; @@ -256,8 +254,6 @@ private: bool idxLeft(); /// moves cursor index one cell to the right bool idxRight(); - /// moves cursor to beginning first cell of current line - bool idxLineFirst(); /// moves cursor to end of last cell of current line bool idxLineLast(); /// moves cursor position one cell to the left diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index e4b1768b73..116f46ce57 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -8,6 +8,8 @@ #include "math_mathmlstream.h" #include "math_streamstr.h" #include "math_support.h" +#include "math_extern.h" +#include "math_charinset.h" #include "debug.h" #include "textpainter.h" #include "funcrequest.h" @@ -653,6 +655,82 @@ void MathHullInset::check() const } +void MathHullInset::doExtern + (FuncRequest const & func, idx_type & idx, pos_type & pos) +{ + string lang; + string extra; + istringstream iss(func.argument.c_str()); + iss >> lang >> extra; + if (extra.empty()) + extra = "noextra"; + +#ifdef WITH_WARNINGS +#warning temporarily disabled + //if (selection()) { + // MathArray ar; + // selGet(ar); + // lyxerr << "use selection: " << ar << "\n"; + // insert(pipeThroughExtern(lang, extra, ar)); + // return; + //} +#endif + + MathArray eq; + eq.push_back(MathAtom(new MathCharInset('='))); + + // go to first item in line + idx -= idx % ncols(); + pos = 0; + + if (getType() == "simple") { + size_type pos = cell(idx).find_last(eq); + MathArray ar; + if (pos == cell(idx).size()) { + ar = cell(idx); + lyxerr << "use whole cell: " << ar << "\n"; + } else { + ar = MathArray(cell(idx).begin() + pos + 1, cell(idx).end()); + lyxerr << "use partial cell form pos: " << pos << "\n"; + } + cell(idx).append(eq); + cell(idx).append(pipeThroughExtern(lang, extra, ar)); + pos = cell(idx).size(); + return; + } + + if (getType() == "equation") { + lyxerr << "use equation inset\n"; + mutate("eqnarray"); + MathArray & ar = cell(idx); + lyxerr << "use cell: " << ar << "\n"; + cell(idx + 1) = eq; + cell(idx + 2) = pipeThroughExtern(lang, extra, ar); + // move to end of line + idx += 2; + pos = cell(idx).size(); + return; + } + + { + lyxerr << "use eqnarray\n"; + idx -= idx % ncols(); + idx += 2; + pos = 0; + MathArray ar = cell(idx); + lyxerr << "use cell: " << ar << "\n"; +#ifdef WITH_WARNINGS +#warning temporarily disabled +#endif + addRow(row(idx)); + cell(idx + 2) = eq; + cell(idx + 3) = pipeThroughExtern(lang, extra, ar); + idx += 3; + pos = cell(idx).size(); + } +} + + MathInset::result_type MathHullInset::dispatch (FuncRequest const & cmd, idx_type & idx, pos_type & pos) { @@ -726,6 +804,10 @@ MathInset::result_type MathHullInset::dispatch // we explicitly don't want the default behaviour here return UNDISPATCHED; + case LFUN_MATH_EXTERN: + doExtern(cmd, idx, pos); + return DISPATCHED_POP; + default: return MathGridInset::dispatch(cmd, idx, pos); diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 8204d5fbf2..b45c4f8872 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -101,6 +101,8 @@ private: /// string nicelabel(row_type row) const; /// + void doExtern(FuncRequest const & func, idx_type & idx, pos_type & pos); + /// void glueall(); /// char const * standardFont() const; -- 2.39.2