]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
2308ae753f385c89f41396939109bb46dad2764f
[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                 bool boundary, int & x, int & y) const;
73         /// Returns true if (mouse) action is over the inset's button.
74         /// Always returns false when the inset does not have a
75         /// button.
76         bool hitButton(FuncRequest const &) const;
77         ///
78         docstring const getNewLabel(docstring const & l) const;
79         ///
80         EDITABLE editable(BufferView const & bv) const;
81         /// can we go further down on mouse click?
82         bool descendable(BufferView const & bv) const;
83         ///
84         void setLabel(docstring const & l);
85         ///
86         virtual void setButtonLabel() {}
87         ///
88         virtual docstring const buttonLabel(BufferView const & bv) const
89                 { return labelstring_; }
90         ///
91         bool isOpen(BufferView const & bv) const 
92                 { return geometry(bv) != ButtonOnly; }
93         ///
94         CollapseStatus status(BufferView const & bv) const;
95         /** Of the old CollapseStatus we only keep the values  
96          *  Open and Collapsed.
97          * We define a list of possible inset decoration
98          * styles, and a list of possible (concrete, visual)
99          * inset geometries. Relationships between them
100          * (geometries in body of table):
101          *
102          *               \       CollapseStatus:
103          *   Decoration:  \ Open                Collapsed
104          *   -------------+-------------------------------
105          *   Classic      | *) TopButton, <--x) ButtonOnly
106          *                | LeftButton
107          *   Minimalistic | NoButton            ButtonOnly
108          *   Conglomerate | SubLabel            Corners
109          *   ---------------------------------------------
110          *   *) toggled by openinlined_
111          *   x) toggled by autoOpen_
112          */
113
114         /// Default looks
115         virtual InsetLayout::InsetDecoration decoration() const;
116         ///
117         enum Geometry {
118                 TopButton,
119                 ButtonOnly,
120                 NoButton,
121                 LeftButton,
122                 SubLabel,
123                 Corners
124         };
125         /// Returns the geometry based on CollapseStatus
126         /// (status_), autoOpen_ and openinlined_, and of
127         /// course decoration().
128         Geometry geometry(BufferView const & bv) const;
129         /// Allow spellchecking, except for insets with latex_language
130         bool allowSpellCheck() const { return !forceLTR(); }
131         ///
132         bool allowMultiPar() const;
133         ///
134         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
135         ///
136         void setStatus(Cursor & cur, CollapseStatus st);
137         ///
138         bool setMouseHover(bool mouse_hover);
139         ///
140         ColorCode backgroundColor() const { return layout_->bgcolor(); }
141         ///
142         int latex(odocstream &, OutputParams const &) const;
143         ///
144         int docbook(odocstream &, OutputParams const &) const;
145         ///
146         void validate(LaTeXFeatures &) const;
147         ///
148         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
149
150         /// Allow multiple blanks
151         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
152         /// Don't eliminate empty paragraphs
153         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
154         /// Force inset into LTR environment if surroundings are RTL?
155         virtual bool forceLTR() const { return layout_->isForceLtr(); }
156         ///
157         virtual bool usePlainLayout() const { return true; }
158         /// Is this inset's layout defined in the document's textclass?
159         /// May be wrong after textclass change or paste from another document
160         bool undefined() const;
161         /// the string that is passed to the TOC
162         void tocString(odocstream &) const;
163         ///
164         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
165 protected:
166         ///
167         void doDispatch(Cursor & cur, FuncRequest & cmd);
168         ///
169         void edit(Cursor & cur, bool front, 
170                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
171         ///
172         Inset * editXY(Cursor & cur, int x, int y);
173         ///
174         docstring floatName(std::string const & type, BufferParams const &) const;
175         ///
176         virtual void resetParagraphsFont();
177         ///
178         mutable CollapseStatus status_;
179 private:
180         /// cache for the layout_. Make sure it is in sync with the document class!
181         InsetLayout const * layout_;
182         ///
183         Dimension dimensionCollapsed(BufferView const & bv) const;
184         ///
185         /// should paragraphs be forced to use the empty layout?
186         virtual bool forcePlainLayout(idx_type = 0) const 
187                 { return getLayout().forcePlainLayout(); }
188         /// should the user be allowed to customize alignment, etc.?
189         virtual bool allowParagraphCustomization(idx_type = 0) const 
190                 { return getLayout().allowParagraphCustomization(); }
191         docstring labelstring_;
192         ///
193         mutable Box button_dim;
194         /// a substatus of the Open status, determined automatically in metrics
195         mutable bool openinlined_;
196         /// the inset will automatically open when the cursor is inside. This is
197         /// dependent on the bufferview, compare with MathMacro::editing_.
198         mutable std::map<BufferView const *, bool> auto_open_;
199         /// changes color when mouse enters/leaves this inset
200         bool mouse_hover_;
201 };
202
203 } // namespace lyx
204
205 #endif