]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
e641701ca63fcb829dc99757501c6d70d45c0af6
[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         dispatch_result localDispatch(FuncRequest const &);
72         ///
73         int latex(Buffer const &, std::ostream &,
74                   LatexRunParams const &) const;
75         ///
76         int ascii(Buffer const &, std::ostream &, int) const;
77         ///
78         int linuxdoc(Buffer const &, std::ostream &) const;
79         ///
80         int docbook(Buffer const &, std::ostream &, bool mixcont) const;
81         ///
82         void validate(LaTeXFeatures & features) const;
83         /// FIXME, document
84         void getCursorPos(BufferView *, int & x, int & y) const;
85         /// Get the absolute document x,y of the cursor
86         virtual void getCursor(BufferView &, int &, int &) const;
87         ///
88         void fitInsetCursor(BufferView * bv) const;
89         ///
90         UpdatableInset * getLockingInset() const;
91         ///
92         UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
93         ///
94         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
95                  bool selectall = false);
96         ///
97         void setLabel(std::string const & l) const;
98         ///
99         void setLabelFont(LyXFont & f);
100 #if 0
101         ///
102         void setAutoCollapse(bool f);
103 #endif
104         ///
105         LyXText * getLyXText(BufferView const *, bool const recursive) const;
106         ///
107         void deleteLyXText(BufferView *, bool recursive=true) const;
108         /// Appends \c list with all labels found within this inset.
109         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
110         ///
111         int scroll(bool recursive=true) const;
112         ///
113         void scroll(BufferView *bv, float sx) const;
114         ///
115         void scroll(BufferView *bv, int offset) const;
116         ///
117         InsetOld * getInsetFromID(int id) const;
118         ///
119         ParagraphList * getParagraphs(int) const;
120         ///
121         LyXText * getText(int) const;
122         ///
123         LyXCursor const & cursor(BufferView *) const;
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         void dimension_collapsed(Dimension &) const;
154         ///
155         int height_collapsed() const;
156         ///
157         void draw_collapsed(PainterInfo & pi, int x, int y) const;
158         ///
159         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
160         /// Should be non-const...
161         void setCollapsed(bool) const;
162         ///
163         Box const & buttonDim() const;
164
165 private:
166         ///
167         void lfunMouseRelease(FuncRequest const &);
168         ///
169         FuncRequest adjustCommand(FuncRequest const &);
170         ///
171         void edit(BufferView *, int index);
172
173 public:
174         ///
175         mutable InsetText inset;
176 private:
177         ///
178         mutable bool collapsed_;
179         ///
180         LyXFont labelfont_;
181         ///
182         mutable Box button_dim;
183         ///
184         mutable int topx;
185         mutable int topbaseline;
186
187         ///
188         mutable std::string label;
189 #if 0
190         ///
191         bool autocollapse;
192 #endif
193         ///
194         bool in_update;
195         ///
196         mutable bool first_after_edit;
197 };
198
199
200 inline
201 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
202 {
203         return inset.insetAllowed(code);
204 }
205
206
207 inline
208 bool InsetCollapsable::isTextInset() const
209 {
210         return true;
211 }
212
213
214 inline
215 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
216 {
217         inset.fitInsetCursor(bv);
218 }
219
220 inline
221 void InsetCollapsable::setLabelFont(LyXFont & f)
222 {
223         labelfont_ = f;
224 }
225
226 #if 0
227 inline
228 void InsetCollapsable::setAutoCollapse(bool f)
229 {
230         autocollapse = f;
231 }
232 #endif
233
234 inline
235 void InsetCollapsable::scroll(BufferView *bv, float sx) const
236 {
237         UpdatableInset::scroll(bv, sx);
238 }
239
240
241 inline
242 void InsetCollapsable::scroll(BufferView *bv, int offset) const
243 {
244         UpdatableInset::scroll(bv, offset);
245 }
246
247
248 inline
249 bool InsetCollapsable::isOpen() const
250 {
251         return !collapsed_;
252 }
253
254
255 inline
256 bool InsetCollapsable::allowSpellcheck() const
257 {
258         return inset.allowSpellcheck();
259 }
260
261
262 inline
263 void InsetCollapsable::selectSelectedWord(BufferView * bv)
264 {
265         inset.selectSelectedWord(bv);
266 }
267
268
269 inline
270 Box const & InsetCollapsable::buttonDim() const
271 {
272         return button_dim;
273 }
274
275 #endif