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 toolTip(BufferView const & bv, int x, int y) const;
52 docstring name() const { return from_ascii("Collapsable"); }
53 InsetLayout const & getLayout(BufferParams const &) const
56 void setLayout(BufferParams const &);
57 /// (Re-)set the character style parameters from \p il
58 void setLayout(InsetLayout const & il);
60 void read(Buffer const &, Lexer &);
62 void write(Buffer const &, std::ostream &) const;
64 void metrics(MetricsInfo &, Dimension &) const;
66 void draw(PainterInfo & pi, int x, int y) const;
68 /// return x,y of given position relative to the inset's baseline
69 void cursorPos(BufferView const & bv, CursorSlice const & sl,
70 bool boundary, int & x, int & y) const;
72 bool hitButton(FuncRequest const &) const;
74 docstring const getNewLabel(docstring const & l) const;
76 EDITABLE editable() const;
77 /// can we go further down on mouse click?
78 bool descendable() const;
80 bool isMacroScope(Buffer const & buf) const;
82 void setLabel(docstring const & l);
84 virtual void setButtonLabel() {}
86 bool isOpen() const { return geometry() != ButtonOnly; }
88 CollapseStatus status() const;
89 /** Of the old CollapseStatus we only keep the values
91 * We define a list of possible inset decoration
92 * styles, and a list of possible (concrete, visual)
93 * inset geometries. Relationships between them
94 * (geometries in body of table):
97 * Decoration: \ Open Collapsed
98 * -------------+-------------------------------
99 * Classic | *) TopButton, <--x) ButtonOnly
101 * Minimalistic | ButtonOnly NoButton
102 * Conglomerate | SubLabel Corners
103 * ---------------------------------------------
104 * *) toggled by openinlined_
105 * x) toggled by autoOpen_
115 virtual Decoration decoration() const;
125 /// Returns the geometry based on CollapseStatus
126 /// (status_), autoOpen_ and openinlined_, and of
127 /// course decoration().
128 Geometry geometry() const;
130 bool allowSpellCheck() const { return true; }
132 bool allowMultiPar() const;
134 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
136 void setStatus(Cursor & cur, CollapseStatus st);
138 bool setMouseHover(bool mouse_hover);
140 virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
142 int latex(Buffer const &, odocstream &,
143 OutputParams const &) const;
145 void validate(LaTeXFeatures &) const;
147 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
149 /// Allow multiple blanks
150 virtual bool isFreeSpacing() const { return layout_->freespacing; }
151 /// Don't eliminate empty paragraphs
152 virtual bool allowEmpty() const { return layout_->keepempty; }
153 /// Force inset into LTR environment if surroundings are RTL?
154 virtual bool forceLTR() const { return layout_->forceltr; }
158 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
160 void edit(Cursor & cur, bool left);
162 Inset * editXY(Cursor & cur, int x, int y);
164 docstring floatName(std::string const & type, BufferParams const &) const;
166 virtual void resetParagraphsFont();
170 InsetLayout const * layout_;
173 Dimension dimensionCollapsed() const;
175 docstring labelstring_;
177 mutable Box button_dim;
179 mutable CollapseStatus status_;
180 /// a substatus of the Open status, determined automatically in metrics
181 mutable bool openinlined_;
182 /// the inset will automatically open when the cursor is inside
183 mutable bool autoOpen_;
184 /// changes color when mouse enters/leaves this inset