]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Hopefully fixed the redo problems with insets!
[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 &) 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 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         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         ///
132         void setLabel(string const & l) const;
133         ///
134         void setLabelFont(LyXFont & f) { labelfont = f; }
135 #if 0
136         ///
137         void setAutoCollapse(bool f) { autocollapse = f; }
138 #endif
139 #if 0
140         ///
141         int getMaxWidth(BufferView *, UpdatableInset const *) const;
142 #endif
143         ///
144         LyXText * getLyXText(BufferView const *, bool const recursive) const;
145         ///
146         void deleteLyXText(BufferView *, bool recursive=true) const;
147         ///
148         void resizeLyXText(BufferView *, bool force = false) const;
149         ///
150         std::vector<string> const getLabelList() const;
151         ///
152         bool nodraw() const;
153         ///
154         int scroll(bool recursive=true) const;
155         ///
156         void scroll(BufferView *bv, float sx) const {
157                 UpdatableInset::scroll(bv, sx);
158         }
159         ///
160         void scroll(BufferView *bv, int offset) const {
161                 UpdatableInset::scroll(bv, offset);
162         }
163         ///
164         Paragraph * getParFromID(int id) const;
165         ///
166         Inset * getInsetFromID(int id) const;
167         ///
168         Paragraph * firstParagraph() const;
169         ///
170         Paragraph * getFirstParagraph(int) const;
171         ///
172         LyXCursor const & cursor(BufferView *) const;
173         ///
174         bool isOpen() const { return !collapsed_; }
175         ///
176         void open(BufferView *);
177         ///
178         void close(BufferView *) const;
179         ///
180         bool allowSpellcheck() { return inset.allowSpellcheck(); }
181         string const selectNextWordToSpellcheck(BufferView *, float &) const;
182
183         void selectSelectedWord(BufferView * bv) {
184                 inset.selectSelectedWord(bv);
185         }
186         void toggleSelection(BufferView * bv, bool kill_selection) {
187                 inset.toggleSelection(bv, kill_selection);
188         }
189         ///
190         bool searchForward(BufferView * bv, string const & str,
191                            bool const & cs = true, bool const & mw = false);
192         bool searchBackward(BufferView * bv, string const & str,
193                             bool const & cs = true, bool const & mw = false);
194
195 protected:
196         ///
197         int ascent_collapsed() const;
198         ///
199         int descent_collapsed() const;
200         ///
201         int width_collapsed() const;
202         ///
203         void draw_collapsed(Painter & pain, int , float &) const;
204         ///
205         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
206         
207         ///
208         mutable bool collapsed_;
209         ///
210         LColor::color framecolor;
211         ///
212         LyXFont labelfont;
213 public:
214         ///
215         mutable InsetText inset;
216 protected:
217         ///
218         mutable int button_length;
219         ///
220         mutable int button_top_y;
221         ///
222         mutable int button_bottom_y;
223         ///
224         mutable int topx;
225         mutable int topbaseline;
226         mutable UpdateCodes need_update;
227
228 private:
229         ///
230         mutable string label;
231 #if 0
232         ///
233         bool autocollapse;
234 #endif
235         ///
236         mutable int oldWidth;
237         ///
238         bool in_update;
239         ///
240         mutable bool first_after_edit;
241 };
242
243 #endif