]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
761faa9c901a6b8c02a54bfc5bd608884cc71701
[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 CursorSlice;
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         ///
38         enum CollapseStatus {
39                 Open,
40                 Collapsed,
41                 Inlined
42         };
43         ///
44         InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
45         ///
46         InsetCollapsable(InsetCollapsable const & in);
47         ///
48         void read(Buffer const &, LyXLex &);
49         ///
50         void write(Buffer const &, std::ostream &) const;
51         ///
52         void metrics(MetricsInfo &, Dimension &) const;
53         ///
54         void draw(PainterInfo & pi, int x, int y) const;
55         ///
56         void drawSelection(PainterInfo & pi, int x, int y) const;
57         ///
58         bool hitButton(FuncRequest const &) const;
59         ///
60         std::string const getNewLabel(std::string const & l) const;
61         ///
62         EDITABLE editable() const;
63         /// can we go further down on mouse click?
64         bool descendable() const;
65         ///
66         bool insetAllowed(InsetOld::Code code) const;
67         ///
68         bool isTextInset() const { return true; }
69         ///
70         int latex(Buffer const &, std::ostream &,
71                   OutputParams const &) const;
72         ///
73         int plaintext(Buffer const &, std::ostream &,
74                   OutputParams const &) const;
75         ///
76         int linuxdoc(Buffer const &, std::ostream &,
77                      OutputParams const &) const;
78         ///
79         int docbook(Buffer const &, std::ostream &,
80                     OutputParams const & runparams) const;
81         ///
82         void validate(LaTeXFeatures & features) const;
83         /// get the screen x,y of the cursor
84         void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
85         ///
86         void setLabel(std::string const & l);
87         ///
88         virtual void setButtonLabel() {}
89         ///
90         void setLabelFont(LyXFont & f);
91         /// Appends \c list with all labels found within this inset.
92         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
93         ///
94         int scroll(bool recursive = true) const;
95         ///
96         void scroll(BufferView & bv, float sx) const;
97         ///
98         void scroll(BufferView & bv, int offset) const;
99         ///
100         int numParagraphs() const;
101         ///
102         LyXText * getText(int) const;
103         ///
104         bool isOpen() const { return status_ == Open || status_ == Inlined; }
105         ///
106         bool inlined() const { return status_ == Inlined; }
107         ///
108         CollapseStatus status() const { return status_; }
109         ///
110         void open();
111         ///
112         void close();
113         ///
114         void markErased();
115         ///
116         void addPreview(lyx::graphics::PreviewLoader &) const;
117         ///
118         void setBackgroundColor(LColor_color);
119         ///
120         void setStatus(CollapseStatus st);
121         ///
122         bool allowSpellCheck() const { return true; }
123
124 protected:
125         ///
126         DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
127         ///
128         void dimension_collapsed(Dimension &) const;
129         ///
130         int height_collapsed() const;
131         ///
132         void draw_collapsed(PainterInfo & pi, int x, int y) const;
133         ///
134         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
135         ///
136         Box const & buttonDim() const;
137         ///
138         void edit(LCursor & cur, bool left);
139         ///
140         void edit(LCursor & cur, int x, int y);
141
142 private:
143         ///
144         DispatchResult lfunMouseRelease(LCursor & cur, FuncRequest const & cmd);
145
146 public:
147         ///
148         mutable InsetText inset;
149 protected:
150         ///
151         LyXFont labelfont_;
152         ///
153         mutable Box button_dim;
154         ///
155         mutable int topx;
156         ///
157         mutable int topbaseline;
158         ///
159         mutable std::string label;
160 private:
161         ///
162         mutable CollapseStatus status_;
163 };
164
165 #endif