]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Alfredo's second patch
[lyx.git] / src / insets / insetcollapsable.h
1 // -*- C++ -*-
2 /**
3  * \file insetcollapsable.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author Jürgen Vigna
9  * \author Lars Gullik Bjønnes
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 #ifndef INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
16
17
18 #include "inset.h"
19 #include "insettext.h"
20 #include "lyxfont.h"
21 #include "LColor.h"
22
23 #include <boost/weak_ptr.hpp>
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         static int const TEXT_TO_TOP_OFFSET = 2;
37         ///
38         static int const TEXT_TO_BOTTOM_OFFSET = 2;
39         /// inset is initially collapsed if bool = true
40         InsetCollapsable(BufferParams const &, bool = false);
41         ///
42         InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
43         ///
44         void read(Buffer const *, LyXLex &);
45         ///
46         void write(Buffer const *, std::ostream &) const;
47         ///
48         int ascent(BufferView *, LyXFont const &) const;
49         ///
50         int descent(BufferView *, LyXFont const &) const;
51         ///
52         int width(BufferView *, LyXFont const &) const;
53         ///
54         void draw(BufferView *, const LyXFont &, int , float &) const;
55         /// draw, either inlined (no button) or collapsed/open
56         void draw(BufferView * bv, LyXFont const & f,
57                   int baseline, float & x, bool inlined) const;
58         ///
59         void update(BufferView *, bool =false);
60         ///
61         void edit(BufferView *, int, int, mouse_button::state);
62         ///
63         void edit(BufferView *, bool front = true);
64         ///
65         EDITABLE editable() const;
66         ///
67         bool insertInset(BufferView *, Inset * inset);
68         ///
69         virtual bool insetAllowed(Inset::Code code) const {
70                 return inset.insetAllowed(code);
71         }
72         ///
73         bool isTextInset() const { return true; }
74         ///
75         void insetUnlock(BufferView *);
76         ///
77         bool needFullRow() const { return isOpen(); }
78         ///
79         bool lockInsetInInset(BufferView *, UpdatableInset *);
80         ///
81         bool unlockInsetInInset(BufferView *, UpdatableInset *,
82                                 bool lr = false);
83         ///
84         bool updateInsetInInset(BufferView *, Inset *);
85         ///
86         int insetInInsetY() const;
87         ///
88         RESULT localDispatch(FuncRequest const &);
89         ///
90         int latex(Buffer const *, std::ostream &,
91                   bool fragile, bool free_spc) const;
92         ///
93         int ascii(Buffer const *, std::ostream &, int) const;
94         ///
95         int linuxdoc(Buffer const *, std::ostream &) const;
96         ///
97         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
98         ///
99         void validate(LaTeXFeatures & features) const;
100         ///
101         void getCursorPos(BufferView *, int & x, int & y) const;
102         ///
103         void toggleInsetCursor(BufferView *);
104         ///
105         void showInsetCursor(BufferView *, bool show = true);
106         ///
107         void hideInsetCursor(BufferView *);
108         ///
109         void fitInsetCursor(BufferView * bv) const {
110                 inset.fitInsetCursor(bv);
111         }
112         UpdatableInset * getLockingInset() const;
113         ///
114         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
115         ///
116         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
117                  bool selectall = false);
118         ///
119         void setLabel(string const & l) const;
120         ///
121         void setLabelFont(LyXFont & f) { labelfont = f; }
122 #if 0
123         ///
124         void setAutoCollapse(bool f) { autocollapse = f; }
125 #endif
126         ///
127         LyXText * getLyXText(BufferView const *, bool const recursive) const;
128         ///
129         void deleteLyXText(BufferView *, bool recursive=true) const;
130         ///
131         void resizeLyXText(BufferView *, bool force = false) const;
132         ///
133         std::vector<string> const getLabelList() const;
134         ///
135         bool nodraw() const;
136         ///
137         int scroll(bool recursive=true) const;
138         ///
139         void scroll(BufferView *bv, float sx) const {
140                 UpdatableInset::scroll(bv, sx);
141         }
142         ///
143         void scroll(BufferView *bv, int offset) const {
144                 UpdatableInset::scroll(bv, offset);
145         }
146         ///
147         Inset * getInsetFromID(int id) const;
148         ///
149         Paragraph * firstParagraph() const;
150         ///
151         Paragraph * getFirstParagraph(int) const;
152         ///
153         LyXCursor const & cursor(BufferView *) const;
154         ///
155         bool isOpen() const { return !collapsed_; }
156         ///
157         void open(BufferView *);
158         ///
159         void close(BufferView *) const;
160         ///
161         bool allowSpellcheck() const { return inset.allowSpellcheck(); }
162         ///
163         WordLangTuple const
164         selectNextWordToSpellcheck(BufferView *, float &) const;
165         ///
166         void selectSelectedWord(BufferView * bv) {
167                 inset.selectSelectedWord(bv);
168         }
169         ///
170         void toggleSelection(BufferView * bv, bool kill_selection) {
171                 inset.toggleSelection(bv, kill_selection);
172         }
173  
174         void markErased();
175  
176         bool nextChange(BufferView * bv, lyx::pos_type & length);
177
178         ///
179         bool searchForward(BufferView * bv, string const & str,
180                            bool = true, bool = false);
181         bool searchBackward(BufferView * bv, string const & str,
182                             bool = true, bool = false);
183
184         ///
185         void addPreview(grfx::PreviewLoader &) const;
186
187 protected:
188         ///
189         virtual void cache(BufferView *) const;
190         ///
191         virtual BufferView * view() const;
192
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
224 private:
225         ///
226         void lfunMousePress(FuncRequest const &);
227         ///
228         bool lfunMouseRelease(FuncRequest const &);
229         ///
230         void lfunMouseMotion(FuncRequest const &);
231
232         ///
233         mutable string label;
234 #if 0
235         ///
236         bool autocollapse;
237 #endif
238         ///
239         mutable int oldWidth;
240         ///
241         bool in_update;
242         ///
243         mutable bool first_after_edit;
244         ///
245         mutable boost::weak_ptr<BufferView> view_;
246 };
247
248 #endif