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"
28 namespace frontend { class Painter; }
30 /** A collapsable text inset
33 class InsetCollapsable : public InsetText {
36 InsetCollapsable(Buffer const &,
37 CollapseStatus status = Inset::Open, DocumentClass * tc = 0);
39 InsetCollapsable(InsetCollapsable const & rhs);
41 InsetCollapsable * asInsetCollapsable() { return this; }
43 InsetCollapsable const * asInsetCollapsable() const { return this; }
45 docstring toolTip(BufferView const & bv, int x, int y) const;
47 docstring name() const { return from_ascii("Collapsable"); }
49 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
51 InsetLayout const & getLayout() const { return *layout_; }
53 void setLayout(BufferParams const &);
54 /// (Re-)set the character style parameters from \p tc according
56 void setLayout(DocumentClass const * const tc);
58 virtual bool useEmptyLayout() { return true; }
62 void write(std::ostream &) const;
64 void metrics(MetricsInfo &, Dimension &) const;
66 void draw(PainterInfo & pi, int x, int y) const;
68 /// return x,y of given position relative to the inset's baseline
69 void cursorPos(BufferView const & bv, CursorSlice const & sl,
71 bool boundary, int & x, int & y) const;
73 bool hitButton(FuncRequest const &) const;
75 docstring const getNewLabel(docstring const & l) const;
77 EDITABLE editable() const;
78 /// can we go further down on mouse click?
79 bool descendable() const;
81 void setLabel(docstring const & l);
83 virtual void setButtonLabel() {}
85 bool isOpen() const { return geometry() != ButtonOnly; }
87 CollapseStatus status() const;
88 /** Of the old CollapseStatus we only keep the values
90 * We define a list of possible inset decoration
91 * styles, and a list of possible (concrete, visual)
92 * inset geometries. Relationships between them
93 * (geometries in body of table):
96 * Decoration: \ Open Collapsed
97 * -------------+-------------------------------
98 * Classic | *) TopButton, <--x) ButtonOnly
100 * Minimalistic | NoButton ButtonOnly
101 * Conglomerate | SubLabel Corners
102 * ---------------------------------------------
103 * *) toggled by openinlined_
104 * x) toggled by autoOpen_
108 virtual InsetLayout::InsetDecoration decoration() const;
118 /// Returns the geometry based on CollapseStatus
119 /// (status_), autoOpen_ and openinlined_, and of
120 /// course decoration().
121 Geometry geometry() const;
123 bool allowSpellCheck() const { return true; }
125 bool allowMultiPar() const;
127 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
129 void setStatus(Cursor & cur, CollapseStatus st);
131 bool setMouseHover(bool mouse_hover);
133 ColorCode backgroundColor() const { return layout_->bgcolor(); }
135 int latex(odocstream &, OutputParams const &) const;
137 void validate(LaTeXFeatures &) const;
139 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
141 /// Allow multiple blanks
142 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
143 /// Don't eliminate empty paragraphs
144 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
145 /// Force inset into LTR environment if surroundings are RTL?
146 virtual bool forceLTR() const { return layout_->isForceLtr(); }
148 virtual bool useEmptyLayout() const { return true; }
149 /// Is this inset's layout defined in the document's textclass?
150 /// May be wrong after textclass change or paste from another document
151 bool undefined() const;
153 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
156 void doDispatch(Cursor & cur, FuncRequest & cmd);
158 void edit(Cursor & cur, bool front,
159 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
161 Inset * editXY(Cursor & cur, int x, int y);
163 docstring floatName(std::string const & type, BufferParams const &) const;
165 virtual void resetParagraphsFont();
168 /// cache for the layout_. Make sure it is in sync with the document class!
169 InsetLayout const * layout_;
171 Dimension dimensionCollapsed() const;
173 docstring labelstring_;
175 mutable Box button_dim;
177 mutable CollapseStatus status_;
178 /// a substatus of the Open status, determined automatically in metrics
179 mutable bool openinlined_;
180 /// the inset will automatically open when the cursor is inside
181 mutable bool autoOpen_;
182 /// changes color when mouse enters/leaves this inset