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 dispatch_result localDispatch(FuncRequest const &);
73 int latex(Buffer const &, std::ostream &,
74 LatexRunParams const &) const;
76 int ascii(Buffer const &, std::ostream &, int) const;
78 int linuxdoc(Buffer const &, std::ostream &) const;
80 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
82 void validate(LaTeXFeatures & features) const;
84 void getCursorPos(BufferView *, int & x, int & y) const;
85 /// Get the absolute document x,y of the cursor
86 virtual void getCursor(BufferView &, int &, int &) const;
88 void fitInsetCursor(BufferView * bv) const;
90 UpdatableInset * getLockingInset() const;
92 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
94 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
95 bool selectall = false);
97 void setLabel(std::string const & l) const;
99 void setLabelFont(LyXFont & f);
102 void setAutoCollapse(bool f);
105 LyXText * getLyXText(BufferView const *, bool const recursive) const;
107 void deleteLyXText(BufferView *, bool recursive=true) const;
108 /// Appends \c list with all labels found within this inset.
109 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
111 int scroll(bool recursive=true) const;
113 void scroll(BufferView *bv, float sx) const;
115 void scroll(BufferView *bv, int offset) const;
117 InsetOld * getInsetFromID(int id) const;
119 ParagraphList * getParagraphs(int) const;
121 LyXCursor const & cursor(BufferView *) const;
125 void open(BufferView *);
127 void close(BufferView *) const;
129 bool allowSpellcheck() const;
132 selectNextWordToSpellcheck(BufferView *, float &) const;
134 void selectSelectedWord(BufferView *);
138 bool nextChange(BufferView * bv, lyx::pos_type & length);
141 bool searchForward(BufferView * bv, std::string const & str,
142 bool = true, bool = false);
143 bool searchBackward(BufferView * bv, std::string const & str,
144 bool = true, bool = false);
147 void addPreview(lyx::graphics::PreviewLoader &) const;
151 void dimension_collapsed(Dimension &) const;
153 int height_collapsed() const;
155 void draw_collapsed(PainterInfo & pi, int x, int y) const;
157 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
158 /// Should be non-const...
159 void setCollapsed(bool) const;
161 Box const & buttonDim() const;
165 void lfunMouseRelease(FuncRequest const &);
167 FuncRequest adjustCommand(FuncRequest const &);
171 mutable InsetText inset;
174 mutable bool collapsed_;
178 mutable Box button_dim;
181 mutable int topbaseline;
184 mutable std::string label;
192 mutable bool first_after_edit;
197 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
199 return inset.insetAllowed(code);
204 bool InsetCollapsable::isTextInset() const
211 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
213 inset.fitInsetCursor(bv);
217 void InsetCollapsable::setLabelFont(LyXFont & f)
224 void InsetCollapsable::setAutoCollapse(bool f)
231 void InsetCollapsable::scroll(BufferView *bv, float sx) const
233 UpdatableInset::scroll(bv, sx);
238 void InsetCollapsable::scroll(BufferView *bv, int offset) const
240 UpdatableInset::scroll(bv, offset);
245 bool InsetCollapsable::isOpen() const
252 bool InsetCollapsable::allowSpellcheck() const
254 return inset.allowSpellcheck();
259 void InsetCollapsable::selectSelectedWord(BufferView * bv)
261 inset.selectSelectedWord(bv);
266 Box const & InsetCollapsable::buttonDim() const