home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 215 / DDJ9206.ZIP / DFLT12.ZIP / RADIO.C < prev    next >
Text File  |  1992-04-22  |  3KB  |  106 lines

  1. /* -------- radio.c -------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static CTLWINDOW *rct[MAXRADIOS];
  6.  
  7. int RadioButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  8. {
  9.     int rtn;
  10.     DBOX *db = GetParent(wnd)->extension;
  11.     CTLWINDOW *ct = GetControl(wnd);
  12.     if (ct != NULL)    {
  13.         switch (msg)    {
  14.             case SETFOCUS:
  15.                 if (!(int)p1)
  16.                     SendMessage(NULL, HIDE_CURSOR, 0, 0);
  17.             case MOVE:
  18.                 rtn = BaseWndProc(RADIOBUTTON,wnd,msg,p1,p2);
  19.                 SetFocusCursor(wnd);
  20.                 return rtn;
  21.             case PAINT:    {
  22.                 char rb[] = "( )";
  23.                 if (ct->setting)
  24.                     rb[1] = 7;
  25.                 SendMessage(wnd, CLEARTEXT, 0, 0);
  26.                 SendMessage(wnd, ADDTEXT, (PARAM) rb, 0);
  27.                 SetFocusCursor(wnd);
  28.                 break;
  29.             }
  30.             case KEYBOARD:
  31.                 if ((int)p1 != ' ')
  32.                     break;
  33.             case LEFT_BUTTON:
  34.                 PushRadioButton(db, ct->command);
  35.                 break;
  36.             default:
  37.                 break;
  38.         }
  39.     }
  40.     return BaseWndProc(RADIOBUTTON, wnd, msg, p1, p2);
  41. }
  42.  
  43. void PushRadioButton(DBOX *db, enum commands cmd)
  44. {
  45.     CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
  46.     if (ct != NULL)    {
  47.         SetRadioButton(db, ct);
  48.         ct->isetting = ON;
  49.     }
  50. }
  51.  
  52. void SetRadioButton(DBOX *db, CTLWINDOW *ct)
  53. {
  54.     CTLWINDOW *ctt = db->ctl;
  55.     int i;
  56.  
  57.     /* --- clear all the radio buttons
  58.                 in this group on the dialog box --- */
  59.  
  60.     /* -------- build a table of all radio buttons at the
  61.             same x vector ---------- */
  62.     for (i = 0; i < MAXRADIOS; i++)
  63.         rct[i] = NULL;
  64.     while (ctt->class)    {
  65.         if (ctt->class == RADIOBUTTON)
  66.             if (ct->dwnd.x == ctt->dwnd.x)
  67.                 rct[ctt->dwnd.y] = ctt;
  68.         ctt++;
  69.     }
  70.  
  71.     /* ----- find the start of the radiobutton group ---- */
  72.     i = ct->dwnd.y;
  73.     while (i >= 0 && rct[i] != NULL)
  74.         --i;
  75.     /* ---- ignore everthing before the group ------ */
  76.     while (i >= 0)
  77.         rct[i--] = NULL;
  78.  
  79.     /* ----- find the end of the radiobutton group ---- */
  80.     i = ct->dwnd.y;
  81.     while (i < MAXRADIOS && rct[i] != NULL)
  82.         i++;
  83.     /* ---- ignore everthing past the group ------ */
  84.     while (i < MAXRADIOS)
  85.         rct[i++] = NULL;
  86.  
  87.     for (i = 0; i < MAXRADIOS; i++)    {
  88.         if (rct[i] != NULL)    {
  89.             int wason = rct[i]->setting;
  90.             rct[i]->setting = OFF;
  91.             if (wason)
  92.                 SendMessage(rct[i]->wnd, PAINT, 0, 0);
  93.         }
  94.     }
  95.     ct->setting = ON;
  96.     SendMessage(ct->wnd, PAINT, 0, 0);
  97. }
  98.  
  99. BOOL RadioButtonSetting(DBOX *db, enum commands cmd)
  100. {
  101.     CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
  102.     if (ct != NULL)
  103.         return (ct->setting == ON);
  104.     return FALSE;
  105. }
  106.