]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
* src/paragraph_funcs.cpp (breakParagraph): change parameter 'flag' to
[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         void metrics(MetricsInfo &, Dimension &) const;
58         ///
59         void draw(PainterInfo & pi, int x, int y) const;
60
61         /// return x,y of given position relative to the inset's baseline
62         void cursorPos(BufferView const & bv, CursorSlice const & sl,
63                 bool boundary, int & x, int & y) const;
64         ///
65         bool hitButton(FuncRequest const &) const;
66         ///
67         docstring const getNewLabel(docstring const & l) const;
68         ///
69         EDITABLE editable() const;
70         /// can we go further down on mouse click?
71         bool descendable() const;
72         ///
73         void setLabel(docstring const & l);
74         ///
75         virtual void setButtonLabel() {}
76         ///
77         void setLabelFont(Font const & f);
78         ///
79         bool isOpen() const { return geometry() != ButtonOnly; }
80         ///
81         CollapseStatus status() const;
82         /** Of the old CollapseStatus we only keep the values  
83          *  Open and Collapsed.
84          * We define a list of possible inset decoration
85          * styles, and a list of possible (concrete, visual)
86          * inset geometries. Relationships between them
87          * (geometries in body of table):
88          *
89          *               \       CollapseStatus:
90          *   Decoration:  \ Open                Collapsed
91          *   -------------+-------------------------------
92          *   Classic      | *) TopButton, <--x) ButtonOnly
93          *                | LeftButton
94          *   Minimalistic | ButtonOnly          NoButton
95          *   Conglomerate | SubLabel            Corners
96          *   ---------------------------------------------
97          *   *) toggled by openinlined_
98          *   x) toggled by autoOpen_
99          */
100
101         ///
102         enum Decoration {
103                 Classic,
104                 Minimalistic,
105                 Conglomerate
106         };
107         /// Default looks
108         virtual Decoration decoration() const;
109         ///
110         enum Geometry {
111                 TopButton,
112                 ButtonOnly,
113                 NoButton,
114                 LeftButton,
115                 SubLabel,
116                 Corners
117         };
118         /// Returns the geometry based on CollapseStatus
119         /// (status_), autoOpen_ and openinlined_, and of
120         /// course decoration().
121         Geometry geometry() const;
122         ///
123         bool allowSpellCheck() const { return true; }
124         ///
125         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
126         ///
127         void setStatus(Cursor & cur, CollapseStatus st);
128         ///
129         bool setMouseHover(bool mouse_hover);
130         ///
131         virtual Color_color backgroundColor() const {return layout_.bgcolor; }
132
133         int latex(Buffer const &, odocstream &,
134                   OutputParams const &) const;
135         ///
136         void validate(LaTeXFeatures &) const;
137
138 protected:
139         ///
140         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
141         ///
142         Dimension dimensionCollapsed() const;
143         ///
144         Box const & buttonDim() const;
145         ///
146         void edit(Cursor & cur, bool left);
147         ///
148         Inset * editXY(Cursor & cur, int x, int y);
149         ///
150         docstring floatName(std::string const & type, BufferParams const &) const;
151
152 protected:
153         ///
154         mutable Box button_dim;
155         ///
156         mutable int topx;
157         ///
158         mutable int topbaseline;
159         ///
160         mutable InsetLayout layout_;
161         ///
162         CollapseStatus internalStatus() const { return status_; }
163 private:
164         ///
165         mutable CollapseStatus status_;
166         /// a substatus of the Open status, determined automatically in metrics
167         mutable bool openinlined_;
168         /// the inset will automatically open when the cursor is inside
169         mutable bool autoOpen_;
170         /// changes color when mouse enters/leaves this inset
171         bool mouse_hover_;
172 };
173
174 // A helper function that pushes the cursor out of the inset.
175 void leaveInset(Cursor & cur, Inset const & in);
176
177 } // namespace lyx
178
179 #endif