home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 January / macformat-033.iso / mac / Shareware City / Developers / ABox.v1.8 / CPlus Files / ABMovieTopic.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-23  |  11.5 KB  |  528 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc.
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABMovieTopic.c
  15.  
  16. NAME
  17.     ABMovieTopic.c, part of the ABox project source code,
  18.     responsible for handling the ABMovieTopic class stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                netromancr@aol.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.  
  29. CARETAKER - George (ty) Tempel <netromancr@aol.com>
  30.      Please consult this person for any changes or suggestions to this file.
  31.  
  32. MODIFICATION HISTORY
  33.  
  34.     dd mmm yy    -    xxx    -    patchxx: description of patch
  35.     24 June 94    -    ty    -    Initial Version Created
  36.     20-july-94    -    ty    -    initial version released
  37.     28-july-94    -    ty    -    1.0.6 -- removed cursor flipping from Load
  38.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  39.                             release and the associated Universal Headers from Apple:
  40.                             most methods that returned references now have "Ref" at
  41.                             the end of their methods names to prevent possible collisions
  42.                             with datatypes and classes of the same name (older versions
  43.                             of the compiler didn't have a problem with this).
  44.  
  45. */
  46.  
  47. /*===========================================================================*/
  48.  
  49. /*======= Segmentation directives ========*/
  50.  
  51. #ifdef USE_MANUAL_SEGMENTATION
  52. #pragma segment ty
  53. #endif
  54.  
  55. /*============ Header files ==============*/
  56.     
  57. #include     "ABMovieTopic.h"
  58. #include    "ABoxDefs.h"
  59.  
  60.  
  61. /*=============== Globals ================*/
  62.  
  63. /*================ CODE ==================*/
  64.  
  65.  
  66. /*=============================== ABMovieTopic::ABMovieTopic ================================*/
  67. ABMovieTopic::ABMovieTopic(const FSSpec& inTopicFSSpec)
  68.     :    ABTopic(inTopicFSSpec)
  69. {
  70.     this->ResetSlideInfo();
  71.  
  72.     mBoxRect.left = mBoxRect.right = mBoxRect.top = mBoxRect.bottom = 0;
  73.     this->TopicType() = ETopicType_MovieTopic;
  74. } // end ABMovieTopic
  75.  
  76.  
  77.  
  78.  
  79. /*=============================== ABMovieTopic::~ABMovieTopic ================================*/
  80. ABMovieTopic::~ABMovieTopic(void)
  81. {
  82.     this->Close();
  83.     
  84. } // end ~ABMovieTopic
  85.  
  86.  
  87.  
  88. /*=============================== ABMovieTopic::GetProperty ================================*/
  89. OSErr    ABMovieTopic::GetProperty(ABProperty prop, 
  90.                                 void *ptr, 
  91.                                 long *ptrSize)
  92. {
  93.     OSErr    error = noErr;
  94.     long    pSize;
  95.     
  96.     //    begin here...
  97.     
  98.     if (!ptr)
  99.         return kABPropertyNullStorage;
  100.     
  101.     switch (prop)
  102.     {
  103.         case    kABTopicIsMovie:
  104.                     *((Boolean *)ptr) = true;
  105.                     pSize = kABTopicIsMovieSize;
  106.                     break;
  107.         case    kABTopicHasMovieController:
  108.                     *((Boolean *)ptr) = this->HasController();
  109.                     pSize = kABTopicIsMovieSize;
  110.                     break;
  111.         case    kABMovieFile:
  112.                     ::BlockMove ((Ptr)this->FSSpecPointerRef(), (Ptr)ptr, kABMovieFileSize);
  113.                     pSize = kABMovieFileSize;
  114.                     break;
  115.         default:
  116.                     error = kABMovieTopicSuperProperties::GetProperty(prop, ptr, ptrSize);
  117.                     break;
  118.     } // end switch block
  119.     
  120.     if (ptrSize && !error)
  121.         *ptrSize = pSize;
  122.     return error;
  123.     
  124. } // end GetProperty
  125.  
  126.  
  127.  
  128.  
  129.  
  130. /*=============================== ABMovie::SetProperty ================================*/
  131. OSErr    ABMovieTopic::SetProperty(ABProperty prop, 
  132.                                 void *ptr, 
  133.                                 long ptrSize)
  134. {
  135.     OSErr            error = noErr;
  136.     Boolean            resolvedAliasChains = true,
  137.                     targetIsFolder = false,
  138.                     wasAliased = false;
  139.     
  140.     
  141.     //    begin here...
  142.     
  143.     if (!ptr)
  144.         return kABPropertyNullStorage;
  145.     
  146.     switch (prop)
  147.     {
  148.         case    kABTopicIsMovie:
  149.         case    kABTopicHasMovieController:
  150.                     error = kABPropertyReadOnly;
  151.                     break;
  152.  
  153.         case    kABMovieFile:
  154.                     {
  155.                         FSSpec    tFSS;
  156.                         
  157.                         ::BlockMove (ptr, (Ptr)&tFSS, kABMovieFileSize);
  158.                         
  159.                         error = ::ResolveAliasFile (&tFSS, 
  160.                                                     resolvedAliasChains, 
  161.                                                     &targetIsFolder, 
  162.                                                     &wasAliased);
  163.                         if (!error && targetIsFolder)
  164.                             error = this->CheckAndCopyFSSpec (tFSS);
  165.                             
  166.                     }
  167.                     break;
  168.         default:
  169.                     error = kABMovieTopicSuperProperties::SetProperty(prop, ptr, ptrSize);
  170.                     break;
  171.     } // end switch block
  172.     
  173.     return error;
  174.     
  175. } // end SetProperty
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. /*=============================== ABMovieTopic::Resize ===============================*/
  184. //
  185. //    this function will rearrange and resize the picture and the
  186. //    text fields that appear on a slide.
  187. //
  188. //    This method will cause the current slide for the
  189. //    topic to resize by invoking that item's resize method.
  190. //
  191. //    is called by:
  192. //
  193. OSErr    ABMovieTopic::Resize (Rect const *field)
  194. {
  195.     //    begin here...
  196.     
  197.     if (!field)
  198.         return paramErr;
  199.     else
  200.         this->BoxRectRef() = *field;
  201.         
  202.     return noErr;
  203. } // end of Resize
  204.  
  205.  
  206.  
  207.  
  208.  
  209. /*=============================== ABMovieTopic::OpenTopic ================================*/
  210. OSErr    ABMovieTopic::OpenTopic(void)
  211. {
  212.     OSErr        error = noErr;
  213.     short         movieResID = 0;
  214.     short        newMovieFlags = newMovieActive;
  215.     Boolean        dataRefWasChanged = false;
  216.  
  217.     //    begin here...
  218.     
  219.     //    now load the movie...
  220.     //
  221.     ABUCursor::WatchCursor();
  222.     error = ::OpenMovieFile(this->FSSpecPointerRef(), &(this->FileRefNumRef()), fsRdPerm);
  223.     if (error) 
  224.     {
  225.         //ABoxDebug(kABErrQuickTimeOpenMovieFile, error);
  226.         ABUCursor::ArrowCursor();
  227.         return error;
  228.     }    //    end if block    
  229.     
  230.     //
  231.     //    NEW_movieFile
  232.     //
  233.     //    the deal is that a file is selected but you do not know the moov id; 
  234.     //    so we pass 0 for id to get the first moov resource available 
  235.     //    (we do nothing with the returned ID, we could pass nil), nil for name pointer
  236.     //    and 0 for flags since I want a complete movie and don't want it to be active
  237.  
  238.     //ABoxDebugNew();
  239.     error =:: NewMovieFromFile( &(this->MovieRef()),                //    the movie
  240.                             this->FileRefNumRef(),            //    file reference number
  241.                             &movieResID,            //    resource id
  242.                             nil,                    //    resource name
  243.                             newMovieFlags,             //    newMovieFlags
  244.                             &dataRefWasChanged );    //    dataRefWasChanged
  245.  
  246.     ABUCursor::ArrowCursor();
  247.     if (error) 
  248.     {
  249.         //ABoxDebug(kABErrQuickTimeNewMovieFromFile, error);
  250.         return error;
  251.     }    //    end if block
  252.  
  253.     ::CloseMovieFile(this->FileRefNumRef());
  254.     this->ResetFileRefNum();
  255.     return error;
  256. } // end OpenTopic
  257.  
  258.  
  259.  
  260.  
  261.  
  262. /*=============================== ABMovieTopic::CloseTopic ================================*/
  263. OSErr    ABMovieTopic::CloseTopic(void)
  264. {
  265.     OSErr        error = noErr;
  266.  
  267.     //    begin here...
  268.     ABUCursor::WatchCursor();
  269.     error = this->Stop();
  270.     ABUCursor::ArrowCursor();
  271.     return error;
  272. } // end CloseTopic
  273.  
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280. /*=============================== ABMovieTopic::DoLoad ===============================*/
  281. //
  282. OSErr    ABMovieTopic::DoLoad (void)
  283. {
  284.     OSErr        error = noErr;
  285.     Boolean        fileOK = false;
  286.  
  287.     //    begin here...
  288.     //
  289.     if (!ABUEnvQuickTime::IsPresent())
  290.     {
  291.         return paramErr;
  292.     } else {
  293.         error = this->Initialize();
  294.     } // end if else block
  295.     
  296.     //    begin here...
  297.  
  298.     error = ::OpenMovieFile(this->FSSpecPointerRef(), &(this->FileRefNumRef()), fsRdPerm);
  299.     if (error) 
  300.     {
  301.         return error;
  302.     }    //    end if block    
  303.     
  304.     
  305.     ::CloseMovieFile(this->FileRefNumRef());
  306.     this->ResetFileRefNum();
  307.     //DisposeMovie(movie);
  308.     
  309.     return error;
  310.     
  311. }    //    end of function DoLoad
  312.  
  313.  
  314.  
  315. /*=============================== ABMovieTopic::DoCheckSlides ===============================*/
  316. //
  317. //    This function checks a file for the presense of a topic/slide definition
  318. //    resource and will an error type (OSErr)
  319. //
  320. //    is called by:
  321. //
  322. short    ABMovieTopic::DoCheckSlides (void)
  323. {
  324.     OSErr        error = noErr;
  325.     const short    hasNothing = 0;
  326.     const short    hasSomething = 1;
  327.     
  328.     //    begin here...
  329.     //
  330.     if (!ABUEnvQuickTime::IsPresent())
  331.         return hasNothing;
  332.     else
  333.         error = this->Initialize();
  334.     
  335.     error = this->OpenTopic();
  336.     if (error)
  337.     {
  338.         this->ResetFileInfo();
  339.         return hasNothing;
  340.     } // end if (error) block
  341.     
  342.     error = this->CloseTopic();
  343.     if (error)
  344.         return hasNothing;
  345.     else
  346.         return hasSomething;
  347.  
  348. }    //    end of function DoCheckSlides
  349.  
  350.  
  351.  
  352.  
  353.  
  354. /*=============================== ABMovieTopic::Draw ================================*/
  355. OSErr    ABMovieTopic::Draw(WindowPtr window)
  356. {
  357.     OSErr                error = noErr;
  358.     Rect                box;
  359.     
  360.     Rect                movieRect;
  361.     short                 movieResID = 0;
  362.     short                newMovieFlags = newMovieActive;
  363.     Boolean                dataRefWasChanged = false;
  364.     short                movieWidth,
  365.                         movieHeight;
  366.     
  367.     //    begin here...
  368.     
  369.     if (this->DoesntHaveFSSpecPointer())
  370.         return paramErr;
  371.     
  372.     if (!window)
  373.         return paramErr;
  374.         
  375.     if (this->DoesntHaveMovie())
  376.     {
  377.         return paramErr;
  378.     } // end if block
  379.     
  380.  
  381.     //    Draw a bezel around the field _including_ the scroll bar
  382.     //
  383.     box = this->BoxRectRef();
  384.     this->EraseFrame (box);
  385.     error = ABObject::Draw(window);
  386.     if (error != noErr)
  387.         return error;
  388.         
  389.     //    set up the area for the movie...
  390.     //
  391.     ::GetMovieBox (this->MovieRef(), &movieRect);
  392.     error = ::GetMoviesError();
  393.     if (error) 
  394.     {
  395.         error = this->Stop ();
  396.         return (error);
  397.     }    //    end if block
  398.  
  399.     error = this->ScaleRectToFit (movieRect, box, 1.0);
  400.     
  401.     movieWidth = movieRect.right - movieRect.left;
  402.     movieHeight = movieRect.bottom - movieRect.top;
  403.  
  404.     movieRect.left = box.left + ((box.right - box.left) - movieWidth)/2;
  405.     movieRect.right = movieRect.left + movieWidth;
  406.     movieRect.top = box.top + ((box.bottom - box.top) - movieHeight)/2;
  407.     movieRect.bottom = movieRect.top + movieHeight;
  408.     ::SetMovieBox (this->MovieRef(), &movieRect);
  409.  
  410.     ::SetMovieGWorld(this->MovieRef(), (CGrafPtr)window, NULL);            //    point to the window...
  411.     error = ::GetMoviesError();
  412.     if (error) 
  413.     {
  414.         error = this->Stop ();
  415.         return (error);
  416.     }    //    end if block
  417.  
  418.     //    1.0a3 ty ... additions for movie controller support
  419.     //
  420.     //ABoxDebugNew();
  421.     if (this->DoesntHaveController())
  422.         this->MovieControllerRef() = ::NewMovieController(this->MovieRef(), 
  423.                                         &movieRect, 
  424.                                         mcScaleMovieToFit | mcWithFrame);
  425.     if (this->HasController())
  426.     {
  427.         ::MCGetControllerBoundsRect(this->MovieControllerRef(), &movieRect);
  428.         
  429.         //    Peter Hoddie, Apple DTS, recommends in _develop_ #18
  430.         //    that this single line of code be used to activate
  431.         //    keyboard events for the controller.
  432.         //MCDoAction (controller, mcActionSetKeysEnabled, (void *)true);
  433.         
  434.         //    Peter also recommends turning on the movie controller
  435.         //    copy/cut/paste/clear functions via:
  436.         //MCEnableEditing(controller, true);
  437.         //    and supplying event processing in the event loop. I'll
  438.         //    provide this in the Event method below
  439.  
  440.     } // end if block
  441.     
  442.     error = this->Begin();
  443.     
  444.     return error;
  445.     
  446. } // end Draw
  447.  
  448.  
  449.  
  450.  
  451.  
  452. /*=============================== ABMovieTopic::Update ================================*/
  453. OSErr    ABMovieTopic::Update(WindowPtr /* window*/ )
  454. {
  455.     //    begin here...
  456.     //
  457.     Rect    box = this->BoxRectRef();
  458.     
  459.     this->DrawFrame (box);
  460.         
  461.     return noErr;
  462.     
  463. } // end Update
  464.  
  465.  
  466.  
  467.  
  468. /*=============================== ABMovieTopic::Event ================================*/
  469. Boolean    ABMovieTopic::Event(EventRecord *eventRec)
  470. {
  471.     OSErr    error = noErr;
  472.     
  473.     Boolean    test = false;                            //    1.0a4p3 ty...added variable
  474.     
  475.     //    begin here...
  476.     
  477.     if (!(ABUEnvQuickTime::IsPresent() && this->HasMovie())) 
  478.     {
  479.         return test;                                //    1.0a5 ty...changed to return test
  480.     }    //    end if block
  481.         
  482.     //    "play" the movie
  483.     //
  484.     if (this->HasController()) 
  485.     {
  486.         if (eventRec) 
  487.         {                                //    1.0a3    ty    ...    added check for event
  488.             test = ::MCIsPlayerEvent(this->MovieControllerRef(), eventRec);
  489.             
  490.         }    //    end if block
  491.     } else {
  492.         //    there is a movie, but the controller is defective, so give
  493.         //    some time to the movie.
  494.         //
  495.         test = ::IsMovieDone(this->MovieRef());
  496.         if (!test) 
  497.         {
  498.             ::MoviesTask(this->MovieRef(), kABserviceAllMovies);
  499.             test = true;
  500.         }    //    end if block
  501.     }    //    end if else block
  502.  
  503.     return test;
  504. } // end Event
  505.  
  506.  
  507.  
  508.  
  509.  
  510. /*=============================== ABMovieTopic::Stop ================================*/
  511. OSErr    ABMovieTopic::Stop(void)
  512. {
  513.     //    begin here...
  514.     //
  515.     this->CleanUp();
  516.     return noErr;
  517.     
  518. } // end Stop
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. //    end of file
  527.  
  528.