]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.h
The "I want this in now" patch.
[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 #include "insets/updatableinset.h"
17 #include "lyxfont.h"
18
19 #include <boost/weak_ptr.hpp>
20 #include <iosfwd>
21
22 class Buffer;
23 class BufferView;
24 class MathAtom;
25
26
27 /// An abstract base class for all math related LyX insets
28 class InsetFormulaBase : public UpdatableInset {
29 public:
30         ///
31         InsetFormulaBase();
32         ///
33         Inset * clone(Buffer const &, bool same_id = false) const = 0;
34         ///
35         virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0;
36         /// lowest x coordinate
37         virtual int xlow() const;
38         /// highest x coordinate
39         virtual int xhigh() const;
40         /// lowest y coordinate
41         virtual int ylow() const;
42         /// highest y coordinate
43         virtual int yhigh() const;
44
45 public:
46         ///
47         // Don't use this for AMS validation as long as there is no
48         // user-accessible way to override "false positives"
49         virtual void validate(LaTeXFeatures &) const;
50         ///
51         virtual Inset::Code lyxCode() const;
52         /// what appears in the minibuffer when opening
53         virtual string const editMessage() const;
54         ///
55         virtual void fitInsetCursor(BufferView *) const;
56         /// FIXME
57         virtual void getCursorPos(BufferView *, int &, int &) const;
58         /// get the absolute document x,y of the cursor
59         virtual void getCursor(BufferView & bv, int & x, int & y) const;
60         ///
61         virtual void toggleInsetSelection(BufferView * bv);
62         ///
63         virtual void insetUnlock(BufferView *);
64
65         /// To allow transparent use of math editing functions
66         virtual dispatch_result localDispatch(FuncRequest const &);
67         /// To allow transparent use of math editing functions
68         //virtual void status(FuncRequest const &);
69
70         ///
71         virtual std::vector<string> const getLabelList() const;
72         ///
73         virtual MathAtom const & par() const = 0;
74         ///
75         virtual MathAtom & par() = 0;
76         ///
77         // And shouldn't this really return a shared_ptr<BufferView> instead?
78         BufferView * view() const;
79
80         ///
81         virtual bool searchForward(BufferView *, string const &,
82                                    bool = true, bool = false);
83         ///
84         virtual bool searchBackward(BufferView *, string const &,
85                                     bool = true, bool = false);
86         ///
87         virtual bool isTextInset() const { return true; }
88         ///
89         virtual void mutateToText();
90         ///
91         virtual void revealCodes(BufferView *) const;
92         ///
93         virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
94         ///
95         bool display() const;
96         // return the selection as string
97         string selectionAsString() const;
98
99 private:
100         /// unimplemented
101         void operator=(const InsetFormulaBase &);
102         /// common base for handling accents
103         void handleAccent(BufferView * bv, string const & arg, string const & name);
104         /// lfun handler
105         dispatch_result lfunMousePress(FuncRequest const &);
106         ///
107         dispatch_result lfunMouseRelease(FuncRequest const &);
108         ///
109         dispatch_result lfunMouseMotion(FuncRequest const &);
110
111 protected:
112         ///
113         mutable boost::weak_ptr<BufferView> view_;
114         ///
115         mutable LyXFont font_;
116
117 protected:
118         ///
119         void metrics(BufferView * bv, LyXFont const & font) const;
120         ///
121         void metrics(BufferView * bv = 0) const;
122         ///
123         void handleFont(BufferView * bv, string const & arg, string const & font);
124
125         ///
126         mutable int xo_;
127         ///
128         mutable int yo_;
129 };
130
131 // We don't really mess want around with mathed stuff outside mathed.
132 // So do it here.
133 void mathDispatch(FuncRequest const &);
134
135 ///
136 void releaseMathCursor(BufferView * bv);
137
138 #endif