Page 1 of 1

scrollbargadget Eventtype - stepwidth not Pagelenght

Posted: Mon Dec 05, 2016 10:42 pm
by Amnesty
Hello and good eveneing,

is t possible to catch the Events when you klick on the scroll arrow ?

Problem: When I click on the right arrow, it increases gadgetstate() + 1, but i would like to increase by 20 for example, I dont know how.

Anybody knows a way to do it ?

Thanks in advance

AMnesty

Here is an example, to explain more detailed, what I am telling about.

Code: Select all

If OpenWindow(0, 0, 0, 305, 140, "ScrollBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget       (2,  10, 25, 250,  20, "ScrollBar Standard  (start=50, page=30/100)",#PB_Text_Center)
  ScrollBarGadget  (0,  10, 42, 250,  20, 0, 100, 30)
  Repeat 
    event = WaitWindowEvent() 
    If EventGadget() = 0
      If EventType() = #PB_EventType_LeftClick
        Debug GetGadgetState(0)
      EndIf
    EndIf
  Until event = #PB_Event_CloseWindow
EndIf

Re: scrollbargadget Eventtype - stepwidth not Pagelenght

Posted: Sun Dec 11, 2016 5:56 am
by netmaestro
It's actually not that simple to do it right. You can respond to the PB event and add or subtract 20 (or whatever) to the gadgetstate, but which one? the click event gives no information about which arrow, if any, was pressed. You could keep track of the state and check the new state for higher or lower but you still get a move of 1 happening first and then your 20. It looks stupid and it is. So I can show you how to do it right on Windows with a subclass of the scrollbar, but if you want something crossplatform someone else will have to chime in.

Code: Select all

Structure SCROLLBARINFO 
  cbSize.l
  rcScrollBar.RECT
  dxyLineButton.i
  xyThumbTop.i
  xyThumbBottom.i
  reserved.i
  rgstate.l[6]
EndStructure

Procedure ScrollProc(hwnd, msg, wparam, lparam)
  oldproc = GetProp_(hwnd, "oldproc")
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
      
    Case #WM_LBUTTONDOWN, #WM_LBUTTONDBLCLK
      With sbi.SCROLLBARINFO
        \cbSize = SizeOf(SCROLLBARINFO)
      EndWith
      SendMessage_(hwnd, #SBM_GETSCROLLBARINFO, 0, @sbi)
      MapWindowPoints_(0, hwnd, @sbi\rcScrollBar, 2)
      buttonsize = sbi\dxyLineButton
      SetRect_(leftarrow.RECT, 0, 0, buttonsize, buttonsize)
      SetRect_(rightarrow.RECT, sbi\rcScrollBar\right-buttonsize,0,sbi\rcScrollBar\right,sbi\rcScrollBar\bottom)
      cp.q = (lparam >> 16) << 32 | lparam & $FF
      If PtInRect_(leftarrow, cp)
        SetGadgetState(GetDlgCtrlID_(hwnd),GetGadgetState(GetDlgCtrlID_(hwnd))-20)
      ElseIf PtInRect_(rightarrow, cp)
        SetGadgetState(GetDlgCtrlID_(hwnd),GetGadgetState(GetDlgCtrlID_(hwnd))+20)
      EndIf
      ProcedureReturn 0
  EndSelect
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure

If OpenWindow(0, 0, 0, 305, 140, "ScrollBarGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  TextGadget(2,  10, 25, 250,  20, "ScrollBar Standard  (start=50, page=30/100)",#PB_Text_Center)
  sb = ScrollBarGadget  (0,  10, 42, 250,  20, 0, 100, 30)
  SetProp_(sb, "oldproc", SetWindowLongPtr_(sb, #GWL_WNDPROC, @ScrollProc()))
  Repeat 
    event = WaitWindowEvent() 
    If EventGadget() = 0
      If EventType() = #PB_EventType_LeftClick
        
      EndIf
    EndIf
  Until event = #PB_Event_CloseWindow
EndIf

Re: scrollbargadget Eventtype - stepwidth not Pagelenght

Posted: Sat Dec 24, 2016 2:25 pm
by Amnesty
Thank you very much, i thought that its possible to get a unique event for the specific arrow.

I think the best way is to build a custom canvas based scrollbar.

Thank you

amnesty