]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Fix linking issue with MacOSX.
[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 #include <string>
24
25 class LyXText;
26 class Paragraph;
27 class CursorSlice;
28
29 namespace lyx {
30 namespace frontend {
31 class Painter;
32 }
33 }
34
35
36 /** A collapsable text inset
37
38 */
39 class InsetCollapsable : public InsetText {
40 public:
41         ///
42         static int const TEXT_TO_TOP_OFFSET = 2;
43         ///
44         static int const TEXT_TO_BOTTOM_OFFSET = 2;
45         ///
46         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
47         ///
48         void read(Buffer const &, LyXLex &);
49         ///
50         void write(Buffer const &, std::ostream &) const;
51         ///
52         void metrics(MetricsInfo &, Dimension &) const;
53         ///
54         void draw(PainterInfo & pi, int x, int y) const;
55         ///
56         void drawSelection(PainterInfo & pi, int x, int y) const;
57         /// return x,y of given position relative to the inset's baseline
58         void cursorPos(CursorSlice const & sl, bool boundary, int & x, int & y) const;
59         ///
60         bool hitButton(FuncRequest const &) const;
61         ///
62         std::string const getNewLabel(std::string const & l) const;
63         ///
64         EDITABLE editable() const;
65         /// can we go further down on mouse click?
66         bool descendable() const;
67         ///
68         void setLabel(std::string const & l);
69         ///
70         virtual void setButtonLabel() {}
71         ///
72         void setLabelFont(LyXFont & f);
73         ///
74         bool isOpen() const { return status_ == Open || status_ == Inlined; }
75         ///
76         bool inlined() const { return status_ == Inlined; }
77         ///
78         CollapseStatus status() const;
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         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
89         ///
90         Dimension dimensionCollapsed() const;
91         ///
92         Box const & buttonDim() const;
93         ///
94         void edit(LCursor & cur, bool left);
95         ///
96         InsetBase * editXY(LCursor & cur, int x, int y);
97         ///
98         void setInlined() { status_ = Inlined; }
99         ///
100         std::string floatName(std::string const & type, BufferParams const &);
101
102 protected:
103         ///
104         LyXFont labelfont_;
105         ///
106         mutable Box button_dim;
107         ///
108         mutable int topx;
109         ///
110         mutable int topbaseline;
111         ///
112         mutable std::string label;
113 private:
114         ///
115         mutable CollapseStatus status_;
116         /// a substatus of the Open status, determined automatically in metrics
117         mutable bool openinlined_;
118         /// the inset will automatically open when the cursor is inside
119         mutable bool autoOpen_;
120         ///
121         mutable Dimension textdim_;
122 };
123
124 // A helper function that pushes the cursor out of the inset.
125 void leaveInset(LCursor & cur, InsetBase const & in);
126
127 #endif