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;
38 InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
40 void read(Buffer const &, LyXLex &);
42 void write(Buffer const &, std::ostream &) const;
44 void metrics(MetricsInfo &, Dimension &) const;
46 void draw(PainterInfo & pi, int x, int y) const;
48 void drawSelection(PainterInfo & pi, int x, int y) const;
49 /// return x,y of given position relative to the inset's baseline
50 void getCursorPos(CursorSlice const & sl, int & x, int & y) const;
52 bool hitButton(FuncRequest const &) const;
54 std::string const getNewLabel(std::string const & l) const;
56 EDITABLE editable() const;
57 /// can we go further down on mouse click?
58 bool descendable() const;
60 bool isTextInset() const { return true; }
62 void setLabel(std::string const & l);
64 virtual void setButtonLabel() {}
66 void setLabelFont(LyXFont & f);
68 int scroll(bool recursive = true) const;
70 bool isOpen() const { return status_ == Open || status_ == Inlined; }
72 bool inlined() const { return status_ == Inlined; }
74 CollapseStatus status() const { return status_; }
76 bool allowSpellCheck() const { return true; }
78 bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
80 void setStatus(LCursor & cur, CollapseStatus st);
85 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
87 Dimension dimensionCollapsed() const;
89 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
91 Box const & buttonDim() const;
93 void edit(LCursor & cur, bool left);
95 InsetBase * editXY(LCursor & cur, int x, int y);
97 void setInlined() { status_ = Inlined; }
103 mutable Box button_dim;
107 mutable int topbaseline;
109 mutable std::string label;
112 mutable CollapseStatus status_;
113 /// a substatus of the Open status, determined automatically in metrics
114 mutable bool openinlined_;
116 mutable Dimension textdim_;
119 // A helper function that pushes the cursor out of the inset.
120 void leaveInset(LCursor & cur, InsetBase const & in);