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 &, InsetText::UsePlain = InsetText::PlainLayout);
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,
69 bool boundary, int & x, int & y) const;
70 /// Returns true if (mouse) action is over the inset's button.
71 /// Always returns false when the inset does not have a
73 bool hitButton(FuncRequest const &) const;
75 docstring const getNewLabel(docstring const & l) const;
77 bool editable() const;
79 bool hasSettings() const { return true; }
80 /// can we go further down on mouse click?
81 bool descendable() const;
83 void setLabel(docstring const & l);
85 virtual void setButtonLabel() {}
87 virtual docstring const buttonLabel(BufferView const &) const
88 { return labelstring_; }
90 bool isOpen(BufferView const & bv) const
91 { return geometry(bv) != ButtonOnly; }
93 CollapseStatus status(BufferView const & bv) const;
94 /** Of the old CollapseStatus we only keep the values
96 * We define a list of possible inset decoration
97 * styles, and a list of possible (concrete, visual)
98 * inset geometries. Relationships between them
99 * (geometries in body of table):
102 * Decoration: \ Open Collapsed
103 * -------------+-------------------------------
104 * Classic | *) TopButton, <--x) ButtonOnly
106 * Minimalistic | NoButton ButtonOnly
107 * Conglomerate | SubLabel Corners
108 * ---------------------------------------------
109 * *) toggled by openinlined_
110 * x) toggled by auto_open_
114 virtual InsetLayout::InsetDecoration decoration() const;
124 /// Returns the geometry based on CollapseStatus
125 /// (status_), auto_open_[BufferView] and openinlined_,
126 /// and of course decoration().
127 Geometry geometry(BufferView const & bv) const;
128 /// Returns the geometry disregarding auto_open_
129 Geometry geometry() const;
130 /// Allow spellchecking, except for insets with latex_language
131 bool allowSpellCheck() const { return !forceLTR(); }
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 ColorCode backgroundColor() const { return layout_->bgcolor(); }
143 int latex(odocstream &, OutputParams const &) const;
145 int docbook(odocstream &, OutputParams const &) const;
146 /// It will rarely be right to call this from subclasses, due
147 /// to the fact that it steps counters, etc. Instead, call
148 /// InsetText::xhtml().
149 docstring xhtml(odocstream &, OutputParams const &) const;
151 void validate(LaTeXFeatures &) const;
153 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
155 /// Allow multiple blanks
156 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
157 /// Don't eliminate empty paragraphs
158 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
159 /// Force inset into LTR environment if surroundings are RTL?
160 virtual bool forceLTR() const { return layout_->isForceLtr(); }
162 virtual bool usePlainLayout() const { return true; }
163 /// Is this inset's layout defined in the document's textclass?
164 /// May be wrong after textclass change or paste from another document
165 bool undefined() const;
166 /// the string that is passed to the TOC
167 void tocString(odocstream &) const;
169 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
172 void doDispatch(Cursor & cur, FuncRequest & cmd);
174 void edit(Cursor & cur, bool front,
175 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
177 Inset * editXY(Cursor & cur, int x, int y);
179 docstring floatName(std::string const & type, BufferParams const &) const;
181 virtual void resetParagraphsFont();
183 mutable CollapseStatus status_;
185 /// cache for the layout_. Make sure it is in sync with the document class!
186 InsetLayout const * layout_;
188 Dimension dimensionCollapsed(BufferView const & bv) const;
190 /// should paragraphs be forced to use the empty layout?
191 virtual bool forcePlainLayout(idx_type = 0) const
192 { return getLayout().forcePlainLayout(); }
193 /// should the user be allowed to customize alignment, etc.?
194 virtual bool allowParagraphCustomization(idx_type = 0) const
195 { return getLayout().allowParagraphCustomization(); }
196 docstring labelstring_;
198 mutable Box button_dim;
199 /// a substatus of the Open status, determined automatically in metrics
200 mutable bool openinlined_;
201 /// the inset will automatically open when the cursor is inside. This is
202 /// dependent on the bufferview, compare with MathMacro::editing_.
203 mutable std::map<BufferView const *, bool> auto_open_;
204 /// changes color when mouse enters/leaves this inset