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 lockInsetInInset(BufferView *, UpdatableInset *);
71 bool unlockInsetInInset(BufferView *, UpdatableInset *,
74 int insetInInsetY() const;
76 RESULT localDispatch(FuncRequest const &);
78 int latex(Buffer const &, std::ostream &,
79 LatexRunParams const &) const;
81 int ascii(Buffer const &, std::ostream &, int) const;
83 int linuxdoc(Buffer const &, std::ostream &) const;
85 int docbook(Buffer const &, std::ostream &, bool mixcont) const;
87 void validate(LaTeXFeatures & features) const;
89 void getCursorPos(BufferView *, int & x, int & y) const;
90 /// Get the absolute document x,y of the cursor
91 virtual void getCursor(BufferView &, int &, int &) const;
93 void fitInsetCursor(BufferView * bv) const {
94 inset.fitInsetCursor(bv);
96 UpdatableInset * getLockingInset() const;
98 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
100 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
101 bool selectall = false);
103 void setLabel(string const & l) const;
105 void setLabelFont(LyXFont & f) { labelfont = f; }
108 void setAutoCollapse(bool f) { autocollapse = f; }
111 LyXText * getLyXText(BufferView const *, bool const recursive) const;
113 void deleteLyXText(BufferView *, bool recursive=true) const;
115 void getLabelList(std::vector<string> &) const;
117 int scroll(bool recursive=true) const;
119 void scroll(BufferView *bv, float sx) const {
120 UpdatableInset::scroll(bv, sx);
123 void scroll(BufferView *bv, int offset) const {
124 UpdatableInset::scroll(bv, offset);
127 InsetOld * getInsetFromID(int id) const;
129 ParagraphList * getParagraphs(int) const;
131 LyXCursor const & cursor(BufferView *) const;
133 bool isOpen() const { return !collapsed_; }
135 void open(BufferView *);
137 void close(BufferView *) const;
139 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
142 selectNextWordToSpellcheck(BufferView *, float &) const;
144 void selectSelectedWord(BufferView * bv) {
145 inset.selectSelectedWord(bv);
150 bool nextChange(BufferView * bv, lyx::pos_type & length);
153 bool searchForward(BufferView * bv, string const & str,
154 bool = true, bool = false);
155 bool searchBackward(BufferView * bv, string const & str,
156 bool = true, bool = false);
159 void addPreview(lyx::graphics::PreviewLoader &) const;
163 virtual void cache(BufferView *) const;
165 virtual BufferView * view() const;
168 void dimension_collapsed(Dimension &) const;
170 int height_collapsed() const;
172 void draw_collapsed(PainterInfo & pi, int x, int y) const;
174 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
177 mutable bool collapsed_;
179 LColor::color framecolor;
184 mutable InsetText inset;
187 mutable Box button_dim;
190 mutable int topbaseline;
194 void lfunMouseRelease(FuncRequest const &);
196 FuncRequest adjustCommand(FuncRequest const &);
199 mutable string label;
207 mutable bool first_after_edit;
209 mutable boost::weak_ptr<BufferView> view_;