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