]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Added copy constructor to inset.h and used it in most insets which permit
[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         ///
134         void setLabel(string const & l, bool flag = false);
135         ///
136         void setLabelFont(LyXFont & f) { labelfont = f; }
137         ///
138         void setAutoCollapse(bool f) { autocollapse = f; }
139         ///
140         int getMaxWidth(BufferView *, UpdatableInset const *) const;
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         LyXCursor const & cursor(BufferView *) const;
169         ///
170         bool isOpen() const { return !collapsed_; }
171         void open(BufferView *, bool);
172         ///
173         string selectNextWord(BufferView * bv, float & value) const {
174                 return inset.selectNextWord(bv, value);
175         }
176         void selectSelectedWord(BufferView * bv) {
177                 inset.selectSelectedWord(bv);
178         }
179         void toggleSelection(BufferView * bv, bool kill_selection) {
180                 inset.toggleSelection(bv, kill_selection);
181         }
182         ///
183         bool searchForward(BufferView * bv, string const & str,
184                            bool const & cs = true, bool const & mw = false) {
185                 return inset.searchForward(bv, str, cs, mw);
186         }
187         bool searchBackward(BufferView * bv, string const & str,
188                             bool const & cs = true, bool const & mw = false) {
189                 return inset.searchBackward(bv, str, cs, mw);
190         }
191
192 protected:
193         ///
194         int ascent_collapsed(Painter &) const;
195         ///
196         int descent_collapsed(Painter &) const;
197         ///
198         int width_collapsed(Painter &) const;
199         ///
200         void draw_collapsed(Painter & pain, int , float &) const;
201         ///
202         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
203         
204         ///
205         bool collapsed_;
206         ///
207         LColor::color framecolor;
208         ///
209         LyXFont labelfont;
210 public:
211         ///
212         InsetText inset;
213 protected:
214         ///
215         string get_new_label() const;
216
217         ///
218         mutable int button_length;
219         ///
220         mutable int button_top_y;
221         ///
222         mutable int button_bottom_y;
223 private:
224         ///
225         string label;
226         ///
227         mutable string draw_label;
228         ///
229         bool autocollapse;
230         ///
231         mutable int oldWidth;
232         ///
233         mutable int topx;
234         mutable int topbaseline;
235         mutable UpdateCodes need_update;
236         ///
237         bool inlined;
238         ///
239         bool change_label_with_text;
240 };
241
242 #endif