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"
33 namespace frontend { class Painter; }
35 /** A collapsable text inset
38 class InsetCollapsable : public InsetText {
41 InsetCollapsable(BufferParams const &,
42 CollapseStatus status = Inset::Open, DocumentClass * tc = 0);
44 InsetCollapsable(InsetCollapsable const & rhs);
46 InsetCollapsable * asInsetCollapsable() { return this; }
48 InsetCollapsable const * asInsetCollapsable() const { return this; }
50 docstring toolTip(BufferView const & bv, int x, int y) const;
52 docstring name() const { return from_ascii("Collapsable"); }
54 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
56 InsetLayout const & getLayout() const { return *layout_; }
58 void setLayout(BufferParams const &);
59 /// (Re-)set the character style parameters from \p tc according
61 void setLayout(DocumentClass const * const tc);
63 virtual bool useEmptyLayout() { return true; }
67 void write(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,
76 bool boundary, int & x, int & y) const;
78 bool hitButton(FuncRequest const &) const;
80 docstring const getNewLabel(docstring const & l) const;
82 EDITABLE editable() const;
83 /// can we go further down on mouse click?
84 bool descendable() const;
86 bool isMacroScope() const;
88 void setLabel(docstring const & l);
90 virtual void setButtonLabel() {}
92 bool isOpen() const { return geometry() != ButtonOnly; }
94 CollapseStatus status() const;
95 /** Of the old CollapseStatus we only keep the values
97 * We define a list of possible inset decoration
98 * styles, and a list of possible (concrete, visual)
99 * inset geometries. Relationships between them
100 * (geometries in body of table):
103 * Decoration: \ Open Collapsed
104 * -------------+-------------------------------
105 * Classic | *) TopButton, <--x) ButtonOnly
107 * Minimalistic | NoButton ButtonOnly
108 * Conglomerate | SubLabel Corners
109 * ---------------------------------------------
110 * *) toggled by openinlined_
111 * x) toggled by autoOpen_
115 virtual InsetLayout::InsetDecoration decoration() const;
125 /// Returns the geometry based on CollapseStatus
126 /// (status_), autoOpen_ and openinlined_, and of
127 /// course decoration().
128 Geometry geometry() const;
130 bool allowSpellCheck() const { return true; }
132 bool allowMultiPar() const;
134 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
136 void setStatus(Cursor & cur, CollapseStatus st);
138 bool setMouseHover(bool mouse_hover);
140 virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
142 int latex(odocstream &, OutputParams const &) const;
144 void validate(LaTeXFeatures &) const;
146 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
148 /// Allow multiple blanks
149 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
150 /// Don't eliminate empty paragraphs
151 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
152 /// Force inset into LTR environment if surroundings are RTL?
153 virtual bool forceLTR() const { return layout_->isForceLtr(); }
155 virtual bool useEmptyLayout() const { return true; }
156 /// Is this inset's layout defined in the document's textclass?
157 /// May be wrong after textclass change or paste from another document
158 bool undefined() const;
161 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
163 void edit(Cursor & cur, bool front,
164 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
166 Inset * editXY(Cursor & cur, int x, int y);
168 docstring floatName(std::string const & type, BufferParams const &) const;
170 virtual void resetParagraphsFont();
173 /// cache for the layout_. Make sure it is in sync with the document class!
174 InsetLayout const * layout_;
176 Dimension dimensionCollapsed() const;
178 docstring labelstring_;
180 mutable Box button_dim;
182 mutable CollapseStatus status_;
183 /// a substatus of the Open status, determined automatically in metrics
184 mutable bool openinlined_;
185 /// the inset will automatically open when the cursor is inside
186 mutable bool autoOpen_;
187 /// changes color when mouse enters/leaves this inset