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"
36 /** A collapsable text inset
39 class InsetCollapsable : public InsetText {
42 static int const TEXT_TO_TOP_OFFSET = 2;
44 static int const TEXT_TO_BOTTOM_OFFSET = 2;
46 InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
48 void read(Buffer const &, LyXLex &);
50 void write(Buffer const &, std::ostream &) const;
52 void metrics(MetricsInfo &, Dimension &) const;
54 void draw(PainterInfo & pi, int x, int y) const;
56 void drawSelection(PainterInfo & pi, int x, int y) const;
57 /// return x,y of given position relative to the inset's baseline
58 void cursorPos(BufferView const & bv, CursorSlice const & sl,
59 bool boundary, int & x, int & y) const;
61 bool hitButton(FuncRequest const &) const;
63 lyx::docstring const getNewLabel(lyx::docstring const & l) const;
65 EDITABLE editable() const;
66 /// can we go further down on mouse click?
67 bool descendable() const;
69 void setLabel(lyx::docstring const & l);
71 virtual void setButtonLabel() {}
73 void setLabelFont(LyXFont & f);
75 bool isOpen() const { return status_ == Open || status_ == Inlined; }
77 bool inlined() const { return status_ == Inlined; }
79 CollapseStatus status() const;
81 bool allowSpellCheck() const { return true; }
83 bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
85 void setStatus(LCursor & cur, CollapseStatus st);
89 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
91 Dimension dimensionCollapsed() const;
93 Box const & buttonDim() const;
95 void edit(LCursor & cur, bool left);
97 InsetBase * editXY(LCursor & cur, int x, int y);
99 void setInlined() { status_ = Inlined; }
101 lyx::docstring floatName(std::string const & type, BufferParams const &);
107 mutable Box button_dim;
111 mutable int topbaseline;
113 mutable lyx::docstring label;
116 mutable CollapseStatus status_;
117 /// a substatus of the Open status, determined automatically in metrics
118 mutable bool openinlined_;
119 /// the inset will automatically open when the cursor is inside
120 mutable bool autoOpen_;
122 mutable Dimension textdim_;
125 // A helper function that pushes the cursor out of the inset.
126 void leaveInset(LCursor & cur, InsetBase const & in);