]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Added inline functionallity to InsetERT. Fixed cache.clear() problem in
[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 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);
133         ///
134         void setLabelFont(LyXFont & f) { labelfont = f; }
135 #if 0
136         ///
137         void setAutoCollapse(bool f) { autocollapse = f; }
138 #endif
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         ///
172         void open(BufferView *);
173         ///
174         void close(BufferView *);
175         ///
176         string const selectNextWord(BufferView * bv, float & value) const {
177                 return inset.selectNextWord(bv, value);
178         }
179         void selectSelectedWord(BufferView * bv) {
180                 inset.selectSelectedWord(bv);
181         }
182         void toggleSelection(BufferView * bv, bool kill_selection) {
183                 inset.toggleSelection(bv, kill_selection);
184         }
185         ///
186         bool searchForward(BufferView * bv, string const & str,
187                            bool const & cs = true, bool const & mw = false) {
188                 return inset.searchForward(bv, str, cs, mw);
189         }
190         bool searchBackward(BufferView * bv, string const & str,
191                             bool const & cs = true, bool const & mw = false) {
192                 return inset.searchBackward(bv, str, cs, mw);
193         }
194         /// check if the font of the char we want inserting is correct
195         /// and modify it if it is not.
196         virtual bool checkInsertChar(LyXFont &) { return false; }
197
198 protected:
199         ///
200         int ascent_collapsed() const;
201         ///
202         int descent_collapsed() const;
203         ///
204         int width_collapsed() const;
205         ///
206         void draw_collapsed(Painter & pain, int , float &) const;
207         ///
208         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
209         
210         ///
211         bool collapsed_;
212         ///
213         LColor::color framecolor;
214         ///
215         LyXFont labelfont;
216 public:
217         ///
218         InsetText inset;
219 protected:
220         ///
221         mutable int button_length;
222         ///
223         mutable int button_top_y;
224         ///
225         mutable int button_bottom_y;
226         ///
227         mutable int topx;
228         mutable int topbaseline;
229         mutable UpdateCodes need_update;
230
231 private:
232         ///
233         string label;
234 #if 0
235         ///
236         bool autocollapse;
237 #endif
238         ///
239         mutable int oldWidth;
240 };
241
242 #endif