HideMenuBar.c

/*
    File:       HideMenuBar.c
 
    Contains:   code snippet for hiding menu bar.
 
    Written by: John Wang   
 
    Copyright:  Copyright © 1994-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/18/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                03/14/94    JW              Re-Created for Universal Headers.
 
*/
 
#ifdef THINK_C
#define     applec
#endif
 
#include    <Memory.h>
#include    <QuickDraw.h>
#include    <LowMem.h>
 
#include    "HideMenuBar.h"
 
typedef struct  {                       
    short               oldMBarHeight;
    RgnHandle           theBarRgn;
} MenuBarGlobals;
 
/* ------------------------------------------------------------------------- */
 
/*
    Description:    Call this routine to hide menu bar.
 
    Format Params:  
        Name            Usage   Description/Assumptions
        ----            ----    -----------------------
        return          R       Returns a handle that must be passed back to RestoreMenuBar().
                
    Usage: P=Parameter,R=ReturnValue,E=External,G=FileGlobal,L=Local,I=Input,O=Output
    
    Error Handling: Return nil if failed.
 
    Special Notes:  xxx put other comments here xxx
 
*/
 
Handle MyHideMenuBar()
{
    Rect                mBarRect;
    RgnHandle           mBarRgn;
    MenuBarGlobals      **myHandle;
    Rect                myMainDeviceRect;
    
    myHandle = (MenuBarGlobals **) NewHandleClear(sizeof(MenuBarGlobals));
    if ( myHandle == nil )
        goto bail;
        
    myMainDeviceRect = (**GetMainDevice()).gdRect;
    
    (**myHandle).oldMBarHeight = GetMBarHeight();
    LMSetMBarHeight(0);
    SetRect(&mBarRect, myMainDeviceRect.left, myMainDeviceRect.top,
            myMainDeviceRect.right, myMainDeviceRect.top + (**myHandle).oldMBarHeight);
    mBarRgn = NewRgn();
    RectRgn(mBarRgn, &mBarRect);
    UnionRgn(LMGetGrayRgn(), mBarRgn, LMGetGrayRgn());
    (**myHandle).theBarRgn = mBarRgn;
    
bail:
    return( (Handle) myHandle );
}
 
/* ------------------------------------------------------------------------- */
 
/*
    Description:    Call this routine to restore menu bar.
 
    Format Params:  
        Name            Usage   Description/Assumptions
        ----            ----    -----------------------
        theHandle       PI      Contains info to restore menu bar.
                
    Usage: P=Parameter,R=ReturnValue,E=External,G=FileGlobal,L=Local,I=Input,O=Output
    
    Error Handling: If passed nil handle, then just quit.
 
    Special Notes:  xxx put other comments here xxx
 
*/
 
void RestoreMenuBar(Handle theHandle)
{
    RgnHandle           mBarRgn;
    MenuBarGlobals      **myHandle;
    
    if (theHandle == nil)
        goto bail;
    myHandle = (MenuBarGlobals **) theHandle;
        
    //  Restore menu bar.
    LMSetMBarHeight((**myHandle).oldMBarHeight);
    mBarRgn = (**myHandle).theBarRgn;
    DiffRgn(LMGetGrayRgn(), mBarRgn, LMGetGrayRgn());
    DisposeRgn(mBarRgn);
    DrawMenuBar();
    
bail:
    if (theHandle != nil)
        DisposeHandle(theHandle);
}