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"
29 namespace frontend { class Painter; }
31 /** A collapsable text inset
34 class InsetCollapsable : public InsetText {
37 InsetCollapsable(Buffer const &, InsetText::UsePlain = InsetText::PlainLayout);
39 InsetCollapsable(InsetCollapsable const & rhs);
41 InsetCollapsable * asInsetCollapsable() { return this; }
43 InsetCollapsable const * asInsetCollapsable() const { return this; }
45 docstring toolTip(BufferView const & bv, int x, int y) const;
47 docstring name() const { return from_ascii("Collapsable"); }
49 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
51 InsetLayout const & getLayout() const { return *layout_; }
53 void setLayout(BufferParams const &);
54 /// (Re-)set the character style parameters from \p tc according
56 void setLayout(DocumentClass const * const tc);
58 virtual bool usePlainLayout() { return true; }
62 void write(std::ostream &) const;
64 void metrics(MetricsInfo &, Dimension &) const;
66 void draw(PainterInfo & pi, int x, int y) const;
68 /// return x,y of given position relative to the inset's baseline
69 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 bool editable() const;
80 bool hasSettings() const { return true; }
81 /// can we go further down on mouse click?
82 bool descendable() const;
84 void setLabel(docstring const & l);
86 virtual void setButtonLabel() {}
88 virtual docstring const buttonLabel(BufferView const &) const
89 { return labelstring_; }
91 bool isOpen(BufferView const & bv) const
92 { return geometry(bv) != ButtonOnly; }
94 CollapseStatus status(BufferView const & bv) 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 auto_open_
115 virtual InsetLayout::InsetDecoration decoration() const;
125 /// Returns the geometry based on CollapseStatus
126 /// (status_), auto_open_[BufferView] and openinlined_,
127 /// and of course decoration().
128 Geometry geometry(BufferView const & bv) const;
129 /// Returns the geometry disregarding auto_open_
130 Geometry geometry() const;
131 /// Allow spellchecking, except for insets with latex_language
132 bool allowSpellCheck() const { return !forceLTR(); }
134 bool allowMultiPar() const;
136 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
138 void setStatus(Cursor & cur, CollapseStatus st);
140 bool setMouseHover(bool mouse_hover);
142 ColorCode backgroundColor() const { return layout_->bgcolor(); }
144 int latex(odocstream &, OutputParams const &) const;
146 int docbook(odocstream &, OutputParams const &) const;
147 /// It will rarely be right to call this from subclasses, due
148 /// to the fact that it steps counters, etc. Instead, call
149 /// InsetText::xhtml().
150 docstring xhtml(odocstream &, OutputParams const &) const;
152 void validate(LaTeXFeatures &) const;
154 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
156 /// Allow multiple blanks
157 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
158 /// Don't eliminate empty paragraphs
159 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
160 /// Force inset into LTR environment if surroundings are RTL?
161 virtual bool forceLTR() const { return layout_->isForceLtr(); }
163 virtual bool usePlainLayout() 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;
167 /// the string that is passed to the TOC
168 void tocString(odocstream &) const;
170 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
173 void doDispatch(Cursor & cur, FuncRequest & cmd);
175 void edit(Cursor & cur, bool front,
176 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
178 Inset * editXY(Cursor & cur, int x, int y);
180 docstring floatName(std::string const & type, BufferParams const &) const;
182 virtual void resetParagraphsFont();
184 InsetCaption const * getCaptionInset() const;
186 docstring getCaptionText(OutputParams const &) const;
188 docstring getCaptionHTML(OutputParams const &) const;
190 mutable CollapseStatus status_;
192 /// cache for the layout_. Make sure it is in sync with the document class!
193 InsetLayout const * layout_;
195 Dimension dimensionCollapsed(BufferView const & bv) const;
197 /// should paragraphs be forced to use the empty layout?
198 virtual bool forcePlainLayout(idx_type = 0) const
199 { return getLayout().forcePlainLayout(); }
200 /// should the user be allowed to customize alignment, etc.?
201 virtual bool allowParagraphCustomization(idx_type = 0) const
202 { return getLayout().allowParagraphCustomization(); }
203 docstring labelstring_;
205 mutable Box button_dim;
206 /// a substatus of the Open status, determined automatically in metrics
207 mutable bool openinlined_;
208 /// the inset will automatically open when the cursor is inside. This is
209 /// dependent on the bufferview, compare with MathMacro::editing_.
210 mutable std::map<BufferView const *, bool> auto_open_;
211 /// changes color when mouse enters/leaves this inset