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(bool = false);
47 InsetCollapsable(InsetCollapsable const & in, bool same_id = false);
49 Inset * clone(Buffer const &, bool same_id = false) const;
51 void read(Buffer const *, LyXLex &);
53 void write(Buffer const *, std::ostream &) const;
55 int ascent(BufferView *, LyXFont const &) const;
57 int descent(BufferView *, LyXFont const &) const;
59 int width(BufferView *, LyXFont const & f) const;
61 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
63 void update(BufferView *, LyXFont const &, bool =false);
65 void edit(BufferView *, int, int, unsigned int);
67 void edit(BufferView *, bool front = true);
69 EDITABLE editable() const;
71 bool insertInset(BufferView *, Inset * inset);
73 bool insetAllowed(Inset::Code code) const {
74 return inset.insetAllowed(code);
77 bool isTextInset() const { return true; }
79 bool doClearArea() const;
81 void insetUnlock(BufferView *);
83 bool needFullRow() const { return !collapsed_; }
85 bool lockInsetInInset(BufferView *, UpdatableInset *);
87 bool unlockInsetInInset(BufferView *, UpdatableInset *,
90 bool updateInsetInInset(BufferView *, Inset *);
92 unsigned int insetInInsetY();
94 void insetButtonRelease(BufferView *, int, int, int);
96 void insetButtonPress(BufferView *, int, int, int);
98 void insetMotionNotify(BufferView *, int, int, int);
100 void insetKeyPress(XKeyEvent *);
102 UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
105 int latex(Buffer const *, std::ostream &,
106 bool fragile, bool free_spc) const;
108 int ascii(Buffer const *, std::ostream &, int) const { return 0; }
110 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
112 int docBook(Buffer const *, std::ostream &) const { return 0; }
114 void validate(LaTeXFeatures & features) const;
116 void getCursorPos(BufferView *, int & x, int & y) const;
118 void toggleInsetCursor(BufferView *);
120 void showInsetCursor(BufferView *, bool show = true);
122 void hideInsetCursor(BufferView *);
124 void fitInsetCursor(BufferView * bv) const {
125 inset.fitInsetCursor(bv);
127 UpdatableInset * getLockingInset() const;
129 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
131 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
132 bool selectall = false);
135 void setLabel(string const & l, bool flag = false);
138 void setLabel(string const & l);
141 void setLabelFont(LyXFont & f) { labelfont = f; }
144 void setAutoCollapse(bool f) { autocollapse = f; }
147 int getMaxWidth(BufferView *, UpdatableInset const *) const;
149 LyXText * getLyXText(BufferView const *, bool const recursive) const;
151 void deleteLyXText(BufferView *, bool recursive=true) const;
153 void resizeLyXText(BufferView *, bool force = false) const;
155 std::vector<string> const getLabelList() const;
159 int scroll(bool recursive=true) const;
161 void scroll(BufferView *bv, float sx) const {
162 UpdatableInset::scroll(bv, sx);
165 void scroll(BufferView *bv, int offset) const {
166 UpdatableInset::scroll(bv, offset);
169 Paragraph * getParFromID(int id) const;
171 Inset * getInsetFromID(int id) const;
173 Paragraph * firstParagraph() const;
175 LyXCursor const & cursor(BufferView *) const;
177 bool isOpen() const { return !collapsed_; }
180 void open(BufferView *, bool);
183 void open(BufferView *);
185 void close(BufferView *);
188 string const selectNextWord(BufferView * bv, float & value) const {
189 return inset.selectNextWord(bv, value);
191 void selectSelectedWord(BufferView * bv) {
192 inset.selectSelectedWord(bv);
194 void toggleSelection(BufferView * bv, bool kill_selection) {
195 inset.toggleSelection(bv, kill_selection);
198 bool searchForward(BufferView * bv, string const & str,
199 bool const & cs = true, bool const & mw = false) {
200 return inset.searchForward(bv, str, cs, mw);
202 bool searchBackward(BufferView * bv, string const & str,
203 bool const & cs = true, bool const & mw = false) {
204 return inset.searchBackward(bv, str, cs, mw);
209 int ascent_collapsed() const;
211 int descent_collapsed() const;
213 int width_collapsed() const;
215 void draw_collapsed(Painter & pain, int , float &) const;
217 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
222 LColor::color framecolor;
231 string const get_new_label() const;
234 mutable int button_length;
236 mutable int button_top_y;
238 mutable int button_bottom_y;
244 mutable string draw_label;
251 mutable int oldWidth;
254 mutable int topbaseline;
255 mutable UpdateCodes need_update;
260 bool change_label_with_text;