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