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(); }
128 /// It will rarely be right to call this from subclasses, due
129 /// to the fact that it steps counters, etc. Instead, call
130 /// InsetText::xhtml().
131 docstring xhtml(odocstream &, OutputParams const &) const;
133 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
136 virtual bool usePlainLayout() const { return true; }
137 /// the string that is passed to the TOC
138 void tocString(odocstream &) const;
140 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
143 void doDispatch(Cursor & cur, FuncRequest & cmd);
145 void edit(Cursor & cur, bool front,
146 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
148 Inset * editXY(Cursor & cur, int x, int y);
150 docstring floatName(std::string const & type) const;
152 mutable CollapseStatus status_;
155 Dimension dimensionCollapsed(BufferView const & bv) const;
157 /// should paragraphs be forced to use the empty layout?
158 virtual bool forcePlainLayout(idx_type = 0) const
159 { return getLayout().forcePlainLayout(); }
160 /// should the user be allowed to customize alignment, etc.?
161 virtual bool allowParagraphCustomization(idx_type = 0) const
162 { return getLayout().allowParagraphCustomization(); }
163 docstring labelstring_;
165 mutable Box button_dim;
166 /// a substatus of the Open status, determined automatically in metrics
167 mutable bool openinlined_;
168 /// the inset will automatically open when the cursor is inside. This is
169 /// dependent on the bufferview, compare with MathMacro::editing_.
170 mutable std::map<BufferView const *, bool> auto_open_;
171 /// changes color when mouse enters/leaves this inset