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 ParagraphList * getParagraphs(int) const;
120 int numParagraphs() 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;
136 bool nextChange(BufferView * bv, lyx::pos_type & length);
139 bool searchForward(BufferView * bv, std::string const & str,
140 bool = true, bool = false);
141 bool searchBackward(BufferView * bv, std::string const & str,
142 bool = true, bool = false);
145 void addPreview(lyx::graphics::PreviewLoader &) const;
151 priv_dispatch(FuncRequest const &, idx_type &, pos_type &);
153 void dimension_collapsed(Dimension &) const;
155 int height_collapsed() const;
157 void draw_collapsed(PainterInfo & pi, int x, int y) const;
159 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
160 /// Should be non-const...
161 void setCollapsed(bool) const;
163 Box const & buttonDim() const;
167 void lfunMouseRelease(FuncRequest const &);
169 FuncRequest adjustCommand(FuncRequest const &);
171 void edit(BufferView *, int index);
175 mutable InsetText inset;
178 mutable bool collapsed_;
182 mutable Box button_dim;
185 mutable int topbaseline;
188 mutable std::string label;
196 mutable bool first_after_edit;
201 bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
203 return inset.insetAllowed(code);
208 bool InsetCollapsable::isTextInset() const
215 void InsetCollapsable::fitInsetCursor(BufferView * bv) const
217 inset.fitInsetCursor(bv);
221 void InsetCollapsable::setLabelFont(LyXFont & f)
228 void InsetCollapsable::setAutoCollapse(bool f)
235 void InsetCollapsable::scroll(BufferView *bv, float sx) const
237 UpdatableInset::scroll(bv, sx);
242 void InsetCollapsable::scroll(BufferView *bv, int offset) const
244 UpdatableInset::scroll(bv, offset);
249 bool InsetCollapsable::isOpen() const
256 Box const & InsetCollapsable::buttonDim() const