AWCTTYPA@UIAMVS.BITNET ("David A. Lyons") (02/01/89)
>Date: Tue, 31 Jan 89 08:21:16 GMT >From: Doug Gwyn <adm!smoke!gwyn@NYU.EDU> > >How about explaining this. I don't have a "resource manager" on >my REAL computers and haven't felt the need for one. What does it >buy you (other than a cheap, inelegant way to support multiple >natural language messages)? Why, soit-en-ly! I'd be glad to, in spite of your apparent negative views of the reality of the Apple IIgs and the elegance of resources. You've never felt the _need_ for a resource manager? Have you ever written a desktop-based application? (Or have you ever used a resource editor to customize menus and dialogs (among other things) in existing Macintosh application?) First, a little background is in order. I'll describe what resources are and how they are used on the Macintosh; it's probably reasonable to assume there won't be too many differences between the Macintosh implementation and the Apple IIgs implementation. Macintosh files have two separate "forks": the data fork, which is the part you would normally think of as a traditional file, and the resource fork. The data fork is usually where most of the stuff in your documents it kept (the text of a word processor document would be in the file's data fork, and the file's resource fork would be mostly empty). For an Application file, on the other hand, most of the stuff is in the other fork, the resource fork--and the data fork is often empty. Inside the resource fork are a whole bunch of "resources." (Brilliant, eh?) A resource, in general, is just an arbitrary collection of data bytes, and each resource is identified by a four-character "resouce type" and by a 16-bit number (from -32768 to 32767). (Individual resources can also have long _names_ to save you from having to remember the numbers you gave the resources.) Here are a few of the common resource types and their uses on the Macintosh: ALRT -- template for an alert box CODE -- application code segment (yes, code is stored in resources!) CURS -- mouse cursor (arrow, watch, I-beam, or _anything_) DLOG -- template for a dialog box ICN# -- list of icons MBAR -- menu bar MENU -- a pull-down menu STR# -- list of strings (messages, etc) WIND -- window template (These are just examples; there are lots more common types, and applications are free to invent their own types for their own uses.) To start with Doug's example, if an application keeps all of its messages in STR# resources in appropriate ways (i.e., not making icky assumptions about word order when messages need to be "built" from text+filenames), then that application can be customized for a new language using just a resource editor--no code needs to be changed. I suppose this isn't the most elegant conceivable scheme for doing international applications, but compared to _nothing_ (which most systems offer) it's pretty slick. Many kinds of resources can be edited interactively in an application called a resource editor (like ResEdit on the Mac). Good examples are Icons, fonts, and templates for menus, windows, controls, dialog item lists, alerts, and dialogs. Here's the kind of difference it makes. The following Pascal code creates a modal dialog on the Apple IIgs...the hard way. (This is excerpted from the source code from DIcEd (Desktop Icon Editor), a real live GS application.) This creates a modal dialog with an Ok button, a Cancel button, a Color check box, and several edit-line items with static text messages near them. SetRect(r,14,45,626,150); dlg := NewModalDialog(r,true,0); {--- OK button ---} SetRect(r,520,17,590,32); NewDItem(dlg,1,r,buttonItem,@'OK',0,0,nil); {--- Cancel button ---} OffsetRect(r,0,20); NewDItem(dlg,2,r,buttonItem,@'Cancel',0,0,nil); {--- Color check box ---} SetRect(r,520,57,590,72); NewDItem(dlg,50,r,checkItem,@'Color',0,0,nil); {--- application pathname ---} SetRect(r,20,72,580,82); NewDItem(dlg,3,r,statTextItem+itemDisable, @'Application pathname:',0,0,nil); SetRect(r,20,82,590,95); NewDItem(dlg,4,r,editLineItem+itemDisable,@'',63,0,nil); {--- filename ---} SetRect(r,20,57,110,68); NewDItem(dlg,5,r,statTextItem+itemDisable,@'Filename:', 0,0,nil); SetRect(r,120,56,285,69); NewDItem(dlg,6,r,editLineItem+itemDisable,@'',15,0,nil); {--- aux type ---} SetRect(r,150,36,240,49); NewDItem(dlg,9,r,statTextItem+itemDisable,@'aux type: $',0,0,nil); SetRect(r,240,35,285,48); NewDItem(dlg,10,r,editLineItem+itemDisable,@'',4,0,nil); {--- filetype ---} SetRect(r,150,11,240,22); NewDItem(dlg,7,r,statTextItem+itemDisable,@'filetype: $',0,0,nil); SetRect(r,240,10,285,23); NewDItem(dlg,8,r,editLineItem+itemDisable,@'',4,0,nil); {--- do the modal dialog ---} ... With resources, all that would be replaced by something like: dlg := GetNewModalDialog(1); plus a few minutes spent interactively designing the dialog in a resource editor. If you decide to move the items around, you just go back into the resource editor and move all the things where you want them. (It's a _lot_ more fun than playing with lists of coordinates in SetRect calls!) Since it's possible (on the Mac anyway) to have executable code in resources, there are some really keen things you can do: You can let the user customize your program by adding code to it! (HyperCard lets you add XCMD (external command) resources to your stacks, for example. And the Resource Editor lets you add code resources for handling the interactive editing of new kinds of resources that you invent, if you want.) --David A. Lyons bitnet: awcttypa@uiamvs DAL Systems CompuServe: 72177,3233 P.O. Box 287 GEnie mail: D.LYONS2 North Liberty, IA 52317 AppleLinkPE: Dave Lyons