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