]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathHull.h
1e94d6badc13dcbf4ee9019aeb9f17c78ad1c567
[lyx.git] / src / mathed / InsetMathHull.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMathHull.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MATH_HULLINSET_H
13 #define MATH_HULLINSET_H
14
15 #include "InsetMathGrid.h"
16
17 #include "OutputEnums.h"
18
19 #include <boost/scoped_ptr.hpp>
20
21
22 namespace lyx {
23
24 class InsetLabel;
25 class ParConstIterator;
26 class RenderPreview;
27
28
29 /// This provides an interface between "LyX insets" and "LyX math insets"
30 class InsetMathHull : public InsetMathGrid {
31 public:
32         ///
33         InsetMathHull(Buffer * buf);
34         ///
35         InsetMathHull(Buffer * buf, HullType type);
36         ///
37         ~InsetMathHull();
38         ///
39         void setBuffer(Buffer &);
40         ///
41         void updateLabels(ParIterator const &, UpdateType);
42         ///
43         void addToToc(DocIterator const &);
44         ///
45         InsetMathHull & operator=(InsetMathHull const &);
46         ///
47         mode_type currentMode() const;
48         ///
49         void metrics(MetricsInfo & mi, Dimension & dim) const;
50         /// 
51         void drawBackground(PainterInfo & pi, int x, int y) const;
52         ///
53         void draw(PainterInfo &, int x, int y) const;
54         ///
55         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
56         ///
57         void drawT(TextPainter &, int x, int y) const;
58         ///
59         docstring label(row_type row) const;
60         ///
61         void label(row_type row, docstring const & label);
62         ///
63         ColorCode backgroundColor(PainterInfo const &) const;
64         ///
65         void numbered(row_type row, bool num);
66         ///
67         bool numbered(row_type row) const;
68         ///
69         bool numberedType() const;
70         ///
71         bool ams() const;
72         ///
73         void validate(LaTeXFeatures & features) const;
74         /// identifies HullInset
75         InsetMathHull const * asHullInset() const { return this; }
76         /// identifies HullInset
77         InsetMathHull * asHullInset() { return this; }
78
79         /// add a row
80         void addRow(row_type row);
81         /// delete a row
82         void delRow(row_type row);
83         /// swap two rows
84         void swapRow(row_type row);
85         /// add a column
86         void addCol(col_type col);
87         /// delete a column
88         void delCol(col_type col);
89
90         /// get type
91         HullType getType() const;
92         /// change type
93         void mutate(HullType newtype);
94
95         ///
96         int defaultColSpace(col_type col);
97         ///
98         char defaultColAlign(col_type col);
99         ///
100         bool idxFirst(Cursor &) const;
101         ///
102         bool idxLast(Cursor &) const;
103
104         ///
105         void write(WriteStream & os) const;
106         ///
107         void mathmlize(MathStream &) const;
108         ///
109         void normalize(NormalStream &) const;
110         ///
111         void infoize(odocstream & os) const;
112
113         ///
114         void write(std::ostream & os) const;
115         ///
116         void header_write(WriteStream &) const;
117         ///
118         void footer_write(WriteStream &) const;
119         ///
120         void read(Lexer & lex);
121         ///
122         bool readQuiet(Lexer & lex);
123         ///
124         int plaintext(odocstream &, OutputParams const &) const;
125         ///
126         int docbook(odocstream &, OutputParams const &) const;
127         ///
128         docstring xhtml(XHTMLStream &, OutputParams const &) const;
129         /// the string that is passed to the TOC
130         void tocString(odocstream &) const;
131
132         /// get notification when the cursor leaves this inset
133         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
134         ///
135         //bool insetAllowed(InsetCode code) const;
136         ///
137         void addPreview(DocIterator const & inset_pos,
138                 graphics::PreviewLoader &) const;
139         /// Prepare the preview if preview is enabled.
140         void preparePreview(DocIterator const & pos) const;
141         /// Recreates the preview if preview is enabled.
142         void reloadPreview(DocIterator const & pos) const;
143         ///
144         void initUnicodeMath() const;
145
146         ///
147         static int displayMargin() { return 12; }
148         
149         /// Force inset into LTR environment if surroundings are RTL?
150         virtual bool forceLTR() const { return true; }
151
152         ///
153         virtual docstring contextMenu(BufferView const &, int, int) const;
154         ///
155         InsetCode lyxCode() const { return MATH_HULL_CODE; }
156
157 protected:
158         InsetMathHull(InsetMathHull const &);
159
160         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
161
162         /// do we want to handle this event?
163         bool getStatus(Cursor & cur, FuncRequest const & cmd,
164                 FuncStatus & status) const;
165         ///
166         docstring eolString(row_type row, bool fragile) const;
167
168 private:
169         virtual Inset * clone() const;
170         ///
171         void setType(HullType type);
172         ///
173         void validate1(LaTeXFeatures & features);
174         ///
175         docstring nicelabel(row_type row) const;
176         ///
177         void doExtern(Cursor & cur, FuncRequest & func);
178         ///
179         void glueall();
180         /*!
181          * split every row at the first relation operator.
182          * The number of columns must be 1. One column is added.
183          * The first relation operator and everything after it goes to the
184          * second column.
185          */
186         void splitTo2Cols();
187         /*!
188          * split every row at the first relation operator.
189          * The number of columns must be < 3. One or two columns are added.
190          * The first relation operator goes to the second column.
191          * Everything after it goes to the third column.
192          */
193         void splitTo3Cols();
194         /// change number of columns, split or combine columns if necessary.
195         void changeCols(col_type);
196         ///
197         docstring standardFont() const;
198         /// consistency check
199         void check() const;
200         /// can this change its number of rows?
201         bool rowChangeOK() const;
202         /// can this change its number of cols?
203         bool colChangeOK() const;
204
205         /// "none", "simple", "display", "eqnarray",...
206         HullType type_;
207         ///
208         std::vector<bool> nonum_;
209         ///
210         std::vector<InsetLabel *> label_;
211         ///
212         boost::scoped_ptr<RenderPreview> preview_;
213         ///
214         mutable bool use_preview_;
215 //
216 // Incorporate me
217 //
218 public:
219         ///
220         virtual void mutateToText();
221         ///
222         virtual void revealCodes(Cursor & cur) const;
223         ///
224         bool editable() const { return true; }
225         ///
226         void edit(Cursor & cur, bool front, 
227                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
228         ///
229         Inset * editXY(Cursor & cur, int x, int y);
230         ///
231         DisplayType display() const;
232
233 protected:
234         ///
235         void handleFont(Cursor & cur, docstring const & arg,
236                 docstring const & font);
237         ///
238         void handleFont2(Cursor & cur, docstring const & arg);
239         ///
240         bool previewState(BufferView * bv) const;
241 };
242
243
244
245 } // namespace lyx
246 #endif