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