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"
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 bool hitButton(FuncRequest const &) const;
56 EDITABLE editable() const;
58 bool insertInset(BufferView *, InsetOld * inset);
60 virtual bool insetAllowed(InsetOld::Code code) const {
61 return inset.insetAllowed(code);
64 bool isTextInset() const { return true; }
66 void insetUnlock(BufferView *);
68 bool lockInsetInInset(BufferView *, UpdatableInset *);
70 bool unlockInsetInInset(BufferView *, UpdatableInset *,
73 int insetInInsetY() const;
75 RESULT localDispatch(FuncRequest const &);
77 int latex(Buffer const &, std::ostream &,
78 LatexRunParams const &) const;
80 int ascii(Buffer const &, std::ostream &, int) const;
82 int linuxdoc(Buffer const &, std::ostream &) const;
84 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
86 void validate(LaTeXFeatures & features) const;
88 void getCursorPos(BufferView *, int & x, int & y) const;
89 /// Get the absolute document x,y of the cursor
90 virtual void getCursor(BufferView &, int &, int &) const;
92 void fitInsetCursor(BufferView * bv) const {
93 inset.fitInsetCursor(bv);
95 UpdatableInset * getLockingInset() const;
97 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
99 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
100 bool selectall = false);
102 void setLabel(string const & l) const;
104 void setLabelFont(LyXFont & f) { labelfont = f; }
107 void setAutoCollapse(bool f) { autocollapse = f; }
110 LyXText * getLyXText(BufferView const *, bool const recursive) const;
112 void deleteLyXText(BufferView *, bool recursive=true) const;
114 void getLabelList(std::vector<string> &) const;
116 int scroll(bool recursive=true) const;
118 void scroll(BufferView *bv, float sx) const {
119 UpdatableInset::scroll(bv, sx);
122 void scroll(BufferView *bv, int offset) const {
123 UpdatableInset::scroll(bv, offset);
126 InsetOld * getInsetFromID(int id) const;
128 ParagraphList * getParagraphs(int) const;
130 LyXCursor const & cursor(BufferView *) const;
132 bool isOpen() const { return !collapsed_; }
134 void open(BufferView *);
136 void close(BufferView *) const;
138 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
141 selectNextWordToSpellcheck(BufferView *, float &) const;
143 void selectSelectedWord(BufferView * bv) {
144 inset.selectSelectedWord(bv);
149 bool nextChange(BufferView * bv, lyx::pos_type & length);
152 bool searchForward(BufferView * bv, string const & str,
153 bool = true, bool = false);
154 bool searchBackward(BufferView * bv, string const & str,
155 bool = true, bool = false);
158 void addPreview(lyx::graphics::PreviewLoader &) const;
162 virtual void cache(BufferView *) const;
164 virtual BufferView * view() const;
167 void dimension_collapsed(Dimension &) const;
169 int height_collapsed() const;
171 void draw_collapsed(PainterInfo & pi, int x, int y) const;
173 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
176 mutable bool collapsed_;
178 LColor::color framecolor;
183 mutable InsetText inset;
186 mutable Box button_dim;
189 mutable int topbaseline;
193 void lfunMouseRelease(FuncRequest const &);
195 FuncRequest adjustCommand(FuncRequest const &);
198 mutable string label;
206 mutable bool first_after_edit;
208 mutable boost::weak_ptr<BufferView> view_;