]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
f8f095b719086265e26fbbd4c7e1492da15f97d3
[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 class Painter;
24 class LyXText;
25 class Paragraph;
26 class LyXCursor;
27
28 /** A collapsable text inset
29
30 */
31 class InsetCollapsable : public UpdatableInset {
32 public:
33         ///
34         static int const TEXT_TO_TOP_OFFSET = 2;
35         ///
36         static int const TEXT_TO_BOTTOM_OFFSET = 2;
37         /// inset is initially collapsed if bool = true
38         InsetCollapsable(BufferParams const &, bool collapsed = false);
39         ///
40         InsetCollapsable(InsetCollapsable const & in);
41         ///
42         void read(Buffer const &, LyXLex &);
43         ///
44         void write(Buffer const &, std::ostream &) const;
45         ///
46         void metrics(MetricsInfo &, Dimension &) const;
47         ///
48         void draw(PainterInfo & pi, int x, int y) const;
49         /// draw, either inlined (no button) or collapsed/open
50         void draw(PainterInfo & pi, int x, int y, bool inlined) const;
51         ///
52         bool hitButton(FuncRequest const &) const;
53         ///
54         EDITABLE editable() const;
55         /// can we go further down on mouse click?
56         bool descendable() const { return isOpen(); }
57         ///
58         bool insertInset(BufferView *, InsetOld * inset);
59         ///
60         bool insetAllowed(InsetOld::Code code) const;
61         ///
62         bool isTextInset() const { return true; }
63         ///
64         int insetInInsetY() const;
65         ///
66         int latex(Buffer const &, std::ostream &,
67                   OutputParams const &) const;
68         ///
69         int plaintext(Buffer const &, std::ostream &,
70                   OutputParams const &) const;
71         ///
72         int linuxdoc(Buffer const &, std::ostream &,
73                      OutputParams const &) const;
74         ///
75         int docbook(Buffer const &, std::ostream &,
76                     OutputParams const & runparams) const;
77         ///
78         void validate(LaTeXFeatures & features) const;
79         /// get the screen x,y of the cursor
80         void getCursorPos(BufferView *, int & x, int & y) const;
81         ///
82         void fitInsetCursor(BufferView * bv) const;
83         ///
84         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
85                  bool selectall = false);
86         ///
87         void setLabel(std::string const & l) const;
88         ///
89         void setLabelFont(LyXFont & f);
90 #if 0
91         ///
92         void setAutoCollapse(bool f);
93 #endif
94         ///
95         void deleteLyXText(BufferView *) const;
96         /// Appends \c list with all labels found within this inset.
97         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
98         ///
99         int scroll(bool recursive=true) const;
100         ///
101         void scroll(BufferView *bv, float sx) const;
102         ///
103         void scroll(BufferView *bv, int offset) const;
104         ///
105         ParagraphList * getParagraphs(int) const;
106         ///
107         int numParagraphs() const;
108         ///
109         LyXText * getText(int) const;
110         ///
111         bool display() const { return isOpen(); }
112         ///
113         bool isOpen() const;
114         ///
115         void open(BufferView *);
116         ///
117         void close(BufferView *) const;
118         ///
119         void markErased();
120         ///
121         void addPreview(lyx::graphics::PreviewLoader &) const;
122
123 protected:
124         ///
125         virtual
126         DispatchResult
127         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
128         ///
129         void dimension_collapsed(Dimension &) const;
130         ///
131         int height_collapsed() const;
132         ///
133         void draw_collapsed(PainterInfo & pi, int x, int y) const;
134         ///
135         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
136         /// Should be non-const...
137         void setCollapsed(bool) const;
138         ///
139         Box const & buttonDim() const;
140         ///
141         void edit(BufferView *, bool);
142         ///
143         void edit(BufferView *, int, int);
144
145 private:
146         ///
147         DispatchResult lfunMouseRelease(FuncRequest const &);
148         ///
149         FuncRequest adjustCommand(FuncRequest const &);
150
151 public:
152         ///
153         mutable InsetText inset;
154 private:
155         ///
156         mutable bool collapsed_;
157         ///
158         LyXFont labelfont_;
159         ///
160         mutable Box button_dim;
161         ///
162         mutable int topx;
163         ///
164         mutable int topbaseline;
165         ///
166         mutable std::string label;
167 #if 0
168         ///
169         bool autocollapse;
170 #endif
171 };
172
173 #endif