PageRenderTime 63ms CodeModel.GetById 55ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/platform/win/controls/osprogressbar.d

http://github.com/wilkie/djehuty
D | 81 lines | 62 code | 18 blank | 1 comment | 3 complexity | db2175a0f4f5b312f6098eadb8fcd960 MD5 | raw file
 1module platform.win.controls.osprogressbar;
 2
 3import gui.progressbar;
 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
16class OSProgressBar : ProgressBar, OSControl
17{
18public:
19	this(int x, int y, int width, int height)
20	{
21		super(x,y,width,height);
22	}
23
24	override void OnAdd()
25	{
26		 _hWnd = CreateWindowExW(0,
27			"msctls_progress32\0", null, WS_CHILD | WS_VISIBLE , _x,_y,_width,_height,
28			WindowGetPlatformVars(_window).hWnd,null, cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
29
30		SetWindowPos(_hWnd, cast(HWND)HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
31
32		SendMessageW(_hWnd, PBM_SETRANGE32, 0, MAX_RANGE); // from 0 to MAX_RANGE
33		SendMessageW(_hWnd, PBM_SETSTEP, 0, 0);
34
35		SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
36		_oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
37	}
38
39	override void OnRemove()
40	{
41		DestroyWindow(_hWnd);
42	}
43
44	override void setValue(long value)
45	{
46		super.setValue(value);
47
48		// update the control
49
50		if (_value == _max) {
51			SendMessageW( _hWnd, PBM_SETPOS, MAX_RANGE, 0);
52		}
53		else {
54			float percentage = cast(float)(_value - _min) / cast(float)(_max - _min);
55			int newval = cast(int)(cast(float)MAX_RANGE * percentage);
56
57			SendMessageW( _hWnd, PBM_SETPOS, newval, 0);
58		}
59	}
60
61protected:
62
63	const int MAX_RANGE = 0xfffffff;
64
65	LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
66	{
67		return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
68	}
69
70	View _ReturnView(out int x, out int y, out int w, out int h)
71	{
72		x = _x;
73		y = _y;
74		w = _width;
75		h = _height;
76		return _view;
77	}
78
79	HWND _hWnd;
80	WNDPROC _oldproc;
81}