8bd199f9d4a1548c47b85ee362c2374288e1b12e
[vuplus_dvbapp] / lib / gui / ewidget.h
1 #ifndef __lib_gui_ewidget_h
2 #define __lib_gui_ewidget_h
3
4 #include <lib/gdi/grc.h> /* for gRegion */
5 #include <lib/base/eptrlist.h> /* for eSmartPtrList */
6 #include <lib/gui/ewindowstyle.h> /* for eWindowStyle */
7
8 class eWidgetDesktop;class eWidgetDesktop;
9
10 class eWidget
11 {
12         friend class eWidgetDesktop;
13 public:
14         eWidget(eWidget *parent);
15         
16         void move(ePoint pos);
17         void resize(eSize size);
18         
19         ePoint position() const { return m_position; }
20         eSize size() const { return m_size; }
21
22         void invalidate(const gRegion &region = gRegion::invalidRegion());
23         
24                 /* the window were to attach childs to. Normally, this 
25                    is "this", but it can be overridden in case a widget
26                    has a "client area", which is implemented as a child
27                    widget. eWindow overrides this, for example. */
28         virtual eWidget *child() { return this; }
29
30         void show();
31         void hide();
32         
33         void destruct();
34         
35         int getStyle(ePtr<eWindowStyle> &style) { if (!m_style) return 1; style = m_style; return 0; }
36         void setStyle(eWindowStyle *style) { m_style = style; }
37         
38         void setBackgroundColor(const gRGB &col);
39         void clearBackgroundColor();
40         
41                 /* untested code */
42         int isVisible() { return (m_vis & wVisShow) && ((!m_parent) || m_parent->isVisible()); }
43                 /* ... */
44         
45 private:
46         eWidgetDesktop *m_desktop;
47
48         enum { 
49                 wVisShow = 1,
50                 wVisTransparent = 2,
51         };
52         
53         int m_vis;      
54
55         ePtrList<eWidget> m_childs;
56         ePoint m_position;
57         eSize m_size;
58                 /* will be accounted when there's a client offset */
59         eSize m_client_offset;
60         eWidget *m_parent;
61         
62         ePtr<eWindowStyle> m_style;
63         
64         void doPaint(gPainter &painter, const gRegion &region);
65         void recalcClipRegionsWhenVisible();
66         
67         gRGB m_background_color;
68         int m_have_background_color;
69         
70         eWidget *m_current_focus, *m_focus_owner;
71 protected:
72         virtual ~eWidget();
73         void mayKillFocus();
74 public:
75
76                 // all in local space!
77         gRegion m_clip_region, m_visible_region, m_visible_with_childs;
78         struct eWidgetDesktopCompBuffer *m_comp_buffer;
79         
80         enum eWidgetEvent
81         {
82                 evtPaint,
83                 evtKey,
84                 evtChangedPosition,
85                 evtChangedSize,
86                 
87                 evtWillShow,
88                 evtWillHide,
89                 evtWillChangePosition, /* new size is eRect *data */
90                 evtWillChangeSize,
91                 
92                 evtAction,
93                 
94                 evtFocusGot,
95                 evtFocusLost,
96                 
97                 evtUserWidget,
98         };
99         virtual int event(int event, void *data = 0, void *data2 = 0);
100         void setFocus(eWidget *focus);
101 };
102
103 extern eWidgetDesktop *getDesktop();
104
105 #endif