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 "InsetLayout.h"
19 #include "InsetText.h"
22 #include "TextClass.h"
23 #include "TextClassPtr.h"
35 namespace frontend { class Painter; }
37 /** A collapsable text inset
40 class InsetCollapsable : public InsetText {
45 CollapseStatus status = Inset::Open,
46 TextClassPtr tc = TextClassPtr((TextClass *)0)
49 InsetCollapsable(InsetCollapsable const & rhs);
51 InsetCollapsable * asInsetCollapsable() { return this; }
52 InsetCollapsable const * asInsetCollapsable() const { return this; }
53 docstring toolTip(BufferView const & bv, int x, int y) const;
54 docstring name() const { return from_ascii("Collapsable"); }
55 InsetLayout const & getLayout(BufferParams const &) const
57 InsetLayout const & getLayout() const
60 void setLayout(BufferParams const &);
61 /// (Re-)set the character style parameters from \p tc according
63 void setLayout(TextClassPtr tc);
65 virtual bool useEmptyLayout() { return true; }
67 void read(Buffer const &, Lexer &);
69 void write(Buffer const &, std::ostream &) const;
71 void metrics(MetricsInfo &, Dimension &) const;
73 void draw(PainterInfo & pi, int x, int y) const;
75 /// return x,y of given position relative to the inset's baseline
76 void cursorPos(BufferView const & bv, CursorSlice const & sl,
77 bool boundary, int & x, int & y) const;
79 bool hitButton(FuncRequest const &) const;
81 docstring const getNewLabel(docstring const & l) const;
83 EDITABLE editable() const;
84 /// can we go further down on mouse click?
85 bool descendable() const;
87 bool isMacroScope(Buffer const & buf) const;
89 void setLabel(docstring const & l);
91 virtual void setButtonLabel() {}
93 bool isOpen() const { return geometry() != ButtonOnly; }
95 CollapseStatus status() const;
96 /** Of the old CollapseStatus we only keep the values
98 * We define a list of possible inset decoration
99 * styles, and a list of possible (concrete, visual)
100 * inset geometries. Relationships between them
101 * (geometries in body of table):
104 * Decoration: \ Open Collapsed
105 * -------------+-------------------------------
106 * Classic | *) TopButton, <--x) ButtonOnly
108 * Minimalistic | NoButton ButtonOnly
109 * Conglomerate | SubLabel Corners
110 * ---------------------------------------------
111 * *) toggled by openinlined_
112 * x) toggled by autoOpen_
122 virtual Decoration decoration() const;
132 /// Returns the geometry based on CollapseStatus
133 /// (status_), autoOpen_ and openinlined_, and of
134 /// course decoration().
135 Geometry geometry() const;
137 bool allowSpellCheck() const { return true; }
139 bool allowMultiPar() const;
141 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
143 void setStatus(Cursor & cur, CollapseStatus st);
145 bool setMouseHover(bool mouse_hover);
147 virtual ColorCode backgroundColor() const {return layout_->bgcolor; }
149 int latex(Buffer const &, odocstream &,
150 OutputParams const &) const;
152 void validate(LaTeXFeatures &) const;
154 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
156 /// Allow multiple blanks
157 virtual bool isFreeSpacing() const { return layout_->freespacing; }
158 /// Don't eliminate empty paragraphs
159 virtual bool allowEmpty() const { return layout_->keepempty; }
160 /// Force inset into LTR environment if surroundings are RTL?
161 virtual bool forceLTR() const { return layout_->forceltr; }
163 virtual bool useEmptyLayout() const { return true; }
164 /// Is this inset's layout defined in the document's textclass?
165 /// May be wrong after textclass change or paste from another document
166 bool undefined() const;
169 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
171 void edit(Cursor & cur, bool front,
172 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
174 Inset * editXY(Cursor & cur, int x, int y);
176 docstring floatName(std::string const & type, BufferParams const &) const;
178 virtual void resetParagraphsFont();
181 /// text class to keep the InsetLayout above in memory
182 TextClassPtr textClass_;
183 /// cache for the layout_. Make sure it is in sync with the text class!
184 InsetLayout const * layout_;
186 Dimension dimensionCollapsed() const;
188 docstring labelstring_;
190 mutable Box button_dim;
192 mutable CollapseStatus status_;
193 /// a substatus of the Open status, determined automatically in metrics
194 mutable bool openinlined_;
195 /// the inset will automatically open when the cursor is inside
196 mutable bool autoOpen_;
197 /// changes color when mouse enters/leaves this inset