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