]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.h
speed up preview a bit...
[lyx.git] / src / mathed / formulabase.h
1 // -*- C++ -*-
2 /*
3  *  File:        formulabase.h
4  *  Purpose:     Common parts of the math LyX insets
5  *  Author:      André Pönitz
6  *  Created:     May 2001
7  *  Description: Allows the edition of math paragraphs inside Lyx.
8  *
9  *  Copyright: 2001, The LyX Project
10  *
11  *   You are free to use and modify this code under the terms of
12  *   the GNU General Public Licence version 2 or later.
13  */
14
15 #ifndef INSET_FORMULABASE_H
16 #define INSET_FORMULABASE_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "insets/inset.h"
23 #include "frontends/mouse_state.h"
24 #include "lyxfont.h"
25
26 // only for getType():
27 #include "math_defs.h"
28
29 #include <iosfwd>
30
31 class Buffer;
32 class BufferView;
33 class MathAtom;
34
35 /// An abstract base class for all math related LyX insets
36 class InsetFormulaBase : public UpdatableInset {
37 public:
38         ///
39         InsetFormulaBase();
40         ///
41         virtual int ascent(BufferView *, LyXFont const &) const = 0;
42         ///
43         virtual int descent(BufferView *, LyXFont const &) const = 0;
44         ///
45         virtual int width(BufferView *, LyXFont const &) const = 0;
46         ///
47         virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
48         ///
49         virtual MathInsetTypes getType() const = 0;
50         /// lowest x coordinate
51         virtual int xlow() const;
52         /// highest x coordinate
53         virtual int xhigh() const;
54         /// lowest y coordinate
55         virtual int ylow() const;
56         /// highest y coordinate
57         virtual int yhigh() const;
58
59 public:
60         ///
61         virtual void validate(LaTeXFeatures &) const;
62         ///
63         virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
64         ///
65         virtual Inset::Code lyxCode() const;
66         /// what appears in the minibuffer when opening
67         virtual string const editMessage() const;
68         ///
69         virtual void edit(BufferView *, int x, int y, mouse_button::state button);
70         ///
71         virtual void edit(BufferView *, bool front = true);
72         ///
73         virtual void toggleInsetCursor(BufferView *);
74         ///
75         virtual void showInsetCursor(BufferView *, bool show = true);
76         ///
77         virtual void hideInsetCursor(BufferView *);
78         ///
79         virtual void fitInsetCursor(BufferView *) const;
80         ///
81         virtual void getCursorPos(BufferView *, int &, int &) const;
82         ///
83         virtual void toggleInsetSelection(BufferView * bv);
84         ///
85         virtual void insetButtonPress(BufferView *, int x, int y, mouse_button::state button);
86         ///
87         virtual bool insetButtonRelease(BufferView *, int x, int y, mouse_button::state button);
88         ///
89         virtual void insetMotionNotify(BufferView *, int x, int y, mouse_button::state state);
90         ///
91         virtual void insetUnlock(BufferView *);
92
93         /// To allow transparent use of math editing functions
94         virtual RESULT localDispatch(BufferView *, kb_action, string const &);
95
96         ///
97         virtual std::vector<string> const getLabelList() const;
98         ///
99         virtual MathAtom const & par() const = 0;
100         ///
101         virtual MathAtom & par() = 0;
102         ///
103         virtual void updateLocal(BufferView * bv, bool mark_dirty);
104         ///
105         BufferView * view() const { return view_; }
106
107         ///
108         virtual bool searchForward(BufferView *, string const &,
109                                    bool = true, bool = false);
110         ///
111         virtual bool searchBackward(BufferView *, string const &,
112                                     bool = true, bool = false);
113         ///
114         virtual bool isTextInset() const { return true; }
115         ///
116         virtual void mutateToText();
117         ///
118         virtual void revealCodes(BufferView *) const;
119         ///
120         virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
121         ///
122         virtual void updatePreview() {}
123
124
125 private:
126         /// unimplemented
127         void operator=(const InsetFormulaBase &);
128         /// common base for handling accents
129         void handleAccent(BufferView * bv, string const & arg, string const & name);
130
131         ///
132         mutable BufferView * view_;
133         ///
134         mutable LyXFont font_;
135
136 protected:
137         ///
138         void metrics(BufferView * bv, LyXFont const & font) const;
139         ///
140         void metrics(BufferView * bv = 0) const;
141         ///
142         void handleFont(BufferView * bv, string const & arg, string const & font);
143
144         ///
145         mutable int xo_;
146         ///
147         mutable int yo_;
148 };
149
150 // We don't really mess want around with mathed stuff outside mathed.
151 // So do it here.
152 //
153 void mathDispatchCreation(BufferView *, string const &, bool);
154 //
155 void mathDispatchMathDisplay(BufferView *, string const &);
156 //
157 void mathDispatchMathMode(BufferView *, string const &);
158 //
159 void mathDispatchMathMacro(BufferView *, string const &);
160 //
161 void mathDispatchMathDelim(BufferView *, string const &);
162 //
163 void mathDispatchInsertMath(BufferView *, string const &);
164 //
165 void mathDispatchInsertMatrix(BufferView *, string const &);
166 //
167 void mathDispatchGreek(BufferView *, string const &);
168 //
169 void mathDispatchMathImportSelection(BufferView *, string const &);
170 //
171 void mathDispatch(BufferView *, kb_action, string const &);
172 //
173 void mathDispatch(BufferView *, string const &);
174
175 #endif