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