]> git.lyx.org Git - lyx.git/blob - src/mathed/formulabase.h
small up/down tweaking
[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 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "insets/inset.h"
21 #include "frontends/mouse_state.h"
22 #include "lyxfont.h"
23
24 #include <boost/weak_ptr.hpp>
25 #include <iosfwd>
26
27 class Buffer;
28 class BufferView;
29 class MathAtom;
30
31 /// An abstract base class for all math related LyX insets
32 class InsetFormulaBase : public UpdatableInset {
33 public:
34         ///
35         InsetFormulaBase();
36         ///
37         virtual int ascent(BufferView *, LyXFont const &) const = 0;
38         ///
39         virtual int descent(BufferView *, LyXFont const &) const = 0;
40         ///
41         virtual int width(BufferView *, LyXFont const &) const = 0;
42         ///
43         virtual void draw(BufferView *,LyXFont const &, int, float &, bool) const = 0;
44         /// lowest x coordinate
45         virtual int xlow() const;
46         /// highest x coordinate
47         virtual int xhigh() const;
48         /// lowest y coordinate
49         virtual int ylow() const;
50         /// highest y coordinate
51         virtual int yhigh() const;
52
53 public:
54         ///
55         virtual void validate(LaTeXFeatures &) const;
56         ///
57         virtual Inset * clone(Buffer const &, bool same_id = false) const = 0;
58         ///
59         virtual Inset::Code lyxCode() const;
60         /// what appears in the minibuffer when opening
61         virtual string const editMessage() const;
62         ///
63         virtual void edit(BufferView *, int x, int y, mouse_button::state button);
64         ///
65         virtual void edit(BufferView *, bool front = true);
66         ///
67         virtual void toggleInsetCursor(BufferView *);
68         ///
69         virtual void showInsetCursor(BufferView *, bool show = true);
70         ///
71         virtual void hideInsetCursor(BufferView *);
72         ///
73         virtual void fitInsetCursor(BufferView *) const;
74         ///
75         virtual void getCursorPos(BufferView *, int &, int &) const;
76         ///
77         virtual void toggleInsetSelection(BufferView * bv);
78         ///
79         virtual void insetUnlock(BufferView *);
80
81         /// To allow transparent use of math editing functions
82         virtual RESULT localDispatch(FuncRequest const &);
83         /// To allow transparent use of math editing functions
84         //virtual void status(FuncRequest const &);
85
86         ///
87         virtual std::vector<string> const getLabelList() const;
88         ///
89         virtual MathAtom const & par() const = 0;
90         ///
91         virtual MathAtom & par() = 0;
92         ///
93         virtual void updateLocal(BufferView * bv, bool mark_dirty);
94         ///
95         BufferView * view() const { return view_.get(); }
96
97         ///
98         virtual bool searchForward(BufferView *, string const &,
99                                    bool = true, bool = false);
100         ///
101         virtual bool searchBackward(BufferView *, string const &,
102                                     bool = true, bool = false);
103         ///
104         virtual bool isTextInset() const { return true; }
105         ///
106         virtual void mutateToText();
107         ///
108         virtual void revealCodes(BufferView *) const;
109         ///
110         virtual EDITABLE editable() const { return HIGHLY_EDITABLE; }
111         ///
112         bool display() const;
113         // return the selection as string
114         string selectionAsString() const;
115
116 private:
117         /// unimplemented
118         void operator=(const InsetFormulaBase &);
119         /// common base for handling accents
120         void handleAccent(BufferView * bv, string const & arg, string const & name);
121         /// lfun handler
122         RESULT lfunMousePress(FuncRequest const &);
123         ///
124         RESULT lfunMouseRelease(FuncRequest const &);
125         ///
126         RESULT lfunMouseMotion(FuncRequest const &);
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 ///
153 void releaseMathCursor(BufferView * bv);
154
155 #endif