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"
28 /** A collapsable text inset
31 class InsetCollapsable : public UpdatableInset {
34 static int const TEXT_TO_TOP_OFFSET = 2;
36 static int const TEXT_TO_BOTTOM_OFFSET = 2;
37 /// inset is initially collapsed if bool = true
38 InsetCollapsable(BufferParams const &, bool collapsed = false);
40 InsetCollapsable(InsetCollapsable const & in);
42 void read(Buffer const &, LyXLex &);
44 void write(Buffer const &, std::ostream &) const;
46 void metrics(MetricsInfo &, Dimension &) const;
48 void draw(PainterInfo & pi, int x, int y) const;
49 /// draw, either inlined (no button) or collapsed/open
50 void draw(PainterInfo & pi, int x, int y, bool inlined) const;
52 bool hitButton(FuncRequest const &) const;
54 EDITABLE editable() const;
56 bool insertInset(BufferView *, InsetOld * inset);
58 virtual bool insetAllowed(InsetOld::Code code) const;
60 bool isTextInset() const;
62 void insetUnlock(BufferView *);
64 bool lockInsetInInset(BufferView *, UpdatableInset *);
66 bool unlockInsetInInset(BufferView *, UpdatableInset *,
69 int insetInInsetY() const;
71 int latex(Buffer const &, std::ostream &,
72 LatexRunParams const &) const;
74 int ascii(Buffer const &, std::ostream &, int) const;
76 int linuxdoc(Buffer const &, std::ostream &) const;
78 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
80 void validate(LaTeXFeatures & features) const;
82 void getCursorPos(BufferView *, int & x, int & y) const;
83 /// Get the absolute document x,y of the cursor
84 virtual void getCursor(BufferView &, int &, int &) const;
86 void fitInsetCursor(BufferView * bv) const;
88 UpdatableInset * getLockingInset() const;
90 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
92 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
93 bool selectall = false);
95 void setLabel(std::string const & l) const;
97 void setLabelFont(LyXFont & f);
100 void setAutoCollapse(bool f);
103 LyXText * getLyXText(BufferView const *, bool const recursive) const;
105 void deleteLyXText(BufferView *, bool recursive=true) const;
106 /// Appends \c list with all labels found within this inset.
107 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
109 int scroll(bool recursive=true) const;
111 void scroll(BufferView *bv, float sx) const;
113 void scroll(BufferView *bv, int offset) const;
115 InsetOld * getInsetFromID(int id) const;
117 ParagraphList * getParagraphs(int) const;
119 LyXText * getText(int) const;
121 LyXCursor const & cursor(BufferView *) const;
123 virtual bool display() const { return isOpen(); }
127 void open(BufferView *);
129 void close(BufferView *) const;
131 bool allowSpellcheck() const;
134 selectNextWordToSpellcheck(BufferView *, float &) const;
136 void selectSelectedWord(BufferView *);
140 bool nextChange(BufferView * bv, lyx::pos_type & length);
143 bool searchForward(BufferView * bv, std::string const & str,
144 bool = true, bool = false);
145 bool searchBackward(BufferView * bv, std::string const & str,
146 bool = true, bool = false);
149 void addPreview(lyx::graphics::PreviewLoader &) const;
155 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
157 void dimension_collapsed(Dimension &) const;
159 int height_collapsed() const;
161 void draw_collapsed(PainterInfo & pi, int x, int y) const;
163 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
164 /// Should be non-const...
165 void setCollapsed(bool) const;
167 Box const & buttonDim() const;
171 void lfunMouseRelease(FuncRequest const &);
173 FuncRequest adjustCommand(FuncRequest const &);
175 void edit(BufferView *, int index);
179 mutable InsetText inset;
182 mutable bool collapsed_;
186 mutable Box button_dim;
189 mutable int topbaseline;
192 mutable std::string label;
200 mutable bool first_after_edit;
205 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
207 return inset.insetAllowed(code);
212 bool InsetCollapsable::isTextInset() const
219 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
221 inset.fitInsetCursor(bv);
225 void InsetCollapsable::setLabelFont(LyXFont & f)
232 void InsetCollapsable::setAutoCollapse(bool f)
239 void InsetCollapsable::scroll(BufferView *bv, float sx) const
241 UpdatableInset::scroll(bv, sx);
246 void InsetCollapsable::scroll(BufferView *bv, int offset) const
248 UpdatableInset::scroll(bv, offset);
253 bool InsetCollapsable::isOpen() const
260 bool InsetCollapsable::allowSpellcheck() const
262 return inset.allowSpellcheck();
267 void InsetCollapsable::selectSelectedWord(BufferView * bv)
269 inset.selectSelectedWord(bv);
274 Box const & InsetCollapsable::buttonDim() const