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