]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Implemented Search/Replace functionality for Insets. Cleaned up a bit.
[lyx.git] / src / insets / insetcollapsable.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2000-2001 The LyX Team.
8  *
9  *======================================================
10  */
11
12
13 #ifndef INSETCOLLAPSABLE_H
14 #define INSETCOLLAPSABLE_H
15
16 #ifdef __GNUG__
17 #pragma interface
18 #endif
19
20 #include "inset.h"
21 #include "insettext.h"
22 #include "lyxfont.h"
23 #include "LColor.h"
24
25 class Painter;
26 class LyXText;
27 class Paragraph;
28 class LyXCursor;
29
30 /** A colapsable text inset
31   
32 */
33 class InsetCollapsable : public UpdatableInset {
34 public:
35         ///
36         enum UpdateCodes {
37                 NONE = 0,
38                 FULL
39         };
40         ///
41         static int const TEXT_TO_TOP_OFFSET = 2;
42         ///
43         static int const TEXT_TO_BOTTOM_OFFSET = 2;
44         ///
45         InsetCollapsable();
46         ///
47         void read(Buffer const *, LyXLex &);
48         ///
49         void write(Buffer const *, std::ostream &) const;
50         ///
51         int ascent(BufferView *, LyXFont const &) const;
52         ///
53         int descent(BufferView *, LyXFont const &) const;
54         ///
55         int width(BufferView *, LyXFont const & f) const;
56         ///
57         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
58         ///
59         void update(BufferView *, LyXFont const &, bool =false); 
60         ///
61         void edit(BufferView *, int, int, unsigned int);
62         ///
63         void edit(BufferView *, bool front = true);
64         ///
65         EDITABLE editable() const;
66         ///
67         bool insertInset(BufferView *, Inset * inset);
68         ///
69         bool insetAllowed(Inset::Code code) const {
70                 return inset.insetAllowed(code);
71         }
72         ///
73         bool isTextInset() const { return true; }
74         ///
75         bool doClearArea() const;
76         ///
77         void insetUnlock(BufferView *);
78         ///
79         bool needFullRow() const { return !collapsed_; }
80         ///
81         bool lockInsetInInset(BufferView *, UpdatableInset *);
82         ///
83         bool unlockInsetInInset(BufferView *, UpdatableInset *,
84                                 bool lr = false);
85         ///
86         bool updateInsetInInset(BufferView *, Inset *);
87         ///
88         unsigned int insetInInsetY();
89         ///
90         void insetButtonRelease(BufferView *, int, int, int);
91         ///
92         void insetButtonPress(BufferView *, int, int, int);
93         ///
94         void insetMotionNotify(BufferView *, int, int, int);
95         ///
96         void insetKeyPress(XKeyEvent *);
97         ///
98         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
99                                              string const &);
100         ///
101         int latex(Buffer const *, std::ostream &,
102                   bool fragile, bool free_spc) const;
103         ///
104         int ascii(Buffer const *, std::ostream &, int) const { return 0; }
105         ///
106         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
107         ///
108         int docBook(Buffer const *, std::ostream &) const { return 0; }
109         ///
110         void validate(LaTeXFeatures & features) const;
111         ///
112         void getCursorPos(BufferView *, int & x, int & y) const;
113         ///
114         void toggleInsetCursor(BufferView *);
115         ///
116         void showInsetCursor(BufferView *, bool show = true);
117         ///
118         void hideInsetCursor(BufferView *);
119         ///
120         void fitInsetCursor(BufferView * bv) const {
121                 inset.fitInsetCursor(bv);
122         }
123         UpdatableInset * getLockingInset() const;
124         ///
125         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
126         ///
127         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
128                  bool selectall = false);
129         ///
130         void setLabel(string const & l) { label = l; }
131         ///
132         void setLabelFont(LyXFont & f) { labelfont = f; }
133         ///
134         void setAutoCollapse(bool f) { autocollapse = f; }
135         ///
136         int getMaxWidth(BufferView *, UpdatableInset const *) const;
137         ///
138         LyXText * getLyXText(BufferView const *, bool const recursive) const;
139         ///
140         void deleteLyXText(BufferView *, bool recursive=true) const;
141         ///
142         void resizeLyXText(BufferView *, bool force = false) const;
143         ///
144         std::vector<string> const getLabelList() const;
145         ///
146         bool nodraw() const;
147         ///
148         int scroll(bool recursive=true) const;
149         ///
150         void scroll(BufferView *bv, float sx) const {
151                 UpdatableInset::scroll(bv, sx);
152         }
153         ///
154         void scroll(BufferView *bv, int offset) const {
155                 UpdatableInset::scroll(bv, offset);
156         }
157         ///
158         Paragraph * getParFromID(int id) const;
159         ///
160         Inset * getInsetFromID(int id) const;
161         ///
162         Paragraph * firstParagraph() const;
163         ///
164         LyXCursor const & cursor(BufferView *) const;
165         ///
166         bool isOpen() const { return !collapsed_; }
167         void open(BufferView *, bool);
168         ///
169         string selectNextWord(BufferView * bv, float & value) const {
170                 return inset.selectNextWord(bv, value);
171         }
172         void selectSelectedWord(BufferView * bv) {
173                 inset.selectSelectedWord(bv);
174         }
175         void toggleSelection(BufferView * bv, bool kill_selection) {
176                 inset.toggleSelection(bv, kill_selection);
177         }
178         ///
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);
182         }
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);
186         }
187
188 protected:
189         ///
190         int ascent_collapsed(Painter &, LyXFont const &) const;
191         ///
192         int descent_collapsed(Painter &, LyXFont const &) const;
193         ///
194         int width_collapsed(Painter &, LyXFont const & f) const;
195         ///
196         void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
197         ///
198         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
199         
200         ///
201         bool collapsed_;
202         ///
203         LColor::color framecolor;
204         ///
205         LyXFont labelfont;
206 public:
207         ///
208         InsetText inset;
209 protected:
210         ///
211         mutable int button_length;
212         ///
213         mutable int button_top_y;
214         ///
215         mutable int button_bottom_y;
216 private:
217         ///
218         string label;
219         ///
220         bool autocollapse;
221         ///
222         int widthCollapsed;
223         ///
224         mutable int oldWidth;
225         ///
226         mutable int topx;
227         mutable int topbaseline;
228         mutable UpdateCodes need_update;
229 };
230
231 #endif