4 * Common parts of the math LyX insets
7 * Full author contact details are available in file CREDITS
9 * You are free to use and modify this code under the terms of
10 * the GNU General Public Licence version 2 or later.
13 #ifndef INSET_FORMULABASE_H
14 #define INSET_FORMULABASE_H
17 #include "insets/updatableinset.h"
18 #include "frontends/mouse_state.h"
21 #include <boost/weak_ptr.hpp>
28 /// An abstract base class for all math related LyX insets
29 class InsetFormulaBase : public UpdatableInset {
34 virtual int ascent(BufferView *, LyXFont const &) const = 0;
36 virtual int descent(BufferView *, LyXFont const &) const = 0;
38 virtual int width(BufferView *, LyXFont const &) const = 0;
40 virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0;
41 /// lowest x coordinate
42 virtual int xlow() const;
43 /// highest x coordinate
44 virtual int xhigh() const;
45 /// lowest y coordinate
46 virtual int ylow() const;
47 /// highest y coordinate
48 virtual int yhigh() const;
52 // Don't use this for AMS validation as long as there is no
53 // user-accessible way to override "false positives"
54 virtual void validate(LaTeXFeatures &) const;
56 virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
58 virtual Inset::Code lyxCode() const;
59 /// what appears in the minibuffer when opening
60 virtual string const editMessage() const;
62 virtual void fitInsetCursor(BufferView *) const;
64 virtual void getCursorPos(BufferView *, int &, int &) const;
65 /// get the absolute document x,y of the cursor
66 virtual void getCursor(BufferView & bv, int & x, int & y) const;
68 virtual void toggleInsetSelection(BufferView * bv);
70 virtual void insetUnlock(BufferView *);
72 /// To allow transparent use of math editing functions
73 virtual dispatch_result localDispatch(FuncRequest const &);
74 /// To allow transparent use of math editing functions
75 //virtual void status(FuncRequest const &);
78 virtual std::vector<string> const getLabelList() const;
80 virtual MathAtom const & par() const = 0;
82 virtual MathAtom & par() = 0;
84 // And shouldn't this really return a shared_ptr<BufferView> instead?
85 BufferView * view() const;
88 virtual bool searchForward(BufferView *, string const &,
89 bool = true, bool = false);
91 virtual bool searchBackward(BufferView *, string const &,
92 bool = true, bool = false);
94 virtual bool isTextInset() const { return true; }
96 virtual void mutateToText();
98 virtual void revealCodes(BufferView *) const;
100 virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
102 bool display() const;
103 // return the selection as string
104 string selectionAsString() const;
108 void operator=(const InsetFormulaBase &);
109 /// common base for handling accents
110 void handleAccent(BufferView * bv, string const & arg, string const & name);
112 dispatch_result lfunMousePress(FuncRequest const &);
114 dispatch_result lfunMouseRelease(FuncRequest const &);
116 dispatch_result lfunMouseMotion(FuncRequest const &);
120 mutable boost::weak_ptr<BufferView> view_;
122 mutable LyXFont font_;
126 void metrics(BufferView * bv, LyXFont const & font) const;
128 void metrics(BufferView * bv = 0) const;
130 void handleFont(BufferView * bv, string const & arg, string const & font);
138 // We don't really mess want around with mathed stuff outside mathed.
140 void mathDispatch(FuncRequest const &);
143 void releaseMathCursor(BufferView * bv);