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