[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: Bernie <fb.list@...>
Date: Sat, 25 Mar 2006 07:39:44 +0000
Max wrote:

> Running 10.4.3 with FB 4.2 and your code always gives 17 errors  
> when I try to compile it. With or without the TOOLBOX FN commented  
> out. Problem is none of the errors seem fixable. I'll keep trying.  
> Brian said it worked for him.


Sorry about that, Max. I've just checked it out with the FB lite demo  
(downloaded from the Staz site) and it throws up 5 errors. If you're  
getting 17 errors, I suspect you're either running earlier versions  
of the headers than what's available or some of those pesky  
underscores are going missing in the e-mail.

This one works (I hope):

'----------
include "Tlbx HIView.incl"

#if ndef _kWindowCompositingAttribute
_kWindowCompositingAttribute = (1 << 19)
#define ThemeMenuType as UInt16
toolbox fn HIMenuGetContentView( MenuRef inMenu, ThemeMenuType ¬
inMenuType, HIViewRef *outView ) = OSStatus
#endif

_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 )
long if ( w != 0 )
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
end if
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
'----------