]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Fix bug #6315: counters in insets that don't produce output have ghost values.
[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 "InsetText.h"
18
19 #include "Box.h"
20
21 #include <map>
22
23 namespace lyx {
24
25 class CursorSlice;
26 class InsetLayout;
27
28 namespace frontend { class Painter; }
29
30 /** A collapsable text inset
31
32 */
33 class InsetCollapsable : public InsetText {
34 public:
35         ///
36         InsetCollapsable(Buffer *, InsetText::UsePlain = InsetText::PlainLayout);
37         ///
38         InsetCollapsable(InsetCollapsable const & rhs);
39         ///
40         virtual ~InsetCollapsable();
41         ///
42         InsetCollapsable * asInsetCollapsable() { return this; }
43         ///
44         InsetCollapsable const * asInsetCollapsable() const { return this; }
45         ///
46         docstring toolTip(BufferView const & bv, int x, int y) const;
47         ///
48         docstring name() const { return from_ascii("Collapsable"); }
49         ///
50         void read(Lexer &);
51         ///
52         void write(std::ostream &) const;
53         ///
54         void metrics(MetricsInfo &, Dimension &) const;
55         ///
56         void draw(PainterInfo & pi, int x, int y) const;
57
58         /// return x,y of given position relative to the inset's baseline
59         void cursorPos(BufferView const & bv, CursorSlice const & sl,
60                 bool boundary, int & x, int & y) const;
61         /// Returns true if (mouse) action is over the inset's button.
62         /// Always returns false when the inset does not have a
63         /// button.
64         bool hitButton(FuncRequest const &) const;
65         ///
66         docstring const getNewLabel(docstring const & l) const;
67         ///
68         bool editable() const;
69         ///
70         bool hasSettings() const { return true; }
71         ///
72         bool clickable(int x, int y) const;
73         /// can we go further down on mouse click?
74         bool descendable(BufferView const & bv) const;
75         ///
76         void setLabel(docstring const & l);
77         ///
78         virtual void setButtonLabel() {}
79         ///
80         virtual docstring const buttonLabel(BufferView const &) const;
81         ///
82         bool isOpen(BufferView const & bv) const 
83                 { return geometry(bv) != ButtonOnly; }
84         ///
85         enum CollapseStatus {
86                 Collapsed,
87                 Open
88         };
89         ///
90         virtual void setStatus(Cursor & cur, CollapseStatus st);
91         ///
92         CollapseStatus status(BufferView const & bv) const;
93         /** Of the old CollapseStatus we only keep the values  
94          *  Open and Collapsed.
95          * We define a list of possible inset decoration
96          * styles, and a list of possible (concrete, visual)
97          * inset geometries. Relationships between them
98          * (geometries in body of table):
99          *
100          *               \       CollapseStatus:
101          *   Decoration:  \ Open                Collapsed
102          *   -------------+-------------------------------
103          *   Classic      | *) TopButton, <--x) ButtonOnly
104          *                | LeftButton
105          *   Minimalistic | NoButton            ButtonOnly
106          *   Conglomerate | SubLabel            Corners
107          *   ---------------------------------------------
108          *   *) toggled by openinlined_
109          *   x) toggled by auto_open_
110          */
111
112         /// Default looks
113         virtual InsetLayout::InsetDecoration decoration() const;
114         ///
115         enum Geometry {
116                 TopButton,
117                 ButtonOnly,
118                 NoButton,
119                 LeftButton,
120                 SubLabel,
121                 Corners
122         };
123         /// Returns the geometry based on CollapseStatus
124         /// (status_), auto_open_[BufferView] and openinlined_,
125         /// and of course decoration().
126         Geometry geometry(BufferView const & bv) const;
127         /// Returns the geometry disregarding auto_open_
128         Geometry geometry() const;
129         ///
130         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
131         ///
132         bool setMouseHover(BufferView const * bv, bool mouse_hover) const;
133         ///
134         ColorCode backgroundColor(PainterInfo const &) const
135                 { return getLayout().bgcolor(); }
136         ///
137         ColorCode labelColor() const { return getLayout().labelfont().color(); }
138         ///
139         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
140
141         ///
142         virtual bool usePlainLayout() const { return true; }
143         ///
144         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
145         ///
146         docstring floatName(std::string const & type) const;
147 protected:
148         ///
149         void doDispatch(Cursor & cur, FuncRequest & cmd);
150         ///
151         void edit(Cursor & cur, bool front, 
152                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
153         ///
154         Inset * editXY(Cursor & cur, int x, int y);
155         ///
156         mutable CollapseStatus status_;
157 private:
158         ///
159         Dimension dimensionCollapsed(BufferView const & bv) const;
160         ///
161         docstring labelstring_;
162         ///
163         mutable Box button_dim;
164         /// a substatus of the Open status, determined automatically in metrics
165         mutable bool openinlined_;
166         /// the inset will automatically open when the cursor is inside. This is
167         /// dependent on the bufferview, compare with MathMacro::editing_.
168         mutable std::map<BufferView const *, bool> auto_open_;
169         /// changes color when mouse enters/leaves this inset
170         mutable std::map<BufferView const *, bool> mouse_hover_;
171 };
172
173 } // namespace lyx
174
175 #endif