]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
partial fix for bug 622, cosmetic rest remains open
[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         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
39         ///
40         void read(Buffer const &, LyXLex &);
41         ///
42         void write(Buffer const &, std::ostream &) const;
43         ///
44         void metrics(MetricsInfo &, Dimension &) const;
45         ///
46         void draw(PainterInfo & pi, int x, int y) const;
47         ///
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;
51         ///
52         bool hitButton(FuncRequest const &) const;
53         ///
54         std::string const getNewLabel(std::string const & l) const;
55         ///
56         EDITABLE editable() const;
57         /// can we go further down on mouse click?
58         bool descendable() const;
59         ///
60         bool isTextInset() const { return true; }
61         ///
62         void setLabel(std::string const & l);
63         ///
64         virtual void setButtonLabel() {}
65         ///
66         void setLabelFont(LyXFont & f);
67         ///
68         int scroll(bool recursive = true) const;
69         ///
70         void scroll(BufferView & bv, double sx) const;
71         ///
72         void scroll(BufferView & bv, int offset) const;
73         ///
74         bool isOpen() const { return status_ == Open || status_ == Inlined; }
75         ///
76         bool inlined() const { return status_ == Inlined; }
77         ///
78         CollapseStatus status() const { return status_; }
79         ///
80         bool allowSpellCheck() const { return true; }
81         ///
82         bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
83         ///
84         void setStatus(LCursor & cur, CollapseStatus st);
85
86 protected:
87
88         ///
89         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
90         ///
91         Dimension dimensionCollapsed() const;
92         ///
93         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
94         ///
95         Box const & buttonDim() const;
96         ///
97         void edit(LCursor & cur, bool left);
98         ///
99         InsetBase * editXY(LCursor & cur, int x, int y);
100         ///
101         void setInlined() { status_ = Inlined; }
102
103 protected:
104         ///
105         LyXFont labelfont_;
106         ///
107         mutable Box button_dim;
108         ///
109         mutable int topx;
110         ///
111         mutable int topbaseline;
112         ///
113         mutable std::string label;
114 private:
115         ///
116         mutable CollapseStatus status_;
117         /// a substatus of the Open status, determined automatically in metrics
118         mutable bool openinlined_;
119         ///
120         mutable Dimension textdim_;
121 };
122
123 // A helper function that pushes the cursor out of the inset.
124 void leaveInset(LCursor & cur, InsetBase const & in);
125
126 #endif