[futurebasic] Re: [FB] Browser in standard handler window

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2006 : Group Archive : Group : All Groups

From: Bernie <spam.me.and.i.will.kill.you@...>
Date: Thu, 16 Feb 2006 18:00:02 +0000
Robert P wrote:

> Bernie wrote:
>
>> Couple of annoying 'features' with a data browser in a window with  
>> the standard handler attribute.
>> When the owning window is *not* frontmost:
>> 1. The scrolling trackpad scrolls the browser. [I'm assuming the  
>> same happens with the mouse wheel but I have no way of checking  
>> this].
>> 2. A click on say a checkbox in the browser toggles the checkbox.
>> To eliminate these, I've installed three events on the browser,  
>> kEventControlClick, kEventMouseWheelMoved & kEventTrackpadScrolled.
>> Anyone got better ideas?
>
> May we assume that you are posting because you think your control  
> click handler sucks? If so, then I agree :-)
> The official way is to install a kEventWindowGetClickActivation  
> handler, and pass back (i.e. call SetEventParameter with) a  
> ClickActivationResult of kActivateAndIgnoreClick.

Tried that but kEventWindowGetClickActivation is not triggered when I  
click the browser.

> I have the opposite problem with clicks on a DataBrowser in a non- 
> front window: a click in an empty part of the DB does nothing at  
> all, whereas it should activate the window. I suspect that the  
> handler you are about to write will solve my problem, so please  
> post the code.

Funny, that appears to work OK this side of the equator.

I know you're probably in bed right now, Robert, but would you mind  
getting up for a few minutes to check out this short(ish) example?  
Thanks.

While the window containing the browser is in the background, click  
on one of the text lines in the browser. Notice the item is selected  
but the window remains in the background. Clicking an empty part of  
the browser or clicking the window itself, brings the window forward.

Bernie


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

_cBrowserC001 = _"C001"

begin record cBrowserItemDataRec
dim as Str255 txtC001
end record

begin globals
dynamic gcBrowser(_maxInt) as cBrowserItemDataRec
end globals


def fn UBound( @p as ptr ) = [p + _AutoXREFCurr] - 1// Alain


local fn InstallWindowEvents( w as WindowRef )
'~'1
dim as EventTypeSpec  theEvent
dim as OSStatus       ignore

begin globals
dim as pointer  sWindowEventHandlerUPP
end globals
long if ( sWindowEventHandlerUPP == 0 )
sWindowEventHandlerUPP = fn NewEventHandlerUPP( ¬
[proc "WindowEventHandler" + _FBprocToProcPtrOffset] )
end if

theEvent.eventClass = _kEventClassWindow
theEvent.eventKind  = _kEventWindowGetClickActivation
ignore = fn InstallEventHandler( fn GetWindowEventTarget( w ), ¬
sWindowEventHandlerUPP, 1, @theEvent, #0, #0 )
end fn


long if ( 0 )
"WindowEventHandler"
enterproc fn WindowEventHandler( nextHandler as EventHandlerCallRef, ¬
theEvent as EventRef, userData as pointer ) = OSStatus
'~'1
long if ( fn GetEventClass( theEvent ) == _kEventClassWindow )
if ( fn GetEventKind( theEvent ) == _kEventWindowGetClickActivation )  
then beep
end if
exitproc = _eventNotHandledErr
end if


local fn InstallDataBrowserCallbacks( browser as ControlRef )
'~'1
dim as DataBrowserCallbacks  callbacks
dim as OSStatus              ignore

callbacks.version = _kDataBrowserLatestCallbacks
ignore = fn InitDataBrowserCallbacks( callbacks )
callbacks.u.v1.itemDataCallback         = fn NewDataBrowserItemDataUPP 
( ¬
[proc "ItemDataCallback" + _FBprocToProcPtrOffset] )
callbacks.u.v1.itemNotificationCallback = fn  
NewDataBrowserItemNotificationUPP( ¬
[proc "ItemNotificationCallback" + _FBprocToProcPtrOffset] )
ignore = fn SetDataBrowserCallbacks( browser, callbacks )
end fn


long if 0
"ItemNotificationCallback"
enterproc fn ItemNotificationCallback( browser as ControlRef, ¬
itemID as DataBrowserItemID, message as DataBrowserItemNotification )  
= OSStatus
'~'1
select message
case _kDataBrowserItemSelected

end select
exitproc = _noErr


"ItemDataCallback"
enterproc fn ItemDataCallback( browser as ControlRef, itemID as ¬
DataBrowserItemID, propertyID as DataBrowserPropertyID, ¬
itemData as DataBrowserItemDataRef, setValue as Boolean ) = OSStatus
'~'1
dim as OSStatus  ignore

long if ( setValue )
xelse
select propertyID
case _cBrowserC001
ignore = fn SetDataBrowserItemDataText( itemData, ¬
fn CFSTR( gcBrowser.txtC001( itemID ) ) )
end select
end if

exitproc = _noErr
end if


local fn AddColumns( browser as ControlRef )
'~'1
dim as DatabrowserListViewColumnDesc  columnDesc
dim as OSStatus                       ignore
dim as OSErr                          err

BlockZero( @columnDesc, sizeof( DatabrowserListViewColumnDesc ) )
columnDesc.propertyDesc.propertyID    = _cBrowserC001
columnDesc.propertyDesc.propertyType  = _kDataBrowserTextType
call AddDataBrowserListViewColumn( browser, columnDesc, ¬
_kDataBrowserListViewAppendColumn )
ignore = fn SetDataBrowserTableViewNamedColumnWidth( browser, ¬
_cBrowserC001, 150 )
end fn


local fn AddRows( browser as ControlRef )
'~'1
dim as Handle    @ itemH
dim as long        btnNum, dataItems, @ index
dim as OSStatus    ignore

itemH = fn NewHandle( 0 )
dataItems = fn UBound( gcBrowser )
for index = 1 To dataItems
long if ( fn PtrAndHand( @index, itemH, sizeof 
( DataBrowserItemID ) ) != _noErr )
DisposeHandle( itemH ) : exit fn
end If
next index
ignore = fn AddDataBrowserItems( browser, _kDataBrowserNoItem, ¬
fn GetHandleSize( itemH )\\sizeof( DataBrowserItemID ), #[itemH], ¬
_kDataBrowserItemNoProperty )
DisposeHandle( itemH )
end fn


local fn CreateDataBrowser
'~'1
dim as Rect        @ r
dim as ControlRef  @ browser
dim as OSStatus      ignore

SetRect( r, 20, 20, 380, 280 )
ignore = fn CreateDataBrowserControl( window( _wndRef ), r, ¬
_kDataBrowserListView, browser )
ignore = fn SetDataBrowserTableViewHiliteStyle( browser, ¬
_kDataBrowserTableViewFillHilite )

fn AddColumns( browser )
fn AddRows( browser )

fn InstallDataBrowserCallbacks( browser )
end fn


local fn BuildWindows
'~'1
dim as Rect  r

SetRect( r, 81, 138, 481, 438 )
appearance window -1, "Window1", @r, _kDocumentWindowClass, ¬
_kWindowStandardHandlerAttribute
fn InstallWindowEvents( window( _wndRef ) )
fn CreateDataBrowser
window 1

SetRect( r, 368, 265, 868, 540 )
appearance window 2, "Window 2", @r, _kDocumentWindowClass, ¬
_kWindowStandardHandlerAttribute
end fn


local fn Init
'~'1
dim as Str255  s(26)
dim as long    item

s(1) = "Georgia Sam"
s(2) = "Jezebel the Nun"
s(3) = "Jack the Ripper"
s(4) = "Queen Jane"
s(5) = "Tom Thumb"
s(6) = "Thin Man"
s(7) = "The Brakeman"
s(8) = "Mr. Jones"
s(9) = "One-eyed midget"
s(10) = "Gypsey Davey"
s(11) = "Ma Raney"
s(12) = "Graveyard woman"
s(13) = "Mack the Finger"
s(14) = "The Seventh Son"
s(15) = "Dr. Filth"
s(16) = "The Mighty Quinn"
s(17) = "Tiny Montgomery"
s(18) = "Jack of Hearts"
s(19) = "Brownsville Girl"
s(20) = "John Wesley Harding"
s(21) = "Murf the Surf"
s(22) = "Lily"
s(23) = "Rosemary"
s(24) = "Einstein"
s(25) = "Robin Hood"
s(26) = "Louis the King"

for item = 1 to 26
gcBrowser.txtC001(item) = s(item)
next item

fn BuildWindows
end fn

fn Init

RunApplicationEventLoop()
'----------