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