]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Fixed crash when inserting mathed inset inside InsetERT + new devel banner.
[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 colapsable 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         ///
45         InsetCollapsable();
46         ///
47         void read(Buffer const *, LyXLex &);
48         ///
49         void write(Buffer const *, std::ostream &) const;
50         ///
51         int ascent(BufferView *, LyXFont const &) const;
52         ///
53         int descent(BufferView *, LyXFont const &) const;
54         ///
55         int width(BufferView *, LyXFont const & f) const;
56         ///
57         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
58         ///
59         void update(BufferView *, LyXFont const &, bool =false); 
60         ///
61         void edit(BufferView *, int, int, unsigned int);
62         ///
63         EDITABLE editable() const;
64         ///
65         bool insertInset(BufferView *, Inset * inset);
66         ///
67         bool insertInsetAllowed(Inset * in) const {
68                 return inset.insertInsetAllowed(in);
69         }
70         ///
71         bool isTextInset() const { return true; }
72         ///
73         bool doClearArea() const;
74         ///
75         void insetUnlock(BufferView *);
76         ///
77         bool needFullRow() const { return !collapsed; }
78         ///
79         bool lockInsetInInset(BufferView *, UpdatableInset *);
80         ///
81         bool unlockInsetInInset(BufferView *, UpdatableInset *,
82                                 bool lr = false);
83         ///
84         bool updateInsetInInset(BufferView *, Inset *);
85         ///
86         unsigned int insetInInsetY();
87         ///
88         void insetButtonRelease(BufferView *, int, int, int);
89         ///
90         void insetButtonPress(BufferView *, int, int, int);
91         ///
92         void insetMotionNotify(BufferView *, int, int, int);
93         ///
94         void insetKeyPress(XKeyEvent *);
95         ///
96         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
97                                              string const &);
98         ///
99         int latex(Buffer const *, std::ostream &,
100                   bool fragile, bool free_spc) const;
101         ///
102         int ascii(Buffer const *, std::ostream &, int) const { return 0; }
103         ///
104         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
105         ///
106         int docBook(Buffer const *, std::ostream &) const { return 0; }
107         ///
108         void validate(LaTeXFeatures & features) const;
109         ///
110         void getCursorPos(BufferView *, int & x, int & y) const;
111         ///
112         void toggleInsetCursor(BufferView *);
113         ///
114         UpdatableInset * getLockingInset();
115         ///
116         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
117         ///
118         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
119                  bool selectall = false);
120         ///
121         void setLabel(string const & l) { label = l; }
122         ///
123         void setLabelFont(LyXFont & f) { labelfont = f; }
124         ///
125         void setAutoCollapse(bool f) { autocollapse = f; }
126         ///
127         int getMaxWidth(BufferView *, UpdatableInset const *) const;
128         ///
129         LyXText * getLyXText(BufferView const *, bool const recursive) const;
130         ///
131         void deleteLyXText(BufferView *, bool recursive=true) const;
132         ///
133         void resizeLyXText(BufferView *, bool force = false) const;
134         ///
135         std::vector<string> const getLabelList() const;
136         ///
137         bool nodraw() const;
138         ///
139         int scroll(bool recursive=true) const;
140         ///
141         void scroll(BufferView *bv, float sx) const {
142                 UpdatableInset::scroll(bv, sx);
143         }
144         ///
145         void scroll(BufferView *bv, int offset) const {
146                 UpdatableInset::scroll(bv, offset);
147         }
148         ///
149         Paragraph * getParFromID(int id) const;
150         ///
151         Inset * getInsetFromID(int id) const;
152         ///
153         Paragraph * firstParagraph() const;
154         ///
155         LyXCursor const & cursor(BufferView *) const;
156
157 protected:
158         ///
159         int ascent_collapsed(Painter &, LyXFont const &) const;
160         ///
161         int descent_collapsed(Painter &, LyXFont const &) const;
162         ///
163         int width_collapsed(Painter &, LyXFont const & f) const;
164         ///
165         void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
166         ///
167         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
168         
169         ///
170         bool collapsed;
171         ///
172         LColor::color framecolor;
173         ///
174         LyXFont labelfont;
175 public:
176         ///
177         InsetText inset;
178 protected:
179         ///
180         mutable int button_length;
181         ///
182         mutable int button_top_y;
183         ///
184         mutable int button_bottom_y;
185 private:
186         ///
187         string label;
188         ///
189         bool autocollapse;
190         ///
191         int widthCollapsed;
192         ///
193         mutable int oldWidth;
194         ///
195         mutable int topx;
196         mutable int topbaseline;
197         mutable UpdateCodes need_update;
198 };
199
200 #endif