home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / HelpWindowProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  5.4 KB  |  163 lines  |  [TEXT/KAHL]

  1. /************************************************************************************/
  2. /*    HelpWindowProc                                                                    */
  3. /*                                                                                    */
  4. /*    this procedure contains 16 toolbox calls which may move or purge memory            */
  5. /*                                                                                    */
  6. /************************************************************************************/
  7.  
  8. #include    "HelpWindowProc.h"
  9. #ifndef __C14__
  10. #include    "C14 Calculator.h"
  11. #endif
  12. #include    "TE32K.h"
  13. #include    "Globals.h"
  14. #include    "HelpGetProc.h"
  15. #include    "myActionProc.h"
  16. #include    "HelpCloseProc.h"
  17. #include    "helpCount.h"
  18.  
  19. void    HelpWindowSeg() {}
  20.  
  21. short HelpWindowProc()
  22. {
  23.     short                HelpWindRetCode = 0;
  24.     short                isDebug = 0;
  25.     short                workPart;
  26.     short                h,v;
  27.     short                j,k;
  28.     Rect                sizeRect;
  29.     ControlHandle        workControlHandle;
  30.     ControlActionUPP    myControlProc;
  31.     
  32.     myControlProc = NewControlActionProc((ProcPtr) -1);
  33.     SetPort (windTbl[1].windPtr);            /* set as the grafPort                */
  34.  
  35.     workPoint = gTheEvent.where;
  36.     GlobalToLocal(&workPoint);
  37.  
  38.     switch (gTheEvent.what)                        /* how did I get here?                */
  39.         {
  40.         case (mouseDown):                        /* MouseDown?                        */
  41.             /*DebugStr("\pJust inside HelpWindowProc()! and case(mousedown)");*/
  42.             isDebug = 1;
  43.             switch (myMouseWhere)                /*   What part of window?            */
  44.                 {
  45.                 case (inContent):                /*     content region:                */
  46.                     workRect = (**helpList).rView;            /* view area of list    */
  47.                     workRect.right += 16;                    /* plus scroll bar        */
  48.                     if (PtInRect(workPoint, &workRect))        /* if in the list area    */
  49.                         {
  50.                         workBoolean = LClick (workPoint, gTheEvent.modifiers, helpList);
  51.  
  52.                         for (j=0; j<helpCount; j++)    /* find which cell is on    */
  53.                             {
  54.                             helpCell.h = 0;
  55.                             helpCell.v = j;
  56.                             if (LGetSelect(FALSE, &helpCell, helpList))
  57.                                 break;
  58.                             }
  59.  
  60.                         if ((helpCell.v != helpPrev)
  61.                             && (j < helpCount))
  62.                             {
  63.                             helpPrev = helpCell.v;
  64.                             helpHandle = GetResource('TEXT', 1000 + helpCell.v);
  65.                             /************* GetResource(); may move memory */
  66.                             HLock (helpHandle);
  67.                             helpLong = SizeResource(helpHandle);
  68.                             EraseRect (&(**windTbl[1].windTEH[0]).viewRect);
  69.                             /************* EraseRect(); may move memory */    
  70.                             TESetText (*helpHandle+32, helpLong-32,
  71.                                     windTbl[1].windTEH[0]);
  72.                             /************* TESetText(); may move memory */
  73.                             HUnlock (helpHandle);
  74.                             ReleaseResource (helpHandle);
  75.                             /************* ReleaseResource(); may move memory */
  76.                             TECalText (windTbl[1].windTEH[0]);
  77.                             /************* TECalText(); may move memory */
  78.                             if ((**windTbl[1].windCntlH[0]).contrlValue > 0)
  79.                                 TEScroll (0, (**windTbl[1].windCntlH[0]).contrlValue,
  80.                                         windTbl[1].windTEH[0]);
  81.                             /************* TEScroll(); may move memory */
  82.                             myActionProc (windTbl[1].windCntlH[0], 0);
  83.                             InvalRect (&(**windTbl[1].windTEH[0]).viewRect);
  84.                             /************* InvalRect(); may move memory */
  85.                             }
  86.                         }
  87.                     else
  88.                         {
  89.                         /*DebugStr("\pRight before FindControl()!");*/
  90.                         workPart = FindControl (workPoint,        /* check for control*/
  91.                                 windTbl[1].windPtr,
  92.                                 &workControlHandle);
  93.                         /************* FindControl(); may move memory */
  94.                         if (workPart)                    /* if so, track it            */
  95.                             {
  96.                              if (workPart != inThumb)    /* if not in thumb: my proc    */
  97.                                  {                        /* to scroll and reset thumb    */
  98.                                                          /* on the basis of the scroll    */
  99.                                 /*DebugStr("\pRight before first TrackControl()!");*/
  100.                                 #ifdef    powerc
  101.                                     TrackControl (workControlHandle, workPoint, 
  102.                                             (ControlActionUPP) -1);
  103.                                 #else
  104.                                     TrackControl (workControlHandle, workPoint, NIL);
  105.                                 #endif
  106.                                 /************* TrackControl(); may move memory */
  107.                                 }
  108.                             else                    /* in thumb: use native routine    */
  109.                                 {                    /* then invoke my proc to        */
  110.                                                     /* scroll on the basis of thumb    */
  111.                                 kkk = GetCtlValue (workControlHandle);
  112.                                 /*DebugStr("\pRight before second TrackControl()!");*/
  113.                                 TrackControl (workControlHandle, workPoint, NIL);
  114.                                 /************* TrackControl(); may move memory */
  115.                                 kkk -= GetCtlValue (workControlHandle);
  116.                                 myActionProc(workControlHandle, (short) workPart);
  117.                                 }
  118.                             }
  119.                         }
  120.                 break;
  121.                 
  122.                 case (inDrag):                    /*     drag region:                    */
  123.                     DragWindow (windTbl[1].windPtr,
  124.                                 gTheEvent.where, &gDragRect);
  125.                     /************* DragWindow(); may move memory */
  126.                 break;
  127.                 
  128.                 case (inGoAway):                /*     goaway region:                */
  129.                     if (TrackGoAway (windTbl[1].windPtr, gTheEvent.where))
  130.                         WorkRetCode = HelpCloseProc();
  131.                     /************* TrackGoAway(); may move memory */
  132.                 break;
  133.                 }
  134.              
  135.         break;
  136.         
  137.         case (activateEvt):
  138.             j = (int) BitAnd(gTheEvent.modifiers, activeFlag);
  139.  
  140.             if (j)                                /* if activate...                    */
  141.                 {
  142.                 /*WorkRetCode = MenuUpdate(ProcHelp);*/                    /* set menus    */
  143.                 ShowControl (windTbl[1].windCntlH[0]);
  144.                 /************* ShowControl(); may move memory */
  145.                 HiliteControl (windTbl[1].windCntlH[0], 0);
  146.                 /************* HiliteControl(); may move memory */
  147.                 LActivate (TRUE, helpList);
  148.                 }
  149.             else                                /* if deactivate...                    */
  150.                 {
  151.                 HiliteControl (windTbl[1].windCntlH[0], 255);        /* unhilite        */
  152.                 /************* HiliteControl(); may move memory */
  153.                 HideControl (windTbl[1].windCntlH[0]);        /* hide (to match L/M)    */
  154.                 /************* HideControl(); may move memory */
  155.                 LActivate (FALSE, helpList);
  156.                 }
  157.         break;
  158.         }
  159.     if(isDebug) /*DebugStr("\pRight before return!");*/
  160.     if(WorkRetCode == 99) HelpWindRetCode = WorkRetCode;
  161.     return HelpWindRetCode;
  162. }
  163.