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