]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
Inset::addToToc(): change signature. Use DocIterator instead of ParConstIterator...
[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 &, CollapseStatus status = Inset::Open);
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         InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
49         ///
50         InsetLayout const & getLayout() const { return *layout_; } 
51         ///
52         void setLayout(BufferParams const &);
53         /// (Re-)set the character style parameters from \p tc according
54         /// to name()
55         void setLayout(DocumentClass const * const tc);
56         ///
57         virtual bool useEmptyLayout() { return true; }
58         ///
59         void read(Lexer &);
60         ///
61         void write(std::ostream &) const;
62         ///
63         void metrics(MetricsInfo &, Dimension &) const;
64         ///
65         void draw(PainterInfo & pi, int x, int y) const;
66
67         /// return x,y of given position relative to the inset's baseline
68         void cursorPos(BufferView const & bv, CursorSlice const & sl,
69         ///
70         bool boundary, int & x, int & y) const;
71         ///
72         bool hitButton(FuncRequest const &) const;
73         ///
74         docstring const getNewLabel(docstring const & l) const;
75         ///
76         EDITABLE editable() const;
77         /// can we go further down on mouse click?
78         bool descendable() const;
79         ///
80         void setLabel(docstring const & l);
81         ///
82         virtual void setButtonLabel() {}
83         ///
84         bool isOpen() const { return geometry() != ButtonOnly; }
85         ///
86         CollapseStatus status() const;
87         /** Of the old CollapseStatus we only keep the values  
88          *  Open and Collapsed.
89          * We define a list of possible inset decoration
90          * styles, and a list of possible (concrete, visual)
91          * inset geometries. Relationships between them
92          * (geometries in body of table):
93          *
94          *               \       CollapseStatus:
95          *   Decoration:  \ Open                Collapsed
96          *   -------------+-------------------------------
97          *   Classic      | *) TopButton, <--x) ButtonOnly
98          *                | LeftButton
99          *   Minimalistic | NoButton            ButtonOnly
100          *   Conglomerate | SubLabel            Corners
101          *   ---------------------------------------------
102          *   *) toggled by openinlined_
103          *   x) toggled by autoOpen_
104          */
105
106         /// Default looks
107         virtual InsetLayout::InsetDecoration decoration() const;
108         ///
109         enum Geometry {
110                 TopButton,
111                 ButtonOnly,
112                 NoButton,
113                 LeftButton,
114                 SubLabel,
115                 Corners
116         };
117         /// Returns the geometry based on CollapseStatus
118         /// (status_), autoOpen_ and openinlined_, and of
119         /// course decoration().
120         Geometry geometry() const;
121         /// Allow spellchecking, except for insets with latex_language
122         bool allowSpellCheck() const { return !forceLTR(); }
123         ///
124         bool allowMultiPar() const;
125         ///
126         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
127         ///
128         void setStatus(Cursor & cur, CollapseStatus st);
129         ///
130         bool setMouseHover(bool mouse_hover);
131         ///
132         ColorCode backgroundColor() const { return layout_->bgcolor(); }
133         ///
134         int latex(odocstream &, OutputParams const &) const;
135         ///
136         void validate(LaTeXFeatures &) const;
137         ///
138         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
139
140         /// Allow multiple blanks
141         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
142         /// Don't eliminate empty paragraphs
143         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
144         /// Force inset into LTR environment if surroundings are RTL?
145         virtual bool forceLTR() const { return layout_->isForceLtr(); }
146         ///
147         virtual bool useEmptyLayout() const { return true; }
148         /// Is this inset's layout defined in the document's textclass?
149         /// May be wrong after textclass change or paste from another document
150         bool undefined() const;
151         ///
152         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
153 protected:
154         ///
155         void doDispatch(Cursor & cur, FuncRequest & cmd);
156         ///
157         void edit(Cursor & cur, bool front, 
158                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
159         ///
160         Inset * editXY(Cursor & cur, int x, int y);
161         ///
162         docstring floatName(std::string const & type, BufferParams const &) const;
163         ///
164         virtual void resetParagraphsFont();
165
166 private:
167         /// cache for the layout_. Make sure it is in sync with the document class!
168         InsetLayout const * layout_;
169         ///
170         Dimension dimensionCollapsed() const;
171         ///
172         docstring labelstring_;
173         ///
174         mutable Box button_dim;
175         ///
176         mutable CollapseStatus status_;
177         /// a substatus of the Open status, determined automatically in metrics
178         mutable bool openinlined_;
179         /// the inset will automatically open when the cursor is inside
180         mutable bool autoOpen_;
181         /// changes color when mouse enters/leaves this inset
182         bool mouse_hover_;
183 };
184
185 } // namespace lyx
186
187 #endif