]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
some reindentation, revert workarea xpos++, constify, remove all traces of LyXParagra...
[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 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 "lyxinset.h"
21 #include "insettext.h"
22 #include "lyxfont.h"
23 #include "LColor.h"
24
25 class Painter;
26 class LyXText;
27
28 /** A colapsable text inset
29   
30 */
31 class InsetCollapsable : public UpdatableInset {
32 public:
33         ///
34         enum UpdateCodes {
35                 NONE = 0,
36                 FULL
37         };
38         ///
39         static int const TEXT_TO_TOP_OFFSET = 2;
40         ///
41         static int const TEXT_TO_BOTTOM_OFFSET = 2;
42         ///
43         InsetCollapsable();
44         ///
45         void Read(Buffer const *, LyXLex &);
46         ///
47         void Write(Buffer const *, std::ostream &) const;
48         ///
49         int ascent(BufferView *, LyXFont const &) const;
50         ///
51         int descent(BufferView *, LyXFont const &) const;
52         ///
53         int width(BufferView *, LyXFont const & f) const;
54         ///
55         void draw(BufferView *, const LyXFont &, int , float &, bool) const;
56         ///
57         void update(BufferView *, LyXFont const &, bool =false); 
58         ///
59         void Edit(BufferView *, int, int, unsigned int);
60         ///
61         EDITABLE Editable() const;
62         ///
63         bool InsertInset(BufferView *, Inset * inset);
64         ///
65         bool IsTextInset() const { return true; }
66         ///
67         bool doClearArea() const;
68         ///
69         void InsetUnlock(BufferView *);
70         ///
71         bool needFullRow() const { return !collapsed; }
72         ///
73         bool LockInsetInInset(BufferView *, UpdatableInset *);
74         ///
75         bool UnlockInsetInInset(BufferView *, UpdatableInset *,
76                                 bool lr = false);
77         ///
78         bool UpdateInsetInInset(BufferView *, Inset *);
79         ///
80         unsigned int InsetInInsetY();
81         ///
82         void InsetButtonRelease(BufferView *, int, int, int);
83         ///
84         void InsetButtonPress(BufferView *, int, int, int);
85         ///
86         void InsetMotionNotify(BufferView *, int, int, int);
87         ///
88         void InsetKeyPress(XKeyEvent *);
89         ///
90         UpdatableInset::RESULT LocalDispatch(BufferView *, kb_action,
91                                              string const &);
92         ///
93         int Latex(Buffer const *, std::ostream &,
94                   bool fragile, bool free_spc) const;
95         ///
96         int Ascii(Buffer const *, std::ostream &, int) const { return 0; }
97         ///
98         int Linuxdoc(Buffer const *, std::ostream &) const { return 0; }
99         ///
100         int DocBook(Buffer const *, std::ostream &) const { return 0; }
101         ///
102         void Validate(LaTeXFeatures & features) const;
103         ///
104         void GetCursorPos(BufferView *, int & x, int & y) const;
105         ///
106         void ToggleInsetCursor(BufferView *);
107         ///
108         UpdatableInset * GetLockingInset();
109         ///
110         UpdatableInset * GetFirstLockingInsetOfType(Inset::Code);
111         ///
112         void SetFont(BufferView *, LyXFont const &, bool toggleall = false);
113         ///
114         void setLabel(string const & l) { label = l; }
115         ///
116         void setLabelFont(LyXFont & f) { labelfont = f; }
117         ///
118         void setAutoCollapse(bool f) { autocollapse = f; }
119         ///
120         int getMaxWidth(BufferView *, UpdatableInset const *) const;
121         ///
122         LyXText * getLyXText(BufferView const *, bool const recursive) const;
123         ///
124         void deleteLyXText(BufferView *, bool recursive=true) const;
125         ///
126         void resizeLyXText(BufferView *) const;
127         ///
128         std::vector<string> const getLabelList() const;
129         ///
130         bool nodraw() const;
131         ///
132         int scroll(bool recursive=true) const;
133         ///
134         void scroll(BufferView *bv, float sx) const {
135                 UpdatableInset::scroll(bv, sx);
136         }
137         ///
138         void scroll(BufferView *bv, int offset) const {
139                 UpdatableInset::scroll(bv, offset);
140         }
141
142 protected:
143         ///
144         int ascent_collapsed(Painter &, LyXFont const &) const;
145         ///
146         int descent_collapsed(Painter &, LyXFont const &) const;
147         ///
148         int width_collapsed(Painter &, LyXFont const & f) const;
149         ///
150         void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
151         ///
152         int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
153         
154         ///
155         bool collapsed;
156         ///
157         LColor::color framecolor;
158         ///
159         LyXFont labelfont;
160 public:
161         ///
162         InsetText inset;
163 protected:
164         ///
165         mutable int button_length;
166         ///
167         mutable int button_top_y;
168         ///
169         mutable int button_bottom_y;
170 private:
171         ///
172         string label;
173         ///
174         bool autocollapse;
175         ///
176         int widthCollapsed;
177         ///
178         mutable int oldWidth;
179         ///
180         mutable int topx;
181         mutable int topbaseline;
182         mutable UpdateCodes need_update;
183 };
184
185 #endif