home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / new / dev / c / hce / examples / amiga / pools / gadctrl.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  5KB  |  180 lines

  1. /*
  2.  * Copyright (c) 1994. Author: Jason Petty.
  3.  *
  4.  * Permission is granted to anyone to use this software for any purpose
  5.  * on any computer system, and to redistribute it freely, with the
  6.  * following restrictions:
  7.  * 1) No charge may be made other than reasonable charges for reproduction.
  8.  * 2) Modified versions must be clearly marked as such.
  9.  * 3) The authors are not responsible for any harmful consequences
  10.  *    of using this software, even if they result from defects in it.
  11.  *
  12.  *
  13.  *     GadControl.c:
  14.  *
  15.  *     This file decides what happens after a gadget is pressed/depressed.
  16.  *
  17.  */
  18.  
  19. #include <exec/types.h>
  20. #include <clib/stdio.h>
  21. #include <intuition/intuition.h>
  22.  
  23. #ifndef GRAPHICS_GFXBASE_H
  24. #include <graphics/gfxbase.h>
  25. #endif
  26.  
  27. #include <libraries/gadtools.h>
  28. #include "pools.h"
  29.  
  30. extern struct Screen *my_screen;      /* Only screen. */
  31. extern struct Window *gfx_window;     /* Graphics window. (Shared window).*/
  32. extern struct Window *g_window;       /* Options window. (Shared window). */
  33. extern struct NewWindow g_new_window;
  34.  
  35. extern struct Gadget *gt_gadlist;     /* Head of league gadget list.    */
  36. extern struct Gadget *sl_gadlist;     /* Head of select league gad list.*/
  37. extern int coupon_c;                  /* Current pools coupon number.   */
  38.  
  39. static char *gt_sptr;                 /* Pointer to string gadget strings.*/
  40.  
  41.  
  42. int Open_GWind(name)   /* Open g_window, and add BOOL 'League' gadgets. */
  43. char *name;
  44. {
  45.         g_new_window.FirstGadget = gt_gadlist;
  46.         g_new_window.TopEdge = 1;
  47.         g_new_window.Height = 255;  /* Do not lower this. */
  48.    if(name)
  49.         g_new_window.Title = (UBYTE *)name;
  50.       else
  51.         g_new_window.Title = NULL;
  52.  
  53.   if(!(g_window = (struct Window *) OpenWindow( &g_new_window )))
  54.         return(NULL);
  55.  
  56.    GT_RefreshWindow(g_window);
  57. return(1);
  58. }
  59.  
  60. void Refresh_GWind()  /* Refresh gadgets in 'g_window'. */
  61. {
  62.    GT_RefreshWindow(g_window);
  63. }
  64.  
  65. void Close_GWind()  /* Close g_window. (General purpose Window). */
  66. {
  67.   if(g_window)
  68.    CloseWindow(g_window);
  69.    g_window = NULL;
  70. }
  71.  
  72. long Get_GMsgs()  /* Return Gadget selected ,window close(1000) or, */
  73. {                 /* -1 if nothing has happened. (g_window).        */
  74.   ULONG class;
  75.   APTR address;
  76.   LONG retval = -1;
  77.   int gnum;
  78.  
  79.   struct Gadget *agad = NULL;
  80.   struct StringInfo *astr;
  81.   struct IntuiMessage *imsg;
  82.  
  83.   imsg = (struct IntuiMessage *) GT_GetIMsg( g_window->UserPort );
  84.  
  85.   if(imsg)
  86.     {
  87.       class = imsg->Class;
  88.       address = (APTR)imsg->IAddress;
  89.  
  90.       GT_ReplyIMsg( imsg );
  91.  
  92.       switch( class )
  93.       {
  94.         case IDCMP_CLOSEWINDOW:            /* Close window gadget! */
  95.                retval = 1000;
  96.                break;                          
  97.         case IDCMP_GADGETUP:
  98.               agad = (struct Gadget *)gt_gadlist;
  99.  
  100.            if(!agad)      /* ?. */
  101.               return(-1);
  102.  
  103.               agad = agad->NextGadget;        /* Get past dummy gad. */
  104.               gnum = 0;
  105.  
  106.               if(agad)  /* Get Gadget num & string if string gadget. */
  107.                 {
  108.                     do {
  109.                      if(address == (APTR)agad) {       /* Find gad num. */
  110.                              retval = (LONG)gnum;
  111.                           if(agad->SpecialInfo) {      /* Is string gad?. */
  112.                              astr = (struct StringInfo *)agad->SpecialInfo;
  113.                              gt_sptr = (char *)astr->Buffer; /* Get str!.*/
  114.                              coupon_c = (int)astr->LongInt;
  115.                              }
  116.                          }
  117.                            gnum++;
  118.                           agad = agad->NextGadget;
  119.                        } while(agad && gnum < 36);
  120.                  }
  121.         break;
  122.         }
  123.     }
  124. return(retval);
  125. }
  126.  
  127. long Get_GMsgs2()  /* Return Gadget selected ,window close(1000) or, */
  128. {                  /* -1 if nothing has happened.  (gfx_window).     */
  129.   ULONG class;
  130.   APTR address;
  131.   LONG retval = -1;
  132.   int gnum;
  133.  
  134.   struct Gadget *agad = NULL;
  135.   struct StringInfo *astr;
  136.   struct IntuiMessage *imsg;
  137.  
  138.   imsg = (struct IntuiMessage *) GT_GetIMsg( gfx_window->UserPort );
  139.  
  140.   if(imsg)
  141.     {
  142.       class = imsg->Class;
  143.       address = (APTR)imsg->IAddress;
  144.  
  145.       GT_ReplyIMsg( imsg );
  146.  
  147.       switch( class )
  148.       {
  149.         case IDCMP_CLOSEWINDOW:            /* Close window gadget! */
  150.                retval = 1000;
  151.                break;                          
  152.         case IDCMP_GADGETUP:
  153.               agad = (struct Gadget *)sl_gadlist;
  154.  
  155.            if(!agad)      /* ?. */
  156.               return(-1);
  157.  
  158.               agad = agad->NextGadget;        /* Get past dummy gad. */
  159.               gnum = 0;
  160.  
  161.               if(agad)  /* Get Gadget num & string if string gadget. */
  162.                 {
  163.                     do {
  164.                      if(address == (APTR)agad) {       /* Find gad num. */
  165.                              retval = (LONG)gnum;
  166.                           if(agad->SpecialInfo) {      /* Is string gad?. */
  167.                              astr = (struct StringInfo *)agad->SpecialInfo;
  168.                              gt_sptr = (char *)astr->Buffer; /* Get str!.*/
  169.                              }
  170.                          }
  171.                            gnum++;
  172.                           agad = agad->NextGadget;
  173.                        } while(agad && gnum < 35);
  174.                  }
  175.         break;
  176.         }
  177.     }
  178. return(retval);
  179. }
  180.