]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathHull.h
Avoid crash with cursor down in math
[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 "support/unique_ptr.h"
21
22
23 namespace lyx {
24
25 class InsetLabel;
26 class MacroNameSet;
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         /// How a line is numbered
35         enum Numbered {
36                 /// not numbered, LaTeX code \\nonumber if line differs from inset
37                 NONUMBER,
38                 /// numbered, LaTeX code \\number if line differs from inset
39                 NUMBER,
40                 /// not numbered, LaTeX code \\notag if line differs from inset
41                 NOTAG
42         };
43         ///
44         InsetMathHull(Buffer * buf);
45         ///
46         InsetMathHull(Buffer * buf, HullType type);
47         ///
48         virtual ~InsetMathHull();
49         ///
50         void setBuffer(Buffer &);
51         ///
52         void updateBuffer(ParIterator const &, UpdateType);
53         ///
54         void addToToc(DocIterator const & di, bool output_active,
55                                   UpdateType utype, TocBackend & backend) const;
56         ///
57         InsetMathHull & operator=(InsetMathHull const &);
58         ///
59         mode_type currentMode() const;
60         ///
61         void metrics(MetricsInfo & mi, Dimension & dim) const;
62         ///
63         void drawBackground(PainterInfo & pi, int x, int y) const;
64         ///
65         void draw(PainterInfo &, int x, int y) const;
66         ///
67         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
68         ///
69         void drawT(TextPainter &, int x, int y) const;
70         ///
71         docstring label(row_type row) const;
72         ///
73         void label(row_type row, docstring const & label);
74         ///
75         std::vector<InsetLabel *> const & getLabels() { return label_; }
76         ///
77         ColorCode backgroundColor(PainterInfo const &) const;
78         ///
79         void numbered(row_type row, bool num) { numbered(row, num ? NUMBER : NONUMBER); }
80         ///
81         void numbered(row_type row, Numbered num);
82         ///
83         bool numbered(row_type row) const;
84         ///
85         bool numberedType() const;
86         ///
87         bool ams() const;
88         ///
89         bool outerDisplay() const;
90         ///
91         void validate(LaTeXFeatures & features) const;
92         /// identifies HullInset
93         InsetMathHull const * asHullInset() const { return this; }
94         /// identifies HullInset
95         InsetMathHull * asHullInset() { return this; }
96
97         /// add a row
98         void addRow(row_type row);
99         /// delete a row
100         void delRow(row_type row);
101         /// swap two rows
102         void swapRow(row_type row);
103         /// add a column
104         void addCol(col_type col);
105         /// delete a column
106         void delCol(col_type col);
107
108         /// get type
109         HullType getType() const;
110         /// is mutation implemented for this type?
111         static bool isMutable(HullType type);
112         /// change type
113         void mutate(HullType newtype);
114
115         ///
116         int defaultColSpace(col_type col);
117         ///
118         int displayColSpace(col_type col) const;
119         ///
120         char defaultColAlign(col_type col);
121         ///
122         char displayColAlign(idx_type idx) const;
123         ///
124         bool idxFirst(Cursor &) const;
125         ///
126         bool idxLast(Cursor &) const;
127
128         ///
129         void write(WriteStream & os) const;
130         ///
131         void normalize(NormalStream &) const;
132         ///
133         void infoize(odocstream & os) const;
134
135         ///
136         void write(std::ostream & os) const;
137         ///
138         void header_write(WriteStream &) const;
139         ///
140         void footer_write(WriteStream &) const;
141         ///
142         void read(Lexer & lex);
143         ///
144         bool readQuiet(Lexer & lex);
145         ///
146         int plaintext(odocstringstream &, OutputParams const &,
147                       size_t max_length = INT_MAX) const;
148         ///
149         int docbook(odocstream &, OutputParams const &) const;
150         ///
151         docstring xhtml(XHTMLStream &, OutputParams const &) const;
152         ///
153         void mathmlize(MathStream &) const;
154         ///
155         void htmlize(HtmlStream &) const;
156         ///
157         void mathAsLatex(WriteStream &) const;
158         ///
159         void toString(odocstream &) const;
160         ///
161         void forOutliner(docstring &, size_t const, bool const) const;
162
163         /// get notification when the cursor leaves this inset
164         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
165         ///
166         //bool insetAllowed(InsetCode code) const;
167         ///
168         void addPreview(DocIterator const & inset_pos,
169                 graphics::PreviewLoader &) const;
170         /// Recreates the preview if preview is enabled.
171         void reloadPreview(DocIterator const & pos) const;
172         ///
173         void usedMacros(MathData const & md, DocIterator const & pos,
174                         MacroNameSet & macros, MacroNameSet & defs) const;
175         ///
176         void initUnicodeMath() const;
177
178         ///
179         static int displayMargin() { return 12; }
180
181         /// Force inset into LTR environment if surroundings are RTL
182         virtual bool forceLTR() const { return true; }
183         ///
184         void recordLocation(DocIterator const & di);
185
186         ///
187         std::string contextMenuName() const;
188         ///
189         InsetCode lyxCode() const { return MATH_HULL_CODE; }
190         ///
191         bool canPaintChange(BufferView const &) const;
192         ///
193         bool confirmDeletion() const { return nargs() != 1 || !cell(0).empty(); }
194
195 protected:
196         InsetMathHull(InsetMathHull const &);
197
198         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
199
200         /// do we want to handle this event?
201         bool getStatus(Cursor & cur, FuncRequest const & cmd,
202                 FuncStatus & status) const;
203         /// override to set to 0 for inline equation
204         int leftMargin() const;
205         /// override to set to 0 for inline equation
206         int rightMargin() const;
207         /// override to set to 0 for inline equation
208         int border() const;
209         ///
210         docstring eolString(row_type row, bool fragile, bool latex,
211                         bool last_eoln) const;
212
213 private:
214         virtual Inset * clone() const;
215         /// Prepare the preview if preview is enabled.
216         /// \param forexport: whether this is intended for export
217         /// If so, we ignore LyXRC and wait for the image to be generated.
218         void preparePreview(DocIterator const & pos,
219                             bool forexport = false) const;
220         /// like reloadPreview, but forces load
221         /// used by image export
222         void loadPreview(DocIterator const & pos) const;
223         ///
224         void setType(HullType type);
225         ///
226         void validate1(LaTeXFeatures & features);
227         ///
228         docstring nicelabel(row_type row) const;
229         ///
230         void doExtern(Cursor & cur, FuncRequest & func);
231         ///
232         void glueall(HullType type);
233         /*!
234          * split every row at the first relation operator.
235          * The number of columns must be 1. One column is added.
236          * The first relation operator and everything after it goes to the
237          * second column.
238          */
239         void splitTo2Cols();
240         /*!
241          * split every row at the first relation operator.
242          * The number of columns must be < 3. One or two columns are added.
243          * The first relation operator goes to the second column.
244          * Everything after it goes to the third column.
245          */
246         void splitTo3Cols();
247         /// change number of columns, split or combine columns if necessary.
248         void changeCols(col_type);
249         ///
250         std::string standardFont() const;
251         ///
252         ColorCode standardColor() const;
253         /// consistency check
254         void check() const;
255         /// does it understand tabular-feature commands?
256         bool allowsTabularFeatures() const;
257         /// can this change its number of rows?
258         bool rowChangeOK() const;
259         /// can this change its number of cols?
260         bool colChangeOK() const;
261         /// are any of the equations numbered?
262         bool haveNumbers() const;
263         /// draw four angular markers
264         virtual void drawMarkers(PainterInfo & pi, int x, int y) const;
265
266         /// "none", "simple", "display", "eqnarray",...
267         HullType type_;
268         ///
269         std::vector<Numbered> numbered_;
270         ///
271         std::vector<docstring> numbers_;
272         ///
273         std::vector<InsetLabel *> label_;
274         ///
275         unique_ptr<RenderPreview> preview_;
276         ///
277         DocIterator docit_;
278         ///
279         typedef std::map<docstring, int> CounterMap;
280         /// used to store current values of important counters
281         CounterMap counter_map;
282 //
283 // Incorporate me
284 //
285 public:
286         ///
287         virtual void mutateToText();
288         ///
289         virtual void revealCodes(Cursor & cur) const;
290         ///
291         bool editable() const { return true; }
292         ///
293         void edit(Cursor & cur, bool front,
294                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
295         ///
296         Inset * editXY(Cursor & cur, int x, int y);
297         ///
298         DisplayType display() const;
299         ///
300         int indent(BufferView const &) const;
301
302 protected:
303         ///
304         void handleFont(Cursor & cur, docstring const & arg,
305                 docstring const & font);
306         ///
307         void handleFont2(Cursor & cur, docstring const & arg);
308         ///
309         bool previewState(BufferView const * const bv) const;
310         ///
311         bool previewTooSmall(Dimension const & dim) const;
312 };
313
314
315
316 } // namespace lyx
317 #endif