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