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