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