]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Set up decoration handling for all collapsable insets
[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 = Inset::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 geometry() != ButtonOnly; }
81         ///
82         bool inlined() const { return decoration() == Minimalistic|| decoration() == Conglomerate; }
83         ///
84         CollapseStatus status() const;
85         /** Of the old CollapseStatus we only keep the values  
86          *  Open and Collapsed.
87          * We define a list of possible inset decoration
88          * styles, and a list of possible (concrete, visual)
89          * inset geometries. Relationships between them
90          * (geometries in body of table):
91          *
92          *               \       CollapseStatus:
93          *   Decoration:  \ Open                Collapsed
94          *   -------------+-------------------------------
95          *   Classic      | *) TopButton, <--x) ButtonOnly
96          *                | LeftButton
97          *   Minimalistic | NoButton            NoButton
98          *   Conglomerate | SubLabel            Corners
99          *   ---------------------------------------------
100          *   *) toggled by openinlined_
101          *   x) toggled by autoOpen_
102          */
103
104         ///
105         enum Decoration {
106                 Classic,
107                 Minimalistic,
108                 Conglomerate
109         };
110         /// Default looks
111         virtual Decoration decoration() const;
112         ///
113         enum Geometry {
114                 TopButton,
115                 ButtonOnly,
116                 NoButton,
117                 LeftButton,
118                 SubLabel,
119                 Corners
120         };
121         /// Returns the geometry based on CollapseStatus
122         /// (status_), autoOpen_ and openinlined_, and of
123         /// course decoration().
124         Geometry geometry() const;
125         ///
126         bool allowSpellCheck() const { return true; }
127         ///
128         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
129         ///
130         void setStatus(Cursor & cur, CollapseStatus st);
131         ///
132         bool setMouseHover(bool mouse_hover);
133         ///
134         int latex(Buffer const &, odocstream &,
135                   OutputParams const &) const;
136         ///
137         void validate(LaTeXFeatures &) const;
138
139 protected:
140         ///
141         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
142         ///
143         Dimension dimensionCollapsed() const;
144         ///
145         Box const & buttonDim() const;
146         ///
147         void edit(Cursor & cur, bool left);
148         ///
149         Inset * editXY(Cursor & cur, int x, int y);
150         ///
151         docstring floatName(std::string const & type, BufferParams const &) const;
152
153 protected:
154         ///
155         mutable Box button_dim;
156         ///
157         mutable int topx;
158         ///
159         mutable int topbaseline;
160         ///
161         mutable InsetLayout layout_;
162         ///
163         CollapseStatus internalStatus() const { return status_; }
164 private:
165         ///
166         mutable CollapseStatus status_;
167         /// a substatus of the Open status, determined automatically in metrics
168         mutable bool openinlined_;
169         /// the inset will automatically open when the cursor is inside
170         mutable bool autoOpen_;
171         ///
172         mutable Dimension textdim_;
173         /// changes color when mouse enters/leaves this inset
174         bool mouse_hover_;
175 };
176
177 // A helper function that pushes the cursor out of the inset.
178 void leaveInset(Cursor & cur, Inset const & in);
179
180 } // namespace lyx
181
182 #endif