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