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"
28 /** A collapsable text inset
31 class InsetCollapsable : public UpdatableInset {
39 static int const TEXT_TO_TOP_OFFSET = 2;
41 static int const TEXT_TO_BOTTOM_OFFSET = 2;
42 /// inset is initially collapsed if bool = true
43 InsetCollapsable(BufferParams const &, bool = false);
45 InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
47 void read(Buffer const *, LyXLex &);
49 void write(Buffer const *, std::ostream &) const;
51 int ascent(BufferView *, LyXFont const &) const;
53 int descent(BufferView *, LyXFont const &) const;
55 int width(BufferView *, LyXFont const &) const;
57 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
59 void update(BufferView *, LyXFont const &, 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 bool doClearArea() const;
77 void insetUnlock(BufferView *);
79 bool needFullRow() const { return isOpen(); }
81 bool lockInsetInInset(BufferView *, UpdatableInset *);
83 bool unlockInsetInInset(BufferView *, UpdatableInset *,
86 bool updateInsetInInset(BufferView *, Inset *);
88 int insetInInsetY() const;
90 RESULT localDispatch(FuncRequest const &);
92 int latex(Buffer const *, std::ostream &,
93 bool fragile, bool free_spc) const;
95 int ascii(Buffer const *, std::ostream &, int) const;
97 int linuxdoc(Buffer const *, std::ostream &) const;
99 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
101 void validate(LaTeXFeatures & features) const;
103 void getCursorPos(BufferView *, int & x, int & y) const;
105 void toggleInsetCursor(BufferView *);
107 void showInsetCursor(BufferView *, bool show = true);
109 void hideInsetCursor(BufferView *);
111 void fitInsetCursor(BufferView * bv) const {
112 inset.fitInsetCursor(bv);
114 UpdatableInset * getLockingInset() const;
116 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
118 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
119 bool selectall = false);
121 void setLabel(string const & l) const;
123 void setLabelFont(LyXFont & f) { labelfont = f; }
126 void setAutoCollapse(bool f) { autocollapse = f; }
130 int getMaxWidth(BufferView *, UpdatableInset const *) const;
133 LyXText * getLyXText(BufferView const *, bool const recursive) const;
135 void deleteLyXText(BufferView *, bool recursive=true) const;
137 void resizeLyXText(BufferView *, bool force = false) const;
139 std::vector<string> const getLabelList() const;
143 int scroll(bool recursive=true) const;
145 void scroll(BufferView *bv, float sx) const {
146 UpdatableInset::scroll(bv, sx);
149 void scroll(BufferView *bv, int offset) const {
150 UpdatableInset::scroll(bv, offset);
153 Inset * getInsetFromID(int id) const;
155 Paragraph * firstParagraph() const;
157 Paragraph * getFirstParagraph(int) const;
159 LyXCursor const & cursor(BufferView *) const;
161 bool isOpen() const { return !collapsed_; }
163 void open(BufferView *);
165 void close(BufferView *) const;
167 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
170 selectNextWordToSpellcheck(BufferView *, float &) const;
172 void selectSelectedWord(BufferView * bv) {
173 inset.selectSelectedWord(bv);
176 void toggleSelection(BufferView * bv, bool kill_selection) {
177 inset.toggleSelection(bv, kill_selection);
182 bool nextChange(BufferView * bv, lyx::pos_type & length);
185 bool searchForward(BufferView * bv, string const & str,
186 bool = true, bool = false);
187 bool searchBackward(BufferView * bv, string const & str,
188 bool = true, bool = false);
191 void addPreview(grfx::PreviewLoader &) const;
195 int ascent_collapsed() const;
197 int descent_collapsed() const;
199 int width_collapsed() const;
201 void draw_collapsed(Painter & pain, int , float &) const;
203 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
206 mutable bool collapsed_;
208 LColor::color framecolor;
213 mutable InsetText inset;
216 mutable int button_length;
218 mutable int button_top_y;
220 mutable int button_bottom_y;
223 mutable int topbaseline;
224 mutable UpdateCodes need_update;
228 void lfunMousePress(FuncRequest const &);
230 bool lfunMouseRelease(FuncRequest const &);
232 void lfunMouseMotion(FuncRequest const &);
235 mutable string label;
241 mutable int oldWidth;
245 mutable bool first_after_edit;