A.3. Buttons

function toggle_show (obj)
{
  if (obj.visible)
    obj.hide();
  else
    obj.show();
}

function create_buttons ()
{
  local	box1, box2, table, button = make_array(10), separator,
  i, j, k, b;
  
  win_buttons = new (GtkWindow);
  win_buttons.signal ("destroy", #win_buttons = nil);
  win_buttons.title = "GtkButton";
  win_buttons.border_width = 0;

  box1 = new (GtkVBox);
  win_buttons.add (box1);
  
  table = new (GtkTable);
  table.n_rows = table.n_columns = 3;
  table.row_spacing = table.column_spacing = 5;
  table.border_width = 10;
  
  box1.pack_start (table, TRUE, TRUE, 0);
  
  for (i=0; i<9; i++)
    {
      button[i] = new (GtkButton);
      button[i].label = string ("button", i+1);
    }
  for (i=0; i<3; i++)
    {
      for (j=0; j<3; j++)
	{
	  b = (i * 3 + j);
	  button[b].signal ("clicked",
			    `toggle_show(@button[b==8?0:b+1]));
	  table.attach (button[b], i, i+1, j%3, j%3+1,
			GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
			0, 0);
	}
    }
  
  separator = new (GtkHSeparator);
  box1.pack_start (separator, FALSE, TRUE, 0);
  
  box2 = new (GtkVBox); // gtk_vbox_new (FALSE, 10);
  box2.border_width = 10;
  box1.pack_start (box2, FALSE, TRUE, 0);
  
  button[9] = new (GtkButton);
  button[9].label = "close";
  button[9].signal ("clicked", `(@win_buttons).destroy());
  
  box2.pack_start (button[9], TRUE, TRUE, 0);
  button[9].can_default = TRUE;
  button[9].grab_default();
  
  win_buttons.show_all();
  win_buttons;
}

function main ()
{
  local window, win_buttons;
  TRUE=1;
  FALSE=0;
  window = create_buttons ();
  window.signal ("destroy", #exit_program(0));
  init_ipc("buttons", "buttonsq");
  gtk_main ();
}