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