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 virtual void drawBackground(PainterInfo &, int, int) const {}
60 /// return x,y of given position relative to the inset's baseline
61 void cursorPos(BufferView const & bv, CursorSlice const & sl,
62 bool boundary, int & x, int & y) const;
64 docstring const getNewLabel(docstring const & l) const;
66 bool editable() const;
68 bool hasSettings() const { return true; }
69 /// Returns true if coordinates are over the inset's button.
70 /// Always returns false when the inset does not have a
72 bool clickable(BufferView const & bv, 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 docstring getLabel() const;
80 virtual void setButtonLabel() {}
82 virtual docstring const buttonLabel(BufferView const &) const;
84 bool isOpen(BufferView const & bv) const
85 { return geometry(bv) != ButtonOnly; }
92 virtual void setStatus(Cursor & cur, CollapseStatus st);
94 CollapseStatus status(BufferView const & bv) const;
95 /** Of the old CollapseStatus we only keep the values
97 * We define a list of possible inset decoration
98 * styles, and a list of possible (concrete, visual)
99 * inset geometries. Relationships between them
100 * (geometries in body of table):
103 * Decoration: \ Open Collapsed
104 * -------------+-------------------------------
105 * Classic | *) TopButton, <--x) ButtonOnly
107 * Minimalistic | NoButton ButtonOnly
108 * Conglomerate | SubLabel Corners
109 * ---------------------------------------------
110 * *) toggled by openinlined_
111 * x) toggled by auto_open_
115 virtual InsetLayout::InsetDecoration decoration() const;
117 virtual FontInfo getFont() const { return getLayout().font(); }
119 virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
129 /// Returns the geometry based on CollapseStatus
130 /// (status_), auto_open_[BufferView] and openinlined_,
131 /// and of course decoration().
132 Geometry geometry(BufferView const & bv) const;
134 bool canPaintChange(BufferView const & bv) const;
136 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
138 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
140 ColorCode backgroundColor(PainterInfo const &) const
141 { return getLayout().bgcolor(); }
143 ColorCode labelColor() const { return getLayout().labelfont().color(); }
145 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
148 virtual bool usePlainLayout() const { return true; }
150 std::string contextMenu(BufferView const & bv, int x, int y) const;
152 std::string contextMenuName() const;
154 void addToToc(DocIterator const & dit, bool output_active,
155 UpdateType utype, TocBackend & backend) const; //override
159 void doDispatch(Cursor & cur, FuncRequest & cmd);
161 void edit(Cursor & cur, bool front,
162 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
164 Inset * editXY(Cursor & cur, int x, int y);
166 mutable CollapseStatus status_;
169 Dimension dimensionCollapsed(BufferView const & bv) const;
171 docstring labelstring_;
173 // These variables depend of the view in which the inset is displayed
176 /// The dimension of the inset button
178 /// a substatus of the Open status, determined automatically in metrics
180 /// the inset will automatically open when the cursor is inside. This is
181 /// dependent on the bufferview, compare with MathMacro::editing_.
183 /// changes color when mouse enters/leaves this inset
188 mutable std::map<BufferView const *, View> view_;