]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Remove redundant code and introduce InsetCollapsable::setLabelColor().
[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
23 #include <string>
24
25 namespace lyx {
26
27 class CursorSlice;
28 class FontInfo;
29 class InsetLayout;
30 class Paragraph;
31 class Text;
32
33 namespace frontend { class Painter; }
34
35 /** A collapsable text inset
36
37 */
38 class InsetCollapsable : public InsetText {
39 public:
40         ///
41         InsetCollapsable(BufferParams const &, CollapseStatus status = Inset::Open);
42         ///
43         InsetCollapsable(InsetCollapsable const & rhs);
44         ///
45         docstring name() const { return from_ascii("Collapsable"); }
46         ///
47         void setLayout(BufferParams const &);
48         ///
49         void read(Buffer const &, Lexer &);
50         ///
51         void write(Buffer const &, std::ostream &) const;
52         ///
53         void metrics(MetricsInfo &, Dimension &) const;
54         ///
55         void draw(PainterInfo & pi, int x, int y) const;
56
57         /// return x,y of given position relative to the inset's baseline
58         void cursorPos(BufferView const & bv, CursorSlice const & sl,
59                 bool boundary, int & x, int & y) const;
60         ///
61         bool hitButton(FuncRequest const &) const;
62         ///
63         docstring const getNewLabel(docstring const & l) const;
64         ///
65         EDITABLE editable() const;
66         /// can we go further down on mouse click?
67         bool descendable() const;
68         ///
69         void setLabel(docstring const & l);
70         ///
71         virtual void setButtonLabel() {}
72         ///
73         void setLabelFont(FontInfo const & f);
74         ///
75         void setLabelColor(ColorCode code);
76         ///
77         bool isOpen() const { return geometry() != ButtonOnly; }
78         ///
79         CollapseStatus status() const;
80         /** Of the old CollapseStatus we only keep the values  
81          *  Open and Collapsed.
82          * We define a list of possible inset decoration
83          * styles, and a list of possible (concrete, visual)
84          * inset geometries. Relationships between them
85          * (geometries in body of table):
86          *
87          *               \       CollapseStatus:
88          *   Decoration:  \ Open                Collapsed
89          *   -------------+-------------------------------
90          *   Classic      | *) TopButton, <--x) ButtonOnly
91          *                | LeftButton
92          *   Minimalistic | ButtonOnly          NoButton
93          *   Conglomerate | SubLabel            Corners
94          *   ---------------------------------------------
95          *   *) toggled by openinlined_
96          *   x) toggled by autoOpen_
97          */
98
99         ///
100         enum Decoration {
101                 Classic,
102                 Minimalistic,
103                 Conglomerate
104         };
105         /// Default looks
106         virtual Decoration decoration() const;
107         ///
108         enum Geometry {
109                 TopButton,
110                 ButtonOnly,
111                 NoButton,
112                 LeftButton,
113                 SubLabel,
114                 Corners
115         };
116         /// Returns the geometry based on CollapseStatus
117         /// (status_), autoOpen_ and openinlined_, and of
118         /// course decoration().
119         Geometry geometry() const;
120         ///
121         bool allowSpellCheck() const { return true; }
122         ///
123         bool allowMultiPar() const;
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 ColorCode backgroundColor() const {return layout_.bgcolor; }
132
133         int latex(Buffer const &, odocstream &,
134                   OutputParams const &) const;
135         ///
136         void validate(LaTeXFeatures &) const;
137         ///
138         virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
139
140         /// Allow multiple blanks
141         virtual bool isFreeSpacing() const { return layout_.freespacing; }
142         /// Don't eliminate empty paragraphs
143         virtual bool allowEmpty() const { return layout_.keepempty; }
144
145 protected:
146         ///
147         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
148         ///
149         Dimension dimensionCollapsed() const;
150         ///
151         Box const & buttonDim() const;
152         ///
153         void edit(Cursor & cur, bool left);
154         ///
155         Inset * editXY(Cursor & cur, int x, int y);
156         ///
157         docstring floatName(std::string const & type, BufferParams const &) const;
158         ///
159         virtual void resetParagraphsFont();
160         ///
161         virtual void getDrawFont(FontInfo &) const;
162
163 protected:
164         ///
165         mutable Box button_dim;
166         ///
167         mutable int topx;
168         ///
169         mutable int topbaseline;
170         ///
171         mutable InsetLayout layout_;
172         ///
173         CollapseStatus internalStatus() const { return status_; }
174 private:
175         ///
176         mutable CollapseStatus status_;
177         /// a substatus of the Open status, determined automatically in metrics
178         mutable bool openinlined_;
179         /// the inset will automatically open when the cursor is inside
180         mutable bool autoOpen_;
181         /// changes color when mouse enters/leaves this inset
182         bool mouse_hover_;
183 };
184
185 // A helper function that pushes the cursor out of the inset.
186 void leaveInset(Cursor & cur, Inset const & in);
187
188 } // namespace lyx
189
190 #endif