PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/platform/win/controls/oslistbox.d

http://github.com/wilkie/djehuty
D | 91 lines | 70 code | 20 blank | 1 comment | 1 complexity | d1be01b551d92ef6bc8cf0fe3f685d20 MD5 | raw file
 1module platform.win.controls.oslistbox;
 2
 3import gui.listbox;
 4import core.string;
 5
 6import platform.win.definitions;
 7import platform.win.vars;
 8import platform.win.common;
 9import platform.win.oscontrolinterface;
10
11import platform.win.main;
12import core.view;
13import gui.widget;
14import gui.window;
15
16import interfaces.list;
17
18class OSListBox : ListBox, OSControl
19{
20public:
21
22	this(int x, int y, int width, int height, AbstractList!(String) list = null)
23	{
24		super(x,y,width,height,list);
25	}
26
27	override void OnAdd()
28	{
29	   _hWnd = CreateWindowExW(0, "LISTBOX\0", null, WS_CHILD | WS_VISIBLE | LBS_NOINTEGRALHEIGHT | WS_BORDER | WS_VSCROLL , _x,_y,_width,_height,
30			WindowGetPlatformVars(_window).hWnd,null, cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
31
32		SetWindowPos(_hWnd, cast(HWND)HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
33
34		SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
35		_oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
36
37		SendMessageW( _hWnd, WM_SETFONT, cast(WPARAM)win_button_font, 1);
38
39		// Add all members of the list
40		Iterator irate = getIterator();
41
42		String data;
43		while(getItem(data, irate))
44		{
45			SendMessageW(_hWnd, LB_ADDSTRING, 0, cast(LPARAM)data.ptr);
46		}
47	}
48
49	override void OnRemove()
50	{
51		DestroyWindow(_hWnd);
52	}
53
54	override void addItem(String text)
55	{
56		super.addItem(text);
57		SendMessageW(_hWnd, LB_ADDSTRING, 0, cast(LPARAM)text.ptr);
58	}
59
60	override void addItem(StringLiteral text)
61	{
62		super.addItem(text);
63		SendMessageW(_hWnd, LB_ADDSTRING, 0, cast(LPARAM)text.ptr);
64	}
65
66protected:
67
68	LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
69	{
70		switch (message)
71		{
72			break;
73		default:
74			break;
75		}
76
77		return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
78	}
79
80	View _ReturnView(out int x, out int y, out int w, out int h)
81	{
82		x = _x;
83		y = _y;
84		w = _width;
85		h = _height;
86		return _view;
87	}
88
89	HWND _hWnd;
90	WNDPROC _oldproc;
91}