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 {
35 /// By default, InsetCollapsable uses the plain layout. If you
36 /// want to override this in a subclass, you'll need to call
37 /// Paragraph::setDefaultLayout() in its constructor. See
38 /// InsetBranch for an example.
39 InsetCollapsable(Buffer const &);
41 InsetCollapsable(InsetCollapsable const & rhs);
43 InsetCollapsable * asInsetCollapsable() { return this; }
45 InsetCollapsable const * asInsetCollapsable() const { return this; }
47 docstring toolTip(BufferView const & bv, int x, int y) const;
49 docstring name() const { return from_ascii("Collapsable"); }
51 InsetLayout const & getLayout(BufferParams const &) const { return *layout_; }
53 InsetLayout const & getLayout() const { return *layout_; }
55 void setLayout(BufferParams const &);
56 /// (Re-)set the character style parameters from \p tc according
58 void setLayout(DocumentClass const * const tc);
60 virtual bool usePlainLayout() { return true; }
64 void write(std::ostream &) const;
66 void metrics(MetricsInfo &, Dimension &) const;
68 void draw(PainterInfo & pi, int x, int y) const;
70 /// return x,y of given position relative to the inset's baseline
71 void cursorPos(BufferView const & bv, CursorSlice const & sl,
73 bool boundary, int & x, int & y) const;
74 /// Returns true if (mouse) action is over the inset's button.
75 /// Always returns false when the inset does not have a
77 bool hitButton(FuncRequest const &) const;
79 docstring const getNewLabel(docstring const & l) const;
81 EDITABLE editable(BufferView const & bv) const;
82 /// can we go further down on mouse click?
83 bool descendable(BufferView const & bv) const;
85 void setLabel(docstring const & l);
87 virtual void setButtonLabel() {}
89 bool isOpen(BufferView const & bv) const
90 { return geometry(bv) != ButtonOnly; }
92 CollapseStatus status(BufferView const & bv) const;
93 /** Of the old CollapseStatus we only keep the values
95 * We define a list of possible inset decoration
96 * styles, and a list of possible (concrete, visual)
97 * inset geometries. Relationships between them
98 * (geometries in body of table):
101 * Decoration: \ Open Collapsed
102 * -------------+-------------------------------
103 * Classic | *) TopButton, <--x) ButtonOnly
105 * Minimalistic | NoButton ButtonOnly
106 * Conglomerate | SubLabel Corners
107 * ---------------------------------------------
108 * *) toggled by openinlined_
109 * x) toggled by autoOpen_
113 virtual InsetLayout::InsetDecoration decoration() const;
123 /// Returns the geometry based on CollapseStatus
124 /// (status_), autoOpen_ and openinlined_, and of
125 /// course decoration().
126 Geometry geometry(BufferView const & bv) const;
127 /// Allow spellchecking, except for insets with latex_language
128 bool allowSpellCheck() const { return !forceLTR(); }
130 bool allowMultiPar() const;
132 bool getStatus(Cursor &, FuncRequest const &, FuncStatus &) const;
134 void setStatus(Cursor & cur, CollapseStatus st);
136 bool setMouseHover(bool mouse_hover);
138 ColorCode backgroundColor() const { return layout_->bgcolor(); }
140 int latex(odocstream &, OutputParams const &) const;
142 int docbook(odocstream &, OutputParams const &) const;
144 void validate(LaTeXFeatures &) const;
146 InsetCode lyxCode() const { return COLLAPSABLE_CODE; }
148 /// Allow multiple blanks
149 virtual bool isFreeSpacing() const { return layout_->isFreeSpacing(); }
150 /// Don't eliminate empty paragraphs
151 virtual bool allowEmpty() const { return layout_->isKeepEmpty(); }
152 /// Force inset into LTR environment if surroundings are RTL?
153 virtual bool forceLTR() const { return layout_->isForceLtr(); }
155 virtual bool usePlainLayout() const { return true; }
156 /// Is this inset's layout defined in the document's textclass?
157 /// May be wrong after textclass change or paste from another document
158 bool undefined() const;
159 /// the string that is passed to the TOC
160 void tocString(odocstream &) const;
162 virtual docstring contextMenu(BufferView const & bv, int x, int y) const;
165 void doDispatch(Cursor & cur, FuncRequest & cmd);
167 void edit(Cursor & cur, bool front,
168 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE);
170 Inset * editXY(Cursor & cur, int x, int y);
172 docstring floatName(std::string const & type, BufferParams const &) const;
174 virtual void resetParagraphsFont();
176 mutable CollapseStatus status_;
178 /// cache for the layout_. Make sure it is in sync with the document class!
179 InsetLayout const * layout_;
181 Dimension dimensionCollapsed() const;
183 /// should paragraphs be forced to use the empty layout?
184 virtual bool forcePlainLayout(idx_type = 0) const
185 { return getLayout().forcePlainLayout(); }
186 /// should the user be allowed to customize alignment, etc.?
187 virtual bool allowParagraphCustomization(idx_type = 0) const
188 { return getLayout().allowParagraphCustomization(); }
189 docstring labelstring_;
191 mutable Box button_dim;
192 /// a substatus of the Open status, determined automatically in metrics
193 mutable bool openinlined_;
194 /// the inset will automatically open when the cursor is inside. This is
195 /// dependent on the bufferview, compare with MathMacro::editing_.
196 mutable std::map<BufferView const *, bool> auto_open_;
197 /// changes color when mouse enters/leaves this inset