3 * \file InsetCollapsible.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 INSETCOLLAPSIBLE_H
15 #define INSETCOLLAPSIBLE_H
17 #include "InsetText.h"
28 namespace support { class TempFile; }
30 namespace frontend { class Painter; }
32 /** A collapsible text inset
35 class InsetCollapsible : public InsetText {
38 InsetCollapsible(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
40 InsetCollapsible(InsetCollapsible const & rhs);
42 InsetCollapsible const & operator=(InsetCollapsible const &);
44 virtual ~InsetCollapsible();
46 InsetCollapsible * asInsetCollapsible() { return this; }
48 InsetCollapsible const * asInsetCollapsible() const { return this; }
50 docstring toolTip(BufferView const & bv, int x, int y) const;
52 docstring layoutName() const { return from_ascii("Collapsible"); }
56 void write(std::ostream &) const;
58 void metrics(MetricsInfo &, Dimension &) const;
60 void draw(PainterInfo & pi, int x, int y) const;
62 virtual void drawBackground(PainterInfo &, int, int) const {}
64 /// return x,y of given position relative to the inset's baseline
65 void cursorPos(BufferView const & bv, CursorSlice const & sl,
66 bool boundary, int & x, int & y) const;
68 docstring const getNewLabel(docstring const & l) const;
70 bool editable() const;
72 bool hasSettings() const { return true; }
73 /// Returns true if coordinates are over the inset's button.
74 /// Always returns false when the inset does not have a
76 bool clickable(BufferView const & bv, int x, int y) const;
77 /// can we go further down on mouse click?
78 bool descendable(BufferView const & bv) const;
80 void setLabel(docstring const & l);
82 docstring getLabel() const;
84 virtual void setButtonLabel() {}
86 virtual docstring const buttonLabel(BufferView const &) const;
88 bool isOpen(BufferView const & bv) const
89 { return geometry(bv) != ButtonOnly; }
96 virtual void setStatus(Cursor & cur, CollapseStatus st);
98 CollapseStatus status(BufferView const & bv) const;
99 /** Of the old CollapseStatus we only keep the values
100 * Open and Collapsed.
101 * We define a list of possible inset decoration
102 * styles, and a list of possible (concrete, visual)
103 * inset geometries. Relationships between them
104 * (geometries in body of table):
107 * Decoration: \ Open Collapsed
108 * -------------+-------------------------------
109 * Classic | *) TopButton, <--x) ButtonOnly
111 * Minimalistic | NoButton ButtonOnly
112 * Conglomerate | SubLabel Corners
113 * ---------------------------------------------
114 * *) toggled by openinlined_
115 * x) toggled by auto_open_
119 virtual InsetLayout::InsetDecoration decoration() const;
121 virtual FontInfo getFont() const { return getLayout().font(); }
123 virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
133 /// Returns the geometry based on CollapseStatus
134 /// (status_), auto_open_[BufferView] and openinlined_,
135 /// and of course decoration().
136 Geometry geometry(BufferView const & bv) const;
138 bool canPaintChange(BufferView const & bv) const;
140 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
142 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
144 ColorCode backgroundColor(PainterInfo const &) const
145 { return getLayout().bgcolor(); }
147 ColorCode labelColor() const { return getLayout().labelfont().color(); }
149 InsetCode lyxCode() const { return COLLAPSIBLE_CODE; }
152 virtual bool usePlainLayout() const { return true; }
154 std::string contextMenu(BufferView const & bv, int x, int y) const;
156 std::string contextMenuName() const;
158 void addToToc(DocIterator const & dit, bool output_active,
159 UpdateType utype, TocBackend & backend) const; //override
163 void doDispatch(Cursor & cur, FuncRequest & cmd);
165 void edit(Cursor & cur, bool front,
166 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
168 Inset * editXY(Cursor & cur, int x, int y);
170 mutable CollapseStatus status_;
172 unique_ptr<support::TempFile> tempfile_;
175 Dimension dimensionCollapsed(BufferView const & bv) const;
177 docstring labelstring_;
179 // These variables depend of the view in which the inset is displayed
182 /// The dimension of the inset button
184 /// a substatus of the Open status, determined automatically in metrics
186 /// the inset will automatically open when the cursor is inside. This is
187 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
189 /// changes color when mouse enters/leaves this inset
194 mutable std::map<BufferView const *, View> view_;