aboutsummaryrefslogtreecommitdiff
path: root/lib/gui/ewidget.h
blob: 345977f225da2026fe40f7168c7dd75d577aeb0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef __lib_gui_ewidget_h
#define __lib_gui_ewidget_h

#include <lib/gdi/grc.h> /* for gRegion */
#include <lib/base/eptrlist.h> /* for eSmartPtrList */
#include <lib/gui/ewindowstyle.h> /* for eWindowStyle */

class eWidget
{
	friend class eWidgetDesktop;
public:
	eWidget(eWidget *parent);
	
	void move(ePoint pos);
	void resize(eSize size);
	
	ePoint position() const { return m_position; }
	eSize size() const { return m_size; }

	void invalidate(const gRegion &region = gRegion::invalidRegion());
	
		/* the window were to attach childs to. Normally, this 
		   is "this", but it can be overridden in case a widget
		   has a "client area", which is implemented as a child
		   widget. eWindow overrides this, for example. */
	virtual eWidget *child() { return this; }

	void show();
	void hide();
	
	void destruct();
	
	int getStyle(ePtr<eWindowStyle> &style) { if (!m_style) return 1; style = m_style; return 0; }
	void setStyle(eWindowStyle *style) { m_style = style; }
	
	void setBackgroundColor(const gRGB &col);
	void clearBackgroundColor();
	
		/* untested code */
	int isVisible() { return (m_vis & wVisShow) && ((!m_parent) || m_parent->isVisible()); }
		/* ... */
	
private:
	eWidgetDesktop *m_desktop;

	enum { 
		wVisShow = 1,
		wVisTransparent = 2,
	};
	
	int m_vis;	

	ePtrList<eWidget> m_childs;
	ePoint m_position;
	eSize m_size;
	eWidget *m_parent;
	
	ePtr<eWindowStyle> m_style;
	
	void doPaint(gPainter &painter, const gRegion &region);
	void recalcClipRegionsWhenVisible();
	
	gRGB m_background_color;
	int m_have_background_color;
	
	eWidget *m_current_focus, *m_focus_owner;
protected:
	virtual ~eWidget();
	void mayKillFocus();
public:

		// all in local space!
	gRegion	m_clip_region, m_visible_region, m_visible_with_childs;
	
	enum eWidgetEvent
	{
		evtPaint,
		evtKey,
		evtChangedPosition,
		evtChangedSize,
		
		evtWillShow,
		evtWillHide,
		evtWillChangePosition, /* new size is eRect *data */
		evtWillChangeSize,
		
		evtAction,
		
		evtFocusGot,
		evtFocusLost,
		
		evtUserWidget,
	};
	virtual int event(int event, void *data = 0, void *data2 = 0);
	void setFocus(eWidget *focus);
};

extern eWidgetDesktop *getDesktop();

#endif