home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / Programming Stuff / Sample Code / Movie Toolbox / MyMultipleMoviesApp ƒ / MyMovieStuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-14  |  7.7 KB  |  294 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        MyMovieStuff.c
  3.     
  4.     Contains:    My Application 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>        03/14/94    JW        Re-Created for Universal Headers.
  13.  
  14.     To Do:
  15.     
  16. */
  17.  
  18. #ifdef THINK_C
  19. #define        applec
  20. #endif
  21.  
  22. #include    <Types.h>
  23. #include    <Memory.h>
  24. #include    <QuickDraw.h>
  25. #include    <Palettes.h>
  26. #include    <QDOffscreen.h>
  27. #include    <Errors.h>
  28. #include    <Fonts.h>
  29. #include    <Dialogs.h>
  30. #include    <Windows.h>
  31. #include    <Menus.h>
  32. #include    <Events.h>
  33. #include    <Desk.h>
  34. #include    <DiskInit.h>
  35. #include    <OSUtils.h>
  36. #include    <Resources.h>
  37. #include    <ToolUtils.h>
  38. #include    <AppleEvents.h>
  39. #include    <EPPC.h>
  40. #include    <GestaltEqu.h>
  41. #include    <Processes.h>
  42. #include    <Balloons.h>
  43. #include    <Aliases.h>
  44. #include    <MixedMode.h>
  45. #include    <Scrap.h>
  46. #include    <LowMem.h>
  47.  
  48. #include    <Movies.h>
  49.  
  50. #include    "MyApplication Shell (2.0).h"
  51. #include    "MyApplication.h"
  52. #include    "BetterFlattenMovie.h"
  53. #include    "MyMovieStuff.h"
  54.  
  55. /* ------------------------------------------------------------------------- */
  56.  
  57. void adjustMoviesMenu(WindowPtr theWindow)
  58. {
  59.     WindowInfoHandle    myWinfo;
  60.     FSSpec                theFSSpec;
  61.     short                theRefNum;
  62.     MenuHandle            myMenu;
  63.     short                movieCount;
  64.     Handle                movieResource;
  65.     short                movieID;
  66.     ResType                movieType;
  67.     Str255                movieName;
  68.     short                i;
  69.     
  70.     //    Delete old menu if it exists.
  71.     if (myMenu = GetMHandle(kMENU_MOVIES)) {
  72.         DeleteMenu(kMENU_MOVIES);
  73.         DisposeMenu(myMenu);
  74.     }
  75.  
  76.     //    If a window is passed, then update the menu for it.
  77.     if (IsMyWindow(theWindow)) {
  78.         myWinfo = (WindowInfoHandle) GetWRefCon(theWindow);
  79.         theFSSpec = (**myWinfo).theFSSpec;
  80.         theRefNum = (**myWinfo).refNum;
  81.         myMenu = NewMenu(kMENU_MOVIES, theFSSpec.name);
  82.         InsertMenu(myMenu, 0);
  83.         
  84.         //    Add resource fork movies into menu.
  85.         if (theRefNum != -1) {
  86.             movieCount = Count1Resources('moov');
  87.             for (i=1; i<=movieCount; i++) {
  88.                 movieResource = Get1IndResource('moov', i);
  89.                 GetResInfo(movieResource, &movieID, &movieType, movieName);
  90.                 if (movieName[0] == 0) {
  91.                     NumToString(movieID, &movieName[23]);
  92.                     movieName[0] = movieName[23] + 23;
  93.                     BlockMove("Resource Fork Movie ID#", &movieName[1], 23);
  94.                 }
  95.                 AppendMenu(myMenu, movieName);
  96.                 ReleaseResource(movieResource);
  97.             }
  98.         }
  99.         
  100.         //    Add single fork movies into menu.
  101.         if (CountMoviesInDataFork(&theFSSpec, &movieCount) == noErr) {
  102.             for (i=0; i<movieCount; i++) {
  103.                 NumToString(i+1, &movieName[19]);
  104.                 movieName[0] = movieName[19] + 19;
  105.                 BlockMove("Single Fork Movie #", &movieName[1], 19);
  106.                 AppendMenu(myMenu, movieName);
  107.             }
  108.         }
  109.     }
  110.  
  111.     //    Update MenuBar.
  112.     DrawMenuBar();
  113. }
  114.  
  115. void SelectThisMovie(short item)
  116. {
  117.     OSErr                err;
  118.     WindowPtr            frontWindow;
  119.     WindowInfoHandle    myWinfo;
  120.     short                resCount, dataCount;
  121.     Handle                movieResource;
  122.     short                movieID;
  123.     ResType                movieType;
  124.     long                 controllerFlags;
  125.     Rect                movieBounds;
  126.     short                i, xoffset, yoffset;
  127.     Str255                junkStr;
  128.     short                myRefNum;
  129.     Movie                tempMovie;
  130.     short                tempResId;
  131.     long                tempMovieOffset;
  132.     
  133.     if ((frontWindow = FrontWindow()) == nil)
  134.         return;
  135.         
  136.     if (IsMyWindow(frontWindow)) {
  137.         myWinfo = (WindowInfoHandle) GetWRefCon(frontWindow);
  138.  
  139.         //    Get rid of old movie
  140.         if ((**myWinfo).theMC != nil)
  141.             DisposeMovieController((**myWinfo).theMC);
  142.         if ((**myWinfo).theMovie != nil)
  143.             DisposeMovie((**myWinfo).theMovie);
  144.         (**myWinfo).theMovie = nil;
  145.         (**myWinfo).theMC = nil;
  146.         (**myWinfo).moviename[0] = 0;
  147.         (**myWinfo).resId = -1;
  148.         (**myWinfo).movieOffset = -1;
  149.  
  150.         //    Invalidate window.
  151.         InvalRect(&(frontWindow->portRect));
  152.         
  153.         //    Count the number of movies in resource fork and data fork
  154.         resCount = Count1Resources('moov');
  155.         CountMoviesInDataFork(&((**myWinfo).theFSSpec), &dataCount);
  156.  
  157.         //    Find which movie to play.
  158.         if (item <= resCount) {
  159.             movieResource = Get1IndResource('moov', item);
  160.             GetResInfo(movieResource, &tempResId, &movieType, (**myWinfo).moviename);
  161.             ReleaseResource(movieResource);
  162.             err = NewMovieFromFile(&tempMovie, (**myWinfo).refNum, &tempResId, nil,
  163.                                 newMovieActive, (Boolean *) 0);
  164.             (**myWinfo).theMovie = tempMovie;
  165.             (**myWinfo).resId = tempResId;
  166.             if (err) {
  167.                 Alert(kALERT_CANTOPEN, nil);
  168.                 return;
  169.             }
  170.         } else {
  171.             item = item-resCount;
  172.             err = SearchMoviesInDataFork(&((**myWinfo).theFSSpec), item, &tempMovieOffset);
  173.             (**myWinfo).movieOffset = tempMovieOffset;
  174.             if (err) {
  175.                 Alert(kALERT_CANTOPEN, nil);
  176.                 return;
  177.             }
  178.             if (FSpOpenDF(&((**myWinfo).theFSSpec), fsRdPerm, &myRefNum) == noErr) {
  179.                 err = NewMovieFromDataFork(&tempMovie, myRefNum, (**myWinfo).movieOffset, newMovieActive, nil);
  180.                 (**myWinfo).theMovie = tempMovie;
  181.                 FSClose(myRefNum);
  182.                 if (err) {
  183.                     Alert(kALERT_CANTOPEN, nil);
  184.                     return;
  185.                 }
  186.             }
  187.         }
  188.         
  189.         //    Set the movie box into middle of window.
  190.         SetMovieGWorld((**myWinfo).theMovie, (CGrafPtr) frontWindow, 0);
  191.         GetMovieBox((**myWinfo).theMovie, &movieBounds);
  192.         OffsetRect(&movieBounds, -movieBounds.left, -movieBounds.top);
  193.         SetMovieBox((**myWinfo).theMovie, &movieBounds);
  194.         xoffset = (frontWindow->portRect.right - frontWindow->portRect.left
  195.                      - movieBounds.right + movieBounds.left) / 2;
  196.         yoffset = (frontWindow->portRect.bottom - frontWindow->portRect.top
  197.                      - movieBounds.bottom + movieBounds.top) / 2;
  198.         OffsetRect(&movieBounds, xoffset, yoffset);
  199.         (**myWinfo).theMC = NewMovieController((**myWinfo).theMovie, &movieBounds, mcTopLeftMovie);
  200.     
  201.         //    Tell the controller to attach a movie’s CLUT to the window as appropriate.
  202.         MCDoAction((**myWinfo).theMC, mcActionGetFlags, &controllerFlags);
  203.         MCDoAction((**myWinfo).theMC, mcActionSetFlags, (void *)(controllerFlags | mcFlagsUseWindowPalette));
  204.     
  205.         //    Allow the controller to accept keyboard events.
  206.         MCDoAction((**myWinfo).theMC, mcActionSetKeysEnabled, (void *)true);
  207.     }    
  208. }
  209.  
  210. void getNewMovie(Movie *theMovie, Str255 *movieName)
  211. {
  212.     StandardFileReply        reply;
  213.     SFTypeList                types;
  214.     short                    refNum, resId;
  215.     
  216.     *theMovie = nil;
  217.     
  218.     types[0] = 'MooV';
  219.     StandardGetFilePreview(nil, 1, types, &reply);
  220.     if (!reply.sfGood) return;
  221.     
  222.     //    Read movie atom of source movie.
  223.     if (OpenMovieFile(&reply.sfFile, &refNum, fsRdPerm)) {
  224.         SysBeep(50);
  225.         return;
  226.     }
  227.     resId = 0;
  228.     (*movieName)[0] = 0;
  229.     if (NewMovieFromFile(theMovie, refNum, &resId, *movieName, 0, (Boolean *) 0)) {
  230.         SysBeep(50);
  231.         *theMovie = nil;
  232.         return;
  233.     }
  234.     if ((*movieName)[0] == 0)
  235.         BlockMove(reply.sfFile.name, *movieName, reply.sfFile.name[0]+1);
  236.     CloseMovieFile(refNum);
  237. }
  238.  
  239. void Mac_AddMovieResAtom(short *docRefNum, FSSpec *docFSSpec)
  240. {
  241.     Movie                    theMovie;
  242.     Str255                    movieName;
  243.     short                    resId;
  244.  
  245.     getNewMovie(&theMovie, &movieName);    
  246.     if (theMovie != nil) {
  247.         resId = 0;
  248.         AddMovieResource(theMovie, *docRefNum, &resId, movieName);
  249.         DisposeMovie(theMovie);
  250.     }
  251. }
  252.  
  253. void Mac_AddMovieAll(short *docRefNum, FSSpec *docFSSpec)
  254. {
  255.     Movie                    theMovie;
  256.     Str255                    movieName;
  257.  
  258.     getNewMovie(&theMovie, &movieName);    
  259.     if (theMovie != nil) {
  260.         CloseMovieFile(*docRefNum);
  261.         BetterFlattenMovie(theMovie, 0, docFSSpec, 'WnG1', smSystemScript, 0, nil, movieName);
  262.         OpenMovieFile(docFSSpec, docRefNum, fsRdWrPerm);
  263.         DisposeMovie(theMovie);
  264.     }
  265. }
  266.  
  267. void Cross_AddMovieAll(short *docRefNum, FSSpec *docFSSpec)
  268. {
  269.     Movie                    theMovie;
  270.     Str255                    movieName;
  271.  
  272.     getNewMovie(&theMovie, &movieName);    
  273.     if (theMovie != nil) {
  274.         CloseMovieFile(*docRefNum);
  275.         BetterFlattenMovieData(theMovie, flattenAddMovieToDataFork, docFSSpec, 'WnG1', smSystemScript, 0);
  276.         OpenMovieFile(docFSSpec, docRefNum, fsRdWrPerm);
  277.         DisposeMovie(theMovie);
  278.     }
  279. }
  280.  
  281. void Both_AddMovieAll(short *docRefNum, FSSpec *docFSSpec)
  282. {
  283.     Movie                    theMovie;
  284.     Str255                    movieName;
  285.  
  286.     getNewMovie(&theMovie, &movieName);    
  287.     if (theMovie != nil) {
  288.         CloseMovieFile(*docRefNum);
  289.         BetterFlattenMovie(theMovie, flattenAddMovieToDataFork, docFSSpec, 'WnG1', smSystemScript, 0, nil, movieName);
  290.         OpenMovieFile(docFSSpec, docRefNum, fsRdWrPerm);
  291.         DisposeMovie(theMovie);
  292.     }
  293. }
  294.