home *** CD-ROM | disk | FTP | other *** search
- // SmallDesk © 1994 Reinder Verlinde
- //
- // Patches DisableItem, tests for call from Finder and right item,
- // calls EnableItem instead if match found.
- //
- // Detailed description:
- //
- // Init time:
- // Find the addresses for both 'DisableItem' and EnableItem'
- // Patch DisableItem
- //
- // Patched DisableItem:
- // When called from the Finder, and the menu is the View menu, call
- // EnableItem instead. Remember the handle of the View menu for faster
- // processing. This is potentially a problem since the Finder may be quit
- // and relaunched while using another handle for the view menu. If this
- // happens smalldesk simply is disabled. More seriously another application
- // might be launched which uses the same handle as a menu handle. That
- // application will then be unable to disable items in that particular menu.
- // I don't expect this to happen easily, though ;-)
- //
- #include <Traps.h>
-
- #define FinderName 0x02E0
- #define CurApName 0x0910
- #define MenuList 0x0A1C
-
- void main( void)
- {
- asm
- {
- //
- // DetachResource called to make this code stay around in
- // the system heap after the init has run. The resource
- // is in the system heap and locked (its resource flags are
- // set like that)
- //
- // #pragma parameter __A0 RecoverHandle(__A0)
- move.l d0,a0
- dc.w _RecoverHandle
- // pascal void DetachResource(Handle theResource)
- Move.l a0,-(SP)
- dc.w _DetachResource
- //
- // Remember old values of EnableItem and DisableItem
- // We do not really need to be able to call 'EnableItem', but
- // calling EnableItem instead of DisableItem is way easier than
- // having to figure out what to do with the stack ourselves.
- // It also better reflects the way to do this with MacsBug.
- // (atba DisableItem ';sw pc A939;g')
- //
- move.w #_EnableItem,d0
- dc.w _GetToolTrapAddress
- lea @oldEnable,a1
- move.l a0,(a1)
-
- move.w #_DisableItem,d0
- dc.w _GetToolTrapAddress
- lea @oldDisable,a1
- move.l a0,(a1)
- //
- // Install our patch
- //
- lea @newDisable,a0
- move.w #_DisableItem,d0
- dc.w _SetToolTrapAddress
- //
- // and quit
- //
- rts
- oldEnable:
- dc.l 0x00000000
-
- oldDisable:
- dc.l 0x00000000
-
- ViewMenuHandle:
- dc.l 0x00000000
-
- newDisable:
- //
- // This is the patch for DisableItem.
- // First we do a fast test. If we were passed a handle to the 'View'
- // menu earlier we remembered it in 'ViewMenuHandle'. A simple compare
- // is then used to test for the View menu handle. If the view menu handle
- // has not yet been passed we have to check whether the current handle
- // is the handle to the view menu.
- //
- lea @ViewMenuHandle,a0
- move.l (a0),d0
- cmp.l #0x00,d0
- beq.s @menu_not_yet_seen
- cmp.l 0x06(sp),d0
- beq.s @doEnable
-
- doDisable:
- move.l @oldDisable,a0
- jmp (a0)
-
- menu_not_yet_seen:
- //
- // Is this call done from within the Finder?
- //
- move.l #FinderName,a0
- move.l #CurApName,a1
-
- move.b (a0)+,d0 // length of name of Finder
- cmp.b (a1)+,d0 // length of name of current application
- bne.s @doDisable // length bytes differ => it's not the Finder
-
- again:
- move.b (a0)+,d1
- cmp.b (a1)+,d1
- bne.s @doDisable // characters differ => it's not the Finder
- dbpl d0,@again
- //
- // We were called from the Finder. Is this the 'View' menu?
- // We simply look into the Menu Handle for the length byte
- // and first three characters of the menu title. If they are
- // 0x04, respectively 'Vie', we assume this is the View menu.
- //
- move.l 0x06(sp),a0
- move.l (a0),a0
- move.l 0x0E(a0),d0
- cmp.l #0x04566965,d0
- bne.s @doDisable
- //
- // We found the view menu. Remember its handle and do an
- // enable instead of a disable
- //
- move.l 0x06(sp),d0
- lea @ViewMenuHandle,a0
- move.l d0,(a0)
-
- doEnable:
- move.l @oldEnable,a0
- jmp (a0)
- }
- }
-