4 * Purpose: Common parts of the math LyX insets
7 * Description: Allows the edition of math paragraphs inside Lyx.
9 * Copyright: 2001, The LyX Project
11 * You are free to use and modify this code under the terms of
12 * the GNU General Public Licence version 2 or later.
15 #ifndef INSET_FORMULABASE_H
16 #define INSET_FORMULABASE_H
22 #include "insets/inset.h"
23 #include "frontends/mouse_state.h"
26 #include <boost/weak_ptr.hpp>
33 /// An abstract base class for all math related LyX insets
34 class InsetFormulaBase : public UpdatableInset {
39 virtual int ascent(BufferView *, LyXFont const &) const = 0;
41 virtual int descent(BufferView *, LyXFont const &) const = 0;
43 virtual int width(BufferView *, LyXFont const &) const = 0;
45 virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
46 /// lowest x coordinate
47 virtual int xlow() const;
48 /// highest x coordinate
49 virtual int xhigh() const;
50 /// lowest y coordinate
51 virtual int ylow() const;
52 /// highest y coordinate
53 virtual int yhigh() const;
57 virtual void validate(LaTeXFeatures &) const;
59 virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
61 virtual Inset::Code lyxCode() const;
62 /// what appears in the minibuffer when opening
63 virtual string const editMessage() const;
65 virtual void edit(BufferView *, int x, int y, mouse_button::state button);
67 virtual void edit(BufferView *, bool front = true);
69 virtual void toggleInsetCursor(BufferView *);
71 virtual void showInsetCursor(BufferView *, bool show = true);
73 virtual void hideInsetCursor(BufferView *);
75 virtual void fitInsetCursor(BufferView *) const;
77 virtual void getCursorPos(BufferView *, int &, int &) const;
79 virtual void toggleInsetSelection(BufferView * bv);
81 virtual void insetUnlock(BufferView *);
83 /// To allow transparent use of math editing functions
84 virtual RESULT localDispatch(FuncRequest const &);
85 /// To allow transparent use of math editing functions
86 //virtual void status(FuncRequest const &);
89 virtual std::vector<string> const getLabelList() const;
91 virtual MathAtom const & par() const = 0;
93 virtual MathAtom & par() = 0;
95 virtual void updateLocal(BufferView * bv, bool mark_dirty);
97 BufferView * view() const { return view_.get(); }
100 virtual bool searchForward(BufferView *, string const &,
101 bool = true, bool = false);
103 virtual bool searchBackward(BufferView *, string const &,
104 bool = true, bool = false);
106 virtual bool isTextInset() const { return true; }
108 virtual void mutateToText();
110 virtual void revealCodes(BufferView *) const;
112 virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
114 bool display() const;
118 void operator=(const InsetFormulaBase &);
119 /// common base for handling accents
120 void handleAccent(BufferView * bv, string const & arg, string const & name);
122 RESULT lfunMousePress(FuncRequest const &);
124 RESULT lfunMouseRelease(FuncRequest const &);
126 RESULT lfunMouseMotion(FuncRequest const &);
130 mutable boost::weak_ptr<BufferView> view_;
132 mutable LyXFont font_;
136 void metrics(BufferView * bv, LyXFont const & font) const;
138 void metrics(BufferView * bv = 0) const;
140 void handleFont(BufferView * bv, string const & arg, string const & font);
148 // We don't really mess want around with mathed stuff outside mathed.
150 void mathDispatch(FuncRequest const &);