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 collapsed = false);
42 InsetCollapsable(InsetCollapsable const & in);
44 void read(Buffer const *, LyXLex &);
46 void write(Buffer const *, std::ostream &) const;
48 void metrics(MetricsInfo &, Dimension &) const;
50 void draw(PainterInfo & pi, int x, int y) const;
51 /// draw, either inlined (no button) or collapsed/open
52 void draw(PainterInfo & pi, int x, int y, bool inlined) const;
54 void update(BufferView *, bool = false);
56 EDITABLE editable() const;
58 bool insertInset(BufferView *, Inset * inset);
60 virtual bool insetAllowed(Inset::Code code) const {
61 return inset.insetAllowed(code);
64 bool isTextInset() const { return true; }
66 void insetUnlock(BufferView *);
68 bool needFullRow() const { return isOpen(); }
70 bool lockInsetInInset(BufferView *, UpdatableInset *);
72 bool unlockInsetInInset(BufferView *, UpdatableInset *,
75 bool updateInsetInInset(BufferView *, Inset *);
77 int insetInInsetY() const;
79 RESULT localDispatch(FuncRequest const &);
81 int latex(Buffer const *, std::ostream &,
82 LatexRunParams const &) const;
84 int ascii(Buffer const *, std::ostream &, int) const;
86 int linuxdoc(Buffer const *, std::ostream &) const;
88 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
90 void validate(LaTeXFeatures & features) const;
92 void getCursorPos(BufferView *, int & x, int & y) const;
93 /// Get the absolute document x,y of the cursor
94 virtual void getCursor(BufferView &, int &, int &) const;
96 void fitInsetCursor(BufferView * bv) const {
97 inset.fitInsetCursor(bv);
99 UpdatableInset * getLockingInset() const;
101 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
103 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
104 bool selectall = false);
106 void setLabel(string const & l) const;
108 void setLabelFont(LyXFont & f) { labelfont = f; }
111 void setAutoCollapse(bool f) { autocollapse = f; }
114 LyXText * getLyXText(BufferView const *, bool const recursive) const;
116 void deleteLyXText(BufferView *, bool recursive=true) const;
118 void resizeLyXText(BufferView *, bool force = false) const;
120 std::vector<string> const getLabelList() const;
124 int scroll(bool recursive=true) const;
126 void scroll(BufferView *bv, float sx) const {
127 UpdatableInset::scroll(bv, sx);
130 void scroll(BufferView *bv, int offset) const {
131 UpdatableInset::scroll(bv, offset);
134 Inset * getInsetFromID(int id) const;
136 ParagraphList * getParagraphs(int) const;
138 LyXCursor const & cursor(BufferView *) const;
140 bool isOpen() const { return !collapsed_; }
142 void open(BufferView *);
144 void close(BufferView *) const;
146 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
149 selectNextWordToSpellcheck(BufferView *, float &) const;
151 void selectSelectedWord(BufferView * bv) {
152 inset.selectSelectedWord(bv);
155 void toggleSelection(BufferView * bv, bool kill_selection) {
156 inset.toggleSelection(bv, kill_selection);
161 bool nextChange(BufferView * bv, lyx::pos_type & length);
164 bool searchForward(BufferView * bv, string const & str,
165 bool = true, bool = false);
166 bool searchBackward(BufferView * bv, string const & str,
167 bool = true, bool = false);
170 void addPreview(grfx::PreviewLoader &) const;
174 virtual void cache(BufferView *) const;
176 virtual BufferView * view() const;
179 void dimension_collapsed(Dimension &) const;
181 int height_collapsed() const;
183 void draw_collapsed(PainterInfo & pi, int x, int y) const;
185 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
188 mutable bool collapsed_;
190 LColor::color framecolor;
195 mutable InsetText inset;
198 mutable int button_length;
200 mutable int button_top_y;
202 mutable int button_bottom_y;
205 mutable int topbaseline;
209 void lfunMouseRelease(FuncRequest const &);
211 FuncRequest adjustCommand(FuncRequest const &);
214 mutable string label;
220 mutable int oldWidth;
224 mutable bool first_after_edit;
226 mutable boost::weak_ptr<BufferView> view_;