]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.h
streamlining interaction mathed <-> rest of the world
[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 #include <iosfwd>
28
29 class Buffer;
30 class BufferView;
31 class MathAtom;
32
33 /// An abstract base class for all math related LyX insets
34 class InsetFormulaBase : public UpdatableInset {
35 public:
36         ///
37         InsetFormulaBase();
38         ///
39         virtual int ascent(BufferView *, LyXFont const &) const = 0;
40         ///
41         virtual int descent(BufferView *, LyXFont const &) const = 0;
42         ///
43         virtual int width(BufferView *, LyXFont const &) const = 0;
44         ///
45         virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
46         /// lowest x coordinate
47         virtual int xlow() const;
48         /// highest x coordinate
49         virtual int xhigh() const;
50         /// lowest y coordinate
51         virtual int ylow() const;
52         /// highest y coordinate
53         virtual int yhigh() const;
54
55 public:
56         ///
57         virtual void validate(LaTeXFeatures &) const;
58         ///
59         virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
60         ///
61         virtual Inset::Code lyxCode() const;
62         /// what appears in the minibuffer when opening
63         virtual string const editMessage() const;
64         ///
65         virtual void edit(BufferView *, int x, int y, mouse_button::state button);
66         ///
67         virtual void edit(BufferView *, bool front = true);
68         ///
69         virtual void toggleInsetCursor(BufferView *);
70         ///
71         virtual void showInsetCursor(BufferView *, bool show = true);
72         ///
73         virtual void hideInsetCursor(BufferView *);
74         ///
75         virtual void fitInsetCursor(BufferView *) const;
76         ///
77         virtual void getCursorPos(BufferView *, int &, int &) const;
78         ///
79         virtual void toggleInsetSelection(BufferView * bv);
80         ///
81         virtual void insetButtonPress(BufferView *, int x, int y, mouse_button::state button);
82         ///
83         virtual bool insetButtonRelease(BufferView *, int x, int y, mouse_button::state button);
84         ///
85         virtual void insetMotionNotify(BufferView *, int x, int y, mouse_button::state state);
86         ///
87         virtual void insetUnlock(BufferView *);
88
89         /// To allow transparent use of math editing functions
90         virtual RESULT localDispatch(FuncRequest const &);
91         /// To allow transparent use of math editing functions
92         //virtual void status(FuncRequest const &);
93
94         ///
95         virtual std::vector<string> const getLabelList() const;
96         ///
97         virtual MathAtom const & par() const = 0;
98         ///
99         virtual MathAtom & par() = 0;
100         ///
101         virtual void updateLocal(BufferView * bv, bool mark_dirty);
102         ///
103         BufferView * view() const { return view_.get(); }
104
105         ///
106         virtual bool searchForward(BufferView *, string const &,
107                                    bool = true, bool = false);
108         ///
109         virtual bool searchBackward(BufferView *, string const &,
110                                     bool = true, bool = false);
111         ///
112         virtual bool isTextInset() const { return true; }
113         ///
114         virtual void mutateToText();
115         ///
116         virtual void revealCodes(BufferView *) const;
117         ///
118         virtual Inset::EDITABLE editable() const { return HIGHLY_EDITABLE; }
119         ///
120         bool display() const;
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 boost::weak_ptr<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 void mathDispatch(FuncRequest const &);
151
152 #endif