[futurebasic] Re: [FB] I've no idea why anyone would want to do this but...

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

From: Brian Stevens <brilor@...>
Date: Fri, 24 Mar 2006 16:11:44 -0700
Bernie, very nice.  Did you intend the opaque image on the FILE menu  
in addition to the popup?  Some of the HI calls are not familiar  
(SetZOrder) and I'm not sure why we create an OffScreenImage (I'm  
betting its necessary but just my unfamiliarity) . Maybe I'll figure  
it out after study (or maybe not!). Care to add a few explanatory  
comments in the ControlEventHandler?  Does this HI offscreen call  
replace any of the deprecated Quickdraw gWorld calls?

Regarding "why would I use this?" , I'm not sure either. Maybe as a  
background for a window (as either an advertisement or a nag for  
unregistered users), but I'm not sure about using it in menus (any  
variety).   Still, very cool!

Thanks for submitting!




On Mar 24, 2006, at 4:27 AM, Bernie wrote:

>
> Needs at least OS X 10.3 and, depending on your version of Tlbx  
> HIView.incl, you may need to uncommnent the toolbox definition.
>
> Bernie
>
>
> '----------
> include "Tlbx HIView.incl"
> /*
> toolbox fn HIMenuGetContentView( MenuRef inMenu, ¬
> ThemeMenuType inMenuType, HIViewRef *outView ) = OSStatus
> */
>
> _MenuWithEmbededImageWnd = 1
> begin enum 1
> _cPop
> _cPict
> end enum
>
> _mFile = 1
> begin enum 1
> _iNew
> _iOpen
> _iOpenRecent
> _iRestoreEnvironment
> _
> _iClose
> _iSave
> _iSaveAs
> _iRevert
> _
> _iPageSetup
> _iPrint
> _iPrintSelection
>
> _iQuit
> end enum
> _mEdit = 2
> _mPop = 101
>
> _pictID = 30333
>
> local fn WindowGetContentView( w as WindowRef )
> '~'1
> dim as OSStatus     ignore
> dim as HIViewRef  @ contentView
>
> ignore = fn HIViewFindByID( fn HIViewGetRoot( w ), ¬
> kHIViewWindowContentID.signature, kHIViewWindowContentID.id, ¬
> @contentView )
> end fn = contentView
>
>
> local fn InstallControlEvent( c as HIViewRef )
> '~'1
> dim as EventTypeSpec  theEvent
> dim as OSStatus       ignore
> begin globals
> dim as pointer   sControlEventHandlerUPP
> end globals
> long if ( sControlEventHandlerUPP == 0 )
> sControlEventHandlerUPP = fn NewEventHandlerUPP( ¬
> [proc "ControlEventHandler" + _FBprocToProcPtrOffset] )
> end if
> theEvent.eventClass = _kEventClassControl
> theEvent.eventKind  = _kEventControlOwningWindowChanged
> ignore = fn InstallEventHandler( fn GetControlEventTarget( c ), ¬
> sControlEventHandlerUPP, 1, @theEvent, #0, #0 )
> end fn
>
> long if 0
> "ControlEventHandler"
> enterproc fn ControlEventHandler( nextHandler as  
> EventHandlerCallRef, ¬
> theEvent as EventRef, userData as pointer ) = OSStatus
> '~'1
> dim as HIRect        bounds
> dim as WindowRef   @ w
> dim as HiViewRef   @ c, content, imageView
> dim as CGImageRef  @ image
> dim as long          result
> dim as OSStatus      ignore
>
> result = _eventNotHandledErr
> ignore = fn GetEventParameter( theEvent, ¬
> _kEventParamControlCurrentOwningWindow, _typeWindowRef, ¬
> #0, sizeof( WindowRef ), #0, @w )
> select fn GetEventClass( theEvent )
> case _kEventClassControl
> select fn GetEventKind( theEvent )
> case _kEventControlOwningWindowChanged
> content = fn WindowGetContentView( w )
>
> window _MenuWithEmbededImageWnd
> ignore = fn HIViewCreateOffScreenImage( button&( _cPict ), ¬
> 0, @bounds, image )
>
> ignore = fn HIImageViewCreate( image, @imageView )
> ignore = fn HIImageViewSetOpaque( imageView, _false )
> ignore = fn HIImageViewSetAlpha( imageView, 0.3 )
> CFRelease( image )
>
> ignore = fn HIViewAddSubview( content, imageView )
> ignore = fn HIViewSetZOrder( imageView, _kHIViewZOrderBelow, 0 )
> ignore = fn HIViewSetVisible( imageView, _true )
>
> ignore = fn HIViewGetBounds( content, @bounds )
> ignore = fn HIViewSetFrame( imageView, @bounds )
> end select
> end select
> exitproc = result
> end If
>
>
> local fn BuildPopMenu( id as long )
> '~'1
> dim as Handle popH
>
> menu id, 0, _enable, ""
> menu id, 1, _enable, "Item 1;Item 2;Item 3;Item 4;Item 5;¬
> Item 6;Item 7;Item 8;Item 9;Item 10;Item 11;Item 12"
> popH = fn GetMenuHandle( id )
> DeleteMenu( id )
> InsertMenu( popH, -1 )
> end fn
>
>
> local fn BuildMenuBar
> '~'1
> dim as MenuRef  @ subMenu
> dim as OSErr      ignore
>
> menu _mFile, 0, _enable, "File"
> menu _mFile, _iNew, _enable, "New/N"
> menu _mFile, _iOpen, _enable, "Open…/O"
> menu _mFile, _iOpenRecent, _enable, "Open Recent"
> menu _mFile, _iRestoreEnvironment, _enable, "Restore Environment/R"
> ignore = fn SetMenuItemModifiers( fn GetMenuHandle( _mFile ), ¬
> _iRestoreEnvironment, _kMenuShiftModifier )
>
> menu _mFile, _iClose, _enable, "Close/W"
> menu _mFile, _iSave, _enable, "Save/S"
> menu _mFile, _iSaveAs, _enable, "Save As…/S"
> ignore = fn SetMenuItemModifiers( fn GetMenuHandle( _mFile ), ¬
> _iSaveAs, _kMenuShiftModifier )
> menu _mFile, _iRevert, _enable, "Revert"
>
> menu _mFile, _iPageSetup, _enable, "Page Setup"
> ignore = fn SetMenuItemModifiers( fn GetMenuHandle( _mFile ), ¬
> _iPageSetup, _kMenuShiftModifier )
> menu _mFile, _iPrint, _enable, "Print/P"
> menu _mFile, _iPrintSelection, _enable, "Print Selection"
>
> menu _mFile, _iQuit, _enable, "Quit/Q"
>
> gFBEditSelectAll = _zTrue
> edit menu _mEdit
> end fn
>
>
> local fn BuildMenuWithEmbededImageWnd
> '~'1
> dim as Rect         r
> dim as HIViewRef  @ c
> dim as OSStatus     ignore
>
> SetRect( r, 187, 127, 527, 456 )
> appearance window -_MenuWithEmbededImageWnd, "Menu with Embeded  
> Image", ¬
> @r, _kDocumentWindowClass, ¬
> _kWindowStandardHandlerAttribute _kWindowCompositingAttribute
>
> SetRect( r, 20, 20, 320, 40 )
> appearance button _cPop, _activeBtn,, _mPop, -1, "Pop:", ¬
> @r, _kControlPopupButtonProc
>
> SetRect( r, 53, 69, 293, 309 )
> appearance button -_cPict, _activeBtn, _pictID,,,, @r, ¬
> _kControlPictureNoTrackProc
>
> ignore = fn HIMenuGetContentView( fn GetMenuHandle( _mFile ), ¬
> _kThemeMenuTypePullDown, @c )
> fn InstallControlEvent( c )
>
> ignore = fn HIMenuGetContentView( fn GetMenuHandle( _mPop ), ¬
> _kThemeMenuTypePopUp, @c )
> fn InstallControlEvent( c )
>
> window _MenuWithEmbededImageWnd
> end fn
>
> fn BuildMenuBar
> fn BuildPopMenu( _mPop )
> fn BuildMenuWithEmbededImageWnd
>
> do
> HandleEvents
> until gFBQuit
> '----------
>
> --
>
>