sources/WindowSupport.c

/*
    File:       WindowSupport.c
 
    Copyright:  © 2000-2001 by Apple Computer, Inc., all rights reserved.
 
 
*/
 
#include <ConditionalMacros.h>
#include <TextUtils.h>
 
#include <string.h>
 
#include <QuicktimeComponents.h>
#include <MoviesFormat.h>
#include <Movies.h>
 
#include <QuickTimeStreaming.h>
#include <QTStreamingComponents.h>
 
 
#include "AppSupport.h"
#include "QTSSampleCodeUtils.h"
#include "UsherCommands.h"
#include "WindowSupport.h"
 
// ----- window types we know about -----
 
#include "UsherMinWindow.h"
#include "PresInfoWindow.h"
    
// ---------------------------------------------------------------------------
//      D E F I N I T I O N S
// ---------------------------------------------------------------------------
 
#define kSignature_NotAStandardWindow       FOUR_CHAR_CODE('xstd')
 
// ---------------------------------------------------------------------------
//      P R O T O T Y P E S
// ---------------------------------------------------------------------------
 
// ---------------------------------------------------------------------------
//      WindowSupport_NewWindowOfType
// ---------------------------------------------------------------------------
 
OSErr WindowSupport_NewWindowOfType(OSType inWindowType, Boolean inUseAlt, WindowPtr *outWindow)
{
    OSErr       err = noErr;
    
    *outWindow = NULL;
    if (inWindowType == 0)  {
        inWindowType = kSignature_UsherMinWind;
    }
 
    switch (inWindowType)  {
        case kSignature_UsherMinWind:
            err = UsherMinWind_New(inUseAlt, outWindow);
            break;  
        case kSignature_PresInfoWind:
            err = PresInfoWind_New(outWindow);
            break;
 
        case kSignature_NoWindow:
            // this means don't make a window and don't return an error
            break;
 
        default:
            DEBUGF(("WindowSupport_NewWindowOfType - unknown type '%.4s'", &inWindowType));
            break;
    }
    return err;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_CloseWindow
// ---------------------------------------------------------------------------
 
void WindowSupport_CloseWindow(WindowPtr inWindow)
{
    OSType      windowType;
 
    if ( WindowSupport_IsAppWindow(inWindow) )  {
        windowType = WindowSupport_GetWindowType(inWindow);
        switch (windowType)  {
            case kSignature_UsherMinWind:
                UsherMinWind_Close(inWindow);
                break;      
            case kSignature_PresInfoWind:
                PresInfoWind_Close(inWindow);
                break;
        
            default:
                DEBUGF(("WindowSupport_CloseWindow $%.8x - unknown type '%.4s'", inWindow, &windowType));
                break;
        }
    }
    return;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_GetWindowType
// ---------------------------------------------------------------------------
 
OSType WindowSupport_GetWindowType(WindowPtr inWindow)
{
    OSType                  windowType = kSignature_NotAStandardWindow;
    StandardWindowPeek      windowPeek;
    
    if (inWindow == NULL)  {
        windowType = kSignature_NoWindow;   
    }  else  {
        windowPeek = (StandardWindowPeek)GetWRefCon(inWindow);
        if (windowPeek != 0)  {
            if (windowPeek->standardWindowSignature == kSignature_StandardWindow)  {
                windowType = windowPeek->signature;
            }
        }
    }
    return windowType;
}
 
#pragma mark -
 
// ---------------------------------------------------------------------------
//      WindowSupport_GrowWindow
// ---------------------------------------------------------------------------
 
void WindowSupport_GrowWindow(WindowPtr inWindow, EventRecord *inEvent)
{
    OSType      windowType;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            UsherMinWind_GrowWindow(inWindow, inEvent);
            break;
        case kSignature_PresInfoWind:
            PresInfoWind_GrowWindow(inWindow, inEvent);
            break;
    
        default:
            DEBUGF(("WindowSupport_GrowWindow $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
    return;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_DoContentClick
// ---------------------------------------------------------------------------
 
void WindowSupport_DoContentClick(WindowPtr inWindow, EventRecord *inEvent)
{
    OSType      windowType;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            UsherMinWind_DoContentClick(inWindow, inEvent);
            break;
        case kSignature_PresInfoWind:
            PresInfoWind_DoContentClick(inWindow, inEvent);
            break;
    
        default:
            DEBUGF(("WindowSupport_DoContentClick $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
    return;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_ActivateWindow
// ---------------------------------------------------------------------------
 
void WindowSupport_ActivateWindow(WindowPtr inWindow, Boolean inBecomingActive)
{
    OSType      windowType;
 
    SetPortWindowPort( inWindow );
    if (WindowSupport_IsAppWindow(inWindow)) {
        windowType = WindowSupport_GetWindowType(inWindow);
        switch (windowType)  {
            case kSignature_UsherMinWind:
                UsherMinWind_ActivateWindow(inWindow, inBecomingActive);
                break;
            case kSignature_PresInfoWind:
                PresInfoWind_ActivateWindow(inWindow, inBecomingActive);
                break;
        
            default:
                DEBUGF(("WindowSupport_ActivateWindow $%.8x - unknown type '%.4s'", inWindow, &windowType));
                break;
        }
    }
    return;
}
 
 
// ---------------------------------------------------------------------------
//      WindowSupport_Draw
// ---------------------------------------------------------------------------
 
void WindowSupport_Draw(WindowPtr inWindow)
{
    OSType      windowType;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            UsherMinWind_Draw(inWindow);
            break;
        case kSignature_PresInfoWind:
            PresInfoWind_Draw(inWindow);
            break;
    
        default:
            DEBUGF(("WindowSupport_Draw $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
    return;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_DoUpdate
// ---------------------------------------------------------------------------
 
void WindowSupport_DoUpdate(WindowPtr inWindow)
{
    OSType      windowType;
 
    windowType = WindowSupport_GetWindowType(inWindow);
 
    SetPortWindowPort(inWindow);
    BeginUpdate(inWindow);
 
    switch (windowType)  {
        case kSignature_UsherMinWind:
            UsherMinWind_Draw(inWindow);
            break;
        case kSignature_PresInfoWind:
            PresInfoWind_Draw(inWindow);
            break;
    
        default:
            DEBUGF(("WindowSupport_DoUpdate $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
 
    EndUpdate(inWindow);
    return;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_HandleMessage
// ---------------------------------------------------------------------------
 
OSErr WindowSupport_HandleMessage(WindowPtr inWindow, long inMessage, void *inMessageParams)
{
    OSType      windowType;
    OSErr       err = noErr;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            err = UsherMinWind_HandleMessage(inWindow, inMessage, inMessageParams);
            break;
        case kSignature_PresInfoWind:
            err = PresInfoWind_HandleMessage(inWindow, inMessage, inMessageParams);
            break;
    
        default:
            err = qtsBadSelectorErr;
            DEBUGF(("WindowSupport_DoUpdate $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
    return err;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_GetMenuCommand
// ---------------------------------------------------------------------------
 
long WindowSupport_GetMenuCommand(WindowPtr inWindow, long inMenuResult, void **outCommandParams)
{
    OSType      windowType;
    long        command = kCommand_Nothing;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            command = UsherMinWind_GetMenuCommand(inWindow, inMenuResult, outCommandParams);
            break;
        case kSignature_PresInfoWind:
            command = PresInfoWind_GetMenuCommand(inWindow, inMenuResult, outCommandParams);
            break;
    
        default:
            DEBUGF(("WindowSupport_GetMenuCommand $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
    return command;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_DoCommand
// ---------------------------------------------------------------------------
 
OSErr WindowSupport_DoCommand(WindowPtr inWindow, long inCommand, void *inCommandParams)
{
    OSType      windowType;
    OSErr       err = noErr;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            err = UsherMinWind_DoCommand(inWindow, inCommand, inCommandParams);
            break;
        case kSignature_PresInfoWind:
            err = PresInfoWind_DoCommand(inWindow, inCommand, inCommandParams);
            break;
    
        default:
            DEBUGF(("WindowSupport_DoCommand $%.8x - unknown type '%.4s'", inWindow, &windowType));
            err = kErr_AppUnhandledCommand;
            break;
    }
    return err;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_Idle
// ---------------------------------------------------------------------------
 
void WindowSupport_Idle(WindowPtr inWindow)
{
    OSType      windowType;
 
    windowType = WindowSupport_GetWindowType(inWindow);
    switch (windowType)  {
        case kSignature_UsherMinWind:
            UsherMinWind_Idle(inWindow);
            break;
        case kSignature_PresInfoWind:
            PresInfoWind_Idle(inWindow);
            break;
    
        default:
            DEBUGF(("WindowSupport_Idle $%.8x - unknown type '%.4s'", inWindow, &windowType));
            break;
    }
    return;
}
 
#pragma mark -
#pragma mark .----- utils -----
 
// ---------------------------------------------------------------------------
//      WindowSupport_IsAppWindow
// ---------------------------------------------------------------------------
 
Boolean WindowSupport_IsAppWindow(WindowPtr inWindow)
{
    Boolean     isAppWindow = false;
 
    if (inWindow != NULL)  {
        /* application windows have windowKinds = userKind (8) */
        isAppWindow = (GetWindowKind(inWindow) == userKind);
    }
    return isAppWindow;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_IsDAWindow
// ---------------------------------------------------------------------------
 
Boolean WindowSupport_IsDAWindow(WindowPtr inWindow)
{
    Boolean     isDAWindow = false;
    
    if (inWindow != NULL)  {
        isDAWindow = (GetWindowKind(inWindow) < 0);
    }
    return isDAWindow;
}
 
// ---------------------------------------------------------------------------
//      WindowSupport_InitStandardRecord
// ---------------------------------------------------------------------------
 
void WindowSupport_InitStandardRecord(StandardWindowRecord *inStandardRecord,
                    OSType inWindowType, WindowPtr inWindow)
{
    inStandardRecord->signature = inWindowType;
    inStandardRecord->standardWindowSignature = kSignature_StandardWindow;
    inStandardRecord->window = inWindow;
}