3 * \file InsetCollapsable.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
9 * \author Lars Gullik Bjønnes
11 * Full author contact details are available in file CREDITS.
14 #ifndef INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
18 #include "InsetText.h"
19 #include "TextClass.h"
33 namespace frontend { class Painter; }
35 /** A collapsable text inset
38 class InsetCollapsable : public InsetText {
41 static int const TEXT_TO_TOP_OFFSET = 2;
43 static int const TEXT_TO_BOTTOM_OFFSET = 2;
45 InsetCollapsable(BufferParams const &, CollapseStatus status = Inset::Open);
47 InsetCollapsable(InsetCollapsable const & rhs);
49 docstring name() const { return from_ascii("Collapsable"); }
51 void setLayout(BufferParams const &);
53 void read(Buffer const &, Lexer &);
55 void write(Buffer const &, std::ostream &) const;
57 bool metrics(MetricsInfo &, Dimension &) const;
59 void draw(PainterInfo & pi, int x, int y) const;
61 void drawSelection(PainterInfo & pi, int x, int y) const;
62 /// return x,y of given position relative to the inset's baseline
63 void cursorPos(BufferView const & bv, CursorSlice const & sl,
64 bool boundary, int & x, int & y) const;
66 bool hitButton(FuncRequest const &) const;
68 docstring const getNewLabel(docstring const & l) const;
70 EDITABLE editable() const;
71 /// can we go further down on mouse click?
72 bool descendable() const;
74 void setLabel(docstring const & l);
76 virtual void setButtonLabel() {}
78 void setLabelFont(Font const & f);
80 bool isOpen() const { return geometry() != ButtonOnly; }
82 CollapseStatus status() const;
83 /** Of the old CollapseStatus we only keep the values
85 * We define a list of possible inset decoration
86 * styles, and a list of possible (concrete, visual)
87 * inset geometries. Relationships between them
88 * (geometries in body of table):
91 * Decoration: \ Open Collapsed
92 * -------------+-------------------------------
93 * Classic | *) TopButton, <--x) ButtonOnly
95 * Minimalistic | ButtonOnly NoButton
96 * Conglomerate | SubLabel Corners
97 * ---------------------------------------------
98 * *) toggled by openinlined_
99 * x) toggled by autoOpen_
109 virtual Decoration decoration() const;
119 /// Returns the geometry based on CollapseStatus
120 /// (status_), autoOpen_ and openinlined_, and of
121 /// course decoration().
122 Geometry geometry() const;
124 bool allowSpellCheck() const { return true; }
126 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
128 void setStatus(Cursor & cur, CollapseStatus st);
130 bool setMouseHover(bool mouse_hover);
132 virtual Color_color backgroundColor() const {return layout_.bgcolor; }
134 int latex(Buffer const &, odocstream &,
135 OutputParams const &) const;
137 void validate(LaTeXFeatures &) const;
141 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
143 Dimension dimensionCollapsed() const;
145 Box const & buttonDim() const;
147 void edit(Cursor & cur, bool left);
149 Inset * editXY(Cursor & cur, int x, int y);
151 docstring floatName(std::string const & type, BufferParams const &) const;
155 mutable Box button_dim;
159 mutable int topbaseline;
161 mutable InsetLayout layout_;
163 CollapseStatus internalStatus() const { return status_; }
166 mutable CollapseStatus status_;
167 /// a substatus of the Open status, determined automatically in metrics
168 mutable bool openinlined_;
169 /// the inset will automatically open when the cursor is inside
170 mutable bool autoOpen_;
171 /// changes color when mouse enters/leaves this inset
175 // A helper function that pushes the cursor out of the inset.
176 void leaveInset(Cursor & cur, Inset const & in);