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