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;
129 virtual FontInfo getFont() const;
131 virtual FontInfo getLabelfont() const;
141 /// Returns the geometry based on CollapseStatus
142 /// (status_), auto_open_[BufferView] and openinlined_,
143 /// and of course decoration().
144 Geometry geometry(BufferView const & bv) const;
146 bool canPaintChange(BufferView const & bv) const override;
148 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const override;
150 bool setMouseHover(BufferView const * bv, bool mouse_hover) const override;
152 ColorCode backgroundColor(PainterInfo const &) const override;
154 ColorCode labelColor() const override;
156 InsetCode lyxCode() const override { return COLLAPSIBLE_CODE; }
159 bool usePlainLayout() const override { return true; }
161 std::string contextMenu(BufferView const & bv, int x, int y) const override;
163 std::string contextMenuName() const override;
165 void addToToc(DocIterator const & dit, bool output_active,
166 UpdateType utype, TocBackend & backend) const override;
170 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
172 void edit(Cursor & cur, bool front,
173 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
175 Inset * editXY(Cursor & cur, int x, int y) override;
177 mutable CollapseStatus status_;
179 unique_ptr<support::TempFile> tempfile_;
182 Dimension dimensionCollapsed(BufferView const & bv) const;
184 docstring labelstring_;
186 // These variables depend of the view in which the inset is displayed
189 /// The dimension of the inset button
191 /// a substatus of the Open status, determined automatically in metrics
193 /// the inset will automatically open when the cursor is inside. This is
194 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
196 /// changes color when mouse enters/leaves this inset
201 mutable std::map<BufferView const *, View> view_;