home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / Papers / aSEPiA example source / Application / HideShowMbar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-25  |  2.2 KB  |  58 lines  |  [TEXT/CWIE]

  1. /*---------------------------------------------------------------
  2.  
  3.     HideShowMbar.c
  4.     
  5.     routine to hide or show the menu bar.
  6.  
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "HideShowMbar.h"
  10. #include <Quickdraw.h>
  11. #include <LowMem.h>
  12.  
  13. short    gSavedMenuBarHeight = 20;    // go default
  14.  
  15. void HideShowMBAR(DoHide isDoHide)
  16. {
  17.     RgnHandle        grayRgnHandle, mbarRgnHandle;
  18.     GDHandle        theGDHandle;
  19.     Rect            modifiedScreenRect;
  20.  
  21.     theGDHandle = GetMainDevice();
  22.     modifiedScreenRect = (*theGDHandle)->gdRect;
  23.  
  24.     if (isDoHide == eHide) { //then hide window
  25.        //1) Save the gray region using  LMGetGrayRgn();
  26.        grayRgnHandle = LMGetGrayRgn();  
  27.        //2) Save the menubar region using LMGetMBarHeight() and RectRgn();
  28.        mbarRgnHandle = NewRgn();
  29.        SetRectRgn (mbarRgnHandle, 0, 0, modifiedScreenRect.right, LMGetMBarHeight() );
  30.        gSavedMenuBarHeight = LMGetMBarHeight();
  31.        
  32.        //3) Set the menubar height to zero using LMSetMBarHeight()
  33.        //    see note below about saving height before setting it to zero
  34.        LMSetMBarHeight(0);
  35.        //4) Add the menubar region to the gray region using UnionRgn();
  36.        UnionRgn (mbarRgnHandle, grayRgnHandle, grayRgnHandle );
  37.        //5) Inval the old menu bar region with InvalRgn();
  38.        InvalRgn( mbarRgnHandle ); //not sure if this will be necessary
  39.     } else { 
  40.         //to restore the menubar -- Simply the reverse above.
  41.        
  42.        //1) Save the gray region using  LMGetGrayRgn();
  43.        grayRgnHandle = LMGetGrayRgn();  
  44.        //2) create new menubar region 
  45.        mbarRgnHandle = NewRgn();
  46.        SetRectRgn (mbarRgnHandle, 0, 0, modifiedScreenRect.right, 20 );
  47.        //3) Reset the menubar height
  48.           //set to default Roman height--this won't work for non Roman Script systems
  49.           //a better method is to save the mbar height from before you removed it
  50.           //In that case, also use that height in the above line of code (replacing 20)
  51.        LMSetMBarHeight(gSavedMenuBarHeight);
  52.        //4) Remove the menubar region from the gray region
  53.        DiffRgn (grayRgnHandle, mbarRgnHandle, grayRgnHandle );
  54.        //5) Inval the old menu bar region with InvalRgn();
  55.        InvalRgn( mbarRgnHandle ); //not sure if this will be necessary
  56.        DrawMenuBar(); 
  57.     }  //end else
  58. }