]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
58666bfe19c8034273a344713b52898b0c508ec7
[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 "InsetLayout.h"
19 #include "InsetText.h"
20
21 #include "Box.h"
22 #include "TextClass.h"
23 #include "TextClassPtr.h"
24
25 #include <string>
26
27 namespace lyx {
28
29 class CursorSlice;
30 class FontInfo;
31 class InsetLayout;
32 class Paragraph;
33 class Text;
34
35 namespace frontend { class Painter; }
36
37 /** A collapsable text inset
38
39 */
40 class InsetCollapsable : public InsetText {
41 public:
42         ///
43         InsetCollapsable(
44                 BufferParams const &,
45                 CollapseStatus status = Inset::Open,
46                 TextClassPtr tc = TextClassPtr((TextClass *)0)
47                 );
48         ///
49         InsetCollapsable(InsetCollapsable const & rhs);
50         ///
51         InsetCollapsable * asInsetCollapsable() { return this; }
52         ///
53         InsetCollapsable const * asInsetCollapsable() const { return this; }
54         ///
55         docstring toolTip(BufferView const & bv, int x, int y) const;
56         ///
57         docstring name() const { return from_ascii("Collapsable"); }
58         ///
59         InsetLayout const & getLayout(BufferParams const &) const
60                 { return *layout_; } 
61         ///
62         InsetLayout const & getLayout() const
63                 { return *layout_; } 
64         ///
65         void setLayout(BufferParams const &);
66         /// (Re-)set the character style parameters from \p tc according
67         /// to name()
68         void setLayout(TextClassPtr tc);
69         ///
70         virtual bool useEmptyLayout() { return true; }
71         ///
72         void read(Buffer const &, Lexer &);
73         ///
74         void write(Buffer const &, std::ostream &) const;
75         ///
76         void metrics(MetricsInfo &, Dimension &) const;
77         ///
78         void draw(PainterInfo & pi, int x, int y) const;
79
80         /// return x,y of given position relative to the inset's baseline
81         void cursorPos(BufferView const & bv, CursorSlice const & sl,
82         ///
83         bool boundary, int & x, int & y) const;
84         ///
85         bool hitButton(FuncRequest const &) const;
86         ///
87         docstring const getNewLabel(docstring const & l) const;
88         ///
89         EDITABLE editable() const;
90         /// can we go further down on mouse click?
91         bool descendable() const;
92         ///
93         bool isMacroScope(Buffer const & buf) const;
94         ///
95         void setLabel(docstring const & l);
96         ///
97         virtual void setButtonLabel() {}
98         ///
99         bool isOpen() const { return geometry() != ButtonOnly; }
100         ///
101         CollapseStatus status() const;
102         /** Of the old CollapseStatus we only keep the values  
103          *  Open and Collapsed.
104          * We define a list of possible inset decoration
105          * styles, and a list of possible (concrete, visual)
106          * inset geometries. Relationships between them
107          * (geometries in body of table):
108          *
109          *               \       CollapseStatus:
110          *   Decoration:  \ Open                Collapsed
111          *   -------------+-------------------------------
112          *   Classic      | *) TopButton, <--x) ButtonOnly
113          *                | LeftButton
114          *   Minimalistic | NoButton            ButtonOnly
115          *   Conglomerate | SubLabel            Corners
116          *   ---------------------------------------------
117          *   *) toggled by openinlined_
118          *   x) toggled by autoOpen_
119          */
120
121         ///
122         enum Decoration {
123                 Classic,
124                 Minimalistic,
125                 Conglomerate
126         };
127         /// Default looks
128         virtual Decoration decoration() const;
129         ///
130         enum Geometry {
131                 TopButton,
132                 ButtonOnly,
133                 NoButton,
134                 LeftButton,
135                 SubLabel,
136                 Corners
137         };
138         /// Returns the geometry based on CollapseStatus
139         /// (status_), autoOpen_ and openinlined_, and of
140         /// course decoration().
141         Geometry geometry() const;
142         ///
143         bool allowSpellCheck() const { return true; }
144         ///
145         bool allowMultiPar() const;
146         ///
147         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
148         ///
149         void setStatus(Cursor & cur, CollapseStatus st);
150         ///
151         bool setMouseHover(bool mouse_hover);
152         ///
153         virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
154         ///
155         int latex(Buffer const &, odocstream &,
156                   OutputParams const &) const;
157         ///
158         void validate(LaTeXFeatures &) const;
159         ///
160         virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
161
162         /// Allow multiple blanks
163         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
164         /// Don't eliminate empty paragraphs
165         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
166         /// Force inset into LTR environment if surroundings are RTL?
167         virtual bool forceLTR() const { return layout_->isForceLtr(); }
168         ///
169         virtual bool useEmptyLayout() const { return true; }
170         /// Is this inset's layout defined in the document's textclass?
171         /// May be wrong after textclass change or paste from another document
172         bool undefined() const;
173 protected:
174         ///
175         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
176         ///
177         void edit(Cursor & cur, bool front, 
178                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
179         ///
180         Inset * editXY(Cursor & cur, int x, int y);
181         ///
182         docstring floatName(std::string const & type, BufferParams const &) const;
183         ///
184         virtual void resetParagraphsFont();
185
186 private:
187         /// text class to keep the InsetLayout above in memory
188         TextClassPtr textClass_;
189         /// cache for the layout_. Make sure it is in sync with the text class!
190         InsetLayout const * layout_;
191         ///
192         Dimension dimensionCollapsed() const;
193         ///
194         docstring labelstring_;
195         ///
196         mutable Box button_dim;
197         ///
198         mutable CollapseStatus status_;
199         /// a substatus of the Open status, determined automatically in metrics
200         mutable bool openinlined_;
201         /// the inset will automatically open when the cursor is inside
202         mutable bool autoOpen_;
203         /// changes color when mouse enters/leaves this inset
204         bool mouse_hover_;
205 };
206
207 } // namespace lyx
208
209 #endif