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