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