Transfer Menu
Volume Number: 7
Issue Number: 12
Column Tag: Pascal Procedures
By Clifford Story, Goleta, CA
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
A Transfer Menu... Again
You may have seen my earlier article on a Transfer DA, which adds a Transfer
menu to any application. A Transfer DA has to do its work without any help from the
application; consequently, my DA did a lot of hacking with the system and low-memory
globals. One result became apparent just about the time the article was published: my
Transfer DA bombs under System 6.0.2. Sic transit gloria..[A revised version is now
on the source code disk for the Transfer DA (#37)].
The Transfer DA finds all applications on the boot disk and puts them on the
Transfer menu. This is fine, so long as all the applications you’re interested in are on
the same disk as your System folder. And so long as you haven’t too many of them;
scrolling the menu for item #358 can be a pain! Lately, though, I’ve been working
with my System folder on a separate partition of my hard disk; this makes it easy to use
different System versions (I have a System 4.2 partition and a System 6.0.2 partition)
but my Transfer menu comes up empty.
This article presents a different sort of Transfer menu, with a different sort of
Transfer. First, it’s an application Transfer menu, not a DA; this means that the
application will shut itself down before the transfer; no system hacking required. It’s
all high-level stuff, and the program works under all system versions I have tested,
and under the MultiFinder. Second, the menu is built and maintained by the user. He
can add applications via an SFget dialog, and remove them with a delete dialog. (But the
menu doesn’t scroll, so he can’t add too many.)
Components of the Program
The program may be broken into several parts:
• The main program, which contains the code to perform the transfer and maintain
the menu. The program doesn’t do anything but support desk accessories and the
Transfer menu. This menu looks like this:
• When the user selects the first item, the program puts up an SFget dialog, and
transfers to the selected program after adding it to the menu. If he selects the
second item, the program puts up a delete dialog, with the applications on a
scrolling list. He can then select applications to delete from the menu. If he
selects one of the named applications, the program transfers to that application.
• The menu definition procedure (MDEF) which draws and hit-tests the menu.
This is a fairly simple MDEF but I went through a lot of screen shots with fatbits
to determine the constants that would reproduce the spacing on a standard menu. I
didn’t reproduce scrolling; this menu doesn’t scroll.
• The list definition procedure (LDEF) which draws the list of menu items used in
the delete dialog.
These three parts use a common data structure, stored as a “TRNS” resource,
that lists all the applications on the menu. The main program uses it to transfer to a
selected application; it is also in charge of adding and deleting applications. The MDEF
uses it in place of the menuhandle as its source of data, and the LDEF uses it in the same
way.
Source Files
Seven source files make up the program, which is written in Pascal and compiled
under MPW. The seven are:
• Transfer.make, the MPW make file;
• Transfer.r, the Rez input file (resource source file);
• mytypes.p, a catchall unit of constant and type declarations;
• Common.p, which contains the declaration of the common data structure;
• Transfer Menu.p, the MDEF source;
• Transfer List.p, the LDEF source; and
• Transfer.p, the main program source.
I will discuss them individually in that order (the first three don’t require much
discussion).
A Note from Apple
I ran into a problem while I was working on this program: It failed (although, at
least, it didn’t crash) under the Multi finder. So I wrote a letter to Apple and asked for
help. They actually replied to my letter (which is something), but their reply was less
than helpful. Anyway, I quote from the reply:
In general, we do not recommend that applications contain a Transfer menu or
menu item. There are various system compatibility problems.
I wonder if they’ve taken a look at Resedit lately... And they enclosed a copy of
Tech Note 126, which is about sublaunching! I wonder if they read their letters before
they mail them out. Anyway, there’s the Word from Olympus.
#1
#***************************************
#
# Transfer.make
#
# (c) 1988, by Clifford Story
# & Attic Software
#
#***************************************
#***************************************
# Compile the resources
#***************************************
Rez Transfer.r -append -o Transfer
#***************************************
# Compile the common data declarations
#***************************************
Common.p.o Transfer.make Common.p
Pascal Common.p
#***************************************
# Compile the MDEF
#***************************************
'Transfer Menu'.p.o Transfer.make ∂
'Transfer Menu'.p Common.p.o
Pascal 'Transfer Menu'.p
'Transfer Menu'.p.o
Link -m MENUDEF -w -t 'APPL' ∂
-c '????' -rt MDEF=1001 ∂
-sn Main='Transfer Menu' ∂
'Transfer Menu'.p.o ∂
"{Libraries}"Interface.o ∂
"{Libraries}"Runtime.o ∂
"{PLibraries}"PasLib.o ∂
"{PLibraries}"SANELib.o ∂
-o Transfer
#***************************************
# Compile the LDEF
#***************************************
'Transfer List'.p.o Transfer.make ∂
'Transfer List'.p Common.p.o
Pascal 'Transfer List'.p
'Transfer List'.p.o
Link -m LISTDEF -w -t 'APPL' ∂
-c '????' -rt LDEF=1001 ∂
-sn Main='Transfer List' ∂
'Transfer List'.p.o ∂
"{Libraries}"Interface.o ∂
"{Libraries}"Runtime.o ∂
"{PLibraries}"PasLib.o ∂
"{PLibraries}"SANELib.o ∂
-o Transfer
#***************************************
# Compile the main program
#***************************************
Transfer.p.o Transfer.make ∂
Transfer.p Common.p.o
Pascal Transfer.p
Link -w -t APPL -c '????' ∂
Transfer.p.o ∂
"{Libraries}"Interface.o ∂
"{Libraries}"Runtime.o ∂
"{PLibraries}"PasLib.o ∂
"{PLibraries}"SANELib.o ∂
-o Transfer
#***************************************
The Program’s Resources
Here we have a standard set of resources, with MENUs and ALRTs and DITLs and
so on. Two resources are a bit out of the ordinary: MENU 1004 and the TRNS resource.
MENU 1004 is, of course, the Transfer menu. Notice that it uses MDEF 1001
instead of textMenuProc. You might wonder why it has any data, since I’ve already said
that the MDEF will use a separate data structure in place of the menuhandle to draw the
menu. It’s true that it doesn’t need alot of the data included here, but it does plain need
the first item, since that item has a keyboard equivalent. The MDEF may not look at the
menu handle, but MenuKey does.
The TRNS resource is the menu list data structure. The record is declared in
Common.p; suffice it to say here that the first word is the number of applications in the
list. So what is declared here is an empty list.
/* 2 */
/****************************************
Transfer.r
Resources for Transfer menu demo.
(c) 1988, by Clifford Story
& Attic Software
****************************************/
#include "types.r
/****************************************
Menu resources
****************************************/
resource 'MENU' (1001) {
1001,
textMenuProc,
$7FFFFFFB,
enabled,
apple,
{ /* array: 3 elements */
/* [1] */
"About Transfer...", noicon,
"", "", plain,
/* [2] */
"About Attic Software...", noicon,
"", "", plain,
/* [3] */
"-", noIcon, "", "", plain
}
};
resource 'MENU' (1002, preload) {
1002,
textMenuProc,
0x7FFFFF83,
enabled,
"File",
{ /* array: 1 elements */
/* [1] */
"Quit", noIcon, "Q", "", plain
}
};
resource 'MENU' (1003, preload) {
1003,