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
19 #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 = 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 void edit(BufferView *, int, int, mouse_button::state);
63 void edit(BufferView *, bool front = true);
65 EDITABLE editable() const;
67 bool insertInset(BufferView *, Inset * inset);
69 virtual bool insetAllowed(Inset::Code code) const {
70 return inset.insetAllowed(code);
73 bool isTextInset() const { return true; }
75 void insetUnlock(BufferView *);
77 bool needFullRow() const { return isOpen(); }
79 bool lockInsetInInset(BufferView *, UpdatableInset *);
81 bool unlockInsetInInset(BufferView *, UpdatableInset *,
84 bool updateInsetInInset(BufferView *, Inset *);
86 int insetInInsetY() const;
88 RESULT localDispatch(FuncRequest const &);
90 int latex(Buffer const *, std::ostream &,
91 bool fragile, bool free_spc) const;
93 int ascii(Buffer const *, std::ostream &, int) const;
95 int linuxdoc(Buffer const *, std::ostream &) const;
97 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
99 void validate(LaTeXFeatures & features) const;
101 void getCursorPos(BufferView *, int & x, int & y) const;
102 /// Get the absolute document x,y of the cursor
103 virtual void getCursor(BufferView &, int &, int &) const;
105 void fitInsetCursor(BufferView * bv) const {
106 inset.fitInsetCursor(bv);
108 UpdatableInset * getLockingInset() const;
110 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
112 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
113 bool selectall = false);
115 void setLabel(string const & l) const;
117 void setLabelFont(LyXFont & f) { labelfont = f; }
120 void setAutoCollapse(bool f) { autocollapse = f; }
123 LyXText * getLyXText(BufferView const *, bool const recursive) const;
125 void deleteLyXText(BufferView *, bool recursive=true) const;
127 void resizeLyXText(BufferView *, bool force = false) const;
129 std::vector<string> const getLabelList() const;
133 int scroll(bool recursive=true) const;
135 void scroll(BufferView *bv, float sx) const {
136 UpdatableInset::scroll(bv, sx);
139 void scroll(BufferView *bv, int offset) const {
140 UpdatableInset::scroll(bv, offset);
143 Inset * getInsetFromID(int id) const;
145 ParagraphList * getParagraphs(int) const;
147 LyXCursor const & cursor(BufferView *) const;
149 bool isOpen() const { return !collapsed_; }
151 void open(BufferView *);
153 void close(BufferView *) const;
155 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
158 selectNextWordToSpellcheck(BufferView *, float &) const;
160 void selectSelectedWord(BufferView * bv) {
161 inset.selectSelectedWord(bv);
164 void toggleSelection(BufferView * bv, bool kill_selection) {
165 inset.toggleSelection(bv, kill_selection);
170 bool nextChange(BufferView * bv, lyx::pos_type & length);
173 bool searchForward(BufferView * bv, string const & str,
174 bool = true, bool = false);
175 bool searchBackward(BufferView * bv, string const & str,
176 bool = true, bool = false);
179 void addPreview(grfx::PreviewLoader &) const;
183 virtual void cache(BufferView *) const;
185 virtual BufferView * view() const;
188 int ascent_collapsed() const;
190 int descent_collapsed() const;
192 int width_collapsed() const;
194 void draw_collapsed(Painter & pain, int , float &) const;
196 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
199 mutable bool collapsed_;
201 LColor::color framecolor;
206 mutable InsetText inset;
209 mutable int button_length;
211 mutable int button_top_y;
213 mutable int button_bottom_y;
216 mutable int topbaseline;
220 void lfunMousePress(FuncRequest const &);
222 bool lfunMouseRelease(FuncRequest const &);
224 void lfunMouseMotion(FuncRequest const &);
227 mutable string label;
233 mutable int oldWidth;
237 mutable bool first_after_edit;
239 mutable boost::weak_ptr<BufferView> view_;