/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

  1. module platform.win.controls.ostrackbar;
  2. import gui.trackbar;
  3. import core.string;
  4. import platform.win.definitions;
  5. import platform.win.vars;
  6. import platform.win.common;
  7. import platform.win.oscontrolinterface;
  8. import platform.win.main;
  9. import core.view;
  10. import gui.widget;
  11. import gui.window;
  12. class OSTrackBar : TrackBar, 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. "msctls_trackbar32\0", null, WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS , _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. setRange(_min, _max);
  28. setValue(_value);
  29. setTickFrequency(_tickFreq);
  30. }
  31. override void OnRemove()
  32. {
  33. DestroyWindow(_hWnd);
  34. }
  35. override void setValue(long value)
  36. {
  37. super.setValue(value);
  38. if (_is64)
  39. {
  40. int val = cast(int)((cast(double)_value) * _proportion);
  41. SendMessageW(_hWnd, TBM_SETPOS, 0, val);
  42. }
  43. else
  44. {
  45. SendMessageW(_hWnd, TBM_SETPOS, 0, cast(int)_value);
  46. }
  47. }
  48. override void setRange(long min, long max)
  49. {
  50. super.setRange(min, max);
  51. if (_min <= 0xfffffff && _max <= 0xfffffff)
  52. {
  53. _implMin = cast(int)_min;
  54. _implMax = cast(int)_max;
  55. _proportion = 1.0f;
  56. _is64=false;
  57. }
  58. else
  59. {
  60. _implMin = 0;
  61. _implMax = 0xfffffff;
  62. _is64=true;
  63. _proportion = cast(double)(_max - _min) / cast(double)0xfffffff;
  64. }
  65. SendMessageW(_hWnd, TBM_SETRANGEMIN, 0, _implMin);
  66. SendMessageW(_hWnd, TBM_SETRANGEMAX, 0, _implMax);
  67. }
  68. override void setTickFrequency(ulong tickFreq)
  69. {
  70. super.setTickFrequency(tickFreq);
  71. if (_is64) {
  72. int _freq = cast(int)((cast(double)_tickFreq) * _proportion);
  73. SendMessageW(_hWnd, TBM_SETTICFREQ, _freq, 0);
  74. } else {
  75. SendMessageW(_hWnd, TBM_SETTICFREQ, cast(int)_tickFreq, 0);
  76. }
  77. }
  78. protected:
  79. int _implMin;
  80. int _implMax;
  81. double _proportion;
  82. bool _is64;
  83. LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
  84. {
  85. return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
  86. }
  87. View _ReturnView(out int x, out int y, out int w, out int h)
  88. {
  89. x = _x;
  90. y = _y;
  91. w = _width;
  92. h = _height;
  93. return _view;
  94. }
  95. HWND _hWnd;
  96. WNDPROC _oldproc;
  97. }