]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
compile fix
[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         bool insertInsetAllowed(Inset::Code code) const {
71                 return inset.insertInsetAllowed(code);
72         }
73         ///
74         bool isTextInset() const { return true; }
75         ///
76         bool doClearArea() const;
77         ///
78         void insetUnlock(BufferView *);
79         ///
80         bool needFullRow() const { return !collapsed_; }
81         ///
82         bool lockInsetInInset(BufferView *, UpdatableInset *);
83         ///
84         bool unlockInsetInInset(BufferView *, UpdatableInset *,
85                                 bool lr = false);
86         ///
87         bool updateInsetInInset(BufferView *, Inset *);
88         ///
89         unsigned int insetInInsetY();
90         ///
91         void insetButtonRelease(BufferView *, int, int, int);
92         ///
93         void insetButtonPress(BufferView *, int, int, int);
94         ///
95         void insetMotionNotify(BufferView *, int, int, int);
96         ///
97         void insetKeyPress(XKeyEvent *);
98         ///
99         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
100                                              string const &);
101         ///
102         int latex(Buffer const *, std::ostream &,
103                   bool fragile, bool free_spc) const;
104         ///
105         int ascii(Buffer const *, std::ostream &, int) const { return 0; }
106         ///
107         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
108         ///
109         int docBook(Buffer const *, std::ostream &) const { return 0; }
110         ///
111         void validate(LaTeXFeatures & features) const;
112         ///
113         void getCursorPos(BufferView *, int & x, int & y) const;
114         ///
115         void toggleInsetCursor(BufferView *);
116         ///
117         UpdatableInset * getLockingInset() const;
118         ///
119         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
120         ///
121         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
122                  bool selectall = false);
123         ///
124         void setLabel(string const & l) { label = l; }
125         ///
126         void setLabelFont(LyXFont & f) { labelfont = f; }
127         ///
128         void setAutoCollapse(bool f) { autocollapse = f; }
129         ///
130         int getMaxWidth(BufferView *, UpdatableInset const *) const;
131         ///
132         LyXText * getLyXText(BufferView const *, bool const recursive) const;
133         ///
134         void deleteLyXText(BufferView *, bool recursive=true) const;
135         ///
136         void resizeLyXText(BufferView *, bool force = false) const;
137         ///
138         std::vector<string> const getLabelList() const;
139         ///
140         bool nodraw() const;
141         ///
142         int scroll(bool recursive=true) const;
143         ///
144         void scroll(BufferView *bv, float sx) const {
145                 UpdatableInset::scroll(bv, sx);
146         }
147         ///
148         void scroll(BufferView *bv, int offset) const {
149                 UpdatableInset::scroll(bv, offset);
150         }
151         ///
152         Paragraph * getParFromID(int id) const;
153         ///
154         Inset * getInsetFromID(int id) const;
155         ///
156         Paragraph * firstParagraph() const;
157         ///
158         LyXCursor const & cursor(BufferView *) const;
159         ///
160         bool isCollapsable() const { return true; }
161         bool collapsed() const { return collapsed_; }
162         void collapsed(BufferView *, bool);
163         ///
164         string selectNextWord(BufferView * bv, float & value) const {
165                 return inset.selectNextWord(bv, value);
166         }
167         void selectSelectedWord(BufferView * bv) {
168                 inset.selectSelectedWord(bv);
169         }
170         void toggleSelection(BufferView * bv, bool kill_selection) {
171                 inset.toggleSelection(bv, kill_selection);
172         }
173
174 protected:
175         ///
176         int ascent_collapsed(Painter &, LyXFont const &) const;
177         ///
178         int descent_collapsed(Painter &, LyXFont const &) const;
179         ///
180         int width_collapsed(Painter &, LyXFont const & f) const;
181         ///
182         void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
183         ///
184         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
185         
186         ///
187         bool collapsed_;
188         ///
189         LColor::color framecolor;
190         ///
191         LyXFont labelfont;
192 public:
193         ///
194         InsetText inset;
195 protected:
196         ///
197         mutable int button_length;
198         ///
199         mutable int button_top_y;
200         ///
201         mutable int button_bottom_y;
202 private:
203         ///
204         string label;
205         ///
206         bool autocollapse;
207         ///
208         int widthCollapsed;
209         ///
210         mutable int oldWidth;
211         ///
212         mutable int topx;
213         mutable int topbaseline;
214         mutable UpdateCodes need_update;
215 };
216
217 #endif