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