A.21. Radio Buttons

function example_callback (button, input_string)
{
  if (button.get_active() == TRUE)
    princ(string(input_string, " was pressed."),"\n");
}

function create_radio_buttons ()
{
  local	box1, box2, group, button, separator;
  
  win_radio_buttons = new (GtkWindow);
  win_radio_buttons.signal ("destroy", #win_radio_buttons = nil);
  win_radio_buttons.title = "radio buttons";
  win_radio_buttons.border_width = 0;
  
  box1 = new (GtkVBox);
  win_radio_buttons.add (box1);
  
  box2 = new (GtkVBox);
  box2.border_width = 10;
  box2.spacing = 10;
  box1.pack_start (box2, TRUE, TRUE, 0);
  
  button1 = gtk_radio_button_new_with_label(nil, "button1");
  box2.pack_start (button1, TRUE, TRUE, 0);
  button1.signal("clicked", #example_callback(button1, "Button 1"));
  
  button2 = gtk_radio_button_new_with_label(list(button1), "button2");
  button2.set_active(TRUE);
  box2.pack_start (button2, TRUE, TRUE, 0);
  button2.signal("clicked", `example_callback(@button2, "Button 2"));
  
  button3 = gtk_radio_button_new_with_label(list(button1,button2),
					    "button3");
  box2.pack_start (button3, TRUE, TRUE, 0);
  button3.signal("clicked", `example_callback(@button3, "Button 3"));

      /* Here's an alternate way to create a group of radio buttons, using
	 the new_with_label_from_widget() method of GtkRadioButton.
      
	 button1 = new(GtkRadioButton);
	 button1.label = "button1";
	 ...
	 
	 button = button1.new_with_label_from_widget("button2");
	 ...
	 
	 button = button1.new_with_label_from_widget("button3");
	 ...

	 Note that with these, each button after the first one
	 does not need a unique name.
      */
      
  separator = new (GtkHSeparator);
  box1.pack_start (separator, FALSE, TRUE, 0);
  
  box2 = new (GtkVBox);
  box2.border_width = 10;
  box1.pack_start (box2, FALSE, TRUE, 0);
  
  button = new (GtkButton);
  button.label = "close";
  button.signal ("clicked", `(@win_radio_buttons).destroy());
  box2.pack_start (button, TRUE, TRUE, 0);
  button.can_default = TRUE;
  button.grab_default();

  win_radio_buttons.show_all();
  win_radio_buttons;
}

function main ()
{
  local window, win_radio_buttons;
  TRUE=1;
  FALSE=0;
  window = create_radio_buttons ();
  window.signal ("destroy", #exit_program(0));
  init_ipc("radio_but", "radio_butq");
  gtk_main ();
}