home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / df3os2.zip / RADIO.CPP < prev    next >
C/C++ Source or Header  |  1993-09-23  |  2KB  |  58 lines

  1. // ------------- radio.cpp
  2.  
  3. #include "radio.h"
  4. #include "desktop.h"
  5.  
  6. RadioButton::RadioButton(const char *lbl, int lf, int tp,
  7.         DFWindow *par) : Button(lbl, lf, tp, par)
  8. {
  9.     windowtype = RadioButtonWindow;
  10.     setchar = 7;
  11. }
  12.  
  13. void RadioButton::InvertButton()
  14. {
  15.     PushButton();
  16. }
  17.  
  18. void RadioButton::PushButton()
  19. {
  20.     int ht = desktop.screen().Height();
  21.     DFWindow **rd = new DFWindow *[ht];
  22.     for (int i = 0; i < ht; i++)
  23.         rd[i] = 0;
  24.     // - build a table of radio buttons at the same x coordinate
  25.     DFWindow *sib = Parent()->First();
  26.     while (sib != 0)    {
  27.         if (sib->WindowType() == RadioButtonWindow)    {
  28.             if (sib->Left() == Left())    {
  29.                 int tp = sib->Top();
  30.                 if (tp < ht)
  31.                     rd[tp] = sib;
  32.             }
  33.         }
  34.         sib = sib->Next();
  35.     }
  36.     // ----- find the start of the radiobutton group
  37.     i = Top();
  38.     while (i >= 0 && rd[i] != 0)
  39.         --i;
  40.     // ---- ignore everthing before the group
  41.     while (i >= 0)
  42.         rd[i--] = 0;
  43.     // ----- find the end of the radiobutton group
  44.     i = Top();
  45.     while (i < ht && rd[i] != 0)
  46.         i++;
  47.     // ---- ignore everthing past the group
  48.     while (i < ht)
  49.         rd[i++] = 0;
  50.     // ------ release all the radio buttons in the group
  51.     for (i = 0; i < ht; i++)
  52.         if (rd[i] != 0)
  53.             ((RadioButton *)rd[i])->ReleaseButton();
  54.     delete [] rd;
  55.     // ----- set the chosen radio button
  56.     Button::PushButton();
  57. }
  58.