home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / Projects / Demo Project / Show Off Classes / ZShowOffApplication.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-11  |  6.0 KB  |  283 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp            -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZShowOffApplication.cpp    -- the demo application
  9. *
  10. *
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21. #include    "ZShowOffApplication.h"
  22. #include    "MacZoop.h"
  23. #include    "ZGWorldWindow.h"
  24. #include    "ZDialog.h"
  25. #include    "ZProgress.h"
  26. #include    "ZFolderScanner.h"
  27. #include    "ZSortTestWindow.h"
  28.  
  29. #ifdef APPEARANCE_MGR_AWARE
  30.     #include    "ZAMDialog.h"
  31. #endif
  32.  
  33.  
  34. /*--------------------------------***  CONSTRUCTOR  ***---------------------------------*/
  35.  
  36.  
  37. ZShowOffApplication::ZShowOffApplication()
  38.     : ZApplication()
  39. {
  40.     // this application can open TEXT and PICT files
  41.     
  42.     AddFileType('TEXT');
  43.     AddFileType('PICT');
  44.     
  45.     anFType = 'PICT';
  46. }
  47.  
  48.  
  49.  
  50. void    ZShowOffApplication::StartUp()
  51. {
  52.     gMenuBar->NominateWindowsMenu( 132 );
  53. }
  54.  
  55.  
  56. /*------------------------------***  MAKENEWWINDOW  ***---------------------------------*/
  57. /*    
  58.  
  59. makes a document window of type ZGWorldWindow or ZSortTestWindow according to the filetype
  60. picked.
  61.  
  62. ----------------------------------------------------------------------------------------*/
  63.  
  64. void    ZShowOffApplication::MakeNewWindow()
  65. {
  66.     if (anFType == 'PICT')
  67.         FailNIL(mostRecent = new ZGWorldWindow( this,  kUntitledWindowID ));
  68.     else
  69.         FailNIL(mostRecent = new ZSortTestWindow( this,  kUntitledWindowID ));
  70.     
  71.     try
  72.     {
  73.         mostRecent->InitZWindow();
  74.     }
  75.     catch(OSErr err)
  76.     {
  77.         ForgetObject(mostRecent);
  78.         
  79.         throw err;
  80.     }
  81. }
  82.  
  83.  
  84. /*--------------------------------***  NEWFLOATER  ***----------------------------------*/
  85. /*    
  86. makes a new floating window, to demonstrate this cool new feature!
  87. ----------------------------------------------------------------------------------------*/
  88.  
  89. void    ZShowOffApplication::NewFloater()
  90. {
  91.     FailNIL( mostRecent = new ZWindow( this, kFloaterID ));
  92.     
  93.     try
  94.     {
  95.         mostRecent->InitZWindow();
  96.         
  97.     }
  98.     catch( OSErr err )
  99.     {
  100.         ForgetObject( mostRecent );
  101.         
  102.         throw err;
  103.     }
  104.     
  105.     mostRecent->Select();
  106. }
  107.  
  108.  
  109. /*-------------------------------***  UPDATEMENUS  ***---------------------------------*/
  110. /*    
  111.  
  112. Enable the dialog demo menu items
  113.  
  114. ----------------------------------------------------------------------------------------*/
  115.  
  116. void    ZShowOffApplication::UpdateMenus()
  117. {
  118.     // enable the menus
  119.     
  120.     gMenuBar->EnableCommand( kCmdOpenMoveableModal );
  121.     gMenuBar->EnableCommand( kCmdOpenModal );
  122.     gMenuBar->EnableCommand( kCmdOpenModeless );
  123.     gMenuBar->EnableCommand( kCmdTestProgress );
  124.     gMenuBar->EnableCommand( kCmdScanFolder );
  125.     gMenuBar->EnableCommand( kCmdNewFloater );
  126.     
  127.     inherited::UpdateMenus();
  128. }
  129.  
  130.  
  131.  
  132. /*-------------------------------***  HANDLECOMMAND  ***--------------------------------*/
  133. /*    
  134.  
  135. handle the menu items for dialog demo
  136.  
  137. ----------------------------------------------------------------------------------------*/
  138.  
  139.  
  140. void    ZShowOffApplication::HandleCommand( const long aCmd )
  141. {
  142.     switch ( aCmd )
  143.     {
  144.         case kCmdOpenMoveableModal:
  145.             OpenDialog( kDialog1 );
  146.             break;
  147.         case kCmdOpenModal:
  148.             OpenDialog( kDialog2 );
  149.             break;
  150.         case kCmdOpenModeless:
  151.             OpenDialog( kDialog3 );
  152.             break;
  153.         case kCmdTestProgress:
  154.             TestProgress();
  155.             break;
  156.         case kCmdScanFolder:
  157.             TestScan();
  158.             break;
  159.         case kCmdNewFloater:
  160.             NewFloater();
  161.             break;
  162.     }
  163.     
  164.     // ask base class to handle any other menu commnds
  165.     
  166.     inherited::HandleCommand( aCmd );
  167. }
  168.  
  169.  
  170. /*----------------------------------***  OPENFILE  ***----------------------------------*/
  171. /*    
  172. make sure we create the right sort of window for the file type chosen
  173. ----------------------------------------------------------------------------------------*/
  174.  
  175. void    ZShowOffApplication::OpenFile( const FSSpec& aFile, const OSType fType)
  176. {
  177.     anFType = fType;
  178.     
  179.     inherited::OpenFile( aFile, fType );
  180. }
  181.  
  182.  
  183. /*--------------------------------***  TESTPROGRESS  ***--------------------------------*/
  184. /*    
  185.  
  186. this shows how to use the progress dialog class (ZProgress)
  187. ----------------------------------------------------------------------------------------*/
  188.  
  189. #define    kLoops    500
  190.  
  191.  
  192. void    ZShowOffApplication::TestProgress()
  193. {
  194.     // make the progress dialog object on the heap
  195.     
  196.     ZProgress    aPD (this, kStdProgressResID, kLoops, kProportionalProgress, kCancelType);
  197.     
  198.     long        loop;
  199.     
  200.     // caller has responsibility to set the animated cursor
  201.     
  202.     SetBeachBallCursor();
  203.     
  204.     // wait two seconds before showing the dialog
  205.     
  206.     aPD.SetDelay(kTwoSeconds);
  207.     aPD.SetMessage("\pLooping 500 times...");
  208.     
  209.     // loop <kLoops> times, updating the progress and
  210.     // aborting if the user cancelled
  211.     
  212.     for (loop = 0; loop < kLoops; loop++)
  213.     {
  214.         if (! aPD.InformProgress(loop))
  215.             break;
  216.     }
  217.     
  218.     // when the dialog goes out of scope now, it will be automatically deleted
  219.     // and the chain of command maintained accordingly. Neat, huh?
  220. }
  221.  
  222.  
  223.  
  224.  
  225. /*---------------------------------***  OPENDIALOG  ***---------------------------------*/
  226. /*    
  227.  
  228. construct dialog windows with the ID passed- used to demonstrate dialogs
  229.  
  230. ----------------------------------------------------------------------------------------*/
  231.  
  232. void    ZShowOffApplication::OpenDialog(short id)
  233. {
  234.     ZDialog*    aDialog;
  235.     
  236.     #ifdef APPEARANCE_MGR_AWARE
  237.     
  238.     if ( gMacInfo.hasAppearanceMgr )
  239.         FailNIL( aDialog = new ZAMDialog( this, id ));
  240.     else
  241.         FailNIL(aDialog = new ZDialog(this, id));
  242.     
  243.     #else
  244.     FailNIL(aDialog = new ZDialog(this, id));
  245.     #endif
  246.     
  247.     try
  248.     {
  249.         aDialog->InitZWindow();
  250.     }
  251.     catch(OSErr err)
  252.     {
  253.         ForgetObject(aDialog);
  254.         
  255.         throw err;
  256.     }
  257.     
  258.     // show the window and make it active
  259.     
  260.     aDialog->Select();
  261. }
  262.  
  263.  
  264. /*-----------------------------------***  TESTSCAN  ***---------------------------------*/
  265. /*    
  266. demonstrate the folder scanner- this scans every file in the selected folder.
  267.  
  268. ----------------------------------------------------------------------------------------*/
  269.  
  270. void    ZShowOffApplication::TestScan()
  271. {
  272.     ZFolderScanner    aScanner;                        // make object on the stack
  273.     
  274.     if (aScanner.PickFolder())
  275.     {
  276.         SetBeachBallCursor();                        // animate cursor
  277.  
  278.         aScanner.SetSearchDepth(-1);                // search every folder.
  279.         aScanner.ScanFolder();                        // do the scan
  280.     }
  281. }
  282.  
  283.