]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathHull.h
5462acd8ef9ab961ddf053569743e4da0dd00961
[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 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         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);
53         ///
54         void addToToc(DocIterator const & di, bool output_active) const;
55         ///
56         InsetMathHull & operator=(InsetMathHull const &);
57         ///
58         mode_type currentMode() const;
59         ///
60         void metrics(MetricsInfo & mi, Dimension & dim) const;
61         /// 
62         void drawBackground(PainterInfo & pi, int x, int y) const;
63         ///
64         void draw(PainterInfo &, int x, int y) const;
65         ///
66         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
67         ///
68         void drawT(TextPainter &, int x, int y) const;
69         ///
70         docstring label(row_type row) const;
71         ///
72         void label(row_type row, docstring const & label);
73         ///
74         std::vector<InsetLabel *> const & getLabels() { return label_; }
75         ///
76         ColorCode backgroundColor(PainterInfo const &) const;
77         ///
78         void numbered(row_type row, bool num) { numbered(row, num ? NUMBER : NONUMBER); }
79         ///
80         void numbered(row_type row, Numbered num);
81         ///
82         bool numbered(row_type row) const;
83         ///
84         bool numberedType() const;
85         ///
86         bool ams() const;
87         ///
88         void validate(LaTeXFeatures & features) const;
89         /// identifies HullInset
90         InsetMathHull const * asHullInset() const { return this; }
91         /// identifies HullInset
92         InsetMathHull * asHullInset() { return this; }
93
94         /// add a row
95         void addRow(row_type row);
96         /// delete a row
97         void delRow(row_type row);
98         /// swap two rows
99         void swapRow(row_type row);
100         /// add a column
101         void addCol(col_type col);
102         /// delete a column
103         void delCol(col_type col);
104
105         /// get type
106         HullType getType() const;
107         /// change type
108         void mutate(HullType newtype);
109
110         ///
111         int defaultColSpace(col_type col);
112         ///
113         char defaultColAlign(col_type col);
114         ///
115         char displayColAlign(idx_type idx) 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 usedMacros(MathData const & md, DocIterator const & pos,
167                         MacroNameSet & macros, MacroNameSet & defs) const;
168         ///
169         void initUnicodeMath() const;
170
171         ///
172         static int displayMargin() { return 12; }
173         
174         /// Force inset into LTR environment if surroundings are RTL
175         virtual bool forceLTR() const { return true; }
176         ///
177         void recordLocation(DocIterator const & di);
178
179         ///
180         std::string contextMenuName() const;
181         ///
182         InsetCode lyxCode() const { return MATH_HULL_CODE; }
183
184 protected:
185         InsetMathHull(InsetMathHull const &);
186
187         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
188
189         /// do we want to handle this event?
190         bool getStatus(Cursor & cur, FuncRequest const & cmd,
191                 FuncStatus & status) const;
192         ///
193         docstring eolString(row_type row, bool fragile, bool latex,
194                         bool last_eoln) const;
195
196 private:
197         virtual Inset * clone() const;
198         /// Prepare the preview if preview is enabled.
199         /// \param forexport: whether this is intended for export
200         /// If so, we ignore LyXRC and wait for the image to be generated.
201         void preparePreview(DocIterator const & pos,
202                             bool forexport = false) const;
203         /// like reloadPreview, but forces load 
204         /// used by image export
205         void loadPreview(DocIterator const & pos) const;
206         ///
207         void setType(HullType type);
208         ///
209         void validate1(LaTeXFeatures & features);
210         ///
211         docstring nicelabel(row_type row) const;
212         ///
213         void doExtern(Cursor & cur, FuncRequest & func);
214         ///
215         void glueall(HullType type);
216         /*!
217          * split every row at the first relation operator.
218          * The number of columns must be 1. One column is added.
219          * The first relation operator and everything after it goes to the
220          * second column.
221          */
222         void splitTo2Cols();
223         /*!
224          * split every row at the first relation operator.
225          * The number of columns must be < 3. One or two columns are added.
226          * The first relation operator goes to the second column.
227          * Everything after it goes to the third column.
228          */
229         void splitTo3Cols();
230         /// change number of columns, split or combine columns if necessary.
231         void changeCols(col_type);
232         ///
233         docstring standardFont() const;
234         ///
235         ColorCode standardColor() const;
236         /// consistency check
237         void check() const;
238         /// can this change its number of rows?
239         bool rowChangeOK() const;
240         /// can this change its number of cols?
241         bool colChangeOK() const;
242         /// are any of the equations numbered?
243         bool haveNumbers() const;
244
245         /// "none", "simple", "display", "eqnarray",...
246         HullType type_;
247         ///
248         std::vector<Numbered> numbered_;
249         ///
250         std::vector<docstring> numbers_;
251         ///
252         std::vector<InsetLabel *> label_;
253         ///
254         boost::scoped_ptr<RenderPreview> preview_;
255         ///
256         mutable bool use_preview_;
257         ///
258         DocIterator docit_;
259         ///
260         typedef std::map<docstring, int> CounterMap;
261         /// used to store current values of important counters
262         CounterMap counter_map;
263 //
264 // Incorporate me
265 //
266 public:
267         ///
268         virtual void mutateToText();
269         ///
270         virtual void revealCodes(Cursor & cur) const;
271         ///
272         bool editable() const { return true; }
273         ///
274         void edit(Cursor & cur, bool front, 
275                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
276         ///
277         Inset * editXY(Cursor & cur, int x, int y);
278         ///
279         DisplayType display() const;
280
281 protected:
282         ///
283         void handleFont(Cursor & cur, docstring const & arg,
284                 docstring const & font);
285         ///
286         void handleFont2(Cursor & cur, docstring const & arg);
287         ///
288         bool previewState(BufferView const * const bv) const;
289         ///
290         bool previewTooSmall(Dimension const & dim) const;
291 };
292
293
294
295 } // namespace lyx
296 #endif