home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / apps.to.go / Kibitz / PPCBrowserOverride.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  6.7 KB  |  234 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        ppcbrowseroverride.c
  5. ** Written by:  C.K. Haun
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __CONTROLS__
  21. #include <Controls.h>
  22. #endif
  23.  
  24. #ifndef __OSEVENTS__
  25. #include <OSEvents.h>
  26. #endif
  27.  
  28. #ifndef __TRAPS__
  29. #include <Traps.h>
  30. #endif
  31.  
  32.  
  33.  
  34. /*****************************************************************************/
  35.  
  36.  
  37.  
  38. /* Thanks to C.K. for his Hack-To-Go service here in DTS.  Just leave a message,
  39. ** and the hack will show up via QuickMail really soon.  This is really interesting,
  40. ** since I've seen him type.  I don't know how he gets them done so fast.
  41. ** My only figuring is that he doesn't waste too much time with the space or tab keys
  42. ** on his keyboard.  (I added the spaces and tabs.) */
  43.  
  44. /* Theory of hack:
  45. ** Lots of zones (which describes Apple) is a real pain to browse looking for a game
  46. ** of chess.  This hack allows a really slimy way of coercing PPCBrowser to scan the
  47. ** zones until it finds a zone that has a machine running Kibitz.  Since we figure
  48. ** that this need doesn't apply to many companies (how many companies have hundreds
  49. ** of zones?), there really isn't much need to spend too much time polishing this
  50. ** “feature”.
  51. **
  52. ** Since it is a really slimy hack, it was implemented into Kibitz as a hiddel feature.
  53. ** If you hold down the shift key when you do the menu command to connect to another
  54. ** player, then you have this auto-scan-of-zones feature active.  If the feature is
  55. ** active, then if you are displaying a zone that has no machine running Kibitz, after
  56. ** a maximum of 10 seconds, the patch posts a down-arrow.  The down arrow moves the
  57. ** zone list to the next available zone, assuming that the zone list is the active
  58. ** list.
  59. **
  60. ** Of course, if the zone list isn't the active zone, this feature isn't too useful.
  61. ** This is why it is a hack.  It does the job, if you know what you are doing.
  62. **
  63. ** It actually works reasonably well, as it beats the heck of choosing on the next
  64. ** zone by hand to see if anybody's running Kibitz in that zone.
  65. */
  66.  
  67.  
  68.  
  69. typedef struct myParamBlock {
  70.     short                activeFlag;
  71.     short                dialogUp;
  72.     short                scrollActive;
  73.     long                tickCounter;
  74.     UniversalProcPtr    oldGND;
  75.     UniversalProcPtr    oldMD;
  76.     UniversalProcPtr    oldDD;
  77.     long                oldFilter;
  78. } myParamBlock;
  79. myParamBlock OurParamBlock;
  80.  
  81. /* this define contains the ASCII and the keycode, in case anyone cares */
  82. /* This is, by the way, for a US keyboard in US script.  Your script may */
  83. /* vary, please check your owners manual */
  84.  
  85. #define kDownArrowKey 0x27D1F
  86. #define kFiveSeconds 300
  87.  
  88. extern void        GNDPatch(void);  /* the actual paramter passing doesn't matter here */
  89. extern void        MDPatch(void);
  90. extern void        DDPatch(void);
  91.  
  92. void            TogglePPCPatches(Boolean on);
  93. Boolean            CheckMachineList(void);
  94. void            DoModalFilter(void);
  95. ControlHandle    FindSB(WindowPtr theWindow);
  96.  
  97.  
  98.  
  99. /*****************************************************************************/
  100.  
  101.  
  102.  
  103. void    TogglePPCPatches(Boolean on) {
  104. #ifndef __MWERKS__
  105. #pragma unused (on)
  106. #endif
  107.  
  108. #ifndef __MWERKS__
  109. #ifndef powerc
  110.  
  111.     if (on) {        /* turn everything on */
  112.         OurParamBlock.activeFlag   = true;
  113.         OurParamBlock.dialogUp     = false;
  114.         OurParamBlock.scrollActive = false;
  115.         OurParamBlock.tickCounter  = 0;
  116.         OurParamBlock.oldGND       = NGetTrapAddress(_GetNewDialog,ToolTrap);
  117.         OurParamBlock.oldMD        = NGetTrapAddress(_ModalDialog,ToolTrap);
  118.         OurParamBlock.oldDD        = NGetTrapAddress(_DisposDialog,ToolTrap);
  119.  
  120.         /* and set them to what we want please */
  121.  
  122.         NSetTrapAddress((UniversalProcPtr)GNDPatch,_GetNewDialog,ToolTrap);
  123.         NSetTrapAddress((UniversalProcPtr)MDPatch,_ModalDialog,ToolTrap);
  124.         NSetTrapAddress((UniversalProcPtr)DDPatch,_DisposDialog,ToolTrap);
  125.     }
  126.     else {        /* turning off.  Kill ebbybiddy */
  127.         OurParamBlock.activeFlag   = false;
  128.         OurParamBlock.dialogUp     = false;
  129.         OurParamBlock.scrollActive = false;
  130.         OurParamBlock.tickCounter  = 0;
  131.  
  132.         /* revert the routines */
  133.  
  134.         NSetTrapAddress(OurParamBlock.oldGND,_GetNewDialog,ToolTrap);
  135.         NSetTrapAddress(OurParamBlock.oldMD,_ModalDialog,ToolTrap);
  136.         NSetTrapAddress(OurParamBlock.oldDD,_DisposDialog,ToolTrap);
  137.     }
  138. #endif
  139. #endif
  140. }
  141.  
  142.  
  143.  
  144. /*****************************************************************************/
  145.  
  146.  
  147.  
  148. Boolean    CheckMachineList(void) {
  149.     short            v1, v2;
  150.     WindowPtr        theWind    = FrontWindow();
  151.     ControlHandle    theControl = ((WindowPeek)theWind)->controlList;
  152.     Rect            minRect    = {16000, 16000, 16000, 16000};
  153.     ControlHandle    minCtl     = nil;
  154.  
  155.     /* walk through the controls in the Front Window and find the scrollbar for the */
  156.     /* machine list.  If there are no machines listed, then we're happening. */
  157.     /* NOTE!!!! Avert young children's eyes at this point, please!  */
  158.     /* I'm being cheap and sleazy here, and using information about the */
  159.     /* PPC browser dialog (that you can see in MacsBug) itself to do this fast.*/
  160.  
  161.     while(theControl) {
  162.         v1 = (*theControl)->contrlRect.top + (*theControl)->contrlRect.left;
  163.         v2 = minRect.top + minRect.left;
  164.         if (v1 < v2) {
  165.             minRect = (*theControl)->contrlRect;
  166.             minCtl  = theControl;
  167.         }
  168.         theControl = (*theControl)->nextControl;
  169.     }
  170.  
  171.     if (minCtl)
  172.         if ((*minCtl)->contrlMax == -6)
  173.             return(true);
  174.  
  175.      return(false);
  176. }
  177.  
  178.  
  179.  
  180. /*****************************************************************************/
  181.  
  182.  
  183.  
  184. /* here's the workhorse for us */
  185. /* we make the following assumptions */
  186. /* well, only one really....    */
  187. /* the FrontWindow IS the PPC browser! */
  188. /* if this isn't true, then things are too weird for words */
  189.  
  190. void    DoModalFilter(void) {
  191.     if(TickCount() > OurParamBlock.tickCounter) {
  192.         OurParamBlock.tickCounter = TickCount() + kFiveSeconds;
  193.         if(CheckMachineList()) {
  194.             PostEvent(keyDown,kDownArrowKey);
  195.             PostEvent(keyUp,kDownArrowKey);
  196.         }
  197.     }
  198. }
  199.  
  200.  
  201.  
  202. /*****************************************************************************/
  203.  
  204.  
  205.  
  206. ControlHandle    FindSB(WindowPtr theWindow) {
  207.     Ptr                sBarProc, otherProc;
  208.     ControlHandle    theControls, fakeScroll;
  209.     WindowPeek        theWind = (WindowPeek)theWindow;
  210.     Rect            theRect = {0, 0, 9, 9};
  211.  
  212.     fakeScroll = NewControl((WindowPtr)theWind, &theRect, "\p", false, 0, 0, 10, 16, 0);
  213.     sBarProc   = *((*fakeScroll)->contrlDefProc);
  214.     StripAddress(&sBarProc);
  215.     DisposeControl(fakeScroll);
  216.  
  217.     theControls = theWind->controlList;
  218.     while (theControls) {
  219.         /* don't test against my sample */
  220.         if (theControls != fakeScroll) {
  221.             otherProc = *((*theControls)->contrlDefProc);
  222.             StripAddress(&otherProc);
  223.             if (otherProc == sBarProc)
  224.                 return(theControls);
  225.         }
  226.     }
  227.     theControls = (*theControls)->nextControl;
  228.  
  229.     return(nil);
  230. }
  231.  
  232.  
  233.  
  234.