[futurebasic] Re: [FB] FB^3 R6 -- Question about mouse handler

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

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Fri, 8 Mar 2002 00:45:02 -0500
Oops, forgot about the "Quit" button in Window 1!

This handles it properly.

Remember: This code is Carbon for OS X only.

Also, this code is a little better commented. Please use it instead
of that in the last post. I hate that my ISP somehow strips out the
underscores before constants on the Associate web site, but they
should come through okay in the e-mail version.

Ken

'---- BEGIN REVISED FB^3 R^ CODE -------

// Code to demonstrate the new Mouse <event>
// Appearance Compliant routines for FB^3 R6
//
// Ken Shmidheiser
// Somerset, KY
// 3-7-02
// rev. 2 (Corrected "Quit" button code)

#if ndef _appearanceRuntime
compile shutdown "Must be compiled as ¬
Appearance Compliant (or as an Appearance project)"
#endif

local fn buildMenus

apple menu "(Ken's Mouse Event Checker"

MENU 1,0,_enable, "File"
MENU 1,1,_enable, "Show Window 1"
MENU 1,2,_enable, "Show Window 2"
MENU 1,3,_enable, "Show Window 3"

// This built-in, undocumented R6 global
// automatically adds a "Select All"
// menu to the Edit Menu in OS X
gFBEditSelectAll = _zTrue
edit menu 2

end fn

LOCAL FN buildWindowOne
DIM AS RECT r

SETRECT( r, 40, 50, 390, 190 )
APPEARANCE WINDOW -1, "Window 1", @r, _kDocumentWindowClass,¬
_kWindowStandardFloatingAttributes, _clickThru
SETRECT( r, 260, 98, 320, 120 )
BUTTON 1,_activeBtn,"Quit",@r,_shadow
END FN

LOCAL FN buildWindowTwo
DIM AS RECT r

SETRECT( r, 80, 90, 430, 230 )
APPEARANCE WINDOW -2, "Window 2", @r, _kDocumentWindowClass,¬
_kWindowStandardFloatingAttributes, _clickThru
END FN

LOCAL FN buildWindowThree
DIM AS RECT r

SETRECT( r, 120, 130, 520, 270 )
APPEARANCE WINDOW -3, "Window 3", @r, _kDocumentWindowClass,¬
_kWindowStandardFloatingAttributes, _clickThru
END FN


LOCAL MODE
LOCAL FN doBeep( times AS INT )
DIM AS INT i

PRINT "WINDOW"; times; " clicked"
FOR i = 1 TO times
BEEP
// Note: In Carbon in OS X we must now
// pause between BEEPs since they are
// not quequed in the same way we are
// used to in Classic
DELAY 500
NEXT i


END FN

LOCAL FN doDialog
DIM AS LONG evnt, id

evnt = DIALOG( 0)
id   = DIALOG( evnt )

SELECT CASE( evnt )
CASE _wndClose
SELECT( id )
CASE 1 : WINDOW -1
CASE 2 : WINDOW -2
CASE 3 : WINDOW -3
END SELECT

CASE _wndRefresh
SELECT( id )
// Get use to redrawing Appearance Controls
// on refresh events in OS X. I think
// this may not yet be documented
CASE 1 : DrawOneControl( button&( 1 ) )
END SELECT

CASE _btnClick
SELECT( id )
CASE 1 : gFBQuit = _zTrue
END SELECT

END SELECT

END FN

LOCAL FN doMenu
DIM AS LONG menuID, itemID
menuID = MENU(_menuID)
itemID = MENU(_itemID)
SELECT CASE( menuID )
CASE 1
SELECT( itemID )
CASE 1 : CLS : WINDOW 1
CASE 2 : CLS : WINDOW 2
CASE 3 : CLS : WINDOW 3
END SELECT
END SELECT
MENU
END FN


// Check MOUSE <event> functions
// Reference Manual Page 381
// Be sure to read new info for Appearance
LOCAL FN doMouse
DIM AS LONG wndNum, clickType

wndNum    = MOUSE(_mouseWindow)
clickType = MOUSE( 0 )

// wndNum tells us what window
// the mouse is over at any
// given time as long as one
// handleevent cycle has
// been completed. On slower
// machines in OS x, this may
// mean waiting a split second
// for a response
SELECT CASE wndNum
CASE 1
DrawOneControl( button&( 1 ) )
SELECT clickType
// _clickInDrag clickType detects
// a single mouse-down click,
// does not wait for mouse up
CASE _click1nDrag : FN doBeep( 1 )
END SELECT

CASE 2
SELECT clickType
CASE _click1nDrag : FN doBeep( 2 )
END SELECT

CASE 3
SELECT clickType
CASE _click1nDrag : FN doBeep( 3 )
END SELECT

END SELECT

END FN

ON DIALOG FN doDialog
ON MENU   FN doMenu
ON MOUSE  FN doMouse

// The functions build the windows invisible for speed
FN buildMenus
FN buildWindowOne
FN buildWindowTwo
FN buildWindowThree
// Now, make the built windows visible
WINDOW 1
WINDOW 2
WINDOW 3

DO
HANDLEEVENTS
UNTIL gFBQuit
END

'------ END CODE ------