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