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
24 #include <boost/weak_ptr.hpp>
31 /** A collapsable text inset
34 class InsetCollapsable : public UpdatableInset {
37 static int const TEXT_TO_TOP_OFFSET = 2;
39 static int const TEXT_TO_BOTTOM_OFFSET = 2;
40 /// inset is initially collapsed if bool = true
41 InsetCollapsable(BufferParams const &, bool collapsed = false);
43 InsetCollapsable(InsetCollapsable const & in);
45 void read(Buffer const *, LyXLex &);
47 void write(Buffer const *, std::ostream &) const;
49 void metrics(MetricsInfo &, Dimension &) const;
51 void draw(PainterInfo & pi, int x, int y) const;
52 /// draw, either inlined (no button) or collapsed/open
53 void draw(PainterInfo & pi, int x, int y, bool inlined) const;
55 bool hitButton(FuncRequest const &) const;
57 EDITABLE editable() const;
59 bool insertInset(BufferView *, InsetOld * inset);
61 virtual bool insetAllowed(InsetOld::Code code) const {
62 return inset.insetAllowed(code);
65 bool isTextInset() const { return true; }
67 void insetUnlock(BufferView *);
69 bool needFullRow() const { return isOpen(); }
71 bool lockInsetInInset(BufferView *, UpdatableInset *);
73 bool unlockInsetInInset(BufferView *, UpdatableInset *,
76 int insetInInsetY() const;
78 RESULT localDispatch(FuncRequest const &);
80 int latex(Buffer const *, std::ostream &,
81 LatexRunParams const &) const;
83 int ascii(Buffer const *, std::ostream &, int) const;
85 int linuxdoc(Buffer const *, std::ostream &) const;
87 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
89 void validate(LaTeXFeatures & features) const;
91 void getCursorPos(BufferView *, int & x, int & y) const;
92 /// Get the absolute document x,y of the cursor
93 virtual void getCursor(BufferView &, int &, int &) const;
95 void fitInsetCursor(BufferView * bv) const {
96 inset.fitInsetCursor(bv);
98 UpdatableInset * getLockingInset() const;
100 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
102 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
103 bool selectall = false);
105 void setLabel(string const & l) const;
107 void setLabelFont(LyXFont & f) { labelfont = f; }
110 void setAutoCollapse(bool f) { autocollapse = f; }
113 LyXText * getLyXText(BufferView const *, bool const recursive) const;
115 void deleteLyXText(BufferView *, bool recursive=true) const;
117 void resizeLyXText(BufferView *, bool force = false) const;
119 void getLabelList(std::vector<string> &) const;
121 int scroll(bool recursive=true) const;
123 void scroll(BufferView *bv, float sx) const {
124 UpdatableInset::scroll(bv, sx);
127 void scroll(BufferView *bv, int offset) const {
128 UpdatableInset::scroll(bv, offset);
131 InsetOld * getInsetFromID(int id) const;
133 ParagraphList * getParagraphs(int) const;
135 LyXCursor const & cursor(BufferView *) const;
137 bool isOpen() const { return !collapsed_; }
139 void open(BufferView *);
141 void close(BufferView *) const;
143 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
146 selectNextWordToSpellcheck(BufferView *, float &) const;
148 void selectSelectedWord(BufferView * bv) {
149 inset.selectSelectedWord(bv);
154 bool nextChange(BufferView * bv, lyx::pos_type & length);
157 bool searchForward(BufferView * bv, string const & str,
158 bool = true, bool = false);
159 bool searchBackward(BufferView * bv, string const & str,
160 bool = true, bool = false);
163 void addPreview(lyx::graphics::PreviewLoader &) const;
167 virtual void cache(BufferView *) const;
169 virtual BufferView * view() const;
172 void dimension_collapsed(Dimension &) const;
174 int height_collapsed() const;
176 void draw_collapsed(PainterInfo & pi, int x, int y) const;
178 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
181 mutable bool collapsed_;
183 LColor::color framecolor;
188 mutable InsetText inset;
191 mutable Box button_dim;
194 mutable int topbaseline;
198 void lfunMouseRelease(FuncRequest const &);
200 FuncRequest adjustCommand(FuncRequest const &);
203 mutable string label;
209 mutable int oldWidth;
213 mutable bool first_after_edit;
215 mutable boost::weak_ptr<BufferView> view_;