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 docstring name() const { return from_ascii("Collapsable"); }
47 void setLayout(BufferParams const &);
49 void read(Buffer const &, Lexer &);
51 void write(Buffer const &, std::ostream &) const;
53 void metrics(MetricsInfo &, Dimension &) const;
55 void draw(PainterInfo & pi, int x, int y) const;
57 /// return x,y of given position relative to the inset's baseline
58 void cursorPos(BufferView const & bv, CursorSlice const & sl,
59 bool boundary, int & x, int & y) const;
61 bool hitButton(FuncRequest const &) const;
63 docstring const getNewLabel(docstring const & l) const;
65 EDITABLE editable() const;
66 /// can we go further down on mouse click?
67 bool descendable() const;
69 void setLabel(docstring const & l);
71 virtual void setButtonLabel() {}
73 void setLabelFont(FontInfo const & f);
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();
159 virtual void getDrawFont(FontInfo &) const;
163 mutable Box button_dim;
167 mutable int topbaseline;
169 mutable InsetLayout layout_;
171 CollapseStatus internalStatus() const { return status_; }
174 mutable CollapseStatus status_;
175 /// a substatus of the Open status, determined automatically in metrics
176 mutable bool openinlined_;
177 /// the inset will automatically open when the cursor is inside
178 mutable bool autoOpen_;
179 /// changes color when mouse enters/leaves this inset
183 // A helper function that pushes the cursor out of the inset.
184 void leaveInset(Cursor & cur, Inset const & in);