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