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 &);
38 InsetCollapsable(InsetCollapsable const & rhs);
40 InsetCollapsable * asInsetCollapsable() { return this; }
42 InsetCollapsable const * asInsetCollapsable() const { return this; }
44 docstring toolTip(BufferView const & bv, int x, int y) const;
46 docstring name() const { return from_ascii("Collapsable"); }
48 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
50 InsetLayout const & getLayout() const { return *layout_; }
52 void setLayout(BufferParams const &);
53 /// (Re-)set the character style parameters from \p tc according
55 void setLayout(DocumentClass const * const tc);
57 virtual bool usePlainLayout() { return true; }
61 void write(std::ostream &) const;
63 void metrics(MetricsInfo &, Dimension &) const;
65 void draw(PainterInfo & pi, int x, int y) const;
67 /// return x,y of given position relative to the inset's baseline
68 void cursorPos(BufferView const & bv, CursorSlice const & sl,
70 bool boundary, int & x, int & y) const;
71 /// Returns true if (mouse) action is over the inset's button.
72 /// Always returns false when the inset does not have a
74 bool hitButton(FuncRequest const &) const;
76 docstring const getNewLabel(docstring const & l) const;
78 EDITABLE editable() const;
79 /// can we go further down on mouse click?
80 bool descendable() const;
82 void setLabel(docstring const & l);
84 virtual void setButtonLabel() {}
86 bool isOpen() const { return geometry() != ButtonOnly; }
88 CollapseStatus status() const;
89 /** Of the old CollapseStatus we only keep the values
91 * We define a list of possible inset decoration
92 * styles, and a list of possible (concrete, visual)
93 * inset geometries. Relationships between them
94 * (geometries in body of table):
97 * Decoration: \ Open Collapsed
98 * -------------+-------------------------------
99 * Classic | *) TopButton, <--x) ButtonOnly
101 * Minimalistic | NoButton ButtonOnly
102 * Conglomerate | SubLabel Corners
103 * ---------------------------------------------
104 * *) toggled by openinlined_
105 * x) toggled by autoOpen_
109 virtual InsetLayout::InsetDecoration decoration() const;
119 /// Returns the geometry based on CollapseStatus
120 /// (status_), autoOpen_ and openinlined_, and of
121 /// course decoration().
122 Geometry geometry() const;
123 /// Allow spellchecking, except for insets with latex_language
124 bool allowSpellCheck() const { return !forceLTR(); }
126 bool allowMultiPar() const;
128 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
130 void setStatus(Cursor & cur, CollapseStatus st);
132 bool setMouseHover(bool mouse_hover);
134 ColorCode backgroundColor() const { return layout_->bgcolor(); }
136 int latex(odocstream &, OutputParams const &) const;
138 void validate(LaTeXFeatures &) const;
140 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
142 /// Allow multiple blanks
143 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
144 /// Don't eliminate empty paragraphs
145 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
146 /// Force inset into LTR environment if surroundings are RTL?
147 virtual bool forceLTR() const { return layout_->isForceLtr(); }
149 virtual bool usePlainLayout() const { return true; }
150 /// Is this inset's layout defined in the document's textclass?
151 /// May be wrong after textclass change or paste from another document
152 bool undefined() const;
154 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
157 void doDispatch(Cursor & cur, FuncRequest & cmd);
159 void edit(Cursor & cur, bool front,
160 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
162 Inset * editXY(Cursor & cur, int x, int y);
164 docstring floatName(std::string const & type, BufferParams const &) const;
166 virtual void resetParagraphsFont();
168 mutable CollapseStatus status_;
170 /// cache for the layout_. Make sure it is in sync with the document class!
171 InsetLayout const * layout_;
173 Dimension dimensionCollapsed() const;
175 docstring labelstring_;
177 mutable Box button_dim;
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