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 = false);
42 InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
44 void read(Buffer const *, LyXLex &);
46 void write(Buffer const *, std::ostream &) const;
48 int ascent(BufferView *, LyXFont const &) const;
50 int descent(BufferView *, LyXFont const &) const;
52 int width(BufferView *, LyXFont const &) const;
54 void draw(BufferView *, const LyXFont &, int , float &) const;
55 /// draw, either inlined (no button) or collapsed/open
56 void draw(BufferView * bv, LyXFont const & f,
57 int baseline, float & x, bool inlined) const;
59 void update(BufferView *, bool =false);
61 EDITABLE editable() const;
63 bool insertInset(BufferView *, Inset * inset);
65 virtual bool insetAllowed(Inset::Code code) const {
66 return inset.insetAllowed(code);
69 bool isTextInset() const { return true; }
71 void insetUnlock(BufferView *);
73 bool needFullRow() const { return isOpen(); }
75 bool lockInsetInInset(BufferView *, UpdatableInset *);
77 bool unlockInsetInInset(BufferView *, UpdatableInset *,
80 bool updateInsetInInset(BufferView *, Inset *);
82 int insetInInsetY() const;
84 RESULT localDispatch(FuncRequest const &);
86 int latex(Buffer const *, std::ostream &,
87 bool fragile, bool free_spc) const;
89 int ascii(Buffer const *, std::ostream &, int) const;
91 int linuxdoc(Buffer const *, std::ostream &) const;
93 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
95 void validate(LaTeXFeatures & features) const;
97 void getCursorPos(BufferView *, int & x, int & y) const;
98 /// Get the absolute document x,y of the cursor
99 virtual void getCursor(BufferView &, int &, int &) const;
101 void fitInsetCursor(BufferView * bv) const {
102 inset.fitInsetCursor(bv);
104 UpdatableInset * getLockingInset() const;
106 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
108 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
109 bool selectall = false);
111 void setLabel(string const & l) const;
113 void setLabelFont(LyXFont & f) { labelfont = f; }
116 void setAutoCollapse(bool f) { autocollapse = f; }
119 LyXText * getLyXText(BufferView const *, bool const recursive) const;
121 void deleteLyXText(BufferView *, bool recursive=true) const;
123 void resizeLyXText(BufferView *, bool force = false) const;
125 std::vector<string> const getLabelList() const;
129 int scroll(bool recursive=true) const;
131 void scroll(BufferView *bv, float sx) const {
132 UpdatableInset::scroll(bv, sx);
135 void scroll(BufferView *bv, int offset) const {
136 UpdatableInset::scroll(bv, offset);
139 Inset * getInsetFromID(int id) const;
141 ParagraphList * getParagraphs(int) const;
143 LyXCursor const & cursor(BufferView *) const;
145 bool isOpen() const { return !collapsed_; }
147 void open(BufferView *);
149 void close(BufferView *) const;
151 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
154 selectNextWordToSpellcheck(BufferView *, float &) const;
156 void selectSelectedWord(BufferView * bv) {
157 inset.selectSelectedWord(bv);
160 void toggleSelection(BufferView * bv, bool kill_selection) {
161 inset.toggleSelection(bv, kill_selection);
166 bool nextChange(BufferView * bv, lyx::pos_type & length);
169 bool searchForward(BufferView * bv, string const & str,
170 bool = true, bool = false);
171 bool searchBackward(BufferView * bv, string const & str,
172 bool = true, bool = false);
175 void addPreview(grfx::PreviewLoader &) const;
179 virtual void cache(BufferView *) const;
181 virtual BufferView * view() const;
184 int ascent_collapsed() const;
186 int descent_collapsed() const;
188 int width_collapsed() const;
190 void draw_collapsed(Painter & pain, int , float &) const;
192 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
195 mutable bool collapsed_;
197 LColor::color framecolor;
202 mutable InsetText inset;
205 mutable int button_length;
207 mutable int button_top_y;
209 mutable int button_bottom_y;
212 mutable int topbaseline;
216 void lfunMouseRelease(FuncRequest const &);
218 FuncRequest adjustCommand(FuncRequest const &);
221 mutable string label;
227 mutable int oldWidth;
231 mutable bool first_after_edit;
233 mutable boost::weak_ptr<BufferView> view_;