home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Documentation / develop / develop Issue 7 / develop 7 code / QuickTime / SimpleInMovies / SimpleInMovies.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-15  |  23.5 KB  |  864 lines  |  [TEXT/MPS ]

  1.  
  2. /*     
  3. SimpleInMovies
  4.  
  5. Sample programs demonstrating how to open and display
  6. QuickTime™ Movies.
  7.  
  8. SimpleInMovies.c file contains the code for the main loop and the
  9. routines that open and display movies in a window.
  10.  
  11. Each window is associated with a movie and an instance of the movie
  12. controller. There are menu equivalents for movie controller commands
  13. to show how to interact with the controller.
  14.  
  15. Guillermo A. Ortiz
  16. Macintosh Developer Technical Support
  17.  
  18. 07/17/91 Editing code goes in for the first time
  19. 08/07/91 Added code to put cuts into the scrap when being switched in/out.
  20.  
  21. */
  22.  
  23. /* Interface changes:
  24. 08/06/91 -- OpenMovieFile lost the parameter.
  25. 12/03/91 -- Using MCGetControllerInfo to adjust menus.
  26. */
  27.  
  28. /* More changes
  29. 10/08/92 -- Fixed bug in the way loop menu items are enabled/checked.
  30.  
  31. */
  32.  
  33. #include <SimpleInMovie.h>
  34.  
  35. void myGetMoov(void);
  36. OSErr MakeNewMovie(void);
  37. void DoIdleStuff(void);
  38. OSErr CreateMinMovie(Movie *);
  39.  
  40. extern void ChangeMooVState(void);
  41. extern void ChangeMooVSound(void);
  42. extern void NextMooVFrame(void);
  43. extern void PrevMooVFrame(void);
  44. extern void SetMovieLoop(short);
  45.  
  46. extern void DoEnableEditing(void);
  47. extern void    DoUndoMovie(void);
  48. extern void    DoCutMovie(void);
  49. extern void DoCopyMovie(void);
  50. extern void DoPasteMovie(void);
  51. extern void DoClearMovie(void);
  52. extern void DoSelectAll(void);
  53. extern void DoScrapStuff(Boolean toScrap);
  54.  
  55. extern Boolean CreateOneWindow(Movie, StandardFileReply, short, short);
  56. extern Boolean IsAppWindow(WindowPtr);
  57. extern Boolean    DisposeAllWindows(void);
  58. extern Boolean    DisposeOneWindow(WindowPtr, short);
  59. extern Boolean DoSave(short);
  60.  
  61. extern Boolean IsPlayerEvent(WindowPtr, EventRecord *);
  62. extern Handle    GetAppResource(ResType,short, OSErr *);
  63.  
  64. void AdjustMenus(void);
  65.  
  66. extern void DoGet1MoviePict(void);
  67. extern void DoGetTrackPicts(void); /* displays track picts */
  68. extern void DoGetMoviePicts(void); /* displays movie picts THIS ONE IS USED NOW -- see comment below */
  69.  
  70. extern void PresentStyleDialog ( void );
  71. extern void PrintPoster( void);
  72. extern void PrintTerminate(void);
  73. extern void PrintInit(void);
  74.  
  75. extern void    pstrcat(char *, char *);
  76. extern void    pstrcpy(char *, char *);
  77. /*
  78.  * Global Data objects, used by routines external to main().
  79.  */
  80. MenuHandle        MyMenus[menuCount];     /* The menu handles */
  81. Boolean         DoneFlag;                /* Becomes TRUE when File/Quit chosen */
  82. short            gUntitledCount=1;
  83.  
  84. Boolean gMoviesInited, wasChanged;
  85. long timeOfMovie = 0;
  86.  
  87. Component movieControllerComponent;
  88.  
  89. extern void _DataInit();
  90. extern Movie cuts;                    /* local scrappy movie */
  91. /*******************************************************************************************
  92.  *******************************************************************************************/
  93. /* Initialize the movie toolbox, call InitMovies to let the toolbox know
  94.    of this app, get controller; if something fails set flag to get out of here */
  95.    
  96. void InitMovieStuff()
  97. {
  98. ComponentDescription controllerDescriptor;
  99. extern Boolean        DoneFlag;
  100. long version;
  101.  
  102. /* We have to fill in the fields for the player descriptor in order to get the
  103.    standard movie controller component */
  104.     controllerDescriptor.componentType = 'play';
  105.     controllerDescriptor.componentSubType = 0;
  106.     controllerDescriptor.componentManufacturer = 0;
  107.     controllerDescriptor.componentFlags = 0;
  108.     controllerDescriptor.componentFlagsMask = 0;
  109.  
  110.     /* we'll use gMoviesInited as a flag for everything, a false value
  111.        indicates that the movie toolbox or the standard player couldn't be initialized */
  112.     gMoviesInited = false;                /* so pessimistic            */
  113.     
  114.     if (!(Gestalt(gestaltQuickTime, &version)))
  115.       if ( ! (EnterMovies()) ) 
  116.         if ( movieControllerComponent = FindNextComponent((Component) 0, 
  117.             &controllerDescriptor) )                 /* no error means we are OK */
  118.           gMoviesInited = true;            /* good!                    */
  119.  
  120.     if (!gMoviesInited) {
  121.       Alert(rBadMooviesALRT,nil);     /* inform user                    */
  122.       DoneFlag = true;                /* we are bailing out            */
  123.     }
  124. }
  125. /*******************************************************************************************
  126.  *******************************************************************************************/
  127.  
  128. Boolean CheckSystem()
  129. {
  130. long systemVersion;
  131. Boolean notSeven = true;
  132.  
  133.     if (!Gestalt(gestaltSystemVersion, &systemVersion) ) {
  134.       if (systemVersion >= 0x0700) 
  135.         notSeven = false;
  136.     }
  137.     if (notSeven) {
  138.       Alert(rNotSeven,nil);     /* inform user                    */
  139.       DoneFlag = true;                /* we are bailing out            */
  140.     }
  141.     return (notSeven);
  142. }
  143. void DoInits()
  144. {
  145.     UnloadSeg((Ptr) _DataInit);        /* note that _DataInit must not be in Main! */
  146.  
  147.     /*
  148.      * Initialization traps
  149.      */
  150.     InitGraf(&qd.thePort); 
  151.     InitFonts();
  152.     FlushEvents(everyEvent, 0);
  153.     InitWindows();
  154.     InitMenus();
  155.     TEInit();
  156.     InitDialogs(nil); 
  157.     InitCursor();
  158.     
  159.     MaxApplZone();
  160.     if (!CheckSystem() )
  161.       InitMovieStuff();
  162.     PrintInit();
  163. }
  164. /*******************************************************************************************
  165.  *******************************************************************************************/
  166.  
  167. /* Main contains the event loop, we dispatch here to serve the different
  168.    events, movie fans should pay attention to the way controller events are
  169.    handled when comming through the loop.
  170. */
  171. short main()
  172. {
  173.     Rect                    screenRect;
  174.     Rect                    dragRect;
  175.     EventRecord             myEvent;
  176.     WindowPtr                theActiveWindow;
  177.     WindowPtr                whichWindow;
  178.     Boolean                 Result;
  179.     extern void             setupMenus();
  180.     extern void             doCommand();
  181.     DocRecHandle             wHndl;
  182.     Boolean                    inBackground = false;
  183.  
  184.     DoInits();
  185.     
  186.     setupMenus();            
  187.     
  188.     screenRect = qd.screenBits.bounds;
  189.     SETRECT(&dragRect, 4, 20 + 4, screenRect.right-4, screenRect.bottom-4);
  190.         
  191.     DoneFlag = false;
  192.     
  193.     for ( ;; ) {
  194.         if (DoneFlag) {
  195.             /*
  196.              * Quit has been requested, by the File/Quit menu, or perhaps
  197.              * by a fatal error somewhere else (missing resource, etc).
  198.              * Here we put up a Save Changes? DLOG, which also
  199.              * allows the Cancel buttion to set DoneFlag to false.
  200.              */
  201.             if (!DisposeAllWindows())    /* this releases stdplayer instances */
  202.               DoneFlag = false;            /* user pressed cancel maybe? */
  203.             else 
  204.               break;        /* from main event loop */
  205.         }
  206.         /*
  207.          * Main Event tasks:
  208.          */
  209.         SystemTask();
  210.         theActiveWindow = FrontWindow();        /* Used often, avoid repeated calls */
  211.  
  212.         Result = GetNextEvent(everyEvent, &myEvent);
  213.  
  214. /* When the movie controller is being used it is a good idea to let it handle the
  215.    updates for movies; to accomplish this the controller has to be given time every
  216.    pass through the event loop. If the controller handles the event then roll again
  217.    if not then we let the normal loop code take care of it.
  218. */
  219.         if (IsPlayerEvent(*(WindowPtr*) WindowList, &myEvent) ) 
  220.           continue;
  221.         if (Result ) { 
  222.           
  223.         switch (myEvent.what) {
  224.             case mouseDown:
  225.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  226.                     case inSysWindow:
  227.                         SystemClick(&myEvent, whichWindow);
  228.                         break;
  229.  
  230.                     case inMenuBar:
  231.                         {
  232.                         doCommand(MenuSelect(myEvent.where));
  233.                         }
  234.                         break;
  235.  
  236.                     case inDrag:
  237.                         DragWindow(whichWindow, myEvent.where, &dragRect);
  238.                         break;
  239.  
  240.                 case inGoAway:
  241.                     if (TrackGoAway(whichWindow, myEvent.where)) {
  242.                         DisposeOneWindow(whichWindow, closeMovie);
  243.                     }
  244.                     break;
  245.  
  246.                     case inGrow:
  247.                         /* There is no grow box. (Fall through) */
  248.  
  249.                     case inContent:
  250.                       if (whichWindow != theActiveWindow) {
  251.                             SelectWindow(whichWindow);
  252.                         }
  253.                     default:
  254.                         break;
  255.                     }/*endsw FindWindow*/
  256.                     break;
  257.  
  258.             case keyDown:
  259.             case autoKey:
  260.                     if (myEvent.modifiers & cmdKey) {
  261.                         AdjustMenus();
  262.                         doCommand(MenuKey(myEvent.message & charCodeMask));
  263.                     }
  264.                 break;
  265.                 
  266.             case activateEvt:
  267.                 break;
  268.  
  269.             case updateEvt:
  270.                 if ( IsAppWindow((WindowPtr) myEvent.message )) {
  271.                     BeginUpdate((WindowPtr) myEvent.message );
  272.                     SetPort((WindowPtr) myEvent.message);
  273.                     EraseRect(&(((GrafPtr) myEvent.message)->portRect));
  274.                     if (wHndl = (DocRecHandle)GetWRefCon((WindowPtr) myEvent.message) ) {
  275.                         UpdateMovie((*wHndl)->wMovie); 
  276.                     }
  277.                     EndUpdate((WindowPtr) myEvent.message );
  278.                 }
  279.             break;
  280.             case osEvt:
  281.               switch ((myEvent.message >> 24) & 0x0FF) {
  282.                     /* Must logical and with 0x0FF to get only low byte. */
  283.  
  284.                 case mouseMovedMessage:
  285.                     break;
  286.  
  287.                 case suspendResumeMessage:
  288.                     inBackground = !(myEvent.message & resumeFlag);
  289.                       DoScrapStuff(inBackground);
  290.                     break;
  291.             }
  292.             break;
  293.  
  294.             default:
  295.                 break;
  296.  
  297.         }/*endsw myEvent.what*/
  298.       AdjustMenus();
  299.     }
  300.     else {                 /* this is the place where you normally would call your idle routine */
  301. /*      DoIdleStuff(); */    /* to activate movies; in this case we let the standard controller     */
  302.     }                    /* do the idle stuff                                                 */
  303.  
  304.     }/*endfor Main Event loop*/
  305.     PrintTerminate();
  306.     ExitMovies();        /* make sure all references to this app are removed */
  307.     
  308.     return 0;        /* Return from main() to allow C runtime cleanup */
  309. }
  310.  
  311. /*******************************************************************************************
  312.  *******************************************************************************************/
  313.  
  314.  /* standard Macintosh routines */
  315.  
  316. void setupMenus()
  317. {
  318.     extern        MenuHandle    MyMenus[];
  319.     register    MenuHandle    *pMenu;
  320.  
  321.     /*
  322.      * Set up the desk accessories menu.
  323.      * The "About Sample..." item, followed by a grey line,
  324.      * is presumed to be already in the resource.  We then
  325.      * append the desk accessory names from the 'DRVR' resources.
  326.      */
  327.     MyMenus[appleMenu] = GetMenu(appleID);
  328.     AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
  329.     /*
  330.      * Now the  menus.
  331.      */
  332.  
  333.     MyMenus[fileMenu] = GetMenu(fileID);
  334.     MyMenus[editMenu] = GetMenu(editID);
  335.     MyMenus[moovieMenu] = GetMenu(moovieID);
  336.     MyMenus[pictsMenu] = GetMenu(pictsID);
  337.  
  338.     /*
  339.      * Now insert all of the application menus in the menu bar.
  340.      *
  341.      */
  342.     for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
  343.         InsertMenu(*pMenu, 0);
  344.     }
  345.  
  346.     DrawMenuBar();
  347.  
  348.     return;
  349. }
  350.  
  351. pascal Boolean AboutFilter(DialogPtr d, EventRecord *ev, short *item);
  352.  
  353. /* we use this filter proc to give time to the movie controller */
  354. pascal Boolean AboutFilter(DialogPtr d, EventRecord *ev, short *item)
  355. {
  356. #pragma unused(item);
  357.  
  358. MovieController mc;
  359. Boolean result;
  360.  
  361.     mc = (MovieController)GetWRefCon(d); /* get controller */
  362.     result = MCIsPlayerEvent(mc, ev);     /* and see if it wants to handle the event */
  363.  
  364.     return result;
  365. }
  366. /*
  367.  * Display the Sample Application dialog.
  368.  * If there is a window showing a movie we display it in the dialog.
  369.  * Then wait until the OK button is clicked before returning.
  370.  */
  371. void showAboutMeDialog()
  372. {
  373.     GrafPtr     savePort;
  374.     DialogPtr    theDialog;
  375.     short        itemType;
  376.     Handle        itemHdl;
  377.     Rect        itemRect;
  378.     short        itemHit;
  379.     MovieController 
  380.                 moovC;
  381.     WindowPtr     window;
  382.     DocRecHandle
  383.                 wHndl;
  384.     Boolean     doMovieStuff = false;
  385.     short         resID = 0;
  386.     Movie        moov;
  387.     OSErr        err;
  388.     ModalFilterProcPtr
  389.                 filter = nil;
  390.                 
  391.     GetPort(&savePort);
  392.  
  393.     if (window = FrontWindow()) { /* don't bother if no movies */
  394.       if (IsAppWindow(window)       /* make sure it is our window */
  395.           && (wHndl = (DocRecHandle)GetWRefCon(window)) /* and we have our data */
  396.           && ((*wHndl)->wFileInfo.sfr.sfFile.vRefNum != kInvalVRefNum) ) /* and this is not a window created with 'New Movie' which does not have a movie yet */
  397.         if ( err = NewMovieFromFile( &moov, (*wHndl)->wFileInfo.resFile, &resID, nil, newMovieActive, &wasChanged) ) {
  398.           DebugStr("\pCould not get the moov for dialog ");
  399.         }
  400.         else
  401.           doMovieStuff = true;
  402.     }
  403.  
  404.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  405.     SetPort(theDialog);
  406.  
  407.     GetDItem(theDialog, authorItem, &itemType, &itemHdl, &itemRect);
  408.     SetIText(itemHdl, "\pGuillermo A. Ortiz, MacDTS");
  409.     GetDItem(theDialog, languageItem, &itemType, &itemHdl, &itemRect);
  410.     SetIText(itemHdl, "\pC");
  411.  
  412.     GetDItem(theDialog, moovItem, &itemType, &itemHdl, &itemRect); /* get rect for movie */
  413.     if ( doMovieStuff ) {
  414.         SetMovieGWorld(moov, (CGrafPtr) theDialog, nil); /* point to the window */
  415.         SetMovieBox(moov,&itemRect);                     /* and the right place */
  416.         if (moovC = NewMovieController(moov, &itemRect, mcScaleMovieToFit+mcWithFrame) ) {/* get controller */            
  417.           if ( MCDoAction(moovC, mcActionPlay, (Ptr)0x00010000) ) /* set the movie in motion */
  418.             DebugStr("\pError at MCDoAction -> Play");
  419.           filter = (ModalFilterProcPtr)AboutFilter; /* put our proc in the filter pointer */
  420.           SetWRefCon(theDialog, (long)moovC);        /* we need this guy when in the filter proc */
  421.         }
  422.     }
  423.  
  424.     do {
  425.       ModalDialog(filter, &itemHit);
  426.     } while (itemHit != okButton);
  427.  
  428.     CloseDialog(theDialog);
  429.     if ( doMovieStuff ) {
  430.       DisposeMovieController(moovC);
  431.       DisposeMovie(moov);
  432.     }
  433.     SetPort(savePort);
  434.     return;
  435. }
  436.  
  437. /*
  438.  * Process mouse clicks in menu bar
  439.  */
  440.  
  441. Boolean hilited = false;
  442. void doCommand(mResult)
  443.     long    mResult;
  444. {
  445.     long                 theMenu, theItem;
  446.     char                daName[256];
  447.     GrafPtr             savePort;
  448.     extern MenuHandle    MyMenus[];
  449.     extern Boolean        DoneFlag;
  450.     extern void         showAboutMeDialog();
  451.  
  452.     theItem = LOWORD(mResult);
  453.     theMenu = HIWORD(mResult);        /* This is the resource ID */
  454.  
  455.     switch (theMenu) {
  456.         case appleID:
  457.             if (theItem == aboutMeCommand) {
  458.                 showAboutMeDialog();
  459.             } else {
  460.                 GetItem(MyMenus[appleMenu], theItem, daName);
  461.                 GetPort(&savePort);
  462.                 (void) OpenDeskAcc(daName);
  463.                 SetPort(savePort);
  464.             }
  465.             break;
  466.  
  467.         case fileID:
  468.             switch (theItem) {
  469.                 case newMovie:
  470.                      MakeNewMovie();
  471.                      break;
  472.                 case loadMovie:
  473.                      {
  474.                         myGetMoov();                        /* selects MooVie */
  475.                         break;
  476.                      }
  477.                 case closeMovie:
  478.                     DisposeOneWindow(FrontWindow(), closeMovie);
  479.                     break;
  480.                 case saveMovie:
  481.                     DoSave(saveMovie);
  482.                     break;
  483.                 case saveMovieAs:
  484.                     DoSave(saveMovieAs);
  485.                     break;
  486.                 case printCommand:
  487.                     PrintPoster();
  488.                     break;
  489.                 case pageCommand:
  490.                     PresentStyleDialog();
  491.                     break;
  492.                 case quitCommand:
  493.                     DoneFlag = true;            /* Request exit */
  494.                     break;
  495.                 default:
  496.                     break;
  497.             }
  498.             break;
  499.  
  500.         case editID:
  501.             /*
  502.              * If this is for a 'standard' edit item,
  503.              * run it through SystemEdit first.
  504.              * SystemEdit will return FALSE if it's not a system window.
  505.              */
  506.             if ((theItem <= selectAllCommand) && SystemEdit(theItem-1)) {
  507.                 break;
  508.             }
  509.             /* We will use the standard controller to do all the movie editing stuff     */
  510.             /* all this commands will affect the front most window only                 */
  511.             switch (theItem) {
  512.                 case undoCommand:
  513.                   DoUndoMovie();
  514.                   break;
  515.                 case cutCommand:
  516.                   DoCutMovie();
  517.                   break;
  518.                 case copyCommand:
  519.                   DoCopyMovie();
  520.                   break;
  521.                 case pasteCommand:
  522.                   DoPasteMovie();
  523.                   break;
  524.                 case clearCommand:
  525.                   DoClearMovie();
  526.                   break;
  527.                 case selectAllCommand:
  528.                   DoSelectAll();
  529.                   break;
  530.                 default:
  531.                     break;
  532.             } /*endsw theItem*/
  533.             break;
  534.  
  535.         case moovieID:
  536.             switch (theItem) {
  537.                 case stplayMovie:
  538.                      {
  539.                         ChangeMooVState();                        /* stop-start movie */
  540.                         break;
  541.                      }
  542.                 case soundMovie:
  543.                      {
  544.                         ChangeMooVSound();                        /* toggles sound */
  545.                         break;
  546.                      }
  547.                 case advFrMovie:
  548.                      {
  549.                         NextMooVFrame();                        /* advances one frame */
  550.                         break;
  551.                      }
  552.                 case revFrMovie:
  553.                      {
  554.                         PrevMooVFrame();                        /* moves one frame back */
  555.                         break;
  556.                      }
  557.                 case loopMovie:
  558.                      {
  559.                         SetMovieLoop(theItem);                    /* sets playback to loop */
  560.                         break;
  561.                      }
  562.                 case weirdLoopMovie:
  563.                      {
  564.                         SetMovieLoop(theItem);                    /* Loop back and forth */
  565.                         break;
  566.                      }
  567.                 case editMovie:
  568.                     {
  569.                         DoEnableEditing();
  570.                         break;
  571.                     }
  572.                 default:
  573.                     break;
  574.                 
  575.             }
  576.             break;
  577.  
  578.         case pictsID:
  579.             switch (theItem) {
  580.                 case getTrackPicts:
  581.                      {
  582. //                        DoGetTrackPicts();     /* uncomment if you want track picts */
  583.                         DoGetMoviePicts();   /* meanwhile get movie picts instead */
  584.                         break;
  585.                      }
  586.                 case get1MoviePict:
  587.                      {
  588.                         DoGet1MoviePict();        
  589.                         break;
  590.                      }
  591.                 default:
  592.                     break;
  593.                 
  594.             }
  595.             break;
  596.  
  597.         default:
  598.             break;
  599.  
  600.     }/*endsw theMenu*/
  601.  
  602.     HiliteMenu(0);
  603.  
  604.     return;
  605. }
  606.  
  607.  
  608. /*******************************************************************************************
  609.  *******************************************************************************************/
  610. /* the following code creates a new movie, it comes empty but you could use pastes to
  611.    add stuff to it.
  612.    
  613. */
  614. OSErr MakeNewMovie(void)
  615. {
  616. OSErr theErr;
  617. Movie newMoov;
  618. StandardFileReply fake;
  619. Str255 s1,s2="\pUntitled # ";
  620.  
  621.     if (theErr = CreateMinMovie(&newMoov)) {
  622.       DebugStr("\pmovie creation failed");    
  623.       return (theErr);
  624.     }
  625.     
  626.     NumToString(gUntitledCount,s1); /* get current untitled count     */
  627.     gUntitledCount++;                /* then bump it                    */
  628.     
  629.     pstrcat (s2, s1);
  630.     pstrcpy (fake.sfFile.name, s2);
  631.     
  632.     fake.sfFile.vRefNum = kInvalVRefNum;
  633.     
  634.     CreateOneWindow(newMoov, fake, kNoFileOpen, kNoResourceYet);
  635.     ClearMovieChanged(newMoov);
  636. }
  637.  
  638. /*******************************************************************************************
  639.  *******************************************************************************************/
  640.  
  641. void myGetMoov(void)
  642. {
  643. SFTypeList myFileTypes = {'MooV'};
  644. StandardFileReply reply;
  645. Point where = {20,20};
  646.  
  647. short    saveResFile, movieResFile;
  648. OSErr err;
  649.  
  650. Rect    moovBox;
  651. Movie moov;
  652. short resID = 0;
  653.  
  654.  
  655. saveResFile = CurResFile();
  656. StandardGetFilePreview(0L, 1, myFileTypes, &reply);
  657.  
  658. if (reply.sfGood)
  659.   { 
  660.  
  661.  
  662. /* we will open the file with read permission and ask for no MoviesDataRef 
  663.    which is necessary when adding stuff to a movie */
  664. /****** OpenMovieFile lost the last parameter 08/06/91 
  665.     if ( OpenMovieFile(&(reply.sfFile), &movieResFile,fsRdPerm, nil) ) {
  666. */
  667.     if ( OpenMovieFile(&(reply.sfFile), &movieResFile,fsRdWrPerm) ) {
  668.         SysBeep(10);        /* cheap way of saying 'I couldn't open the file     */
  669.         return;                /* and go back                                        */
  670.     }
  671.     else { /* the deal is that a file is selected but you do not know the moov id; 
  672.             so we pass 0 for id to get the first moov resource available 
  673.             (we do nothing with the returned ID, we could pass nil), nil for name pointer
  674.             and 0 for flags since I want a complete movie and don't want it to be active     */
  675.  
  676.       if ( err = NewMovieFromFile( &moov, movieResFile, &resID, nil, 0, &wasChanged) ) {
  677.         DebugStr("\pCould not get the moov ");
  678.       }
  679. /* We allow for editing files so we don't close the files after getting the movie.
  680.    This change reflects in the permision for OpenMovieFile above.
  681.     CloseMovieFile(movieResFile);
  682. */
  683.     }
  684.  
  685.     if ( !err ) { 
  686.         GetMovieBox(moov,&moovBox); /* Use the movie box to resize window */
  687.         OffsetRect(&moovBox, -moovBox.left, -moovBox.top);  /* force topleft to zero */
  688.         SetMovieBox(moov, &moovBox);
  689.  
  690.         CreateOneWindow(moov, reply, movieResFile, resID);
  691.  
  692.         SetMovieActive(moov,true);  /* we got the movie inactive */
  693.         if (err = GetMoviesError() )
  694.             DebugStr("\perror after SetMovieActive"); 
  695.  
  696. /* When using the controller you want to make all calls that affect the state of the
  697.    movie through the controller action calls; if you don't the controller could go
  698.    off sync. For example, instead of calling StartMovie, you call
  699.    MCDoAction((*DocHandle)->wPlayer, mcActionPlay, (Ptr)0x00010000) in order to
  700.    set the movie in motion. Check the routine CreateOneWindow in SimpleInWindows.c.
  701.  
  702.         if (! err) {
  703.             StartMovie(moov);                    **** if we do this then the movie will be
  704.             if (err = GetMoviesError() )        **** playing but the start button will show 
  705.                 DebugStr("\perror after startmovie");
  706.         }
  707. */
  708.     }
  709.   }
  710. UseResFile(saveResFile); /* Just in case */
  711.  
  712. }
  713.  
  714.  
  715. /*******************************************************************************************
  716.  *******************************************************************************************/
  717. /* If an app is not using the standard controller it has to call MoviesTask in order to     */
  718. /* let the Movie Toolbox animate the movies. In this sample DoIdleStuff is not called        */
  719. void DoIdleStuff(void)
  720. {
  721. OSErr err;
  722. WindowPtr window;
  723.  
  724.   if (window = FrontWindow()) { /* don't bother if no movies to play */
  725.     MoviesTask((Movie) 0, 500);    /* but since we have one service all */    
  726.     if (err = GetMoviesError() )
  727.       DebugStr("\pafter MoviesTask");         
  728.   }
  729. }
  730.  
  731.  
  732. /*******************************************************************************************
  733.  *******************************************************************************************/
  734.  
  735. /* this enables/disables menu items as the state of the current front most
  736.    movie requires. 
  737. */
  738. void AdjustMenus()
  739. {
  740. WindowPtr window;
  741. DocRecHandle wHndl;
  742. long mcInfo;
  743.  
  744.   if (window = FrontWindow()) { /* don't bother if no movies to play */
  745.     if (IsAppWindow(window) && (wHndl = (DocRecHandle)GetWRefCon(window)) ) {
  746.       EnableItem(MyMenus[moovieMenu],nil);
  747.       EnableItem(MyMenus[pictsMenu],nil);
  748.       EnableItem(MyMenus[editMenu],nil);
  749.       DrawMenuBar();
  750.       
  751.       if ( MCGetControllerInfo((*wHndl)->wPlayer, &mcInfo) )
  752.         DebugStr("\pCould not get controller info");
  753.     
  754.     /* Check Edit menu items */
  755.       if ( mcInfo & mcInfoEditingEnabled) { /* fix edit menu items */
  756.         if ( mcInfo & mcInfoUndoAvailable)
  757.           EnableItem(MyMenus[editMenu],undoCommand);
  758.         else
  759.           DisableItem(MyMenus[editMenu],undoCommand);
  760.           
  761.         if ( mcInfo & mcInfoCutAvailable)
  762.           EnableItem(MyMenus[editMenu],cutCommand);
  763.         else
  764.           DisableItem(MyMenus[editMenu],cutCommand);
  765.           
  766.         if ( mcInfo & mcInfoCopyAvailable)
  767.           EnableItem(MyMenus[editMenu],copyCommand);
  768.         else
  769.           DisableItem(MyMenus[editMenu],copyCommand);
  770.           
  771.         if ( mcInfo & mcInfoClearAvailable)
  772.           EnableItem(MyMenus[editMenu],clearCommand);
  773.         else
  774.           DisableItem(MyMenus[editMenu],clearCommand);
  775.           
  776.         if ( cuts /* mcInfo & mcInfoPasteAvailable */)
  777.           EnableItem(MyMenus[editMenu],pasteCommand);
  778.         else
  779.           DisableItem(MyMenus[editMenu],pasteCommand);
  780.           
  781.         EnableItem(MyMenus[editMenu],selectAllCommand); /* and last */
  782.           
  783.       }
  784.       else
  785.         DisableItem(MyMenus[editMenu],nil); /* no editing happening */
  786.     
  787.     
  788.     /* Check Movie menu items */
  789.     /* fix sound item according to front most window */
  790.       if ( mcInfo & mcInfoHasSound ) {
  791.         EnableItem(MyMenus[moovieMenu],soundMovie);
  792.         if ( GetMovieVolume((*wHndl)->wMovie) > 0) { /* fix sound menu item*/
  793.           SetItem(MyMenus[moovieMenu], soundMovie,"\pSound Off");
  794.         }
  795.         else  { 
  796.           SetItem(MyMenus[moovieMenu], soundMovie,"\pSound On");
  797.         }
  798.       }
  799.       else
  800.         DisableItem(MyMenus[moovieMenu],soundMovie);
  801.         
  802.       if ( mcInfo & mcInfoEditingEnabled) { /* fix edit menu item*/
  803.         SetItem(MyMenus[moovieMenu], editMovie,"\pDisable Edits");
  804.       }
  805.       else  { 
  806.         SetItem(MyMenus[moovieMenu], editMovie,"\pEnable Edits");
  807.       }
  808.       
  809.       if ( mcInfo & mcInfoIsPlaying ) {/* fix motion menu item */
  810.         SetItem(MyMenus[moovieMenu], stplayMovie,"\pStop Movie");
  811.       }
  812.       else  { 
  813.         SetItem(MyMenus[moovieMenu], stplayMovie,"\pStart Movie");
  814.       }
  815.  
  816.       /* loop menu items */
  817.  
  818.       CheckItem(MyMenus[moovieMenu], loopMovie,( (mcInfo & mcInfoIsLooping) != 0));
  819.       
  820.       if ((mcInfo & mcInfoIsLooping))
  821.         EnableItem(MyMenus[moovieMenu], weirdLoopMovie);
  822.       else
  823.         DisableItem(MyMenus[moovieMenu], weirdLoopMovie);
  824.  
  825.       CheckItem(MyMenus[moovieMenu], weirdLoopMovie,((mcInfo & mcInfoIsInPalindrome) != 0));
  826.       
  827.       EnableItem(MyMenus[fileMenu],closeMovie);    
  828.       EnableItem(MyMenus[fileMenu],saveMovie);    
  829.       EnableItem(MyMenus[fileMenu],saveMovieAs);    
  830.     }
  831.   }
  832.   else {
  833.     DisableItem(MyMenus[fileMenu],closeMovie);
  834.     DisableItem(MyMenus[fileMenu],saveMovie);
  835.     DisableItem(MyMenus[fileMenu],saveMovieAs);
  836.     DisableItem(MyMenus[editMenu],nil);
  837.     DisableItem(MyMenus[moovieMenu],nil);
  838.     DisableItem(MyMenus[pictsMenu],nil);
  839.  }
  840. }
  841.  
  842. /*******************************************************************************************
  843.  *******************************************************************************************/
  844.  
  845. OSErr CreateMinMovie(moovPtr)
  846. Movie *moovPtr;
  847. {
  848. Movie localMovie;
  849. OSErr theErr;
  850.  
  851.     localMovie = NewMovie(newMovieActive /* newMovieFlags */);
  852.     if (theErr = GetMoviesError() ) {
  853.       *moovPtr = nil;
  854.       DebugStr("\pCould not create movie");
  855.     }
  856.     else
  857.       *moovPtr = localMovie;
  858.     return (theErr);
  859. }
  860.  
  861. /*******************************************************************************************
  862.  *******************************************************************************************/
  863.  
  864.