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 void read(Buffer const *, LyXLex &);
49 void write(Buffer const *, std::ostream &) const;
51 int ascent(BufferView *, LyXFont const &) const;
53 int descent(BufferView *, LyXFont const &) const;
55 int width(BufferView *, LyXFont const & f) const;
57 void draw(BufferView *, const LyXFont &, int , float &, bool) const;
59 void update(BufferView *, LyXFont const &, bool =false);
61 void edit(BufferView *, int, int, unsigned int);
63 void edit(BufferView *, bool front = true);
65 EDITABLE editable() const;
67 bool insertInset(BufferView *, Inset * inset);
69 bool insetAllowed(Inset::Code code) const {
70 return inset.insetAllowed(code);
73 bool isTextInset() const { return true; }
75 bool doClearArea() const;
77 void insetUnlock(BufferView *);
79 bool needFullRow() const { return !collapsed_; }
81 bool lockInsetInInset(BufferView *, UpdatableInset *);
83 bool unlockInsetInInset(BufferView *, UpdatableInset *,
86 bool updateInsetInInset(BufferView *, Inset *);
88 unsigned int insetInInsetY();
90 void insetButtonRelease(BufferView *, int, int, int);
92 void insetButtonPress(BufferView *, int, int, int);
94 void insetMotionNotify(BufferView *, int, int, int);
96 void insetKeyPress(XKeyEvent *);
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 { return 0; }
106 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
108 int docBook(Buffer const *, std::ostream &) const { return 0; }
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, bool flag = false);
132 void setLabelFont(LyXFont & f) { labelfont = f; }
134 void setAutoCollapse(bool f) { autocollapse = f; }
136 int getMaxWidth(BufferView *, UpdatableInset const *) const;
138 LyXText * getLyXText(BufferView const *, bool const recursive) const;
140 void deleteLyXText(BufferView *, bool recursive=true) const;
142 void resizeLyXText(BufferView *, bool force = false) const;
144 std::vector<string> const getLabelList() const;
148 int scroll(bool recursive=true) const;
150 void scroll(BufferView *bv, float sx) const {
151 UpdatableInset::scroll(bv, sx);
154 void scroll(BufferView *bv, int offset) const {
155 UpdatableInset::scroll(bv, offset);
158 Paragraph * getParFromID(int id) const;
160 Inset * getInsetFromID(int id) const;
162 Paragraph * firstParagraph() const;
164 LyXCursor const & cursor(BufferView *) const;
166 bool isOpen() const { return !collapsed_; }
167 void open(BufferView *, bool);
169 string selectNextWord(BufferView * bv, float & value) const {
170 return inset.selectNextWord(bv, value);
172 void selectSelectedWord(BufferView * bv) {
173 inset.selectSelectedWord(bv);
175 void toggleSelection(BufferView * bv, bool kill_selection) {
176 inset.toggleSelection(bv, kill_selection);
179 bool searchForward(BufferView * bv, string const & str,
180 bool const & cs = true, bool const & mw = false) {
181 return inset.searchForward(bv, str, cs, mw);
183 bool searchBackward(BufferView * bv, string const & str,
184 bool const & cs = true, bool const & mw = false) {
185 return inset.searchBackward(bv, str, cs, mw);
190 int ascent_collapsed(Painter &, LyXFont const &) const;
192 int descent_collapsed(Painter &, LyXFont const &) const;
194 int width_collapsed(Painter &, LyXFont const & f) const;
196 void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
198 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
203 LColor::color framecolor;
211 string get_new_label() const;
214 mutable int button_length;
216 mutable int button_top_y;
218 mutable int button_bottom_y;
223 mutable string draw_label;
227 mutable int widthCollapsed;
229 mutable int oldWidth;
232 mutable int topbaseline;
233 mutable UpdateCodes need_update;
237 bool change_label_with_text;