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