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