]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
This should clean up the language stuff a bit and a small new check for
[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(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 & f) 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, unsigned int);
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 !collapsed_; }
82         ///
83         bool lockInsetInInset(BufferView *, UpdatableInset *);
84         ///
85         bool unlockInsetInInset(BufferView *, UpdatableInset *,
86                                 bool lr = false);
87         ///
88         bool updateInsetInInset(BufferView *, Inset *);
89         ///
90         unsigned int insetInInsetY();
91         ///
92         void insetButtonRelease(BufferView *, int, int, int);
93         ///
94         void insetButtonPress(BufferView *, int, int, int);
95         ///
96         void insetMotionNotify(BufferView *, int, int, int);
97         ///
98         void insetKeyPress(XKeyEvent *);
99         ///
100         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
101                                              string const &);
102         ///
103         int latex(Buffer const *, std::ostream &,
104                   bool fragile, bool free_spc) const;
105         ///
106         int ascii(Buffer const *, std::ostream &, int) const { return 0; }
107         ///
108         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
109         ///
110         int docBook(Buffer const *, std::ostream &) const { return 0; }
111         ///
112         void validate(LaTeXFeatures & features) const;
113         ///
114         void getCursorPos(BufferView *, int & x, int & y) const;
115         ///
116         void toggleInsetCursor(BufferView *);
117         ///
118         void showInsetCursor(BufferView *, bool show = true);
119         ///
120         void hideInsetCursor(BufferView *);
121         ///
122         void fitInsetCursor(BufferView * bv) const {
123                 inset.fitInsetCursor(bv);
124         }
125         UpdatableInset * getLockingInset() const;
126         ///
127         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
128         ///
129         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
130                  bool selectall = false);
131 #if 0
132         ///
133         void setLabel(string const & l, bool flag = false);
134 #else
135         ///
136         void setLabel(string const & l);
137 #endif
138         ///
139         void setLabelFont(LyXFont & f) { labelfont = f; }
140 #if 0
141         ///
142         void setAutoCollapse(bool f) { autocollapse = f; }
143 #endif
144         ///
145         int getMaxWidth(BufferView *, UpdatableInset const *) const;
146         ///
147         LyXText * getLyXText(BufferView const *, bool const recursive) const;
148         ///
149         void deleteLyXText(BufferView *, bool recursive=true) const;
150         ///
151         void resizeLyXText(BufferView *, bool force = false) const;
152         ///
153         std::vector<string> const getLabelList() const;
154         ///
155         bool nodraw() const;
156         ///
157         int scroll(bool recursive=true) const;
158         ///
159         void scroll(BufferView *bv, float sx) const {
160                 UpdatableInset::scroll(bv, sx);
161         }
162         ///
163         void scroll(BufferView *bv, int offset) const {
164                 UpdatableInset::scroll(bv, offset);
165         }
166         ///
167         Paragraph * getParFromID(int id) const;
168         ///
169         Inset * getInsetFromID(int id) const;
170         ///
171         Paragraph * firstParagraph() const;
172         ///
173         LyXCursor const & cursor(BufferView *) const;
174         ///
175         bool isOpen() const { return !collapsed_; }
176 #if 0
177         ///
178         void open(BufferView *, bool);
179 #else
180         ///
181         void open(BufferView *);
182         ///
183         void close(BufferView *);
184 #endif
185         ///
186         string const selectNextWord(BufferView * bv, float & value) const {
187                 return inset.selectNextWord(bv, value);
188         }
189         void selectSelectedWord(BufferView * bv) {
190                 inset.selectSelectedWord(bv);
191         }
192         void toggleSelection(BufferView * bv, bool kill_selection) {
193                 inset.toggleSelection(bv, kill_selection);
194         }
195         ///
196         bool searchForward(BufferView * bv, string const & str,
197                            bool const & cs = true, bool const & mw = false) {
198                 return inset.searchForward(bv, str, cs, mw);
199         }
200         bool searchBackward(BufferView * bv, string const & str,
201                             bool const & cs = true, bool const & mw = false) {
202                 return inset.searchBackward(bv, str, cs, mw);
203         }
204         /// check if the font of the char we want inserting is correct
205         /// and modify it if it is not.
206         virtual bool checkInsertChar(LyXFont &) { return false; }
207
208 protected:
209         ///
210         int ascent_collapsed() const;
211         ///
212         int descent_collapsed() const;
213         ///
214         int width_collapsed() const;
215         ///
216         void draw_collapsed(Painter & pain, int , float &) const;
217         ///
218         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
219         
220         ///
221         bool collapsed_;
222         ///
223         LColor::color framecolor;
224         ///
225         LyXFont labelfont;
226 public:
227         ///
228         InsetText inset;
229 protected:
230 #if 0
231         ///
232         string const get_new_label() const;
233 #endif
234         ///
235         mutable int button_length;
236         ///
237         mutable int button_top_y;
238         ///
239         mutable int button_bottom_y;
240 private:
241         ///
242         string label;
243 #if 0
244         ///
245         mutable string draw_label;
246 #endif
247 #if 0
248         ///
249         bool autocollapse;
250 #endif
251         ///
252         mutable int oldWidth;
253         ///
254         mutable int topx;
255         mutable int topbaseline;
256         mutable UpdateCodes need_update;
257         ///
258         bool inlined;
259 #if 0
260         ///
261         bool change_label_with_text;
262 #endif
263 };
264
265 #endif