home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / PostScript OSA / PSRunner.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.1 KB  |  214 lines

  1. #include "DropShell3.h"
  2.  
  3. #include <Memory.h>
  4. #include <Resources.h>
  5. #include <Errors.h>
  6. #include <string.h>
  7. #include <iostream>
  8.  
  9. #include <SIOUX.h>            /* To manipulate the console */
  10. #include <SIOUXGlobals.h>    /* To manipulate the console */
  11. #include <SIOUXMenus.h>        /* To manipulate the console menus */
  12.  
  13. #include "DS3Resources.h"
  14. // #include "FileLib.h"
  15. // #include "GenLib.h"
  16.  
  17. #include "AEHandlers.h"
  18.  
  19. class CPSRunner : public CDropShell {
  20. public:
  21.     CPSRunner ( Boolean walkFolders = false ) : CDropShell ( walkFolders ) {}
  22.     virtual ~CPSRunner () {}
  23.  
  24.     void EventLoop( void );
  25.     OSErr InitGlobals ( void );
  26.     void DeInitGlobals ( void );
  27.  
  28.     OSErr InitAEVTStuff (void);
  29.     void QuitApp ( void );
  30.  
  31.     OSErr ProcessItem ( FSSpec &theFile );
  32.     void SelectFile ( void ) ;
  33.     void SelectFile ( AEEventClass inClass, AEEventID inID );
  34.  
  35.     void SetUpMenus (void);
  36.     void DoMenu ( long menuChoice ) ;
  37.     void DoMouseDown ( EventRecord *curEvent ) ;
  38.  
  39. private:
  40. };
  41.  
  42. void CPSRunner::QuitApp (void) 
  43.     fDone = true; 
  44.     SIOUXQuitting = true; 
  45.     SIOUXTextWindow->dirty = false;    // this will make sure it doesn't ask to save!
  46. }
  47.  
  48. OSErr CPSRunner::InitGlobals( void )
  49. {
  50.     SIOUXSettings.initializeTB    = false;
  51.     SIOUXSettings.standalone    = true;
  52.     SIOUXSettings.setupmenus    = false;
  53.     
  54.     // ClearMenuBar();        /* 1.2 ZSS - if we use SIOUX, we clear the menubar and let it take over... */
  55.     
  56.     // cout << "Welcome to PDF Library Tester" << endl;
  57.     return noErr;
  58. }
  59.  
  60. void  CPSRunner::DeInitGlobals    ( void )
  61. {
  62. }
  63.  
  64.  
  65. void CPSRunner::SetUpMenus (void) 
  66. {
  67.     // install the SIOUX menus
  68.     SIOUXSetupMenus();
  69.     
  70.     // install any custom menus of our own
  71.     // MenuHandle    hMenu = GetMenu ( kToolsNum );
  72.     // InsertMenu ( hMenu, 0 );
  73.     DrawMenuBar();
  74. }
  75.  
  76. void CPSRunner::DoMenu ( long menuChoice ) 
  77. {
  78.     short    menuID, itemID;
  79.  
  80.     menuID = HiWord ( menuChoice );
  81.     itemID = LoWord ( menuChoice );
  82.     
  83.     switch ( menuID ) {
  84.     
  85.         default:
  86.             SIOUXDoMenuChoice(menuChoice);
  87.             break;
  88.             
  89.         }
  90.         
  91.     HiliteMenu ( 0 );        // turn off the menu
  92.     }
  93.  
  94. void CPSRunner::DoMouseDown ( EventRecord *curEvent ) 
  95. {
  96.     WindowPtr    whichWindow;
  97.     short        whichPart;
  98.  
  99.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  100.     switch ( whichPart ) {
  101.         case inMenuBar:
  102.             SIOUXUpdateMenuItems();
  103.             DoMenu ( MenuSelect ( curEvent->where ));
  104.             break;
  105.  
  106.         default:
  107.             break;
  108.         }
  109.     }
  110.  
  111. void CPSRunner::EventLoop( void )
  112. {
  113.     EventRecord    anEvent;
  114.                 
  115.     Boolean haveEvent = WaitNextEvent ( everyEvent, &anEvent, 0, NULL );
  116.     Boolean    handled = false;
  117.     
  118.     // don't let SIOUX do my high levels!
  119.     if (anEvent.what != kHighLevelEvent)
  120.         handled = SIOUXHandleOneEvent( &anEvent );
  121.     
  122.     if (haveEvent && !handled) {
  123.         switch ( anEvent.what ) {
  124.             case kHighLevelEvent:
  125.                 AEProcessAppleEvent ( &anEvent );
  126.                 break;
  127.  
  128.             case mouseDown:
  129.                 DoMouseDown ( &anEvent );
  130.                 break;
  131.                 
  132.             case keyDown:
  133.             case autoKey:
  134.                 DoKeyDown ( &anEvent );
  135.                 break;
  136.  
  137.             case diskEvt:
  138.                 if ( HiWord ( anEvent.message )) {
  139.                     Point diskInitPt = { 100, 100 };
  140.                     
  141.                     DILoad ();
  142.                     DIBadMount ( diskInitPt, anEvent.message );
  143.                     DIUnload ();
  144.                     }
  145.                 break;
  146.                 
  147.             default:
  148.                 break;
  149.         }
  150.     }
  151.     
  152.     if (SIOUXQuitting)    fDone = true;
  153. }
  154.  
  155.  
  156. OSErr CPSRunner::InitAEVTStuff ()
  157. {
  158.     CDropShell::InitAEVTStuff();    // call the base & install the default
  159.     
  160.     OSErr err = noErr;
  161.  
  162.     // now for all our app specific ones
  163.     err = AEInstallEventHandler ( kAEMiscStandards, kAEDoScript, 
  164.             NewAEEventHandlerProc ( HandleDoScript ), 0, false );
  165.     
  166.     return err;    
  167. }
  168.  
  169. void CPSRunner::SelectFile () 
  170. {
  171.     StandardFileReply    stdReply;
  172.     SFTypeList            theTypeList = {'TEXT'};
  173.  
  174.     StandardGetFile ( NULL, 4, theTypeList, &stdReply );
  175.     if ( stdReply.sfGood )    // user did not cancel
  176.         SendODOCToSelf ( &stdReply.sfFile );    // so send me an event!
  177. }
  178.  
  179. OSErr CPSRunner::ProcessItem ( FSSpec &theFile ) 
  180. {
  181. #pragma unused (theFile)
  182.  
  183.     OSErr    err = noErr;
  184.     
  185.     // will never get here, but just in case!
  186.     Debugger();
  187.     
  188.     return err;
  189. }
  190.  
  191.  
  192. /*
  193.     Main Program for the Demo App
  194. */
  195.  
  196. void main ( void ) 
  197. {
  198.     CPSRunner    *theApp;
  199.  
  200. //    Create the app
  201. //    true  --> handle folders as collections
  202. //    false --> handle folders as individual items
  203.     theApp = new CPSRunner ( true );
  204.  
  205. //    Run the app
  206.     theApp->Run ();
  207.  
  208. //    kill it off
  209.     delete theApp;
  210. }
  211.  
  212. #pragma segment CompilerCruft
  213.