3 * \file InsetCollapsable.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 INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
18 #include "InsetText.h"
31 namespace frontend { class Painter; }
33 /** A collapsable text inset
36 class InsetCollapsable : public InsetText {
39 static int const TEXT_TO_TOP_OFFSET = 2;
41 static int const TEXT_TO_BOTTOM_OFFSET = 2;
43 InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
45 InsetCollapsable(InsetCollapsable const & rhs);
47 docstring name() const { return from_ascii("Collapsable"); }
49 void read(Buffer const &, Lexer &);
51 void write(Buffer const &, std::ostream &) const;
53 bool metrics(MetricsInfo &, Dimension &) const;
55 void draw(PainterInfo & pi, int x, int y) const;
57 void drawSelection(PainterInfo & pi, int x, int y) const;
58 /// return x,y of given position relative to the inset's baseline
59 void cursorPos(BufferView const & bv, CursorSlice const & sl,
60 bool boundary, int & x, int & y) const;
62 bool hitButton(FuncRequest const &) const;
64 docstring const getNewLabel(docstring const & l) const;
66 EDITABLE editable() const;
67 /// can we go further down on mouse click?
68 bool descendable() const;
70 void setLabel(docstring const & l);
72 virtual void setButtonLabel() {}
74 void setLabelFont(Font & f);
76 bool isOpen() const { return status_ == Open || status_ == Inlined; }
78 bool inlined() const { return status_ == Inlined; }
80 CollapseStatus status() const;
82 bool allowSpellCheck() const { return true; }
84 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
86 void setStatus(Cursor & cur, CollapseStatus st);
88 bool setMouseHover(bool mouse_hover);
92 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
94 Dimension dimensionCollapsed() const;
96 Box const & buttonDim() const;
98 void edit(Cursor & cur, bool left);
100 Inset * editXY(Cursor & cur, int x, int y);
102 void setInlined() { status_ = Inlined; }
104 docstring floatName(std::string const & type, BufferParams const &) const;
110 mutable Box button_dim;
114 mutable int topbaseline;
116 mutable docstring label;
119 mutable CollapseStatus status_;
120 /// a substatus of the Open status, determined automatically in metrics
121 mutable bool openinlined_;
122 /// the inset will automatically open when the cursor is inside
123 mutable bool autoOpen_;
125 mutable Dimension textdim_;
126 /// changes color when mouse enters/leaves this inset
130 // A helper function that pushes the cursor out of the inset.
131 void leaveInset(Cursor & cur, Inset const & in);