home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / CustomDialog Demo / Source / Custom.c next >
Encoding:
C/C++ Source or Header  |  1995-09-17  |  4.3 KB  |  152 lines  |  [TEXT/MMCC]

  1. /**********************************************************************
  2.  *
  3.  *                        CustomGetFile Dialog Demo
  4.  *
  5.  *    Custom.c
  6.  *
  7.  *    Written in CodeWarrior Gold 5.5
  8.  *    August 31, 1995
  9.  *
  10.  *    Copyright © 1995 Carl B. Constantine
  11.  *    Some portions Copyright © 1995 MetroWerks, Inc.
  12.  *    Some portions Copyright © 1995 Apple Computer, Inc.
  13.  *
  14.  **********************************************************************/
  15.  
  16.  /*------------------------------------------------------------------
  17.   #
  18.   #                            File History
  19.   #
  20.   #        Date                Description of Change
  21.   #        ----                ---------------------
  22.   #        Aug 31/93            — Original creation of file
  23.   #
  24.   #
  25.   -------------------------------------------------------------------*/
  26.  
  27.  
  28. /*============================ Include Files ============================*/
  29.  
  30. #include <ToolUtils.h>    // included for BitTst Function
  31.  
  32. #include "Custom.h"
  33. #include "ErrUtils.h"
  34.  
  35. /*======================== Procedures & Functions =======================*/
  36.  
  37.  
  38. static pascal short MyDlgHook( short item, DialogPtr theDialog, Ptr myDataPtr )
  39. {
  40.  
  41.     short    myType, answer;
  42.     Handle    myHandle;
  43.     Rect    myRect;
  44.     Str255    myName={"\pSelect"}; // The only way to initialze a Pascal string in C ;)
  45.     
  46.         
  47.     if ( GetWRefCon( (WindowPtr)theDialog) != (long) sfMainDialogRefCon )
  48.         return( 0 );    // We don't want any other dialog
  49.         
  50.     // A description of each of these sf... types is in Inside Mac: Files
  51.     // pp 3-21 to 3-27.  You'll also find these in the Book "Programming for
  52.     // System 7" by Garry Little and Tim Swihart pp 77-77.
  53.     
  54.     switch( item )
  55.     {
  56.         case sfHookFirstCall:
  57.             GetDItem( theDialog, sfItemOpenButton, &myType, &myHandle, &myRect );
  58.             SetCTitle( (ControlHandle)myHandle, myName );
  59.             answer = sfHookGoToDesktop;
  60.             break;
  61.         case sfHookGoToDesktop:
  62.             answer = sfHookNullEvent;
  63.             break;
  64.         case sfHookChangeSelection:
  65.             answer = sfHookGoToDesktop;
  66.             break;
  67.         case sfHookGoToNextDrive:
  68.             answer = sfHookNullEvent;
  69.             break;
  70.         case sfHookGoToPrevDrive:
  71.             answer = sfHookNullEvent;
  72.             break;
  73.         case sfItemOpenButton:
  74.         case sfHookOpenFolder:
  75.             answer = sfItemOpenButton;
  76.             break;
  77.         default:
  78.             answer = item;
  79.             break;
  80.     }
  81.     return( answer );
  82.  
  83. }
  84.  
  85. /*-----------------------------------------------------------------------*/
  86.  
  87. static pascal Boolean MyCustomFileFilter( CInfoPBPtr pb, Ptr myDataPtr )
  88. {
  89.  
  90.     // mask out anything but drive volumes using the toolbox BitTst function
  91.     // to test the folder bit of the hFileInfo rec part of the union
  92.     
  93.     if ( ( BitTst( (Ptr)pb->hFileInfo.ioFlAttrib, kFolderBit ) ) 
  94.         && ( pb->dirInfo.ioDrParID == fsRtParID ) )
  95.         
  96.     // The other way (and possibly faster ) to do the above using C synatax is
  97.     // if ( (pb->hFileInfo.ioFlAttrib & 0x10) && (pb->dirInfo.ioDrParID == fsRtParID))
  98.     // but why get too complicated when the mac provides a nice way to do this for you ;)
  99.     
  100.         return( false );    
  101.     else
  102.         return( true );
  103.  
  104. }
  105.  
  106. /*-----------------------------------------------------------------------*/
  107.  
  108. StandardFileReply DoGetVolume( void )
  109. {
  110.     StandardFileReply        myReply;
  111.     SFTypeList                myTypes;
  112.     Point                    myPoint = { -1, -1 }; // Standard position
  113.     short                    myNumTypes = -1;
  114.     ModalFilterYDUPP        myModalFilter = nil;    // Using the Universal Proc Pointers
  115.     ActivationOrderListPtr    myActiveList = nil;
  116.     ActivateYDUPP            myActivateProc = nil;
  117.     DlgHookYDUPP            dialogHook;        // don't set these to nil as they will be initialized
  118.     FileFilterYDUPP            fileFilter;        // with a call to the routine descriptor.
  119.     GetHookRec                myData;
  120.     
  121.         
  122.     // Set up the routine descriptors.
  123.  
  124.     if ( ( dialogHook = NewDlgHookYDProc( MyDlgHook ) ) == NULL ) 
  125.     {
  126.         DeathAlert( errNoMem );
  127.     }
  128.  
  129.     if ( ( fileFilter = NewFileFilterYDProc( MyCustomFileFilter ) ) == NULL ) 
  130.     {
  131.         DeathAlert( errNoMem );
  132.     }
  133.     
  134.     // This call is larger than it needs to be.  In many cases you wouldn't actually
  135.     // use variables for fields that are 'nil' (0L), but I've left them here to be more
  136.     // conforming to what Inside Macintosh says and for a description of each of the fields
  137.     // and their use.
  138.  
  139.     CustomGetFile( fileFilter, myNumTypes, myTypes, &myReply, 
  140.         rGetVolumeDLOG, myPoint, dialogHook, myModalFilter, myActiveList, 
  141.         myActivateProc, &myData );
  142.     
  143.     
  144.     // Remember to dispose of the memory allocated by the routine descriptors
  145.     
  146.     DisposeRoutineDescriptor( dialogHook );
  147.     DisposeRoutineDescriptor( fileFilter );
  148.     return( myReply );
  149.     
  150. }
  151.  
  152. /*============================= End of File ==============================*/