]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
61be4dae7a5bb88b77484ce046f0870493534c13
[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 latex(Buffer const &, std::ostream &,
65                   OutputParams const &) const;
66         ///
67         int plaintext(Buffer const &, std::ostream &,
68                   OutputParams const &) const;
69         ///
70         int linuxdoc(Buffer const &, std::ostream &,
71                      OutputParams const &) const;
72         ///
73         int docbook(Buffer const &, std::ostream &,
74                     OutputParams const & runparams) const;
75         ///
76         void validate(LaTeXFeatures & features) const;
77         /// get the screen x,y of the cursor
78         void getCursorPos(int & x, int & y) const;
79         ///
80         void setLabel(std::string const & l) const;
81         ///
82         void setLabelFont(LyXFont & f);
83 #if 0
84         ///
85         void setAutoCollapse(bool f);
86 #endif
87         /// Appends \c list with all labels found within this inset.
88         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
89         ///
90         int scroll(bool recursive=true) const;
91         ///
92         void scroll(BufferView *bv, float sx) const;
93         ///
94         void scroll(BufferView *bv, int offset) const;
95         ///
96         ParagraphList * getParagraphs(int) const;
97         ///
98         int numParagraphs() const;
99         ///
100         LyXText * getText(int) const;
101         ///
102         bool display() const { return isOpen(); }
103         ///
104         bool isOpen() const;
105         ///
106         void open();
107         ///
108         void close() const;
109         ///
110         void markErased();
111         ///
112         void addPreview(lyx::graphics::PreviewLoader &) const;
113
114 protected:
115         ///
116         virtual
117         DispatchResult
118         priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
119         ///
120         void dimension_collapsed(Dimension &) const;
121         ///
122         int height_collapsed() const;
123         ///
124         void draw_collapsed(PainterInfo & pi, int x, int y) const;
125         ///
126         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
127         /// Should be non-const...
128         void setCollapsed(bool) const;
129         ///
130         Box const & buttonDim() const;
131         ///
132         void edit(BufferView *, bool);
133         ///
134         void edit(BufferView *, int, int);
135
136 private:
137         ///
138         DispatchResult lfunMouseRelease(FuncRequest const &);
139         ///
140         FuncRequest adjustCommand(FuncRequest const &);
141
142 public:
143         ///
144         mutable InsetText inset;
145 private:
146         ///
147         mutable bool collapsed_;
148         ///
149         LyXFont labelfont_;
150         ///
151         mutable Box button_dim;
152         ///
153         mutable int topx;
154         ///
155         mutable int topbaseline;
156         ///
157         mutable std::string label;
158 #if 0
159         ///
160         bool autocollapse;
161 #endif
162 };
163
164 #endif