]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsible.h
0f2711afbae8dfe035a358652566aad512acb717
[lyx.git] / src / insets / InsetCollapsible.h
1 // -*- C++ -*-
2 /**
3  * \file InsetCollapsible.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 INSETCOLLAPSIBLE_H
15 #define INSETCOLLAPSIBLE_H
16
17 #include "InsetText.h"
18
19 #include "Box.h"
20
21 #include "support/unique_ptr.h"
22
23 #include <map>
24
25 namespace lyx {
26
27 class CursorSlice;
28 class InsetLayout;
29
30 enum class InsetDecoration : int;
31
32 namespace support { class TempFile; }
33
34 /** A collapsible text inset
35
36 */
37 class InsetCollapsible : public InsetText {
38 public:
39         ///
40         InsetCollapsible(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
41         ///
42         InsetCollapsible(InsetCollapsible const & rhs);
43         ///
44         InsetCollapsible & operator=(InsetCollapsible const &);
45         ///
46         virtual ~InsetCollapsible();
47         ///
48         InsetCollapsible * asInsetCollapsible() override { return this; }
49         ///
50         InsetCollapsible const * asInsetCollapsible() const override { return this; }
51         ///
52         docstring toolTip(BufferView const & bv, int x, int y) const override;
53         ///
54         docstring layoutName() const override { return from_ascii("Collapsible"); }
55         ///
56         void read(Lexer &) override;
57         ///
58         void write(std::ostream &) const override;
59
60         ///
61         int topOffset(BufferView const * bv) const override;
62         ///
63         int bottomOffset(BufferView const * bv) const override;
64
65         ///
66         void metrics(MetricsInfo &, Dimension &) const override;
67         ///
68         void draw(PainterInfo & pi, int x, int y) const override;
69         ///
70         void drawBackground(PainterInfo &, int, int) const override {}
71
72         /// return x,y of given position relative to the inset's baseline
73         void cursorPos(BufferView const & bv, CursorSlice const & sl,
74                 bool boundary, int & x, int & y) const override;
75         ///
76         docstring const getNewLabel(docstring const & l) const;
77         ///
78         bool editable() const override;
79         ///
80         bool hasSettings() const override { return true; }
81         /// Returns true if coordinates are over the inset's button.
82         /// Always returns false when the inset does not have a
83         /// button.
84         bool clickable(BufferView const & bv, int x, int y) const override;
85         /// can we go further down on mouse click?
86         bool descendable(BufferView const & bv) const override;
87         ///
88         void setLabel(docstring const & l);
89         ///
90         docstring getLabel() const;
91         ///
92         virtual void setButtonLabel() {}
93         ///
94         virtual docstring const buttonLabel(BufferView const &) const;
95         ///
96         bool isOpen(BufferView const & bv) const
97                 { return geometry(bv) != ButtonOnly; }
98         ///
99         enum CollapseStatus {
100                 Collapsed,
101                 Open
102         };
103         ///
104         virtual void setStatus(Cursor & cur, CollapseStatus st);
105         ///
106         CollapseStatus status(BufferView const & bv) const;
107         /** Of the old CollapseStatus we only keep the values
108          *  Open and Collapsed.
109          * We define a list of possible inset decoration
110          * styles, and a list of possible (concrete, visual)
111          * inset geometries. Relationships between them
112          * (geometries in body of table):
113          *
114          *               \       CollapseStatus:
115          *   Decoration:  \ Open                Collapsed
116          *   -------------+-------------------------------
117          *   Classic      | *) TopButton, <--x) ButtonOnly
118          *                | LeftButton
119          *   Minimalistic | NoButton            ButtonOnly
120          *   Conglomerate | SubLabel            Corners
121          *   ---------------------------------------------
122          *   *) toggled by openinlined_
123          *   x) toggled by auto_open_
124          */
125
126         /// Default looks
127         virtual InsetDecoration decoration() const;
128         ///
129         enum Geometry {
130                 TopButton,
131                 ButtonOnly,
132                 NoButton,
133                 LeftButton,
134                 SubLabel,
135                 Corners
136         };
137         /// Returns the geometry based on CollapseStatus
138         /// (status_), auto_open_[BufferView] and openinlined_,
139         /// and of course decoration().
140         Geometry geometry(BufferView const & bv) const;
141         ///
142         bool canPaintChange(BufferView const & bv) const override;
143         ///
144         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
145         ///
146         bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
147         ///
148         ColorCode backgroundColor(PainterInfo const &) const override;
149         ///
150         ColorCode labelColor() const override;
151         ///
152         InsetCode lyxCode() const override { return COLLAPSIBLE_CODE; }
153
154         ///
155         bool usePlainLayout() const override { return true; }
156         ///
157         std::string contextMenu(BufferView const & bv, int x, int y) const override;
158         ///
159         std::string contextMenuName() const override;
160         ///
161         void addToToc(DocIterator const & dit, bool output_active,
162                       UpdateType utype, TocBackend & backend) const override;
163
164 protected:
165         ///
166         void doDispatch(Cursor & cur, FuncRequest & cmd) override;
167         ///
168         void edit(Cursor & cur, bool front,
169                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
170         ///
171         Inset * editXY(Cursor & cur, int x, int y) override;
172         ///
173         mutable CollapseStatus status_;
174         ///
175         unique_ptr<support::TempFile> tempfile_;
176 private:
177         ///
178         Dimension dimensionCollapsed(BufferView const & bv) const;
179         ///
180         docstring labelstring_;
181
182         // These variables depend of the view in which the inset is displayed
183         struct View
184         {
185                 /// The dimension of the inset button
186                 Box button_dim_;
187                 /// a substatus of the Open status, determined automatically in metrics
188                 bool openinlined_;
189                 /// the inset will automatically open when the cursor is inside. This is
190                 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
191                 bool auto_open_;
192                 /// changes color when mouse enters/leaves this inset
193                 bool mouse_hover_;
194         };
195
196         ///
197         mutable std::map<BufferView const *, View> view_;
198 };
199
200 } // namespace lyx
201
202 #endif