]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
partial inset toggling ; insetAllowed stuff
[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 insetAllowed(Inset::Code code) const {
68                 return inset.insetAllowed(code);
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() const;
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         bool isOpen() const { return !collapsed_; }
158         void open(BufferView *, bool);
159         ///
160         string selectNextWord(BufferView * bv, float & value) const {
161                 return inset.selectNextWord(bv, value);
162         }
163         void selectSelectedWord(BufferView * bv) {
164                 inset.selectSelectedWord(bv);
165         }
166         void toggleSelection(BufferView * bv, bool kill_selection) {
167                 inset.toggleSelection(bv, kill_selection);
168         }
169
170 protected:
171         ///
172         int ascent_collapsed(Painter &, LyXFont const &) const;
173         ///
174         int descent_collapsed(Painter &, LyXFont const &) const;
175         ///
176         int width_collapsed(Painter &, LyXFont const & f) const;
177         ///
178         void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
179         ///
180         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
181         
182         ///
183         bool collapsed_;
184         ///
185         LColor::color framecolor;
186         ///
187         LyXFont labelfont;
188 public:
189         ///
190         InsetText inset;
191 protected:
192         ///
193         mutable int button_length;
194         ///
195         mutable int button_top_y;
196         ///
197         mutable int button_bottom_y;
198 private:
199         ///
200         string label;
201         ///
202         bool autocollapse;
203         ///
204         int widthCollapsed;
205         ///
206         mutable int oldWidth;
207         ///
208         mutable int topx;
209         mutable int topbaseline;
210         mutable UpdateCodes need_update;
211 };
212
213 #endif