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"
22 #include "TextClassPtr.h"
34 namespace frontend { class Painter; }
36 /** A collapsable text inset
39 class InsetCollapsable : public InsetText {
42 InsetCollapsable(BufferParams const &,
43 CollapseStatus status = Inset::Open, TextClassPtr tc = 0);
45 InsetCollapsable(InsetCollapsable const & rhs);
47 InsetCollapsable * asInsetCollapsable() { return this; }
49 InsetCollapsable const * asInsetCollapsable() const { return this; }
51 docstring toolTip(BufferView const & bv, int x, int y) const;
53 docstring name() const { return from_ascii("Collapsable"); }
55 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
57 InsetLayout const & getLayout() const { return *layout_; }
59 void setLayout(BufferParams const &);
60 /// (Re-)set the character style parameters from \p tc according
62 void setLayout(TextClassPtr tc);
64 virtual bool useEmptyLayout() { return true; }
68 void write(std::ostream &) const;
70 void metrics(MetricsInfo &, Dimension &) const;
72 void draw(PainterInfo & pi, int x, int y) const;
74 /// return x,y of given position relative to the inset's baseline
75 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() 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_
116 virtual InsetLayout::InsetDecoration decoration() const;
126 /// Returns the geometry based on CollapseStatus
127 /// (status_), autoOpen_ and openinlined_, and of
128 /// course decoration().
129 Geometry geometry() const;
131 bool allowSpellCheck() const { return true; }
133 bool allowMultiPar() const;
135 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
137 void setStatus(Cursor & cur, CollapseStatus st);
139 bool setMouseHover(bool mouse_hover);
141 virtual ColorCode backgroundColor() const {return layout_->bgcolor(); }
143 int latex(odocstream &, OutputParams const &) const;
145 void validate(LaTeXFeatures &) const;
147 virtual InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
149 /// Allow multiple blanks
150 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
151 /// Don't eliminate empty paragraphs
152 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
153 /// Force inset into LTR environment if surroundings are RTL?
154 virtual bool forceLTR() const { return layout_->isForceLtr(); }
156 virtual bool useEmptyLayout() const { return true; }
157 /// Is this inset's layout defined in the document's textclass?
158 /// May be wrong after textclass change or paste from another document
159 bool undefined() const;
162 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
164 void edit(Cursor & cur, bool front,
165 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
167 Inset * editXY(Cursor & cur, int x, int y);
169 docstring floatName(std::string const & type, BufferParams const &) const;
171 virtual void resetParagraphsFont();
174 /// text class to keep the InsetLayout above in memory
175 /// FIXME This probably isn't needed now
176 TextClassPtr textClass_;
177 /// cache for the layout_. Make sure it is in sync with the text class!
178 InsetLayout const * layout_;
180 Dimension dimensionCollapsed() const;
182 docstring labelstring_;
184 mutable Box button_dim;
186 mutable CollapseStatus status_;
187 /// a substatus of the Open status, determined automatically in metrics
188 mutable bool openinlined_;
189 /// the inset will automatically open when the cursor is inside
190 mutable bool autoOpen_;
191 /// changes color when mouse enters/leaves this inset