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 {
41 static int const TEXT_TO_TOP_OFFSET = 2;
43 static int const TEXT_TO_BOTTOM_OFFSET = 2;
44 /// inset is initially collapsed if bool = true
45 InsetCollapsable(BufferParams const &, bool = false);
47 InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
49 void read(Buffer const *, LyXLex &);
51 void write(Buffer const *, std::ostream &) const;
53 int ascent(BufferView *, LyXFont const &) const;
55 int descent(BufferView *, LyXFont const &) const;
57 int width(BufferView *, LyXFont const &) const;
59 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
61 void update(BufferView *, LyXFont const &, bool =false);
63 void edit(BufferView *, int, int, mouse_button::state);
65 void edit(BufferView *, bool front = true);
67 EDITABLE editable() const;
69 bool insertInset(BufferView *, Inset * inset);
71 virtual bool insetAllowed(Inset::Code code) const {
72 return inset.insetAllowed(code);
75 bool isTextInset() const { return true; }
77 bool doClearArea() const;
79 void insetUnlock(BufferView *);
81 bool needFullRow() const { return isOpen(); }
83 bool lockInsetInInset(BufferView *, UpdatableInset *);
85 bool unlockInsetInInset(BufferView *, UpdatableInset *,
88 bool updateInsetInInset(BufferView *, Inset *);
90 int insetInInsetY() const;
92 RESULT localDispatch(FuncRequest const &);
94 int latex(Buffer const *, std::ostream &,
95 bool fragile, bool free_spc) const;
97 int ascii(Buffer const *, std::ostream &, int) const;
99 int linuxdoc(Buffer const *, std::ostream &) const;
101 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
103 void validate(LaTeXFeatures & features) const;
105 void getCursorPos(BufferView *, int & x, int & y) const;
107 void toggleInsetCursor(BufferView *);
109 void showInsetCursor(BufferView *, bool show = true);
111 void hideInsetCursor(BufferView *);
113 void fitInsetCursor(BufferView * bv) const {
114 inset.fitInsetCursor(bv);
116 UpdatableInset * getLockingInset() const;
118 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
120 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
121 bool selectall = false);
123 void setLabel(string const & l) const;
125 void setLabelFont(LyXFont & f) { labelfont = f; }
128 void setAutoCollapse(bool f) { autocollapse = f; }
132 int getMaxWidth(BufferView *, UpdatableInset const *) const;
135 LyXText * getLyXText(BufferView const *, bool const recursive) const;
137 void deleteLyXText(BufferView *, bool recursive=true) const;
139 void resizeLyXText(BufferView *, bool force = false) const;
141 std::vector<string> const getLabelList() const;
145 int scroll(bool recursive=true) const;
147 void scroll(BufferView *bv, float sx) const {
148 UpdatableInset::scroll(bv, sx);
151 void scroll(BufferView *bv, int offset) const {
152 UpdatableInset::scroll(bv, offset);
155 Inset * getInsetFromID(int id) const;
157 Paragraph * firstParagraph() const;
159 Paragraph * getFirstParagraph(int) const;
161 LyXCursor const & cursor(BufferView *) const;
163 bool isOpen() const { return !collapsed_; }
165 void open(BufferView *);
167 void close(BufferView *) const;
169 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
172 selectNextWordToSpellcheck(BufferView *, float &) const;
174 void selectSelectedWord(BufferView * bv) {
175 inset.selectSelectedWord(bv);
178 void toggleSelection(BufferView * bv, bool kill_selection) {
179 inset.toggleSelection(bv, kill_selection);
184 bool nextChange(BufferView * bv, lyx::pos_type & length);
187 bool searchForward(BufferView * bv, string const & str,
188 bool = true, bool = false);
189 bool searchBackward(BufferView * bv, string const & str,
190 bool = true, bool = false);
193 void addPreview(grfx::PreviewLoader &) const;
197 virtual void cache(BufferView *) const;
199 virtual BufferView * view() const;
202 int ascent_collapsed() const;
204 int descent_collapsed() const;
206 int width_collapsed() const;
208 void draw_collapsed(Painter & pain, int , float &) const;
210 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
213 mutable bool collapsed_;
215 LColor::color framecolor;
220 mutable InsetText inset;
223 mutable int button_length;
225 mutable int button_top_y;
227 mutable int button_bottom_y;
230 mutable int topbaseline;
231 mutable UpdateCodes need_update;
235 void lfunMousePress(FuncRequest const &);
237 bool lfunMouseRelease(FuncRequest const &);
239 void lfunMouseMotion(FuncRequest const &);
242 mutable string label;
248 mutable int oldWidth;
252 mutable bool first_after_edit;
254 mutable boost::weak_ptr<BufferView> view_;