TweetFollow Us on Twitter

Icon in DA Menu
Volume Number:5
Issue Number:4
Column Tag:Assembly Lab

Related Info: Desk Manager Menu Manager

Icons in DA Menus

By John A. Love, III, Springfield, VA

John got his start in the world of computers a long time ago on main frames while serving in the U. S. Air Force. He has gone from the Apple ][ to the “Fat” Mac to his SE. He can be found on GEnie (J.LOVE7).

I am currently writing a Desk Accessory in whose MENU Items I would like to have ICONs. Immediately we have two seemingly disparate numbering systems as dictated by “Inside Macintosh” {IM}. The first deals with the arithmetic pertaining to IDs for Resources owned by Desk Accessories; the second pertains to IDs for ICONs placed in MENU Items. Each set of arithmetic is simple enough to understand. The challenge, of course, is their combined implementation in each of two different operational environments.

Let’s quickly review the 1st numbering system pertaining to owned Resources. The best way to accomplish this is the picture contained in Volume I of IM:

Figure 1. Resource ID of an Owned System Resource

Since a Desk Accessory is a DRVR-type Resource, the type bits = 000. The ID of the owning Resource can be derived one of two ways, the most common of which relies on dCtlRefNum in the Device Control Entry (DCE). The last 5 bits, earmarked “variable”, are up for grabs so long, obviously, as the quantity is in the range 0 --> 31. Speaking of ranges, what this long word reduces to is a number in the range = -16000 --> -15521 for a Desk Accessory.

NOW, what about the 2nd numbering system that addresses the IDs of ICONs for MENU Items?? IM stipulates that these numbers be in the range 257 --> 511. Once again it is obvious that when you load or create your MENUs in the Open Section of your DRVR, you’ve got to temporarily change the high negative ID of your owned MENU ICON to a low positive # before you call _SetItmIcon. No sweat, right ?*!!*? Yup, anything you say !!

As if the above gymnastics weren’t enough, it turns out that “Suitcase” searches for the 1st empty slot {a positive Unit # = the ID of the owning Resource} and temporarily converts that to new IDs for your owned Resources. For example, if your Source Code specifies a Unit # of 16 {mandatory range = 12 --> 26}, but “Suitcase” detects an empty Slot #12, “Suitcase” will temporarily change all the IDs of your DA’s owned Resources accordingly {I don’t know what “Font/DA Juggler Plus” does behind the scenes}. Interesting, you say ?*!!*?

Before I address the solution to the above puzzle, I must praise to the skies both the intelligence and patience of the following folk, without whom I would still be groveling:

• Steve Brecher, author of “Suitcase”.

• Dave McWherter, author of

“McAssembly™” {$5000 SW} and the

“McSink” DA. By the way, the latter is now

called “Vantage™” and goes for $8995.

• Dave Smith..

By the way, if I blow it, I hereby declare that I am the sole occupant at the end of this tree limb that I’m busily sawing off. Steve and the two Dave’s are not responsible for any of my mistakes.

First, what does NOT work:

 Open Section   -->  _GetResInfo {original ID}
            
  _SetResInfo {new ID}
 ; ------------------------------

 Close Section -->    _SetResInfo {original ID}

These gyrations won’t work in either operational environment. Oh, your MENU ICONs will show up as advertised after you open your DA in both; however, upon closing the DA, the new ID is still in place {257 -> 511} for the 1st environment [using “Font/DA Mover”]. NO resetting was implemented. As you can see, I do NOT call _WriteResource on closing, because then I would update the System File Resource {YUCK !!} Even if I would be willing to suffer the latter, “Suitcase”, remember, messes with the owned Resource ID and the reset would be back to its make-believe ID, NOT my ID as stored on disk. “Ain’t life wonderful ??”

Okay, folks, how about making a copy of the Handle to your MENU ICONs, and, after doing the appropriate arithmetic, using the copy for your MENU and best of all, this works {well, almost }. All the Source Code that follows uses “McAssembly™”, Version 7.3 :


setMenuIcon MACRO&1,&2,&3 ; MenuHandle,Menu Item #,ICON Name.

 ; First, retrieve the attached ICON Resource:
 move.w RescIDBase,iconID
 addi.w #&2,iconID
 GetIconiconID,=iconHdl
 move.l iconHdl,tempHdl   ; Just temporary, folks !!
 
 ; Then, get the Resource file’s Attributes so we can
 ; reset them later.  After that, we make a copy of the
 ; ICON’s Handle so that we can use the COPY for the MENU:
 
 HomeResFileiconHdl,=resFileRef
 GetResFileAttrs resFileRef,=resFileAttrs
 ; ----------
 move.l iconHdl,a0
 _HandToHand
 move.l a0,cyHdl
 ReleaseResource tempHdl  ; The ORIGINAL Resource.
 ; Now, place the ICON’s COPY in the Menu Item by
 ; changing the ICON’s ID # to between 257 --> 511:
 move.w #&2,iconID
 addi.w #256,iconID
 AddResourcecyHdl,#’ICON’,iconID,!.name
 bra.s  .1
.name   text#&&3
 align
 ; Reset to ORIGINAL Attributes to clear the resChanged
 ; Bit in the Attribute Byte so that we don’t update the
 ; Resource upon Closing AND so “Suitcase” DOES reset to
 ; the disk-based ID:

.1 SetResFileAttrs resFileRef,resFileAttrs
 SetItmIcon &1,#&2,#&2    ; menuHandle,item #,icon #.
 ENDM

Okay, this almost works, but _SetResFileAttrs , itself, will eventually do a _WriteResource. Since close only counts in horseshoes, so much for that idea. Anything else?

What about setting the “MapReadOnly” bit of the Resource file’s Attribute byte so that the changed Resource Map is NOT written to disk. This could be done upon Opening the DA. Upon Closing, the original “MapReadOnly” bit could be reset. Steve Brecher correctly pointed out, however, that this effectively holds your DA’s Resource(s) captive ==> a super big “no-no” !!

Okay, I guess I’ll just have to implement what Dave McWherter suggested several months back write my own Menu Definition Procedure and thank heaven for Darryl Lovato (MacTutor, August 86). Darryl presented his code in Pascal. Just for the sake of converting to assembly, there’s no need to blatantly repeat his code here. However, I do wish to present the sub-Function that handles “mChooseMsg” simply because I have added access to hierarchical menu items that, guess what, also have ICONs. By the way, I use Mike Schuster’s “PopupSelect” routine to implement the hierarchical Menus {see MacTutor, Dec 85}:

Before I present the modified assembly Source code, I would like to extend a 1000 special “Atta-Boys” to Dave McWherter, author of “McAssembly™” and the “Vantage™” DA, aka “McSink”.

Dave’s Assembler, in my considered judgment, incorporates many of the most powerful features of Apple’s “MPW”, while retaining the ultimate of user friendliness. You can even program in the worlds of the 68010, 68020 and 68851 CPUs by invoking a pseudo-opcode, for example, ‘M68020’. A very significant part of this user friendliness focuses on what he calls the “Trap Compiler” with which the assembly language programmer can implement the sometimes-lengthy pushes onto the Stack prior to actually calling the various TRAPs via ONE line of code, just like “LightSpeed Pascal”. At the present time, the current Version (7.3) uses Apple’s “Edit”, or other comparable Editor external to “McAssembly™”. Be forewarned, however -- Dave is working on an update to “McAssembly™” wherein he is incorporating his own Editor internal to his Assembler. In this manner, if there is an assembly error (horrors !!), you bounce automatically into his Editor. Neat, isn’t it, again just like “LightSpeed Pascal”.

So long as I’m advertising, Dave’s “McSink” is now being distributed by :

Preferred Software

5100 Poplar Avenue

Suite 2716

Memphis, TN 38137

(901) 683-3383

“McSink”, now called “Vantage™”, is a text Processing Desk Accessory that includes :

Auto-paste and Auto-copy between multiple windows (max = 16)

Horizontal scrolling

KeyPad control of cursor placement

Catalog Folder contents

Statistics -- # of characters, lines, words, sentences and paragraph in the shown document

Add/Strip prefix & suffix strings, as well as line #s

Dave can be reached via:

Signature Software

2151 Brown Avenue

Bensalem, PA. 19020

(215) 639-8764

Now, onto the Source Code I’ve promised

First, how do I install my own Menu Definition Procedure?? It’s really very easy -- all I do is create a 6--byte handle in which I have code to effect an absolute jump to my Procedure. This Handle is then stored in in the “menuDefHandle” field of the Menu Record. This teeny--tiny code parcel is as follows:

In the Open section of the Desk Accessory Driver:

 move.l #6,d0    ; “jmp  myMenuDefProc”.
 _NewHandle,clear
 move.l a0,myMenuDefHdl
 bra.s  .skipCode
 ; ----------
.code   jmp $CCCCCCCC; 6 bytes.
.absAddrdc.lmyMenuDefProc-.absAddr
 ; ----------
.skipCode move.l (a0),a0  ; Convert to a Pointer.
 lea  .code,a1
 move.w (a1)+,(a0)+; Object Code word for “jmp”.
 lea  .absAddr,a1
 move.l (a1),d1
 lea  (a1,d1.l),a1 ; Absolute address of
 move.l a1,(a0)  ;   “myMenuDefProc”.
  
 NewMenudCtlMenu,!newMenuName,=mainMenuHdl
 AppendMenu mainMenuHdl,!mainMenuItems
 InstallMenuProc mainMenuHdl
  
InstallMenuProc  MACRO  &1; MenuHandle.

 move.l &1,a1    ; Handle -->
 move.l (a1),a1  ;   Pointer.
 move.l myMenuDefHdl,menuDefHandle(a1) ; _NewHandle into Menu Record.
 ; ----------
 CalcMenuSize  &1
 ENDM

Now, the “mChooseMsg” portion of my Menu Definition Procedure as I stated earlier. By the way, you’ll see below some strange looking animals, such as func, endParms, locals, endLocals, enter & exit. These beasts are special Macros that Dave McWherter wrote to assist in the Stack manipulation required to link to an external subroutine.

Some “screwy” things have to happen here in order to simulate a Hierarchical Menu. First, when you choose a main Menu Item that has a Hierarchical {sub} Menu -- you know it’s a Hierarchical Menu Item because its “Cmd-key” = $1B -- you immediately go to an external Popup Menu routine as shown below. Nothing unusual so far But, now you have to fake-out the Menu Manager by returning an un-believably high Item #, like the maximum # = 31, so the Menu Manager does not blink an Item on the main, or parent Menu as you release the Mouse over the subMenu. Hold on, I’m not through yet Down a-ways into the Code, you’ll see a reference to supporting your local _MenuChoice on the Macintosh II. Sure enough, but there’s another equally important reason for placing the Item # in the global, MenuDisable. The reason is that you peg on MenuDisable in the Menu Event section of your Desk Accessory code, instead of on the csParam field of the Parameter Block Record. The reason for this last divet is that otherwise the Menu Manager will not communicate a Menu Event to your DA. Actually, to tell you the truth, this doesn’t make a darn bit of sense, but it’s true when you write your own Menu Definition Procedure instead of using Apple’s !!

Now, hold on a cotton-pickin minute, Love, don’t you know that the new Menu Manger supports Hierarchical Menus already. Yup, sure enough!! However, there’s a bug in the portion of the new Menu Manager that handles screen up-dates after you release the Mouse over a Hierarchical Menu Item {anybody know when System Version 7.0 is due out ??}

; ======================================
; FUNCTION  doChooseMessage (myMenu:MenuHandle; myRect:Rect; myPoint:Point;
;     oldItem:INTEGER) : INTEGER;
; Returns Menu Item # you selected:
doChooseMessage  funcinteger
.myMenu handle
.myRect pointer
.myPointpoint
.oldIteminteger
 endParms
 locals
.oldRectrect
.itemKeychar
.itemMark char
.itemRect rect
 endLocals
.menuHdlrequa1   ; My worker bees ...
.cyParamBlkPtr requa2
.cyDCEPtr requ a3
.menuRegrequa4
.theItemrequd3   ; Counts Items to get current one.
.enableFlagsrequ d4; A disabled
.shift  requd0   ;   item ??
 enter
 
 movem.ld1-d7/a0-a4,-(sp) ; All your goodies.
 ; ==========
 move.l .myMenu,.menuHdl  ; Handle -->
 move.l (.menuHdl),.menuReg ;   Pointer.
 ;
 PtInRect .myPoint,.myRect,=d0
 beq  .outsideMRect
 moveq  #0,.theItem; Initialize counter.
.chooseLoop addq.w #1,.theItem
 push.l .myMenu
 push.l .myRect
 push.w .theItem
 pea  .itemRect
 bsr  GetItemRect
 ; ----------    
 PtInRect .myPoint,!.itemRect,=d1
 beq.s  .chooseLoop
 move.l menuID(.menuReg),d2 ; Support _MenuChoice
 move.w .theItem,d2;   for the Mac II.
 move.l d2,MenuDisable
.disabled?move.l menuEnable(.menuReg),.enableFlags
 BitAnd .enableFlags,#1,=d0 ; Bit #0 for ENTIRE Menu.
 beq.s  .yup; ... it’s disabled.
 ; ----------
 moveq  #1,.shift
 lsl.l  .theItem,.shift   
 BitAnd .enableFlags,.shift,=d1
 bne.s  .deSelectOld
 ; ----------    
.yup    moveq  #0,.theItem; Item is disabled.
.deSelectOldcmp.w.oldItem,.theItem
 beq  .aSelection
 tst.w  .oldItem
 beq.s  .selectNew ; MenuBar, so don’t invert back.
 ; ----------    
 push.l .myMenu
 push.l .myRect
 push.w .oldItem
 pea  .oldRect
 bsr  GetItemRect
 InverRect!.oldRect; Invert back to white
.selectNewtst.w  .theItem
 beq.s  .itsDisabled
 ; ----------    
 InverRect!.itemRect ; Blacken current selection.
 push.l .myMenu
 push.w .theItem
 pea  .itemKey
 bsr  GetItemKey
 cmpi.w #hMenuCmd,.itemKey
 bne.s  .aSelection
 ;
 GetItmMark .myMenu,.theItem,!.itemMark
 GetMHandle .itemMark,=a0 ; = MenuHandle.
 clr.l  -(sp)
 push.l a0
 push.l .myPoint
 bsr  PopupSelect
 pop.l  d1
 tst.w  d1
 beq.s  .onMenuBar ; Item’s disabled.
 move.w #31,.theItem ; ... fake out Menu Manager so it
 ;     doesn’t blink a parent item.
.itsDisabled
.aSelection move.w .theItem,.result
 bra.s  .end
 ; ==========
.outsideMRect  tst.w .oldItem
 beq.s  .onMenuBar
 ; ----------    
 push.l .myMenu
 push.l .myRect
 push.w .oldItem
 pea  .oldRect
 bsr  GetItemRect
 InverRect!.oldRect; Back to white.
.onMenuBarclr.w  .result
 ; ==========
.end    movem.l  (sp)+,d1-d7/a0-a4 ; Withdraw life savings !!
 
 exit

 
AAPL
$524.94
Apple Inc.
+5.93
MSFT
$40.01
Microsoft Corpora
-0.39
GOOG
$536.10
Google Inc.
-20.44

MacTech Search:
Community Search:

Software Updates via MacUpdate

VMware Fusion 6.0.3 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
Tweetbot 1.5.1 - Popular iOS twitter cli...
Tweetbot is a full-featured OS X Twitter client with a lot of personality. Whether it's the meticulously-crafted interface, sounds and animation, or features like multiple timelines and column views... Read more
Mac DVDRipper Pro 4.1.7 - Copy, backup,...
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
PDFpenPro 6.2 - Advanced PDF toolkit for...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.2 - Edit and annotate PDFs with...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
Monolingual 1.5.9 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. It requires a 64-bit capable Intel-based Mac and at least... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more

Latest Forum Discussions

See All

Have a Special Dead Trigger 2 Easter Bas...
Have a Special Dead Trigger 2 Easter Basket Full of Goodies, Courtesy of Madfinger Games Posted by Rob Rich on April 18th, 2014 [ permalink ] Dead Trigger 2 | Read more »
Almost All of Playdek’s Library is on Sa...
Almost All of Playdek’s Library is on Sale Right Now, and You Should Check it Out Posted by Rob Rich on April 18th, 2014 [ permalink ] Playdek has released quite a few great iOS ports of board and card games over the years, and now most of them... | Read more »
Zynga Launches Brand New Farmville Exper...
Zynga Launches Brand New Farmville Experience with Farmville 2: Country Escape Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
David. Review
David. Review By Cata Modorcea on April 18th, 2014 Our Rating: :: MINIMALISTIC IN A DIFFERENT WAYUniversal App - Designed for iPhone and iPad David is a minimalistic game wrapped inside of a soothing atmosphere in which the hero... | Read more »
Eyefi Unveils New Eyefi Cloud Service Th...
Eyefi Unveils New Eyefi Cloud Service That Allows Users to Share Media Across Personal Devices Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
Tales from the Dragon Mountain: The Lair...
Tales from the Dragon Mountain: The Lair Review By Jennifer Allen on April 18th, 2014 Our Rating: :: STEADY ADVENTURINGiPad Only App - Designed for the iPad Treading a safe path, Tales from the Dragon Mountain: The Lair is a... | Read more »
Yahoo Updates Flickr App with Advanced E...
Yahoo Updates Flickr App with Advanced Editing Features and More Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »
My Incredible Body - A Kid's App to...
My Incredible Body - A Kid's App to Learn about the Human Body 1.1.00 Device: iOS Universal Category: Education Price: $2.99, Version: 1.1.00 (iTunes) Description: Wouldn’t it be cool to look inside yourself and see what was going on... | Read more »
Trials Frontier Review
Trials Frontier Review By Carter Dotson on April 18th, 2014 Our Rating: :: A ROUGH LANDINGUniversal App - Designed for iPhone and iPad Trials Frontier finally brings the famed stunt racing franchise to mobile, but how much does its... | Read more »
Evernote Business Notebook by Moleskin I...
Evernote Business Notebook by Moleskin Introduced – Support Available in Evernote for iOS Posted by Tre Lawrence on April 18th, 2014 [ permalink ] | Read more »

Price Scanner via MacPrices.net

Deal Alert! 13-inch MacBook Pro on sale for $...
Best Buy has the 13″ 2.5GHz MacBook Pro on sale for $999.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $200 off MSRP. Price is valid... Read more
Free HopTo 2.2 Helps Enhance Your Productivit...
The HopTo app helps you do more on your iPad by providing more and easier adaccess to files and documents. Version 2.2 adds Egnyte and HopTo’s Mac OSX File Connector. If you already have the hopTo... Read more
National Distracted Driving Awareness Month:...
As the country recognizes National Distracted Driving Awareness Month, Sprint is reminding wireless consumers to focus on driving while behind the wheel, to not text or email while driving, and to... Read more
13-inch 2.4GHz Retina MacBook Pro available f...
Abt has the 13″ 2.4GHz 128GB Retina MacBook Pro available for $1229 including free shipping. Their price is $70 off MSRP. Read more
iMacs on sale for up to $160 off MSRP this we...
Best Buy has iMacs on sale for up to $160 off MSRP for a limited time. Choose free home shipping or free instant local store pickup (if available). Prices are valid for online orders only, in-store... Read more
iPad Airs on sale this weekend for up to $100...
Best Buy has WiFi iPad Airs on sale for $50 off MSRP and WiFi + Cellular iPad Airs on sale for $100 off MSRP on their online store for a limited time, with prices now starting at $449. Choose free... Read more
Apple restocks refurbished Mac minis starting...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more
Hyundai Brings Apple CarPlay To The 2015 Sona...
Hyundai Motor America has announced it will bring Apple CarPlay functionality to the 2015 Sonata. CarPlay is pitched as a smarter, safer and easier way to use iPhone in the car and gives iPhone users... Read more
Updated iPads Coming Sooner Than We Had Thoug...
MacRumors, cites KGI securities analyst Ming Chi Kuo, well-respected as an Apple product prognisticator, saying that Apple will introduce an upgraded iPad Air and iPad mini in 2014/Q3, meaning the... Read more
Toshiba Unveils New High And Low End Laptop M...
Toshiba has announced new laptop models covering both the high-end and low-end of the notebook computer spectrum. Toshiba 4K Ultra HD Laptop Toshiba’s new Satellite P55t features one of the world’s... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
…customers purchase our products, you're the one who helps them get more out of their new Apple technology. Your day in the Apple Store is filled with a range of Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Inc. Research Data Specialist - Appl...
…of Worldwide Market Research & Intelligence. The team is responsible for conducting Apple branded consumer market research. It is also responsible for analyzing data Read more
*Apple* Automotive Parts Department position...
Apple Automotive is one of the fastest growing dealer…and it shows. Consider making the switch to the Apple Automotive Group today! At Apple Automotive, we Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.