home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Util / Df-Dz / Drop Menus / Drop Menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-21  |  3.7 KB  |  151 lines  |  [TEXT/KAHL]

  1. /* ################################################################## */
  2. /*
  3.  * Drop Menus : A Sick Hack
  4.  *
  5.  * Drop Menus is an attempt at providing Windows-like drop-menus in
  6.  * the Macintosh environment.  It is loosely based on "Auto Menus" by
  7.  * Michael J. Conrad, who kindly provided me the source to Auto Menus
  8.  * version 2.0 to work with.  Drop Menus eschews the VBL approach of 
  9.  * Auto Menus in favour of direct clicking on the menu bar.
  10.  *
  11.  * main() and GetRight() functions based on 'C' code by Michael Conrad
  12.  * Drop Menus is Copyright 1991 by Richard Outerbridge (outer)
  13.  * Compiled with Symantec's THINK C, Version 4.02
  14.  *
  15.  * Version History
  16.  * 1.2.0 : 910313 - first cut with _WaitMouseDown
  17.  * 1.2.2 : 910314 - Oops!  Infinite loop.  Changed to _FlushEvents (4)
  18.  * 1.2.3 : 910315 - added _Delay, and _FlushEvents 6 and 6
  19.  * 1.2.4 : 910321 - changed to _FlushEvents 6 and 2; added comments
  20.  */
  21.  
  22. #define StillDown        0xA973            /* _StillDown trap */
  23.  
  24. long oldStillDown;
  25. unsigned char trigger;
  26. unsigned char lastSD;
  27. short menuRight;
  28.  
  29. extern void    main(void);
  30. extern void myStillDown(void);
  31. extern void    PutMouse(void);
  32. extern short GetRight(void);
  33.  
  34. /* ################################################################## */
  35.  
  36. void main() {
  37. asm{
  38.         movem.l    d0/a0-a1/a4,-(a7)
  39.         lea.l    main,a4
  40.         lea.l    main,a0
  41.         _RecoverHandle
  42.         move.l    a0,a1
  43.         _HLock
  44.         move.w    d0,0x0220
  45.         move.l    a1,-(a7)
  46.         _DetachResource
  47.         move.w    #StillDown,d0
  48.         _GetTrapAddress
  49.         move.l    a0,oldStillDown
  50.         lea.l    myStillDown,a0
  51.         move.w    #StillDown,d0
  52.         _SetTrapAddress
  53.         clr.w    trigger
  54.         jsr        GetRight
  55.         move.w    d0,menuRight
  56.         movem.l    (a7)+,d0/a0-a1/a4
  57.         }
  58.     }    
  59.                 
  60. /* ################################################################### */
  61.  
  62. short GetRight() {
  63. asm {
  64.         link    a6,#-10
  65.         pea.l    -8(a6)
  66.         _GetPort
  67.         move.l    #0x006c,d0
  68.         _NewPtr
  69.         move.w    d0,0x0220
  70.         move.l    a0,-4(a6)
  71.         move.l    a0,-(a7)
  72.         _OpenPort
  73.         move.l    -4(a6),a0
  74.         move.w    14(a0),-10(a6)
  75.         move.l    -4(a6),-(a7)
  76.         _ClosePort
  77.         move.l    -4(a6),a0
  78.         _DisposPtr
  79.         move.w    d0,0x0220
  80.         move.l    -8(a6),-(a7)
  81.         _SetPort
  82.         add.w    #-100,-10(a6)
  83.         move.w    -10(a6),d0
  84.         unlk    a6
  85.         }
  86.     }
  87.         
  88. /* ################################################################## */
  89.  
  90. void myStillDown() {
  91. asm {
  92.         move.l    a4,-(a7)
  93.         lea.l    main,a4            ; Where are the globals?
  94.         move.b    trigger,d0        ; Are we already activated?
  95.         bne.s    @still
  96.                                 ; Is the mouse in the menu bar?
  97.         move.w    0x0baa,d0        ; MBarHeight
  98.         subq.w    #2,d0
  99.         cmp.w    0x0828,d0        ; mouse Y (undocumented)
  100.         ble.s    @clear
  101.         move.w    0x082a,d0        ; mouse X (undocumented)
  102.         cmp.w    menuRight,d0    ; To the right of the menus?
  103.         bge.s    @clear
  104.         cmp.w    #10,d0            ; To the left of the Apple?
  105.         ble.s    @clear
  106.         
  107.         moveq.l    #0,d0
  108.         move.w    0x02f2,d0        ; DoubleTime (lsw)
  109.         lsr.w    #2,d0            ; Divide by 4
  110.         move.l    d0,a0
  111.         _Delay                    ; Wait till things settle
  112.         
  113.         moveq.l    #6,d0
  114.         _FlushEvents            ; Clear all mouse downs & ups    
  115.         move.b    #1,trigger        ; Set the trigger
  116. @still:    
  117.         clr.w    -(a7)            ; Call the "real" routine
  118.         move.l    oldStillDown,a0
  119.         jsr        (a0)
  120.         move.b    (a7)+,d0        ; Are we really still down?
  121.         bne.s    @last            ; Yes: return 1
  122.         clr.w    -(a7)
  123.         _Button
  124.         move.b    (a7)+,d0        ; Is the Button still down?
  125.         bne.s    @notSD            ; No: return 0
  126.         move.b    lastSD,d0        ; Were we really still down last time?
  127.         beq.s    @fixSD            ; No: return 1 - else return 0
  128. @notSD:
  129.         moveq.l    #2,d0
  130.         _FlushEvents            ; Clear all lingering mouse downs
  131.         clr.w    trigger            ; Reset the trigger & lastSD
  132.         moveq.l    #0,d0            ; Get set to return 0
  133. @sdown:
  134.         move.l    (a7)+,a4
  135.         move.w    d0,4(a7)
  136.         rts
  137. @last:
  138.         move.b    #1,lastSD        ; Set lastSd
  139. @fixSD:
  140.         move.w    #0x0100,d0        ; Get set to return 1
  141.         bra.s    @sdown
  142. @clear:                            ; Not in the menu bar
  143.         move.l    oldStillDown,a0
  144.         move.l    (a7)+,a4
  145.         jmp        (a0)            ; Pass control to the "real" routine
  146.         /* rts */
  147.         }
  148.     }
  149.  
  150. /* ################################################################## */
  151.