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 & 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;
59 int topOffset(BufferView const * bv) const;
61 int bottomOffset(BufferView const * bv) const;
64 void metrics(MetricsInfo &, Dimension &) const;
66 void draw(PainterInfo & pi, int x, int y) const;
68 virtual void drawBackground(PainterInfo &, int, int) const {}
70 /// return x,y of given position relative to the inset's baseline
71 void cursorPos(BufferView const & bv, CursorSlice const & sl,
72 bool boundary, int & x, int & y) const;
74 docstring const getNewLabel(docstring const & l) const;
76 bool editable() const;
78 bool hasSettings() const { return true; }
79 /// Returns true if coordinates are over the inset's button.
80 /// Always returns false when the inset does not have a
82 bool clickable(BufferView const & bv, int x, int y) const;
83 /// can we go further down on mouse click?
84 bool descendable(BufferView const & bv) const;
86 void setLabel(docstring const & l);
88 docstring getLabel() const;
90 virtual void setButtonLabel() {}
92 virtual docstring const buttonLabel(BufferView const &) const;
94 bool isOpen(BufferView const & bv) const
95 { return geometry(bv) != ButtonOnly; }
102 virtual void setStatus(Cursor & cur, CollapseStatus st);
104 CollapseStatus status(BufferView const & bv) const;
105 /** Of the old CollapseStatus we only keep the values
106 * Open and Collapsed.
107 * We define a list of possible inset decoration
108 * styles, and a list of possible (concrete, visual)
109 * inset geometries. Relationships between them
110 * (geometries in body of table):
113 * Decoration: \ Open Collapsed
114 * -------------+-------------------------------
115 * Classic | *) TopButton, <--x) ButtonOnly
117 * Minimalistic | NoButton ButtonOnly
118 * Conglomerate | SubLabel Corners
119 * ---------------------------------------------
120 * *) toggled by openinlined_
121 * x) toggled by auto_open_
125 virtual InsetLayout::InsetDecoration decoration() const;
127 virtual FontInfo getFont() const { return getLayout().font(); }
129 virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
139 /// Returns the geometry based on CollapseStatus
140 /// (status_), auto_open_[BufferView] and openinlined_,
141 /// and of course decoration().
142 Geometry geometry(BufferView const & bv) const;
144 bool canPaintChange(BufferView const & bv) const;
146 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
148 bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
150 ColorCode backgroundColor(PainterInfo const &) const
151 { return getLayout().bgcolor(); }
153 ColorCode labelColor() const { return getLayout().labelfont().color(); }
155 InsetCode lyxCode() const { return COLLAPSIBLE_CODE; }
158 virtual bool usePlainLayout() const { return true; }
160 std::string contextMenu(BufferView const & bv, int x, int y) const;
162 std::string contextMenuName() const;
164 void addToToc(DocIterator const & dit, bool output_active,
165 UpdateType utype, TocBackend & backend) const; //override
169 void doDispatch(Cursor & cur, FuncRequest & cmd);
171 void edit(Cursor & cur, bool front,
172 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
174 Inset * editXY(Cursor & cur, int x, int y);
176 mutable CollapseStatus status_;
178 unique_ptr<support::TempFile> tempfile_;
181 Dimension dimensionCollapsed(BufferView const & bv) const;
183 docstring labelstring_;
185 // These variables depend of the view in which the inset is displayed
188 /// The dimension of the inset button
190 /// a substatus of the Open status, determined automatically in metrics
192 /// the inset will automatically open when the cursor is inside. This is
193 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
195 /// changes color when mouse enters/leaves this inset
200 mutable std::map<BufferView const *, View> view_;