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"
21 #include "support/unique_ptr.h"
30 enum class InsetDecoration : int;
32 namespace support { class TempFile; }
34 /** A collapsible text inset
37 class InsetCollapsible : public InsetText {
40 InsetCollapsible(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
42 InsetCollapsible(InsetCollapsible const & rhs);
44 InsetCollapsible & operator=(InsetCollapsible const &);
46 virtual ~InsetCollapsible();
48 InsetCollapsible * asInsetCollapsible() override { return this; }
50 InsetCollapsible const * asInsetCollapsible() const override { return this; }
52 docstring toolTip(BufferView const & bv, int x, int y) const override;
54 docstring layoutName() const override { return from_ascii("Collapsible"); }
56 void read(Lexer &) override;
58 void write(std::ostream &) const override;
61 int topOffset(BufferView const * bv) const override;
63 int bottomOffset(BufferView const * bv) const override;
66 void metrics(MetricsInfo &, Dimension &) const override;
68 void draw(PainterInfo & pi, int x, int y) const override;
70 void drawBackground(PainterInfo &, int, int) const override {}
72 /// return x,y of given position relative to the inset's baseline
73 void cursorPos(BufferView const & bv, CursorSlice const & sl,
74 bool boundary, int & x, int & y) const override;
76 docstring const getNewLabel(docstring const & l) const;
78 bool editable() const override;
80 bool hasSettings() const override { return true; }
81 /// Returns true if coordinates are over the inset's button.
82 /// Always returns false when the inset does not have a
84 bool clickable(BufferView const & bv, int x, int y) const override;
85 /// can we go further down on mouse click?
86 bool descendable(BufferView const & bv) const override;
88 void setLabel(docstring const & l);
90 docstring getLabel() const;
92 virtual void setButtonLabel() {}
94 virtual docstring const buttonLabel(BufferView const &) const;
96 bool isOpen(BufferView const & bv) const
97 { return geometry(bv) != ButtonOnly; }
104 virtual void setStatus(Cursor & cur, CollapseStatus st);
106 CollapseStatus status(BufferView const & bv) const;
107 /** Of the old CollapseStatus we only keep the values
108 * Open and Collapsed.
109 * We define a list of possible inset decoration
110 * styles, and a list of possible (concrete, visual)
111 * inset geometries. Relationships between them
112 * (geometries in body of table):
115 * Decoration: \ Open Collapsed
116 * -------------+-------------------------------
117 * Classic | *) TopButton, <--x) ButtonOnly
119 * Minimalistic | NoButton ButtonOnly
120 * Conglomerate | SubLabel Corners
121 * ---------------------------------------------
122 * *) toggled by openinlined_
123 * x) toggled by auto_open_
127 virtual InsetDecoration decoration() const;
137 /// Returns the geometry based on CollapseStatus
138 /// (status_), auto_open_[BufferView] and openinlined_,
139 /// and of course decoration().
140 Geometry geometry(BufferView const & bv) const;
142 bool canPaintChange(BufferView const & bv) const override;
144 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
146 bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
148 ColorCode backgroundColor(PainterInfo const &) const override;
150 ColorCode labelColor() const override;
152 InsetCode lyxCode() const override { return COLLAPSIBLE_CODE; }
155 bool usePlainLayout() const override { return true; }
157 std::string contextMenu(BufferView const & bv, int x, int y) const override;
159 std::string contextMenuName() const override;
161 void addToToc(DocIterator const & dit, bool output_active,
162 UpdateType utype, TocBackend & backend) const override;
166 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
168 void edit(Cursor & cur, bool front,
169 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
171 Inset * editXY(Cursor & cur, int x, int y) override;
173 mutable CollapseStatus status_;
175 unique_ptr<support::TempFile> tempfile_;
178 Dimension dimensionCollapsed(BufferView const & bv) const;
180 docstring labelstring_;
182 // These variables depend of the view in which the inset is displayed
185 /// The dimension of the inset button
187 /// a substatus of the Open status, determined automatically in metrics
189 /// the inset will automatically open when the cursor is inside. This is
190 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
192 /// changes color when mouse enters/leaves this inset
197 mutable std::map<BufferView const *, View> view_;