home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / SmallDesk.sit / SmallDesk / SmallDesk.c next >
C/C++ Source or Header  |  1994-07-08  |  3KB  |  127 lines

  1. // SmallDesk ゥ 1994 Reinder Verlinde
  2. //
  3. // Patches DisableItem, tests for call from Finder and right item,
  4. // calls EnableItem instead if match found.
  5. //
  6. // Detailed description:
  7. //
  8. // Init time:
  9. //   Find the addresses for both 'DisableItem' and EnableItem'
  10. //   Patch DisableItem
  11. //
  12. #include <Traps.h>
  13.  
  14. #define FinderName    0x02E0
  15. #define CurApName    0x0910
  16. #define MenuList    0x0A1C
  17.  
  18. void main( void)
  19. {
  20.     asm
  21.     {
  22.         //
  23.         // DetachResource called to make this code stay around in
  24.         // the system heap after the init has run. The resource
  25.         // is in the system heap and locked (its resource flags are
  26.         // set like that)
  27.         //
  28.                         // #pragma parameter __A0 RecoverHandle(__A0)
  29.         move.l  d0,a0
  30.         dc.w    _RecoverHandle
  31.                         // pascal void DetachResource(Handle theResource)
  32.         Move.l    a0,-(SP)
  33.         dc.w    _DetachResource
  34.         //
  35.         // Remember old values of EnableItem and DisableItem
  36.         // We do not really need to be able to call 'EnableItem', but
  37.         // calling EnableItem instead of DisableItem is way easier than
  38.         // having to figure out what to do with the stack ourselves.
  39.         // It also better reflects the way to do this with MacsBug.
  40.         // (atba DisableItem ';sw pc A939;g')
  41.         //
  42.         move.w    #_EnableItem,d0
  43.         dc.w    _GetToolTrapAddress
  44.         lea        @oldEnable,a1
  45.         move.l    a0,(a1)
  46.     
  47.         move.w    #_DisableItem,d0
  48.         dc.w    _GetToolTrapAddress
  49.         lea        @oldDisable,a1
  50.         move.l    a0,(a1)
  51.         //
  52.         // Install our patch
  53.         //
  54.         lea        @newDisable,a0
  55.         move.w    #_DisableItem,d0
  56.         dc.w    _SetToolTrapAddress
  57.         //
  58.         // and quit
  59.         //
  60.         rts
  61.     oldEnable:
  62.         dc.l    0x00000000
  63.         
  64.     oldDisable:
  65.         dc.l    0x00000000
  66.  
  67.     ViewMenuHandle:
  68.         dc.l    0x00000000
  69.         
  70.     newDisable:
  71.         //
  72.         // First we do a fast test. If this is the handle of the 'View menu'
  73.         // we simply call EnableItem
  74.         //
  75.         lea        @ViewMenuHandle,a0
  76.         move.l    (a0),d0
  77.         cmp.l    #0x00,d0
  78.         beq.s    @menu_not_yet_seen
  79.         cmp.l    0x06(sp),d0
  80.         beq.s    @doEnable
  81.  
  82.     doDisable:
  83.         move.l    @oldDisable,a0
  84.         jmp        (a0)
  85.  
  86.     menu_not_yet_seen:
  87.         //
  88.         // Is this call done from within the Finder?
  89.         //
  90.         move.l    #FinderName,a0
  91.         move.l    #CurApName,a1
  92.         
  93.         move.b    (a0)+,d0
  94.         cmp.b    (a1)+,d0
  95.         bne.s    @doDisable
  96.         
  97.     again:
  98.         move.b    (a0)+,d1
  99.         cmp.b    (a1)+,d1
  100.         bne.s    @doDisable
  101.         dbpl    d0,@again
  102.         //
  103.         // We were called from the Finder. Is this the 'View' menu?
  104.         // We simply look into the Menu Handle for the length byte
  105.         // and first three characters of the menu title. If they are
  106.         // 0x04, respectively 'Vie', we assume this is the View menu.
  107.         //
  108.         move.l    0x06(sp),a0
  109.         move.l    (a0),a0
  110.         move.l    0x0E(a0),d0
  111.         cmp.l    #0x04566965,d0
  112.         bne.s    @doDisable
  113.         //
  114.         // We found the view menu. Remember its handle and do an
  115.         // enable instead of a disable
  116.         //
  117.         move.l    0x06(sp),d0
  118.         lea        @ViewMenuHandle,a0
  119.         move.l    d0,(a0)
  120.  
  121.     doEnable:
  122.         move.l    @oldEnable,a0
  123.         jmp        (a0)
  124.  
  125.     }
  126. }
  127.