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 &, bool) 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 virtual void validate(LaTeXFeatures &) const;
54 virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
56 virtual Inset::Code lyxCode() const;
57 /// what appears in the minibuffer when opening
58 virtual string const editMessage() const;
60 virtual void edit(BufferView *, int x, int y, mouse_button::state button);
62 virtual void edit(BufferView *, bool front = true);
64 virtual void toggleInsetCursor(BufferView *);
66 virtual void showInsetCursor(BufferView *, bool show = true);
68 virtual void hideInsetCursor(BufferView *);
70 virtual void fitInsetCursor(BufferView *) const;
72 virtual void getCursorPos(BufferView *, int &, int &) const;
74 virtual void toggleInsetSelection(BufferView * bv);
76 virtual void insetUnlock(BufferView *);
78 /// To allow transparent use of math editing functions
79 virtual dispatch_result localDispatch(FuncRequest const &);
80 /// To allow transparent use of math editing functions
81 //virtual void status(FuncRequest const &);
84 virtual std::vector<string> const getLabelList() const;
86 virtual MathAtom const & par() const = 0;
88 virtual MathAtom & par() = 0;
90 virtual void updateLocal(BufferView * bv, bool mark_dirty);
92 #warning move this to formulabase.C (Lgb)
93 // And shouldn't this really return a shared_ptr<BufferView> instead?
94 BufferView * view() const {
95 return view_.lock().get();
99 virtual bool searchForward(BufferView *, string const &,
100 bool = true, bool = false);
102 virtual bool searchBackward(BufferView *, string const &,
103 bool = true, bool = false);
105 virtual bool isTextInset() const { return true; }
107 virtual void mutateToText();
109 virtual void revealCodes(BufferView *) const;
111 virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
113 bool display() const;
114 // return the selection as string
115 string selectionAsString() const;
119 void operator=(const InsetFormulaBase &);
120 /// common base for handling accents
121 void handleAccent(BufferView * bv, string const & arg, string const & name);
123 dispatch_result lfunMousePress(FuncRequest const &);
125 dispatch_result lfunMouseRelease(FuncRequest const &);
127 dispatch_result lfunMouseMotion(FuncRequest const &);
131 mutable boost::weak_ptr<BufferView> view_;
133 mutable LyXFont font_;
137 void metrics(BufferView * bv, LyXFont const & font) const;
139 void metrics(BufferView * bv = 0) const;
141 void handleFont(BufferView * bv, string const & arg, string const & font);
149 // We don't really mess want around with mathed stuff outside mathed.
151 void mathDispatch(FuncRequest const &);
154 void releaseMathCursor(BufferView * bv);