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
17 #include "InsetText.h"
28 namespace frontend { class Painter; }
30 /** A collapsable text inset
33 class InsetCollapsable : public InsetText {
36 InsetCollapsable(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
38 InsetCollapsable(InsetCollapsable const & rhs);
40 virtual ~InsetCollapsable();
42 InsetCollapsable * asInsetCollapsable() { return this; }
44 InsetCollapsable const * asInsetCollapsable() const { return this; }
46 docstring toolTip(BufferView const & bv, int x, int y) const;
48 docstring layoutName() const { return from_ascii("Collapsable"); }
52 void write(std::ostream &) const;
54 void metrics(MetricsInfo &, Dimension &) const;
56 void draw(PainterInfo & pi, int x, int y) const;
58 /// return x,y of given position relative to the inset's baseline
59 void cursorPos(BufferView const & bv, CursorSlice const & sl,
60 bool boundary, int & x, int & y) const;
61 /// Returns true if (mouse) action is over the inset's button.
62 /// Always returns false when the inset does not have a
64 bool hitButton(FuncRequest const &) const;
66 docstring const getNewLabel(docstring const & l) const;
68 bool editable() const;
70 bool hasSettings() const { return true; }
72 bool clickable(int x, int y) const;
73 /// can we go further down on mouse click?
74 bool descendable(BufferView const & bv) const;
76 void setLabel(docstring const & l);
78 virtual void setButtonLabel() {}
80 virtual docstring const buttonLabel(BufferView const &) const;
82 bool isOpen(BufferView const & bv) const
83 { return geometry(bv) != ButtonOnly; }
90 virtual void setStatus(Cursor & cur, CollapseStatus st);
92 CollapseStatus status(BufferView const & bv) const;
93 /** Of the old CollapseStatus we only keep the values
95 * We define a list of possible inset decoration
96 * styles, and a list of possible (concrete, visual)
97 * inset geometries. Relationships between them
98 * (geometries in body of table):
101 * Decoration: \ Open Collapsed
102 * -------------+-------------------------------
103 * Classic | *) TopButton, <--x) ButtonOnly
105 * Minimalistic | NoButton ButtonOnly
106 * Conglomerate | SubLabel Corners
107 * ---------------------------------------------
108 * *) toggled by openinlined_
109 * x) toggled by auto_open_
113 virtual InsetLayout::InsetDecoration decoration() const;
115 virtual FontInfo getFont() const { return getLayout().font(); }
117 virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
127 /// Returns the geometry based on CollapseStatus
128 /// (status_), auto_open_[BufferView] and openinlined_,
129 /// and of course decoration().
130 Geometry geometry(BufferView const & bv) const;
131 /// Returns the geometry disregarding auto_open_
132 Geometry geometry() const;
134 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
136 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
138 ColorCode backgroundColor(PainterInfo const &) const
139 { return getLayout().bgcolor(); }
141 ColorCode labelColor() const { return getLayout().labelfont().color(); }
143 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
146 virtual bool usePlainLayout() const { return true; }
148 std::string contextMenu(BufferView const & bv, int x, int y) const;
150 std::string contextMenuName() const;
153 void doDispatch(Cursor & cur, FuncRequest & cmd);
155 void edit(Cursor & cur, bool front,
156 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
158 Inset * editXY(Cursor & cur, int x, int y);
160 mutable CollapseStatus status_;
163 Dimension dimensionCollapsed(BufferView const & bv) const;
165 docstring labelstring_;
167 mutable Box button_dim;
168 /// a substatus of the Open status, determined automatically in metrics
169 mutable bool openinlined_;
170 /// the inset will automatically open when the cursor is inside. This is
171 /// dependent on the bufferview, compare with MathMacro::editing_.
172 mutable std::map<BufferView const *, bool> auto_open_;
173 /// changes color when mouse enters/leaves this inset
174 mutable std::map<BufferView const *, bool> mouse_hover_;