Merge branch 'WirelessLanSetup' into vuplus_experimental
[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 #include <lib/gui/ewidgetanimation.h>
8
9 #define MAX_LAYER 16
10
11 class eWidgetDesktop;class eWidgetDesktop;
12
13 class eWidget
14 {
15         friend class eWidgetDesktop;
16 public:
17         eWidget(eWidget *parent);
18         virtual ~eWidget();
19
20         void move(ePoint pos);
21         void resize(eSize size);
22         
23         ePoint position() const { return m_position; }
24         eSize size() const { return m_size; }
25         eSize csize() const { return m_client_size; }
26
27         void invalidate(const gRegion &region = gRegion::invalidRegion());
28         
29                 /* the window were to attach childs to. Normally, this 
30                    is "this", but it can be overridden in case a widget
31                    has a "client area", which is implemented as a child
32                    widget. eWindow overrides this, for example. */
33         virtual eWidget *child() { return this; }
34
35         void show();
36         void hide();
37         
38         void destruct();
39         
40         SWIG_VOID(int) getStyle(ePtr<eWindowStyle> &SWIG_NAMED_OUTPUT(style)) { if (!m_style) return 1; style = m_style; return 0; }
41         void setStyle(eWindowStyle *style) { m_style = style; }
42         
43         void setBackgroundColor(const gRGB &col);
44         void clearBackgroundColor();
45         
46         void setZPosition(int z);
47         void setTransparent(int transp);
48         
49                 /* untested code */
50         int isVisible() { return (m_vis & wVisShow) && ((!m_parent) || m_parent->isVisible()); }
51                 /* ... */
52                 
53         int isTransparent() { return m_vis & wVisTransparent; }
54         
55         ePoint getAbsolutePosition();
56         
57         eWidgetAnimation m_animation;
58 private:
59         eWidgetDesktop *m_desktop;
60
61         enum { 
62                 wVisShow = 1,
63                 wVisTransparent = 2,
64         };
65         
66         int m_vis;      
67
68         int m_layer;
69
70         ePtrList<eWidget> m_childs;
71         ePoint m_position;
72         eSize m_size, m_client_size;
73                 /* will be accounted when there's a client offset */
74         eSize m_client_offset;
75         eWidget *m_parent;
76         
77         ePtr<eWindowStyle> m_style;
78         
79         void insertIntoParent();
80         void doPaint(gPainter &painter, const gRegion &region, int layer);
81         void recalcClipRegionsWhenVisible();
82         
83         void parentRemoved();
84         
85         gRGB m_background_color;
86         int m_have_background_color;
87         
88         eWidget *m_current_focus, *m_focus_owner;
89         
90         int m_z_position;
91         int m_notify_child_on_position_change;
92 protected:
93         void mayKillFocus();
94 public:
95
96                 // all in local space!
97         gRegion m_clip_region, m_visible_region, m_visible_with_childs;
98         struct eWidgetDesktopCompBuffer *m_comp_buffer[MAX_LAYER];
99         
100         enum eWidgetEvent
101         {
102                 evtPaint,
103                 evtKey,
104                 evtChangedPosition,
105                 evtChangedSize,
106                 
107                 evtParentChangedPosition,
108                 
109                 evtParentVisibilityChanged,
110                 evtWillChangePosition, /* new size is eRect *data */
111                 evtWillChangeSize,
112                 
113                 evtAction,
114                 
115                 evtFocusGot,
116                 evtFocusLost,
117                 
118                 evtUserWidget,
119         };
120         virtual int event(int event, void *data = 0, void *data2 = 0);
121         void setFocus(eWidget *focus);
122
123                 /* enable this if you need the absolute position of the widget */
124         void setPositionNotifyChild(int n) { m_notify_child_on_position_change = 1; }
125
126         void notifyShowHide();
127 };
128
129 extern eWidgetDesktop *getDesktop(int which);
130
131 #endif