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 EDITABLE editable() const;
56 bool insertInset(BufferView *, InsetOld * inset);
58 virtual bool insetAllowed(InsetOld::Code code) const {
59 return inset.insetAllowed(code);
62 bool isTextInset() const { return true; }
64 void insetUnlock(BufferView *);
66 bool needFullRow() const { return isOpen(); }
68 bool lockInsetInInset(BufferView *, UpdatableInset *);
70 bool unlockInsetInInset(BufferView *, UpdatableInset *,
73 bool updateInsetInInset(BufferView *, InsetOld *);
75 int insetInInsetY() const;
77 RESULT localDispatch(FuncRequest const &);
79 int latex(Buffer const *, std::ostream &,
80 LatexRunParams const &) const;
82 int ascii(Buffer const *, std::ostream &, int) const;
84 int linuxdoc(Buffer const *, std::ostream &) const;
86 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
88 void validate(LaTeXFeatures & features) const;
90 void getCursorPos(BufferView *, int & x, int & y) const;
91 /// Get the absolute document x,y of the cursor
92 virtual void getCursor(BufferView &, int &, int &) const;
94 void fitInsetCursor(BufferView * bv) const {
95 inset.fitInsetCursor(bv);
97 UpdatableInset * getLockingInset() const;
99 UpdatableInset * getFirstLockingInsetOfType(InsetOld::Code);
101 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
102 bool selectall = false);
104 void setLabel(string const & l) const;
106 void setLabelFont(LyXFont & f) { labelfont = f; }
109 void setAutoCollapse(bool f) { autocollapse = f; }
112 LyXText * getLyXText(BufferView const *, bool const recursive) const;
114 void deleteLyXText(BufferView *, bool recursive=true) const;
116 void resizeLyXText(BufferView *, bool force = false) const;
118 void getLabelList(std::vector<string> &) const;
122 int scroll(bool recursive=true) const;
124 void scroll(BufferView *bv, float sx) const {
125 UpdatableInset::scroll(bv, sx);
128 void scroll(BufferView *bv, int offset) const {
129 UpdatableInset::scroll(bv, offset);
132 InsetOld * getInsetFromID(int id) const;
134 ParagraphList * getParagraphs(int) const;
136 LyXCursor const & cursor(BufferView *) const;
138 bool isOpen() const { return !collapsed_; }
140 void open(BufferView *);
142 void close(BufferView *) const;
144 bool allowSpellcheck() const { return inset.allowSpellcheck(); }
147 selectNextWordToSpellcheck(BufferView *, float &) const;
149 void selectSelectedWord(BufferView * bv) {
150 inset.selectSelectedWord(bv);
153 void toggleSelection(BufferView * bv, bool kill_selection) {
154 inset.toggleSelection(bv, kill_selection);
159 bool nextChange(BufferView * bv, lyx::pos_type & length);
162 bool searchForward(BufferView * bv, string const & str,
163 bool = true, bool = false);
164 bool searchBackward(BufferView * bv, string const & str,
165 bool = true, bool = false);
168 void addPreview(lyx::graphics::PreviewLoader &) const;
172 virtual void cache(BufferView *) const;
174 virtual BufferView * view() const;
177 void dimension_collapsed(Dimension &) const;
179 int height_collapsed() const;
181 void draw_collapsed(PainterInfo & pi, int x, int y) const;
183 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
186 mutable bool collapsed_;
188 LColor::color framecolor;
193 mutable InsetText inset;
196 mutable int button_length;
198 mutable int button_top_y;
200 mutable int button_bottom_y;
203 mutable int topbaseline;
207 void lfunMouseRelease(FuncRequest const &);
209 FuncRequest adjustCommand(FuncRequest const &);
212 mutable string label;
218 mutable int oldWidth;
222 mutable bool first_after_edit;
224 mutable boost::weak_ptr<BufferView> view_;