]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
a8e365ffbd88edb0f01b4f9c90313d3dcdec2c19
[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         /// inset is initially collapsed if bool = true
38         InsetCollapsable(BufferParams const &, bool collapsed = false);
39         ///
40         InsetCollapsable(InsetCollapsable const & in);
41         ///
42         void read(Buffer const &, LyXLex &);
43         ///
44         void write(Buffer const &, std::ostream &) const;
45         ///
46         void metrics(MetricsInfo &, Dimension &) const;
47         ///
48         void draw(PainterInfo & pi, int x, int y) const;
49         /// draw, either inlined (no button) or collapsed/open
50         void draw(PainterInfo & pi, int x, int y, bool inlined) const;
51         ///
52         bool hitButton(FuncRequest const &) const;
53         ///
54         EDITABLE editable() const;
55         ///
56         bool insertInset(BufferView *, InsetOld * inset);
57         ///
58         virtual bool insetAllowed(InsetOld::Code code) const;
59         ///
60         bool isTextInset() const;
61         ///
62         void insetUnlock(BufferView *);
63         ///
64         bool lockInsetInInset(BufferView *, UpdatableInset *);
65         ///
66         bool unlockInsetInInset(BufferView *, UpdatableInset *,
67                                 bool lr = false);
68         ///
69         int insetInInsetY() const;
70         ///
71         int latex(Buffer const &, std::ostream &,
72                   LatexRunParams const &) const;
73         ///
74         int ascii(Buffer const &, std::ostream &, int) const;
75         ///
76         int linuxdoc(Buffer const &, std::ostream &) const;
77         ///
78         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
79         ///
80         void validate(LaTeXFeatures & features) const;
81         /// FIXME, document
82         void getCursorPos(BufferView *, int & x, int & y) const;
83         /// Get the absolute document x,y of the cursor
84         virtual void getCursor(BufferView &, int &, int &) const;
85         ///
86         void fitInsetCursor(BufferView * bv) const;
87         ///
88         UpdatableInset * getLockingInset() const;
89         ///
90         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
91         ///
92         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
93                  bool selectall = false);
94         ///
95         void setLabel(std::string const & l) const;
96         ///
97         void setLabelFont(LyXFont & f);
98 #if 0
99         ///
100         void setAutoCollapse(bool f);
101 #endif
102         ///
103         LyXText * getLyXText(BufferView const *, bool const recursive) const;
104         ///
105         void deleteLyXText(BufferView *, bool recursive=true) const;
106         /// Appends \c list with all labels found within this inset.
107         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
108         ///
109         int scroll(bool recursive=true) const;
110         ///
111         void scroll(BufferView *bv, float sx) const;
112         ///
113         void scroll(BufferView *bv, int offset) const;
114         ///
115         InsetOld * getInsetFromID(int id) const;
116         ///
117         ParagraphList * getParagraphs(int) const;
118         ///
119         LyXText * getText(int) const;
120         ///
121         LyXCursor const & cursor(BufferView *) const;
122         ///
123         virtual bool display() const { return isOpen(); }
124         ///
125         bool isOpen() const;
126         ///
127         void open(BufferView *);
128         ///
129         void close(BufferView *) const;
130         ///
131         bool allowSpellcheck() const;
132         ///
133         WordLangTuple const
134         selectNextWordToSpellcheck(BufferView *, float &) const;
135         ///
136         void selectSelectedWord(BufferView *);
137
138         void markErased();
139
140         bool nextChange(BufferView * bv, lyx::pos_type & length);
141
142         ///
143         bool searchForward(BufferView * bv, std::string const & str,
144                            bool = true, bool = false);
145         bool searchBackward(BufferView * bv, std::string const & str,
146                             bool = true, bool = false);
147
148         ///
149         void addPreview(lyx::graphics::PreviewLoader &) const;
150
151 protected:
152         ///
153         virtual
154         DispatchResult
155         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
156         ///
157         void dimension_collapsed(Dimension &) const;
158         ///
159         int height_collapsed() const;
160         ///
161         void draw_collapsed(PainterInfo & pi, int x, int y) const;
162         ///
163         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
164         /// Should be non-const...
165         void setCollapsed(bool) const;
166         ///
167         Box const & buttonDim() const;
168
169 private:
170         ///
171         void lfunMouseRelease(FuncRequest const &);
172         ///
173         FuncRequest adjustCommand(FuncRequest const &);
174         ///
175         void edit(BufferView *, int index);
176
177 public:
178         ///
179         mutable InsetText inset;
180 private:
181         ///
182         mutable bool collapsed_;
183         ///
184         LyXFont labelfont_;
185         ///
186         mutable Box button_dim;
187         ///
188         mutable int topx;
189         mutable int topbaseline;
190
191         ///
192         mutable std::string label;
193 #if 0
194         ///
195         bool autocollapse;
196 #endif
197         ///
198         bool in_update;
199         ///
200         mutable bool first_after_edit;
201 };
202
203
204 inline
205 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
206 {
207         return inset.insetAllowed(code);
208 }
209
210
211 inline
212 bool InsetCollapsable::isTextInset() const
213 {
214         return true;
215 }
216
217
218 inline
219 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
220 {
221         inset.fitInsetCursor(bv);
222 }
223
224 inline
225 void InsetCollapsable::setLabelFont(LyXFont & f)
226 {
227         labelfont_ = f;
228 }
229
230 #if 0
231 inline
232 void InsetCollapsable::setAutoCollapse(bool f)
233 {
234         autocollapse = f;
235 }
236 #endif
237
238 inline
239 void InsetCollapsable::scroll(BufferView *bv, float sx) const
240 {
241         UpdatableInset::scroll(bv, sx);
242 }
243
244
245 inline
246 void InsetCollapsable::scroll(BufferView *bv, int offset) const
247 {
248         UpdatableInset::scroll(bv, offset);
249 }
250
251
252 inline
253 bool InsetCollapsable::isOpen() const
254 {
255         return !collapsed_;
256 }
257
258
259 inline
260 bool InsetCollapsable::allowSpellcheck() const
261 {
262         return inset.allowSpellcheck();
263 }
264
265
266 inline
267 void InsetCollapsable::selectSelectedWord(BufferView * bv)
268 {
269         inset.selectSelectedWord(bv);
270 }
271
272
273 inline
274 Box const & InsetCollapsable::buttonDim() const
275 {
276         return button_dim;
277 }
278
279 #endif