]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
fix #832
[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 #include "inset.h"
18 #include "insettext.h"
19 #include "lyxfont.h"
20 #include "funcrequest.h" // for adjustCommand
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         EDITABLE editable() const;
62         ///
63         bool insertInset(BufferView *, Inset * inset);
64         ///
65         virtual bool insetAllowed(Inset::Code code) const {
66                 return inset.insetAllowed(code);
67         }
68         ///
69         bool isTextInset() const { return true; }
70         ///
71         void insetUnlock(BufferView *);
72         ///
73         bool needFullRow() const { return isOpen(); }
74         ///
75         bool lockInsetInInset(BufferView *, UpdatableInset *);
76         ///
77         bool unlockInsetInInset(BufferView *, UpdatableInset *,
78                                 bool lr = false);
79         ///
80         bool updateInsetInInset(BufferView *, Inset *);
81         ///
82         int insetInInsetY() const;
83         ///
84         RESULT localDispatch(FuncRequest const &);
85         ///
86         int latex(Buffer const *, std::ostream &,
87                   bool fragile, bool free_spc) const;
88         ///
89         int ascii(Buffer const *, std::ostream &, int) const;
90         ///
91         int linuxdoc(Buffer const *, std::ostream &) const;
92         ///
93         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
94         ///
95         void validate(LaTeXFeatures & features) const;
96         /// FIXME, document
97         void getCursorPos(BufferView *, int & x, int & y) const;
98         /// Get the absolute document x,y of the cursor
99         virtual void getCursor(BufferView &, int &, int &) const;
100         ///
101         void fitInsetCursor(BufferView * bv) const {
102                 inset.fitInsetCursor(bv);
103         }
104         UpdatableInset * getLockingInset() const;
105         ///
106         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
107         ///
108         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
109                  bool selectall = false);
110         ///
111         void setLabel(string const & l) const;
112         ///
113         void setLabelFont(LyXFont & f) { labelfont = f; }
114 #if 0
115         ///
116         void setAutoCollapse(bool f) { autocollapse = f; }
117 #endif
118         ///
119         LyXText * getLyXText(BufferView const *, bool const recursive) const;
120         ///
121         void deleteLyXText(BufferView *, bool recursive=true) const;
122         ///
123         void resizeLyXText(BufferView *, bool force = false) const;
124         ///
125         std::vector<string> const getLabelList() const;
126         ///
127         bool nodraw() const;
128         ///
129         int scroll(bool recursive=true) const;
130         ///
131         void scroll(BufferView *bv, float sx) const {
132                 UpdatableInset::scroll(bv, sx);
133         }
134         ///
135         void scroll(BufferView *bv, int offset) const {
136                 UpdatableInset::scroll(bv, offset);
137         }
138         ///
139         Inset * getInsetFromID(int id) const;
140         ///
141         ParagraphList * getParagraphs(int) const;
142         ///
143         LyXCursor const & cursor(BufferView *) const;
144         ///
145         bool isOpen() const { return !collapsed_; }
146         ///
147         void open(BufferView *);
148         ///
149         void close(BufferView *) const;
150         ///
151         bool allowSpellcheck() const { return inset.allowSpellcheck(); }
152         ///
153         WordLangTuple const
154         selectNextWordToSpellcheck(BufferView *, float &) const;
155         ///
156         void selectSelectedWord(BufferView * bv) {
157                 inset.selectSelectedWord(bv);
158         }
159         ///
160         void toggleSelection(BufferView * bv, bool kill_selection) {
161                 inset.toggleSelection(bv, kill_selection);
162         }
163  
164         void markErased();
165  
166         bool nextChange(BufferView * bv, lyx::pos_type & length);
167
168         ///
169         bool searchForward(BufferView * bv, string const & str,
170                            bool = true, bool = false);
171         bool searchBackward(BufferView * bv, string const & str,
172                             bool = true, bool = false);
173
174         ///
175         void addPreview(grfx::PreviewLoader &) const;
176
177 protected:
178         ///
179         virtual void cache(BufferView *) const;
180         ///
181         virtual BufferView * view() const;
182
183         ///
184         int ascent_collapsed() const;
185         ///
186         int descent_collapsed() const;
187         ///
188         int width_collapsed() const;
189         ///
190         void draw_collapsed(Painter & pain, int , float &) const;
191         ///
192         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
193
194         ///
195         mutable bool collapsed_;
196         ///
197         LColor::color framecolor;
198         ///
199         LyXFont labelfont;
200 public:
201         ///
202         mutable InsetText inset;
203 protected:
204         ///
205         mutable int button_length;
206         ///
207         mutable int button_top_y;
208         ///
209         mutable int button_bottom_y;
210         ///
211         mutable int topx;
212         mutable int topbaseline;
213
214 private:
215         ///
216         void lfunMouseRelease(FuncRequest const &);
217         ///
218         FuncRequest adjustCommand(FuncRequest const &);
219
220         ///
221         mutable string label;
222 #if 0
223         ///
224         bool autocollapse;
225 #endif
226         ///
227         mutable int oldWidth;
228         ///
229         bool in_update;
230         ///
231         mutable bool first_after_edit;
232         ///
233         mutable boost::weak_ptr<BufferView> view_;
234 };
235
236 #endif