]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[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 LyXText;
24 class Paragraph;
25 class CursorSlice;
26
27 namespace lyx {
28 namespace frontend {
29 class Painter;
30 }
31 }
32
33
34 /** A collapsable text inset
35
36 */
37 class InsetCollapsable : public InsetText {
38 public:
39         ///
40         static int const TEXT_TO_TOP_OFFSET = 2;
41         ///
42         static int const TEXT_TO_BOTTOM_OFFSET = 2;
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 cursorPos(CursorSlice const & sl, bool boundary, 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         void setLabel(std::string const & l);
67         ///
68         virtual void setButtonLabel() {}
69         ///
70         void setLabelFont(LyXFont & f);
71         ///
72         bool isOpen() const { return status_ == Open || status_ == Inlined; }
73         ///
74         bool inlined() const { return status_ == Inlined; }
75         ///
76         CollapseStatus status() const;
77         ///
78         bool allowSpellCheck() const { return true; }
79         ///
80         bool getStatus(LCursor &, FuncRequest const &, FuncStatus &) const;
81         ///
82         void setStatus(LCursor & cur, CollapseStatus st);
83
84 protected:
85         ///
86         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
87         ///
88         Dimension dimensionCollapsed() const;
89         ///
90         Box const & buttonDim() const;
91         ///
92         void edit(LCursor & cur, bool left);
93         ///
94         InsetBase * editXY(LCursor & cur, int x, int y);
95         ///
96         void setInlined() { status_ = Inlined; }
97
98 protected:
99         ///
100         LyXFont labelfont_;
101         ///
102         mutable Box button_dim;
103         ///
104         mutable int topx;
105         ///
106         mutable int topbaseline;
107         ///
108         mutable std::string label;
109 private:
110         ///
111         mutable CollapseStatus status_;
112         /// a substatus of the Open status, determined automatically in metrics
113         mutable bool openinlined_;
114         /// the inset will automatically open when the cursor is inside
115         mutable bool autoOpen_;
116         ///
117         mutable Dimension textdim_;
118 };
119
120 // A helper function that pushes the cursor out of the inset.
121 void leaveInset(LCursor & cur, InsetBase const & in);
122
123 #endif