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 bool isMacroScope() const;
83 void setLabel(docstring const & l);
85 virtual void setButtonLabel() {}
87 bool isOpen() const { return geometry() != ButtonOnly; }
89 CollapseStatus status() const;
90 /** Of the old CollapseStatus we only keep the values
92 * We define a list of possible inset decoration
93 * styles, and a list of possible (concrete, visual)
94 * inset geometries. Relationships between them
95 * (geometries in body of table):
98 * Decoration: \ Open Collapsed
99 * -------------+-------------------------------
100 * Classic | *) TopButton, <--x) ButtonOnly
102 * Minimalistic | NoButton ButtonOnly
103 * Conglomerate | SubLabel Corners
104 * ---------------------------------------------
105 * *) toggled by openinlined_
106 * x) toggled by autoOpen_
110 virtual InsetLayout::InsetDecoration decoration() const;
120 /// Returns the geometry based on CollapseStatus
121 /// (status_), autoOpen_ and openinlined_, and of
122 /// course decoration().
123 Geometry geometry() const;
125 bool allowSpellCheck() const { return true; }
127 bool allowMultiPar() const;
129 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
131 void setStatus(Cursor & cur, CollapseStatus st);
133 bool setMouseHover(bool mouse_hover);
135 ColorCode backgroundColor() const { return layout_->bgcolor(); }
137 int latex(odocstream &, OutputParams const &) const;
139 void validate(LaTeXFeatures &) const;
141 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
143 /// Allow multiple blanks
144 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
145 /// Don't eliminate empty paragraphs
146 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
147 /// Force inset into LTR environment if surroundings are RTL?
148 virtual bool forceLTR() const { return layout_->isForceLtr(); }
150 virtual bool useEmptyLayout() const { return true; }
151 /// Is this inset's layout defined in the document's textclass?
152 /// May be wrong after textclass change or paste from another document
153 bool undefined() 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