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
22 #include "insettext.h"
31 /** A collapsable text inset
34 class InsetCollapsable : public UpdatableInset {
42 static int const TEXT_TO_TOP_OFFSET = 2;
44 static int const TEXT_TO_BOTTOM_OFFSET = 2;
45 /// inset is initially collapsed if bool = true
46 InsetCollapsable(BufferParams const &, bool = false);
48 InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
50 void read(Buffer const *, LyXLex &);
52 void write(Buffer const *, std::ostream &) const;
54 int ascent(BufferView *, LyXFont const &) const;
56 int descent(BufferView *, LyXFont const &) const;
58 int width(BufferView *, LyXFont const &) const;
60 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
62 void update(BufferView *, LyXFont const &, bool =false);
64 void edit(BufferView *, int, int, mouse_button::state);
66 void edit(BufferView *, bool front = true);
68 EDITABLE editable() const;
70 bool insertInset(BufferView *, Inset * inset);
72 virtual bool insetAllowed(Inset::Code code) const {
73 return inset.insetAllowed(code);
76 bool isTextInset() const { return true; }
78 bool doClearArea() const;
80 void insetUnlock(BufferView *);
82 bool needFullRow() const { return isOpen(); }
84 bool lockInsetInInset(BufferView *, UpdatableInset *);
86 bool unlockInsetInInset(BufferView *, UpdatableInset *,
89 bool updateInsetInInset(BufferView *, Inset *);
91 int insetInInsetY() const;
93 RESULT localDispatch(FuncRequest const &);
95 int latex(Buffer const *, std::ostream &,
96 bool fragile, bool free_spc) const;
98 int ascii(Buffer const *, std::ostream &, int) const;
100 int linuxdoc(Buffer const *, std::ostream &) const;
102 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
104 void validate(LaTeXFeatures & features) const;
106 void getCursorPos(BufferView *, int & x, int & y) const;
108 void toggleInsetCursor(BufferView *);
110 void showInsetCursor(BufferView *, bool show = true);
112 void hideInsetCursor(BufferView *);
114 void fitInsetCursor(BufferView * bv) const {
115 inset.fitInsetCursor(bv);
117 UpdatableInset * getLockingInset() const;
119 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
121 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
122 bool selectall = false);
124 void setLabel(string const & l) const;
126 void setLabelFont(LyXFont & f) { labelfont = f; }
129 void setAutoCollapse(bool f) { autocollapse = f; }
133 int getMaxWidth(BufferView *, UpdatableInset const *) const;
136 LyXText * getLyXText(BufferView const *, bool const recursive) const;
138 void deleteLyXText(BufferView *, bool recursive=true) const;
140 void resizeLyXText(BufferView *, bool force = false) const;
142 std::vector<string> const getLabelList() const;
146 int scroll(bool recursive=true) const;
148 void scroll(BufferView *bv, float sx) const {
149 UpdatableInset::scroll(bv, sx);
152 void scroll(BufferView *bv, int offset) const {
153 UpdatableInset::scroll(bv, offset);
156 Paragraph * getParFromID(int id) const;
158 Inset * getInsetFromID(int id) const;
160 Paragraph * firstParagraph() const;
162 Paragraph * getFirstParagraph(int) const;
164 LyXCursor const & cursor(BufferView *) const;
166 bool isOpen() const { return !collapsed_; }
168 void open(BufferView *);
170 void close(BufferView *) const;
172 bool allowSpellcheck() { return inset.allowSpellcheck(); }
175 selectNextWordToSpellcheck(BufferView *, float &) const;
177 void selectSelectedWord(BufferView * bv) {
178 inset.selectSelectedWord(bv);
181 void toggleSelection(BufferView * bv, bool kill_selection) {
182 inset.toggleSelection(bv, kill_selection);
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;