I can get this code to run. I get a dialogue box that says: "The following toolbox items are not available on this computer. HIViewSetID" -Joe Lertola On May 30, 2006, at 7:07 AM, Bernie wrote: > > OK (now that Robert P has showed me what I was doing wrong), here's a > non-nib way to add custom items to a nav dialog: > > '---------- > /* > Add custom items to a nav dialog > > Bernie Wylde 30 May 2006 > */ > > include "Tlbx HIView.incl" > include "Tlbx Navigation.incl" > > _navCustomItemsWnd = 1 > _navCustomUserPane = 1 > _navCustomCheckBox = 2 > > begin record CustomData > dim as long wndNum > dim as HIViewRef userPane > end record > > > local mode > local fn CreateCustomUserPane( userData as ^CustomData ) > '~'1 > dim as Rect r > dim as OSStatus ignore > > SetRect( r, 0, 0, 400, 40 ) > appearance window -_NavCustomItemsWnd,, @r, _kDocumentWindowClass > userData.wndNum = _NavCustomItemsWnd > appearance button _navCustomUserPane,, ¬ > _kControlSupportsEmbedding,,,, @r, _kControlUserPaneProc > userData.userPane = button&( _navCustomUserPane ) > SetRect( r, 10, 10, 145, 28 ) > appearance button _navCustomCheckBox,, ¬ > _kControlCheckBoxUncheckedValue,,, "Custom CheckBox", ¬ > @r, _kControlCheckBoxAutoToggleProc > ignore = fn HIViewSetID( button&( _navCustomCheckBox ), ¬ > _"Chck", 1 ) > ignore = fn HIViewAddSubview( userData.userPane, ¬ > button&( _navCustomCheckBox ) ) > end fn > > > local fn HandleCarbonCustomizeEvent( callBackParms as ^NavCBRecPtr, ¬ > userData as ^CustomData ) > '~'1 > dim as Rect bounds > dim as SInt16 neededHeight, neededWidth > dim as OSStatus ignore > > begin globals > dim as SInt16 sCarbonEventLastTryHeight// static > dim as SInt16 sCarbonEventLastTryWidth// static > end globals > > long if ( userData.userPane == 0 ) > fn CreateCustomUserPane( userData ) > end if > GetControlBounds( userData.userPane, @bounds ) > neededWidth = callBackParms.customRect.left + ¬ > ( bounds.right - bounds.left ) > neededHeight = callBackParms.customRect.top + ¬ > ( bounds.bottom - bounds.top ) > long if ( ( callBackParms.customRect.right == 0 ) ¬ > and ( callBackParms.customRect.bottom == 0 ) ) > callBackParms.customRect.right = neededWidth > callBackParms.customRect.bottom = neededHeight > xelse > long if ( sCarbonEventLastTryWidth != ¬ > callBackParms.customRect.right ) > long if ( callBackParms.customRect.right < neededWidth ) > callBackParms.customRect.right = neededWidth > end if > end if > long if ( sCarbonEventLastTryHeight != ¬ > callBackParms.customRect.bottom ) > long if ( callBackParms.customRect.bottom < neededHeight ) > callBackParms.customRect.bottom = neededHeight > end if > end if > end if > sCarbonEventLastTryWidth = callBackParms.customRect.right > sCarbonEventLastTryHeight = callBackParms.customRect.bottom > end fn > > > local mode > local fn HandleCarbonStartEvent( callBackParms as ¬ > ^NavCBRecPtr, userData as ^CustomData ) > '~'1 > dim as HIViewRef @ userPane > dim as OSStatus ignore > > userPane = userData.userPane > ignore = fn NavCustomControl( callBackParms.context, ¬ > _kNavCtlAddControl, #userPane ) > MoveControl( userPane, callBackParms.customRect.left, ¬ > callBackParms.customRect.top ) > end fn > > > local mode > local fn HandleCustomMouseDown( callBackParms as ^NavCBRecPtr ) > '~'1 > dim evt as ^EventRecord > dim as Point where > dim as ControlRef @ whichControl > dim as OSStatus ignore > > evt = callBackParms.eventData.eventDataParms.event > where = evt.where > GlobalToLocal( @where ) > whichControl = fn FindControlUnderMouse( where, ¬ > callBackParms.window, #0 ) > long if ( whichControl ) > ignore = fn HandleControlClick( whichControl, ¬ > where, evt.modifiers, 0 ) > end if > end fn > > > local mode > local fn HandleNormalEvents( callBackParms as ^NavCBRecPtr ) > '~'1 > dim evt as ^EventRecord > > evt = callBackParms.eventData.eventDataParms.event > select evt.what > case _mButDwnEvt : fn HandleCustomMouseDown( callBackParms ) > end select > end fn > > > long if 0 > "EventProc" > enterproc EventProc( callBackSelector as NavEventCallbackMessage, ¬ > callBackParms as ^NavCBRecPtr, userData as ^CustomData ) > '~'1 > dim as Str255 msg > dim as HIViewRef @ checkBox > dim as OSStatus ignore > > select callBackSelector > case _kNavCBTerminate > window close userData.wndNum > > case _kNavCBCustomize > fn HandleCarbonCustomizeEvent( callBackParms, userData ) > > case _kNavCBStart > fn HandleCarbonStartEvent( callBackParms, userData ) > > case _kNavCBEvent > fn HandleNormalEvents( callBackParms ) > > case _kNavCBAdjustRect > long if ( userData.userPane ) > MoveControl( userData.userPane, ¬ > callBackParms.customRect.left, ¬ > callBackParms.customRect.top ) > end if > > case _kNavCBAccept > ignore = fn HIViewFindByID( fn HIViewGetRoot( ¬ > callBackParms.window ), _"Chck", 1, @checkBox ) > long if ( fn GetControl32BitValue( checkBox )¬ > == _kControlCheckBoxCheckedValue ) > msg = "Custom CheckBox is checked" > xelse > msg = "Custom CheckBox is unchecked" > end if > ignore = fn StandardAlert( _kAlertCautionAlert, msg, "", 0, #0 ) > end select > exitproc > end if > > > local mode > local fn BuildMenuBar > '~'1 > dim as OSStatus ignore > > menu 1, 0, 1, "File" > menu 1, 1, 1, "New…/N" > ignore = fn SetMenuItemCommandID( fn GetMenuHandle( 1 ), ¬ > 1, _kHICommandNew ) > end fn > > > local fn DoNewWindow > '~'1 > dim as NavDialogCreationOptions options > dim as CustomData userData > dim as NavDialogRef @ navDialog > dim as OSStatus ignore > > begin globals > dim as proc sEventUPP// static > end globals > sEventUPP = fn NewNavEventUPP( ¬ > [proc "EventProc" + _FBprocToProcPtrOffset] ) > > userData = fn malloc( sizeof( CustomData ) ) > userData.userPane = 0 > call NavGetDefaultDialogCreationOptions( @options ) > ignore = fn NavCreatePutFileDialog( options, 0, 0, ¬ > sEventUPP, userData, @navDialog ) > call NavDialogRun( navDialog ) > NavDialogDispose( navDialog ) > free( userData ) > end fn > > > local fn InstallApplicationEvents > '~'1 > dim as EventTypeSpec theEvent > dim as OSStatus ignore > > begin globals > dim as pointer sApplicationEventHandlerUPP > end globals > long if ( sApplicationEventHandlerUPP == 0 ) > sApplicationEventHandlerUPP = fn NewEventHandlerUPP( ¬ > [proc "ApplicationEventHandler" + _FBprocToProcPtrOffset] ) > end if > > theEvent.eventClass = _kEventClassCommand > theEvent.eventKind = _kEventCommandProcess > ignore = fn InstallEventHandler( fn GetApplicationEventTarget(), ¬ > sApplicationEventHandlerUPP, 1, @theEvent, #0, #0 ) > end fn > > > fn BuildMenuBar > fn DoNewWindow > fn InstallApplicationEvents > > > RunApplicationEventLoop() > > > long if 0 > "ApplicationEventHandler" > enterproc fn ApplicationEventHandler( nextHandler as > EventHandlerCallRef, ¬ > theEvent as EventRef, userData as pointer ) > '~'1 > dim as HICommand command > dim as long result > > result = _eventNotHandledErr > call GetEventParameter( theEvent, _kEventParamDirectObject, ¬ > _typeHICommand, #0, sizeof( HICommand ), #0, @command ) > select command.commandID > case _kHICommandNew : fn DoNewWindow > result = _noErr > end select > exitproc = result > end if > '---------- > > -- > > >