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 void read(Buffer const &, LyXLex &);
49 void write(Buffer const &, std::ostream &) const;
51 bool metrics(MetricsInfo &, Dimension &) const;
53 void draw(PainterInfo & pi, int x, int y) const;
55 void drawSelection(PainterInfo & pi, int x, int y) const;
56 /// return x,y of given position relative to the inset's baseline
57 void cursorPos(BufferView const & bv, CursorSlice const & sl,
58 bool boundary, int & x, int & y) const;
60 bool hitButton(FuncRequest const &) const;
62 docstring const getNewLabel(docstring const & l) const;
64 EDITABLE editable() const;
65 /// can we go further down on mouse click?
66 bool descendable() const;
68 void setLabel(docstring const & l);
70 virtual void setButtonLabel() {}
72 void setLabelFont(LyXFont & f);
74 bool isOpen() const { return status_ == Open || status_ == Inlined; }
76 bool inlined() const { return status_ == Inlined; }
78 CollapseStatus status() const;
80 bool allowSpellCheck() const { return true; }
82 bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
84 void setStatus(LCursor & cur, CollapseStatus st);
86 bool setMouseHover(bool mouse_hover);
90 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
92 Dimension dimensionCollapsed() const;
94 Box const & buttonDim() const;
96 void edit(LCursor & cur, bool left);
98 InsetBase * editXY(LCursor & cur, int x, int y);
100 void setInlined() { status_ = Inlined; }
102 docstring floatName(std::string const & type, BufferParams const &) const;
108 mutable Box button_dim;
112 mutable int topbaseline;
114 mutable docstring label;
117 mutable CollapseStatus status_;
118 /// a substatus of the Open status, determined automatically in metrics
119 mutable bool openinlined_;
120 /// the inset will automatically open when the cursor is inside
121 mutable bool autoOpen_;
123 mutable Dimension textdim_;
124 /// changes color when mouse enters/leaves this inset
128 // A helper function that pushes the cursor out of the inset.
129 void leaveInset(LCursor & cur, InsetBase const & in);