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() const { return *layout_; }
50 void setLayout(BufferParams const &);
51 /// (Re-)set the character style parameters from \p tc according
53 void setLayout(DocumentClass const * const tc);
55 virtual bool usePlainLayout() { return true; }
59 void write(std::ostream &) const;
61 void metrics(MetricsInfo &, Dimension &) const;
63 void draw(PainterInfo & pi, int x, int y) const;
65 /// return x,y of given position relative to the inset's baseline
66 void cursorPos(BufferView const & bv, CursorSlice const & sl,
67 bool boundary, int & x, int & y) const;
68 /// Returns true if (mouse) action is over the inset's button.
69 /// Always returns false when the inset does not have a
71 bool hitButton(FuncRequest const &) const;
73 docstring const getNewLabel(docstring const & l) const;
75 bool editable() const;
77 bool hasSettings() const { return true; }
78 /// can we go further down on mouse click?
79 bool descendable() const;
81 void setLabel(docstring const & l);
83 virtual void setButtonLabel() {}
85 virtual docstring const buttonLabel(BufferView const &) const
86 { return labelstring_; }
88 bool isOpen(BufferView const & bv) const
89 { return geometry(bv) != ButtonOnly; }
91 CollapseStatus status(BufferView const & bv) const;
92 /** Of the old CollapseStatus we only keep the values
94 * We define a list of possible inset decoration
95 * styles, and a list of possible (concrete, visual)
96 * inset geometries. Relationships between them
97 * (geometries in body of table):
100 * Decoration: \ Open Collapsed
101 * -------------+-------------------------------
102 * Classic | *) TopButton, <--x) ButtonOnly
104 * Minimalistic | NoButton ButtonOnly
105 * Conglomerate | SubLabel Corners
106 * ---------------------------------------------
107 * *) toggled by openinlined_
108 * x) toggled by auto_open_
112 virtual InsetLayout::InsetDecoration decoration() const;
122 /// Returns the geometry based on CollapseStatus
123 /// (status_), auto_open_[BufferView] and openinlined_,
124 /// and of course decoration().
125 Geometry geometry(BufferView const & bv) const;
126 /// Returns the geometry disregarding auto_open_
127 Geometry geometry() const;
128 /// Allow spellchecking, except for insets with latex_language
129 bool allowSpellCheck() const { return !forceLTR(); }
131 bool allowMultiPar() const;
133 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
135 void setStatus(Cursor & cur, CollapseStatus st);
137 bool setMouseHover(bool mouse_hover);
139 ColorCode backgroundColor() const { return getLayout().bgcolor(); }
141 int latex(odocstream &, OutputParams const &) const;
143 int docbook(odocstream &, OutputParams const &) const;
144 /// It will rarely be right to call this from subclasses, due
145 /// to the fact that it steps counters, etc. Instead, call
146 /// InsetText::xhtml().
147 docstring xhtml(odocstream &, OutputParams const &) const;
149 void validate(LaTeXFeatures &) const;
151 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
153 /// Allow multiple blanks
154 virtual bool isFreeSpacing() const { return getLayout().isFreeSpacing(); }
155 /// Don't eliminate empty paragraphs
156 virtual bool allowEmpty() const { return getLayout().isKeepEmpty(); }
157 /// Force inset into LTR environment if surroundings are RTL?
158 virtual bool forceLTR() const { return getLayout().isForceLtr(); }
160 virtual bool usePlainLayout() const { return true; }
161 /// Is this inset's layout defined in the document's textclass?
162 /// May be wrong after textclass change or paste from another document
163 bool undefined() const;
164 /// the string that is passed to the TOC
165 void tocString(odocstream &) const;
167 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
170 void doDispatch(Cursor & cur, FuncRequest & cmd);
172 void edit(Cursor & cur, bool front,
173 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
175 Inset * editXY(Cursor & cur, int x, int y);
177 docstring floatName(std::string const & type, BufferParams const &) const;
179 virtual void resetParagraphsFont();
181 mutable CollapseStatus status_;
183 /// cache for the layout_. Make sure it is in sync with the document class!
184 InsetLayout const * layout_;
186 Dimension dimensionCollapsed(BufferView const & bv) const;
188 /// should paragraphs be forced to use the empty layout?
189 virtual bool forcePlainLayout(idx_type = 0) const
190 { return getLayout().forcePlainLayout(); }
191 /// should the user be allowed to customize alignment, etc.?
192 virtual bool allowParagraphCustomization(idx_type = 0) const
193 { return getLayout().allowParagraphCustomization(); }
194 docstring labelstring_;
196 mutable Box button_dim;
197 /// a substatus of the Open status, determined automatically in metrics
198 mutable bool openinlined_;
199 /// the inset will automatically open when the cursor is inside. This is
200 /// dependent on the bufferview, compare with MathMacro::editing_.
201 mutable std::map<BufferView const *, bool> auto_open_;
202 /// changes color when mouse enters/leaves this inset