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);
134 void setLabel(string const & l, bool flag = false);
136 void setLabelFont(LyXFont & f) { labelfont = f; }
138 void setAutoCollapse(bool f) { autocollapse = f; }
140 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 LyXCursor const & cursor(BufferView *) const;
170 bool isOpen() const { return !collapsed_; }
171 void open(BufferView *, bool);
173 string selectNextWord(BufferView * bv, float & value) const {
174 return inset.selectNextWord(bv, value);
176 void selectSelectedWord(BufferView * bv) {
177 inset.selectSelectedWord(bv);
179 void toggleSelection(BufferView * bv, bool kill_selection) {
180 inset.toggleSelection(bv, kill_selection);
183 bool searchForward(BufferView * bv, string const & str,
184 bool const & cs = true, bool const & mw = false) {
185 return inset.searchForward(bv, str, cs, mw);
187 bool searchBackward(BufferView * bv, string const & str,
188 bool const & cs = true, bool const & mw = false) {
189 return inset.searchBackward(bv, str, cs, mw);
194 int ascent_collapsed(Painter &) const;
196 int descent_collapsed(Painter &) const;
198 int width_collapsed(Painter &) const;
200 void draw_collapsed(Painter & pain, int , float &) const;
202 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
207 LColor::color framecolor;
215 string get_new_label() const;
218 mutable int button_length;
220 mutable int button_top_y;
222 mutable int button_bottom_y;
227 mutable string draw_label;
231 mutable int oldWidth;
234 mutable int topbaseline;
235 mutable UpdateCodes need_update;
239 bool change_label_with_text;