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; }
53 InsetCollapsable const * asInsetCollapsable() const { return this; }
55 docstring toolTip(BufferView const & bv, int x, int y) const;
57 docstring name() const { return from_ascii("Collapsable"); }
59 InsetLayout const & getLayout(BufferParams const &) const
62 InsetLayout const & getLayout() const
65 void setLayout(BufferParams const &);
66 /// (Re-)set the character style parameters from \p tc according
68 void setLayout(TextClassPtr tc);
70 virtual bool useEmptyLayout() { return true; }
72 void read(Buffer const &, Lexer &);
74 void write(Buffer const &, std::ostream &) const;
76 void metrics(MetricsInfo &, Dimension &) const;
78 void draw(PainterInfo & pi, int x, int y) const;
80 /// return x,y of given position relative to the inset's baseline
81 void cursorPos(BufferView const & bv, CursorSlice const & sl,
83 bool boundary, int & x, int & y) const;
85 bool hitButton(FuncRequest const &) const;
87 docstring const getNewLabel(docstring const & l) const;
89 EDITABLE editable() const;
90 /// can we go further down on mouse click?
91 bool descendable() const;
93 bool isMacroScope(Buffer const & buf) const;
95 void setLabel(docstring const & l);
97 virtual void setButtonLabel() {}
99 bool isOpen() const { return geometry() != ButtonOnly; }
101 CollapseStatus status() const;
102 /** Of the old CollapseStatus we only keep the values
103 * Open and Collapsed.
104 * We define a list of possible inset decoration
105 * styles, and a list of possible (concrete, visual)
106 * inset geometries. Relationships between them
107 * (geometries in body of table):
110 * Decoration: \ Open Collapsed
111 * -------------+-------------------------------
112 * Classic | *) TopButton, <--x) ButtonOnly
114 * Minimalistic | NoButton ButtonOnly
115 * Conglomerate | SubLabel Corners
116 * ---------------------------------------------
117 * *) toggled by openinlined_
118 * x) toggled by autoOpen_
128 virtual Decoration decoration() const;
138 /// Returns the geometry based on CollapseStatus
139 /// (status_), autoOpen_ and openinlined_, and of
140 /// course decoration().
141 Geometry geometry() const;
143 bool allowSpellCheck() const { return true; }
145 bool allowMultiPar() const;
147 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
149 void setStatus(Cursor & cur, CollapseStatus st);
151 bool setMouseHover(bool mouse_hover);
153 virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
155 int latex(Buffer const &, odocstream &,
156 OutputParams const &) const;
158 void validate(LaTeXFeatures &) const;
160 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
162 /// Allow multiple blanks
163 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
164 /// Don't eliminate empty paragraphs
165 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
166 /// Force inset into LTR environment if surroundings are RTL?
167 virtual bool forceLTR() const { return layout_->isForceLtr(); }
169 virtual bool useEmptyLayout() const { return true; }
170 /// Is this inset's layout defined in the document's textclass?
171 /// May be wrong after textclass change or paste from another document
172 bool undefined() const;
175 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
177 void edit(Cursor & cur, bool front,
178 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
180 Inset * editXY(Cursor & cur, int x, int y);
182 docstring floatName(std::string const & type, BufferParams const &) const;
184 virtual void resetParagraphsFont();
187 /// text class to keep the InsetLayout above in memory
188 TextClassPtr textClass_;
189 /// cache for the layout_. Make sure it is in sync with the text class!
190 InsetLayout const * layout_;
192 Dimension dimensionCollapsed() const;
194 docstring labelstring_;
196 mutable Box button_dim;
198 mutable CollapseStatus status_;
199 /// a substatus of the Open status, determined automatically in metrics
200 mutable bool openinlined_;
201 /// the inset will automatically open when the cursor is inside
202 mutable bool autoOpen_;
203 /// changes color when mouse enters/leaves this inset