]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Fix InsetLine metrics and drawing.
[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 "TextClass.h"
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         /// can we go further down on mouse click?
72         bool descendable(BufferView const & bv) const;
73         ///
74         void setLabel(docstring const & l);
75         ///
76         virtual void setButtonLabel() {}
77         ///
78         virtual docstring const buttonLabel(BufferView const &) const;
79         ///
80         bool isOpen(BufferView const & bv) const 
81                 { return geometry(bv) != ButtonOnly; }
82         ///
83         enum CollapseStatus {
84                 Collapsed,
85                 Open
86         };
87         ///
88         virtual void setStatus(Cursor & cur, CollapseStatus st);
89         ///
90         CollapseStatus status(BufferView const & bv) const;
91         /** Of the old CollapseStatus we only keep the values  
92          *  Open and Collapsed.
93          * We define a list of possible inset decoration
94          * styles, and a list of possible (concrete, visual)
95          * inset geometries. Relationships between them
96          * (geometries in body of table):
97          *
98          *               \       CollapseStatus:
99          *   Decoration:  \ Open                Collapsed
100          *   -------------+-------------------------------
101          *   Classic      | *) TopButton, <--x) ButtonOnly
102          *                | LeftButton
103          *   Minimalistic | NoButton            ButtonOnly
104          *   Conglomerate | SubLabel            Corners
105          *   ---------------------------------------------
106          *   *) toggled by openinlined_
107          *   x) toggled by auto_open_
108          */
109
110         /// Default looks
111         virtual InsetLayout::InsetDecoration decoration() const;
112         ///
113         enum Geometry {
114                 TopButton,
115                 ButtonOnly,
116                 NoButton,
117                 LeftButton,
118                 SubLabel,
119                 Corners
120         };
121         /// Returns the geometry based on CollapseStatus
122         /// (status_), auto_open_[BufferView] and openinlined_,
123         /// and of course decoration().
124         Geometry geometry(BufferView const & bv) const;
125         /// Returns the geometry disregarding auto_open_
126         Geometry geometry() const;
127         ///
128         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
129         ///
130         bool setMouseHover(BufferView const * bv, bool mouse_hover);
131         ///
132         ColorCode backgroundColor(PainterInfo const &) const
133                 { return getLayout().bgcolor(); }
134         ///
135         ColorCode labelColor() const { return getLayout().labelfont().color(); }
136         ///
137         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
138
139         ///
140         virtual bool usePlainLayout() const { return true; }
141         ///
142         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
143         ///
144         docstring floatName(std::string const & type) const;
145 protected:
146         ///
147         void doDispatch(Cursor & cur, FuncRequest & cmd);
148         ///
149         void edit(Cursor & cur, bool front, 
150                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
151         ///
152         Inset * editXY(Cursor & cur, int x, int y);
153         ///
154         mutable CollapseStatus status_;
155 private:
156         ///
157         Dimension dimensionCollapsed(BufferView const & bv) const;
158         ///
159         docstring labelstring_;
160         ///
161         mutable Box button_dim;
162         /// a substatus of the Open status, determined automatically in metrics
163         mutable bool openinlined_;
164         /// the inset will automatically open when the cursor is inside. This is
165         /// dependent on the bufferview, compare with MathMacro::editing_.
166         mutable std::map<BufferView const *, bool> auto_open_;
167         /// changes color when mouse enters/leaves this inset
168         mutable std::map<BufferView const *, bool> mouse_hover_;
169 };
170
171 } // namespace lyx
172
173 #endif