]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
static_cast-based key/mouse-state. Kill insetKeyPress.
[lyx.git] / src / insets / insetcollapsable.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000-2001 The LyX Team.
8  *
9  *======================================================
10  */
11
12
13 #ifndef INSETCOLLAPSABLE_H
14 #define INSETCOLLAPSABLE_H
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "inset.h"
21 #include "insettext.h"
22 #include "lyxfont.h"
23 #include "LColor.h"
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         bool insetButtonRelease(BufferView *, int, int, mouse_button::state);
93         ///
94         void insetButtonPress(BufferView *, int, int, mouse_button::state);
95         ///
96         void insetMotionNotify(BufferView *, int, int, mouse_button::state);
97         ///
98         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
99                                              string const &);
100         ///
101         int latex(Buffer const *, std::ostream &,
102                   bool fragile, bool free_spc) const;
103         ///
104         int ascii(Buffer const *, std::ostream &, int) const;
105         ///
106         int linuxdoc(Buffer const *, std::ostream &) const;
107         ///
108         int docbook(Buffer const *, std::ostream &) const;
109         ///
110         void validate(LaTeXFeatures & features) const;
111         ///
112         void getCursorPos(BufferView *, int & x, int & y) const;
113         ///
114         void toggleInsetCursor(BufferView *);
115         ///
116         void showInsetCursor(BufferView *, bool show = true);
117         ///
118         void hideInsetCursor(BufferView *);
119         ///
120         void fitInsetCursor(BufferView * bv) const {
121                 inset.fitInsetCursor(bv);
122         }
123         UpdatableInset * getLockingInset() const;
124         ///
125         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
126         ///
127         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
128                  bool selectall = false);
129         ///
130         void setLabel(string const & l) const;
131         ///
132         void setLabelFont(LyXFont & f) { labelfont = f; }
133 #if 0
134         ///
135         void setAutoCollapse(bool f) { autocollapse = f; }
136 #endif
137 #if 0
138         ///
139         int getMaxWidth(BufferView *, UpdatableInset const *) const;
140 #endif
141         ///
142         LyXText * getLyXText(BufferView const *, bool const recursive) const;
143         ///
144         void deleteLyXText(BufferView *, bool recursive=true) const;
145         ///
146         void resizeLyXText(BufferView *, bool force = false) const;
147         ///
148         std::vector<string> const getLabelList() const;
149         ///
150         bool nodraw() const;
151         ///
152         int scroll(bool recursive=true) const;
153         ///
154         void scroll(BufferView *bv, float sx) const {
155                 UpdatableInset::scroll(bv, sx);
156         }
157         ///
158         void scroll(BufferView *bv, int offset) const {
159                 UpdatableInset::scroll(bv, offset);
160         }
161         ///
162         Paragraph * getParFromID(int id) const;
163         ///
164         Inset * getInsetFromID(int id) const;
165         ///
166         Paragraph * firstParagraph() const;
167         ///
168         Paragraph * getFirstParagraph(int) const;
169         ///
170         LyXCursor const & cursor(BufferView *) const;
171         ///
172         bool isOpen() const { return !collapsed_; }
173         ///
174         void open(BufferView *);
175         ///
176         void close(BufferView *) const;
177         ///
178         bool allowSpellcheck() { return inset.allowSpellcheck(); }
179         string const selectNextWordToSpellcheck(BufferView *, float &) const;
180
181         void selectSelectedWord(BufferView * bv) {
182                 inset.selectSelectedWord(bv);
183         }
184         void toggleSelection(BufferView * bv, bool kill_selection) {
185                 inset.toggleSelection(bv, kill_selection);
186         }
187         ///
188         bool searchForward(BufferView * bv, string const & str,
189                            bool = true, bool = false);
190         bool searchBackward(BufferView * bv, string const & str,
191                             bool = true, bool = false);
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         mutable string label;
229 #if 0
230         ///
231         bool autocollapse;
232 #endif
233         ///
234         mutable int oldWidth;
235         ///
236         bool in_update;
237         ///
238         mutable bool first_after_edit;
239 };
240
241 #endif