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, mouse_button::state);
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 int insetInInsetY() const;
92 RESULT localDispatch(FuncRequest const &);
94 int latex(Buffer const *, std::ostream &,
95 bool fragile, bool free_spc) const;
97 int ascii(Buffer const *, std::ostream &, int) const;
99 int linuxdoc(Buffer const *, std::ostream &) const;
101 int docbook(Buffer const *, std::ostream &, bool mixcont) const;
103 void validate(LaTeXFeatures & features) const;
105 void getCursorPos(BufferView *, int & x, int & y) const;
107 void toggleInsetCursor(BufferView *);
109 void showInsetCursor(BufferView *, bool show = true);
111 void hideInsetCursor(BufferView *);
113 void fitInsetCursor(BufferView * bv) const {
114 inset.fitInsetCursor(bv);
116 UpdatableInset * getLockingInset() const;
118 UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
120 void setFont(BufferView *, LyXFont const &, bool toggleall = false,
121 bool selectall = false);
123 void setLabel(string const & l) const;
125 void setLabelFont(LyXFont & f) { labelfont = f; }
128 void setAutoCollapse(bool f) { autocollapse = f; }
132 int getMaxWidth(BufferView *, UpdatableInset const *) const;
135 LyXText * getLyXText(BufferView const *, bool const recursive) const;
137 void deleteLyXText(BufferView *, bool recursive=true) const;
139 void resizeLyXText(BufferView *, bool force = false) const;
141 std::vector<string> const getLabelList() const;
145 int scroll(bool recursive=true) const;
147 void scroll(BufferView *bv, float sx) const {
148 UpdatableInset::scroll(bv, sx);
151 void scroll(BufferView *bv, int offset) const {
152 UpdatableInset::scroll(bv, offset);
155 Paragraph * getParFromID(int id) const;
157 Inset * getInsetFromID(int id) const;
159 Paragraph * firstParagraph() const;
161 Paragraph * getFirstParagraph(int) const;
163 LyXCursor const & cursor(BufferView *) const;
165 bool isOpen() const { return !collapsed_; }
167 void open(BufferView *);
169 void close(BufferView *) const;
171 bool allowSpellcheck() { return inset.allowSpellcheck(); }
174 selectNextWordToSpellcheck(BufferView *, float &) const;
176 void selectSelectedWord(BufferView * bv) {
177 inset.selectSelectedWord(bv);
180 void toggleSelection(BufferView * bv, bool kill_selection) {
181 inset.toggleSelection(bv, kill_selection);
184 bool searchForward(BufferView * bv, string const & str,
185 bool = true, bool = false);
186 bool searchBackward(BufferView * bv, string const & str,
187 bool = true, bool = false);
190 void addPreview(grfx::PreviewLoader &) const;
194 int ascent_collapsed() const;
196 int descent_collapsed() const;
198 int width_collapsed() const;
200 void draw_collapsed(Painter & pain, int , float &) const;
202 int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
205 mutable bool collapsed_;
207 LColor::color framecolor;
212 mutable InsetText inset;
215 mutable int button_length;
217 mutable int button_top_y;
219 mutable int button_bottom_y;
222 mutable int topbaseline;
223 mutable UpdateCodes need_update;
227 void lfunMousePress(FuncRequest const &);
229 bool lfunMouseRelease(FuncRequest const &);
231 void lfunMouseMotion(FuncRequest const &);
234 mutable string label;
240 mutable int oldWidth;
244 mutable bool first_after_edit;