]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
This should be the last of the commits refactoring the InsetLayout code.
[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         /// Default looks
121         virtual InsetDecoration decoration() const;
122         ///
123         enum Geometry {
124                 TopButton,
125                 ButtonOnly,
126                 NoButton,
127                 LeftButton,
128                 SubLabel,
129                 Corners
130         };
131         /// Returns the geometry based on CollapseStatus
132         /// (status_), autoOpen_ and openinlined_, and of
133         /// course decoration().
134         Geometry geometry() const;
135         ///
136         bool allowSpellCheck() const { return true; }
137         ///
138         bool allowMultiPar() const;
139         ///
140         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
141         ///
142         void setStatus(Cursor & cur, CollapseStatus st);
143         ///
144         bool setMouseHover(bool mouse_hover);
145         ///
146         virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
147         ///
148         int latex(Buffer const &, odocstream &,
149                   OutputParams const &) const;
150         ///
151         void validate(LaTeXFeatures &) const;
152         ///
153         virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
154
155         /// Allow multiple blanks
156         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
157         /// Don't eliminate empty paragraphs
158         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
159         /// Force inset into LTR environment if surroundings are RTL?
160         virtual bool forceLTR() const { return layout_->isForceLtr(); }
161         ///
162         virtual bool useEmptyLayout() const { return true; }
163         /// Is this inset's layout defined in the document's textclass?
164         /// May be wrong after textclass change or paste from another document
165         bool undefined() const;
166 protected:
167         ///
168         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
169         ///
170         void edit(Cursor & cur, bool front, 
171                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
172         ///
173         Inset * editXY(Cursor & cur, int x, int y);
174         ///
175         docstring floatName(std::string const & type, BufferParams const &) const;
176         ///
177         virtual void resetParagraphsFont();
178
179 private:
180         /// text class to keep the InsetLayout above in memory
181         TextClassPtr textClass_;
182         /// cache for the layout_. Make sure it is in sync with the text class!
183         InsetLayout const * layout_;
184         ///
185         Dimension dimensionCollapsed() const;
186         ///
187         docstring labelstring_;
188         ///
189         mutable Box button_dim;
190         ///
191         mutable CollapseStatus status_;
192         /// a substatus of the Open status, determined automatically in metrics
193         mutable bool openinlined_;
194         /// the inset will automatically open when the cursor is inside
195         mutable bool autoOpen_;
196         /// changes color when mouse enters/leaves this inset
197         bool mouse_hover_;
198 };
199
200 } // namespace lyx
201
202 #endif