[comp.sys.mac.programmer] How do I make the Menu Bar disappear

kmcentee@Apple.COM (Kevin McEntee) (04/01/89)

Does anyone know of a quick and dirty way that a multifinder application can 
make the menu bar disappear?  Like in HyperCard?


If you do, please let me know.

Thanks,

	Kevin McEntee
	kmcentee@apple.com

earleh@eleazar.dartmouth.edu (Earle R. Horton) (04/04/89)

In article <28192@apple.Apple.COM> kmcentee@Apple.COM (Kevin McEntee) writes:
>
>Does anyone know of a quick and dirty way that a multifinder application can 
>make the menu bar disappear?  Like in HyperCard?
>
>
     You mean like this?

Earle
----------------------cut here----------------------
{
This unit provides the ability to hide the Menu Bar, and to show
it.  When the Menu Bar is hidden, windows may be placed in the
area normally used for the Menu Bar.

Usage:
        PROCEDURE MBar_Init:
          Used to initialize global variables used here.
          Call once at beginning of application code.
        PROCEDURE MBar_be_Gone;
          Hides the Menu Bar.
        PROCEDURE MBar_Restore;
          Shows the Menu Bar.  Call this whenever you are going
          to be put into the background.  Call before Exit.

The procedures in this unit will probably break under some future
release of the Macintosh Operating System, because they manipulate
the GrayRgn.  They do work under MultiFinder 6.1a2.  The most 
serious warning I can give concerning use of these routines is
that you must never allow your application to be placed into the
background with the Menu Bar hidden.

This file is part of Earle R. Horton's private source code library.
Earle R. Horton assumes no responsibility for any damages arising
out of use of this source code for any purpose.  Earle R. Horton
places no restrictions on use of all or any part of this source code,
except that this paragraph may not be altered or removed.

Original Language:
   MPW Pascal, v. 2.0.2
Origination Date:
   March 20, 1989
}
UNIT MenuBar;
  INTERFACE

    USES
      {$Load PasDump.dump}
      Memtypes, Quickdraw, OSIntf, Script, ToolIntf;

    CONST
      pop_a_long        = $21DF;
      GrayRgn           = $09EE;

    PROCEDURE MBar_be_Gone;
    PROCEDURE MBar_Restore;
    PROCEDURE MBar_Init;
{
 INLINE Procedures used for setting low memory globals.
}
    PROCEDURE SetMBarHeight(newheight:integer);
    INLINE smPopStack2Word,smMBarHeight;        { move.w        (a7)+,$0BAA }
    PROCEDURE SetGrayRgn(new_gray_rgn:RgnHandle);
    INLINE pop_a_long,GrayRgn;                  { move.l        (a7)+,$09EE }

    VAR
      Real_MBar_Height: integer;        { Copy of lowmem MBarHeight }
      Real_Gray_Region: RgnHandle;      { Copy of GrayRgn }
      Hidden_Flag:      Boolean;        { State info }
      MBar_Rect:        Rect;           { Rect in which MBar is drawn }

  IMPLEMENTATION

    PROCEDURE MBar_Init;
    BEGIN
      Hidden_FLag := false;
      Real_MBar_Height := GetMBarHeight;
      SetRect(MBar_Rect,
              screenBits.bounds.left,
              screenBits.bounds.top,
              screenBits.bounds.right,
              screenBits.bounds.top + Real_MBar_Height);
    END;
{
Make the Menu Bar go away under MultiFinder or UniFinder.
Since this procedure manipulates the Gray Region, future
compatibility is unknown.
}
    PROCEDURE MBar_be_Gone;
    VAR
      New_Gray_Region:  RgnHandle;
      MBar_Region:      RgnHandle;
      theWindow:        WindowPeek;
      BEGIN
        IF not Hidden_Flag THEN
          BEGIN
            Hidden_Flag := true;
                                                { Get some Regions to work with. }
            New_Gray_Region := NewRgn;
            MBar_Region := NewRgn;
                                              { Set the Menu Bar height to zero. }
            SetMBarHeight(0);
                                                         { Save the old GrayRgn. }
            Real_Gray_Region := GetGrayRgn;
               { Fix up GrayRgn to cover the old GrayRgn plus the Menu Bar Rect. }
            RectRgn(MBar_Region,MBar_Rect);
            UnionRgn(Real_Gray_Region,MBar_Region,New_Gray_Region);
            SetGrayRgn(New_Gray_Region);
                    { Paint and fix up visRgn for any windows with exposed area. }
            theWindow := WindowPeek(FrontWindow);
            PaintOne(theWindow,MBar_Region);
            PaintBehind(theWindow,MBar_Region);
            CalcVis(theWindow);
            CalcVisBehind(theWindow,MBar_Region);
            DisposeRgn(MBar_Region);                          { Clean up, leave. }
          END;
      END;
{
Restore the Menu Bar and GrayRgn to normality.
Call when app is put into background.
}
    PROCEDURE MBar_Restore;
    VAR
      MBar_Region:      RgnHandle;
      theWindow:        WindowPeek;
    BEGIN
    IF Hidden_Flag THEN
      BEGIN
        Hidden_Flag := false;
                         { (Re-use old GrayRgn.) }
        MBar_Region := GetGrayRgn; 
                           { Restore to original }
        SetGrayRgn(Real_Gray_Region);
                       { Restore Menu Bar height }
        SetMBarHeight(Real_MBar_Height);
                    { Fix up any covered windows }
        RectRgn(MBar_Region,MBar_Rect);
        theWindow := WindowPeek(FrontWindow);
        CalcVis(theWindow);
        CalcVisBehind(theWindow,MBar_Region);
        DisposeRgn(MBar_Region);
                { Draw the Menu, get out of here }
        HiliteMenu(0);
        DrawMenuBar;
      END;
    END;
END.

earleh@eleazar.dartmouth.edu (Earle R. Horton) (04/05/89)

In article <12865@dartvax.Dartmouth.EDU> earleh@eleazar.dartmouth.edu 
	(Earle R. Horton) writes:
>In article <28192@apple.Apple.COM> kmcentee@Apple.COM (Kevin McEntee) writes:
>>
>>Does anyone know of a quick and dirty way that a multifinder application can 
>>make the menu bar disappear?  Like in HyperCard?
>>
>>
>     You mean like this?
...
     The code I posted yesterday would cause problems in the unlikely
event that your program would crash while the Menu Bar was hidden.
Specifically, it would replace GrayRgn with a handle to a Region in the
application heap, and save the real GrayRgn Handle for restoration
later when you restored the Menu Bar.  If your program crashed, and the
Menu Bar was hidden, then GrayRgn was left pointing to a Region in a
defunct application heap, which could cause all sorts of problems for
applications which were still running.

     This version does not change the Handle, but rather modifies the contents
of GrayRgn.  If you crash with the Menu Bar hidden, GrayRgn is left pointing 
to a valid area of storage, at least.  There are still problems since the
Menu Bar can be left hidden, but these are slightly less severe than leaving
a dangling Handle in the system heap.

Earle
----------------------cut here----------------------
{
This unit provides the ability to hide the Menu Bar, and to show
it.  When the Menu Bar is hidden, windows may be placed in the
area normally used for the Menu Bar.

Usage:
        PROCEDURE MBar_Init:
          Used to initialize global variables used here.
          Call once at beginning of application code.
        PROCEDURE MBar_be_Gone;
          Hides the Menu Bar.
        PROCEDURE MBar_Restore;
          Shows the Menu Bar.  Call this whenever you are going
          to be put into the background.  Call before Exit.

The procedures in this unit will probably break under some future
release of the Macintosh Operating System, because they manipulate
the GrayRgn.  They do work under MultiFinder 6.1a2.  The most 
serious warning I can give concerning use of these routines is
that you must never allow your application to be placed into the
background with the Menu Bar hidden.

Possible compatibility problems:

  Modifies lowmem MBarHeight
  Modifies contents of GrayRgn
 
This file is part of Earle R. Horton's private source code library.
Earle R. Horton assumes no responsibility for any damages arising
out of use of this source code for any purpose.  Earle R. Horton
places no restrictions on use of all or any part of this source code,
except that this paragraph may not be altered or removed.

Original Language:
   MPW Pascal, v. 2.0.2
Origination Date:
   March 20, 1989
Modifications:
   April 4, 1989 ERH
     First version changed lowmem GrayRgn to point to a Region in the
application heap while the Menu Bar was hidden.  This version copies the
new Region to GrayRgn.  If the application crashes with the Menu Bar
hidden, GrayRgn no longer points to part of the defunct application
heap.  There are still problems, however, because the Menu Bar is left
hidden and other applications cannot access it. 
}
UNIT MenuBar;
  INTERFACE

    USES
      {$Load PasDump.dump}
      Memtypes, Quickdraw, OSIntf, Script, ToolIntf;

    PROCEDURE MBar_be_Gone;
    PROCEDURE MBar_Restore;
    PROCEDURE MBar_Init;

    PROCEDURE SetMBarHeight(newheight:integer);
    INLINE smPopStack2Word,smMBarHeight;        { move.w        (a7)+,$0BAA }

    VAR
      Real_MBar_Height: integer;        { Copy of lowmem MBarHeight }
      Save_Region:      RgnHandle;      { Copy of GrayRgn }
      Hidden_Flag:      Boolean;        { State info }
      MBar_Rect:        Rect;           { Rect in which MBar is drawn }

  IMPLEMENTATION

    PROCEDURE MBar_Init;
    BEGIN
      Hidden_FLag := false;
      Real_MBar_Height := GetMBarHeight;
      SetRect(MBar_Rect,
              screenBits.bounds.left,
              screenBits.bounds.top,
              screenBits.bounds.right,
              screenBits.bounds.top + Real_MBar_Height);
    END;
{
Make the Menu Bar go away under MultiFinder or UniFinder.
Since this procedure manipulates the Gray Region, future
compatibility is unknown.
}
    PROCEDURE MBar_be_Gone;
    VAR
      MBar_Region:      RgnHandle;
      theWindow:        WindowPeek;
      BEGIN
        IF not Hidden_Flag THEN
          BEGIN
            Hidden_Flag := true;
                                                { Get some Regions to work with. }
            Save_Region := NewRgn;
            MBar_Region := NewRgn;
                                              { Set the Menu Bar height to zero. }
            SetMBarHeight(0);
                                                         { Save the old GrayRgn. }
            CopyRgn(GetGrayRgn,Save_Region);
               { Fix up GrayRgn to cover the old GrayRgn plus the Menu Bar Rect. }
            RectRgn(MBar_Region,MBar_Rect);
            UnionRgn(GetGrayRgn,MBar_Region,GetGrayRgn);
                    { Paint and fix up visRgn for any windows with exposed area. }
            theWindow := WindowPeek(FrontWindow);
            PaintOne(theWindow,MBar_Region);
            PaintBehind(theWindow,MBar_Region);
            CalcVis(theWindow);
            CalcVisBehind(theWindow,MBar_Region);
            DisposeRgn(MBar_Region);                          { Clean up, leave. }
          END;
      END;
{
Restore the Menu Bar and GrayRgn to normality.
Call when app is put into background.
}
    PROCEDURE MBar_Restore;
    VAR
      theWindow:        WindowPeek;
    BEGIN
    IF Hidden_Flag THEN
      BEGIN
        Hidden_Flag := false;
                           { Restore to original }
        CopyRgn(Save_Region,GetGrayRgn);
                       { Restore Menu Bar height }
        SetMBarHeight(Real_MBar_Height);
                    { Fix up any covered windows }
        RectRgn(Save_Region,MBar_Rect);
        theWindow := WindowPeek(FrontWindow);
        CalcVis(theWindow);
        CalcVisBehind(theWindow,Save_Region);
        DisposeRgn(Save_Region);
                { Draw the Menu, get out of here }
        HiliteMenu(0);
        DrawMenuBar;
      END;
    END;
END.

wade@ksuvax1.cis.ksu.edu (Gary L. Wade) (04/06/89)

In article <28192@apple.Apple.COM> kmcentee@Apple.COM (Kevin McEntee) writes:
*Does anyone know of a quick and dirty way that a multifinder application can 
*make the menu bar disappear?  Like in HyperCard?

I think that Apple ought to provide some kind of trap call to perform this
feature in some future System release so we would KNOW that it won't break
on us...what does everyone else think?

alexis@ccnysci.UUCP (Alexis Rosen) (04/07/89)

Quite convenient for this to show up just as I was getting ready to
figure it out myself. Undoubtedly Earle has saved me some work (and
not for the first time, either). Thanks, Earle.

But... I would be interested in finding out how HyperCard does it.
Does anyone know? It is likely that Hypercard's way is the safest.
If nobody knows, I guess I'll soon know whether or not I'm interested
in the answer enough to break out MacsBug... Yuck.

---
Alexis Rosen
alexis@ccnysci.{uucp,bitnet}

kent@lloyd.camex.uucp (Kent Borg) (04/08/89)

In article <1554@deimos.cis.ksu.edu> wade@ksuvax1.cis.ksu.edu (Gary L. Wade) writes:
>In article <28192@apple.Apple.COM> kmcentee@Apple.COM (Kevin McEntee) writes:
>*Does anyone know of a quick and dirty way that a multifinder application can 
>*make the menu bar disappear?  Like in HyperCard?
>
>I think that Apple ought to provide some kind of trap call to perform this
>feature in some future System release so we would KNOW that it won't break
>on us...what does everyone else think?

I think that they shouldn't.  

One of the most important of the User Interface Commandments is: "The
*user* is in charge here."  Killing the menu bar is a great way to
remove that control and confuse the user.  Certainly, if you want to
write a program that does that to the user, that's your business, but
that doesn't mean that Apple has to help you do it.  

Remember that one of Apple's biggest assets is the user interface,
they have little motivation to help us break it.

Kent Borg
kent@lloyd.uucp
or
...!hscfvax!lloyd!kent

P.S.  The fact that *they* do it in HyperCard doesn't necessarily make
it a good idea.

wetter@cit-vax.Caltech.Edu (Pierce T. Wetter) (04/09/89)

 >*Does anyone know of a quick and dirty way that a multifinder application can 
 >*make the menu bar disappear?  Like in HyperCard?
 >
   Set MBarHeight to zero.

Pierce
-- 
wetter@csvax.caltech.edu | wetter@tybalt.caltech.edu | pwetter@caltech.bitnet
|----------------------------------------------------|
|              This Rent For Space                  -|
|____________________________________________________|

pepke@loligo.cc.fsu.edu (Eric Pepke) (04/12/89)

In article <367@lloyd.camex.uucp> kent@lloyd.UUCP (Kent Borg) writes:
>P.S.  The fact that *they* do it in HyperCard doesn't necessarily make
>it a good idea.

I agree loudly.  A "hide menubar" in HyperCard will make the menu bar
go away even if HC is running on a Mac II under MultiFinder.  When HC
blows up under MultiFinder and the menu bar is not there, even rerunning
HC will not fix the problem, at least not with the version of HC that 
came with the Apple Learning Disc, which blew up frequently.  You have
to push the big button in the sky, without being able to clean up the 
file system.

Eric Pepke                                     ARPA:   pepke@gw.scri.fsu.edu
Supercomputer Computations Research Institute  MFENET: pepke@fsu
Florida State University                       SPAN:   pepke@scri
Tallahassee, FL 32306-4052                     BITNET: pepke@fsu

Disclaimer: My employers seldom even LISTEN to my opinions.
Meta-disclaimer: Any society that needs disclaimers has too many lawyers.