]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/formulabase.h
fix #1073
[lyx.git] / src / mathed / formulabase.h
index 3d45a7814fbc6ba7ee1519344091c30d9d8ef890..1459c894a3b14bf30b2dc482ea6ad33858e1e853 100644 (file)
@@ -1,35 +1,31 @@
 // -*- C++ -*-
+
 /*
- *  File:        formulabase.h
- *  Purpose:     Common parts of the math LyX insets
- *  Author:      André Pönitz
- *  Created:     May 2001
- *  Description: Allows the edition of math paragraphs inside Lyx. 
+ * Common parts of the math LyX insets
+ * \author  André Pönitz
  *
- *  Copyright: 2001, The LyX Project
+ * Full author contact details are available in file CREDITS
  *
- *   You are free to use and modify this code under the terms of
- *   the GNU General Public Licence version 2 or later.
+ * You are free to use and modify this code under the terms of
+ * the GNU General Public Licence version 2 or later.
  */
 
-#ifndef INSET_FORMULABASE_H 
+#ifndef INSET_FORMULABASE_H
 #define INSET_FORMULABASE_H
 
-#ifdef __GNUG__
-#pragma interface
-#endif
 
-#include <iosfwd>
-#include "insets/inset.h"
+#include "insets/updatableinset.h"
+#include "frontends/mouse_state.h"
+#include "lyxfont.h"
 
-// only for getType():
-#include "math_defs.h"
+#include <boost/weak_ptr.hpp>
+#include <iosfwd>
 
 class Buffer;
 class BufferView;
 class MathAtom;
 
-///
+/// An abstract base class for all math related LyX insets
 class InsetFormulaBase : public UpdatableInset {
 public:
        ///
@@ -41,12 +37,20 @@ public:
        ///
        virtual int width(BufferView *, LyXFont const &) const = 0;
        ///
-       virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
-       ///
-       virtual MathInsetTypes getType() const = 0;
+       virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0;
+       /// lowest x coordinate
+       virtual int xlow() const;
+       /// highest x coordinate
+       virtual int xhigh() const;
+       /// lowest y coordinate
+       virtual int ylow() const;
+       /// highest y coordinate
+       virtual int yhigh() const;
 
 public:
        ///
+       // Don't use this for AMS validation as long as there is no
+       // user-accessible way to override "false positives"
        virtual void validate(LaTeXFeatures &) const;
        ///
        virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
@@ -55,7 +59,7 @@ public:
        /// what appears in the minibuffer when opening
        virtual string const editMessage() const;
        ///
-       virtual void edit(BufferView *, int x, int y, unsigned int button);
+       virtual void edit(BufferView *, int x, int y, mouse_button::state button);
        ///
        virtual void edit(BufferView *, bool front = true);
        ///
@@ -65,23 +69,19 @@ public:
        ///
        virtual void hideInsetCursor(BufferView *);
        ///
+       virtual void fitInsetCursor(BufferView *) const;
+       ///
        virtual void getCursorPos(BufferView *, int &, int &) const;
        ///
        virtual void toggleInsetSelection(BufferView * bv);
        ///
-       virtual void insetButtonPress(BufferView *, int x, int y, int button);
-       ///
-       virtual void insetButtonRelease(BufferView *, int x, int y, int button);
-       ///
-       virtual void insetKeyPress(XKeyEvent * ev);
-       ///
-       virtual void insetMotionNotify(BufferView *, int x, int y, int state);
-       ///
        virtual void insetUnlock(BufferView *);
-   
+
+       /// To allow transparent use of math editing functions
+       virtual dispatch_result localDispatch(FuncRequest const &);
        /// To allow transparent use of math editing functions
-       virtual RESULT localDispatch(BufferView *, kb_action, string const &);
-    
+       //virtual void status(FuncRequest const &);
+
        ///
        virtual std::vector<string> const getLabelList() const;
        ///
@@ -89,37 +89,65 @@ public:
        ///
        virtual MathAtom & par() = 0;
        ///
-       virtual void metrics(BufferView * bv = 0, LyXFont const * font = 0) const;
+       // And shouldn't this really return a shared_ptr<BufferView> instead?
+       BufferView * view() const;
+
+       ///
+       virtual bool searchForward(BufferView *, string const &,
+                                  bool = true, bool = false);
+       ///
+       virtual bool searchBackward(BufferView *, string const &,
+                                   bool = true, bool = false);
        ///
-       virtual void updateLocal(BufferView * bv, bool mark_dirty);
+       virtual bool isTextInset() const { return true; }
+       ///
+       virtual void mutateToText();
+       ///
+       virtual void revealCodes(BufferView *) const;
+       ///
+       virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
+       ///
+       bool display() const;
+       // return the selection as string
+       string selectionAsString() const;
+
 private:
        /// unimplemented
        void operator=(const InsetFormulaBase &);
+       /// common base for handling accents
+       void handleAccent(BufferView * bv, string const & arg, string const & name);
+       /// lfun handler
+       dispatch_result lfunMousePress(FuncRequest const &);
        ///
-       mutable BufferView * view_;     
+       dispatch_result lfunMouseRelease(FuncRequest const &);
        ///
-       mutable LyXFont const * font_;
+       dispatch_result lfunMouseMotion(FuncRequest const &);
+
+protected:
+       ///
+       mutable boost::weak_ptr<BufferView> view_;
+       ///
+       mutable LyXFont font_;
+
+protected:
+       ///
+       void metrics(BufferView * bv, LyXFont const & font) const;
+       ///
+       void metrics(BufferView * bv = 0) const;
+       ///
+       void handleFont(BufferView * bv, string const & arg, string const & font);
+
+       ///
+       mutable int xo_;
+       ///
+       mutable int yo_;
 };
 
 // We don't really mess want around with mathed stuff outside mathed.
 // So do it here.
-//
-void mathDispatchCreation(BufferView *, string const &, bool);
-//
-void mathDispatchMathDisplay(BufferView *, string const &);
-//
-void mathDispatchMathMode(BufferView *, string const &);
-//
-void mathDispatchMathMacro(BufferView *, string const &);
-//
-void mathDispatchMathDelim(BufferView *, string const &);
-//
-void mathDispatchInsertMath(BufferView *, string const &);
-//
-void mathDispatchInsertMatrix(BufferView *, string const &);
-//
-void mathDispatchGreek(BufferView *, string const &);
-//
-void mathDispatchMathImportSelection(BufferView *, string const &);
+void mathDispatch(FuncRequest const &);
+
+///
+void releaseMathCursor(BufferView * bv);
 
 #endif