]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
0ed8bcf63fc55ecd8979af7e6a591443677db25d
[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                 { return labelstring_; }
78         ///
79         bool isOpen(BufferView const & bv) const 
80                 { return geometry(bv) != ButtonOnly; }
81         ///
82         CollapseStatus status(BufferView const & bv) const;
83         /** Of the old CollapseStatus we only keep the values  
84          *  Open and Collapsed.
85          * We define a list of possible inset decoration
86          * styles, and a list of possible (concrete, visual)
87          * inset geometries. Relationships between them
88          * (geometries in body of table):
89          *
90          *               \       CollapseStatus:
91          *   Decoration:  \ Open                Collapsed
92          *   -------------+-------------------------------
93          *   Classic      | *) TopButton, <--x) ButtonOnly
94          *                | LeftButton
95          *   Minimalistic | NoButton            ButtonOnly
96          *   Conglomerate | SubLabel            Corners
97          *   ---------------------------------------------
98          *   *) toggled by openinlined_
99          *   x) toggled by auto_open_
100          */
101
102         /// Default looks
103         virtual InsetLayout::InsetDecoration decoration() const;
104         ///
105         enum Geometry {
106                 TopButton,
107                 ButtonOnly,
108                 NoButton,
109                 LeftButton,
110                 SubLabel,
111                 Corners
112         };
113         /// Returns the geometry based on CollapseStatus
114         /// (status_), auto_open_[BufferView] and openinlined_,
115         /// and of course decoration().
116         Geometry geometry(BufferView const & bv) const;
117         /// Returns the geometry disregarding auto_open_
118         Geometry geometry() const;
119         ///
120         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
121         ///
122         void setStatus(Cursor & cur, CollapseStatus st);
123         ///
124         bool setMouseHover(bool mouse_hover);
125         ///
126         ColorCode backgroundColor() const { return getLayout().bgcolor(); }
127         ///
128         ColorCode labelColor() const { return getLayout().labelfont().color(); }
129         ///
130         int latex(odocstream &, OutputParams const &) const;
131         ///
132         int docbook(odocstream &, OutputParams const &) const;
133         /// It will rarely be right to call this from subclasses, due
134         /// to the fact that it steps counters, etc. Instead, call
135         /// InsetText::xhtml().
136         docstring xhtml(odocstream &, OutputParams const &) const;
137         ///
138         void validate(LaTeXFeatures &) const;
139         ///
140         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
141
142         ///
143         virtual bool usePlainLayout() const { return true; }
144         /// Is this inset's layout defined in the document's textclass?
145         /// May be wrong after textclass change or paste from another document
146         bool undefined() const;
147         /// the string that is passed to the TOC
148         void tocString(odocstream &) const;
149         ///
150         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
151 protected:
152         ///
153         void doDispatch(Cursor & cur, FuncRequest & cmd);
154         ///
155         void edit(Cursor & cur, bool front, 
156                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
157         ///
158         Inset * editXY(Cursor & cur, int x, int y);
159         ///
160         docstring floatName(std::string const & type) const;
161         ///
162         virtual void resetParagraphsFont();
163         ///
164         mutable CollapseStatus status_;
165 private:
166         ///
167         Dimension dimensionCollapsed(BufferView const & bv) const;
168         ///
169         /// should paragraphs be forced to use the empty layout?
170         virtual bool forcePlainLayout(idx_type = 0) const 
171                 { return getLayout().forcePlainLayout(); }
172         /// should the user be allowed to customize alignment, etc.?
173         virtual bool allowParagraphCustomization(idx_type = 0) const 
174                 { return getLayout().allowParagraphCustomization(); }
175         docstring labelstring_;
176         ///
177         mutable Box button_dim;
178         /// a substatus of the Open status, determined automatically in metrics
179         mutable bool openinlined_;
180         /// the inset will automatically open when the cursor is inside. This is
181         /// dependent on the bufferview, compare with MathMacro::editing_.
182         mutable std::map<BufferView const *, bool> auto_open_;
183         /// changes color when mouse enters/leaves this inset
184         bool mouse_hover_;
185 };
186
187 } // namespace lyx
188
189 #endif