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