PageRenderTime 19ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1. module platform.win.controls.osprogressbar;
  2. import gui.progressbar;
  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 OSProgressBar : ProgressBar, 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_progress32\0", null, WS_CHILD | WS_VISIBLE , _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. SendMessageW(_hWnd, PBM_SETRANGE32, 0, MAX_RANGE); // from 0 to MAX_RANGE
  26. SendMessageW(_hWnd, PBM_SETSTEP, 0, 0);
  27. SetWindowLongW(_hWnd, GWLP_USERDATA, cast(ulong)(cast(void*)(cast(OSControl)this)));
  28. _oldproc = cast(WNDPROC)SetWindowLongW(_hWnd, GWLP_WNDPROC, cast(ulong)&CtrlProc);
  29. }
  30. override void OnRemove()
  31. {
  32. DestroyWindow(_hWnd);
  33. }
  34. override void setValue(long value)
  35. {
  36. super.setValue(value);
  37. // update the control
  38. if (_value == _max) {
  39. SendMessageW( _hWnd, PBM_SETPOS, MAX_RANGE, 0);
  40. }
  41. else {
  42. float percentage = cast(float)(_value - _min) / cast(float)(_max - _min);
  43. int newval = cast(int)(cast(float)MAX_RANGE * percentage);
  44. SendMessageW( _hWnd, PBM_SETPOS, newval, 0);
  45. }
  46. }
  47. protected:
  48. const int MAX_RANGE = 0xfffffff;
  49. LRESULT _AppLoopMessage(uint message, WPARAM wParam, LPARAM lParam)
  50. {
  51. return CallWindowProcW(_oldproc, _hWnd, message, wParam, lParam);
  52. }
  53. View _ReturnView(out int x, out int y, out int w, out int h)
  54. {
  55. x = _x;
  56. y = _y;
  57. w = _width;
  58. h = _height;
  59. return _view;
  60. }
  61. HWND _hWnd;
  62. WNDPROC _oldproc;
  63. }