]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Embedding: merge lyx::EmbeddedFiles to lyx::support::EmbeddedFileList
[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 "InsetLayout.h"
19 #include "InsetText.h"
20
21 #include "Box.h"
22
23 #include <string>
24
25 namespace lyx {
26
27 class CursorSlice;
28 class FontInfo;
29 class InsetLayout;
30 class Paragraph;
31 class Text;
32
33 namespace frontend { class Painter; }
34
35 /** A collapsable text inset
36
37 */
38 class InsetCollapsable : public InsetText {
39 public:
40         ///
41         InsetCollapsable(
42                 BufferParams const &,
43                 CollapseStatus status = Inset::Open,
44                 InsetLayout const * il = 0
45                 );
46         ///
47         InsetCollapsable(InsetCollapsable const & rhs);
48         
49         InsetCollapsable * asInsetCollapsable() { return this; }
50         InsetCollapsable const * asInsetCollapsable() const { return this; }
51         docstring toolTip(BufferView const & bv, int x, int y) const;
52         docstring name() const { return from_ascii("Collapsable"); }
53         InsetLayout const & getLayout(BufferParams const &) const
54         { return *layout_; } 
55         ///
56         void setLayout(BufferParams const &);
57         /// (Re-)set the character style parameters from \p il
58         void setLayout(InsetLayout const & il);
59         ///
60         void read(Buffer const &, Lexer &);
61         ///
62         void write(Buffer const &, std::ostream &) const;
63         ///
64         void metrics(MetricsInfo &, Dimension &) const;
65         ///
66         void draw(PainterInfo & pi, int x, int y) const;
67
68         /// return x,y of given position relative to the inset's baseline
69         void cursorPos(BufferView const & bv, CursorSlice const & sl,
70                 bool boundary, int & x, int & y) const;
71         ///
72         bool hitButton(FuncRequest const &) const;
73         ///
74         docstring const getNewLabel(docstring const & l) const;
75         ///
76         EDITABLE editable() const;
77         /// can we go further down on mouse click?
78         bool descendable() const;
79         ///
80         bool isMacroScope(Buffer const & buf) const;
81         ///
82         void setLabel(docstring const & l);
83         ///
84         virtual void setButtonLabel() {}
85         ///
86         bool isOpen() const { return geometry() != ButtonOnly; }
87         ///
88         CollapseStatus status() const;
89         /** Of the old CollapseStatus we only keep the values  
90          *  Open and Collapsed.
91          * We define a list of possible inset decoration
92          * styles, and a list of possible (concrete, visual)
93          * inset geometries. Relationships between them
94          * (geometries in body of table):
95          *
96          *               \       CollapseStatus:
97          *   Decoration:  \ Open                Collapsed
98          *   -------------+-------------------------------
99          *   Classic      | *) TopButton, <--x) ButtonOnly
100          *                | LeftButton
101          *   Minimalistic | ButtonOnly          NoButton
102          *   Conglomerate | SubLabel            Corners
103          *   ---------------------------------------------
104          *   *) toggled by openinlined_
105          *   x) toggled by autoOpen_
106          */
107
108         ///
109         enum Decoration {
110                 Classic,
111                 Minimalistic,
112                 Conglomerate
113         };
114         /// Default looks
115         virtual Decoration decoration() const;
116         ///
117         enum Geometry {
118                 TopButton,
119                 ButtonOnly,
120                 NoButton,
121                 LeftButton,
122                 SubLabel,
123                 Corners
124         };
125         /// Returns the geometry based on CollapseStatus
126         /// (status_), autoOpen_ and openinlined_, and of
127         /// course decoration().
128         Geometry geometry() const;
129         ///
130         bool allowSpellCheck() const { return true; }
131         ///
132         bool allowMultiPar() const;
133         ///
134         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
135         ///
136         void setStatus(Cursor & cur, CollapseStatus st);
137         ///
138         bool setMouseHover(bool mouse_hover);
139         ///
140         virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
141
142         int latex(Buffer const &, odocstream &,
143                   OutputParams const &) const;
144         ///
145         void validate(LaTeXFeatures &) const;
146         ///
147         virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
148
149         /// Allow multiple blanks
150         virtual bool isFreeSpacing() const { return layout_->freespacing; }
151         /// Don't eliminate empty paragraphs
152         virtual bool allowEmpty() const { return layout_->keepempty; }
153         /// Force inset into LTR environment if surroundings are RTL?
154         virtual bool forceLTR() const { return layout_->forceltr; }
155
156 protected:
157         ///
158         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
159         ///
160         void edit(Cursor & cur, bool left);
161         ///
162         Inset * editXY(Cursor & cur, int x, int y);
163         ///
164         docstring floatName(std::string const & type, BufferParams const &) const;
165         ///
166         virtual void resetParagraphsFont();
167
168 protected:
169         ///
170         InsetLayout const * layout_;
171 private:
172         ///
173         Dimension dimensionCollapsed() const;
174         ///
175         docstring labelstring_;
176         ///
177         mutable Box button_dim;
178         ///
179         mutable CollapseStatus status_;
180         /// a substatus of the Open status, determined automatically in metrics
181         mutable bool openinlined_;
182         /// the inset will automatically open when the cursor is inside
183         mutable bool autoOpen_;
184         /// changes color when mouse enters/leaves this inset
185         bool mouse_hover_;
186 };
187
188 } // namespace lyx
189
190 #endif