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