]> git.lyx.org Git - lyx.git/blob - src/insets/insetcollapsable.h
Fixed inset-redraw problems on resizing lyx-window, and some other small
[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 "lyxfont.h"
22 #include "LColor.h"
23
24
25 class Painter;
26 class InsetText;
27 class LyXText;
28
29 /** A colapsable text inset
30   
31 */
32 class InsetCollapsable : public UpdatableInset {
33 public:
34     ///
35     enum UpdateCodes {
36         NONE = 0,
37         FULL
38     };
39     ///
40     static int const TEXT_TO_TOP_OFFSET = 2;
41     ///
42     static int const TEXT_TO_BOTTOM_OFFSET = 2;
43     ///
44     InsetCollapsable();
45     ///
46     Inset * Clone() const;
47     ///
48     void Read(Buffer const *, LyXLex &);
49     ///
50     void Write(Buffer const *, std::ostream &) const;
51     ///
52     int ascent(BufferView *, LyXFont const &) const;
53     ///
54     int descent(BufferView *, LyXFont const &) const;
55     ///
56     int width(BufferView *, LyXFont const & f) const;
57     ///
58     void draw(BufferView *, const LyXFont &, int , float &, bool) const;
59     ///
60     void update(BufferView *, LyXFont const &, bool =false); 
61     ///
62     void Edit(BufferView *, int, int, unsigned int);
63     ///
64     EDITABLE Editable() const;
65     ///
66     bool InsertInset(BufferView *, Inset * inset);
67     ///
68     bool IsTextInset() const { return true; }
69     ///
70     bool doClearArea() const;
71     ///
72     void InsetUnlock(BufferView *);
73     ///
74     bool needFullRow() const { return !collapsed; }
75     ///
76     bool LockInsetInInset(BufferView *, UpdatableInset *);
77     ///
78     bool UnlockInsetInInset(BufferView *, UpdatableInset *, bool lr = false);
79     ///
80     bool UpdateInsetInInset(BufferView *, Inset *);
81     ///
82     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 *, int, string const &);
93     ///
94     int Latex(Buffer const *, std::ostream &, bool fragile, bool free_spc) const;
95     ///
96     int Ascii(Buffer const *, std::ostream &) 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(Painter & pain, UpdatableInset const *) const;
121     ///
122     LyXText * getLyXText(BufferView *) const;
123     void deleteLyXText(BufferView *, bool recursive=true) const;
124     void resizeLyXText(BufferView *) const;
125
126 protected:
127     ///
128     int ascent_collapsed(Painter &, LyXFont const &) const;
129     ///
130     int descent_collapsed(Painter &, LyXFont const &) const;
131     ///
132     int width_collapsed(Painter &, LyXFont const & f) const;
133     ///
134     void draw_collapsed(Painter & pain, const LyXFont &, int , float &) const;
135     ///
136     int getMaxTextWidth(Painter & pain, UpdatableInset const *) const;
137     
138     ///
139     bool collapsed;
140     ///
141     LColor::color framecolor;
142     ///
143     LyXFont labelfont;
144     ///
145     InsetText * inset;
146     // Instead of making these ints protected we could have a
147     // protected method "clickInButton" (Lgb)
148     ///
149     mutable int
150         button_length, button_top_y, button_bottom_y;
151
152 private:
153     ///
154     string label;
155     ///
156     bool autocollapse;
157     ///
158     int widthCollapsed;
159     ///
160     mutable int oldWidth;
161     ///
162     mutable int topx;
163     mutable int topbaseline;
164     mutable UpdateCodes need_update;
165 };
166
167 #endif