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