PageRenderTime 17ms CodeModel.GetById 11ms RepoModel.GetById 0ms 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
  1. module platform.win.controls.oshscrollbar;
  2. import core.string;
  3. import platform.win.definitions;
  4. import platform.win.vars;
  5. import platform.win.common;
  6. import platform.win.oscontrolinterface;
  7. import platform.win.main;
  8. import core.view;
  9. import gui.widget;
  10. import gui.window;
  11. import gui.hscrollbar;
  12. class OSHScrollBar : HScrollBar, OSControl
  13. {
  14. public:
  15. this(int x, int y, int width, int height)
  16. {
  17. super(x,y,width,height);
  18. }
  19. override void OnAdd()
  20. {
  21. _hWnd = CreateWindowExW(0,
  22. "SCROLLBAR\0", null, WS_CHILD | WS_VISIBLE | SBS_HORZ , _x,_y,_width,_height,
  23. WindowGetPlatformVars(_window).hWnd,null, cast(HINSTANCE)GetWindowLongW(WindowGetPlatformVars(_window).hWnd,GWLP_HINSTANCE), null);
  24. SetWindowPos(_hWnd, cast(HWND)HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  25. SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
  26. _oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
  27. SetScrollRange(_hWnd, SB_CTL, cast(uint)m_min, cast(uint)m_max, FALSE);
  28. }
  29. override void OnRemove()
  30. {
  31. DestroyWindow(_hWnd);
  32. }
  33. protected:
  34. LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
  35. {
  36. SCROLLINFO sinfo = {0};
  37. sinfo.cbSize = SCROLLINFO.sizeof;
  38. sinfo.fMask = SIF_TRACKPOS;
  39. if (message == WM_HSCROLL)
  40. {
  41. switch(wParam)
  42. {
  43. case SB_THUMBTRACK:
  44. GetScrollInfo(_hWnd, SB_CTL, &sinfo);
  45. m_value = sinfo.nTrackPos;
  46. break ;
  47. case SB_LINEDOWN:
  48. m_value += m_small_change ;
  49. if (m_value > m_max) { m_value = m_max; }
  50. break ;
  51. case SB_LINEUP:
  52. m_value -= m_small_change ;
  53. if (m_value < m_min) { m_value = m_min; }
  54. break ;
  55. case SB_PAGEDOWN:
  56. m_value += m_large_change ;
  57. if (m_value > m_max) { m_value = m_max; }
  58. break ;
  59. case SB_PAGEUP:
  60. m_value -= m_large_change ;
  61. if (m_value < m_min) { m_value = m_min; }
  62. break ;
  63. default:
  64. return 0;
  65. }
  66. SetScrollPos (_hWnd, SB_CTL, cast(uint)m_value, 1) ;
  67. raiseSignal(Signal.Scrolled);
  68. _window.redraw();
  69. return 0;
  70. }
  71. return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
  72. }
  73. View _ReturnView(out int x, out int y, out int w, out int h)
  74. {
  75. x = _x;
  76. y = _y;
  77. w = _width;
  78. h = _height;
  79. return _view;
  80. }
  81. HWND _hWnd;
  82. WNDPROC _oldproc;
  83. }