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 "InsetLayout.h"
19 #include "InsetText.h"
33 namespace frontend { class Painter; }
35 /** A collapsable text inset
38 class InsetCollapsable : public InsetText {
43 CollapseStatus status = Inset::Open,
44 InsetLayout const * il = 0
47 InsetCollapsable(InsetCollapsable const & rhs);
49 InsetCollapsable * asInsetCollapsable() { return this; }
50 InsetCollapsable const * asInsetCollapsable() const { return this; }
51 docstring name() const { return from_ascii("Collapsable"); }
52 InsetLayout const & getLayout(BufferParams const &) const
55 void setLayout(BufferParams const &);
56 /// (Re-)set the character style parameters from \p il
57 void setLayout(InsetLayout const & il);
59 void read(Buffer const &, Lexer &);
61 void write(Buffer const &, std::ostream &) const;
63 void metrics(MetricsInfo &, Dimension &) const;
65 void draw(PainterInfo & pi, int x, int y) const;
67 /// return x,y of given position relative to the inset's baseline
68 void cursorPos(BufferView const & bv, CursorSlice const & sl,
69 bool boundary, int & x, int & y) const;
71 bool hitButton(FuncRequest const &) const;
73 docstring const getNewLabel(docstring const & l) const;
75 EDITABLE editable() const;
76 /// can we go further down on mouse click?
77 bool descendable() const;
79 void setLabel(docstring const & l);
81 virtual void setButtonLabel() {}
83 bool isOpen() const { return geometry() != ButtonOnly; }
85 CollapseStatus status() const;
86 /** Of the old CollapseStatus we only keep the values
88 * We define a list of possible inset decoration
89 * styles, and a list of possible (concrete, visual)
90 * inset geometries. Relationships between them
91 * (geometries in body of table):
94 * Decoration: \ Open Collapsed
95 * -------------+-------------------------------
96 * Classic | *) TopButton, <--x) ButtonOnly
98 * Minimalistic | ButtonOnly NoButton
99 * Conglomerate | SubLabel Corners
100 * ---------------------------------------------
101 * *) toggled by openinlined_
102 * x) toggled by autoOpen_
112 virtual Decoration decoration() const;
122 /// Returns the geometry based on CollapseStatus
123 /// (status_), autoOpen_ and openinlined_, and of
124 /// course decoration().
125 Geometry geometry() const;
127 bool allowSpellCheck() const { return true; }
129 bool allowMultiPar() const;
131 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
133 void setStatus(Cursor & cur, CollapseStatus st);
135 bool setMouseHover(bool mouse_hover);
137 virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
139 int latex(Buffer const &, odocstream &,
140 OutputParams const &) const;
142 void validate(LaTeXFeatures &) const;
144 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
146 /// Allow multiple blanks
147 virtual bool isFreeSpacing() const { return layout_->freespacing; }
148 /// Don't eliminate empty paragraphs
149 virtual bool allowEmpty() const { return layout_->keepempty; }
150 /// Force inset into LTR environment if surroundings are RTL?
151 virtual bool forceLTR() const { return layout_->forceltr; }
155 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
157 void edit(Cursor & cur, bool left);
159 Inset * editXY(Cursor & cur, int x, int y);
161 docstring floatName(std::string const & type, BufferParams const &) const;
163 virtual void resetParagraphsFont();
167 InsetLayout const * layout_;
170 Dimension dimensionCollapsed() const;
172 docstring labelstring_;
174 mutable Box button_dim;
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