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