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 bool updateInsetInInset(BufferView *, InsetOld *);
78 int insetInInsetY() const;
80 RESULT localDispatch(FuncRequest const &);
82 int latex(Buffer const *, std::ostream &,
83 LatexRunParams const &) const;
85 int ascii(Buffer const *, std::ostream &, int) const;
87 int linuxdoc(Buffer const *, std::ostream &) const;
89 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
91 void validate(LaTeXFeatures & features) const;
93 void getCursorPos(BufferView *, int & x, int & y) const;
94 /// Get the absolute document x,y of the cursor
95 virtual void getCursor(BufferView &, int &, int &) const;
97 void fitInsetCursor(BufferView * bv) const {
98 inset.fitInsetCursor(bv);
100 UpdatableInset * getLockingInset() const;
102 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
104 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
105 bool selectall = false);
107 void setLabel(string const & l) const;
109 void setLabelFont(LyXFont & f) { labelfont = f; }
112 void setAutoCollapse(bool f) { autocollapse = f; }
115 LyXText * getLyXText(BufferView const *, bool const recursive) const;
117 void deleteLyXText(BufferView *, bool recursive=true) const;
119 void resizeLyXText(BufferView *, bool force = false) const;
121 void getLabelList(std::vector<string> &) const;
123 int scroll(bool recursive=true) const;
125 void scroll(BufferView *bv, float sx) const {
126 UpdatableInset::scroll(bv, sx);
129 void scroll(BufferView *bv, int offset) const {
130 UpdatableInset::scroll(bv, offset);
133 InsetOld * getInsetFromID(int id) const;
135 ParagraphList * getParagraphs(int) const;
137 LyXCursor const & cursor(BufferView *) const;
139 bool isOpen() const { return !collapsed_; }
141 void open(BufferView *);
143 void close(BufferView *) const;
145 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
148 selectNextWordToSpellcheck(BufferView *, float &) const;
150 void selectSelectedWord(BufferView * bv) {
151 inset.selectSelectedWord(bv);
156 bool nextChange(BufferView * bv, lyx::pos_type & length);
159 bool searchForward(BufferView * bv, string const & str,
160 bool = true, bool = false);
161 bool searchBackward(BufferView * bv, string const & str,
162 bool = true, bool = false);
165 void addPreview(lyx::graphics::PreviewLoader &) const;
169 virtual void cache(BufferView *) const;
171 virtual BufferView * view() const;
174 void dimension_collapsed(Dimension &) const;
176 int height_collapsed() const;
178 void draw_collapsed(PainterInfo & pi, int x, int y) const;
180 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
183 mutable bool collapsed_;
185 LColor::color framecolor;
190 mutable InsetText inset;
193 mutable Box button_dim;
196 mutable int topbaseline;
200 void lfunMouseRelease(FuncRequest const &);
202 FuncRequest adjustCommand(FuncRequest const &);
205 mutable string label;
211 mutable int oldWidth;
215 mutable bool first_after_edit;
217 mutable boost::weak_ptr<BufferView> view_;