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"
20 #include "funcrequest.h" // for adjustCommand
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 //InsetCollapsable(InsetCollapsable const & in, bool same_id);
46 void read(Buffer const *, LyXLex &);
48 void write(Buffer const *, std::ostream &) const;
50 void dimension(BufferView *, LyXFont const &, Dimension &) const;
52 void draw(BufferView *, const LyXFont &, int, float &) const;
53 /// draw, either inlined (no button) or collapsed/open
54 void draw(BufferView * bv, LyXFont const & f,
55 int baseline, float & x, bool inlined) const;
57 void update(BufferView *, bool = false);
59 EDITABLE editable() const;
61 bool insertInset(BufferView *, Inset * inset);
63 virtual bool insetAllowed(Inset::Code code) const {
64 return inset.insetAllowed(code);
67 bool isTextInset() const { return true; }
69 void insetUnlock(BufferView *);
71 bool needFullRow() const { return isOpen(); }
73 bool lockInsetInInset(BufferView *, UpdatableInset *);
75 bool unlockInsetInInset(BufferView *, UpdatableInset *,
78 bool updateInsetInInset(BufferView *, Inset *);
80 int insetInInsetY() const;
82 RESULT localDispatch(FuncRequest const &);
84 int latex(Buffer const *, std::ostream &,
85 LatexRunParams const &) const;
87 int ascii(Buffer const *, std::ostream &, int) const;
89 int linuxdoc(Buffer const *, std::ostream &) const;
91 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
93 void validate(LaTeXFeatures & features) const;
95 void getCursorPos(BufferView *, int & x, int & y) const;
96 /// Get the absolute document x,y of the cursor
97 virtual void getCursor(BufferView &, int &, int &) const;
99 void fitInsetCursor(BufferView * bv) const {
100 inset.fitInsetCursor(bv);
102 UpdatableInset * getLockingInset() const;
104 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
106 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
107 bool selectall = false);
109 void setLabel(string const & l) const;
111 void setLabelFont(LyXFont & f) { labelfont = f; }
114 void setAutoCollapse(bool f) { autocollapse = f; }
117 LyXText * getLyXText(BufferView const *, bool const recursive) const;
119 void deleteLyXText(BufferView *, bool recursive=true) const;
121 void resizeLyXText(BufferView *, bool force = false) const;
123 std::vector<string> const getLabelList() const;
127 int scroll(bool recursive=true) const;
129 void scroll(BufferView *bv, float sx) const {
130 UpdatableInset::scroll(bv, sx);
133 void scroll(BufferView *bv, int offset) const {
134 UpdatableInset::scroll(bv, offset);
137 Inset * getInsetFromID(int id) const;
139 ParagraphList * getParagraphs(int) const;
141 LyXCursor const & cursor(BufferView *) const;
143 bool isOpen() const { return !collapsed_; }
145 void open(BufferView *);
147 void close(BufferView *) const;
149 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
152 selectNextWordToSpellcheck(BufferView *, float &) const;
154 void selectSelectedWord(BufferView * bv) {
155 inset.selectSelectedWord(bv);
158 void toggleSelection(BufferView * bv, bool kill_selection) {
159 inset.toggleSelection(bv, kill_selection);
164 bool nextChange(BufferView * bv, lyx::pos_type & length);
167 bool searchForward(BufferView * bv, string const & str,
168 bool = true, bool = false);
169 bool searchBackward(BufferView * bv, string const & str,
170 bool = true, bool = false);
173 void addPreview(grfx::PreviewLoader &) const;
177 virtual void cache(BufferView *) const;
179 virtual BufferView * view() const;
182 void dimension_collapsed(Dimension &) const;
184 int height_collapsed() const;
186 void draw_collapsed(Painter & pain, int, float &) const;
188 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
191 mutable bool collapsed_;
193 LColor::color framecolor;
198 mutable InsetText inset;
201 mutable int button_length;
203 mutable int button_top_y;
205 mutable int button_bottom_y;
208 mutable int topbaseline;
212 void lfunMouseRelease(FuncRequest const &);
214 FuncRequest adjustCommand(FuncRequest const &);
217 mutable string label;
223 mutable int oldWidth;
227 mutable bool first_after_edit;
229 mutable boost::weak_ptr<BufferView> view_;