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