]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
92c91a2704f4acc48376077cc53c3f3dca1d9424
[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         ///     By default, InsetCollapsable uses the plain layout. If you 
36         /// want to override this in a subclass, you'll need to call 
37         /// Paragraph::setDefaultLayout() in its constructor. See
38         /// InsetBranch for an example.
39         InsetCollapsable(Buffer const &);
40         ///
41         InsetCollapsable(InsetCollapsable const & rhs);
42         ///
43         InsetCollapsable * asInsetCollapsable() { return this; }
44         ///
45         InsetCollapsable const * asInsetCollapsable() const { return this; }
46         ///
47         docstring toolTip(BufferView const & bv, int x, int y) const;
48         ///
49         docstring name() const { return from_ascii("Collapsable"); }
50         ///
51         InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
52         ///
53         InsetLayout const & getLayout() const { return *layout_; } 
54         ///
55         void setLayout(BufferParams const &);
56         /// (Re-)set the character style parameters from \p tc according
57         /// to name()
58         void setLayout(DocumentClass const * const tc);
59         ///
60         virtual bool usePlainLayout() { return true; }
61         ///
62         void read(Lexer &);
63         ///
64         void write(std::ostream &) const;
65         ///
66         void metrics(MetricsInfo &, Dimension &) const;
67         ///
68         void draw(PainterInfo & pi, int x, int y) const;
69
70         /// return x,y of given position relative to the inset's baseline
71         void cursorPos(BufferView const & bv, CursorSlice const & sl,
72         ///
73         bool boundary, int & x, int & y) const;
74         /// Returns true if (mouse) action is over the inset's button.
75         /// Always returns false when the inset does not have a
76         /// button.
77         bool hitButton(FuncRequest const &) const;
78         ///
79         docstring const getNewLabel(docstring const & l) const;
80         ///
81         EDITABLE editable() const;
82         /// can we go further down on mouse click?
83         bool descendable() const;
84         ///
85         void setLabel(docstring const & l);
86         ///
87         virtual void setButtonLabel() {}
88         ///
89         bool isOpen() const { return geometry() != ButtonOnly; }
90         ///
91         CollapseStatus status() 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 autoOpen_
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_), autoOpen_ and openinlined_, and of
124         /// course decoration().
125         Geometry geometry() const;
126         /// Allow spellchecking, except for insets with latex_language
127         bool allowSpellCheck() const { return !forceLTR(); }
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 layout_->bgcolor(); }
138         ///
139         int latex(odocstream &, OutputParams const &) const;
140         ///
141         void validate(LaTeXFeatures &) const;
142         ///
143         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
144
145         /// Allow multiple blanks
146         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
147         /// Don't eliminate empty paragraphs
148         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
149         /// Force inset into LTR environment if surroundings are RTL?
150         virtual bool forceLTR() const { return layout_->isForceLtr(); }
151         ///
152         virtual bool usePlainLayout() const { return true; }
153         /// Is this inset's layout defined in the document's textclass?
154         /// May be wrong after textclass change or paste from another document
155         bool undefined() const;
156         ///
157         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
158 protected:
159         ///
160         void doDispatch(Cursor & cur, FuncRequest & cmd);
161         ///
162         void edit(Cursor & cur, bool front, 
163                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
164         ///
165         Inset * editXY(Cursor & cur, int x, int y);
166         ///
167         docstring floatName(std::string const & type, BufferParams const &) const;
168         ///
169         virtual void resetParagraphsFont();
170         ///
171         mutable CollapseStatus status_;
172 private:
173         /// cache for the layout_. Make sure it is in sync with the document class!
174         InsetLayout const * layout_;
175         ///
176         Dimension dimensionCollapsed() const;
177         ///
178         docstring labelstring_;
179         ///
180         mutable Box button_dim;
181         /// a substatus of the Open status, determined automatically in metrics
182         mutable bool openinlined_;
183         /// the inset will automatically open when the cursor is inside
184         mutable bool autoOpen_;
185         /// changes color when mouse enters/leaves this inset
186         bool mouse_hover_;
187 };
188
189 } // namespace lyx
190
191 #endif