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 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, unsigned int);
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 unsigned int insetInInsetY();
92 void insetButtonRelease(BufferView *, int, int, int);
94 void insetButtonPress(BufferView *, int, int, int);
96 void insetMotionNotify(BufferView *, int, int, int);
98 void insetKeyPress(XKeyEvent *);
100 UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
103 int latex(Buffer const *, std::ostream &,
104 bool fragile, bool free_spc) const;
106 int ascii(Buffer const *, std::ostream &, int) const { return 0; }
108 int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
110 int docbook(Buffer const *, std::ostream &) const { return 0; }
112 void validate(LaTeXFeatures & features) const;
114 void getCursorPos(BufferView *, int & x, int & y) const;
116 void toggleInsetCursor(BufferView *);
118 void showInsetCursor(BufferView *, bool show = true);
120 void hideInsetCursor(BufferView *);
122 void fitInsetCursor(BufferView * bv) const {
123 inset.fitInsetCursor(bv);
125 UpdatableInset * getLockingInset() const;
127 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
129 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
130 bool selectall = false);
132 void setLabel(string const & l) const;
134 void setLabelFont(LyXFont & f) { labelfont = f; }
137 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 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 string const selectNextWord(BufferView * bv, float & value) const;
180 void selectSelectedWord(BufferView * bv) {
181 inset.selectSelectedWord(bv);
183 void toggleSelection(BufferView * bv, bool kill_selection) {
184 inset.toggleSelection(bv, kill_selection);
187 bool searchForward(BufferView * bv, string const & str,
188 bool const & cs = true, bool const & mw = false);
189 bool searchBackward(BufferView * bv, string const & str,
190 bool const & cs = true, bool const & mw = false);
191 /// check if the font of the char we want inserting is correct
192 /// and modify it if it is not.
193 virtual bool checkInsertChar(LyXFont &) { return false; }
197 int ascent_collapsed() const;
199 int descent_collapsed() const;
201 int width_collapsed() const;
203 void draw_collapsed(Painter & pain, int , float &) const;
205 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
208 mutable bool collapsed_;
210 LColor::color framecolor;
215 mutable InsetText inset;
218 mutable int button_length;
220 mutable int button_top_y;
222 mutable int button_bottom_y;
225 mutable int topbaseline;
226 mutable UpdateCodes need_update;
230 mutable string label;
236 mutable int oldWidth;
240 mutable bool first_after_edit;