Technical Questions 2.2
Volume Number: 2
Issue Number: 2
Column Tag: Ask Prof. Mac
Readers Technical Questions 
By Steve Brecher, Software Supply, MacTutor Contributing Editor
Prof. Mac depends on your technical questions for inspiration each month. If you
have programming problems in your latest project, or are just curious, send your
questions to Prof. Mac and let him research your problem.
PICTs from MacDraw
Q. Mike LePage would like to know if a MacDraw PICT file is really a QuickDraw
picture; more generally, he asks how to get a MacDraw picture into a PICT resource
that his application can use.
A. I really don't know what file format MacDraw uses; its PICT format sure
doesn't look like a QuickDraw picture to me, but it may have such pictures buried
within it. At any rate, a good way to get a PICT resource from a MacDraw document is to
paste the drawing into the Scrapbook; it will be a PICT resource in the Scrapbook file,
which can then be moved to your application using Copy/Paste within ResEdit. [Note:
ResEdit is available on source code disk #6 for this issue of MacTutor. -Ed.]
Drawing Partial Pictures
Q. Mike LePage also asks, "Suppose I have a giant picture, but want to display
only part of it in a window and not have it all scaled down into the window, with the rest
able to be scrolled into view. Is there a way of setting the bounds rectangle without
creating a bit image of the whole picture first?
A. What I'd do is pass a bounds rectangle to DrawPicture that was as large as the
whole picture. The drawing will be clipped to the window's rectangle, so only the part
of the picture that is in the window will actually be drawn, and it will not be scaled
down. To scroll, use ScrollRect, and draw the picture again with the boundsrect moved
by the size of the scroll.
Simple FilterProc
Q. Mike LePage's third question is, "I have a FilterProc for a modal dialog 'About'
box. I don't want any buttons or other controls, so the function will just check for a
mousedown and return True on that condition only." Mike wants to know how to code
such a FilterProc in assembler.
A. I'd suggest that such a function also return True if Return or Enter is pressed.
So, that's the way I've coded it in Figure 1.
Figure 1
;
; Function MyFilter(theDialog: DialogPtr;
; VAR theEvent: EventRecord;
; VAR itemHit: INTEGER): BOOLEAN;
;
; ModalDialog filterProc which returns True if the event is a
; mousedown or Return or Enter key.
;
Include SysEqu.D
;
; ASCII codes
CR Equ 13
Enter Equ 3
;
; A6 offsets--
OldA6 Set 0
RtnAddr Set OldA6+4
itemHit Set RtnAddr+4
theEvent Set itemHit+4
theDialog Set theEvent+4
Result Set theDialog+4
;
MyFilter:
Link A6,#0 ;set up stack frame
Move.L theEvent(A6),A0 ;A0 := addr of event record
Cmp #MButDwnEvt,(A0) ;mousedown?
;(note evtCode offset = 0)
; remove following 6 instructions if key events not to be tested
Beq.S @0 ;yes
Cmp #KeyDwnEvt,(A0) ;key down?
Bne.S @0 ;no
Cmp.B #CR,evtMessage+3(A0) ;Return?
Beq.S @0 ;yes
Cmp.B #Enter,evtMessage+3(A0) ;Enter?
@0 Seq Result(A6) ;set result
Unlk A6
Move.L (SP)+,A0 ;return address
Lea Result-itemHit(SP),SP ;pop arguments
Jmp (A0) ;return
Resources Potpourri
Q. Pascal M. Giordano has a lot of questions about resources, so many that it
would take too much space to list them all. So, in this case I'll provide only some
answers without the questions!
A. OpenResFile is used to open a resource file and make the resources in it
available to your application, typically via GetResource. When your application is
launched, its resource fork is automatically opened. So, you only need to use
OpenResFile to get at resources in a file other than your application. Some developers
like to maintain their non-code resources in a separate resource file while they're
working on the program, because code changes are much more frequent than resource
changes. Hence, they must use OpenResFile to make those resources available. When
the program is ready for release, the resources are included in the application file and
the call to OpenResFile is removed. My own approach is to have a separate resource
file, but to include the resources in my application file each time I link a test version.
This requires a linker which will directly include resources, such as Consulair's Link
or Signature Software's McAssembly; MDS Link won't do this (it will only include
resources that are in .REL format). That way, I can create or change my resources
directly using ResEdit or ReEdit, without a separate resource compiler step.
I very rarely use RMaker. The current version of ResEdit is quite good for
creating and editing many kinds of standard resources. I use ReEdit primarily for
editing text items in DITLs, since it provides a bigger editing box than ResEdit does for
such items. RMaker is a resource compiler that translates textual descriptions of
resources into actual resources. In olden days it was the only way to create resources;
but as ResEdit matures in its long march to completion it becomes a better and better
replacement for RMaker. [Resources can also be coded in assembler and assembled and
linked under MDS, as previously mentioned. There is also some new software showing
up that allows dialogs and windows to be "designed" on screen with the mouse and then
automatically translated into RMaker text file format. A lot more work is needed in this
area. -Ed.]
"Signature" is the name for the 4-byte code associated with an application.
"Creator" is the name for the analogous code associated with a document. Usually, they
are the same code, serving to link the document with it's creating application. Often,
"Creator" is used in the sense of "Signature," as when one speaks of "the application's
Type and Creator codes.
A BNDL resource is required in any application that is to have a custom icon
displayed by the Finder, or in any that creates documents that need to be associated with
the application (so that opening the document automatically launches the application).
Building an Editor
Q. Dr. K. Desikachary is developing a multilingual editor to process Indian
Languages. He has several questions; again, I'll just imply the questions in my
responses.
A. MacWrite file formats are documented in Apple's Technical Notes #11
(MacWrite 2.2) and #12 (MacWrite 4.5). The Technical notes are available by
subscription at $20/yr from Apple Computer, 20525 Mariani Ave MS 3-T, Cupertino
CA 95014.
I haven't seen any documentation of Microsoft Word file formats.
As far as I know, Apple's Core Edit package is the only text editor building-block
available. (Dr. Desikachary would like to find an editing package that he could build on
that doesn't have Core Edit's limit of 100 font/style changes in a document.) I haven't
seen Core Edit, but I wonder if the limit could be increased by changes to the code. Any
reader who can be of help on this may contact Dr. Desikachary at 13 McGregor St.,
Pinawa, MB ROE 1L0, Canada.
Finding All Files
Q. Bob Perez, author of VMCO (Visual/Vocal MAUG Conferencing program),
wants to know how to find a file on an HFS-formatted volume, no matter in what