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 InsetCollapsable(BufferParams const &, CollapseStatus status = Inset::Open);
43 InsetCollapsable(InsetCollapsable const & rhs);
45 InsetCollapsable * asInsetCollapsable() { return this; }
46 InsetCollapsable const * asInsetCollapsable() const { return this; }
47 docstring name() const { return from_ascii("Collapsable"); }
49 void setLayout(BufferParams const &);
51 void read(Buffer const &, Lexer &);
53 void write(Buffer const &, std::ostream &) const;
55 void metrics(MetricsInfo &, Dimension &) const;
57 void draw(PainterInfo & pi, int x, int y) const;
59 /// return x,y of given position relative to the inset's baseline
60 void cursorPos(BufferView const & bv, CursorSlice const & sl,
61 bool boundary, int & x, int & y) const;
63 bool hitButton(FuncRequest const &) const;
65 docstring const getNewLabel(docstring const & l) const;
67 EDITABLE editable() const;
68 /// can we go further down on mouse click?
69 bool descendable() const;
71 void setLabel(docstring const & l);
73 virtual void setButtonLabel() {}
75 bool isOpen() const { return geometry() != ButtonOnly; }
77 CollapseStatus status() const;
78 /** Of the old CollapseStatus we only keep the values
80 * We define a list of possible inset decoration
81 * styles, and a list of possible (concrete, visual)
82 * inset geometries. Relationships between them
83 * (geometries in body of table):
86 * Decoration: \ Open Collapsed
87 * -------------+-------------------------------
88 * Classic | *) TopButton, <--x) ButtonOnly
90 * Minimalistic | ButtonOnly NoButton
91 * Conglomerate | SubLabel Corners
92 * ---------------------------------------------
93 * *) toggled by openinlined_
94 * x) toggled by autoOpen_
104 virtual Decoration decoration() const;
114 /// Returns the geometry based on CollapseStatus
115 /// (status_), autoOpen_ and openinlined_, and of
116 /// course decoration().
117 Geometry geometry() const;
119 bool allowSpellCheck() const { return true; }
121 bool allowMultiPar() const;
123 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
125 void setStatus(Cursor & cur, CollapseStatus st);
127 bool setMouseHover(bool mouse_hover);
129 virtual ColorCode backgroundColor() const {return layout_.bgcolor; }
131 int latex(Buffer const &, odocstream &,
132 OutputParams const &) const;
134 void validate(LaTeXFeatures &) const;
136 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
138 /// Allow multiple blanks
139 virtual bool isFreeSpacing() const { return layout_.freespacing; }
140 /// Don't eliminate empty paragraphs
141 virtual bool allowEmpty() const { return layout_.keepempty; }
145 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
147 Dimension dimensionCollapsed() const;
149 Box const & buttonDim() const;
151 void edit(Cursor & cur, bool left);
153 Inset * editXY(Cursor & cur, int x, int y);
155 docstring floatName(std::string const & type, BufferParams const &) const;
157 virtual void resetParagraphsFont();
161 mutable Box button_dim;
165 mutable int topbaseline;
167 mutable InsetLayout layout_;
169 CollapseStatus internalStatus() const { return status_; }
172 mutable CollapseStatus status_;
173 /// a substatus of the Open status, determined automatically in metrics
174 mutable bool openinlined_;
175 /// the inset will automatically open when the cursor is inside
176 mutable bool autoOpen_;
177 /// changes color when mouse enters/leaves this inset
181 // A helper function that pushes the cursor out of the inset.
182 void leaveInset(Cursor & cur, Inset const & in);