From a4e4ebc7eb7752c688ae2d87a2e89728d3d66ff9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 17 Feb 2003 17:12:50 +0000 Subject: [PATCH] First step towards unified insets... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6189 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/insets/Makefile.am | 1 + src/insets/inset.C | 6 +++-- src/insets/inset.h | 35 +++++------------------------ src/insets/insetbase.h | 49 +++++++++++++++++++++++++++++++++++++++++ src/mathed/math_inset.h | 11 ++++----- 5 files changed, 64 insertions(+), 38 deletions(-) create mode 100644 src/insets/insetbase.h diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index 2f7edc0b8f..d888b6942a 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -17,6 +17,7 @@ libinsets_la_SOURCES = \ ExternalTemplate.h \ inset.C \ inset.h \ + insetbase.h \ insetbib.C \ insetbib.h \ insetbutton.C \ diff --git a/src/insets/inset.C b/src/insets/inset.C index 50d94871e9..21ca38df6c 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -39,14 +39,16 @@ using std::endl; unsigned int Inset::inset_id = 0; Inset::Inset() - : top_x(0), topx_set(false), top_baseline(0), scx(0), + : InsetBase(), + top_x(0), topx_set(false), top_baseline(0), scx(0), id_(inset_id++), owner_(0), par_owner_(0), background_color_(LColor::inherit) {} Inset::Inset(Inset const & in, bool same_id) - : top_x(0), topx_set(false), top_baseline(0), scx(0), owner_(0), + : InsetBase(), + top_x(0), topx_set(false), top_baseline(0), scx(0), owner_(0), name_(in.name_), background_color_(in.background_color_) { if (same_id) diff --git a/src/insets/inset.h b/src/insets/inset.h index 3a309aee22..7df0f29e04 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -19,6 +19,7 @@ #include #include "LString.h" #include "LColor.h" +#include "insetbase.h" #include "frontends/mouse_state.h" #include "support/types.h" @@ -40,7 +41,7 @@ namespace grfx { } /// Insets -class Inset { +class Inset : public InsetBase { public: /** This is not quite the correct place for this enum. I think the correct would be to let each subclass of Inset declare @@ -140,34 +141,8 @@ public: HIGHLY_EDITABLE }; - /** Dispatch result codes - Now that nested updatable insets are allowed, the local dispatch - becomes a bit complex, just two possible results (boolean) - are not enough. - - 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 RESULT { - UNDISPATCHED = 0, - DISPATCHED, - DISPATCHED_NOUPDATE, - FINISHED, - FINISHED_RIGHT, - FINISHED_UP, - FINISHED_DOWN - }; + /// + typedef InsetBase::dispatch_result RESULT; /// Inset(); @@ -372,6 +347,7 @@ public: */ virtual void generatePreview() const {} + protected: /// mutable int top_x; @@ -537,6 +513,7 @@ public: virtual bool searchBackward(BufferView *, string const &, bool = true, bool = false); + protected: /// void toggleCursorVisible() const { diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h new file mode 100644 index 0000000000..d09874d6ab --- /dev/null +++ b/src/insets/insetbase.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +/** + * \file insetbase.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author none + * + * Full author contact details are available in file CREDITS + */ + +#ifndef INSETBASE_H +#define INSETBASE_H + + +/// 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 + }; + + /// + virtual ~InsetBase() {} +}; + +#endif diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 0ca35c6107..2b0719621c 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -27,6 +27,7 @@ #include "LString.h" #include "frontends/mouse_state.h" +#include "insets/insetbase.h" #include "math_data.h" /** @@ -82,7 +83,7 @@ class Dimension; class FuncRequest; -class MathInset { +class MathInset : public InsetBase { public: /// short of anything else reasonable typedef MathArray::size_type size_type; @@ -96,6 +97,8 @@ 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() {} @@ -229,12 +232,6 @@ public: virtual bool isRelOp() const { return false; } /// -1: text mode, 1: math mode, 0 undecided enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE}; - /// Dispatch result codes, see inset/inset.h - enum result_type { - UNDISPATCHED = 0, DISPATCHED, DISPATCHED_NOUPDATE, - FINISHED, FINISHED_RIGHT, FINISHED_UP, FINISHED_DOWN, - DISPATCHED_POP - }; virtual mode_type currentMode() const { return UNDECIDED_MODE; } /// will this get written as a single block in {..} -- 2.39.2