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 &, InsetText::UsePlain = InsetText::PlainLayout);
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"); }
50 void write(std::ostream &) const;
52 void metrics(MetricsInfo &, Dimension &) const;
54 void draw(PainterInfo & pi, int x, int y) const;
56 /// return x,y of given position relative to the inset's baseline
57 void cursorPos(BufferView const & bv, CursorSlice const & sl,
58 bool boundary, int & x, int & y) const;
59 /// Returns true if (mouse) action is over the inset's button.
60 /// Always returns false when the inset does not have a
62 bool hitButton(FuncRequest const &) const;
64 docstring const getNewLabel(docstring const & l) const;
66 bool editable() const;
68 bool hasSettings() const { return true; }
69 /// can we go further down on mouse click?
70 bool descendable() const;
72 void setLabel(docstring const & l);
74 virtual void setButtonLabel() {}
76 virtual docstring const buttonLabel(BufferView const &) const;
78 bool isOpen(BufferView const & bv) const
79 { return geometry(bv) != ButtonOnly; }
81 CollapseStatus status(BufferView const & bv) const;
82 /** Of the old CollapseStatus we only keep the values
84 * We define a list of possible inset decoration
85 * styles, and a list of possible (concrete, visual)
86 * inset geometries. Relationships between them
87 * (geometries in body of table):
90 * Decoration: \ Open Collapsed
91 * -------------+-------------------------------
92 * Classic | *) TopButton, <--x) ButtonOnly
94 * Minimalistic | NoButton ButtonOnly
95 * Conglomerate | SubLabel Corners
96 * ---------------------------------------------
97 * *) toggled by openinlined_
98 * x) toggled by auto_open_
102 virtual InsetLayout::InsetDecoration decoration() const;
112 /// Returns the geometry based on CollapseStatus
113 /// (status_), auto_open_[BufferView] and openinlined_,
114 /// and of course decoration().
115 Geometry geometry(BufferView const & bv) const;
116 /// Returns the geometry disregarding auto_open_
117 Geometry geometry() const;
119 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
121 void setStatus(Cursor & cur, CollapseStatus st);
123 bool setMouseHover(bool mouse_hover);
125 ColorCode backgroundColor() const { return getLayout().bgcolor(); }
127 ColorCode labelColor() const { return getLayout().labelfont().color(); }
129 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
132 virtual bool usePlainLayout() const { return true; }
134 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
137 void doDispatch(Cursor & cur, FuncRequest & cmd);
139 void edit(Cursor & cur, bool front,
140 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
142 Inset * editXY(Cursor & cur, int x, int y);
144 docstring floatName(std::string const & type) const;
146 mutable CollapseStatus status_;
149 Dimension dimensionCollapsed(BufferView const & bv) const;
151 docstring labelstring_;
153 mutable Box button_dim;
154 /// a substatus of the Open status, determined automatically in metrics
155 mutable bool openinlined_;
156 /// the inset will automatically open when the cursor is inside. This is
157 /// dependent on the bufferview, compare with MathMacro::editing_.
158 mutable std::map<BufferView const *, bool> auto_open_;
159 /// changes color when mouse enters/leaves this inset