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 void metrics(MetricsInfo &, Dimension &) const;
59 void draw(PainterInfo & pi, int x, int y) const;
61 /// return x,y of given position relative to the inset's baseline
62 void cursorPos(BufferView const & bv, CursorSlice const & sl,
63 bool boundary, int & x, int & y) const;
65 bool hitButton(FuncRequest const &) const;
67 docstring const getNewLabel(docstring const & l) const;
69 EDITABLE editable() const;
70 /// can we go further down on mouse click?
71 bool descendable() const;
73 void setLabel(docstring const & l);
75 virtual void setButtonLabel() {}
77 void setLabelFont(Font const & f);
79 bool isOpen() const { return geometry() != ButtonOnly; }
81 CollapseStatus status() const;
82 /** Of the old CollapseStatus we only keep the values
84 * We define a list of possible inset decoration
85 * styles, and a list of possible (concrete, visual)
86 * inset geometries. Relationships between them
87 * (geometries in body of table):
90 * Decoration: \ Open Collapsed
91 * -------------+-------------------------------
92 * Classic | *) TopButton, <--x) ButtonOnly
94 * Minimalistic | ButtonOnly NoButton
95 * Conglomerate | SubLabel Corners
96 * ---------------------------------------------
97 * *) toggled by openinlined_
98 * x) toggled by autoOpen_
108 virtual Decoration decoration() const;
118 /// Returns the geometry based on CollapseStatus
119 /// (status_), autoOpen_ and openinlined_, and of
120 /// course decoration().
121 Geometry geometry() const;
123 bool allowSpellCheck() const { return true; }
125 bool allowMultiPar() const;
127 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
129 void setStatus(Cursor & cur, CollapseStatus st);
131 bool setMouseHover(bool mouse_hover);
133 virtual Color_color backgroundColor() const {return layout_.bgcolor; }
135 int latex(Buffer const &, odocstream &,
136 OutputParams const &) const;
138 void validate(LaTeXFeatures &) const;
142 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
144 Dimension dimensionCollapsed() const;
146 Box const & buttonDim() const;
148 void edit(Cursor & cur, bool left);
150 Inset * editXY(Cursor & cur, int x, int y);
152 docstring floatName(std::string const & type, BufferParams const &) const;
156 mutable Box button_dim;
160 mutable int topbaseline;
162 mutable InsetLayout layout_;
164 CollapseStatus internalStatus() const { return status_; }
167 mutable CollapseStatus status_;
168 /// a substatus of the Open status, determined automatically in metrics
169 mutable bool openinlined_;
170 /// the inset will automatically open when the cursor is inside
171 mutable bool autoOpen_;
172 /// changes color when mouse enters/leaves this inset
176 // A helper function that pushes the cursor out of the inset.
177 void leaveInset(Cursor & cur, Inset const & in);