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