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