]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.h
enable insertion of spaces in all \textxxx modes.
[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 #include <iosfwd>
27
28 class Buffer;
29 class BufferView;
30 class MathAtom;
31
32 /// An abstract base class for all math related LyX insets
33 class InsetFormulaBase : public UpdatableInset {
34 public:
35         ///
36         InsetFormulaBase();
37         ///
38         virtual int ascent(BufferView *, LyXFont const &) const = 0;
39         ///
40         virtual int descent(BufferView *, LyXFont const &) const = 0;
41         ///
42         virtual int width(BufferView *, LyXFont const &) const = 0;
43         ///
44         virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
45         ///
46         virtual string hullType() const { return "none"; }
47         /// lowest x coordinate
48         virtual int xlow() const;
49         /// highest x coordinate
50         virtual int xhigh() const;
51         /// lowest y coordinate
52         virtual int ylow() const;
53         /// highest y coordinate
54         virtual int yhigh() const;
55
56 public:
57         ///
58         virtual void validate(LaTeXFeatures &) const;
59         ///
60         virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
61         ///
62         virtual Inset::Code lyxCode() const;
63         /// what appears in the minibuffer when opening
64         virtual string const editMessage() const;
65         ///
66         virtual void edit(BufferView *, int x, int y, mouse_button::state button);
67         ///
68         virtual void edit(BufferView *, bool front = true);
69         ///
70         virtual void toggleInsetCursor(BufferView *);
71         ///
72         virtual void showInsetCursor(BufferView *, bool show = true);
73         ///
74         virtual void hideInsetCursor(BufferView *);
75         ///
76         virtual void fitInsetCursor(BufferView *) const;
77         ///
78         virtual void getCursorPos(BufferView *, int &, int &) const;
79         ///
80         virtual void toggleInsetSelection(BufferView * bv);
81         ///
82         virtual void insetButtonPress(BufferView *, int x, int y, mouse_button::state button);
83         ///
84         virtual bool insetButtonRelease(BufferView *, int x, int y, mouse_button::state button);
85         ///
86         virtual void insetMotionNotify(BufferView *, int x, int y, mouse_button::state state);
87         ///
88         virtual void insetUnlock(BufferView *);
89
90         /// To allow transparent use of math editing functions
91         virtual RESULT localDispatch(BufferView *, kb_action, string const &);
92
93         ///
94         virtual std::vector<string> const getLabelList() const;
95         ///
96         virtual MathAtom const & par() const = 0;
97         ///
98         virtual MathAtom & par() = 0;
99         ///
100         virtual void updateLocal(BufferView * bv, bool mark_dirty);
101         ///
102         BufferView * view() const { return view_; }
103
104         ///
105         virtual bool searchForward(BufferView *, string const &,
106                                    bool = true, bool = false);
107         ///
108         virtual bool searchBackward(BufferView *, string const &,
109                                     bool = true, bool = false);
110         ///
111         virtual bool isTextInset() const { return true; }
112         ///
113         virtual void mutateToText();
114         ///
115         virtual void revealCodes(BufferView *) const;
116         ///
117         virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
118         ///
119         virtual void updatePreview() {}
120
121
122 private:
123         /// unimplemented
124         void operator=(const InsetFormulaBase &);
125         /// common base for handling accents
126         void handleAccent(BufferView * bv, string const & arg, string const & name);
127
128 protected:
129         ///
130         mutable BufferView * view_;
131         ///
132         mutable LyXFont font_;
133
134 protected:
135         ///
136         void metrics(BufferView * bv, LyXFont const & font) const;
137         ///
138         void metrics(BufferView * bv = 0) const;
139         ///
140         void handleFont(BufferView * bv, string const & arg, string const & font);
141
142         ///
143         mutable int xo_;
144         ///
145         mutable int yo_;
146 };
147
148 // We don't really mess want around with mathed stuff outside mathed.
149 // So do it here.
150 //
151 void mathDispatchCreation(BufferView *, string const &, bool);
152 //
153 void mathDispatchMathDisplay(BufferView *, string const &);
154 //
155 void mathDispatchMathMode(BufferView *, string const &);
156 //
157 void mathDispatchMathMacro(BufferView *, string const &);
158 //
159 void mathDispatchMathDelim(BufferView *, string const &);
160 //
161 void mathDispatchInsertMath(BufferView *, string const &);
162 //
163 void mathDispatchInsertMatrix(BufferView *, string const &);
164 //
165 void mathDispatchGreek(BufferView *, string const &);
166 //
167 void mathDispatchMathImportSelection(BufferView *, string const &);
168 //
169 void mathDispatch(BufferView *, kb_action, string const &);
170 //
171 void mathDispatch(BufferView *, string const &);
172
173 #endif