TweetFollow Us on Twitter

Pin-up Menu
Volume Number:6
Issue Number:6
Column Tag:Pascal Procedures

"PinUpMenu" XCMD

By Steven Fuchs, Coram, NY

Interface the Music

The Problem with the Finder

Excessive Folderfication. How many readers suffer from this graphically oriented computer malady? As our hard drives grow larger we are faced with a delicate balance between maintaining enough folders to satisfy our need for organization, and so many levels of folders that finding a document requires the opening and closing of eight windows. Let’s not even mention a trip to the handy but discouraging “Find File” DA. Don’t get me wrong, I love folders as much as the next guy, but I believe many users would like to have the ability to reach through the folders to ‘grab’ a specific document.

Hypercard “Open Command”

Within the Hypertalk programming environment there exists the “Open ” command . The Open command when used with an application name as its parameter in the form “Open AppName” will launch that application in a manner similar to the Finder. In addition it can be passed a document name as a parameter in the form “Open DocName with AppName” which will cause the application to open to the specified document. This performance parallels the Finder and offers no distinct advantages. The Hypercard advantage lies in its knack for remembering the full pathnames of all documents and applications launched from within it in a “pathname memory”. When launching an application or document from Hypercard only it’s name must be given. Hypercard will search through its “pathname memory” until the correct path is found. If the document is not found Hypercard displays a modal dialog requesting the user’s aid in locating the file. If that search is successful then that pathname is added to the “pathname memory”. This “pathname memory” can be examined by looking at pages 2 through 4 of your Home stack. Here is stored the pathnames of stacks, applications, and documents respectively. If you recognize any folder names that have been changed or deleted, these can be safely removed to save time and disk space.

Introduce Pin-Up Menus

The XCMD to be described this month allows for quick selection from a set of pre-chosen commands, and is accessible from anywhere within Hypercard. The name of the XFCN is “PinUpMenu”, which can be altered by the Hypercard user for his or her own utility. The instance I will use as an example I have dubbed “The Pop-Up Finder”. Which is just what the doctor ordered for quickly launching applications and their documents from within Hypercard.

Figure 1.

Cards-Eye View

Call it Up

Upon invocation, PinUpMenu displays a small window, and waits patiently for a mousedown event (See Figure 1). If this mousedown occurs outside of the window , the window disappears and PinUpMenu has run its course. If this mousedown occurs within the window a pop-up menu (hierarchical if desired) appears and allows for the selection of any desired item. The returned value can then be processed by the script that called it. In the case of “The Pop-Up Finder” the selected application and document will be launched using Hypercards “Open” command.

Necessary Scripts, Options

The PinUpMenu XFCN must be called with at least 2 parameters (See Figure 2). The first parameter is a string which is drawn within the window. Use this parameter to differentiate between your particular implementations of PinUpMenu. Parameters 2 through 16 are used to build the menus, they accomplish this by following a few simple rules. Each parameter should be a Hypercard container which holds one or more items. An Hypercard item being a string delineated by commas. The first item in the list will be the name of that line in the parent menu, while any remaining items will be listed in order as the submenus of that line. If there is only one item in the parameter then that item will be listed alone.

The Returns

PinUpMenu is an XFCN, therefore it must be used within an assignment and will return a value to Hypercard. This value will consist of one or two items. If the original click is made outside of the window or the mouse is released outside of the menu, then “Cancel” is returned. If the mouse is released in the parent menu inside of an item with no submenus then the selection name is returned in a one item string. If the mouse is released in a submenu choice, the answer consists of a two item string, the parent item followed by the submenu item separated by a comma so that your script can process the return with little modification. Be warned, this type of construction will not allow for the use of commas in a menu, as Hypercard will interpret this as two different items.

Figure 2.

Amongst the Gears

Hierarchical Menus

Submenus and Pop-Up Menus themselves are very easy to create and call up. They are created just as are other menus are, with a call to NewMenu. Although GetNewMenu and a resource could have been used, I have decided to create all windows and menus “on the fly”. I believe that XCMD’s should function this way whenever possible, simplifying the resource fork of the users Home stack as well as avoiding numbering conflicts between other external commands. To invoke a parent menu and the associated set of submenus , all you must do is call up the parent menu. The Mac toolbox handles the correct hiliting and displaying of the submenus. In order to alert the toolbox as to what you consider to be the correct hilighting and display two things must be done. First the command key field of the item you wish to give a submenu to should be set to $1B. This is a character which Apple has reserved to represent Hierarchical menus, it consists of the now familiar triangle pointing to the right. Secondly, set the item mark field of that same item to the menu id of the submenu and that’s it. The final step is to call InsertMenu(TheMenu,-1) for each of the submenus, and for the main menu in our case since it is a pop-up menu. By specifying -1 as the second parameter you tell the Mac not to put this menu in the Menubar, but to add it to the menu list anyway. Then call PopUpMenuSelect or MenuSelect and it will take care of the details from there. A very important consideration is that the menu id of a submenu may not be greater than 255, since that value must be a character placed into the item field. Passing a number larger will at the very least not work, and in the worst case cause some major problems.

Stealing Events

While PinUpMenus (or any other external code) is in control, Hypercard is in a semiconscious state so we will have to process events in its stead. This is no problem while running under the Finder, since the Menu Manager refreshes the screen beneath menus. However, if running under MultiFinder update events being generated through application switching will not be handled. This results in white blotches in the Hypercard window. The solution is very simple. By sending Hypercard the message ‘Go to this card’ we can force Hypercard to update itself, without interrupting our goings on (Thanks to Joe Zuffoletto and his article in Feb and March 1989 MacTutor for that handy tip). This however does not update the message box or the tool/pattern windoids. If this causes a problem the windoids can be restored by simply hiding and showing them again once PinUpMenu has run its course. Since the PinUpMenu XFCN serves no real purpose running in the background I plead guilty with explanation to not devising a more graceful alternative.

Saying Goodbye

Cleaning up the stack before returning to Hypercard is very important for any external code. I make sure all menuhandles not used are set to nil. This helps to determine which items have submenus, allowing us to avoid the unpleasant symptoms of deleting a menu which is not there or not deleting a menu that is. When writing external code it is important to dispose of all handles and pointers before returning. The leaving of unneeded blocks of memory lying around the heap for Hypercard to skirt is a very unMac-Like way of programming. In addition the window must be disposed of, and last but certainly not least the GrafPort must be reset to its state before the XFCN ran. If all of these have been done correctly then Hypercard should return without difficulty.

Getting Fancy

Simplicity equals Power

The structure of the XFCN, while remaining simple may be confusing to some developers not familiar with nesting procedures and functions. Under ordinary circumstances this is not necessary, and not often used. When writing a XFCN (or any other code resource) global variables are not allowed. By declaring the important variables in MAIN and then nesting all of the other routines, these variables can be treated as globals by the nested routines.

To sum up the actions of PinUpMenu in a nutshell besides creating a window it merely deciphers Hypercard item lists and calls AppendMenu for each of these. Simplicity yes but where is the power in that? Well, for those of you familiar with AppendMenu’s inherent power the answer is one simple word. Metacharacters. By passing these Metacharacters through Hypercard to PinUpMenus, all of the effects which can be used to make menus more clear can be used.

Staying in Metacharacter

Within the structure of the Mac OS menus may have some different characteristics. Each menu item may be drawn in a different style, may have an icon, may be enabled or disabled, and can have a command key associated with it. These can be added by a developer with little problem, by being specified in a resource file, or added through the AppendMenu call with Metacharacters. A metacharacter is a character which is not part of the actual text. Instead it allows for special distinctions to be made for a menu item. To add an icon to a menu item use the “^” character followed by the icons number less 256. To mark an item with a check mark or some such character, place an exclamation point (!) followed by the character before your item. The less than symbol (<) followed by either B,I,U,O,S sets the style of that item to the corresponding standard style. A slash (/) will associate a command key with that item, and a left parentheses (() will disable the item. If you don’t quite understand this you should get Inside Macintosh Volume 1 (which you should have anyway) and read page 352, where it is all explained very well.

K.I.S.S.

The most important aspect of menus is to add simplicity to your programs, or in this case stacks, menus should serve, not confuse. This means keeping styles, icons, item marks, and command keys to a minimum. By the way any command key equivalents used in PinUpMenus won’t work from Hypercard, since they only exist while the XFCN is running (i.e. while you are holding the mouse button down). If you must use command key equivalents you will have to trap for them yourself from within the scripts.

In Summation

Advantages and Other Uses

The Pop-Up Finder represents a speedy way to launch any desired application and/or document. But this is not the only use for our versatile little XFCN. Since PinUpMenu accepts its parameters as Hypercard item lists, scripts can use it to process and display whatever information they desire. I have written a script which determines the names of all objects in the present card and presents them in menu format. The object which is selected then opens its script for editing. I have also used it as a Pop-Up home stack, presenting the user with a variety of stack categories and names, going to whichever one is selected. For those of you who have taken the time to type this all in, or sent away for the source code, I believe the PinUpMenu represents a very useful XFCN, it makes no great departure from the mandated user interface standard yet allows for a customizable method of processing and choosing your Hypercard data. Hope you like it.

Listing:  XCMDUtil.PUM

unit XCMDUtils;

interface
 uses
 XCMDIntf;
 type
 Str31 = string[31];

 function PasToZero (paramPtr: XCmdPtr;
  str: Str255): Handle;

 procedure ZeroToPas (paramPtr: XCmdPtr;
 zeroStr: Ptr; var pasStr: Str255);

 procedure SendCardMessage (paramPtr: XCmdPtr; 
 msg: Str255);

implementation

 procedure DoJsr (addr: ProcPtr);
 inline
 $205F, $4E90;

 procedure SendCardMessage;
 begin
 with paramPtr^ do
 begin
 inArgs[1] := ORD(@msg);
 request := xreqSendCardMessage;
 DoJsr(entryPoint);
 end;
 end;

 function PasToZero;
 begin
 with paramPtr^ do
 begin
 inArgs[1] := ORD(@str);
 request := xreqPasToZero;
 DoJsr(entryPoint);
 PasToZero := Handle(outArgs[1]);
 end;
 end;

 procedure ZeroToPas;
 begin
 with paramPtr^ do
 begin
 inArgs[1] := ORD(zeroStr);
 inArgs[2] := ORD(@pasStr);
 request := xreqZeroToPas;
 DoJsr(entryPoint);
 end;
 end;

end.
Listing:  PinUpMenu.p

unit PinUpMain;
{--This is the source code of the PinUpMenu XFCN--}
{--Written by Steven Fuchs--}
{--PO Box 129, Coram, NY 11727--}

interface
 uses
 XCMDIntF, XCMDUtils;
 procedure MAIN (ParamPtr: XCMDPtr);
implementation
 type
 MenuArray = array[0..15] of MenuHandle;
 StrArray = array[0..15] of str255;

 procedure MAIN (ParamPtr: XCMDPtr);
 var
 TheMenus: MenuArray;
 TheParams: StrArray;
 PinUpWindow: WindowPtr;
 OldPort: GrafPtr;
 EndRect: rect;
 Name, TheAnswer: str255;
 item: longint;

{--HandleDrawing is a simple routine to draw our windows string--}
 procedure HandleDrawing;
 begin
 MoveTo(PinUpWindow^.portrect.left + 2, PinUpWindow^.portrect.bottom 
- 4);
 DrawString(Name);
 end;

{--HandleThisUpdate determines the correct action to take in  response--}
{--to an Update Event,  if the window is ours it calls HandleDrawing, 
if--}
{--it is the Hypercard main window, it calls SendCardMessage, otherwise--}
{--(most likely one of the tool pallettes) it removes the message--}
 procedure HandleThisUpdate (LilWindow: WindowPtr);
 begin
 BeginUpdate(LilWindow);
 if WindowPtr(LilWindow) = OldPort then
 SendCardMessage(ParamPtr, ‘Go to this card’)
 else if WindowPtr(LilWindow) = PinUpWindow then
 HandleDrawing
 else
 ValidRect(LilWindow^.portrect);
 EndUpdate(LilWindow);
 end;

{--GetParams is responsible for transferring parameters--}
{--sent to MAIN into our variables: Name, and TheParams arrray}
 function GetParams: boolean;
 var
 NumOfMenus, z: integer;
 begin
 NumOfMenus := ParamPtr^.ParamCount - 1;
 GetParams := NumOfMenus >= 1;
 ZeroToPas(ParamPtr, ParamPtr^.params[1]^, Name);
 for z := 1 to 15 do
 if z <= NumOfMenus then
 begin
 ZeroToPas(ParamPtr, ParamPtr^.params[z + 1]^, TheParams[z]);
 TheParams[z] := Include(‘,’, TheParams[z], length(TheParams[z]) + 1);
 end
 else
 TheParams[z] := ‘’;
 end;

{--ReturnWindowRect must determine length of string “Name”--}
{--Size the rectangle so the string fits nicely inside, and locate it 
so that--}
{--it appears in the same spot regardless of screen size--}
 procedure ComputeWindowRect;
 var
 DummyPt: point;
 begin
 SetPt(DummyPt, 150, 100);
 SetRect(EndRect, 0, 0, stringwidth(Name) + 20, 17);
 LocaltoGlobal(DummyPt);
 OffsetRect(EndRect, DummyPt.h, DummyPt.v);
 end;

{--CreateWindow does just that, creating the window for us and setting 
up the default drawing characteristics--}
 procedure CreateWindow;
 var
 LongOne: LongInt;
 begin
 PinUpWindow := NewWindow(nil, EndRect, ‘The Course’, false, 3, nil, 
false, LongOne);
 SetPort(PinUpWindow);
 TextFont(0);
 TextSize(12);
 ShowWindow(PinUpWindow);
 SelectWindow(PinUpWindow);
 end;

{--HitCameInWindow holds our event loop, where it waits for a mousedown--}
{--if this mousedown is within the window we return true, otherwise false.--}
 function HitCameInWindow: boolean;
 var
 Event: EventRecord;
 begin
 HitCameInWindow := false;
 repeat
 SystemTask;
 if GetNextEvent(EveryEvent, Event) then
 case Event.What of
 MouseDown: 
 if PtInRect(Event.Where, EndRect) then
 HitCameInWindow := true;
 UpdateEvt: 
 HandleThisUpdate(WindowPtr(event.message));
 ActivateEvt: 
 HandleDrawing;
 otherwise
 end
 until Event.What = Mousedown;
 end;

{--ReturnAndMaul is our parsing function, it reads the first item from--}
{--the string indicated by Index and returns it. It then deletes that 
item--}
 function ReturnAndMaul (Index: integer): str255;
 var
 ThePlace: integer;
 begin
 ThePlace := Pos(‘,’, TheParams[Index]);
 if ThePlace = 0 then
 ReturnAndMaul := ‘’
 else
 begin
 ReturnAndMaul := str255(copy(TheParams[Index], 1, ThePlace - 1));
 delete(TheParams[Index], 1, ThePlace);
 end;
 end;

{--CreateSubMenu does just that, creating the menu with NewMenu and sets 
the correct fields in the main menu to indicate the submenu exists--}
 procedure CreateSubMenu (Index: integer);
 var
 swf, saf: char;
 begin
 swf := chr($1B);
 saf := chr(240 + Index);
 TheMenus[Index] := NewMenu(240 + Index, ‘ASubMenu’);
{--Tell Mac OS we have a submenu--}
 SetItemCmd(TheMenus[0], Index, swf);
{--Tell Mac OS which Menu it is--}
 SetItemMark(TheMenus[0], Index, saf);
 end;

{--AddAllItems calls ReturnAndMaul repeatedly until there is nothing--}
{--left of string indicated by Index.  Each of items up until--}
{--that point is appended to the end of the submenu.--}
 procedure AddAllItems (TIndex: integer);
 var
 stripe: str255;
 x: integer;
 begin
 repeat
 stripe := ReturnAndMaul(TIndex);
 if stripe <> ‘’ then
 AppendMenu(TheMenus[TIndex], Stripe);
 until stripe = ‘’;
{--Insert our menu into hierarchical portion of MenuList--}
 InsertMenu(TheMenus[TIndex], -1);
 end;

{--BuildThoseMenus is the top layer, it creates the main menu and adds 
the items, decides if that item needs submenus and if so calls the procedures 
to add them--}
 procedure BuildThoseMenus;
 var
 Increment: integer;
 ScaredStr: str255;
 begin
 TheMenus[0] := NewMenu(240, ‘MainMenu’);
 for increment := 1 to 15 do
 begin
 TheMenus[increment] := nil;
 ScaredStr := ReturnAndMaul(increment);
 if ScaredStr <> ‘’ then
 begin
 AppendMenu(TheMenus[0], ScaredStr);
 if Pos(‘,’, TheParams[increment]) <> 0 then
 begin
 CreateSubMenu(increment);
 AddAllItems(increment);
 end;
 end;
 end;
{--Insert main menu into PopUp portion of Menu List--}
{--Same call as for hierarchical menus--}
 InsertMenu(TheMenus[0], -1);
 end;

{--ConvertAnswer takes the longint returned from PopUpMenuSelect and 
Converts it to the proper string for return to Hypercard--}
 function ConvertAnswer (TheL: longInt): str255;
 var
 ThePrimary, TheSecondary: str255;
 begin
 if TheL = 0 then
 ConvertAnswer := ‘Cancel’
 else if HiWord(TheL) = 240 then
 begin
 GetItem(TheMenus[HiWord(TheL) - 240], LoWord(TheL), TheSecondary);
 ConvertAnswer := TheSecondary;
 end
 else
 begin
 GetItem(TheMenus[0], HiWord(TheL) - 240, ThePrimary);
 GetItem(TheMenus[HiWord(TheL) - 240], LoWord(TheL), TheSecondary);
 ConvertAnswer := Str255(concat(ThePrimary, ‘,’, TheSecondary))
 end;
 end;

{--CleanUpMess takes care of the very important work of cleaning up the--}
{--heap before handing the reins back to Hypercard--}
 procedure CleanUpMess;
 var
 x: integer;
 begin
 DisposeWindow(PinUpWindow);
 for x := 0 to 15 do
 if TheMenus[x] <> nil then
 begin
 DeleteMenu(240 + x);
 DisposeMenu(TheMenus[x]);
 end;
 end;

{--Here is the code for the procedure MAIN, it acts at the highest level 
farming out almost all of the tasks to its other procedures and functions--}
 begin
 GetPort(OldPort);
 TheAnswer := ‘Cancel’;
 if GetParams then
 begin
 ComputeWindowRect;
 CreateWindow;
 BuildThoseMenus;
 if HitCameInWindow then
 begin
 Item := PopUpMenuSelect(TheMenus[0], EndRect.bottom + 4, EndRect.left, 
0);
 TheAnswer := ConvertAnswer(Item);
 end;
 SetPort(OldPort);
 CleanUpMess;
 end;
 ParamPtr^.returnvalue := PastoZero(ParamPtr, TheAnswer);
 end;
end.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.