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"
23 #include <boost/weak_ptr.hpp>
30 /** A collapsable text inset
33 class InsetCollapsable : public UpdatableInset {
36 static int const TEXT_TO_TOP_OFFSET = 2;
38 static int const TEXT_TO_BOTTOM_OFFSET = 2;
39 /// inset is initially collapsed if bool = true
40 InsetCollapsable(BufferParams const &, bool collapsed = false);
42 InsetCollapsable(InsetCollapsable const & in);
44 void read(Buffer const &, LyXLex &);
46 void write(Buffer const &, std::ostream &) const;
48 void metrics(MetricsInfo &, Dimension &) const;
50 void draw(PainterInfo & pi, int x, int y) const;
51 /// draw, either inlined (no button) or collapsed/open
52 void draw(PainterInfo & pi, int x, int y, bool inlined) const;
54 bool hitButton(FuncRequest const &) const;
56 EDITABLE editable() const;
58 bool insertInset(BufferView *, InsetOld * inset);
60 virtual bool insetAllowed(InsetOld::Code code) const;
62 bool isTextInset() const;
64 void insetUnlock(BufferView *);
66 bool lockInsetInInset(BufferView *, UpdatableInset *);
68 bool unlockInsetInInset(BufferView *, UpdatableInset *,
71 int insetInInsetY() const;
73 RESULT localDispatch(FuncRequest const &);
75 int latex(Buffer const &, std::ostream &,
76 LatexRunParams const &) const;
78 int ascii(Buffer const &, std::ostream &, int) const;
80 int linuxdoc(Buffer const &, std::ostream &) const;
82 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
84 void validate(LaTeXFeatures & features) const;
86 void getCursorPos(BufferView *, int & x, int & y) const;
87 /// Get the absolute document x,y of the cursor
88 virtual void getCursor(BufferView &, int &, int &) const;
90 void fitInsetCursor(BufferView * bv) const;
92 UpdatableInset * getLockingInset() const;
94 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
96 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
97 bool selectall = false);
99 void setLabel(string const & l) const;
101 void setLabelFont(LyXFont & f);
104 void setAutoCollapse(bool f);
107 LyXText * getLyXText(BufferView const *, bool const recursive) const;
109 void deleteLyXText(BufferView *, bool recursive=true) const;
110 /// Appends \c list with all labels found within this inset.
111 void getLabelList(Buffer const &, std::vector<string> & list) const;
113 int scroll(bool recursive=true) const;
115 void scroll(BufferView *bv, float sx) const;
117 void scroll(BufferView *bv, int offset) const;
119 InsetOld * getInsetFromID(int id) const;
121 ParagraphList * getParagraphs(int) const;
123 LyXCursor const & cursor(BufferView *) const;
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, string const & str,
144 bool = true, bool = false);
145 bool searchBackward(BufferView * bv, string const & str,
146 bool = true, bool = false);
149 void addPreview(lyx::graphics::PreviewLoader &) const;
153 virtual void cache(BufferView *) const;
155 virtual BufferView * view() const;
158 void dimension_collapsed(Dimension &) const;
160 int height_collapsed() const;
162 void draw_collapsed(PainterInfo & pi, int x, int y) const;
164 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
165 /// Should be non-const...
166 void setCollapsed(bool) const;
168 Box const & buttonDim() const;
172 void lfunMouseRelease(FuncRequest const &);
174 FuncRequest adjustCommand(FuncRequest const &);
178 mutable InsetText inset;
181 mutable bool collapsed_;
185 mutable Box button_dim;
188 mutable int topbaseline;
191 mutable string label;
199 mutable bool first_after_edit;
201 mutable boost::weak_ptr<BufferView> view_;
206 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
208 return inset.insetAllowed(code);
213 bool InsetCollapsable::isTextInset() const
220 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
222 inset.fitInsetCursor(bv);
226 void InsetCollapsable::setLabelFont(LyXFont & f)
233 void InsetCollapsable::setAutoCollapse(bool f)
240 void InsetCollapsable::scroll(BufferView *bv, float sx) const
242 UpdatableInset::scroll(bv, sx);
247 void InsetCollapsable::scroll(BufferView *bv, int offset) const
249 UpdatableInset::scroll(bv, offset);
254 bool InsetCollapsable::isOpen() const
261 bool InsetCollapsable::allowSpellcheck() const
263 return inset.allowSpellcheck();
268 void InsetCollapsable::selectSelectedWord(BufferView * bv)
270 inset.selectSelectedWord(bv);
275 Box const & InsetCollapsable::buttonDim() const