]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
The BIG UNDO patch. Recodes undo handling for better use inside InsetText.
[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         EDITABLE editable() const;
64         ///
65         bool insertInset(BufferView *, Inset * inset);
66         ///
67         bool isTextInset() const { return true; }
68         ///
69         bool doClearArea() const;
70         ///
71         void insetUnlock(BufferView *);
72         ///
73         bool needFullRow() const { return !collapsed; }
74         ///
75         bool lockInsetInInset(BufferView *, UpdatableInset *);
76         ///
77         bool unlockInsetInInset(BufferView *, UpdatableInset *,
78                                 bool lr = false);
79         ///
80         bool updateInsetInInset(BufferView *, Inset *);
81         ///
82         unsigned int insetInInsetY();
83         ///
84         void insetButtonRelease(BufferView *, int, int, int);
85         ///
86         void insetButtonPress(BufferView *, int, int, int);
87         ///
88         void insetMotionNotify(BufferView *, int, int, int);
89         ///
90         void insetKeyPress(XKeyEvent *);
91         ///
92         UpdatableInset::RESULT localDispatch(BufferView *, kb_action,
93                                              string const &);
94         ///
95         int latex(Buffer const *, std::ostream &,
96                   bool fragile, bool free_spc) const;
97         ///
98         int ascii(Buffer const *, std::ostream &, int) const { return 0; }
99         ///
100         int linuxdoc(Buffer const *, std::ostream &) const { return 0; }
101         ///
102         int docBook(Buffer const *, std::ostream &) const { return 0; }
103         ///
104         void validate(LaTeXFeatures & features) const;
105         ///
106         void getCursorPos(BufferView *, int & x, int & y) const;
107         ///
108         void toggleInsetCursor(BufferView *);
109         ///
110         UpdatableInset * getLockingInset();
111         ///
112         UpdatableInset * getFirstLockingInsetOfType(Inset::Code);
113         ///
114         void setFont(BufferView *, LyXFont const &, bool toggleall = false,
115                  bool selectall = false);
116         ///
117         void setLabel(string const & l) { label = l; }
118         ///
119         void setLabelFont(LyXFont & f) { labelfont = f; }
120         ///
121         void setAutoCollapse(bool f) { autocollapse = f; }
122         ///
123         int getMaxWidth(BufferView *, UpdatableInset const *) const;
124         ///
125         LyXText * getLyXText(BufferView const *, bool const recursive) const;
126         ///
127         void deleteLyXText(BufferView *, bool recursive=true) const;
128         ///
129         void resizeLyXText(BufferView *, bool force = false) const;
130         ///
131         std::vector<string> const getLabelList() const;
132         ///
133         bool nodraw() const;
134         ///
135         int scroll(bool recursive=true) const;
136         ///
137         void scroll(BufferView *bv, float sx) const {
138                 UpdatableInset::scroll(bv, sx);
139         }
140         ///
141         void scroll(BufferView *bv, int offset) const {
142                 UpdatableInset::scroll(bv, offset);
143         }
144         ///
145         Paragraph * getParFromID(int id) const;
146         ///
147         Inset * getInsetFromID(int id) const;
148         ///
149         Paragraph * firstParagraph() const;
150         ///
151         LyXCursor const & cursor(BufferView *) const;
152
153 protected:
154         ///
155         int ascent_collapsed(Painter &, LyXFont const &) const;
156         ///
157         int descent_collapsed(Painter &, LyXFont const &) const;
158         ///
159         int width_collapsed(Painter &, LyXFont const & f) const;
160         ///
161         void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
162         ///
163         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
164         
165         ///
166         bool collapsed;
167         ///
168         LColor::color framecolor;
169         ///
170         LyXFont labelfont;
171 public:
172         ///
173         InsetText inset;
174 protected:
175         ///
176         mutable int button_length;
177         ///
178         mutable int button_top_y;
179         ///
180         mutable int button_bottom_y;
181 private:
182         ///
183         string label;
184         ///
185         bool autocollapse;
186         ///
187         int widthCollapsed;
188         ///
189         mutable int oldWidth;
190         ///
191         mutable int topx;
192         mutable int topbaseline;
193         mutable UpdateCodes need_update;
194 };
195
196 #endif