
/* Demo showing activating and deactivating objects
*/

#include <stdio.h>
#include "forms.h"

FL_FORM *form;

FL_OBJECT
        *button1,
        *button2,
        *button3,
        *button4,
        *group,
        *firstbut;

void exit_cb(FL_OBJECT *obj, long arg)
  { exit(0); }

void setit(FL_OBJECT *obj, int val)
{
  if (val)
  {
    fl_set_object_lcol(obj,FL_BLACK);
    fl_activate_object(obj);
  }
  else
  {
    fl_set_object_lcol(obj,FL_INACTIVE);
    fl_deactivate_object(obj);
  }
}

void doit(int b1, int b2, int b3, int b4)
{
  setit(button1,b1);
  setit(button2,b2);
  setit(button3,b3);
  setit(button4,b4);
}

void set_active(FL_OBJECT *obj, long arg)
{
  switch (arg)
  {
    case 0: doit(1,1,1,1); break;
    case 1: doit(0,0,0,0); break;
    case 2: doit(0,1,0,1); break;
    case 3: doit(1,0,1,0); break;
  }
}

void create_form(void)
{
  FL_OBJECT *obj;
  form = fl_bgn_form(FL_NO_BOX,420,230);
  obj = fl_add_box(FL_UP_BOX,0,0,420,230,"");
    fl_set_object_color(obj,FL_SLATEBLUE,FL_COL1);
  button1 = obj = fl_add_button(FL_NORMAL_BUTTON,20,170,150,40,"Button 1");
    fl_set_object_lsize(obj,FL_LARGE_SIZE);
  button2 = obj = fl_add_button(FL_NORMAL_BUTTON,20,120,150,40,"Button 2");
    fl_set_object_lsize(obj,FL_LARGE_SIZE);
  button3 = obj = fl_add_button(FL_NORMAL_BUTTON,20,70,150,40,"Button 3");
    fl_set_object_lsize(obj,FL_LARGE_SIZE);
  button4 = obj = fl_add_button(FL_NORMAL_BUTTON,20,20,150,40,"Button 4");
    fl_set_object_lsize(obj,FL_LARGE_SIZE);
  group = fl_bgn_group();
  firstbut = obj = fl_add_lightbutton(FL_RADIO_BUTTON,260,180,140,30,"All active");
    fl_set_object_callback(obj,set_active,0);
  obj = fl_add_lightbutton(FL_RADIO_BUTTON,260,150,140,30,"Non active");
    fl_set_object_callback(obj,set_active,1);
  obj = fl_add_lightbutton(FL_RADIO_BUTTON,260,120,140,30,"Even active");
    fl_set_object_callback(obj,set_active,2);
  obj = fl_add_lightbutton(FL_RADIO_BUTTON,260,90,140,30,"Odd active");
    fl_set_object_callback(obj,set_active,3);
  fl_end_group();
  obj = fl_add_button(FL_NORMAL_BUTTON,270,20,130,30,"Quit");
    fl_set_object_callback(obj,exit_cb,0);
  fl_end_form();
}

int
main(int argc, char **argv)
{

  fl_initialize(argv[0], "FormDemo", 0, 0 ,&argc, argv);
  create_form();

  fl_set_button(firstbut,1);
  fl_show_form(form,FL_PLACE_CENTER,FL_NOBORDER,NULL);
  while (1) fl_do_forms();
  return 0;
}
