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