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