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