SLIDER_SCROLLBAR detection of 'scroll buttons'

BlitzMax Forums/BlitzMax GUI Programming/SLIDER_SCROLLBAR detection of 'scroll buttons'

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hello!
I have made a very interesting discovery while attempting to detect when the user actually clicks on the small scrolling arrows of a SLIDER_SCROLLBAR in bmax (on Mac, not tested on Windows).

In fact, BlitzMax *does* detect that the user clicked on a scroll button, but it fail to deliver that information back to our program, meaning that as far as we are concerned, the event is exactly the same as if the user scrolled the 'movable knob'. This is not good. It will, in fact, always scroll by a value of 1.

There is also another interesting fact: holding down alt + click on a scroll arrow results in a 'page scroll' instead of a line scroll on Mac OS. (try it in any app, any window). Alas, again, in BMax, this information is lost and not transmitted back to our program.
Note: 'page scroll' does indeed work in Max if you happen to try it inside the code window of MaxGUI itself, or the Home/Code panel, or in the help html view. But these are NOT SLIDER_SCROLLBAR, there are in fact built-in scrollbars tied with the textarea and other controls.

But fear not, there is a very easy way of transmitting the scroll intention of the user with two super small modifications in MaxGUI.
1st modif (optional): cocoa.macos.m This is where we actually need to tell the difference between a 'page scroll' and a 'line scroll'. I choosed arbitrary values of 1 for line scroll, 10 for page scroll. It doesn't matter because your code can intercept the EVENT_GADGETACTION in a hook and do something adequate.
-(void)scrollerSelect:(id)sender{
	NSScroller *scroller;
	Int delta=0;
	scroller=(NSScroller *)sender;
	switch([scroller hitPart]){
	Case NSScrollerDecrementLine:
		delta=-1;
		break;
	Case NSScrollerDecrementPage:
		delta=-10;
		break;
	Case NSScrollerIncrementLine:
		delta=1;
		break;	
	Case NSScrollerIncrementPage:
		delta=10;
		break;	
	}
PostGuiEvent(BBEVENT_GADGETACTION,sender,delta,0,0,0,0 );
}


2nd modif: cocoagui.bmx
	If id=EVENT_GADGETACTION
		Select gadget.class
			Case GADGET_SLIDER
				If data Then
					gadget.SetProp(gadget.GetProp()+data)
					x=data ' x field holds the delta movement from a scroll button (Mac)
				End If
				data=gadget.GetProp()

So the only thing we've added here is x=data: this will allow the code to detect that is Event.X is not 0, we now know that the user clicked on a scroll button. If the value is 1 or -1, it's a normal line-scroll. If it's 10 or -10, then it's a page scroll.

I'm happy, it works in my Image Browser app :)