PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/platform/win/controls/oshscrollbar.d

http://github.com/wilkie/djehuty
D | 104 lines | 83 code | 21 blank | 0 comment | 6 complexity | 949089cf19b67f50c8b5a1f161a48aef MD5 | raw file
  1module platform.win.controls.oshscrollbar;
  2
  3import core.string;
  4
  5import platform.win.definitions;
  6import platform.win.vars;
  7import platform.win.common;
  8import platform.win.oscontrolinterface;
  9
 10import platform.win.main;
 11import core.view;
 12
 13import gui.widget;
 14import gui.window;
 15
 16import gui.hscrollbar;
 17
 18class OSHScrollBar : HScrollBar, OSControl
 19{
 20public:
 21	this(int x, int y, int width, int height)
 22	{
 23		super(x,y,width,height);
 24	}
 25
 26	override void OnAdd()
 27	{
 28		 _hWnd = CreateWindowExW(0,
 29			"SCROLLBAR\0", null, WS_CHILD | WS_VISIBLE | SBS_HORZ , _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		SetScrollRange(_hWnd, SB_CTL, cast(uint)m_min, cast(uint)m_max, FALSE);
 38	}
 39
 40	override void OnRemove()
 41	{
 42		DestroyWindow(_hWnd);
 43	}
 44
 45protected:
 46
 47	LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
 48	{
 49		SCROLLINFO sinfo = {0};
 50		sinfo.cbSize = SCROLLINFO.sizeof;
 51		sinfo.fMask = SIF_TRACKPOS;
 52
 53		if (message == WM_HSCROLL)
 54		{
 55			switch(wParam)
 56			{
 57				case SB_THUMBTRACK:
 58					GetScrollInfo(_hWnd, SB_CTL, &sinfo);
 59					m_value = sinfo.nTrackPos;
 60					break ;
 61				case SB_LINEDOWN:
 62					m_value += m_small_change ;
 63					if (m_value > m_max) { m_value = m_max; }
 64					break ;
 65				case SB_LINEUP:
 66					m_value -= m_small_change ;
 67					if (m_value < m_min) { m_value = m_min; }
 68					break ;
 69				case SB_PAGEDOWN:
 70					m_value += m_large_change ;
 71					if (m_value > m_max) { m_value = m_max; }
 72					break ;
 73				case SB_PAGEUP:
 74					m_value -= m_large_change ;
 75					if (m_value < m_min) { m_value = m_min; }
 76					break ;
 77				default:
 78					return 0;
 79			}
 80
 81			SetScrollPos (_hWnd, SB_CTL, cast(uint)m_value, 1) ;
 82
 83			raiseSignal(Signal.Scrolled);
 84
 85			_window.redraw();
 86
 87			return 0;
 88		}
 89
 90		return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
 91	}
 92
 93	View _ReturnView(out int x, out int y, out int w, out int h)
 94	{
 95		x = _x;
 96		y = _y;
 97		w = _width;
 98		h = _height;
 99		return _view;
100	}
101
102	HWND _hWnd;
103	WNDPROC _oldproc;
104}