]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
2a31b1453fe4828a8bd404f1d54344046fb38471
[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 #include "TextClass.h"
20
21 #include "Box.h"
22 #include "Font.h"
23
24 #include <string>
25
26 namespace lyx {
27
28 class Text;
29 class Paragraph;
30 class CursorSlice;
31 class InsetLayout;
32
33 namespace frontend { class Painter; }
34
35 /** A collapsable text inset
36
37 */
38 class InsetCollapsable : public InsetText {
39 public:
40         ///
41         static int const TEXT_TO_TOP_OFFSET = 2;
42         ///
43         static int const TEXT_TO_BOTTOM_OFFSET = 2;
44         ///
45         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
46         ///
47         InsetCollapsable(InsetCollapsable const & rhs);
48         ///
49         docstring name() const { return from_ascii("Collapsable"); }
50         ///
51         void setLayout(BufferParams const &);
52         ///
53         void read(Buffer const &, Lexer &);
54         ///
55         void write(Buffer const &, std::ostream &) const;
56         ///
57         bool metrics(MetricsInfo &, Dimension &) const;
58         ///
59         void draw(PainterInfo & pi, int x, int y) const;
60         ///
61         void drawSelection(PainterInfo & pi, int x, int y) const;
62         /// return x,y of given position relative to the inset's baseline
63         void cursorPos(BufferView const & bv, CursorSlice const & sl,
64                 bool boundary, int & x, int & y) const;
65         ///
66         bool hitButton(FuncRequest const &) const;
67         ///
68         docstring const getNewLabel(docstring const & l) const;
69         ///
70         EDITABLE editable() const;
71         /// can we go further down on mouse click?
72         bool descendable() const;
73         ///
74         void setLabel(docstring const & l);
75         ///
76         virtual void setButtonLabel() {}
77         ///
78         void setLabelFont(Font const & f);
79         ///
80         bool isOpen() const { return status_ == Open || status_ == Inlined; }
81         ///
82         bool inlined() const { return status_ == Inlined; }
83         ///
84         CollapseStatus status() const;
85         ///
86         bool allowSpellCheck() const { return true; }
87         ///
88         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
89         ///
90         void setStatus(Cursor & cur, CollapseStatus st);
91         ///
92         bool setMouseHover(bool mouse_hover);
93
94 protected:
95         ///
96         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
97         ///
98         Dimension dimensionCollapsed() const;
99         ///
100         Box const & buttonDim() const;
101         ///
102         void edit(Cursor & cur, bool left);
103         ///
104         Inset * editXY(Cursor & cur, int x, int y);
105         ///
106         void setInlined() { status_ = Inlined; }
107         ///
108         docstring floatName(std::string const & type, BufferParams const &) const;
109
110 protected:
111         ///
112         mutable Box button_dim;
113         ///
114         mutable int topx;
115         ///
116         mutable int topbaseline;
117         ///
118         mutable docstring label;
119         ///
120         mutable InsetLayout layout_;
121 private:
122         ///
123         mutable CollapseStatus status_;
124         /// a substatus of the Open status, determined automatically in metrics
125         mutable bool openinlined_;
126         /// the inset will automatically open when the cursor is inside
127         mutable bool autoOpen_;
128         ///
129         mutable Dimension textdim_;
130         /// changes color when mouse enters/leaves this inset
131         bool mouse_hover_;
132 };
133
134 // A helper function that pushes the cursor out of the inset.
135 void leaveInset(Cursor & cur, Inset const & in);
136
137 } // namespace lyx
138
139 #endif