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"
28 /** A collapsable text inset
31 class InsetCollapsable : public InsetText {
34 static int const TEXT_TO_TOP_OFFSET = 2;
36 static int const TEXT_TO_BOTTOM_OFFSET = 2;
44 InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
46 void read(Buffer const &, LyXLex &);
48 void write(Buffer const &, std::ostream &) const;
50 void metrics(MetricsInfo &, Dimension &) const;
52 void draw(PainterInfo & pi, int x, int y) const;
54 void drawSelection(PainterInfo & pi, int x, int y) const;
55 /// return x,y of given position relative to the inset's baseline
56 void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
58 bool hitButton(FuncRequest const &) const;
60 std::string const getNewLabel(std::string const & l) const;
62 EDITABLE editable() const;
63 /// can we go further down on mouse click?
64 bool descendable() const;
66 bool isTextInset() const { return true; }
68 void setLabel(std::string const & l);
70 virtual void setButtonLabel() {}
72 void setLabelFont(LyXFont & f);
74 int scroll(bool recursive = true) const;
76 void scroll(BufferView & bv, double sx) const;
78 void scroll(BufferView & bv, int offset) const;
80 bool isOpen() const { return status_ == Open || status_ == Inlined; }
82 bool inlined() const { return status_ == Inlined; }
84 CollapseStatus status() const { return status_; }
90 bool allowSpellCheck() const { return true; }
92 bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
96 void setStatus(CollapseStatus st);
98 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
100 Dimension dimensionCollapsed() const;
102 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
104 Box const & buttonDim() const;
106 void edit(LCursor & cur, bool left);
108 InsetBase * editXY(LCursor & cur, int x, int y) const;
114 mutable Box button_dim;
118 mutable int topbaseline;
120 mutable std::string label;
123 mutable CollapseStatus status_;
124 /// a substatus of the Open status, determined automatically in metrics
125 mutable bool openinlined_;
127 mutable Dimension textdim_;
130 // A helper function that pushes the cursor out of the inset.
131 void leaveInset(LCursor & cur, InsetBase const & in);