]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
more IU
[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         bool hitButton(FuncRequest const &) const;
57         ///
58         std::string const getNewLabel(std::string const & l) const;
59         ///
60         EDITABLE editable() const;
61         /// can we go further down on mouse click?
62         bool descendable() const;
63         ///
64         bool insetAllowed(InsetOld::Code code) const;
65         ///
66         bool isTextInset() const { return true; }
67         ///
68         int latex(Buffer const &, std::ostream &,
69                   OutputParams const &) const;
70         ///
71         int plaintext(Buffer const &, std::ostream &,
72                   OutputParams const &) const;
73         ///
74         int linuxdoc(Buffer const &, std::ostream &,
75                      OutputParams const &) const;
76         ///
77         int docbook(Buffer const &, std::ostream &,
78                     OutputParams const & runparams) const;
79         ///
80         void validate(LaTeXFeatures & features) const;
81         /// get the screen x,y of the cursor
82         void getCursorPos(int cell, int & x, int & y) const;
83         ///
84         void setLabel(std::string const & l);
85         ///
86         virtual void setButtonLabel() {};
87         ///
88         void setLabelFont(LyXFont & f);
89         /// Appends \c list with all labels found within this inset.
90         void getLabelList(Buffer const &, std::vector<std::string> & list) const;
91         ///
92         int scroll(bool recursive=true) const;
93         ///
94         void scroll(BufferView & bv, float sx) const;
95         ///
96         void scroll(BufferView & bv, int offset) const;
97         ///
98         int numParagraphs() const;
99         ///
100         LyXText * getText(int) const;
101         ///
102         bool isOpen() const { return status_ == Open || status_ == Inlined; }
103         ///
104         bool inlined() const { return status_ == Inlined; }
105         ///
106         CollapseStatus status() const { return status_; }
107         ///
108         void open();
109         ///
110         void close();
111         ///
112         void markErased();
113         ///
114         void addPreview(lyx::graphics::PreviewLoader &) const;
115         ///
116         void setBackgroundColor(LColor_color);
117         ///
118         void setStatus(CollapseStatus st);
119         ///
120         bool allowSpellCheck() const { return true; }
121
122 protected:
123         ///
124         virtual
125         DispatchResult
126         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         FuncRequest adjustCommand(FuncRequest const &);
147
148 public:
149         ///
150         mutable InsetText inset;
151 private:
152         ///
153         mutable CollapseStatus status_;
154 protected:
155         ///
156         LyXFont labelfont_;
157         ///
158         mutable Box button_dim;
159         ///
160         mutable int topx;
161         ///
162         mutable int topbaseline;
163         ///
164         mutable std::string label;
165 };
166
167 #endif