]> git.lyx.org Git - lyx.git/blob - src/insets/InsetCollapsable.h
a6213296bac8782c8ea0752ae1cf78451e83d72b
[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 InsetCaption;
27 class InsetLayout;
28
29 namespace frontend { class Painter; }
30
31 /** A collapsable text inset
32
33 */
34 class InsetCollapsable : public InsetText {
35 public:
36         ///
37         InsetCollapsable(Buffer const &, InsetText::UsePlain = InsetText::PlainLayout);
38         ///
39         InsetCollapsable(InsetCollapsable const & rhs);
40         ///
41         InsetCollapsable * asInsetCollapsable() { return this; }
42         ///
43         InsetCollapsable const * asInsetCollapsable() const { return this; }
44         ///
45         docstring toolTip(BufferView const & bv, int x, int y) const;
46         ///
47         docstring name() const { return from_ascii("Collapsable"); }
48         ///
49         InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
50         ///
51         InsetLayout const & getLayout() const { return *layout_; } 
52         ///
53         void setLayout(BufferParams const &);
54         /// (Re-)set the character style parameters from \p tc according
55         /// to name()
56         void setLayout(DocumentClass const * const tc);
57         ///
58         virtual bool usePlainLayout() { return true; }
59         ///
60         void read(Lexer &);
61         ///
62         void write(std::ostream &) const;
63         ///
64         void metrics(MetricsInfo &, Dimension &) const;
65         ///
66         void draw(PainterInfo & pi, int x, int y) const;
67
68         /// return x,y of given position relative to the inset's baseline
69         void cursorPos(BufferView const & bv, CursorSlice const & sl,
70                 bool boundary, int & x, int & y) const;
71         /// Returns true if (mouse) action is over the inset's button.
72         /// Always returns false when the inset does not have a
73         /// button.
74         bool hitButton(FuncRequest const &) const;
75         ///
76         docstring const getNewLabel(docstring const & l) const;
77         ///
78         bool editable() const;
79         ///
80         bool hasSettings() const { return true; }
81         /// can we go further down on mouse click?
82         bool descendable() const;
83         ///
84         void setLabel(docstring const & l);
85         ///
86         virtual void setButtonLabel() {}
87         ///
88         virtual docstring const buttonLabel(BufferView const &) 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 auto_open_
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_), auto_open_[BufferView] and openinlined_,
127         /// and of course decoration().
128         Geometry geometry(BufferView const & bv) const;
129         /// Returns the geometry disregarding auto_open_
130         Geometry geometry() const;
131         /// Allow spellchecking, except for insets with latex_language
132         bool allowSpellCheck() const { return !forceLTR(); }
133         ///
134         bool allowMultiPar() const;
135         ///
136         bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
137         ///
138         void setStatus(Cursor & cur, CollapseStatus st);
139         ///
140         bool setMouseHover(bool mouse_hover);
141         ///
142         ColorCode backgroundColor() const { return layout_->bgcolor(); }
143         ///
144         int latex(odocstream &, OutputParams const &) const;
145         ///
146         int docbook(odocstream &, OutputParams const &) const;
147         /// It will rarely be right to call this from subclasses, due
148         /// to the fact that it steps counters, etc. Instead, call
149         /// InsetText::xhtml().
150         docstring xhtml(odocstream &, OutputParams const &) const;
151         ///
152         void validate(LaTeXFeatures &) const;
153         ///
154         InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
155
156         /// Allow multiple blanks
157         virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
158         /// Don't eliminate empty paragraphs
159         virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
160         /// Force inset into LTR environment if surroundings are RTL?
161         virtual bool forceLTR() const { return layout_->isForceLtr(); }
162         ///
163         virtual bool usePlainLayout() const { return true; }
164         /// Is this inset's layout defined in the document's textclass?
165         /// May be wrong after textclass change or paste from another document
166         bool undefined() const;
167         /// the string that is passed to the TOC
168         void tocString(odocstream &) const;
169         ///
170         virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
171 protected:
172         ///
173         void doDispatch(Cursor & cur, FuncRequest & cmd);
174         ///
175         void edit(Cursor & cur, bool front, 
176                 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
177         ///
178         Inset * editXY(Cursor & cur, int x, int y);
179         ///
180         docstring floatName(std::string const & type, BufferParams const &) const;
181         ///
182         virtual void resetParagraphsFont();
183         ///
184         InsetCaption const * getCaptionInset() const;
185         ///
186         mutable CollapseStatus status_;
187 private:
188         /// cache for the layout_. Make sure it is in sync with the document class!
189         InsetLayout const * layout_;
190         ///
191         Dimension dimensionCollapsed(BufferView const & bv) const;
192         ///
193         /// should paragraphs be forced to use the empty layout?
194         virtual bool forcePlainLayout(idx_type = 0) const 
195                 { return getLayout().forcePlainLayout(); }
196         /// should the user be allowed to customize alignment, etc.?
197         virtual bool allowParagraphCustomization(idx_type = 0) const 
198                 { return getLayout().allowParagraphCustomization(); }
199         docstring labelstring_;
200         ///
201         mutable Box button_dim;
202         /// a substatus of the Open status, determined automatically in metrics
203         mutable bool openinlined_;
204         /// the inset will automatically open when the cursor is inside. This is
205         /// dependent on the bufferview, compare with MathMacro::editing_.
206         mutable std::map<BufferView const *, bool> auto_open_;
207         /// changes color when mouse enters/leaves this inset
208         bool mouse_hover_;
209 };
210
211 } // namespace lyx
212
213 #endif