3 * \file InsetCollapsable.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
9 * \author Lars Gullik Bjønnes
11 * Full author contact details are available in file CREDITS.
14 #ifndef INSETCOLLAPSABLE_H
15 #define INSETCOLLAPSABLE_H
18 #include "InsetLayout.h"
19 #include "InsetText.h"
22 #include "TextClass.h"
23 #include "TextClassPtr.h"
35 namespace frontend { class Painter; }
37 /** A collapsable text inset
40 class InsetCollapsable : public InsetText {
45 CollapseStatus status = Inset::Open,
46 TextClassPtr tc = TextClassPtr((TextClass *)0)
49 InsetCollapsable(InsetCollapsable const & rhs);
51 InsetCollapsable * asInsetCollapsable() { return this; }
52 InsetCollapsable const * asInsetCollapsable() const { return this; }
53 docstring toolTip(BufferView const & bv, int x, int y) const;
54 docstring name() const { return from_ascii("Collapsable"); }
55 InsetLayout const & getLayout(BufferParams const &) const
57 InsetLayout const & getLayout() const
60 void setLayout(BufferParams const &);
61 /// (Re-)set the character style parameters from \p tc according
63 void setLayout(TextClassPtr tc);
65 void read(Buffer const &, Lexer &);
67 void write(Buffer const &, std::ostream &) const;
69 void metrics(MetricsInfo &, Dimension &) const;
71 void draw(PainterInfo & pi, int x, int y) const;
73 /// return x,y of given position relative to the inset's baseline
74 void cursorPos(BufferView const & bv, CursorSlice const & sl,
75 bool boundary, int & x, int & y) const;
77 bool hitButton(FuncRequest const &) const;
79 docstring const getNewLabel(docstring const & l) const;
81 EDITABLE editable() const;
82 /// can we go further down on mouse click?
83 bool descendable() const;
85 bool isMacroScope(Buffer const & buf) const;
87 void setLabel(docstring const & l);
89 virtual void setButtonLabel() {}
91 bool isOpen() const { return geometry() != ButtonOnly; }
93 CollapseStatus status() const;
94 /** Of the old CollapseStatus we only keep the values
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):
102 * Decoration: \ Open Collapsed
103 * -------------+-------------------------------
104 * Classic | *) TopButton, <--x) ButtonOnly
106 * Minimalistic | ButtonOnly NoButton
107 * Conglomerate | SubLabel Corners
108 * ---------------------------------------------
109 * *) toggled by openinlined_
110 * x) toggled by autoOpen_
120 virtual Decoration decoration() const;
130 /// Returns the geometry based on CollapseStatus
131 /// (status_), autoOpen_ and openinlined_, and of
132 /// course decoration().
133 Geometry geometry() const;
135 bool allowSpellCheck() const { return true; }
137 bool allowMultiPar() const;
139 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
141 void setStatus(Cursor & cur, CollapseStatus st);
143 bool setMouseHover(bool mouse_hover);
145 virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
147 int latex(Buffer const &, odocstream &,
148 OutputParams const &) const;
150 void validate(LaTeXFeatures &) const;
152 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
154 /// Allow multiple blanks
155 virtual bool isFreeSpacing() const { return layout_->freespacing; }
156 /// Don't eliminate empty paragraphs
157 virtual bool allowEmpty() const { return layout_->keepempty; }
158 /// Force inset into LTR environment if surroundings are RTL?
159 virtual bool forceLTR() const { return layout_->forceltr; }
163 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
165 void edit(Cursor & cur, bool left);
167 Inset * editXY(Cursor & cur, int x, int y);
169 docstring floatName(std::string const & type, BufferParams const &) const;
171 virtual void resetParagraphsFont();
174 /// text class to keep the InsetLayout above in memory
175 TextClassPtr textClass_;
176 /// cache for the layout_. Make sure it is in sync with the text class!
177 InsetLayout const * layout_;
179 Dimension dimensionCollapsed() const;
181 docstring labelstring_;
183 mutable Box button_dim;
185 mutable CollapseStatus status_;
186 /// a substatus of the Open status, determined automatically in metrics
187 mutable bool openinlined_;
188 /// the inset will automatically open when the cursor is inside
189 mutable bool autoOpen_;
190 /// changes color when mouse enters/leaves this inset