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 "InsetText.h"
21 #include "TextClass.h"
22 #include "TextClassPtr.h"
34 namespace frontend { class Painter; }
36 /** A collapsable text inset
39 class InsetCollapsable : public InsetText {
44 CollapseStatus status = Inset::Open,
45 TextClassPtr tc = TextClassPtr((TextClass *)0)
48 InsetCollapsable(InsetCollapsable const & rhs);
50 InsetCollapsable * asInsetCollapsable() { return this; }
52 InsetCollapsable const * asInsetCollapsable() const { return this; }
54 docstring toolTip(BufferView const & bv, int x, int y) const;
56 docstring name() const { return from_ascii("Collapsable"); }
58 InsetLayout const & getLayout(BufferParams const &) const
61 InsetLayout const & getLayout() const
64 void setLayout(BufferParams const &);
65 /// (Re-)set the character style parameters from \p tc according
67 void setLayout(TextClassPtr tc);
69 virtual bool useEmptyLayout() { return true; }
71 void read(Buffer const &, Lexer &);
73 void write(Buffer const &, std::ostream &) const;
75 void metrics(MetricsInfo &, Dimension &) const;
77 void draw(PainterInfo & pi, int x, int y) const;
79 /// return x,y of given position relative to the inset's baseline
80 void cursorPos(BufferView const & bv, CursorSlice const & sl,
82 bool boundary, int & x, int & y) const;
84 bool hitButton(FuncRequest const &) const;
86 docstring const getNewLabel(docstring const & l) const;
88 EDITABLE editable() const;
89 /// can we go further down on mouse click?
90 bool descendable() const;
92 bool isMacroScope(Buffer const & buf) const;
94 void setLabel(docstring const & l);
96 virtual void setButtonLabel() {}
98 bool isOpen() const { return geometry() != ButtonOnly; }
100 CollapseStatus status() const;
101 /** Of the old CollapseStatus we only keep the values
102 * Open and Collapsed.
103 * We define a list of possible inset decoration
104 * styles, and a list of possible (concrete, visual)
105 * inset geometries. Relationships between them
106 * (geometries in body of table):
109 * Decoration: \ Open Collapsed
110 * -------------+-------------------------------
111 * Classic | *) TopButton, <--x) ButtonOnly
113 * Minimalistic | NoButton ButtonOnly
114 * Conglomerate | SubLabel Corners
115 * ---------------------------------------------
116 * *) toggled by openinlined_
117 * x) toggled by autoOpen_
121 virtual InsetLayout::InsetDecoration decoration() const;
131 /// Returns the geometry based on CollapseStatus
132 /// (status_), autoOpen_ and openinlined_, and of
133 /// course decoration().
134 Geometry geometry() const;
136 bool allowSpellCheck() const { return true; }
138 bool allowMultiPar() const;
140 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
142 void setStatus(Cursor & cur, CollapseStatus st);
144 bool setMouseHover(bool mouse_hover);
146 virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
148 int latex(Buffer const &, odocstream &,
149 OutputParams const &) const;
151 void validate(LaTeXFeatures &) const;
153 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
155 /// Allow multiple blanks
156 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
157 /// Don't eliminate empty paragraphs
158 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
159 /// Force inset into LTR environment if surroundings are RTL?
160 virtual bool forceLTR() const { return layout_->isForceLtr(); }
162 virtual bool useEmptyLayout() const { return true; }
163 /// Is this inset's layout defined in the document's textclass?
164 /// May be wrong after textclass change or paste from another document
165 bool undefined() const;
168 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
170 void edit(Cursor & cur, bool front,
171 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
173 Inset * editXY(Cursor & cur, int x, int y);
175 docstring floatName(std::string const & type, BufferParams const &) const;
177 virtual void resetParagraphsFont();
180 /// text class to keep the InsetLayout above in memory
181 TextClassPtr textClass_;
182 /// cache for the layout_. Make sure it is in sync with the text class!
183 InsetLayout const * layout_;
185 Dimension dimensionCollapsed() const;
187 docstring labelstring_;
189 mutable Box button_dim;
191 mutable CollapseStatus status_;
192 /// a substatus of the Open status, determined automatically in metrics
193 mutable bool openinlined_;
194 /// the inset will automatically open when the cursor is inside
195 mutable bool autoOpen_;
196 /// changes color when mouse enters/leaves this inset