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 &,
75 LatexRunParams const &) const;
77 int linuxdoc(Buffer const &, std::ostream &,
78 LatexRunParams const &) const;
80 int docbook(Buffer const &, std::ostream &,
81 LatexRunParams const & runparams) const;
83 void validate(LaTeXFeatures & features) const;
85 void getCursorPos(BufferView *, int & x, int & y) const;
86 /// Get the absolute document x,y of the cursor
87 virtual void getCursor(BufferView &, int &, int &) const;
89 void fitInsetCursor(BufferView * bv) const;
91 UpdatableInset * getLockingInset() const;
93 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
95 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
96 bool selectall = false);
98 void setLabel(std::string const & l) const;
100 void setLabelFont(LyXFont & f);
103 void setAutoCollapse(bool f);
106 LyXText * getLyXText(BufferView const *, bool const recursive) const;
108 void deleteLyXText(BufferView *, bool recursive=true) const;
109 /// Appends \c list with all labels found within this inset.
110 void getLabelList(Buffer const &, std::vector<std::string> & list) const;
112 int scroll(bool recursive=true) const;
114 void scroll(BufferView *bv, float sx) const;
116 void scroll(BufferView *bv, int offset) const;
118 InsetOld * getInsetFromID(int id) const;
120 ParagraphList * getParagraphs(int) const;
122 LyXText * getText(int) const;
124 LyXCursor const & cursor(BufferView *) const;
126 virtual bool display() const { return isOpen(); }
130 void open(BufferView *);
132 void close(BufferView *) const;
134 bool allowSpellcheck() const;
137 selectNextWordToSpellcheck(BufferView *, float &) const;
139 void selectSelectedWord(BufferView *);
143 bool nextChange(BufferView * bv, lyx::pos_type & length);
146 bool searchForward(BufferView * bv, std::string const & str,
147 bool = true, bool = false);
148 bool searchBackward(BufferView * bv, std::string const & str,
149 bool = true, bool = false);
152 void addPreview(lyx::graphics::PreviewLoader &) const;
158 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
160 void dimension_collapsed(Dimension &) const;
162 int height_collapsed() const;
164 void draw_collapsed(PainterInfo & pi, int x, int y) const;
166 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
167 /// Should be non-const...
168 void setCollapsed(bool) const;
170 Box const & buttonDim() const;
174 void lfunMouseRelease(FuncRequest const &);
176 FuncRequest adjustCommand(FuncRequest const &);
178 void edit(BufferView *, int index);
182 mutable InsetText inset;
185 mutable bool collapsed_;
189 mutable Box button_dim;
192 mutable int topbaseline;
195 mutable std::string label;
203 mutable bool first_after_edit;
208 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
210 return inset.insetAllowed(code);
215 bool InsetCollapsable::isTextInset() const
222 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
224 inset.fitInsetCursor(bv);
228 void InsetCollapsable::setLabelFont(LyXFont & f)
235 void InsetCollapsable::setAutoCollapse(bool f)
242 void InsetCollapsable::scroll(BufferView *bv, float sx) const
244 UpdatableInset::scroll(bv, sx);
249 void InsetCollapsable::scroll(BufferView *bv, int offset) const
251 UpdatableInset::scroll(bv, offset);
256 bool InsetCollapsable::isOpen() const
263 bool InsetCollapsable::allowSpellcheck() const
265 return inset.allowSpellcheck();
270 void InsetCollapsable::selectSelectedWord(BufferView * bv)
272 inset.selectSelectedWord(bv);
277 Box const & InsetCollapsable::buttonDim() const