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