]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
d73daedfdee65bee2eab0434a672076ad25ad657
[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 #include "box.h"
23
24 #include <boost/weak_ptr.hpp>
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         static int const TEXT_TO_TOP_OFFSET = 2;
38         ///
39         static int const TEXT_TO_BOTTOM_OFFSET = 2;
40         /// inset is initially collapsed if bool = true
41         InsetCollapsable(BufferParams const &, bool collapsed = false);
42         ///
43         InsetCollapsable(InsetCollapsable const & in);
44         ///
45         void read(Buffer const *, LyXLex &);
46         ///
47         void write(Buffer const *, std::ostream &) const;
48         ///
49         void metrics(MetricsInfo &, Dimension &) const;
50         ///
51         void draw(PainterInfo & pi, int x, int y) const;
52         /// draw, either inlined (no button) or collapsed/open
53         void draw(PainterInfo & pi, int x, int y, bool inlined) const;
54         ///
55         bool hitButton(FuncRequest const &) const;
56         ///
57         EDITABLE editable() const;
58         ///
59         bool insertInset(BufferView *, InsetOld * inset);
60         ///
61         virtual bool insetAllowed(InsetOld::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 *, InsetOld *);
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(InsetOld::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         void getLabelList(std::vector<string> &) const;
122         ///
123         int scroll(bool recursive=true) const;
124         ///
125         void scroll(BufferView *bv, float sx) const {
126                 UpdatableInset::scroll(bv, sx);
127         }
128         ///
129         void scroll(BufferView *bv, int offset) const {
130                 UpdatableInset::scroll(bv, offset);
131         }
132         ///
133         InsetOld * getInsetFromID(int id) const;
134         ///
135         ParagraphList * getParagraphs(int) const;
136         ///
137         LyXCursor const & cursor(BufferView *) const;
138         ///
139         bool isOpen() const { return !collapsed_; }
140         ///
141         void open(BufferView *);
142         ///
143         void close(BufferView *) const;
144         ///
145         bool allowSpellcheck() const { return inset.allowSpellcheck(); }
146         ///
147         WordLangTuple const
148         selectNextWordToSpellcheck(BufferView *, float &) const;
149         ///
150         void selectSelectedWord(BufferView * bv) {
151                 inset.selectSelectedWord(bv);
152         }
153
154         void markErased();
155
156         bool nextChange(BufferView * bv, lyx::pos_type & length);
157
158         ///
159         bool searchForward(BufferView * bv, string const & str,
160                            bool = true, bool = false);
161         bool searchBackward(BufferView * bv, string const & str,
162                             bool = true, bool = false);
163
164         ///
165         void addPreview(lyx::graphics::PreviewLoader &) const;
166
167 protected:
168         ///
169         virtual void cache(BufferView *) const;
170         ///
171         virtual BufferView * view() const;
172
173         ///
174         void dimension_collapsed(Dimension &) const;
175         ///
176         int height_collapsed() const;
177         ///
178         void draw_collapsed(PainterInfo & pi, int x, int y) const;
179         ///
180         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
181
182         ///
183         mutable bool collapsed_;
184         ///
185         LColor::color framecolor;
186         ///
187         LyXFont labelfont;
188 public:
189         ///
190         mutable InsetText inset;
191 protected:
192         ///
193         mutable Box button_dim;
194         ///
195         mutable int topx;
196         mutable int topbaseline;
197
198 private:
199         ///
200         void lfunMouseRelease(FuncRequest const &);
201         ///
202         FuncRequest adjustCommand(FuncRequest const &);
203
204         ///
205         mutable string label;
206 #if 0
207         ///
208         bool autocollapse;
209 #endif
210         ///
211         mutable int oldWidth;
212         ///
213         bool in_update;
214         ///
215         mutable bool first_after_edit;
216         ///
217         mutable boost::weak_ptr<BufferView> view_;
218 };
219
220 #endif