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