]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
a662c6bc18a984cd639f34a41d355ae9b45dfd14
[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 LyXCursor;
27
28 /** A collapsable text inset
29
30 */
31 class InsetCollapsable : public UpdatableInset {
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                 Open,
40                 Collapsed,
41                 Inlined
42         };
43         /// inset is initially collapsed if bool = true
44         InsetCollapsable(BufferParams const &, bool collapsed = false);
45         ///
46         InsetCollapsable(InsetCollapsable const & in);
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         bool hitButton(FuncRequest const &) const;
57         ///
58         std::string const getNewLabel(std::string const & l) const;
59         ///
60         EDITABLE editable() const;
61         /// can we go further down on mouse click?
62         bool descendable() const;
63         ///
64         bool insertInset(BufferView *, InsetOld * inset);
65         ///
66         bool insetAllowed(InsetOld::Code code) const;
67         ///
68         bool isTextInset() const { return true; }
69         ///
70         int latex(Buffer const &, std::ostream &,
71                   OutputParams const &) const;
72         ///
73         int plaintext(Buffer const &, std::ostream &,
74                   OutputParams const &) const;
75         ///
76         int linuxdoc(Buffer const &, std::ostream &,
77                      OutputParams const &) const;
78         ///
79         int docbook(Buffer const &, std::ostream &,
80                     OutputParams const & runparams) const;
81         ///
82         void validate(LaTeXFeatures & features) const;
83         /// get the screen x,y of the cursor
84         void getCursorPos(int & x, int & y) const;
85         ///
86         void setLabel(std::string const & l) const;
87         ///
88         void setLabelFont(LyXFont & f);
89 #if 0
90         ///
91         void setAutoCollapse(bool f);
92 #endif
93         /// Appends \c list with all labels found within this inset.
94         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
95         ///
96         int scroll(bool recursive=true) const;
97         ///
98         void scroll(BufferView *bv, float sx) const;
99         ///
100         void scroll(BufferView *bv, int offset) const;
101         ///
102         ParagraphList * getParagraphs(int) const;
103         ///
104         int numParagraphs() const;
105         ///
106         LyXText * getText(int) const;
107         ///
108         bool isOpen() const { return status_ == Open || status_ == Inlined; }
109         ///
110         bool inlined() const { return status_ == Inlined; }
111         ///
112         CollapseStatus status() const { return status_; }
113         ///
114         void open();
115         ///
116         void close();
117         ///
118         void markErased();
119         ///
120         void addPreview(lyx::graphics::PreviewLoader &) const;
121         ///
122         void setBackgroundColor(LColor_color);
123         ///
124         virtual void setStatus(CollapseStatus st);
125
126 protected:
127         ///
128         virtual
129         DispatchResult
130         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
131         ///
132         void dimension_collapsed(Dimension &) const;
133         ///
134         int height_collapsed() const;
135         ///
136         void draw_collapsed(PainterInfo & pi, int x, int y) const;
137         ///
138         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
139         ///
140         Box const & buttonDim() const;
141         ///
142         void edit(BufferView *, bool);
143         ///
144         void edit(BufferView *, int, int);
145
146 private:
147         ///
148         DispatchResult lfunMouseRelease(FuncRequest const &);
149         ///
150         FuncRequest adjustCommand(FuncRequest const &);
151
152 public:
153         ///
154         mutable InsetText inset;
155 protected:
156         ///
157         mutable CollapseStatus status_;
158         ///
159         LyXFont labelfont_;
160         ///
161         mutable Box button_dim;
162         ///
163         mutable int topx;
164         ///
165         mutable int topbaseline;
166         ///
167         mutable std::string label;
168 #if 0
169         ///
170         bool autocollapse;
171 #endif
172 };
173
174 #endif