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
77 { return labelstring_; }
79 bool isOpen(BufferView const & bv) const
80 { return geometry(bv) != ButtonOnly; }
82 CollapseStatus status(BufferView const & bv) const;
83 /** Of the old CollapseStatus we only keep the values
85 * We define a list of possible inset decoration
86 * styles, and a list of possible (concrete, visual)
87 * inset geometries. Relationships between them
88 * (geometries in body of table):
91 * Decoration: \ Open Collapsed
92 * -------------+-------------------------------
93 * Classic | *) TopButton, <--x) ButtonOnly
95 * Minimalistic | NoButton ButtonOnly
96 * Conglomerate | SubLabel Corners
97 * ---------------------------------------------
98 * *) toggled by openinlined_
99 * x) toggled by auto_open_
103 virtual InsetLayout::InsetDecoration decoration() const;
113 /// Returns the geometry based on CollapseStatus
114 /// (status_), auto_open_[BufferView] and openinlined_,
115 /// and of course decoration().
116 Geometry geometry(BufferView const & bv) const;
117 /// Returns the geometry disregarding auto_open_
118 Geometry geometry() const;
120 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
122 void setStatus(Cursor & cur, CollapseStatus st);
124 bool setMouseHover(bool mouse_hover);
126 ColorCode backgroundColor() const { return getLayout().bgcolor(); }
128 ColorCode labelColor() const { return getLayout().labelfont().color(); }
130 int latex(odocstream &, OutputParams const &) const;
132 int docbook(odocstream &, OutputParams const &) const;
133 /// It will rarely be right to call this from subclasses, due
134 /// to the fact that it steps counters, etc. Instead, call
135 /// InsetText::xhtml().
136 docstring xhtml(odocstream &, OutputParams const &) const;
138 void validate(LaTeXFeatures &) const;
140 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
143 virtual bool usePlainLayout() const { return true; }
144 /// Is this inset's layout defined in the document's textclass?
145 /// May be wrong after textclass change or paste from another document
146 bool undefined() const;
147 /// the string that is passed to the TOC
148 void tocString(odocstream &) const;
150 virtual docstring contextMenu(BufferView const & bv, int x, int y) 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 docstring floatName(std::string const & type) const;
162 virtual void resetParagraphsFont();
164 mutable CollapseStatus status_;
167 Dimension dimensionCollapsed(BufferView const & bv) const;
169 /// should paragraphs be forced to use the empty layout?
170 virtual bool forcePlainLayout(idx_type = 0) const
171 { return getLayout().forcePlainLayout(); }
172 /// should the user be allowed to customize alignment, etc.?
173 virtual bool allowParagraphCustomization(idx_type = 0) const
174 { return getLayout().allowParagraphCustomization(); }
175 docstring labelstring_;
177 mutable Box button_dim;
178 /// a substatus of the Open status, determined automatically in metrics
179 mutable bool openinlined_;
180 /// the inset will automatically open when the cursor is inside. This is
181 /// dependent on the bufferview, compare with MathMacro::editing_.
182 mutable std::map<BufferView const *, bool> auto_open_;
183 /// changes color when mouse enters/leaves this inset