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