]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
This commit fixes a crash when accessing a math inset. This was due to an invalid...
[lyx.git] / src / insets / insetcollapsable.h
1 // -*- C++ -*-
2 /**
3  * \file insetcollapsable.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
16
17 #include "inset.h"
18 #include "insettext.h"
19
20 #include "box.h"
21 #include "lyxfont.h"
22
23 #include <string>
24
25 class LyXText;
26 class Paragraph;
27 class CursorSlice;
28
29 namespace lyx {
30 namespace frontend {
31 class Painter;
32 }
33 }
34
35
36 /** A collapsable text inset
37
38 */
39 class InsetCollapsable : public InsetText {
40 public:
41         ///
42         static int const TEXT_TO_TOP_OFFSET = 2;
43         ///
44         static int const TEXT_TO_BOTTOM_OFFSET = 2;
45         ///
46         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
47         ///
48         void read(Buffer const &, LyXLex &);
49         ///
50         void write(Buffer const &, std::ostream &) const;
51         ///
52         void metrics(MetricsInfo &, Dimension &) const;
53         ///
54         void draw(PainterInfo & pi, int x, int y) const;
55         ///
56         void drawSelection(PainterInfo & pi, int x, int y) const;
57         /// return x,y of given position relative to the inset's baseline
58         void cursorPos(BufferView const & bv, CursorSlice const & sl,
59                 bool boundary, int & x, int & y) const;
60         ///
61         bool hitButton(FuncRequest const &) const;
62         ///
63         lyx::docstring const getNewLabel(lyx::docstring const & l) const;
64         ///
65         EDITABLE editable() const;
66         /// can we go further down on mouse click?
67         bool descendable() const;
68         ///
69         void setLabel(lyx::docstring const & l);
70         ///
71         virtual void setButtonLabel() {}
72         ///
73         void setLabelFont(LyXFont & f);
74         ///
75         bool isOpen() const { return status_ == Open || status_ == Inlined; }
76         ///
77         bool inlined() const { return status_ == Inlined; }
78         ///
79         CollapseStatus status() const;
80         ///
81         bool allowSpellCheck() const { return true; }
82         ///
83         bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
84         ///
85         void setStatus(LCursor & cur, CollapseStatus st);
86
87 protected:
88         ///
89         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
90         ///
91         Dimension dimensionCollapsed() const;
92         ///
93         Box const & buttonDim() const;
94         ///
95         void edit(LCursor & cur, bool left);
96         ///
97         InsetBase * editXY(LCursor & cur, int x, int y);
98         ///
99         void setInlined() { status_ = Inlined; }
100         ///
101         lyx::docstring floatName(std::string const & type, BufferParams const &);
102
103 protected:
104         ///
105         LyXFont labelfont_;
106         ///
107         mutable Box button_dim;
108         ///
109         mutable int topx;
110         ///
111         mutable int topbaseline;
112         ///
113         mutable lyx::docstring label;
114 private:
115         ///
116         mutable CollapseStatus status_;
117         /// a substatus of the Open status, determined automatically in metrics
118         mutable bool openinlined_;
119         /// the inset will automatically open when the cursor is inside
120         mutable bool autoOpen_;
121         ///
122         mutable Dimension textdim_;
123 };
124
125 // A helper function that pushes the cursor out of the inset.
126 void leaveInset(LCursor & cur, InsetBase const & in);
127
128 #endif