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 /** A collapsible text inset
33 class InsetCollapsible : public InsetText {
36 InsetCollapsible(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
38 InsetCollapsible(InsetCollapsible const & rhs);
40 InsetCollapsible & operator=(InsetCollapsible const &);
42 virtual ~InsetCollapsible();
44 InsetCollapsible * asInsetCollapsible() override { return this; }
46 InsetCollapsible const * asInsetCollapsible() const override { return this; }
48 docstring toolTip(BufferView const & bv, int x, int y) const override;
50 docstring layoutName() const override { return from_ascii("Collapsible"); }
52 void read(Lexer &) override;
54 void write(std::ostream &) const override;
57 int topOffset(BufferView const * bv) const override;
59 int bottomOffset(BufferView const * bv) const override;
62 void metrics(MetricsInfo &, Dimension &) const override;
64 void draw(PainterInfo & pi, int x, int y) const override;
66 void drawBackground(PainterInfo &, int, int) const override {}
68 /// return x,y of given position relative to the inset's baseline
69 void cursorPos(BufferView const & bv, CursorSlice const & sl,
70 bool boundary, int & x, int & y) const override;
72 docstring const getNewLabel(docstring const & l) const;
74 bool editable() const override;
76 bool hasSettings() const override { return true; }
77 /// Returns true if coordinates are over the inset's button.
78 /// Always returns false when the inset does not have a
80 bool clickable(BufferView const & bv, int x, int y) const override;
81 /// can we go further down on mouse click?
82 bool descendable(BufferView const & bv) const override;
84 void setLabel(docstring const & l);
86 docstring getLabel() const;
88 virtual void setButtonLabel() {}
90 virtual docstring const buttonLabel(BufferView const &) const;
92 bool isOpen(BufferView const & bv) const
93 { return geometry(bv) != ButtonOnly; }
100 virtual void setStatus(Cursor & cur, CollapseStatus st);
102 CollapseStatus status(BufferView const & bv) const;
103 /** Of the old CollapseStatus we only keep the values
104 * Open and Collapsed.
105 * We define a list of possible inset decoration
106 * styles, and a list of possible (concrete, visual)
107 * inset geometries. Relationships between them
108 * (geometries in body of table):
111 * Decoration: \ Open Collapsed
112 * -------------+-------------------------------
113 * Classic | *) TopButton, <--x) ButtonOnly
115 * Minimalistic | NoButton ButtonOnly
116 * Conglomerate | SubLabel Corners
117 * ---------------------------------------------
118 * *) toggled by openinlined_
119 * x) toggled by auto_open_
123 virtual InsetLayout::InsetDecoration decoration() const;
125 virtual FontInfo getFont() const { return getLayout().font(); }
127 virtual FontInfo getLabelfont() const { return getLayout().labelfont(); }
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
149 { return getLayout().bgcolor(); }
151 ColorCode labelColor() const override { return getLayout().labelfont().color(); }
153 InsetCode lyxCode() const override { return COLLAPSIBLE_CODE; }
156 bool usePlainLayout() const override { return true; }
158 std::string contextMenu(BufferView const & bv, int x, int y) const override;
160 std::string contextMenuName() const override;
162 void addToToc(DocIterator const & dit, bool output_active,
163 UpdateType utype, TocBackend & backend) const override;
167 void doDispatch(Cursor & cur, FuncRequest & cmd) override;
169 void edit(Cursor & cur, bool front,
170 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE) override;
172 Inset * editXY(Cursor & cur, int x, int y) override;
174 mutable CollapseStatus status_;
176 unique_ptr<support::TempFile> tempfile_;
179 Dimension dimensionCollapsed(BufferView const & bv) const;
181 docstring labelstring_;
183 // These variables depend of the view in which the inset is displayed
186 /// The dimension of the inset button
188 /// a substatus of the Open status, determined automatically in metrics
190 /// the inset will automatically open when the cursor is inside. This is
191 /// dependent on the bufferview, compare with InsetMathMacro::editing_.
193 /// changes color when mouse enters/leaves this inset
198 mutable std::map<BufferView const *, View> view_;