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;
47 virtual string hullType() const { return "none"; }
48 /// lowest x coordinate
49 virtual int xlow() const;
50 /// highest x coordinate
51 virtual int xhigh() const;
52 /// lowest y coordinate
53 virtual int ylow() const;
54 /// highest y coordinate
55 virtual int yhigh() const;
59 virtual void validate(LaTeXFeatures &) const;
61 virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
63 virtual Inset::Code lyxCode() const;
64 /// what appears in the minibuffer when opening
65 virtual string const editMessage() const;
67 virtual void edit(BufferView *, int x, int y, mouse_button::state button);
69 virtual void edit(BufferView *, bool front = true);
71 virtual void toggleInsetCursor(BufferView *);
73 virtual void showInsetCursor(BufferView *, bool show = true);
75 virtual void hideInsetCursor(BufferView *);
77 virtual void fitInsetCursor(BufferView *) const;
79 virtual void getCursorPos(BufferView *, int &, int &) const;
81 virtual void toggleInsetSelection(BufferView * bv);
83 virtual void insetButtonPress(BufferView *, int x, int y, mouse_button::state button);
85 virtual bool insetButtonRelease(BufferView *, int x, int y, mouse_button::state button);
87 virtual void insetMotionNotify(BufferView *, int x, int y, mouse_button::state state);
89 virtual void insetUnlock(BufferView *);
91 /// To allow transparent use of math editing functions
92 virtual RESULT localDispatch(BufferView *, FuncRequest const &);
95 virtual std::vector<string> const getLabelList() const;
97 virtual MathAtom const & par() const = 0;
99 virtual MathAtom & par() = 0;
101 virtual void updateLocal(BufferView * bv, bool mark_dirty);
103 BufferView * view() const { return view_.get(); }
106 virtual bool searchForward(BufferView *, string const &,
107 bool = true, bool = false);
109 virtual bool searchBackward(BufferView *, string const &,
110 bool = true, bool = false);
112 virtual bool isTextInset() const { return true; }
114 virtual void mutateToText();
116 virtual void revealCodes(BufferView *) const;
118 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);
128 mutable boost::weak_ptr<BufferView> view_;
130 mutable LyXFont font_;
134 void metrics(BufferView * bv, LyXFont const & font) const;
136 void metrics(BufferView * bv = 0) const;
138 void handleFont(BufferView * bv, string const & arg, string const & font);
146 // We don't really mess want around with mathed stuff outside mathed.
149 void mathDispatchCreation(BufferView *, string const &, bool);
151 void mathDispatchMathDisplay(BufferView *, string const &);
153 void mathDispatchMathMode(BufferView *, string const &);
155 void mathDispatchMathMacro(BufferView *, string const &);
157 void mathDispatchMathDelim(BufferView *, string const &);
159 void mathDispatchInsertMath(BufferView *, string const &);
161 void mathDispatchInsertMatrix(BufferView *, string const &);
163 void mathDispatchGreek(BufferView *, string const &);
165 void mathDispatchMathImportSelection(BufferView *, string const &);
167 void mathDispatch(BufferView *, FuncRequest const &);
169 void mathDispatch(BufferView *, string const &);