2 /* This file is part of
3 * ======================================================
5 * LyX, The Document Processor
7 * Copyright 2000-2001 The LyX Team.
9 *======================================================
13 #ifndef INSETCOLLAPSABLE_H
14 #define INSETCOLLAPSABLE_H
21 #include "insettext.h"
30 /** A collapsable text inset
33 class InsetCollapsable : public UpdatableInset {
41 static int const TEXT_TO_TOP_OFFSET = 2;
43 static int const TEXT_TO_BOTTOM_OFFSET = 2;
44 /// inset is initially collapsed if bool = true
45 InsetCollapsable(BufferParams const &, bool = false);
47 InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
49 void read(Buffer const *, LyXLex &);
51 void write(Buffer const *, std::ostream &) const;
53 int ascent(BufferView *, LyXFont const &) const;
55 int descent(BufferView *, LyXFont const &) const;
57 int width(BufferView *, LyXFont const &) const;
59 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
61 void update(BufferView *, LyXFont const &, bool =false);
63 void edit(BufferView *, int, int, mouse_button::state);
65 void edit(BufferView *, bool front = true);
67 EDITABLE editable() const;
69 bool insertInset(BufferView *, Inset * inset);
71 virtual bool insetAllowed(Inset::Code code) const {
72 return inset.insetAllowed(code);
75 bool isTextInset() const { return true; }
77 bool doClearArea() const;
79 void insetUnlock(BufferView *);
81 bool needFullRow() const { return isOpen(); }
83 bool lockInsetInInset(BufferView *, UpdatableInset *);
85 bool unlockInsetInInset(BufferView *, UpdatableInset *,
88 bool updateInsetInInset(BufferView *, Inset *);
90 int insetInInsetY() const;
92 bool insetButtonRelease(BufferView *, int, int, mouse_button::state);
94 void insetButtonPress(BufferView *, int, int, mouse_button::state);
96 void insetMotionNotify(BufferView *, int, int, mouse_button::state);
98 UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
101 int latex(Buffer const *, std::ostream &,
102 bool fragile, bool free_spc) const;
104 int ascii(Buffer const *, std::ostream &, int) const;
106 int linuxdoc(Buffer const *, std::ostream &) const;
108 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
110 void validate(LaTeXFeatures & features) const;
112 void getCursorPos(BufferView *, int & x, int & y) const;
114 void toggleInsetCursor(BufferView *);
116 void showInsetCursor(BufferView *, bool show = true);
118 void hideInsetCursor(BufferView *);
120 void fitInsetCursor(BufferView * bv) const {
121 inset.fitInsetCursor(bv);
123 UpdatableInset * getLockingInset() const;
125 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
127 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
128 bool selectall = false);
130 void setLabel(string const & l) const;
132 void setLabelFont(LyXFont & f) { labelfont = f; }
135 void setAutoCollapse(bool f) { autocollapse = f; }
139 int getMaxWidth(BufferView *, UpdatableInset const *) const;
142 LyXText * getLyXText(BufferView const *, bool const recursive) const;
144 void deleteLyXText(BufferView *, bool recursive=true) const;
146 void resizeLyXText(BufferView *, bool force = false) const;
148 std::vector<string> const getLabelList() const;
152 int scroll(bool recursive=true) const;
154 void scroll(BufferView *bv, float sx) const {
155 UpdatableInset::scroll(bv, sx);
158 void scroll(BufferView *bv, int offset) const {
159 UpdatableInset::scroll(bv, offset);
162 Paragraph * getParFromID(int id) const;
164 Inset * getInsetFromID(int id) const;
166 Paragraph * firstParagraph() const;
168 Paragraph * getFirstParagraph(int) const;
170 LyXCursor const & cursor(BufferView *) const;
172 bool isOpen() const { return !collapsed_; }
174 void open(BufferView *);
176 void close(BufferView *) const;
178 bool allowSpellcheck() { return inset.allowSpellcheck(); }
179 string const selectNextWordToSpellcheck(BufferView *, float &) const;
181 void selectSelectedWord(BufferView * bv) {
182 inset.selectSelectedWord(bv);
184 void toggleSelection(BufferView * bv, bool kill_selection) {
185 inset.toggleSelection(bv, kill_selection);
188 bool searchForward(BufferView * bv, string const & str,
189 bool = true, bool = false);
190 bool searchBackward(BufferView * bv, string const & str,
191 bool = true, bool = false);
194 void addPreview(grfx::PreviewLoader &) const;
198 int ascent_collapsed() const;
200 int descent_collapsed() const;
202 int width_collapsed() const;
204 void draw_collapsed(Painter & pain, int , float &) const;
206 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
209 mutable bool collapsed_;
211 LColor::color framecolor;
216 mutable InsetText inset;
219 mutable int button_length;
221 mutable int button_top_y;
223 mutable int button_bottom_y;
226 mutable int topbaseline;
227 mutable UpdateCodes need_update;
231 mutable string label;
237 mutable int oldWidth;
241 mutable bool first_after_edit;