]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathHull.h
support for the LaTeX commands \x***arrow
[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 <boost/scoped_ptr.hpp>
21
22
23 namespace lyx {
24
25 class InsetLabel;
26 class ParConstIterator;
27 class RenderPreview;
28
29
30 /// This provides an interface between "LyX insets" and "LyX math insets"
31 class InsetMathHull : public InsetMathGrid {
32 public:
33         /// How a line is numbered
34         enum Numbered {
35                 /// not numbered, LaTeX code \\nonumber if line differs from inset
36                 NONUMBER,
37                 /// numbered, LaTeX code \\number if line differs from inset
38                 NUMBER,
39                 /// not numbered, LaTeX code \\notag if line differs from inset
40                 NOTAG
41         };
42         ///
43         InsetMathHull(Buffer * buf);
44         ///
45         InsetMathHull(Buffer * buf, HullType type);
46         ///
47         virtual ~InsetMathHull();
48         ///
49         void setBuffer(Buffer &);
50         ///
51         void updateBuffer(ParIterator const &, UpdateType);
52         ///
53         void addToToc(DocIterator const & di, bool output_active) const;
54         ///
55         InsetMathHull & operator=(InsetMathHull const &);
56         ///
57         mode_type currentMode() const;
58         ///
59         void metrics(MetricsInfo & mi, Dimension & dim) const;
60         /// 
61         void drawBackground(PainterInfo & pi, int x, int y) const;
62         ///
63         void draw(PainterInfo &, int x, int y) const;
64         ///
65         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
66         ///
67         void drawT(TextPainter &, int x, int y) const;
68         ///
69         docstring label(row_type row) const;
70         ///
71         void label(row_type row, docstring const & label);
72         ///
73         std::vector<InsetLabel *> const & getLabels() { return label_; }
74         ///
75         ColorCode backgroundColor(PainterInfo const &) const;
76         ///
77         void numbered(row_type row, bool num) { numbered(row, num ? NUMBER : NONUMBER); }
78         ///
79         void numbered(row_type row, Numbered num);
80         ///
81         bool numbered(row_type row) const;
82         ///
83         bool numberedType() const;
84         ///
85         bool ams() const;
86         ///
87         void validate(LaTeXFeatures & features) const;
88         /// identifies HullInset
89         InsetMathHull const * asHullInset() const { return this; }
90         /// identifies HullInset
91         InsetMathHull * asHullInset() { return this; }
92
93         /// add a row
94         void addRow(row_type row);
95         /// delete a row
96         void delRow(row_type row);
97         /// swap two rows
98         void swapRow(row_type row);
99         /// add a column
100         void addCol(col_type col);
101         /// delete a column
102         void delCol(col_type col);
103
104         /// get type
105         HullType getType() const;
106         /// change type
107         void mutate(HullType newtype);
108
109         ///
110         int defaultColSpace(col_type col);
111         ///
112         char defaultColAlign(col_type col);
113         ///
114         ///
115         char displayColAlign(col_type col, row_type row) const;
116         ///
117         bool idxFirst(Cursor &) const;
118         ///
119         bool idxLast(Cursor &) const;
120
121         ///
122         void write(WriteStream & os) const;
123         ///
124         void normalize(NormalStream &) const;
125         ///
126         void infoize(odocstream & os) const;
127
128         ///
129         void write(std::ostream & os) const;
130         ///
131         void header_write(WriteStream &) const;
132         ///
133         void footer_write(WriteStream &) const;
134         ///
135         void read(Lexer & lex);
136         ///
137         bool readQuiet(Lexer & lex);
138         ///
139         int plaintext(odocstringstream &, OutputParams const &, 
140                       size_t max_length = INT_MAX) const;
141         ///
142         int docbook(odocstream &, OutputParams const &) const;
143         ///
144         docstring xhtml(XHTMLStream &, OutputParams const &) const;
145         ///
146         void mathmlize(MathStream &) const;
147         ///
148         void htmlize(HtmlStream &) const;
149         ///
150         void mathAsLatex(WriteStream &) const;
151         /// 
152         void toString(odocstream &) const;
153         ///
154         void forOutliner(docstring &, size_t) const;
155
156         /// get notification when the cursor leaves this inset
157         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
158         ///
159         //bool insetAllowed(InsetCode code) const;
160         ///
161         void addPreview(DocIterator const & inset_pos,
162                 graphics::PreviewLoader &) const;
163         /// Recreates the preview if preview is enabled.
164         void reloadPreview(DocIterator const & pos) const;
165         ///
166         void initUnicodeMath() const;
167
168         ///
169         static int displayMargin() { return 12; }
170         
171         /// Force inset into LTR environment if surroundings are RTL
172         virtual bool forceLTR() const { return true; }
173         ///
174         void recordLocation(DocIterator const & di);
175
176         ///
177         std::string contextMenuName() const;
178         ///
179         InsetCode lyxCode() const { return MATH_HULL_CODE; }
180
181 protected:
182         InsetMathHull(InsetMathHull const &);
183
184         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
185
186         /// do we want to handle this event?
187         bool getStatus(Cursor & cur, FuncRequest const & cmd,
188                 FuncStatus & status) const;
189         ///
190         docstring eolString(row_type row, bool fragile, bool latex,
191                         bool last_eoln) const;
192
193 private:
194         virtual Inset * clone() const;
195         /// Prepare the preview if preview is enabled.
196         /// \param forexport: whether this is intended for export
197         /// If so, we ignore LyXRC and wait for the image to be generated.
198         void preparePreview(DocIterator const & pos,
199                             bool forexport = false) const;
200         /// like reloadPreview, but forces load 
201         /// used by image export
202         void loadPreview(DocIterator const & pos) const;
203         ///
204         void setType(HullType type);
205         ///
206         void validate1(LaTeXFeatures & features);
207         ///
208         docstring nicelabel(row_type row) const;
209         ///
210         void doExtern(Cursor & cur, FuncRequest & func);
211         ///
212         void glueall(HullType type);
213         /*!
214          * split every row at the first relation operator.
215          * The number of columns must be 1. One column is added.
216          * The first relation operator and everything after it goes to the
217          * second column.
218          */
219         void splitTo2Cols();
220         /*!
221          * split every row at the first relation operator.
222          * The number of columns must be < 3. One or two columns are added.
223          * The first relation operator goes to the second column.
224          * Everything after it goes to the third column.
225          */
226         void splitTo3Cols();
227         /// change number of columns, split or combine columns if necessary.
228         void changeCols(col_type);
229         ///
230         docstring standardFont() const;
231         ///
232         ColorCode standardColor() const;
233         /// consistency check
234         void check() const;
235         /// can this change its number of rows?
236         bool rowChangeOK() const;
237         /// can this change its number of cols?
238         bool colChangeOK() const;
239         /// are any of the equations numbered?
240         bool haveNumbers() const;
241
242         /// "none", "simple", "display", "eqnarray",...
243         HullType type_;
244         ///
245         std::vector<Numbered> numbered_;
246         ///
247         std::vector<docstring> numbers_;
248         ///
249         std::vector<InsetLabel *> label_;
250         ///
251         boost::scoped_ptr<RenderPreview> preview_;
252         ///
253         mutable bool use_preview_;
254         ///
255         DocIterator docit_;
256         ///
257         typedef std::map<docstring, int> CounterMap;
258         /// used to store current values of important counters
259         CounterMap counter_map;
260 //
261 // Incorporate me
262 //
263 public:
264         ///
265         virtual void mutateToText();
266         ///
267         virtual void revealCodes(Cursor & cur) const;
268         ///
269         bool editable() const { return true; }
270         ///
271         void edit(Cursor & cur, bool front, 
272                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
273         ///
274         Inset * editXY(Cursor & cur, int x, int y);
275         ///
276         DisplayType display() const;
277
278 protected:
279         ///
280         void handleFont(Cursor & cur, docstring const & arg,
281                 docstring const & font);
282         ///
283         void handleFont2(Cursor & cur, docstring const & arg);
284         ///
285         bool previewState(BufferView const * const bv) const;
286         ///
287         bool previewTooSmall(Dimension const & dim) const;
288 };
289
290
291
292 } // namespace lyx
293 #endif