]> git.lyx.org Git - features.git/blob - src/insets/InsetCollapsable.h
* Lazy MathData to avoid unneeded interpretation of macro definitions
[features.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 "InsetLayout.h"
19 #include "InsetText.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         bool isMacroScope(Buffer const & buf) const;
80         ///
81         void setLabel(docstring const & l);
82         ///
83         virtual void setButtonLabel() {}
84         ///
85         bool isOpen() const { return geometry() != ButtonOnly; }
86         ///
87         CollapseStatus status() const;
88         /** Of the old CollapseStatus we only keep the values  
89          *  Open and Collapsed.
90          * We define a list of possible inset decoration
91          * styles, and a list of possible (concrete, visual)
92          * inset geometries. Relationships between them
93          * (geometries in body of table):
94          *
95          *               \       CollapseStatus:
96          *   Decoration:  \ Open                Collapsed
97          *   -------------+-------------------------------
98          *   Classic      | *) TopButton, <--x) ButtonOnly
99          *                | LeftButton
100          *   Minimalistic | ButtonOnly          NoButton
101          *   Conglomerate | SubLabel            Corners
102          *   ---------------------------------------------
103          *   *) toggled by openinlined_
104          *   x) toggled by autoOpen_
105          */
106
107         ///
108         enum Decoration {
109                 Classic,
110                 Minimalistic,
111                 Conglomerate
112         };
113         /// Default looks
114         virtual Decoration decoration() const;
115         ///
116         enum Geometry {
117                 TopButton,
118                 ButtonOnly,
119                 NoButton,
120                 LeftButton,
121                 SubLabel,
122                 Corners
123         };
124         /// Returns the geometry based on CollapseStatus
125         /// (status_), autoOpen_ and openinlined_, and of
126         /// course decoration().
127         Geometry geometry() const;
128         ///
129         bool allowSpellCheck() const { return true; }
130         ///
131         bool allowMultiPar() const;
132         ///
133         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
134         ///
135         void setStatus(Cursor & cur, CollapseStatus st);
136         ///
137         bool setMouseHover(bool mouse_hover);
138         ///
139         virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
140
141         int latex(Buffer const &, odocstream &,
142                   OutputParams const &) const;
143         ///
144         void validate(LaTeXFeatures &) const;
145         ///
146         virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
147
148         /// Allow multiple blanks
149         virtual bool isFreeSpacing() const { return layout_->freespacing; }
150         /// Don't eliminate empty paragraphs
151         virtual bool allowEmpty() const { return layout_->keepempty; }
152         /// Force inset into LTR environment if surroundings are RTL?
153         virtual bool forceLTR() const { return layout_->forceltr; }
154
155 protected:
156         ///
157         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
158         ///
159         void edit(Cursor & cur, bool left);
160         ///
161         Inset * editXY(Cursor & cur, int x, int y);
162         ///
163         docstring floatName(std::string const & type, BufferParams const &) const;
164         ///
165         virtual void resetParagraphsFont();
166
167 protected:
168         ///
169         InsetLayout const * layout_;
170 private:
171         ///
172         Dimension dimensionCollapsed() const;
173         ///
174         docstring labelstring_;
175         ///
176         mutable Box button_dim;
177         ///
178         mutable CollapseStatus status_;
179         /// a substatus of the Open status, determined automatically in metrics
180         mutable bool openinlined_;
181         /// the inset will automatically open when the cursor is inside
182         mutable bool autoOpen_;
183         /// changes color when mouse enters/leaves this inset
184         bool mouse_hover_;
185 };
186
187 } // namespace lyx
188
189 #endif