]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Introduce inset parameters keepempty, freespacing, needprotect and rename verbatim...
[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 allowMultiPar() const;
126         ///
127         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
128         ///
129         void setStatus(Cursor & cur, CollapseStatus st);
130         ///
131         bool setMouseHover(bool mouse_hover);
132         ///
133         virtual Color_color backgroundColor() const {return layout_.bgcolor; }
134
135         int latex(Buffer const &, odocstream &,
136                   OutputParams const &) const;
137         ///
138         void validate(LaTeXFeatures &) const;
139         ///
140         virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
141
142         /// Allow multiple blanks
143         virtual bool isFreeSpacing() const { return layout_.freespacing; }
144         /// Don't eliminate empty paragraphs
145         virtual bool allowEmpty() const { return layout_.keepempty; }
146
147 protected:
148         ///
149         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
150         ///
151         Dimension dimensionCollapsed() const;
152         ///
153         Box const & buttonDim() const;
154         ///
155         void edit(Cursor & cur, bool left);
156         ///
157         Inset * editXY(Cursor & cur, int x, int y);
158         ///
159         docstring floatName(std::string const & type, BufferParams const &) const;
160
161 protected:
162         ///
163         mutable Box button_dim;
164         ///
165         mutable int topx;
166         ///
167         mutable int topbaseline;
168         ///
169         mutable InsetLayout layout_;
170         ///
171         CollapseStatus internalStatus() const { return status_; }
172 private:
173         ///
174         mutable CollapseStatus status_;
175         /// a substatus of the Open status, determined automatically in metrics
176         mutable bool openinlined_;
177         /// the inset will automatically open when the cursor is inside
178         mutable bool autoOpen_;
179         /// changes color when mouse enters/leaves this inset
180         bool mouse_hover_;
181 };
182
183 // A helper function that pushes the cursor out of the inset.
184 void leaveInset(Cursor & cur, Inset const & in);
185
186 } // namespace lyx
187
188 #endif