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 void setLabelColor(ColorCode code);
77 bool isOpen() const { return geometry() != ButtonOnly; }
79 CollapseStatus status() const;
80 /** Of the old CollapseStatus we only keep the values
82 * We define a list of possible inset decoration
83 * styles, and a list of possible (concrete, visual)
84 * inset geometries. Relationships between them
85 * (geometries in body of table):
88 * Decoration: \ Open Collapsed
89 * -------------+-------------------------------
90 * Classic | *) TopButton, <--x) ButtonOnly
92 * Minimalistic | ButtonOnly NoButton
93 * Conglomerate | SubLabel Corners
94 * ---------------------------------------------
95 * *) toggled by openinlined_
96 * x) toggled by autoOpen_
106 virtual Decoration decoration() const;
116 /// Returns the geometry based on CollapseStatus
117 /// (status_), autoOpen_ and openinlined_, and of
118 /// course decoration().
119 Geometry geometry() const;
121 bool allowSpellCheck() const { return true; }
123 bool allowMultiPar() const;
125 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
127 void setStatus(Cursor & cur, CollapseStatus st);
129 bool setMouseHover(bool mouse_hover);
131 virtual ColorCode backgroundColor() const {return layout_.bgcolor; }
133 int latex(Buffer const &, odocstream &,
134 OutputParams const &) const;
136 void validate(LaTeXFeatures &) const;
138 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
140 /// Allow multiple blanks
141 virtual bool isFreeSpacing() const { return layout_.freespacing; }
142 /// Don't eliminate empty paragraphs
143 virtual bool allowEmpty() const { return layout_.keepempty; }
147 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
149 Dimension dimensionCollapsed() const;
151 Box const & buttonDim() const;
153 void edit(Cursor & cur, bool left);
155 Inset * editXY(Cursor & cur, int x, int y);
157 docstring floatName(std::string const & type, BufferParams const &) const;
159 virtual void resetParagraphsFont();
161 virtual void getDrawFont(FontInfo &) const;
165 mutable Box button_dim;
169 mutable int topbaseline;
171 mutable InsetLayout layout_;
173 CollapseStatus internalStatus() const { return status_; }
176 mutable CollapseStatus status_;
177 /// a substatus of the Open status, determined automatically in metrics
178 mutable bool openinlined_;
179 /// the inset will automatically open when the cursor is inside
180 mutable bool autoOpen_;
181 /// changes color when mouse enters/leaves this inset
185 // A helper function that pushes the cursor out of the inset.
186 void leaveInset(Cursor & cur, Inset const & in);