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"
21 #include "TextClass.h"
28 namespace frontend { class Painter; }
30 /** A collapsable text inset
33 class InsetCollapsable : public InsetText {
36 InsetCollapsable(Buffer const &, CollapseStatus status = Inset::Open);
38 InsetCollapsable(InsetCollapsable const & rhs);
40 InsetCollapsable * asInsetCollapsable() { return this; }
42 InsetCollapsable const * asInsetCollapsable() const { return this; }
44 docstring toolTip(BufferView const & bv, int x, int y) const;
46 docstring name() const { return from_ascii("Collapsable"); }
48 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
50 InsetLayout const & getLayout() const { return *layout_; }
52 void setLayout(BufferParams const &);
53 /// (Re-)set the character style parameters from \p tc according
55 void setLayout(DocumentClass const * const tc);
57 virtual bool useEmptyLayout() { return true; }
61 void write(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,
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 void setLabel(docstring const & l);
82 virtual void setButtonLabel() {}
84 bool isOpen() const { return geometry() != ButtonOnly; }
86 CollapseStatus status() const;
87 /** Of the old CollapseStatus we only keep the values
89 * We define a list of possible inset decoration
90 * styles, and a list of possible (concrete, visual)
91 * inset geometries. Relationships between them
92 * (geometries in body of table):
95 * Decoration: \ Open Collapsed
96 * -------------+-------------------------------
97 * Classic | *) TopButton, <--x) ButtonOnly
99 * Minimalistic | NoButton ButtonOnly
100 * Conglomerate | SubLabel Corners
101 * ---------------------------------------------
102 * *) toggled by openinlined_
103 * x) toggled by autoOpen_
107 virtual InsetLayout::InsetDecoration decoration() const;
117 /// Returns the geometry based on CollapseStatus
118 /// (status_), autoOpen_ and openinlined_, and of
119 /// course decoration().
120 Geometry geometry() const;
122 bool allowSpellCheck() const { return true; }
124 bool allowMultiPar() const;
126 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
128 void setStatus(Cursor & cur, CollapseStatus st);
130 bool setMouseHover(bool mouse_hover);
132 ColorCode backgroundColor() const { return layout_->bgcolor(); }
134 int latex(odocstream &, OutputParams const &) const;
136 void validate(LaTeXFeatures &) const;
138 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
140 /// Allow multiple blanks
141 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
142 /// Don't eliminate empty paragraphs
143 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
144 /// Force inset into LTR environment if surroundings are RTL?
145 virtual bool forceLTR() const { return layout_->isForceLtr(); }
147 virtual bool useEmptyLayout() const { return true; }
148 /// Is this inset's layout defined in the document's textclass?
149 /// May be wrong after textclass change or paste from another document
150 bool undefined() const;
152 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
155 void doDispatch(Cursor & cur, FuncRequest & cmd);
157 void edit(Cursor & cur, bool front,
158 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
160 Inset * editXY(Cursor & cur, int x, int y);
162 docstring floatName(std::string const & type, BufferParams const &) const;
164 virtual void resetParagraphsFont();
167 /// cache for the layout_. Make sure it is in sync with the document class!
168 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