Completed Lab/Events.c

// Play Movie with Controller Sample
// Based on QTShell
// WWDC 2000
 
#include "ComApplication.h"
#include "ComFramework.h"
#include "MacFramework.h"
 
//////////
//
// ActivateController
// Activate or deactivate the movie controller in the specified window.
//
//////////
 
void ActivateController (WindowReference theWindow, Boolean IsActive)
{
    WindowObject        myWindowObject = NULL;
    MovieController     myMC = NULL;
    GrafPtr             mySavedPort = NULL;
    
    if (theWindow == NULL)
        return;
    
    GetPort(&mySavedPort);
    MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
    
    // get the window object associated with the specified window
    myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
    if (myWindowObject != NULL) {
        myMC = (**myWindowObject).fController;
        if (myMC != NULL)
            MCActivate(myMC, QTFrame_GetWindowFromWindowReference(theWindow), IsActive);
    }
    
    MacSetPort(mySavedPort);
}
 
//////////
//
// Draw
// Update the specified window.
//
//////////
 
void Draw (WindowReference theWindow, Rect *theRefreshArea)
{
#pragma unused(theRefreshArea)
 
    GrafPtr             mySavedPort;
    
    GetPort(&mySavedPort);
    MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
    
    BeginUpdate(QTFrame_GetWindowFromWindowReference(theWindow));
    //EraseRect(theRefreshArea);        // this is important only for non-rectangular movies
    
    // ***insert application-specific drawing here***
    
    // draw the movie controller and its movie
    MCDoAction(QTFrame_GetMCFromWindow(theWindow), mcActionDraw, theWindow);
    
    EndUpdate(QTFrame_GetWindowFromWindowReference(theWindow));
    MacSetPort(mySavedPort);
}
 
//////////
//
// CheckMovieControllers
// Let all movie controllers have a chance to process the event.
//
// Returns true if the event was handled by some movie controller, false otherwise
//
//////////
 
Boolean CheckMovieControllers (EventRecord *theEvent)
{   
    WindowPtr               myWindow = NULL;
    MovieController         myMC = NULL;
    
    myWindow = QTFrame_GetFrontMovieWindow();
    while (myWindow != NULL) {
        myMC = QTFrame_GetMCFromWindow(myWindow);
        if (myMC != NULL)
            if (MCIsPlayerEvent(myMC, theEvent))
                return(true);
        
        myWindow = QTFrame_GetNextMovieWindow(myWindow);
    }
    
    return(false);
}