]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
4b89a1684ed646eca63a8d75e5751714437a947a
[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
18 #include "inset.h"
19 #include "insettext.h"
20 #include "lyxfont.h"
21 #include "LColor.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 = false);
41         ///
42         InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
43         ///
44         void read(Buffer const *, LyXLex &);
45         ///
46         void write(Buffer const *, std::ostream &) const;
47         ///
48         int ascent(BufferView *, LyXFont const &) const;
49         ///
50         int descent(BufferView *, LyXFont const &) const;
51         ///
52         int width(BufferView *, LyXFont const &) const;
53         ///
54         void draw(BufferView *, const LyXFont &, int , float &) const;
55         /// draw, either inlined (no button) or collapsed/open
56         void draw(BufferView * bv, LyXFont const & f,
57                   int baseline, float & x, bool inlined) const;
58         ///
59         void update(BufferView *, bool =false);
60         ///
61         void edit(BufferView *, int, int, mouse_button::state);
62         ///
63         void edit(BufferView *, bool front = true);
64         ///
65         EDITABLE editable() const;
66         ///
67         bool insertInset(BufferView *, Inset * inset);
68         ///
69         virtual bool insetAllowed(Inset::Code code) const {
70                 return inset.insetAllowed(code);
71         }
72         ///
73         bool isTextInset() const { return true; }
74         ///
75         void insetUnlock(BufferView *);
76         ///
77         bool needFullRow() const { return isOpen(); }
78         ///
79         bool lockInsetInInset(BufferView *, UpdatableInset *);
80         ///
81         bool unlockInsetInInset(BufferView *, UpdatableInset *,
82                                 bool lr = false);
83         ///
84         bool updateInsetInInset(BufferView *, Inset *);
85         ///
86         int insetInInsetY() const;
87         ///
88         RESULT localDispatch(FuncRequest const &);
89         ///
90         int latex(Buffer const *, std::ostream &,
91                   bool fragile, bool free_spc) const;
92         ///
93         int ascii(Buffer const *, std::ostream &, int) const;
94         ///
95         int linuxdoc(Buffer const *, std::ostream &) const;
96         ///
97         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
98         ///
99         void validate(LaTeXFeatures & features) const;
100         ///
101         void getCursorPos(BufferView *, int & x, int & y) const;
102         ///
103         void toggleInsetCursor(BufferView *);
104         ///
105         void showInsetCursor(BufferView *, bool show = true);
106         ///
107         void hideInsetCursor(BufferView *);
108         ///
109         void fitInsetCursor(BufferView * bv) const {
110                 inset.fitInsetCursor(bv);
111         }
112         UpdatableInset * getLockingInset() const;
113         ///
114         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
115         ///
116         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
117                  bool selectall = false);
118         ///
119         void setLabel(string const & l) const;
120         ///
121         void setLabelFont(LyXFont & f) { labelfont = f; }
122 #if 0
123         ///
124         void setAutoCollapse(bool f) { autocollapse = f; }
125 #endif
126 #if 0
127         ///
128         int getMaxWidth(BufferView *, UpdatableInset const *) const;
129 #endif
130         ///
131         LyXText * getLyXText(BufferView const *, bool const recursive) const;
132         ///
133         void deleteLyXText(BufferView *, bool recursive=true) const;
134         ///
135         void resizeLyXText(BufferView *, bool force = false) const;
136         ///
137         std::vector<string> const getLabelList() const;
138         ///
139         bool nodraw() const;
140         ///
141         int scroll(bool recursive=true) const;
142         ///
143         void scroll(BufferView *bv, float sx) const {
144                 UpdatableInset::scroll(bv, sx);
145         }
146         ///
147         void scroll(BufferView *bv, int offset) const {
148                 UpdatableInset::scroll(bv, offset);
149         }
150         ///
151         Inset * getInsetFromID(int id) const;
152         ///
153         Paragraph * firstParagraph() const;
154         ///
155         Paragraph * getFirstParagraph(int) const;
156         ///
157         LyXCursor const & cursor(BufferView *) const;
158         ///
159         bool isOpen() const { return !collapsed_; }
160         ///
161         void open(BufferView *);
162         ///
163         void close(BufferView *) const;
164         ///
165         bool allowSpellcheck() const { return inset.allowSpellcheck(); }
166         ///
167         WordLangTuple const
168         selectNextWordToSpellcheck(BufferView *, float &) const;
169         ///
170         void selectSelectedWord(BufferView * bv) {
171                 inset.selectSelectedWord(bv);
172         }
173         ///
174         void toggleSelection(BufferView * bv, bool kill_selection) {
175                 inset.toggleSelection(bv, kill_selection);
176         }
177  
178         void markErased();
179  
180         bool nextChange(BufferView * bv, lyx::pos_type & length);
181
182         ///
183         bool searchForward(BufferView * bv, string const & str,
184                            bool = true, bool = false);
185         bool searchBackward(BufferView * bv, string const & str,
186                             bool = true, bool = false);
187
188         ///
189         void addPreview(grfx::PreviewLoader &) const;
190
191 protected:
192         ///
193         virtual void cache(BufferView *) const;
194         ///
195         virtual BufferView * view() const;
196
197         ///
198         int ascent_collapsed() const;
199         ///
200         int descent_collapsed() const;
201         ///
202         int width_collapsed() const;
203         ///
204         void draw_collapsed(Painter & pain, int , float &) const;
205         ///
206         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
207
208         ///
209         mutable bool collapsed_;
210         ///
211         LColor::color framecolor;
212         ///
213         LyXFont labelfont;
214 public:
215         ///
216         mutable InsetText inset;
217 protected:
218         ///
219         mutable int button_length;
220         ///
221         mutable int button_top_y;
222         ///
223         mutable int button_bottom_y;
224         ///
225         mutable int topx;
226         mutable int topbaseline;
227
228 private:
229         ///
230         void lfunMousePress(FuncRequest const &);
231         ///
232         bool lfunMouseRelease(FuncRequest const &);
233         ///
234         void lfunMouseMotion(FuncRequest const &);
235
236         ///
237         mutable string label;
238 #if 0
239         ///
240         bool autocollapse;
241 #endif
242         ///
243         mutable int oldWidth;
244         ///
245         bool in_update;
246         ///
247         mutable bool first_after_edit;
248         ///
249         mutable boost::weak_ptr<BufferView> view_;
250 };
251
252 #endif