First stab. Introduce a common base class and move dispatch codes there.
[Some renaming will occur later, I thought I better keep it small...]

Andre'

-- 
Those who desire to give up Freedom in order to gain Security,
will not have, nor do they deserve, either one. (T. Jefferson)
Index: insets/Makefile.am
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/Makefile.am,v
retrieving revision 1.50
diff -u -p -r1.50 Makefile.am
--- insets/Makefile.am  24 Sep 2002 18:20:26 -0000      1.50
+++ insets/Makefile.am  7 Feb 2003 16:32:54 -0000
@@ -17,6 +17,7 @@ libinsets_la_SOURCES = \
        ExternalTemplate.h \
        inset.C \
        inset.h \
+       insetbase.h \
        insetbib.C \
        insetbib.h \
        insetbutton.C \
Index: insets/inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.C,v
retrieving revision 1.84
diff -u -p -r1.84 inset.C
--- insets/inset.C      1 Dec 2002 22:59:24 -0000       1.84
+++ insets/inset.C      7 Feb 2003 16:32:54 -0000
@@ -42,14 +42,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)
Index: insets/inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/inset.h,v
retrieving revision 1.61
diff -u -p -r1.61 inset.h
--- insets/inset.h      1 Dec 2002 22:59:24 -0000       1.61
+++ insets/inset.h      7 Feb 2003 16:32:55 -0000
@@ -22,6 +22,7 @@
 #include <vector>
 #include "LString.h"
 #include "LColor.h"
+#include "insetbase.h"
 #include "frontends/mouse_state.h"
 
 class LyXFont;
@@ -42,7 +43,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
@@ -142,34 +143,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();
@@ -377,6 +352,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:
        ///
Index: insets/insetbase.C
===================================================================
RCS file: insets/insetbase.C
diff -N insets/insetbase.C
Index: insets/insetbase.h
===================================================================
RCS file: insets/insetbase.h
diff -N insets/insetbase.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ insets/insetbase.h  7 Feb 2003 16:32:55 -0000
@@ -0,0 +1,52 @@
+// -*- 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
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+/// 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
Index: mathed/math_inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v
retrieving revision 1.150
diff -u -p -r1.150 math_inset.h
--- mathed/math_inset.h 7 Jan 2003 11:24:43 -0000       1.150
+++ mathed/math_inset.h 7 Feb 2003 16:32:55 -0000
@@ -30,6 +30,7 @@
 
 #include "LString.h"
 #include "frontends/mouse_state.h"
+#include "insets/insetbase.h"
 #include "math_data.h"
 
 /**
@@ -85,7 +86,7 @@ class Dimension;
 class FuncRequest;
 
 
-class MathInset {
+class MathInset : public InsetBase {
 public:
        /// short of anything else reasonable
        typedef MathArray::size_type        size_type;
@@ -99,6 +100,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() {}
@@ -232,12 +235,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 {..}

Reply via email to