[futurebasic] Re: [FB] Live Controls (Slider)

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Fri, 14 Mar 2008 11:52:54 +1300
David Bailey wrote:

>>> I need a live slider on a window. I used the Button Demo example  
>>> in the FBtoC folder and added a slider in IB with the Live option  
>>> selected. I added a command id and was successful in setting the  
>>> HiView field in the example with a value based on the slider  
>>> position. While the field updates when the mouse is released, I  
>>> can't get the slider to act as a live button and update the field  
>>> while the mouse is down.

>> Robert Responded:
>> You need to call SetControlAction() to specify a function to be  
>> executed as the slider is adjusted

<example snipped>

> That works fine in fbtoc and can be made to work in fb but I was  
> trying to use the carbon events button example. In an ON DIALOG  
> example in FB or your example of a handler the event repeats while  
> the mouse button is down if the control is set for live feedback.  
> The example in the FBtoC folder uses a NIB window and control  
> builder and a carbon event model and I cannot find anything about  
> getting this type of event to repeat WHILE the mouse is down. Once I  
> built the slider in IB and gave it a commanid id the control worked.  
> Just not as a live button repeating as long as the mouse was down. I  
> changed the result within the example handler from a no error to a  
> not handled result and that made no difference. Is a different kind/ 
> style of event handler necessary to make a carbon event repeat/loop  
> while the mouse is down on a live control?

Slider controls aren't live until SetControlAction() gives them  
something to do while tracking. Even a dummy proc that does nothing  
suffices.

The sliders in FBtoC's settings dialog are NIB-based. In code, we  
install a dummy action proc and a handler for  
kEventControlValueFieldChanged. The advantage of handling  
kEventControlValueFieldChanged is that the handler proc gets called  
whenever the value changes; it responds to programmed changes as well  
as user interaction.

The demo below is for FBtoC. Not tested in FB.

'---------------------
include "Tlbx CarbonEvents.incl"

local fn SliderValueChangedProc( unused1 as EventHandlerCallRef,  
unused2 as EventRef, userData as ptr )
'~'1
dim as ControlRef c

c = userData
print %(250, 60) fn GetControl32BitValue( c ) "  ";
end fn = _noErr


local fn DummyActionProc( unused1 as ControlRef, unused2 as  
ControlPartCode )
end fn


local fn InstallSliderHandlers( c as ControlRef )
'~'1
dim as EventTypeSpec   eventSpec

SetControlAction( c, @fn DummyActionProc ) // make slider Really  
Truly™ alive
eventSpec.eventClass = _kEventClassControl
eventSpec.eventKind  = _kEventControlValueFieldChanged
end fn = fn InstallEventHandler( fn GetControlEventTarget( c ), @fn  
SliderValueChangedProc, 1, @eventSpec, #c, #0 )

// main
window 1
dim as Rect r
SetRect( r, 30, 20, 480, 50 )
// slider with 11 tickmarks (-5 to 5)
appearance button 1,, 11, -5, 5,, @r, _kControlSliderProc  
_kControlSliderHasTickMarks _kControlSliderLiveFeedback
fn InstallSliderHandlers( button&( 1 ) )
appearance button 1,, -2 // set initial value to -2
do
HandleEvents
until ( gFBQuit )
'----------------------

Robert P.