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