3 * \file InsetMathHull.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef MATH_HULLINSET_H
13 #define MATH_HULLINSET_H
15 #include "InsetMathGrid.h"
17 #include "DocIterator.h"
18 #include "OutputEnums.h"
20 #include "support/unique_ptr.h"
27 class ParConstIterator;
31 /// This provides an interface between "LyX insets" and "LyX math insets"
32 class InsetMathHull : public InsetMathGrid {
34 /// How a line is numbered
36 /// not numbered, LaTeX code \\nonumber if line differs from inset
38 /// numbered, LaTeX code \\number if line differs from inset
40 /// not numbered, LaTeX code \\notag if line differs from inset
44 InsetMathHull(Buffer * buf);
46 InsetMathHull(Buffer * buf, HullType type);
48 virtual ~InsetMathHull();
50 void setBuffer(Buffer &);
52 void updateBuffer(ParIterator const &, UpdateType);
54 void addToToc(DocIterator const & di, bool output_active,
55 UpdateType utype) const;
57 InsetMathHull & operator=(InsetMathHull const &);
59 mode_type currentMode() const;
61 void metrics(MetricsInfo & mi, Dimension & dim) const;
63 void drawBackground(PainterInfo & pi, int x, int y) const;
65 void draw(PainterInfo &, int x, int y) const;
67 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
69 void drawT(TextPainter &, int x, int y) const;
71 docstring label(row_type row) const;
73 void label(row_type row, docstring const & label);
75 std::vector<InsetLabel *> const & getLabels() { return label_; }
77 ColorCode backgroundColor(PainterInfo const &) const;
79 void numbered(row_type row, bool num) { numbered(row, num ? NUMBER : NONUMBER); }
81 void numbered(row_type row, Numbered num);
83 bool numbered(row_type row) const;
85 bool numberedType() const;
89 bool outerDisplay() const;
91 void validate(LaTeXFeatures & features) const;
92 /// identifies HullInset
93 InsetMathHull const * asHullInset() const { return this; }
94 /// identifies HullInset
95 InsetMathHull * asHullInset() { return this; }
98 void addRow(row_type row);
100 void delRow(row_type row);
102 void swapRow(row_type row);
104 void addCol(col_type col);
106 void delCol(col_type col);
109 HullType getType() const;
110 /// is mutation implemented for this type?
111 static bool isMutable(HullType type);
113 void mutate(HullType newtype);
116 int defaultColSpace(col_type col);
118 int displayColSpace(col_type col) const;
120 char defaultColAlign(col_type col);
122 char displayColAlign(idx_type idx) const;
124 bool idxFirst(Cursor &) const;
126 bool idxLast(Cursor &) const;
129 void write(WriteStream & os) const;
131 void normalize(NormalStream &) const;
133 void infoize(odocstream & os) const;
136 void write(std::ostream & os) const;
138 void header_write(WriteStream &) const;
140 void footer_write(WriteStream &) const;
142 void read(Lexer & lex);
144 bool readQuiet(Lexer & lex);
146 int plaintext(odocstringstream &, OutputParams const &,
147 size_t max_length = INT_MAX) const;
149 int docbook(odocstream &, OutputParams const &) const;
151 docstring xhtml(XHTMLStream &, OutputParams const &) const;
153 void mathmlize(MathStream &) const;
155 void htmlize(HtmlStream &) const;
157 void mathAsLatex(WriteStream &) const;
159 void toString(odocstream &) const;
161 void forOutliner(docstring &, size_t const, bool const) const;
163 /// get notification when the cursor leaves this inset
164 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
166 //bool insetAllowed(InsetCode code) const;
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;
173 void usedMacros(MathData const & md, DocIterator const & pos,
174 MacroNameSet & macros, MacroNameSet & defs) const;
176 void initUnicodeMath() const;
179 static int displayMargin() { return 12; }
181 /// Force inset into LTR environment if surroundings are RTL
182 virtual bool forceLTR() const { return true; }
184 void recordLocation(DocIterator const & di);
187 std::string contextMenuName() const;
189 InsetCode lyxCode() const { return MATH_HULL_CODE; }
191 bool canPaintChange(BufferView const &) const;
194 InsetMathHull(InsetMathHull const &);
196 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
198 /// do we want to handle this event?
199 bool getStatus(Cursor & cur, FuncRequest const & cmd,
200 FuncStatus & status) const;
202 docstring eolString(row_type row, bool fragile, bool latex,
203 bool last_eoln) const;
206 virtual Inset * clone() const;
207 /// Prepare the preview if preview is enabled.
208 /// \param forexport: whether this is intended for export
209 /// If so, we ignore LyXRC and wait for the image to be generated.
210 void preparePreview(DocIterator const & pos,
211 bool forexport = false) const;
212 /// like reloadPreview, but forces load
213 /// used by image export
214 void loadPreview(DocIterator const & pos) const;
216 void setType(HullType type);
218 void validate1(LaTeXFeatures & features);
220 docstring nicelabel(row_type row) const;
222 void doExtern(Cursor & cur, FuncRequest & func);
224 void glueall(HullType type);
226 * split every row at the first relation operator.
227 * The number of columns must be 1. One column is added.
228 * The first relation operator and everything after it goes to the
233 * split every row at the first relation operator.
234 * The number of columns must be < 3. One or two columns are added.
235 * The first relation operator goes to the second column.
236 * Everything after it goes to the third column.
239 /// change number of columns, split or combine columns if necessary.
240 void changeCols(col_type);
242 std::string standardFont() const;
244 ColorCode standardColor() const;
245 /// consistency check
247 /// does it understand tabular-feature commands?
248 bool allowsTabularFeatures() const;
249 /// can this change its number of rows?
250 bool rowChangeOK() const;
251 /// can this change its number of cols?
252 bool colChangeOK() const;
253 /// are any of the equations numbered?
254 bool haveNumbers() const;
256 /// "none", "simple", "display", "eqnarray",...
259 std::vector<Numbered> numbered_;
261 std::vector<docstring> numbers_;
263 std::vector<InsetLabel *> label_;
265 unique_ptr<RenderPreview> preview_;
269 typedef std::map<docstring, int> CounterMap;
270 /// used to store current values of important counters
271 CounterMap counter_map;
277 virtual void mutateToText();
279 virtual void revealCodes(Cursor & cur) const;
281 bool editable() const { return true; }
283 void edit(Cursor & cur, bool front,
284 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
286 Inset * editXY(Cursor & cur, int x, int y);
288 DisplayType display() const;
292 void handleFont(Cursor & cur, docstring const & arg,
293 docstring const & font);
295 void handleFont2(Cursor & cur, docstring const & arg);
297 bool previewState(BufferView const * const bv) const;
299 bool previewTooSmall(Dimension const & dim) const;