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 <boost/scoped_ptr.hpp>
26 class ParConstIterator;
30 /// This provides an interface between "LyX insets" and "LyX math insets"
31 class InsetMathHull : public InsetMathGrid {
33 /// How a line is numbered
35 /// not numbered, LaTeX code \\nonumber if line differs from inset
37 /// numbered, LaTeX code \\number if line differs from inset
39 /// not numbered, LaTeX code \\notag if line differs from inset
43 InsetMathHull(Buffer * buf);
45 InsetMathHull(Buffer * buf, HullType type);
47 virtual ~InsetMathHull();
49 void setBuffer(Buffer &);
51 void updateBuffer(ParIterator const &, UpdateType);
53 void addToToc(DocIterator const & di, bool output_active) const;
55 InsetMathHull & operator=(InsetMathHull const &);
57 mode_type currentMode() const;
59 void metrics(MetricsInfo & mi, Dimension & dim) const;
61 void drawBackground(PainterInfo & pi, int x, int y) const;
63 void draw(PainterInfo &, int x, int y) const;
65 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
67 void drawT(TextPainter &, int x, int y) const;
69 docstring label(row_type row) const;
71 void label(row_type row, docstring const & label);
73 std::vector<InsetLabel *> const & getLabels() { return label_; }
75 ColorCode backgroundColor(PainterInfo const &) const;
77 void numbered(row_type row, bool num) { numbered(row, num ? NUMBER : NONUMBER); }
79 void numbered(row_type row, Numbered num);
81 bool numbered(row_type row) const;
83 bool numberedType() const;
87 void validate(LaTeXFeatures & features) const;
88 /// identifies HullInset
89 InsetMathHull const * asHullInset() const { return this; }
90 /// identifies HullInset
91 InsetMathHull * asHullInset() { return this; }
94 void addRow(row_type row);
96 void delRow(row_type row);
98 void swapRow(row_type row);
100 void addCol(col_type col);
102 void delCol(col_type col);
105 HullType getType() const;
107 void mutate(HullType newtype);
110 int defaultColSpace(col_type col);
112 char defaultColAlign(col_type col);
114 char displayColAlign(idx_type idx) const;
116 bool idxFirst(Cursor &) const;
118 bool idxLast(Cursor &) const;
121 void write(WriteStream & os) const;
123 void normalize(NormalStream &) const;
125 void infoize(odocstream & os) const;
128 void write(std::ostream & os) const;
130 void header_write(WriteStream &) const;
132 void footer_write(WriteStream &) const;
134 void read(Lexer & lex);
136 bool readQuiet(Lexer & lex);
138 int plaintext(odocstringstream &, OutputParams const &,
139 size_t max_length = INT_MAX) const;
141 int docbook(odocstream &, OutputParams const &) const;
143 docstring xhtml(XHTMLStream &, OutputParams const &) const;
145 void mathmlize(MathStream &) const;
147 void htmlize(HtmlStream &) const;
149 void mathAsLatex(WriteStream &) const;
151 void toString(odocstream &) const;
153 void forOutliner(docstring &, size_t) const;
155 /// get notification when the cursor leaves this inset
156 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
158 //bool insetAllowed(InsetCode code) const;
160 void addPreview(DocIterator const & inset_pos,
161 graphics::PreviewLoader &) const;
162 /// Recreates the preview if preview is enabled.
163 void reloadPreview(DocIterator const & pos) const;
165 void initUnicodeMath() const;
168 static int displayMargin() { return 12; }
170 /// Force inset into LTR environment if surroundings are RTL
171 virtual bool forceLTR() const { return true; }
173 void recordLocation(DocIterator const & di);
176 std::string contextMenuName() const;
178 InsetCode lyxCode() const { return MATH_HULL_CODE; }
181 InsetMathHull(InsetMathHull const &);
183 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
185 /// do we want to handle this event?
186 bool getStatus(Cursor & cur, FuncRequest const & cmd,
187 FuncStatus & status) const;
189 docstring eolString(row_type row, bool fragile, bool latex,
190 bool last_eoln) const;
193 virtual Inset * clone() const;
194 /// Prepare the preview if preview is enabled.
195 /// \param forexport: whether this is intended for export
196 /// If so, we ignore LyXRC and wait for the image to be generated.
197 void preparePreview(DocIterator const & pos,
198 bool forexport = false) const;
199 /// like reloadPreview, but forces load
200 /// used by image export
201 void loadPreview(DocIterator const & pos) const;
203 void setType(HullType type);
205 void validate1(LaTeXFeatures & features);
207 docstring nicelabel(row_type row) const;
209 void doExtern(Cursor & cur, FuncRequest & func);
211 void glueall(HullType type);
213 * split every row at the first relation operator.
214 * The number of columns must be 1. One column is added.
215 * The first relation operator and everything after it goes to the
220 * split every row at the first relation operator.
221 * The number of columns must be < 3. One or two columns are added.
222 * The first relation operator goes to the second column.
223 * Everything after it goes to the third column.
226 /// change number of columns, split or combine columns if necessary.
227 void changeCols(col_type);
229 docstring standardFont() const;
231 ColorCode standardColor() const;
232 /// consistency check
234 /// can this change its number of rows?
235 bool rowChangeOK() const;
236 /// can this change its number of cols?
237 bool colChangeOK() const;
238 /// are any of the equations numbered?
239 bool haveNumbers() const;
241 /// "none", "simple", "display", "eqnarray",...
244 std::vector<Numbered> numbered_;
246 std::vector<docstring> numbers_;
248 std::vector<InsetLabel *> label_;
250 boost::scoped_ptr<RenderPreview> preview_;
252 mutable bool use_preview_;
256 typedef std::map<docstring, int> CounterMap;
257 /// used to store current values of important counters
258 CounterMap counter_map;
264 virtual void mutateToText();
266 virtual void revealCodes(Cursor & cur) const;
268 bool editable() const { return true; }
270 void edit(Cursor & cur, bool front,
271 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
273 Inset * editXY(Cursor & cur, int x, int y);
275 DisplayType display() const;
279 void handleFont(Cursor & cur, docstring const & arg,
280 docstring const & font);
282 void handleFont2(Cursor & cur, docstring const & arg);
284 bool previewState(BufferView const * const bv) const;
286 bool previewTooSmall(Dimension const & dim) const;