]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
implement missing getStatus methods
[lyx.git] / src / insets / insetcollapsable.h
1 // -*- C++ -*-
2 /**
3  * \file insetcollapsable.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
16
17 #include "inset.h"
18 #include "insettext.h"
19
20 #include "box.h"
21 #include "lyxfont.h"
22
23 class Painter;
24 class LyXText;
25 class Paragraph;
26 class CursorSlice;
27
28 /** A collapsable text inset
29
30 */
31 class InsetCollapsable : public InsetText {
32 public:
33         ///
34         static int const TEXT_TO_TOP_OFFSET = 2;
35         ///
36         static int const TEXT_TO_BOTTOM_OFFSET = 2;
37         ///
38         enum CollapseStatus {
39                 Collapsed,
40                 Inlined,
41                 Open
42         };
43         ///
44         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
45         ///
46         void read(Buffer const &, LyXLex &);
47         ///
48         void write(Buffer const &, std::ostream &) const;
49         ///
50         void metrics(MetricsInfo &, Dimension &) const;
51         ///
52         void draw(PainterInfo & pi, int x, int y) const;
53         ///
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;
57         ///
58         bool hitButton(FuncRequest const &) const;
59         ///
60         std::string const getNewLabel(std::string const & l) const;
61         ///
62         EDITABLE editable() const;
63         /// can we go further down on mouse click?
64         bool descendable() const;
65         ///
66         bool isTextInset() const { return true; }
67         ///
68         void setLabel(std::string const & l);
69         ///
70         virtual void setButtonLabel() {}
71         ///
72         void setLabelFont(LyXFont & f);
73         ///
74         int scroll(bool recursive = true) const;
75         ///
76         void scroll(BufferView & bv, double sx) const;
77         ///
78         void scroll(BufferView & bv, int offset) const;
79         ///
80         bool isOpen() const { return status_ == Open || status_ == Inlined; }
81         ///
82         bool inlined() const { return status_ == Inlined; }
83         ///
84         CollapseStatus status() const { return status_; }
85         ///
86         void open();
87         ///
88         void close();
89         ///
90         bool allowSpellCheck() const { return true; }
91         ///
92         bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
93
94 protected:
95         ///
96         void setStatus(CollapseStatus st);
97         ///
98         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
99         ///
100         Dimension dimensionCollapsed() const;
101         ///
102         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
103         ///
104         Box const & buttonDim() const;
105         ///
106         void edit(LCursor & cur, bool left);
107         ///
108         InsetBase * editXY(LCursor & cur, int x, int y) const;
109
110 protected:
111         ///
112         LyXFont labelfont_;
113         ///
114         mutable Box button_dim;
115         ///
116         mutable int topx;
117         ///
118         mutable int topbaseline;
119         ///
120         mutable std::string label;
121 private:
122         ///
123         mutable CollapseStatus status_;
124         /// a substatus of the Open status, determined automatically in metrics
125         mutable bool openinlined_;
126         ///
127         mutable Dimension textdim_;
128 };
129
130 // A helper function that pushes the cursor out of the inset.
131 void leaveInset(LCursor & cur, InsetBase const & in);
132
133 #endif