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, 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 bool 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;
108 int linuxdoc(Buffer const *, std::ostream &) const;
110 int docbook(Buffer const *, std::ostream &) const;
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; }
141 int getMaxWidth(BufferView *, UpdatableInset const *) const;
144 LyXText * getLyXText(BufferView const *, bool const recursive) const;
146 void deleteLyXText(BufferView *, bool recursive=true) const;
148 void resizeLyXText(BufferView *, bool force = false) const;
150 std::vector<string> const getLabelList() const;
154 int scroll(bool recursive=true) const;
156 void scroll(BufferView *bv, float sx) const {
157 UpdatableInset::scroll(bv, sx);
160 void scroll(BufferView *bv, int offset) const {
161 UpdatableInset::scroll(bv, offset);
164 Paragraph * getParFromID(int id) const;
166 Inset * getInsetFromID(int id) const;
168 Paragraph * firstParagraph() const;
170 Paragraph * getFirstParagraph(int) const;
172 LyXCursor const & cursor(BufferView *) const;
174 bool isOpen() const { return !collapsed_; }
176 void open(BufferView *);
178 void close(BufferView *) const;
180 bool allowSpellcheck() { return inset.allowSpellcheck(); }
181 string const selectNextWordToSpellcheck(BufferView *, float &) const;
183 void selectSelectedWord(BufferView * bv) {
184 inset.selectSelectedWord(bv);
186 void toggleSelection(BufferView * bv, bool kill_selection) {
187 inset.toggleSelection(bv, kill_selection);
190 bool searchForward(BufferView * bv, string const & str,
191 bool = true, bool = false);
192 bool searchBackward(BufferView * bv, string const & str,
193 bool = true, bool = 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;