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