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