]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.h
cursor.diff, bug 1095
[lyx.git] / src / mathed / formulabase.h
1 // -*- C++ -*-
2
3 /*
4  * Common parts of the math LyX insets
5  * \author  André Pönitz
6  *
7  * Full author contact details are available in file CREDITS
8  *
9  * You are free to use and modify this code under the terms of
10  * the GNU General Public Licence version 2 or later.
11  */
12
13 #ifndef INSET_FORMULABASE_H
14 #define INSET_FORMULABASE_H
15
16
17 #include "insets/updatableinset.h"
18 #include "frontends/mouse_state.h"
19 #include "lyxfont.h"
20
21 #include <boost/weak_ptr.hpp>
22 #include <iosfwd>
23
24 class Buffer;
25 class BufferView;
26 class MathAtom;
27
28 /// An abstract base class for all math related LyX insets
29 class InsetFormulaBase : public UpdatableInset {
30 public:
31         ///
32         InsetFormulaBase();
33         ///
34         virtual int ascent(BufferView *, LyXFont const &) const = 0;
35         ///
36         virtual int descent(BufferView *, LyXFont const &) const = 0;
37         ///
38         virtual int width(BufferView *, LyXFont const &) const = 0;
39         ///
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;
49
50 public:
51         ///
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;
55         ///
56         virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
57         ///
58         virtual Inset::Code lyxCode() const;
59         /// what appears in the minibuffer when opening
60         virtual string const editMessage() const;
61         ///
62         virtual void edit(BufferView *, int x, int y, mouse_button::state button);
63         ///
64         virtual void edit(BufferView *, bool front = true);
65         ///
66         virtual void fitInsetCursor(BufferView *) const;
67         /// FIXME
68         virtual void getCursorPos(BufferView *, int &, int &) const;
69         /// get the absolute document x,y of the cursor
70         virtual void getCursor(BufferView & bv, int & x, int & y) const;
71         ///
72         virtual void toggleInsetSelection(BufferView * bv);
73         ///
74         virtual void insetUnlock(BufferView *);
75
76         /// To allow transparent use of math editing functions
77         virtual dispatch_result localDispatch(FuncRequest const &);
78         /// To allow transparent use of math editing functions
79         //virtual void status(FuncRequest const &);
80
81         ///
82         virtual std::vector<string> const getLabelList() const;
83         ///
84         virtual MathAtom const & par() const = 0;
85         ///
86         virtual MathAtom & par() = 0;
87         ///
88         // And shouldn't this really return a shared_ptr<BufferView> instead?
89         BufferView * view() const;
90
91         ///
92         virtual bool searchForward(BufferView *, string const &,
93                                    bool = true, bool = false);
94         ///
95         virtual bool searchBackward(BufferView *, string const &,
96                                     bool = true, bool = false);
97         ///
98         virtual bool isTextInset() const { return true; }
99         ///
100         virtual void mutateToText();
101         ///
102         virtual void revealCodes(BufferView *) const;
103         ///
104         virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
105         ///
106         bool display() const;
107         // return the selection as string
108         string selectionAsString() const;
109
110 private:
111         /// unimplemented
112         void operator=(const InsetFormulaBase &);
113         /// common base for handling accents
114         void handleAccent(BufferView * bv, string const & arg, string const & name);
115         /// lfun handler
116         dispatch_result lfunMousePress(FuncRequest const &);
117         ///
118         dispatch_result lfunMouseRelease(FuncRequest const &);
119         ///
120         dispatch_result lfunMouseMotion(FuncRequest const &);
121
122 protected:
123         ///
124         mutable boost::weak_ptr<BufferView> view_;
125         ///
126         mutable LyXFont font_;
127
128 protected:
129         ///
130         void metrics(BufferView * bv, LyXFont const & font) const;
131         ///
132         void metrics(BufferView * bv = 0) const;
133         ///
134         void handleFont(BufferView * bv, string const & arg, string const & font);
135
136         ///
137         mutable int xo_;
138         ///
139         mutable int yo_;
140 };
141
142 // We don't really mess want around with mathed stuff outside mathed.
143 // So do it here.
144 void mathDispatch(FuncRequest const &);
145
146 ///
147 void releaseMathCursor(BufferView * bv);
148
149 #endif