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