PageRenderTime 27ms CodeModel.GetById 13ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/controls/ostrackbar.d

http://github.com/wilkie/djehuty
D | 121 lines | 97 code | 24 blank | 0 comment | 5 complexity | 405729f95d74aaacd240189f010ea507 MD5 | raw file
  1module platform.win.controls.ostrackbar;
  2
  3import gui.trackbar;
  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 OSTrackBar : TrackBar, 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_trackbar32\0", null, WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS , _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		SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
 33		_oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
 34
 35		setRange(_min, _max);
 36		setValue(_value);
 37		setTickFrequency(_tickFreq);
 38	}
 39
 40	override void OnRemove()
 41	{
 42		DestroyWindow(_hWnd);
 43	}
 44
 45	override void setValue(long value)
 46	{
 47		super.setValue(value);
 48
 49		if (_is64)
 50		{
 51			int val = cast(int)((cast(double)_value) * _proportion);
 52			SendMessageW(_hWnd, TBM_SETPOS, 0, val);
 53		}
 54		else
 55		{
 56			SendMessageW(_hWnd, TBM_SETPOS, 0, cast(int)_value);
 57		}
 58	}
 59
 60	override void setRange(long min, long max)
 61	{
 62		super.setRange(min, max);
 63
 64		if (_min <= 0xfffffff && _max <= 0xfffffff)
 65		{
 66			_implMin = cast(int)_min;
 67			_implMax = cast(int)_max;
 68
 69			_proportion = 1.0f;
 70			_is64=false;
 71		}
 72		else
 73		{
 74			_implMin = 0;
 75			_implMax = 0xfffffff;
 76			_is64=true;
 77
 78			_proportion = cast(double)(_max - _min) / cast(double)0xfffffff;
 79		}
 80
 81		SendMessageW(_hWnd, TBM_SETRANGEMIN, 0, _implMin);
 82		SendMessageW(_hWnd, TBM_SETRANGEMAX, 0, _implMax);
 83	}
 84
 85	override void setTickFrequency(ulong tickFreq)
 86	{
 87		super.setTickFrequency(tickFreq);
 88
 89		if (_is64) {
 90			int _freq = cast(int)((cast(double)_tickFreq) * _proportion);
 91			SendMessageW(_hWnd, TBM_SETTICFREQ, _freq, 0);
 92		} else {
 93			SendMessageW(_hWnd, TBM_SETTICFREQ, cast(int)_tickFreq, 0);
 94		}
 95	}
 96
 97protected:
 98
 99	int _implMin;
100	int _implMax;
101	double _proportion;
102
103	bool _is64;
104
105	LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
106	{
107		return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
108	}
109
110	View _ReturnView(out int x, out int y, out int w, out int h)
111	{
112		x = _x;
113		y = _y;
114		w = _width;
115		h = _height;
116		return _view;
117	}
118
119	HWND _hWnd;
120	WNDPROC _oldproc;
121}