home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d502 / cells.lha / CELLS / CELLSSource.lzh / cDoRequest.c < prev    next >
C/C++ Source or Header  |  1991-04-20  |  5KB  |  187 lines

  1. /*
  2.  *  CELLS       An Implementation of the WireWorld cellular automata
  3.  *              as described in Scientific American, Jan 1990.
  4.  *
  5.  *              Copyright 1990 by Davide P. Cervone.
  6.  *  You may use this code, provided this copyright notice is kept intact.
  7.  *  See the CELLS.HELP file for complete information on distribution conditions.
  8.  */
  9.  
  10. /*
  11.  *  File:  cDoRequest.c         Handles setting up and removal of requesters.
  12.  */
  13.  
  14.  
  15. #include "Cells.h"
  16. #include "cRequest.h"
  17.  
  18.  
  19. EXTREQUEST *ActiveRequest;      /* The currently active requester */
  20.  
  21.  
  22. #define REQUEST     theRequest->er_Request
  23. #define STRINFO     ((struct StringInfo *)theGadget->SpecialInfo)
  24.  
  25.  
  26. /*
  27.  *  DoReqGadgetDown()
  28.  *
  29.  *  If a requester is active, and there is a gadget down routine for the
  30.  *  requeter, call the routine passing the gadget and message pointers
  31.  */
  32.  
  33. void DoReqGadgetDown(theGadget,theMessage)
  34. struct Gadget *theGadget;
  35. struct IntuiMessage *theMessage;
  36. {
  37.    if (ActiveRequest && ActiveRequest->er_GadgetDown)
  38.       (*(ActiveRequest->er_GadgetDown))(theGadget,theMessage);
  39. }
  40.  
  41.  
  42. /*
  43.  *  DoReqGadgetUp()
  44.  *
  45.  *  If there is an active requester and it has a gadget up routine, call
  46.  *  the routine passing along the gadget and message pointers.
  47.  *  If a quit is in progress and the active requester has been removed
  48.  *  by the gadget up event, set the NotDone flag.
  49.  */
  50.  
  51. int DoReqGadgetUp(theGadget,theMessage,NotDone)
  52. struct Gadget *theGadget;
  53. struct IntuiMessage *theMessage;
  54. int NotDone;
  55. {
  56.    if (ActiveRequest && ActiveRequest->er_GadgetUp)
  57.       (*(ActiveRequest->er_GadgetUp))(theGadget,theMessage);
  58.    if (QuitInProgress && ActiveRequest == NULL) NotDone = FALSE;
  59.    return(NotDone);
  60. }
  61.  
  62.  
  63. /*
  64.  *  DoReqMouseMove()
  65.  *
  66.  *  If there is an active requester and it has a mouse move routine, 
  67.  *  call the routine passing the mouse position and the message pointer.
  68.  */
  69.  
  70. void DoReqMouseMove(MouseX,MouseY,theMessage)
  71. short MouseX,MouseY;
  72. struct IntuiMessage *theMessage;
  73. {
  74.    if (ActiveRequest && ActiveRequest->er_MouseMove)
  75.       (*(ActiveRequest->er_MouseMove))(MouseX,MouseY,theMessage);
  76. }
  77.  
  78.  
  79. /*
  80.  *  RemoveRequest()
  81.  *
  82.  *  End the specified requester and clear the active request pointer.
  83.  */
  84.  
  85. void RemoveRequest(theRequest)
  86. struct Requester *theRequest;
  87. {
  88.    EndRequest(theRequest,myWindow);
  89.    ActiveRequest = NULL;
  90. }
  91.  
  92.  
  93. /*
  94.  *  AddRequest()
  95.  *
  96.  *  If there is already an active requester, remove it.
  97.  *  Set the requester's gadget down, gadget up and mouse move routines
  98.  *    to the ones specified.
  99.  *  Center the requester in the board area of the screen, making sure it
  100.  *    does not fall off the left or top the the screen.
  101.  *  Open the requester, if possible.
  102.  *  If the requester could not be openned,
  103.  *    try to free memory from the Help system, and try again.
  104.  *  If the requester is up, set the active requester pointer,
  105.  *  otherwise give an error message
  106.  */
  107.  
  108. void AddRequest(theRequest,FuncGD,FuncGU,FuncMM)
  109. EXTREQUEST *theRequest;
  110. FUNCTION FuncGD,FuncGU,FuncMM;
  111. {
  112.    int ReqSet;
  113.  
  114.    if (ActiveRequest) RemoveRequest(ActiveRequest);
  115.    theRequest->er_GadgetDown = FuncGD;
  116.    theRequest->er_GadgetUp   = FuncGU;
  117.    theRequest->er_MouseMove  = FuncMM;
  118.    REQUEST.LeftEdge = (BOARDW - REQUEST.Width)  / 2;
  119.    REQUEST.TopEdge  = (BOARDH - REQUEST.Height) / 2;
  120.    if (REQUEST.LeftEdge < 0) REQUEST.LeftEdge = 0;
  121.    if (REQUEST.TopEdge  < 0) REQUEST.TopEdge  = 0;
  122.    ReqSet = Request(theRequest,myWindow);
  123.    if (!ReqSet)
  124.    {
  125.       if (CanClearHelpLines()) ReqSet = Request(theRequest,myWindow);
  126.       if (!ReqSet && CanClearHelpTopics())
  127.          ReqSet = Request(theRequest,myWindow);
  128.    }
  129.    if (ReqSet) ActiveRequest = theRequest;
  130.      else DoError("Not enough Memory to open that Requester");
  131. }
  132.  
  133.  
  134. /*
  135.  *  RefreshRequest()
  136.  *
  137.  *  Refresh the specified gadgets of the specified requester.
  138.  */
  139.  
  140. void RefreshRequest(theRequest,First,Last)
  141. EXTREQUEST *theRequest;
  142. int First,Last;
  143. {
  144.    struct Gadget *theGadget = REQUEST.ReqGadget;
  145.    
  146.    if (Last == NULL) Last = First;
  147.    RefreshGList(&(theGadget[First]),myWindow,theRequest,First-Last);
  148. }
  149.  
  150.  
  151. /*
  152.  *  DoReqSet()
  153.  *
  154.  *  If the request has a gadget that should be activated when the
  155.  *  requester becomes active, activate it.
  156.  */
  157.  
  158. void DoReqSet(theRequest)
  159. EXTREQUEST *theRequest;
  160. {
  161.    if (theRequest && theRequest->er_ActiveGadget)
  162.       ActivateGadget(theRequest->er_ActiveGadget,myWindow,theRequest);
  163. }
  164.  
  165.  
  166. /*
  167.  *  SetStringInfo()
  168.  *
  169.  *  If a string and gadget were specified
  170.  *    copy the string into the gadget's buffer
  171.  *    record the length of the new contents of the string
  172.  *    set the display position to the begining of the string.
  173.  */
  174.  
  175. void SetStringInfo(theGadget,theString)
  176. struct Gadget *theGadget;
  177. char *theString;
  178. {
  179.    if (theString && theGadget)
  180.    {
  181.       strncpy(STRINFO->Buffer,theString,STRINFO->MaxChars);
  182.       STRINFO->Buffer[STRINFO->MaxChars-1] = '\0';
  183.       STRINFO->BufferPos = STRINFO->NumChars = strlen(STRINFO->Buffer);
  184.       STRINFO->DispPos = STRINFO->UndoPos = 0;
  185.    }
  186. }
  187.