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
23 #include "insets/inset.h"
24 #include "frontends/mouse_state.h"
27 // only for getType():
28 #include "math_defs.h"
34 /// An abstract base class for all math related LyX insets
35 class InsetFormulaBase : public UpdatableInset {
40 virtual int ascent(BufferView *, LyXFont const &) const = 0;
42 virtual int descent(BufferView *, LyXFont const &) const = 0;
44 virtual int width(BufferView *, LyXFont const &) const = 0;
46 virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
48 virtual MathInsetTypes getType() const = 0;
49 /// lowest x coordinate
50 virtual int xlow() const;
51 /// highest x coordinate
52 virtual int xhigh() const;
53 /// lowest y coordinate
54 virtual int ylow() const;
55 /// highest y coordinate
56 virtual int yhigh() const;
60 virtual void validate(LaTeXFeatures &) const;
62 virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
64 virtual Inset::Code lyxCode() const;
65 /// what appears in the minibuffer when opening
66 virtual string const editMessage() const;
68 virtual void edit(BufferView *, int x, int y, mouse_button::state button);
70 virtual void edit(BufferView *, bool front = true);
72 virtual void toggleInsetCursor(BufferView *);
74 virtual void showInsetCursor(BufferView *, bool show = true);
76 virtual void hideInsetCursor(BufferView *);
78 virtual void getCursorPos(BufferView *, int &, int &) const;
80 virtual void toggleInsetSelection(BufferView * bv);
82 virtual void insetButtonPress(BufferView *, int x, int y, mouse_button::state button);
84 virtual bool insetButtonRelease(BufferView *, int x, int y, mouse_button::state button);
86 virtual void insetMotionNotify(BufferView *, int x, int y, mouse_button::state state);
88 virtual void insetUnlock(BufferView *);
90 /// To allow transparent use of math editing functions
91 virtual RESULT localDispatch(BufferView *, kb_action, string const &);
94 virtual std::vector<string> const getLabelList() const;
96 virtual MathAtom const & par() const = 0;
98 virtual MathAtom & par() = 0;
100 virtual void updateLocal(BufferView * bv, bool mark_dirty);
102 BufferView * view() const { return view_; }
105 virtual bool searchForward(BufferView *, string const &,
106 bool = true, bool = false);
108 virtual bool searchBackward(BufferView *, string const &,
109 bool = true, bool = false);
111 virtual bool isTextInset() const { return true; }
113 virtual void mutateToText();
115 virtual void revealCodes(BufferView *) const;
117 virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
122 void operator=(const InsetFormulaBase &);
123 /// common base for handling accents
124 void handleAccent(BufferView * bv, string const & arg, string const & name);
127 mutable BufferView * view_;
129 mutable LyXFont font_;
133 void metrics(BufferView * bv, LyXFont const & font) const;
135 void metrics(BufferView * bv = 0) const;
137 void handleFont(BufferView * bv, string const & arg, MathTextCodes t);
145 // We don't really mess want around with mathed stuff outside mathed.
148 void mathDispatchCreation(BufferView *, string const &, bool);
150 void mathDispatchMathDisplay(BufferView *, string const &);
152 void mathDispatchMathMode(BufferView *, string const &);
154 void mathDispatchMathMacro(BufferView *, string const &);
156 void mathDispatchMathDelim(BufferView *, string const &);
158 void mathDispatchInsertMath(BufferView *, string const &);
160 void mathDispatchInsertMatrix(BufferView *, string const &);
162 void mathDispatchGreek(BufferView *, string const &);
164 void mathDispatchMathImportSelection(BufferView *, string const &);
166 void mathDispatch(BufferView *, kb_action, string const &);