]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
partial framebox support
[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(BufferParams const &, 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 &) 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, mouse_button::state);
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         int insetInInsetY() const;
91         ///
92         RESULT localDispatch(FuncRequest const &);
93         ///
94         int latex(Buffer const *, std::ostream &,
95                   bool fragile, bool free_spc) const;
96         ///
97         int ascii(Buffer const *, std::ostream &, int) const;
98         ///
99         int linuxdoc(Buffer const *, std::ostream &) const;
100         ///
101         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
102         ///
103         void validate(LaTeXFeatures & features) const;
104         ///
105         void getCursorPos(BufferView *, int & x, int & y) const;
106         ///
107         void toggleInsetCursor(BufferView *);
108         ///
109         void showInsetCursor(BufferView *, bool show = true);
110         ///
111         void hideInsetCursor(BufferView *);
112         ///
113         void fitInsetCursor(BufferView * bv) const {
114                 inset.fitInsetCursor(bv);
115         }
116         UpdatableInset * getLockingInset() const;
117         ///
118         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
119         ///
120         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
121                  bool selectall = false);
122         ///
123         void setLabel(string const & l) const;
124         ///
125         void setLabelFont(LyXFont & f) { labelfont = f; }
126 #if 0
127         ///
128         void setAutoCollapse(bool f) { autocollapse = f; }
129 #endif
130 #if 0
131         ///
132         int getMaxWidth(BufferView *, UpdatableInset const *) const;
133 #endif
134         ///
135         LyXText * getLyXText(BufferView const *, bool const recursive) const;
136         ///
137         void deleteLyXText(BufferView *, bool recursive=true) const;
138         ///
139         void resizeLyXText(BufferView *, bool force = false) const;
140         ///
141         std::vector<string> const getLabelList() const;
142         ///
143         bool nodraw() const;
144         ///
145         int scroll(bool recursive=true) const;
146         ///
147         void scroll(BufferView *bv, float sx) const {
148                 UpdatableInset::scroll(bv, sx);
149         }
150         ///
151         void scroll(BufferView *bv, int offset) const {
152                 UpdatableInset::scroll(bv, offset);
153         }
154         ///
155         Paragraph * getParFromID(int id) const;
156         ///
157         Inset * getInsetFromID(int id) const;
158         ///
159         Paragraph * firstParagraph() const;
160         ///
161         Paragraph * getFirstParagraph(int) const;
162         ///
163         LyXCursor const & cursor(BufferView *) const;
164         ///
165         bool isOpen() const { return !collapsed_; }
166         ///
167         void open(BufferView *);
168         ///
169         void close(BufferView *) const;
170         ///
171         bool allowSpellcheck() { return inset.allowSpellcheck(); }
172         ///
173         WordLangTuple const
174         selectNextWordToSpellcheck(BufferView *, float &) const;
175         ///
176         void selectSelectedWord(BufferView * bv) {
177                 inset.selectSelectedWord(bv);
178         }
179         ///
180         void toggleSelection(BufferView * bv, bool kill_selection) {
181                 inset.toggleSelection(bv, kill_selection);
182         }
183         ///
184         bool searchForward(BufferView * bv, string const & str,
185                            bool = true, bool = false);
186         bool searchBackward(BufferView * bv, string const & str,
187                             bool = true, bool = false);
188
189         ///
190         void addPreview(grfx::PreviewLoader &) const;
191
192 protected:
193         ///
194         int ascent_collapsed() const;
195         ///
196         int descent_collapsed() const;
197         ///
198         int width_collapsed() const;
199         ///
200         void draw_collapsed(Painter & pain, int , float &) const;
201         ///
202         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
203
204         ///
205         mutable bool collapsed_;
206         ///
207         LColor::color framecolor;
208         ///
209         LyXFont labelfont;
210 public:
211         ///
212         mutable InsetText inset;
213 protected:
214         ///
215         mutable int button_length;
216         ///
217         mutable int button_top_y;
218         ///
219         mutable int button_bottom_y;
220         ///
221         mutable int topx;
222         mutable int topbaseline;
223         mutable UpdateCodes need_update;
224
225 private:
226         ///
227         void lfunMousePress(FuncRequest const &);
228         ///
229         bool lfunMouseRelease(FuncRequest const &);
230         ///
231         void lfunMouseMotion(FuncRequest const &);
232
233         ///
234         mutable string label;
235 #if 0
236         ///
237         bool autocollapse;
238 #endif
239         ///
240         mutable int oldWidth;
241         ///
242         bool in_update;
243         ///
244         mutable bool first_after_edit;
245 };
246
247 #endif