home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Beta / Quicktime 2.0 Beta.iso / Programming Stuff / Sample Code / DTS Sample Code / MyCaptureApp ƒ 1.0b4 / MyCaptureAppShell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-28  |  9.6 KB  |  382 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MyCaptureAppShell.c
  3.     
  4.     Contains:    MyCaptureApp shell.
  5.  
  6.     Written by:    John Wang
  7.  
  8.     Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <1>        04/04/94    JW        Created.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    "MyHeaders"
  23. /*
  24. #include    <Types.h>
  25. #include    <Memory.h>
  26. #include    <QuickDraw.h>
  27. #include    <Palettes.h>
  28. #include    <QDOffscreen.h>
  29. #include    <Errors.h>
  30. #include    <Fonts.h>
  31. #include    <Dialogs.h>
  32. #include    <Windows.h>
  33. #include    <Menus.h>
  34. #include    <Events.h>
  35. #include    <Desk.h>
  36. #include    <DiskInit.h>
  37. #include    <OSUtils.h>
  38. #include    <Resources.h>
  39. #include    <ToolUtils.h>
  40. #include    <AppleEvents.h>
  41. #include    <EPPC.h>
  42. #include    <GestaltEqu.h>
  43. #include    <Processes.h>
  44. #include    <Balloons.h>
  45. #include    <Aliases.h>
  46. #include    <MixedMode.h>
  47. #include    <Scrap.h>
  48. #include    <LowMem.h>
  49. */
  50.  
  51. #include    "MyCaptureAppShell.h"
  52. #include    "MySGStuff.h"
  53. #include    "MyUtils.h"
  54.  
  55. #ifdef powerc
  56. QDGlobals        qd;
  57. #endif
  58.  
  59. Boolean            gDoneFlag;            //    Set to true if you want to Application to kindly quit.
  60.  
  61. /* ------------------------------------------------------------------------- */
  62.  
  63. void main()
  64. {
  65.     EventRecord     myEvent;
  66.     long            yieldTime;
  67.     WindowPtr        foundWindow;
  68.     short            windowPart;
  69.     Boolean            isEvent;
  70.     GrafPtr            savePort;
  71.     GDHandle        saveGD;
  72.     PScrapStuff        myScrapStuff;
  73.  
  74.     //    Initialize here.  Set the yield time too.
  75.     Initialize();
  76.     MyAdjustMenus();
  77.     yieldTime = MyYieldTime(suspendResumeMessage);
  78.  
  79.     //    Event loop.
  80.     for ( ; ; ) {
  81.  
  82.         //    Get the event.
  83.         isEvent = WaitNextEvent(everyEvent, &myEvent, yieldTime, nil);
  84.  
  85.         //    If the event is unhandled by app specific event handling, then we proceed.
  86.         if ( isEvent ) {
  87.             switch ( myEvent.what ) {
  88.  
  89.                 case mouseDown:
  90.                     //    Get current port and device.
  91.                     GetPort(&savePort);
  92.                     saveGD = GetGDevice();
  93.                     
  94.                     //    Set the port and gdevice to the window if we own the window.
  95.                     //    We can then assume anytime the event occured in one of our windows,
  96.                     //       that the port and gdevice are set correctly.
  97.                     windowPart = FindWindow(myEvent.where, &foundWindow);
  98.                     SetPort(foundWindow);
  99.                     SetGDevice(GetMainDevice());
  100.                     
  101.                     //    Handle the different mouse down events.
  102.                     switch ( windowPart ) {
  103.                         case inSysWindow:
  104.                             SystemClick(&myEvent, foundWindow);
  105.                             break;
  106.                         case inMenuBar:
  107.                             MyAdjustMenus();
  108.                             DoCommand(MenuSelect(myEvent.where));
  109.                             MyAdjustMenus();
  110.                             break;
  111.                         case inContent:
  112.                             break;
  113.                         case inDrag:
  114.                             //    If dragging one of the application's windows, then handle it.
  115.                             //    However, if we are dragging a zoomed window, we
  116.                             //    must remember to save the new window location into the
  117.                             //    zoomed rect in the data handle.  Otherwise, the event
  118.                             //    manager will think that we are no longer zoomed.
  119.                             {
  120.                                 WStateData    *zoomData;
  121.                                 Rect        windowRect;
  122.                                 
  123.                                 //    Get window location before drag.
  124.                                 GetGlobalWindow(foundWindow, &windowRect);
  125.                                 
  126.                                 //    Drag window.
  127.                                 MyDrag(foundWindow, myEvent.where);
  128.  
  129.                                 //    If the windowRect in global coordinates matches the zoom rect,
  130.                                 //    then assume that we are dragging the zoomed window.  update
  131.                                 //    zoom rect.
  132.                                 zoomData = (WStateData *) *(((CWindowPeek) foundWindow)->dataHandle);
  133.                                 if ( EqualRect(&(zoomData->stdState), &windowRect) ) {
  134.                                     GetGlobalWindow(foundWindow, &windowRect);
  135.                                     zoomData = (WStateData *) *(((CWindowPeek) foundWindow)->dataHandle);
  136.                                     zoomData->stdState = windowRect;
  137.                                 }
  138.                             }
  139.                             break;
  140.                         case inGrow:
  141.                             break;
  142.                         case inGoAway:
  143.                             //    Handle clicking on the go away.  If it is the clip window,
  144.                             //    then hide it.
  145.                             if ( TrackGoAway (foundWindow, myEvent.where) ) {
  146.                                 BringToFront(foundWindow);
  147.                                 MyClose();
  148.                             }
  149.                             break;
  150.                         case inZoomIn:
  151.                         case inZoomOut:
  152.                             break;
  153.                         default:
  154.                             break;
  155.                     }
  156.                     
  157.                     //    Restore port and device.
  158.                     SetPort(savePort);
  159.                     SetGDevice(saveGD);
  160.                     
  161.                     break;
  162.                 case keyDown:
  163.                 case autoKey:
  164.                     if ( myEvent.modifiers & cmdKey ) {
  165.                         if ( myEvent.what == keyDown ) {
  166.                             MyAdjustMenus();
  167.                             DoCommand(MenuKey(myEvent.message & charCodeMask));
  168.                             MyAdjustMenus();
  169.                         }
  170.                     }
  171.                     break;
  172.                 case updateEvt:
  173.                     //    Handle update events for window and clip window.
  174.                     foundWindow = (WindowPtr) myEvent.message;
  175.                     GetPort(&savePort);
  176.                     saveGD = GetGDevice();
  177.                     SetPort(foundWindow);
  178.                     SetGDevice(GetMainDevice());
  179.                     BeginUpdate(foundWindow);
  180.                     EndUpdate(foundWindow);
  181.                     MyUpdate(foundWindow);
  182.                     SetPort(savePort);
  183.                     SetGDevice(saveGD);
  184.                     break;
  185.                 case diskEvt:
  186.                     //    This handles a bad disk.  Otherwise the disk will not eject.
  187.                     if ( myEvent.message >> 16 ) {
  188.                         Point    tempPoint;
  189.                         tempPoint.v = 50; tempPoint.h = 50;
  190.                         DIBadMount(tempPoint, myEvent.message);
  191.                     }
  192.                     break;
  193.                 case activateEvt:
  194.                     break;
  195.                 case app4Evt:
  196.                     switch ( myEvent.message >> 24 ) {
  197.                         case suspendResumeMessage:
  198.                             yieldTime = MyYieldTime(myEvent.message & 0x01);
  199.                             break;
  200.                         default:
  201.                             DebugStr("\pUnexpected suspend/resume message.");
  202.                     }
  203.                     break;
  204.                 case kHighLevelEvent:
  205.                     AEProcessAppleEvent(&myEvent);
  206.                 default:
  207.                     break;
  208.             }
  209.         }
  210.     
  211.         MyIdle();
  212.  
  213.         //    If DoneFlag set, then quit.
  214.         if ( gDoneFlag ) {
  215.             MyFinishup();
  216.             ExitToShell();
  217.         }
  218.     }
  219. }
  220.  
  221. /* ------------------------------------------------------------------------- */
  222.  
  223. void Initialize()
  224. {
  225.     long                err;
  226.     long                vers;
  227.     Handle                myMenu;
  228.     Boolean                hasAppleEvents;
  229.     
  230.     //    Initialize Managaer.
  231.     MaxApplZone();
  232.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  233.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  234.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  235.     MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
  236.     InitGraf(&qd.thePort);
  237.     FlushEvents(everyEvent, 0);
  238.     InitWindows();
  239.     InitDialogs(nil);
  240.     InitCursor();
  241.  
  242.     //    Set up menus.
  243.     myMenu = GetNewMBar(kMENUBAR);
  244.     SetMenuBar(myMenu);
  245.     DisposHandle(myMenu);
  246.     AddResMenu(GetMHandle(kMENU_APPLEID), 'DRVR');
  247.     DrawMenuBar();
  248.     
  249.     //    Require at least System 7.0 and Color QuickDraw.  We don't really need to be strict
  250.     //    about this.  So, this can be removed if necessary.  But, test thoroughly with
  251.     //    System 6 and non-color if you do.
  252.     Gestalt(gestaltSystemVersion, &vers);
  253.     vers = (vers >> 8) & 0x0f;
  254.     if ( vers < 7 )
  255.         ReportFatal("\pThis Application does not run under System 6!", 0);
  256.         
  257.     Gestalt(gestaltQuickdrawVersion, &vers);
  258.     if ( vers < 0x100 )
  259.         ReportFatal("\pThis Application requires Color QuickDraw!", 0);
  260.     
  261.     //    Initialize AppleEvents if available.
  262.     hasAppleEvents = (Gestalt(gestaltAppleEventsAttr, &vers) == noErr);
  263.     if ( !hasAppleEvents )
  264.         ReportFatal("\pThis Application requires AppleEvents!", 0);
  265.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(AEOpenHandler), 0, false);
  266.     if ( err != noErr )
  267.         ReportFatal("\pError installing AppleEvent handlers.", err);
  268.     err = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(AEOpenDocHandler), 0, false);
  269.     if ( err != noErr )
  270.         ReportFatal("\pError installing AppleEvent handlers.", err);
  271.     err = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(AEQuitHandler), 0, false);
  272.     if ( err != noErr )
  273.         ReportFatal("\pError installing AppleEvent handlers.", err);
  274.     err = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(AEPrintHandler), 0, false);
  275.     if ( err != noErr )
  276.         ReportFatal("\pError installing AppleEvent handlers.", err);
  277.     
  278.     //    Setup other globals.
  279.     gDoneFlag = false;
  280.  
  281.     //    Call app specific Intialization.
  282.     err = MyInitialize();
  283.     if ( err != noErr )
  284.         ReportFatal("\pError returned from MyInitialize:", err);
  285. }
  286.  
  287. void DoCommand(long mResult)
  288. {
  289.     short             theMenu, theItem;
  290.     Str255            myStr;
  291.     GrafPtr            savePort;
  292.     GDHandle        saveGD;
  293.     WindowPtr        foundWindow;
  294.     
  295.     theItem = LoWord(mResult);
  296.     theMenu = HiWord(mResult);
  297.     
  298.     if ( theItem != 0 || theMenu != 0 ) {
  299.         switch ( theMenu ) {
  300.             case kMENU_APPLEID:
  301.                 if ( theItem == 1 ) {
  302.                     ParamText("\pSample QuickTime Recording Application", "\pUses Sequence Grabber.", nil, nil);
  303.                     Alert(kALERT_ABOUT, nil);
  304.                 } else {
  305.                     GetItem(GetMHandle(kMENU_APPLEID), theItem, myStr);
  306.                     GetPort(&savePort);
  307.                     saveGD = GetGDevice();
  308.                     (void) OpenDeskAcc(myStr);
  309.                     SetPort(savePort);
  310.                     SetGDevice(saveGD);
  311.                 }
  312.                 break;
  313.     
  314.             case kMENU_FILEID:
  315.                 switch ( theItem ) {
  316.                     case kMENU_FILENEW:
  317.                         MyNew();
  318.                         break;
  319.                     case kMENU_FILECLOSE:
  320.                         MyClose();
  321.                         break;
  322.                     case kMENU_FILEQUIT:
  323.                         gDoneFlag = true;
  324.                         break;
  325.                     default:
  326.                         ReportFatal("\pError in handling file menu:", theItem);
  327.                 }
  328.                 break;
  329.     
  330.             case kMENU_SETTINGSID:
  331.                 MySettings(theItem);
  332.                 break;
  333.     
  334.             case kMENU_RESIZEID:
  335.                 MyResize(theItem);
  336.                 break;
  337.     
  338.             case kMENU_SPECIALID:
  339.                 MySpecial(theItem);
  340.                 break;
  341.     
  342.             case kMENU_RECORDID:
  343.                 MyRecord();
  344.                 break;
  345.     
  346.             default:
  347.                 ReportFatal("\pError in handling menu:", theMenu);
  348.         }
  349.     }
  350.     HiliteMenu(0);
  351. }
  352.  
  353. /* ------------------------------------------------------------------------- */
  354.  
  355. //    AppleEvents handling (AEOpenHandler, AEOpenDocHandler, AEPrintHandler,
  356. //       and AECloseHandler) :
  357.  
  358. pascal OSErr AEOpenHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  359. {    
  360.     MyNew();
  361.     MyAdjustMenus();
  362.  
  363.     return ( noErr );
  364. }
  365.  
  366. pascal OSErr AEOpenDocHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  367. {
  368.     return ( noErr );
  369. }
  370.  
  371. pascal OSErr AEPrintHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  372. {
  373.     return ( noErr );
  374. }
  375.  
  376. pascal OSErr AEQuitHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
  377. {
  378.     gDoneFlag = true;
  379.     
  380.     return ( noErr );
  381. }
  382.