Blame | Last modification | View Log | Download | RSS feed
/*WASTE Demo Project:Dialog UtilitiesCopyright © 1993-1998 Marco PiovanelliAll Rights ReservedC port by John C. Daub*/#ifndef __DIALOGS__#include <Dialogs.h>#endif#ifndef __WEDEMOAPP__#include "RIntf.h"#endifstatic pascal Boolean MyStandardDialogFilter( DialogPtr dialog, EventRecord *event, SInt16 *item ){GrafPtr savePort;ModalFilterUPP stdFilter = nil;Boolean retval = false;OSErr err;/* set up the port */GetPort( &savePort );SetPort( dialog );/* intercept window events directed to windows behind the dialog */if ( ( event->what == updateEvt ) || ( event->what == activateEvt ) ){if ( ((WindowPtr) event->message) != dialog ){DoWindowEvent( event );}}/* is the default item a pushbutton? */if ( GetDialogItemType( dialog, GetDialogDefaultItem( dialog ) ) == kButtonDialogItem ){/* yes, so tell the Dialog Manager to care about its outline */SetDialogDefaultItem( dialog, GetDialogDefaultItem( dialog ));}/* this is something not in the original WASTE Demo App, but in the work that I've doneon my own projects, I've found it useful and helpful.let's also make sure the cancel button can be handled...now, the cancel buttonshould be dialog item #2. So, we get dialog item #2, check if it's a button.if it fills these 2 criteria, it's cancel. Even if the default item and thecancel item are the same, still let them both be set this way so whatever keyboardkeys sthe user presses will be handled properlypass the number "2" to GetDialogItemType...don't check for the cancel item (cause thocancel is defined as 2, we're not looking for cancel, we're looking for dialog item #2this is just more readable code.remember, this assumes that your cancel item will be item #2 (or at least the itemthat you want to use for cancelling is #2), and that there are at least 2 items inthe dialog to begin with!*/if ( GetDialogItemType( dialog, kStdCancelItemIndex ) == kButtonDialogItem ){SetDialogCancelItem( dialog, kStdCancelItemIndex );}/* call the standard Dialog Manager filter procedure */if ( ( ( err = GetStdFilterProc( &stdFilter ) ) == noErr ) && ( stdFilter != nil ) ){retval = CallModalFilterProc( stdFilter, dialog, event, item );}/* restore the port */SetPort( savePort );return retval;}ModalFilterUPP GetMyStandardDialogFilter( void ){#ifdef __cplusplusstatic ModalFilterUPP sFilterUPP = NewModalFilterProc( MyStandardDialogFilter );#elsestatic ModalFilterUPP sFilterUPP = nil;if ( sFilterUPP == nil ){sFilterUPP = NewModalFilterProc( MyStandardDialogFilter );}#endifreturn sFilterUPP;}SInt16 GetDialogItemType( DialogPtr dialog, SInt16 item ){SInt16 itemType;Handle itemHandle;Rect itemRect;GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );return itemType;}Handle GetDialogItemHandle( DialogPtr dialog, SInt16 item ){SInt16 itemType;Handle itemHandle;Rect itemRect;GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );return itemHandle;}void GetDialogItemRect( DialogPtr dialog, SInt16 item, Rect *itemRect ){SInt16 itemType;Handle itemHandle;GetDialogItem( dialog, item, &itemType, &itemHandle, itemRect );}void SetDialogItemProc( DialogPtr dialog, SInt16 item, UserItemUPP proc ){SInt16 itemType;Handle itemHandle;Rect itemRect;GetDialogItem( dialog, item, &itemType, &itemHandle, &itemRect );if ( ( itemType & 0x007F) == userItem ){SetDialogItem( dialog, item, itemType, (Handle) proc, &itemRect );}}void FlashButton( DialogPtr dialog, SInt16 item ){ControlHandle button;#if ( UNIVERSAL_INTERFACES_VERSION >= 0x300 )UInt32 finalTicks ;#elseSInt32 finalTicks ;#endifbutton = (ControlHandle) GetDialogItemHandle( dialog, item );HiliteControl( button, kControlButtonPart );Delay( 8, &finalTicks );HiliteControl( button, kControlNoPart );}