- fix client positions a bit (still a bit ugly)
[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                 /* will be accounted when there's a client offset */
57         eSize m_client_offset;
58         eWidget *m_parent;
59         
60         ePtr<eWindowStyle> m_style;
61         
62         void doPaint(gPainter &painter, const gRegion &region);
63         void recalcClipRegionsWhenVisible();
64         
65         gRGB m_background_color;
66         int m_have_background_color;
67         
68         eWidget *m_current_focus, *m_focus_owner;
69 protected:
70         virtual ~eWidget();
71         void mayKillFocus();
72 public:
73
74                 // all in local space!
75         gRegion m_clip_region, m_visible_region, m_visible_with_childs;
76         
77         enum eWidgetEvent
78         {
79                 evtPaint,
80                 evtKey,
81                 evtChangedPosition,
82                 evtChangedSize,
83                 
84                 evtWillShow,
85                 evtWillHide,
86                 evtWillChangePosition, /* new size is eRect *data */
87                 evtWillChangeSize,
88                 
89                 evtAction,
90                 
91                 evtFocusGot,
92                 evtFocusLost,
93                 
94                 evtUserWidget,
95         };
96         virtual int event(int event, void *data = 0, void *data2 = 0);
97         void setFocus(eWidget *focus);
98 };
99
100 extern eWidgetDesktop *getDesktop();
101
102 #endif