]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[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 namespace lyx {
26
27 class LyXText;
28 class Paragraph;
29 class CursorSlice;
30
31 namespace frontend { class Painter; }
32
33 /** A collapsable text inset
34
35 */
36 class InsetCollapsable : public InsetText {
37 public:
38         ///
39         static int const TEXT_TO_TOP_OFFSET = 2;
40         ///
41         static int const TEXT_TO_BOTTOM_OFFSET = 2;
42         ///
43         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
44         ///
45         InsetCollapsable(InsetCollapsable const & rhs);
46         ///
47         void read(Buffer const &, LyXLex &);
48         ///
49         void write(Buffer const &, std::ostream &) const;
50         ///
51         bool metrics(MetricsInfo &, Dimension &) const;
52         ///
53         void draw(PainterInfo & pi, int x, int y) const;
54         ///
55         void drawSelection(PainterInfo & pi, int x, int y) const;
56         /// return x,y of given position relative to the inset's baseline
57         void cursorPos(BufferView const & bv, CursorSlice const & sl,
58                 bool boundary, int & x, int & y) const;
59         ///
60         bool hitButton(FuncRequest const &) const;
61         ///
62         docstring const getNewLabel(docstring 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(docstring 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         bool setMouseHover(bool mouse_hover);
87
88 protected:
89         ///
90         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
91         ///
92         Dimension dimensionCollapsed() const;
93         ///
94         Box const & buttonDim() const;
95         ///
96         void edit(LCursor & cur, bool left);
97         ///
98         InsetBase * editXY(LCursor & cur, int x, int y);
99         ///
100         void setInlined() { status_ = Inlined; }
101         /// Is the width forced to some value?
102         virtual bool hasFixedWidth() const { return false; }
103         ///
104         docstring floatName(std::string const & type, BufferParams const &);
105
106 protected:
107         ///
108         LyXFont labelfont_;
109         ///
110         mutable Box button_dim;
111         ///
112         mutable int topx;
113         ///
114         mutable int topbaseline;
115         ///
116         mutable docstring label;
117 private:
118         ///
119         mutable CollapseStatus status_;
120         /// a substatus of the Open status, determined automatically in metrics
121         mutable bool openinlined_;
122         /// the inset will automatically open when the cursor is inside
123         mutable bool autoOpen_;
124         ///
125         mutable Dimension textdim_;
126         /// changes color when mouse enters/leaves this inset
127         bool mouse_hover_;
128 };
129
130 // A helper function that pushes the cursor out of the inset.
131 void leaveInset(LCursor & cur, InsetBase const & in);
132
133 } // namespace lyx
134
135 #endif