]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
insetcharstyle drawing cosmetics
[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         bool hitButton(FuncRequest &) const;
55         ///
56         std::string const getNewLabel(std::string const & l) const;
57         ///
58         EDITABLE editable() const;
59         /// can we go further down on mouse click?
60         bool descendable() const;
61         ///
62         bool isTextInset() const { return true; }
63         ///
64         void setLabel(std::string const & l);
65         ///
66         virtual void setButtonLabel() {}
67         ///
68         void setLabelFont(LyXFont & f);
69         ///
70         int scroll(bool recursive = true) const;
71         ///
72         void scroll(BufferView & bv, float sx) const;
73         ///
74         void scroll(BufferView & bv, int offset) const;
75         ///
76         bool isOpen() const { return status_ == Open || status_ == Inlined; }
77         ///
78         bool inlined() const { return status_ == Inlined; }
79         ///
80         CollapseStatus status() const { return status_; }
81         ///
82         void open();
83         ///
84         void close();
85         ///
86         bool allowSpellCheck() const { return true; }
87
88 protected:
89         ///
90         void setStatus(CollapseStatus st);
91         ///
92         void priv_dispatch(LCursor & cur, FuncRequest & cmd);
93         ///
94         void dimension_collapsed(Dimension &) const;
95         ///
96         void draw_collapsed(PainterInfo & pi, int x, int y) const;
97         ///
98         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
99         ///
100         Box const & buttonDim() const;
101         ///
102         void edit(LCursor & cur, bool left);
103         ///
104         InsetBase * editXY(LCursor & cur, int x, int y) 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 std::string label;
117 private:
118         ///
119         mutable CollapseStatus status_;
120         /// a substatus of the Open status, determined automatically in metrics
121         mutable bool openinlined_;
122         ///
123         mutable Dimension textdim_;
124 };
125
126 // A helper function that pushes the cursor out of the inset.
127 void leaveInset(LCursor & cur, InsetBase const & in);
128
129 #endif