]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Make it compile when USE_BOOST_FORMAT is unset
[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 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "inset.h"
22 #include "insettext.h"
23 #include "lyxfont.h"
24 #include "LColor.h"
25
26 class Painter;
27 class LyXText;
28 class Paragraph;
29 class LyXCursor;
30
31 /** A collapsable text inset
32
33 */
34 class InsetCollapsable : public UpdatableInset {
35 public:
36         ///
37         enum UpdateCodes {
38                 NONE = 0,
39                 FULL
40         };
41         ///
42         static int const TEXT_TO_TOP_OFFSET = 2;
43         ///
44         static int const TEXT_TO_BOTTOM_OFFSET = 2;
45         /// inset is initially collapsed if bool = true
46         InsetCollapsable(BufferParams const &, bool = false);
47         ///
48         InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
49         ///
50         void read(Buffer const *, LyXLex &);
51         ///
52         void write(Buffer const *, std::ostream &) const;
53         ///
54         int ascent(BufferView *, LyXFont const &) const;
55         ///
56         int descent(BufferView *, LyXFont const &) const;
57         ///
58         int width(BufferView *, LyXFont const &) const;
59         ///
60         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
61         ///
62         void update(BufferView *, LyXFont const &, bool =false);
63         ///
64         void edit(BufferView *, int, int, mouse_button::state);
65         ///
66         void edit(BufferView *, bool front = true);
67         ///
68         EDITABLE editable() const;
69         ///
70         bool insertInset(BufferView *, Inset * inset);
71         ///
72         virtual bool insetAllowed(Inset::Code code) const {
73                 return inset.insetAllowed(code);
74         }
75         ///
76         bool isTextInset() const { return true; }
77         ///
78         bool doClearArea() const;
79         ///
80         void insetUnlock(BufferView *);
81         ///
82         bool needFullRow() const { return isOpen(); }
83         ///
84         bool lockInsetInInset(BufferView *, UpdatableInset *);
85         ///
86         bool unlockInsetInInset(BufferView *, UpdatableInset *,
87                                 bool lr = false);
88         ///
89         bool updateInsetInInset(BufferView *, Inset *);
90         ///
91         int insetInInsetY() const;
92         ///
93         RESULT localDispatch(FuncRequest const &);
94         ///
95         int latex(Buffer const *, std::ostream &,
96                   bool fragile, bool free_spc) const;
97         ///
98         int ascii(Buffer const *, std::ostream &, int) const;
99         ///
100         int linuxdoc(Buffer const *, std::ostream &) const;
101         ///
102         int docbook(Buffer const *, std::ostream &, bool mixcont) const;
103         ///
104         void validate(LaTeXFeatures & features) const;
105         ///
106         void getCursorPos(BufferView *, int & x, int & y) const;
107         ///
108         void toggleInsetCursor(BufferView *);
109         ///
110         void showInsetCursor(BufferView *, bool show = true);
111         ///
112         void hideInsetCursor(BufferView *);
113         ///
114         void fitInsetCursor(BufferView * bv) const {
115                 inset.fitInsetCursor(bv);
116         }
117         UpdatableInset * getLockingInset() const;
118         ///
119         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
120         ///
121         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
122                  bool selectall = false);
123         ///
124         void setLabel(string const & l) const;
125         ///
126         void setLabelFont(LyXFont & f) { labelfont = f; }
127 #if 0
128         ///
129         void setAutoCollapse(bool f) { autocollapse = f; }
130 #endif
131 #if 0
132         ///
133         int getMaxWidth(BufferView *, UpdatableInset const *) const;
134 #endif
135         ///
136         LyXText * getLyXText(BufferView const *, bool const recursive) const;
137         ///
138         void deleteLyXText(BufferView *, bool recursive=true) const;
139         ///
140         void resizeLyXText(BufferView *, bool force = false) const;
141         ///
142         std::vector<string> const getLabelList() const;
143         ///
144         bool nodraw() const;
145         ///
146         int scroll(bool recursive=true) const;
147         ///
148         void scroll(BufferView *bv, float sx) const {
149                 UpdatableInset::scroll(bv, sx);
150         }
151         ///
152         void scroll(BufferView *bv, int offset) const {
153                 UpdatableInset::scroll(bv, offset);
154         }
155         ///
156         Paragraph * getParFromID(int id) const;
157         ///
158         Inset * getInsetFromID(int id) const;
159         ///
160         Paragraph * firstParagraph() const;
161         ///
162         Paragraph * getFirstParagraph(int) const;
163         ///
164         LyXCursor const & cursor(BufferView *) const;
165         ///
166         bool isOpen() const { return !collapsed_; }
167         ///
168         void open(BufferView *);
169         ///
170         void close(BufferView *) const;
171         ///
172         bool allowSpellcheck() { return inset.allowSpellcheck(); }
173         ///
174         WordLangTuple const
175         selectNextWordToSpellcheck(BufferView *, float &) const;
176         ///
177         void selectSelectedWord(BufferView * bv) {
178                 inset.selectSelectedWord(bv);
179         }
180         ///
181         void toggleSelection(BufferView * bv, bool kill_selection) {
182                 inset.toggleSelection(bv, kill_selection);
183         }
184         ///
185         bool searchForward(BufferView * bv, string const & str,
186                            bool = true, bool = false);
187         bool searchBackward(BufferView * bv, string const & str,
188                             bool = true, bool = false);
189
190         ///
191         void addPreview(grfx::PreviewLoader &) const;
192
193 protected:
194         ///
195         int ascent_collapsed() const;
196         ///
197         int descent_collapsed() const;
198         ///
199         int width_collapsed() const;
200         ///
201         void draw_collapsed(Painter & pain, int , float &) const;
202         ///
203         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
204
205         ///
206         mutable bool collapsed_;
207         ///
208         LColor::color framecolor;
209         ///
210         LyXFont labelfont;
211 public:
212         ///
213         mutable InsetText inset;
214 protected:
215         ///
216         mutable int button_length;
217         ///
218         mutable int button_top_y;
219         ///
220         mutable int button_bottom_y;
221         ///
222         mutable int topx;
223         mutable int topbaseline;
224         mutable UpdateCodes need_update;
225
226 private:
227         ///
228         void lfunMousePress(FuncRequest const &);
229         ///
230         bool lfunMouseRelease(FuncRequest const &);
231         ///
232         void lfunMouseMotion(FuncRequest const &);
233
234         ///
235         mutable string label;
236 #if 0
237         ///
238         bool autocollapse;
239 #endif
240         ///
241         mutable int oldWidth;
242         ///
243         bool in_update;
244         ///
245         mutable bool first_after_edit;
246 };
247
248 #endif