vertical-slider.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #if defined(Hiro_VerticalSlider)
  2. namespace hiro {
  3. auto pVerticalSlider::construct() -> void {
  4. //TBS_TRANSPARENTBKGND is needed to render the transparent area of sliders properly inside TabFrame controls
  5. //however, this flag will prevent the slider control from redrawing during vertical window resizes when not inside TabFrame controls
  6. //this is because WM_PRINTCLIENT must be implemented in the parent window for this case
  7. //however, WM_PRINTCLIENT is incompatible with WM_PAINT, which is how most hiro custom widgets are rendered
  8. //as a hacky workaround, TBS_TRANSPARENTBKGND is enabled only when sliders are placed inside of TabFrame controls
  9. auto style = WS_CHILD | WS_TABSTOP | TBS_NOTICKS | TBS_BOTH | TBS_VERT;
  10. if(self().parentTabFrame(true)) style |= TBS_TRANSPARENTBKGND;
  11. hwnd = CreateWindow(TRACKBAR_CLASS, L"", style, 0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
  12. pWidget::construct();
  13. setLength(state().length);
  14. setPosition(state().position);
  15. }
  16. auto pVerticalSlider::destruct() -> void {
  17. DestroyWindow(hwnd);
  18. }
  19. auto pVerticalSlider::minimumSize() const -> Size {
  20. return {25_sx, 0};
  21. }
  22. auto pVerticalSlider::setLength(unsigned length) -> void {
  23. length += (length == 0);
  24. SendMessage(hwnd, TBM_SETRANGE, (WPARAM)true, (LPARAM)MAKELONG(0, length - 1));
  25. SendMessage(hwnd, TBM_SETPAGESIZE, 0, (LPARAM)(length >> 3));
  26. }
  27. auto pVerticalSlider::setPosition(unsigned position) -> void {
  28. SendMessage(hwnd, TBM_SETPOS, (WPARAM)true, (LPARAM)position);
  29. }
  30. auto pVerticalSlider::onChange() -> void {
  31. unsigned position = SendMessage(hwnd, TBM_GETPOS, 0, 0);
  32. if(position == state().position) return;
  33. state().position = position;
  34. self().doChange();
  35. }
  36. }
  37. #endif