TweetFollow Us on Twitter

Tear-Off
Volume Number:3
Issue Number:12
Column Tag:Pascal Procedures

Tear-Off Menus Explained

By Darryl Lovato, TML Systems, MacTutor Contributing Editor

Hello once again, this month I would like to show how to implement tear-off menus. What is a tear-off menu? It is a menu which can be removed from the menu bar and used as a window. I first saw a tear off menu in a pre-release version of Hypercard by Bill Atkinson. Since I have had a lot of experience creating and using Menu and Window Definition routines, I thought I would try to duplicate his implementation of tear-offs so that MacTutor readers can see how it is done and use them in their own programs.

I assume that you know how menu and window definition routines work. If you are not familiar with them read my articles in the July, August, and October 1986 issues of MacTutor.

The Window Definition routine used in the example is fairly straight forward, and, in fact, really isn’t needed. It’s sole purpose is to NOT look like a regular window. To do this I made the window’s title bar small and solid black. The pattern drawing is not a part of the definition routine. It is handled in a update event as any other window’s contents. The window looks like the one in figure 1.

Figure 1

The Menu Definition routine used in the example is where the special tear-menu code is. The tear-off menu in figure 2 looks very similar to the tear-off window. The size and draw messages are just as you would expect. The choose message, however, has some special coding to implement the tear-off. When we get the choose message, and the mouse is outside of the menu rectangle we check to see how far outside it is. If it is more than 10 pixels outide of the menu rectange, then we do not return from the choose message routine. Instead, we drag a outline of the menu on the desktop region until the mouse comes up, the user moves the mouse over another menu, or the mouse is moved back onto the original menu. If the mouse comes up while we are tracking it, we send a message back to the program telling it to move and re-display the torn window at that point. We communicate this information by posting an event which is unused by the application. I picked event #12, but you could choose any of the application event numbers. We pass the top left coordinate of where to display the pallete window in the Event.message paramter.

When the main event loop gets event 12, it must move the menu to the location passed in the message and display the window.

Figure #2

There are a couple of things that need to be pointed out. First, drawing all the patterns is real slow (even on a MacII!!!). This could be improved a great deal by keeping a offscreen bitmap of the patterns and use copybits instead of drawing them. Second. I know I have done a big no-no by not making the menu and window defs code resources. Third, you should be able to edit the patterns by double clicking on them to bring up a pattern editor window. Fourth, it would be great if the patterns could be in color on a Mac II. I leave the above enhancements to you as an exersize.

The program I used to create the tear-off windows is given below. It was written is TML Pascal, but the techniques shown should be usefull no matter what language your using. Have fun!

Pascal Code Optimizations

I would like to share some secrets with MacTutor readers out there who strive for the fastest, smallest Pascal code. My tricks will not improve your code 500%, as re-designing a algorithm could, but they can help you get the most out of the code generated by your compiler. These tricks are for TML Pascal, but should help you generate better code in any Pascal.

1. Always use Inc(x) and Dec(x) procedures instead of x := x + 1 or x := x - 1. The inc and dec procedures generate one assembler instruction as opposed to 3 for x := x + 1. This saves 6 bytes each time you use it. When inc and dec are used in loops, this can save a lot of execution time. [Unfortuanately, these are not available in other implementations. -Ed]

2. If you pass a structure larger than 4 bytes to a procedure or function, pass it as a static paramter. When you use a static, instead of regular parameters, you save 18 bytes per paramter in code size. This saves a lot of execution time, too. The reason for this is that when you pass a large structure as a static parameter, it is not copied local to the procedure. This is especially usefull if you pass a lot of strings to procedures and functions.

3. In certain if..then..else statements, you can save code by restructuring the statement to eliminate the else, and 4 bytes!

4. For loops are code hogs! Because Pascal compilers check the bounds of ‘for’ loops before entering them, they generate a lot of error checking. By recoding a ‘for’ loop as a repeat loop you can save 16 bytes. Here is an example:

Instead of this:

 for x := 1 to 100 do
   begin
   end;

Do this:

 x := 1;
 repeat
   inc(x);
 until x = 100;

There are a lot of other optimizations that can be done to make faster, smaller Pascal code, but these are the ones that can be used the most. Of course, re-writting the code in assembler would make the biggest diffrence in code size and speed, but that can take a long time and there are a lot of people who do not understand 680x0 assembler.

[The following code has been sanitized to work in both TML Pascal and LS Pascal and has been tested in both. However, one of the functions that returns a rect as an argument tripped up the Turbo Pascal syntax checker, so some modification may be necessary to get the program compiled in Turbo. We are at a loss as to why Turbo should be more picky than LS Pascal, which I thought was the most fussy of all! The code should also work fine in MPW, but we didn’t take the time to actually try it. -Ed]

We welcome Darryl back to MacTutor and present him with our Program of the Month award for this important and timely example of tear-off menus. One reader wanted it so bad, he made me send an advance copy of the article next day air so his department could get to work on it. Thanks Darryl!

{1}
Listing 1 TML & LS Pascal Source Code
PROGRAM TearMenu;

{ Example of tear-off menus}
{ by Darryl Lovato of TML for MacTutor}
{ Inspired by HyperCard}
{ TML Pascal / LS Pascal Version }
{ Some modifications may be required for Turbo Pascal }
{ Turbo Pascal does not seem to like a rect as }
{ a return variable from a function. }

uses MacIntf;    { remove for LS Pascal }

{$T APPL TEAR}   { remove for LS Pascal }
{$B+}   { remove for LS Pascal }
{$L TearMenuRes} { remove for LS Pascal }

{global constants}
CONST
 AppleMenuID = 1;
 FileMenuID = 2;
 EditMenuID = 3;
 graphicalMenu = 4;
 WindResID = 1;
 AboutID = 3000;

{global variables}
VAR
 myMenus : ARRAY[AppleMenuID..EditMenuID] OF MenuHandle;
 Done : Boolean;
 RegWDEFWindow : WindowPtr;
 GrowArea : rect;
 DragArea : rect;
 myWindowPeek : WindowPeek;
 MyGraphicsMenu : menuhandle;
 currentPatWind : WindowPtr;

{ My Window Definition Function }

 FUNCTION MyWindowDef (varCode : Integer;
 theWindow : WindowPtr;
 message : Integer;
 param : LongInt) : LongInt;
 TYPE
 RectPtr = ^Rect;

 VAR
 aRectPtr : RectPtr;
 myWindowPeek : WindowPeek;

{ Nested procedures follow }
 PROCEDURE DoDrawMessage (WindToDraw : WindowPtr;
 DrawParam : LongInt);
 VAR
 TitleBarRect : Rect;
 CurrentY : Integer;
 index : Integer;
 GoAwayBox : Rect;
 Show : boolean;
 WindowRec : WindowPeek;
 BEGIN
 WindowRec := WindowPeek(WindToDraw);
 Show := WindowRec^.visible;
 IF Show THEN
 BEGIN
 TitleBarRect := WindowRec^.strucRgn^^.rgnBBox;
 IF DrawParam <> 0 THEN {just toggle goAway box}
 BEGIN
 WITH TitleBarRect DO
 BEGIN
 top := top + 3;
 left := left + 5;
 bottom := top + 8;
 right := left + 8;
 END;
 InsetRect(TitleBarRect, 1, 1);
 InvertRect(TitleBarRect);
 END
 ELSE {we need to draw the window frame}
 BEGIN
 PenNormal;
 FrameRect(TitleBarRect);
 TitleBarRect.bottom := TitleBarRect.top + 13;

 FrameRect(TitleBarRect);
 InsetRect(TitleBarRect, 1, 1); {shrink by 1}
 EraseRect(TitleBarRect);

 IF WindowRec^.hilited THEN
 BEGIN { add hiliting }
 FillRect(TitleBarRect, black);
 WITH TitleBarRect DO
 BEGIN
 top := top + 2;
 left := left + 4;
 bottom := top + 8;
 right := left + 8;
 END;
 PenMode(patXor);
 FrameRect(TitleBarRect);
 PenNormal;
 END;
 END;
 END;
 END;

 FUNCTION DoHitMessage (WindToTest : WindowPtr;
 theParam : LongInt) : LongInt;
 VAR
 globalPt : Point;
 aRect : Rect;
 GoAwayBox : Rect;
 tempRect : Rect;
 WindowRec : WindowPeek;
 BEGIN
 globalPt.h := LoWord(theParam);
 globalPt.v := HiWord(theParam);
 WindowRec := WindowPeek(WindToTest);
 aRect := WindowRec^.strucRgn^^.rgnBBox;
 aRect.bottom := aRect.top + 12; {create tBar Rect}
 tempRect := WindowRec^.strucRgn^^.rgnBBox;
 IF PtInRect(globalPt, tempRect) THEN {in structure rgn?}
 BEGIN
 tempRect := WindowRec^.contRgn^^.rgnBBox;
 IF PtInRect(globalPt,tempRect) THEN {if content rgn}
 DoHitMessage := wInContent
 ELSE IF PtInRect(globalPt, aRect) THEN {drag}
 BEGIN
 IF WindowRec^.hilited THEN
 BEGIN {we need to check go-away box}
 WITH aRect DO
 BEGIN
 top := top + 2;
 left := left + 4;
 bottom := top + 8;
 right := left + 8;
 END;
 IF PtInRect(globalPt, aRect) THEN
 DoHitMessage := wInGoAway
 ELSE
 DoHitMessage := wInDrag;
 END
 ELSE
 DoHitMessage := wInDrag;
 END
 ELSE {it was in our window frame}
 DoHitMessage := wNoHit;
 END
 ELSE {it wasn’t in our window at all}
 DoHitMessage := wNoHit;
END;

PROCEDURE DoCalcRgnsMessage (WindToCalc : WindowPtr);
 VAR
 tempRect : Rect;
 aWindowPeek : WindowPeek;
 aRgn : RgnHandle;
 WindowRec : WindowPeek;
BEGIN
 tempRect := WindToCalc^.PortRect;
 OffsetRect(tempRect, -WindToCalc^.PortBits.Bounds.Left, -WindToCalc^.PortBits.Bounds.Top);

 TempRect.top := TempRect.top - 1;
 WindowRec := WindowPeek(WindToCalc);
 RectRgn(WindowRec^.contRgn, tempRect);

 InsetRect(tempRect, -1, -1);
 tempRect.top := tempRect.top - 12;
 RectRgn(WindowRec^.strucRgn, tempRect);
END;

{ End of nested procedures }
BEGIN
 MyWindowDef := 0;
 CASE message OF
 wDraw : 
 DoDrawMessage(theWindow, param);
 wHit : 
 MyWindowDef := DoHitMessage(theWindow, param);
 wCalcRgns : 
 DoCalcRgnsMessage(theWindow);
 wNew : 
 ;
 wDispose : 
 ;
 wGrow : 
 ;
 END; {of case}
END;

{ -------------------------------------------- }
{function GetItemRect(item : integer) : rect; }

FUNCTION GetItemRect (item : integer) : rect;
VAR
 tempRect : Rect;
BEGIN
 WITH tempRect DO
 BEGIN
 top := (((item - 1) DIV 8) * 16) - 1;
 bottom := top + 17;
 left := (((item - 1) MOD 8) * 16) - 1;
 right := left + 17;
 END;
 GetItemRect := tempRect;
END;

{procedure DrawPatWindow;   }

PROCEDURE DrawPatWindow;
 VAR
 i : integer;
 currentPat : Pattern;
 currRect : Rect;
BEGIN
 FOR i := 1 TO 96 DO
 BEGIN
 currRect := GetItemRect(i);
 FrameRect(currRect);
 GetIndPattern(currentPat, 100, i);
 FillRect(currRect, currentPat);
 FrameRect(currRect);
 END;
END;

{function GetMItemRect(whichRect:Integer;myRect:Rect):Rect;}

FUNCTION GetMItemRect (whichRect : Integer;
 myRect : Rect) : Rect;
 VAR
 ItemRect : Rect;
BEGIN
 ItemRect := GetItemRect(whichRect);
 OffSetRect(itemRect, myRect.left, myRect.top);
 GetMItemRect := ItemRect;
END;

{procedure drawItem(myRect : rect; myItem : integer); }

PROCEDURE drawItem (myRect : rect;
 myItem : integer);
 VAR
 currentPat : pattern;
BEGIN
 IF (myItem > 0) AND (myItem < 97) THEN
 BEGIN
 myRect := GetMItemRect(myItem, myRect);
 GetIndPattern(currentPat, 100, myItem);
 FillRect(myRect, currentPat);
 FrameRect(myRect);
 END;
END;

{procedure clearitem(myRect : Rect; lastCell : integer); }

PROCEDURE clearitem (myRect : Rect;
 lastCell : integer);
BEGIN
 DrawItem(myRect, lastCell - 9);
 DrawItem(myRect, lastCell - 8);
 DrawItem(myRect, lastCell - 7);
 DrawItem(myRect, lastCell - 1);
 DrawItem(myRect, lastCell);
 DrawItem(myRect, lastCell + 1);
 DrawItem(myRect, lastCell + 7);
 DrawItem(myRect, lastCell + 8);
 DrawItem(myRect, lastCell + 9);
END;

{Menu Definition Routine   }

PROCEDURE MyMenuDef (message : Integer;
 theMenu : MenuHandle;
 VAR menuRect : Rect;
 hitPt : Point;
 VAR whichItem : Integer);

{ Begin nested procedrues }
 PROCEDURE DoDrawMessage (myMenu : MenuHandle;
 myRect : Rect);
 CONST
 MBarHeight = 20;
 VAR
 whichRect : Integer;
 currentPat : Pattern;
 currRect : Rect;
 BEGIN
 FOR whichRect := 1 TO 96 DO
 Drawitem(myRect, whichRect);
 END;

 FUNCTION DoChooseMessage (myMenu : MenuHandle;
 myRect : Rect;
 myPoint : Point;
 oldItem : Integer) : Integer;
 VAR
 currRect : Rect;
 alldone : boolean;
 whichRect : Integer;
 oldRect : Rect;
 mPt : Point;
 lastPt : Point;
 lastRect : Rect;
 menuPt : Point;
 tempRect : Rect;
 exitrect : rect;
 saveClip : RgnHandle;
 io : integer;
 BEGIN
 ClipRect(myRect);
 whichRect := 1;
 alldone := false;
 REPEAT
 currRect := GetMItemRect(whichRect, myRect);
 IF PtInRect(myPoint, currRect) THEN
 alldone := true
 ELSE
 whichRect := whichRect + 1;
 UNTIL ((AllDone) OR (whichRect > 96));
 IF AllDone THEN { if we are in a item}
 BEGIN
 IF (whichRect <> oldItem) THEN
 BEGIN
 IF (oldItem <> 0) THEN
 ClearItem(myRect, oldItem);
 InsetRect(currRect, -6, -6);
 PenSize(6, 6);
 PenPat(white);
 FrameRect(currRect);
 PenNormal;
 InsetRect(currRect, -1, -1);
 FrameRect(currRect);
 END;
 DoChooseMessage := whichRect;
 END
 ELSE { we are not in a item}
 BEGIN
 IF oldItem <> 0 THEN { invert the old item}
 clearitem(myRect, oldItem);
 DoChooseMessage := 0;

 PenMode(notPatXOR);
 penpat(gray);
 exitrect := myrect;
 InsetRect(ExitRect, -10, -10);
 ExitRect.top := 20;
 menuPt.h := myRect.left + ((myRect.right - myRect.left) DIV 2);
 menuPt.v := myRect.top + ((myRect.bottom - myRect.top) DIV 2);
 SetRect(tempRect, 0, 0, 0, 0);
 lastRect := tempRect;
 ClipRect(screenbits.bounds);
 REPEAT
 GetMouse(mPt);
 LocalToGlobal(mPt);
 IF ((Longint(mpt) <> Longint(lastPt)) AND (NOT PtInRect(mpt, ExitRect)) 
AND (mPt.v > 20)) THEN
 BEGIN
 lastPt := mPt;
 tempRect := myRect;
 OffSetRect(tempRect, mPt.h - menuPt.h, mPt.v - menuPt.v);
 IF tempRect.top < 20 THEN
 BEGIN
 tempRect.top := 20;
 tempRect.bottom := 20 + 202;
 END;
 FrameRect(lastRect);
 FrameRect(tempRect);
 lastRect := tempRect;
 END;
 UNTIL (NOT button) OR ptInRect(mPt, exitrect) OR (mPt.v < 21);
 FrameRect(lastRect);
 PenNormal;
 IF (NOT PtInRect(mpt, ExitRect)) AND (mPt.v > 20) THEN
 BEGIN
 lastrect.top := lastrect.top + 12;
 io := PostEvent(12,Longint(lastRect.topleft));
        { this communicates back to the main event}
        { loop that a window was just torn from the}
        { menu.  We pass the new topLeft in the message}
 END;
 END;
 END;

 PROCEDURE DoSizeMessage (VAR myMenu : MenuHandle);
 BEGIN
 WITH myMenu^^ DO
 BEGIN
 menuWidth := 127;
 menuHeight := 191;
 END;
 END;

{ End of nested procedures }
BEGIN
 CASE message OF
 mSizeMsg : 
 DoSizeMessage(theMenu);
 mDrawMsg : 
 DoDrawMessage(theMenu, menuRect);
 mChooseMsg : 
 whichItem := DoChooseMessage(theMenu, menuRect, hitPt, whichItem);
 END;
END;

{ ---------------------------------- }
{ShowAbout procedure  }

PROCEDURE ShowAbout;
 VAR
 theDlog : DialogPtr;
 theItem : Integer;
BEGIN
 theDlog := GetNewDialog(AboutID, NIL, Pointer(-1));
 ModalDialog(NIL, theItem);
 DisposDialog(theDlog);
END;

{  ProcessMenu procedure   }

PROCEDURE ProcessMenu (codeWord : Longint);
 TYPE
 PatPtr = ^Pattern;
 VAR
 menuNum : Integer;
 itemNum : Integer;
 NameHolder : str255;
 dummy : Integer;
 yuck : boolean;
 myPattern : Pattern;
 DeskPatternPtr : PatPtr;
 savePort, aPort : grafPtr;
 theRgn1, theRgn2 : RgnHandle;
BEGIN
IF codeWord <> 0 THEN
 BEGIN
 menuNum := HiWord(codeWord);
 itemNum := LoWord(codeWord);
 CASE menuNum OF { the different menus}
 AppleMenuID : 
 IF itemNum < 3 THEN
 ShowAbout
 ELSE
 BEGIN
 GetItem(myMenus[AppleMenuID], itemNum, NameHolder);
 dummy := OpenDeskAcc(NameHolder);
 END;
 FileMenuID : 
 Done := true;
 EditMenuID : 
 yuck := SystemEdit(itemNum - 1);
 GraphicalMenu : 
 IF ItemNum <> 0 THEN
 BEGIN
 GetIndPattern(myPattern, 100, ItemNum);
 SetPort(currentPatWind);
 BackPat(myPattern);
 EraseRect(currentPatWind^.portRect);
 END;
 END;
 HiliteMenu(0);
 END;
END;

{Deal With Mouse Downs procedure }

 PROCEDURE DealWithMouseDowns (theEvent : EventRecord);
 VAR
 location : Integer;
 windowPointedTo : WindowPtr;
 mouseLoc : point;
 windowLoc : integer;
 VandH : Longint;
 Height : Integer;
 Width : Integer;
 currRect, myRect : Rect;
 newcell, LastCell : integer;
 thePt, LastPt : Point;
 i : integer;
 myPattern : Pattern;
 BEGIN
 mouseLoc := theEvent.where;
 windowLoc := FindWindow(mouseLoc, windowPointedTo);
 CASE windowLoc OF
 inMenuBar : 
 ProcessMenu(MenuSelect(mouseLoc));
 inSysWindow : 
 SystemClick(theEvent, windowPointedTo);
 inContent : 
 IF windowPointedTo <> FrontWindow THEN
 SelectWindow(windowPointedTo)
 ELSE
 BEGIN
 IF RegWDEFWindow = windowPointedTo THEN
 BEGIN
 SetPort(RegWDEFWindow);
 GetMouse(lastPt);
 newCell := 0;
 lastCell := 0;
 myRect := RegWDEFWindow^.portRect;
 WHILE waitmouseup DO {track in pattern wind}
 BEGIN
 GetMouse(thePt);
 IF NOT PtInRect(thePt, myRect) THEN
 BEGIN {we moved outside the window}
 IF lastCell <> 0 THEN
 clearItem(myRect, lastCell);
 lastCell := 0;
 END
 ELSE
 BEGIN
 FOR i := 1 TO 96 DO
 IF PtInRect(thePt, GetItemRect(i)) THEN
 newCell := i;
 IF newCell <> lastCell THEN
 BEGIN
 IF (lastCell <> 0) THEN
 Clearitem(myRect, lastCell);
 currRect := GetItemRect(newCell);
 InsetRect(currRect, -6, -6);
 PenSize(6, 6);
 PenPat(white);
 FrameRect(currRect);
 PenNormal;
 InsetRect(currRect, -1, -1);
 FrameRect(currRect);
 lastCell := newCell;
 END;
 END;
 END;
 Clearitem(myRect, lastCell);
 GetIndPattern(myPattern, 100, newCell);
 SetPort(currentPatWind);
 BackPat(myPattern);
 EraseRect(currentPatWind^.portRect);
 END;
 END;
 inDrag : 
 BEGIN
 DragWindow(windowPointedTo, mouseLoc, DragArea);
 SelectWindow(windowPointedTo);
 END;
 inGoAway : 
 IF TrackGoAway(windowPointedTo, mouseLoc) THEN
 HideWindow(windowPointedTo);
 END;
END;

{Deal With Key Downs procedure}

 PROCEDURE DealWithKeyDowns (theEvent : EventRecord);
 TYPE
 Trick = PACKED RECORD
 CASE boolean OF
 true:(
 long : Longint
 );
 false : (
 chr3, chr2, chr1, chr0 : char
 )
 END;
 VAR
 CharCode : char;
 TrickVar : Trick;
 BEGIN
 TrickVar.long := theEvent.message;
 CharCode := TrickVar.chr0;
 IF BitAnd(theEvent.modifiers, CmdKey) = CmdKey THEN           
 {check for a menu selection}
 ProcessMenu(MenuKey(CharCode))
 END;

{Deal With Updates procedure}

 PROCEDURE DealWithUpdates (theEvent : EventRecord);
 VAR
 UpDateWindow : WindowPtr;
 tempPort : WindowPtr;

 BEGIN
 UpDateWindow := WindowPtr(theEvent.message);
 GetPort(tempPort);
 SetPort(UpDateWindow);
 BeginUpDate(UpDateWindow);
 EraseRect(UpDateWindow^.portRect);
 IF UpdateWindow <> currentPatWind THEN
 DrawPatWindow;
 EndUpDate(UpDateWindow);
 SetPort(tempPort);
 END;

{MainEventLoop procedure  }

 PROCEDURE MainEventLoop;
 VAR
 Event : EventRecord;
 ProcessIt : boolean;
 where : Point;
 BEGIN
 REPEAT
 SystemTask;
 IF GetNextEvent(everyEvent, Event) THEN
 CASE Event.what OF
 mouseDown : 
 DealWithMouseDowns(Event);
 AutoKey : 
 DealWithKeyDowns(Event);
 KeyDown : 
 DealWithKeyDowns(Event);
 UpdateEvt : 
 DealWithUpdates(Event);
 12 : 
 BEGIN { we return this when a window torn}
 where := Point(Event.message);
 HideWindow(RegWDefWindow);
 MoveWindow(RegWDefWindow, where.h, where.v, true);
 ShowWindow(RegWDEFWindow);
 END;
 OTHERWISE
 BEGIN
 END;
 END; {of case}
 UNTIL Done;
 END;

{SetupMemory procedure      }

 PROCEDURE SetupMemory;
 VAR
 x : Longint;
 BEGIN
{x := ORD4(ApplicZone) + 128000;}
{SetApplLimit(Pointer(x));}
 MaxApplZone;
 MoreMasters;
 MoreMasters;
 MoreMasters;
 END;

{ SetupLimits    }

 PROCEDURE SetupLimits;
 VAR
 Screen : Rect;
 BEGIN
 Screen := ScreenBits.bounds;
 WITH Screen DO
 BEGIN
 SetRect(DragArea, left+4, top+24, right-4, bottom-4);
 SetRect(GrowArea, left, top + 24, right, bottom);
 END;
 END;

{MakeMenus procedure   }

 PROCEDURE MakeMenus;
 VAR
 index : Integer;
 BEGIN
 FOR index := AppleMenuID TO EditMenuID DO
 BEGIN
 myMenus[index] := GetMenu(index);
 InsertMenu(myMenus[index], 0);
 END;
 AddResMenu(myMenus[AppleMenuID], ‘DRVR’);
 MyGraphicsMenu := NewMenu(4, ‘Graphics’);
 MyGraphicsMenu^^.menuProc := NewHandle(0);
 MyGraphicsMenu^^.menuProc^ := Ptr(@MyMenuDef);
 CalcMenuSize(MyGraphicsMenu);
 Insertmenu(MyGraphicsMenu, 0);
 DrawMenuBar;
 END;

 PROCEDURE crash;
 BEGIN
 ExitToShell;
 END;

{ ---------------------------------- }
{Main Program Excecution Starts Here }

BEGIN
 InitGraf(@thePort);
 InitFonts;
 InitWindows;
 InitMenus;
 TEInit;
 InitDialogs(@crash);
 InitCursor;
 Done := false;
 FlushEvents(everyEvent, 0);

 SetupLimits;
 SetupMemory;
 MakeMenus;

 RegWDEFWindow := GetNewWindow(WindResID, NIL, Pointer(-1));
 myWindowPeek := WindowPeek(RegWDEFWindow);
 myWindowPeek^.windowDefProc := NewHandle(0);
 myWindowPeek^.windowDefProc^ := Ptr(@MyWindowDef);
 SetWRefCon(RegWDEFWIndow, Ord4(MyGraphicsMenu));
 currentPatWind := GetNewWindow(2, NIL, pointer(-1));
 SetPort(currentPatWind);
 BackPat(gray);
 EraseRect(currentPatWind^.portRect);

 MainEventLoop;
END. {thats all folkes!}
{2}
Listing 2: TML Link File (Ignore for LS Pascal )
!PAS$Xfer

/Globals -4
TearMenu
PAS$Library
macintf
MacIntfGlue
/Resources
TearMenuRes
/Bundle
/Type  APPL TEAR
/End


Listing 3: REZ version resource file

resource ‘BNDL’ (128) {
 ‘TEAR’,
 0,
 { /* array TypeArray: 2 elements */
 /* [1] */
 ‘ICN#’,
 { /* array IDArray: 1 elements */
 /* [1] */
 0, 128
 },
 /* [2] */
 ‘FREF’,
 { /* array IDArray: 1 elements */
 /* [1] */
 0, 128
 }
 }
};

resource ‘DITL’ (3000) {
 { /* array DITLarray: 3 elements */
 /* [1] */
 {155, 142, 180, 205},
 Button {
 enabled,
 “Okay”
 },
 /* [2] */
 {6, 5, 112, 361},
 StaticText {
 disabled,
 “                                 - Tear “
 “Menu -\n\nWritten by Darryl Lovato of TML “
 “Systems, Inc.\n\nThis program shows how to”
 “ make a window tear off of a menu.  Idea”
 “ from Hypercard by Bill Atkinson.\n”
 },
 /* [3] */
 {115, 5, 149, 361},
 StaticText {
 enabled,
 “Complete Pascal source code for this pro”
 “gram is available from MacTutor Magazine”
 “.”
 }
 }
};

resource ‘DLOG’ (3000, preload) {
 {58, 74, 244, 436},
 dBoxProc,
 visible,
 goAway,
 0x0,
 3000,
 “New Dialog”
};

resource ‘FREF’ (128) {
 ‘APPL’,
 0,
 “”
};
resource ‘ICN#’ (128, purgeable, preload) {
 { /* array: 2 elements */
 /* [1] */
 $”000F F400 007A FD00 01FF F780 05FF 7FE0"
 $”07FF FFB0 0BFB FFD8 0FFF B578 1FDF F6FC”
 $”1F7E E8BC 1E77 A074 3E37 807C 1C00 006C”
 $”3FF0 3E3C 2E38 633C 3DE0 3C24 1E60 4C24"
 $”1400 4004 1C00 0004 0C00 4008 0400 0038"
 $”0404 6028 0001 8038 0200 0078 0008 1050"
 $”0103 C060 0180 0140 0780 0040 7D20 0440"
 $”4510 0820 4887 E050 4980 0088 7FFF FFF8",
 /* [2] */
 $”000F F400 007F FD00 01FF FF80 05FF FFE0"
 $”07FF FFF0 0FFF FFF8 0FFF FFF8 1FFF FFFC”
 $”1FFF FFFC 1FFF FFFC 3FFF FFFC 1FFF FFFC”
 $”3FFF FFFC 3FFF FFFC 3FFF FFFC 1FFF FFFC”
 $”1FFF FFFC 1FFF FFFC 0FFF FFF8 07FF FFF8"
 $”07FF FFF8 03FF FFF8 03FF FFF8 01FF FFF0"
 $”01FF FFE0 01FF FFC0 07FF FFC0 7FFF FFC0"
 $”7FFF FFE0 7FFF FFF0 7FFF FFF8 7FFF FFF8"
 }
};
resource ‘MENU’ (1) {
 1,
 textMenuProc,
 0x7FFFFFFD,
 enabled,
 apple,
 { /* array: 2 elements */
 /* [1] */
 “About Tear Menu...”, noIcon, “”, “”, plain,
 /* [2] */
 “-”, noIcon, “”, “”, plain
 }
};
resource ‘MENU’ (2) {
 2,
 textMenuProc,
 0x7FFFFFF5,
 enabled,
 “File”,
 { /* array: 1 elements */
 /* [1] */
 “Quit”, noIcon, “Q”, “”, plain
 }
};
resource ‘MENU’ (3) {
 3,
 textMenuProc,
 0x7FFFFFFD,
 enabled,
 “Edit”,
 { /* array: 6 elements */
 /* [1] */
 “Undo”, noIcon, “Z”, “”, plain,
 /* [2] */
 “-”, noIcon, “”, “”, plain,
 /* [3] */
 “Cut”, noIcon, “X”, “”, plain,
 /* [4] */
 “Copy”, noIcon, “C”, “”, plain,
 /* [5] */
 “Paste”, noIcon, “V”, “”, plain,
 /* [6] */
 “Clear”, noIcon, “”, “”, plain
 }
};
resource ‘WIND’ (1) {
 {100, 100, 292, 228},
 documentProc,
 invisible,
 goAway,
 0x0,
 “”
};
resource ‘WIND’ (2) {
 {81, 143, 224, 327},
 documentProc,
 visible,
 goAway,
 0x0,
 “Current Pattern”
};
data ‘TEAR’ (0) {
 $”1B54 6561 7220 4D65 6E75 2C20 6279 2044" 
 $”6172 7279 6C20 4C6F 7661 746F” 
};
resource ‘PAT#’ (100, purgeable) {
 { /* array PatArray: 96 elements */
 /* [1] */
 $”FFFF FFFF FFFF FFFF”,
 /* [2] */
 $”DDFF 77FF DDFF 77FF”,
 /* [3] */
 $”DD77 DD77 DD77 DD77",
 /* [4] */
 $”AA55 AA55 AA55 AA55",
 /* [5] */
 $”55FF 55FF 55FF 55FF”,
 /* [6] */
 $”AAAA AAAA AAAA AAAA”,
 /* [7] */
 $”EEDD BB77 EEDD BB77",
 /* [8] */
 $”8888 8888 8888 8888",
 /* [9] */
 $”B130 031B D8C0 0C8D”,
 /* [10] */
 $”8010 0220 0108 4004",
 /* [11] */
 $”FF88 8888 FF88 8888",
 /* [12] */
 $”FF80 8080 FF08 0808",
 /* [13] */
 $”80",
 /* [14] */
 $”8040 2000 0204 08",
 /* [15] */
 $”8244 3944 8201 0101",
 /* [16] */
 $”F874 2247 8F17 2271",
 /* [17] */
 $”55A0 4040 550A 0404",
 /* [18] */
 $”2050 8888 8888 0502",
 /* [19] */
 $”BF00 BFBF B0B0 B0B0",
 /* [20] */
 $””,
 /* [21] */
 $”8000 0800 8000 08",
 /* [22] */
 $”8800 2200 8800 22",
 /* [23] */
 $”8822 8822 8822 8822",
 /* [24] */
 $”AA00 AA00 AA00 AA”,
 /* [25] */
 $”FF00 FF00 FF00 FF”,
 /* [26] */
 $”1122 4488 1122 4488",
 /* [27] */
 $”FF00 0000 FF”,
 /* [28] */
 $”0102 0408 1020 4080",
 /* [29] */
 $”AA00 8000 8800 80",
 /* [30] */
 $”FF80 8080 8080 8080",
 /* [31] */
 $”081C 22C1 8001 0204",
 /* [32] */
 $”8814 2241 8800 AA”,
 /* [33] */
 $”40A0 0000 040A”,
 /* [34] */
 $”0384 4830 0C02 0101",
 /* [35] */
 $”8080 413E 0808 14E3",
 /* [36] */
 $”1020 54AA FF02 0408",
 /* [37] */
 $”8000 0000 08",
 /* [38] */
 $”80",
 /* [39] */
 $”0002 4000 0000 0080",
 /* [40] */
 $”0002 4000 0000 0880",
 /* [41] */
 $”8000 1000 8002 0020",
 /* [42] */
 $”8002 0010 8002 0010",
 /* [43] */
 $”0092 0000 9200 0092",
 /* [44] */
 $”0092 0008 8220 0092",
 /* [45] */
 $”0092 0028 8228 0092",
 /* [46] */
 $”1082 1082 1082 1082",
 /* [47] */
 $”2288 2288 2288 2288",
 /* [48] */
 $”2288 22A8 2288 2288",
 /* [49] */
 $”2288 22A8 2288 2A88",
 /* [50] */
 $”228A 22A8 2288 2A88",
 /* [51] */
 $”228A 22A8 2288 AA88",
 /* [52] */
 $”228A A2A8 2288 AA88",
 /* [53] */
 $”228A AAA8 2288 AAA8",
 /* [54] */
 $”228A AAA8 228A AAA8",
 /* [55] */
 $”AA11 AA45 AA11 AA54",
 /* [56] */
 $”AA51 AA45 AA11 AA55",
 /* [57] */
 $”AA55 AA45 AA55 AA54",
 /* [58] */
 $”AA55 AA45 AA55 AA55",
 /* [59] */
 $”AA55 AA55 AA55 AA55",
 /* [60] */
 $”AA55 BA55 AA55 AA55",
 /* [61] */
 $”AA55 BA55 AA55 AB55",
 /* [62] */
 $”AA55 BA55 AA55 AB75",
 /* [63] */
 $”EE55 BA55 EA55 AB55",
 /* [64] */
 $”EE55 BA55 EE55 AB55",
 /* [65] */
 $”EE55 BA55 EE55 BB55",
 /* [66] */
 $”EE55 BB55 EE55 BB55",
 /* [67] */
 $”EE55 BB55 EE5D BB55",
 /* [68] */
 $”EE55 BB55 EE5D FB55",
 /* [69] */
 $”EE55 FB55 EE5D FB55",
 /* [70] */
 $”EE55 FF55 EE55 FF55",
 /* [71] */
 $”FF55 FF55 FF55 FF55",
 /* [72] */
 $”FF55 FF5D FF55 FF55",
 /* [73] */
 $”FF55 FF5D FF55 FFD5",
 /* [74] */
 $”FF55 FFDD FF55 FFD5",
 /* [75] */
 $”FF55 FFDD FF55 FFDD”,
 /* [76] */
 $”FF57 FF5D FF75 FFD5",
 /* [77] */
 $”FF57 FF7D FF7D FFD7",
 /* [78] */
 $”FFDD FFFF FFF7 FF7F”,
 /* [79] */
 $”FFDF FFFF FFF7 FF7F”,
 /* [80] */
 $”FFFF FFF7 FFFF FF7F”,
 /* [81] */
 $”FFFF FFFF FFFF FF7F”,
 /* [82] */
 $”FFFF FFFF FFFF FFFF”,
 /* [83] */
 $”7FBF DFBF 6BDD BD7B”,
 /* [84] */
 $”FF03 0509 1121 4181",
 /* [85] */
 $”FF83 4529 1129 4583",
 /* [86] */
 $”FF93 5539 FF39 5593",
 /* [87] */
 $”FE93 5539 EF39 5593",
 /* [88] */
 $”FE93 1139 EF39 1193",
 /* [89] */
 $”1010 1038 EF38 1010",
 /* [90] */
 $”1192 5438 EF38 5492",
 /* [91] */
 $”1192 5438 EF38 5492",
 /* [92] */
 $”55AA 55BA 6DBA 55AA”,
 /* [93] */
 $”5FA9 51A3 458A 55AA”,
 /* [94] */
 $”55EA 7DA6 65BE 57AA”,
 /* [95] */
 $”55AA 4182 4182 55AA”,
 /* [96] */
 $”46A6 FFFF 4686 57AE”
 }
 /** Extra bytes follow.. */
 /* $”0000 0034 0001 1400"
};
 
AAPL
$103.30
Apple Inc.
+0.80
MSFT
$45.09
Microsoft Corpora
-0.34
GOOG
$577.33
Google Inc.
+5.73

MacTech Search:
Community Search:

Software Updates via MacUpdate

TextSoap 7.4.0 - Flexible text editing u...
TextSoap is for people who work with text. TextSoap effortlessly cleans up text from endlessly different formats. Wash away unwanted characters, spaces, tabs. Fix paragraphs with hard returns at the... Read more
NetShade 6.0.2 - Browse privately using...
NetShade is an Internet security tool that conceals your IP address on the web. NetShade routes your Web connection through either a public anonymous proxy server, or one of NetShade's own dedicated... Read more
Mac DVDRipper Pro 5.0 - Copy, backup, an...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
pwSafe 3.1 - Secure password management...
pwSafe provides simple and secure password management across devices and computers. pwSafe uses iCloud to keep your password databases backed-up and synced between Macs and iOS devices. It is... Read more
StatsBar 1.8 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Path Finder 6.5.5 - Powerful, award-winn...
Path Finder is a file browser that combines the familiar Finder interface with the powerful utilities and innovative features. Just a small selection of the Path Finder 6 feature set: Dual pane... Read more
QuarkXPress 10.2.1 - Desktop publishing...
With QuarkXPress, you can communicate in all the ways you need to -- and always look professional -- in print and digital media, all in a single tool. Features include: Easy to Use -- QuarkXPress is... Read more
Skype 6.19.0.450 - Voice-over-internet p...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
VueScan 9.4.41 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Cloud 3.0.0 - File sharing from your men...
Cloud is simple file sharing for the Mac. Drag a file from your Mac to the CloudApp icon in the menubar and we take care of the rest. A link to the file will automatically be copied to your clipboard... Read more

Latest Forum Discussions

See All

Modern Combat 5 Gets a Major Multiplayer...
Modern Combat 5 Gets a Major Multiplayer Update Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Alien Creeps TD Review
Alien Creeps TD Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: EXPENSIVE DEFENSESUniversal App - Designed for iPhone and iPad Alien Creeps TD would be a fun if unremarkable Tower Defense game, but its heavy focus on... | Read more »
The Journey Down: Chapter Two Review
The Journey Down: Chapter Two Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: DARK YET ENTICINGUniversal App - Designed for iPhone and iPad It’s a little dark, in every sense of the word, but The Journey Down:... | Read more »
Function Space, a Social Network App for...
Function Space, a Social Network App for Science, Launches on iOS Posted by Ellis Spice on September 2nd, 2014 [ permalink ] | Read more »
Stupidfast – How Taylor Martinez Switche...
How do you make an Endless Running game more than just another Endless Running game? By adding real life prizes to it, of course! That’s the thinking behind StupidFast: a game designed for football enthusiasts, and the brainchild of former college... | Read more »
Little Raiders: Robin’s Revenge Review
Little Raiders: Robin’s Revenge Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: CASUAL RAIDINGUniversal App - Designed for iPhone and iPad Combining simple combat with village building is a potent combination for... | Read more »
Treasure Tombs: Ra Deal Coming from Bulk...
Treasure Tombs: Ra Deal Coming from Bulkypix and Dark Tonic This Fall Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Dark Tonic and | Read more »
Pirate Bash Review
Pirate Bash Review By Nadia Oxford on September 2nd, 2014 Our Rating: :: BAD PIRATES, GOOD TIMESUniversal App - Designed for iPhone and iPad Pirate Bash’s turn-based battles add an intriguing twist to a typical physics game.   | Read more »
Tiny Tower Vegas Review
Tiny Tower Vegas Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: STEADY DEVELOPMENTUniversal App - Designed for iPhone and iPad Build a huge tower again but Vegas-style in Tiny Tower Vegas.   | Read more »
The Manhattan Project Review
The Manhattan Project Review By Andrew Fisher on September 2nd, 2014 Our Rating: :: ROCKET SCIENCEUniversal App - Designed for iPhone and iPad The Manhattan Project offers a great Euro-style gameplay experience, but it is totally... | Read more »

Price Scanner via MacPrices.net

Apple refurbished iPads available for up to $...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
Are We Now In The Post-Post-PC Era?
A longtime and thoroughgoing laptop aficionado, I was more than a little dismayed by Steve Jobs’s declaration back in 2010 when he sprang the iPad on an unsuspecting world. that we’d entered a “post-... Read more
PC Outlook Improves, But 2014 Shipments Still...
According to the International Data Corporation (IDC) Worldwide Quarterly PC Tracker, worldwide PC shipments are expected to fall by -3.7 percent in 2014. To hat’s actually an improvement from the... Read more
IDC Lowers Tablet Sales Projections for 2014...
Following a second consecutive quarter of softer than expected demand, International Data Corporation (IDC) has lowered its worldwide tablet plus 2-in-1 forecast for 2014 to 233.1 million units. The... Read more
Apple now offering refurbished 21-inch 1.4GHz...
The Apple Store is now offering Apple Certified Refurbished 21″ 1.4GHz iMacs for $929 including free shipping plus Apple’s standard one-year warranty. Their price is $170 off the cost of new models,... Read more
Save $50 on the 2.5GHz Mac mini, on sale for...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more
Save up to $300 on an iMac with Apple refurbi...
The Apple Store has Apple Certified Refurbished iMacs available for up to $300 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. These are the best prices on... Read more
The Rise of Phablets
Carlisle & Gallagher Consulting Group, a businesses and technology consulting firm focused solely on the financial services industry, has released an infographic depicting the convergence of... Read more
Bad Driver Database App Allows Good Drivers t...
Bad Driver Database 1.4 by Facile Group is a new iOS and Android app that lets users instantly input and see how many times a careless, reckless or just plain stupid driver has been added to the... Read more
Eddy – Cloud Music Player for iPhone/iPad Fre...
Ukraine based CapableBits announces the release of Eddy, its tiny, but smart and powerful cloud music player for iPhone and iPad that allows users to stream or download music directly from cloud... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.