From a58158344d6afa3ff8a396a1b692d409f2921774 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 18 Feb 2003 11:47:16 +0000 Subject: [PATCH] iu2: move localDispatch() to InsetBase git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6194 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/Makefile.am | 1 + src/insets/inset.C | 6 --- src/insets/inset.h | 6 +-- src/insets/insetbase.C | 17 +++++++++ src/insets/insetbase.h | 70 ++++++++++++++++++++++------------- src/lyxfunc.C | 12 +++--- src/mathed/command_inset.C | 2 +- src/mathed/command_inset.h | 2 +- src/mathed/formulabase.C | 12 +++--- src/mathed/formulabase.h | 8 ++-- src/mathed/math_cursor.C | 11 +++--- src/mathed/math_cursor.h | 2 +- src/mathed/math_gridinset.C | 2 +- src/mathed/math_gridinset.h | 2 +- src/mathed/math_hullinset.C | 2 +- src/mathed/math_hullinset.h | 2 +- src/mathed/math_inset.C | 7 ---- src/mathed/math_inset.h | 7 ---- src/mathed/math_nestinset.C | 2 +- src/mathed/math_nestinset.h | 3 +- src/mathed/math_scriptinset.C | 2 +- src/mathed/math_scriptinset.h | 2 +- src/mathed/ref_inset.C | 2 +- src/mathed/ref_inset.h | 2 +- src/text3.C | 10 ++--- 25 files changed, 104 insertions(+), 90 deletions(-) diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index d888b6942a..562e147f99 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -18,6 +18,7 @@ libinsets_la_SOURCES = \ inset.C \ inset.h \ insetbase.h \ + insetbase.C \ insetbib.C \ insetbib.h \ insetbutton.C \ diff --git a/src/insets/inset.C b/src/insets/inset.C index 21ca38df6c..b62738a609 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -88,12 +88,6 @@ void Inset::edit(BufferView *, bool) {} -Inset::RESULT Inset::localDispatch(FuncRequest const &) -{ - return UNDISPATCHED; -} - - #if 0 LyXFont const Inset::convertFont(LyXFont const & font) const { diff --git a/src/insets/inset.h b/src/insets/inset.h index 7df0f29e04..0f66e29c6c 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -142,15 +142,13 @@ public: }; /// - typedef InsetBase::dispatch_result RESULT; + typedef dispatch_result RESULT; /// Inset(); /// Inset(Inset const & in, bool same_id = false); /// - virtual ~Inset() {} - /// virtual int ascent(BufferView *, LyXFont const &) const = 0; /// virtual int descent(BufferView *, LyXFont const &) const = 0; @@ -171,8 +169,6 @@ public: /// virtual EDITABLE editable() const; /// - virtual RESULT localDispatch(FuncRequest const & cmd); - /// virtual bool isTextInset() const { return false; } /// virtual bool doClearArea() const { return true; } diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index e69de29bb2..58371411a2 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -0,0 +1,17 @@ + +#include "insetbase.h" + + +dispatch_result InsetBase::dispatch(FuncRequest const &, idx_type &, pos_type &) +{ + return UNDISPATCHED; +} + + +dispatch_result InsetBase::localDispatch(FuncRequest const & cmd) +{ + idx_type idx = 0; + pos_type pos = 0; + return dispatch(cmd, idx, pos); +} + diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index d09874d6ab..79933fcc62 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -12,35 +12,55 @@ #ifndef INSETBASE_H #define INSETBASE_H +#include + +class FuncRequest; + +/** Dispatch result codes + DISPATCHED = the inset catched the action + DISPATCHED_NOUPDATE = the inset catched the action and no update + is needed here to redraw the inset + FINISHED = the inset must be unlocked as a result + of the action + FINISHED_RIGHT = FINISHED, but put the cursor to the RIGHT of + the inset. + FINISHED_UP = FINISHED, but put the cursor UP of + the inset. + FINISHED_DOWN = FINISHED, but put the cursor DOWN of + the inset. + UNDISPATCHED = the action was not catched, it should be + dispatched by lower level insets +*/ +enum dispatch_result { + UNDISPATCHED = 0, + DISPATCHED, + DISPATCHED_NOUPDATE, + FINISHED, + FINISHED_RIGHT, + FINISHED_UP, + FINISHED_DOWN, + DISPATCHED_POP +}; + /// Common base class to all insets class InsetBase { public: - /** Dispatch result codes - DISPATCHED = the inset catched the action - DISPATCHED_NOUPDATE = the inset catched the action and no update - is needed here to redraw the inset - FINISHED = the inset must be unlocked as a result - of the action - FINISHED_RIGHT = FINISHED, but put the cursor to the RIGHT of - the inset. - FINISHED_UP = FINISHED, but put the cursor UP of - the inset. - FINISHED_DOWN = FINISHED, but put the cursor DOWN of - the inset. - UNDISPATCHED = the action was not catched, it should be - dispatched by lower level insets - */ - enum dispatch_result { - UNDISPATCHED = 0, - DISPATCHED, - DISPATCHED_NOUPDATE, - FINISHED, - FINISHED_RIGHT, - FINISHED_UP, - FINISHED_DOWN, - DISPATCHED_POP - }; + /// type for cell indices + typedef size_t idx_type; + /// type for cursor positions + typedef size_t pos_type; + /// type for row numbers + typedef size_t row_type; + /// type for column numbers + typedef size_t col_type; + + // the real dispatcher + virtual dispatch_result dispatch + (FuncRequest const & cmd, idx_type & idx, pos_type & pos); + + /// small wrapper for the time being + virtual dispatch_result localDispatch(FuncRequest const & cmd); /// virtual ~InsetBase() {} diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 99a61ed8e2..9cdd982fab 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -789,21 +789,21 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) } else if (((result=inset-> // Hand-over to inset's own dispatch: localDispatch(FuncRequest(view(), action, argument))) == - UpdatableInset::DISPATCHED) || - (result == UpdatableInset::DISPATCHED_NOUPDATE)) + DISPATCHED) || + (result == DISPATCHED_NOUPDATE)) goto exit_with_message; // If UNDISPATCHED, just soldier on - else if (result == UpdatableInset::FINISHED) { + else if (result == FINISHED) { goto exit_with_message; // We do not need special RTL handling here: // FINISHED means that the cursor should be // one position after the inset. - } else if (result == UpdatableInset::FINISHED_RIGHT) { + } else if (result == FINISHED_RIGHT) { TEXT()->cursorRight(view()); moveCursorUpdate(true, false); owner->view_state_changed(); goto exit_with_message; - } else if (result == UpdatableInset::FINISHED_UP) { + } else if (result == FINISHED_UP) { if (TEXT()->cursor.irow()->previous()) { #if 1 TEXT()->setCursorFromCoordinates( @@ -820,7 +820,7 @@ void LyXFunc::dispatch(FuncRequest const & ev, bool verbose) view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR); } goto exit_with_message; - } else if (result == UpdatableInset::FINISHED_DOWN) { + } else if (result == FINISHED_DOWN) { if (TEXT()->cursor.irow()->next()) { #if 1 TEXT()->setCursorFromCoordinates( diff --git a/src/mathed/command_inset.C b/src/mathed/command_inset.C index dcb256f478..22e56af173 100644 --- a/src/mathed/command_inset.C +++ b/src/mathed/command_inset.C @@ -27,7 +27,7 @@ MathInset * CommandInset::clone() const } -MathInset::result_type +dispatch_result CommandInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { switch (cmd.action) { diff --git a/src/mathed/command_inset.h b/src/mathed/command_inset.h index 3fb4258e63..df5981f71e 100644 --- a/src/mathed/command_inset.h +++ b/src/mathed/command_inset.h @@ -29,7 +29,7 @@ public: /// //void infoize(std::ostream & os) const; /// - result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); /// string screenLabel() const; public: diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 1ab3bf9c90..316ea479bf 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -303,7 +303,7 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty) } -Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) +dispatch_result InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) { if (!mathcursor) return UNDISPATCHED; @@ -316,7 +316,7 @@ Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) if (cmd.button() == mouse_button::button3) { // try to dispatch to enclosed insets first - if (mathcursor->dispatch(cmd) == MathInset::UNDISPATCHED) { + if (mathcursor->dispatch(cmd) == UNDISPATCHED) { // launch math panel for right mouse button bv->owner()->getDialogs().showMathPanel(); } @@ -347,7 +347,7 @@ Inset::RESULT InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) } -Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) +dispatch_result InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) { BufferView * bv = cmd.view(); //lyxerr << "lfunMousePress: buttons: " << cmd.button() << endl; @@ -379,12 +379,12 @@ Inset::RESULT InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) } -Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) +dispatch_result InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) { if (!mathcursor) return DISPATCHED; - if (mathcursor->dispatch(FuncRequest(cmd)) != MathInset::UNDISPATCHED) + if (mathcursor->dispatch(FuncRequest(cmd)) != UNDISPATCHED) return DISPATCHED; // only select with button 1 @@ -409,7 +409,7 @@ Inset::RESULT InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) } -Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd) +dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd) { //lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action // << " arg: '" << cmd.argument diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 49d48a4bcd..8dd68ec3ba 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -76,7 +76,7 @@ public: virtual void insetUnlock(BufferView *); /// To allow transparent use of math editing functions - virtual RESULT localDispatch(FuncRequest const &); + virtual dispatch_result localDispatch(FuncRequest const &); /// To allow transparent use of math editing functions //virtual void status(FuncRequest const &); @@ -116,11 +116,11 @@ private: /// common base for handling accents void handleAccent(BufferView * bv, string const & arg, string const & name); /// lfun handler - RESULT lfunMousePress(FuncRequest const &); + dispatch_result lfunMousePress(FuncRequest const &); /// - RESULT lfunMouseRelease(FuncRequest const &); + dispatch_result lfunMouseRelease(FuncRequest const &); /// - RESULT lfunMouseMotion(FuncRequest const &); + dispatch_result lfunMouseMotion(FuncRequest const &); protected: /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 5e89cc4b87..7efecbba79 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -1409,21 +1409,20 @@ MathCursorPos MathCursor::normalAnchor() const } -MathInset::result_type MathCursor::dispatch(FuncRequest const & cmd) +dispatch_result MathCursor::dispatch(FuncRequest const & cmd) { for (int i = Cursor_.size() - 1; i >= 0; --i) { MathCursorPos & pos = Cursor_[i]; - MathInset::result_type - res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_); - if (res != MathInset::UNDISPATCHED) { - if (res == MathInset::DISPATCHED_POP) { + dispatch_result res = pos.par_->dispatch(cmd, pos.idx_, pos.pos_); + if (res != UNDISPATCHED) { + if (res == DISPATCHED_POP) { Cursor_.shrink(i + 1); selClear(); } return res; } } - return MathInset::UNDISPATCHED; + return UNDISPATCHED; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index b0d3a240d6..8043f3b7d9 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -218,7 +218,7 @@ public: unsigned depth() const; /// local dispatcher - MathInset::result_type dispatch(FuncRequest const & cmd); + dispatch_result dispatch(FuncRequest const & cmd); /// describe the situation string info() const; /// dump selection information for debugging diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 7cfd702c9a..8e3c61838d 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -967,7 +967,7 @@ void MathGridInset::splitCell(idx_type & idx, pos_type & pos) } -MathInset::result_type MathGridInset::dispatch +dispatch_result MathGridInset::dispatch (FuncRequest const & cmd, idx_type & idx, pos_type & pos) { switch (cmd.action) { diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 29e8c9afc7..a7df3eb585 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -128,7 +128,7 @@ public: /// identifies GridInset MathGridInset const * asGridInset() const { return this; } /// local dispatcher - result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); /// col_type ncols() const; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 52044b8ef0..5d52dfd0ba 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -743,7 +743,7 @@ void MathHullInset::doExtern } -MathInset::result_type MathHullInset::dispatch +dispatch_result MathHullInset::dispatch (FuncRequest const & cmd, idx_type & idx, pos_type & pos) { switch (cmd.action) { diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index f0911dd926..63e580f105 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -46,7 +46,7 @@ public: /// bool ams() const; /// local dispatcher - result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); /// void getLabelList(std::vector &) const; /// diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 47a1c3d82c..065408881b 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -260,13 +260,6 @@ int MathInset::docbook(std::ostream &, bool) const } -MathInset::result_type - MathInset::dispatch(FuncRequest const &, idx_type &, pos_type &) -{ - return UNDISPATCHED; -} - - string const & MathInset::getType() const { static string t("none"); diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 2b0719621c..c955400858 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -97,13 +97,9 @@ public: typedef size_type row_type; /// type for column numbers typedef size_type col_type; - /// - typedef InsetBase::dispatch_result result_type; /// our members behave nicely... MathInset() {} - /// the virtual base destructor - virtual ~MathInset() {} /// reproduce itself virtual MathInset * clone() const = 0; @@ -289,9 +285,6 @@ public: /// dump content to stderr for debugging virtual void dump() const; - /// local dispatcher - virtual result_type dispatch - (FuncRequest const & cmd, idx_type & idx, pos_type & pos); /// LyXInset stuff /// write labels into a list diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 3ed34a0277..890fe5c017 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -315,7 +315,7 @@ void MathNestInset::notifyCursorLeaves(idx_type idx) } -MathInset::result_type MathNestInset::dispatch +dispatch_result MathNestInset::dispatch (FuncRequest const & cmd, idx_type & idx, pos_type & pos) { BufferView * bv = cmd.view(); diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 4abaa95fea..42dad7d977 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -99,7 +99,8 @@ public: void normalize(NormalStream & os) const; /// local dispatcher - result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + dispatch_result + dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); protected: /// we store the cells in a vector diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 201916eabf..3892ba8832 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -493,7 +493,7 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx) } -MathInset::result_type MathScriptInset::dispatch +dispatch_result MathScriptInset::dispatch (FuncRequest const & cmd, idx_type & idx, pos_type & pos) { if (cmd.action == LFUN_MATH_LIMITS) { diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 6b7688d4b8..fa5dc7653f 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -91,7 +91,7 @@ public: /// say whether we have displayed limits void infoize2(std::ostream & os) const; /// local dispatcher - result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); private: /// returns x offset for main part diff --git a/src/mathed/ref_inset.C b/src/mathed/ref_inset.C index 5002cb5eea..520b6a0c86 100644 --- a/src/mathed/ref_inset.C +++ b/src/mathed/ref_inset.C @@ -36,7 +36,7 @@ void RefInset::infoize(std::ostream & os) const } -MathInset::result_type +dispatch_result RefInset::dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { switch (cmd.action) { diff --git a/src/mathed/ref_inset.h b/src/mathed/ref_inset.h index c8ff0347af..bb9a6c25da 100644 --- a/src/mathed/ref_inset.h +++ b/src/mathed/ref_inset.h @@ -18,7 +18,7 @@ public: /// void infoize(std::ostream & os) const; /// - result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); + dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); /// string screenLabel() const; /// diff --git a/src/text3.C b/src/text3.C index 5dacb94186..3fcc37dfa4 100644 --- a/src/text3.C +++ b/src/text3.C @@ -375,6 +375,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind) bv->updateInset(new_inset, true); } + void doInsertInset(LyXText * lt, FuncRequest const & cmd, bool edit, bool pastesel) { @@ -396,7 +397,6 @@ void doInsertInset(LyXText * lt, FuncRequest const & cmd, else delete inset; } - } } @@ -1055,7 +1055,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_BEGINNINGBUFSEL: if (inset_owner) - return Inset::UNDISPATCHED; + return UNDISPATCHED; update(bv, false); cursorTop(bv); finishChange(bv, true); @@ -1063,7 +1063,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) case LFUN_ENDBUFSEL: if (inset_owner) - return Inset::UNDISPATCHED; + return UNDISPATCHED; update(bv, false); cursorBottom(bv); finishChange(bv, true); @@ -1640,8 +1640,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd) break; default: - return Inset::UNDISPATCHED; + return UNDISPATCHED; } - return Inset::DISPATCHED; + return DISPATCHED; } -- 2.39.5