vertical-scroll-bar.cpp 954 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #if defined(Hiro_VerticalScrollBar)
  2. namespace hiro {
  3. auto pVerticalScrollBar::construct() -> void {
  4. hwnd = CreateWindow(
  5. L"SCROLLBAR", L"", WS_CHILD | SBS_VERT,
  6. 0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0
  7. );
  8. pWidget::construct();
  9. setLength(state().length);
  10. setPosition(state().position);
  11. }
  12. auto pVerticalScrollBar::destruct() -> void {
  13. DestroyWindow(hwnd);
  14. }
  15. auto pVerticalScrollBar::minimumSize() const -> Size {
  16. return {18_sx, 0};
  17. }
  18. auto pVerticalScrollBar::setLength(unsigned length) -> void {
  19. length += (length == 0);
  20. SetScrollRange(hwnd, SB_CTL, 0, length - 1, TRUE);
  21. }
  22. auto pVerticalScrollBar::setPosition(unsigned position) -> void {
  23. SetScrollPos(hwnd, SB_CTL, position, TRUE);
  24. }
  25. auto pVerticalScrollBar::onChange(WPARAM wparam) -> void {
  26. unsigned position = ScrollEvent(hwnd, wparam);
  27. if(position == state().position) return;
  28. state().position = position;
  29. self().doChange();
  30. }
  31. }
  32. #endif