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>
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 void validate(LaTeXFeatures & features) const;
90 /// identifies HullInset
91 InsetMathHull const * asHullInset() const { return this; }
92 /// identifies HullInset
93 InsetMathHull * asHullInset() { return this; }
96 void addRow(row_type row);
98 void delRow(row_type row);
100 void swapRow(row_type row);
102 void addCol(col_type col);
104 void delCol(col_type col);
107 HullType getType() const;
109 void mutate(HullType newtype);
112 int defaultColSpace(col_type col);
114 char defaultColAlign(col_type col);
116 char displayColAlign(idx_type idx) const;
118 bool idxFirst(Cursor &) const;
120 bool idxLast(Cursor &) const;
123 void write(WriteStream & os) const;
125 void normalize(NormalStream &) const;
127 void infoize(odocstream & os) const;
130 void write(std::ostream & os) const;
132 void header_write(WriteStream &) const;
134 void footer_write(WriteStream &) const;
136 void read(Lexer & lex);
138 bool readQuiet(Lexer & lex);
140 int plaintext(odocstringstream &, OutputParams const &,
141 size_t max_length = INT_MAX) const;
143 int docbook(odocstream &, OutputParams const &) const;
145 docstring xhtml(XHTMLStream &, OutputParams const &) const;
147 void mathmlize(MathStream &) const;
149 void htmlize(HtmlStream &) const;
151 void mathAsLatex(WriteStream &) const;
153 void toString(odocstream &) const;
155 void forOutliner(docstring &, size_t const, bool const) const;
157 /// get notification when the cursor leaves this inset
158 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
160 //bool insetAllowed(InsetCode code) const;
162 void addPreview(DocIterator const & inset_pos,
163 graphics::PreviewLoader &) const;
164 /// Recreates the preview if preview is enabled.
165 void reloadPreview(DocIterator const & pos) const;
167 void usedMacros(MathData const & md, DocIterator const & pos,
168 MacroNameSet & macros, MacroNameSet & defs) const;
170 void initUnicodeMath() const;
173 static int displayMargin() { return 12; }
175 /// Force inset into LTR environment if surroundings are RTL
176 virtual bool forceLTR() const { return true; }
178 void recordLocation(DocIterator const & di);
181 std::string contextMenuName() const;
183 InsetCode lyxCode() const { return MATH_HULL_CODE; }
186 InsetMathHull(InsetMathHull const &);
188 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
190 /// do we want to handle this event?
191 bool getStatus(Cursor & cur, FuncRequest const & cmd,
192 FuncStatus & status) const;
194 docstring eolString(row_type row, bool fragile, bool latex,
195 bool last_eoln) const;
198 virtual Inset * clone() const;
199 /// Prepare the preview if preview is enabled.
200 /// \param forexport: whether this is intended for export
201 /// If so, we ignore LyXRC and wait for the image to be generated.
202 void preparePreview(DocIterator const & pos,
203 bool forexport = false) const;
204 /// like reloadPreview, but forces load
205 /// used by image export
206 void loadPreview(DocIterator const & pos) const;
208 void setType(HullType type);
210 void validate1(LaTeXFeatures & features);
212 docstring nicelabel(row_type row) const;
214 void doExtern(Cursor & cur, FuncRequest & func);
216 void glueall(HullType type);
218 * split every row at the first relation operator.
219 * The number of columns must be 1. One column is added.
220 * The first relation operator and everything after it goes to the
225 * split every row at the first relation operator.
226 * The number of columns must be < 3. One or two columns are added.
227 * The first relation operator goes to the second column.
228 * Everything after it goes to the third column.
231 /// change number of columns, split or combine columns if necessary.
232 void changeCols(col_type);
234 docstring standardFont() const;
236 ColorCode standardColor() const;
237 /// consistency check
239 /// can this change its number of rows?
240 bool rowChangeOK() const;
241 /// can this change its number of cols?
242 bool colChangeOK() const;
243 /// are any of the equations numbered?
244 bool haveNumbers() const;
246 /// "none", "simple", "display", "eqnarray",...
249 std::vector<Numbered> numbered_;
251 std::vector<docstring> numbers_;
253 std::vector<InsetLabel *> label_;
255 boost::scoped_ptr<RenderPreview> preview_;
257 mutable bool use_preview_;
261 typedef std::map<docstring, int> CounterMap;
262 /// used to store current values of important counters
263 CounterMap counter_map;
269 virtual void mutateToText();
271 virtual void revealCodes(Cursor & cur) const;
273 bool editable() const { return true; }
275 void edit(Cursor & cur, bool front,
276 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
278 Inset * editXY(Cursor & cur, int x, int y);
280 DisplayType display() const;
284 void handleFont(Cursor & cur, docstring const & arg,
285 docstring const & font);
287 void handleFont2(Cursor & cur, docstring const & arg);
289 bool previewState(BufferView const * const bv) const;
291 bool previewTooSmall(Dimension const & dim) const;