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 *, 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(BufferView const & bv) 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; }
86 virtual void setStatus(Cursor & cur, CollapseStatus st);
88 CollapseStatus status(BufferView const & bv) 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 | NoButton ButtonOnly
102 * Conglomerate | SubLabel Corners
103 * ---------------------------------------------
104 * *) toggled by openinlined_
105 * x) toggled by auto_open_
109 virtual InsetLayout::InsetDecoration decoration() const;
119 /// Returns the geometry based on CollapseStatus
120 /// (status_), auto_open_[BufferView] and openinlined_,
121 /// and of course decoration().
122 Geometry geometry(BufferView const & bv) const;
123 /// Returns the geometry disregarding auto_open_
124 Geometry geometry() const;
126 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
128 bool setMouseHover(bool mouse_hover);
130 ColorCode backgroundColor(PainterInfo const &) const
131 { return getLayout().bgcolor(); }
133 ColorCode labelColor() const { return getLayout().labelfont().color(); }
135 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
138 virtual bool usePlainLayout() const { return true; }
140 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
142 docstring floatName(std::string const & type) const;
145 void doDispatch(Cursor & cur, FuncRequest & cmd);
147 void edit(Cursor & cur, bool front,
148 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
150 Inset * editXY(Cursor & cur, int x, int y);
152 mutable CollapseStatus status_;
155 Dimension dimensionCollapsed(BufferView const & bv) const;
157 docstring labelstring_;
159 mutable Box button_dim;
160 /// a substatus of the Open status, determined automatically in metrics
161 mutable bool openinlined_;
162 /// the inset will automatically open when the cursor is inside. This is
163 /// dependent on the bufferview, compare with MathMacro::editing_.
164 mutable std::map<BufferView const *, bool> auto_open_;
165 /// changes color when mouse enters/leaves this inset