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 bool isMacroScope(Buffer const & buf) const;
81 void setLabel(docstring const & l);
83 virtual void setButtonLabel() {}
85 bool isOpen() const { return geometry() != ButtonOnly; }
87 CollapseStatus status() const;
88 /** Of the old CollapseStatus we only keep the values
90 * We define a list of possible inset decoration
91 * styles, and a list of possible (concrete, visual)
92 * inset geometries. Relationships between them
93 * (geometries in body of table):
96 * Decoration: \ Open Collapsed
97 * -------------+-------------------------------
98 * Classic | *) TopButton, <--x) ButtonOnly
100 * Minimalistic | ButtonOnly NoButton
101 * Conglomerate | SubLabel Corners
102 * ---------------------------------------------
103 * *) toggled by openinlined_
104 * x) toggled by autoOpen_
114 virtual Decoration decoration() const;
124 /// Returns the geometry based on CollapseStatus
125 /// (status_), autoOpen_ and openinlined_, and of
126 /// course decoration().
127 Geometry geometry() const;
129 bool allowSpellCheck() const { return true; }
131 bool allowMultiPar() const;
133 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
135 void setStatus(Cursor & cur, CollapseStatus st);
137 bool setMouseHover(bool mouse_hover);
139 virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
141 int latex(Buffer const &, odocstream &,
142 OutputParams const &) const;
144 void validate(LaTeXFeatures &) const;
146 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
148 /// Allow multiple blanks
149 virtual bool isFreeSpacing() const { return layout_->freespacing; }
150 /// Don't eliminate empty paragraphs
151 virtual bool allowEmpty() const { return layout_->keepempty; }
152 /// Force inset into LTR environment if surroundings are RTL?
153 virtual bool forceLTR() const { return layout_->forceltr; }
157 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
159 void edit(Cursor & cur, bool left);
161 Inset * editXY(Cursor & cur, int x, int y);
163 docstring floatName(std::string const & type, BufferParams const &) const;
165 virtual void resetParagraphsFont();
169 InsetLayout const * layout_;
172 Dimension dimensionCollapsed() const;
174 docstring labelstring_;
176 mutable Box button_dim;
178 mutable CollapseStatus status_;
179 /// a substatus of the Open status, determined automatically in metrics
180 mutable bool openinlined_;
181 /// the inset will automatically open when the cursor is inside
182 mutable bool autoOpen_;
183 /// changes color when mouse enters/leaves this inset