Windows.c

/*
    File:       Windows.c
 
    Contains:   Handle application's windows    
 
    Written by: Chris White 
 
    Copyright:  Copyright © 1996-1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                8/10/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
 
 
 
#pragma segment Core
 
#include <Sound.h>
 
// System Includes
 
#ifndef __TYPES__
    #include <Types.h>
#endif
 
#ifndef __WINDOWS__
    #include <Windows.h>
#endif
 
#ifndef __QUICKDRAW__
    #include <Quickdraw.h>
#endif
 
#ifndef __RESOURCES__
    #include <Resources.h>
#endif
 
#ifndef __FONTS__
    #include <Fonts.h>
#endif
 
#ifndef __DIALOGS__
    #include <Dialogs.h>
#endif
 
#ifndef __ERRORS__
    #include <Errors.h>
#endif
 
 
 
 
// Application Includes
 
#ifndef __BAREBONES__
    #include "BareBones.h"
#endif
 
#ifndef __PROTOTYPES__
    #include "Prototypes.h"
#endif
 
 
 
 
// Static prototypes
 
 
 
 
 
 
void DoActivate ( EventRecord* theEvent )
{
    Boolean     bActiveFlag = theEvent->modifiers & resumeFlag;
    SInt16      ignoreItem;
    WindowRef   ignoreWindow;
    WindowRef   theWindow = (WindowRef) theEvent->message;
    GrafPtr     savePort;
 
    
    GetPort ( &savePort );
    SetPortWindowPort ( theWindow );
    DialogSelect ( theEvent, &ignoreWindow, &ignoreItem );
    SetPort ( savePort );
    
    return;
}
 
 
 
void DoUpdate ( EventRecord* theEvent )
{
    OSErr           theErr;
    GrafPtr         savePort;
    CGrafPtr        thePort;
    WindowRef       theWindow = (WindowRef) theEvent->message;
    RgnHandle       theRgn;
    
    
    
    theRgn = NewRgn ( );
    theErr = MemError ( );
    if ( theErr )   goto CleanupAndBail;
    
    GetPort ( &savePort );
    SetPortWindowPort ( theWindow );
    BeginUpdate ( theWindow );                  // visRgn temporarily = updateRgn
 
    thePort = GetWindowPort ( theWindow );
    UpdateDialog ( theWindow, thePort->visRgn );
    DisposeRgn ( theRgn );
    
    EndUpdate ( theWindow );                    // restore normal visRgn of grafport
    SetPort ( savePort );
    
CleanupAndBail:
 
    return;
}
 
 
 
void DoContentClick ( WindowRef theWindow, EventRecord* theEvent )
{
    WindowRef   frontWindow;
    
    // If a movable modal is active, ignore click in an inactive 
    // window, otherwise select it or handle the content click.
    
    frontWindow = FrontWindow ( );
    if ( theWindow != frontWindow )
    {
        if ( IsMovableModal ( frontWindow ) )
            SysBeep ( 30 );
        else
            SelectWindow ( theWindow );
    }
    else
    {
        SInt16      itemHit;
        
        if ( DialogSelect ( theEvent, &theWindow, &itemHit ) && itemHit == 1 )
        {
            tThreadedOperationPtr theInfo;
            
            theInfo = (tThreadedOperationPtr) GetWRefCon ( theWindow );
            theInfo->bCancelled = true;
        }
    }
    
    return;
    
} // DoContentClick
 
 
 
void DoDragWindow ( WindowRef theWindow, EventRecord* theEvent )
{
    WindowRef   frontWindow;
    
    
    // If a movable modal is active, ignore click in an inactive 
    // title bar, otherwise let the Window Manager handle it.
    
    frontWindow = FrontWindow ( );
    if ( theWindow != frontWindow && IsMovableModal ( frontWindow ) )
        SysBeep ( 30 );
    else                                
    {
        RgnHandle   theRgn;
        Rect        dragRect;
        
        theRgn = GetGrayRgn ( );
        dragRect = (*theRgn)->rgnBBox;
        DragWindow ( theWindow, theEvent->where, &dragRect );
    }
    
    return;
}