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