home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- *
- * CustomGetFile Dialog Demo
- *
- * Custom.c
- *
- * Written in CodeWarrior Gold 5.5
- * August 31, 1995
- *
- * Copyright © 1995 Carl B. Constantine
- * Some portions Copyright © 1995 MetroWerks, Inc.
- * Some portions Copyright © 1995 Apple Computer, Inc.
- *
- **********************************************************************/
-
- /*------------------------------------------------------------------
- #
- # File History
- #
- # Date Description of Change
- # ---- ---------------------
- # Aug 31/93 — Original creation of file
- #
- #
- -------------------------------------------------------------------*/
-
-
- /*============================ Include Files ============================*/
-
- #include <ToolUtils.h> // included for BitTst Function
-
- #include "Custom.h"
- #include "ErrUtils.h"
-
- /*======================== Procedures & Functions =======================*/
-
-
- static pascal short MyDlgHook( short item, DialogPtr theDialog, Ptr myDataPtr )
- {
-
- short myType, answer;
- Handle myHandle;
- Rect myRect;
- Str255 myName={"\pSelect"}; // The only way to initialze a Pascal string in C ;)
-
-
- if ( GetWRefCon( (WindowPtr)theDialog) != (long) sfMainDialogRefCon )
- return( 0 ); // We don't want any other dialog
-
- // A description of each of these sf... types is in Inside Mac: Files
- // pp 3-21 to 3-27. You'll also find these in the Book "Programming for
- // System 7" by Garry Little and Tim Swihart pp 77-77.
-
- switch( item )
- {
- case sfHookFirstCall:
- GetDItem( theDialog, sfItemOpenButton, &myType, &myHandle, &myRect );
- SetCTitle( (ControlHandle)myHandle, myName );
- answer = sfHookGoToDesktop;
- break;
- case sfHookGoToDesktop:
- answer = sfHookNullEvent;
- break;
- case sfHookChangeSelection:
- answer = sfHookGoToDesktop;
- break;
- case sfHookGoToNextDrive:
- answer = sfHookNullEvent;
- break;
- case sfHookGoToPrevDrive:
- answer = sfHookNullEvent;
- break;
- case sfItemOpenButton:
- case sfHookOpenFolder:
- answer = sfItemOpenButton;
- break;
- default:
- answer = item;
- break;
- }
- return( answer );
-
- }
-
- /*-----------------------------------------------------------------------*/
-
- static pascal Boolean MyCustomFileFilter( CInfoPBPtr pb, Ptr myDataPtr )
- {
-
- // mask out anything but drive volumes using the toolbox BitTst function
- // to test the folder bit of the hFileInfo rec part of the union
-
- if ( ( BitTst( (Ptr)pb->hFileInfo.ioFlAttrib, kFolderBit ) )
- && ( pb->dirInfo.ioDrParID == fsRtParID ) )
-
- // The other way (and possibly faster ) to do the above using C synatax is
- // if ( (pb->hFileInfo.ioFlAttrib & 0x10) && (pb->dirInfo.ioDrParID == fsRtParID))
- // but why get too complicated when the mac provides a nice way to do this for you ;)
-
- return( false );
- else
- return( true );
-
- }
-
- /*-----------------------------------------------------------------------*/
-
- StandardFileReply DoGetVolume( void )
- {
- StandardFileReply myReply;
- SFTypeList myTypes;
- Point myPoint = { -1, -1 }; // Standard position
- short myNumTypes = -1;
- ModalFilterYDUPP myModalFilter = nil; // Using the Universal Proc Pointers
- ActivationOrderListPtr myActiveList = nil;
- ActivateYDUPP myActivateProc = nil;
- DlgHookYDUPP dialogHook; // don't set these to nil as they will be initialized
- FileFilterYDUPP fileFilter; // with a call to the routine descriptor.
- GetHookRec myData;
-
-
- // Set up the routine descriptors.
-
- if ( ( dialogHook = NewDlgHookYDProc( MyDlgHook ) ) == NULL )
- {
- DeathAlert( errNoMem );
- }
-
- if ( ( fileFilter = NewFileFilterYDProc( MyCustomFileFilter ) ) == NULL )
- {
- DeathAlert( errNoMem );
- }
-
- // This call is larger than it needs to be. In many cases you wouldn't actually
- // use variables for fields that are 'nil' (0L), but I've left them here to be more
- // conforming to what Inside Macintosh says and for a description of each of the fields
- // and their use.
-
- CustomGetFile( fileFilter, myNumTypes, myTypes, &myReply,
- rGetVolumeDLOG, myPoint, dialogHook, myModalFilter, myActiveList,
- myActivateProc, &myData );
-
-
- // Remember to dispose of the memory allocated by the routine descriptors
-
- DisposeRoutineDescriptor( dialogHook );
- DisposeRoutineDescriptor( fileFilter );
- return( myReply );
-
- }
-
- /*============================= End of File ==============================*/