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