A.12. Handle Box

function new_pixmap (window_wgt, filename)
{
  local		pixmask;
  
  pixmask = gdk_pixmap_create_from_xpm
    (window_wgt.get_window(),
     window_wgt.get_color_struct (GTK_COLOR_BACKGROUND, GTK_STATE_NORMAL),
     filename);

  if (car(pixmask))
    gtk_pixmap_new (car(pixmask), cadr(pixmask));
  else
    nil;
}

method GtkWidget.get_color_struct (where, state)
{
  local		color = new GdkColor();
  color.pixel = .get_color (where, state);
  color;
}

function create_handle_box ()
{
  local handle_box, handle_box2, vbox, hbox, label, separator, toolbar,
  button;
  
  win_handle_box = new (GtkWindow);
  win_handle_box.signal ("destroy", #win_handle_box = nil);
  win_handle_box.title = "Handle Box Test";
  win_handle_box.border_width = 20;
  win_handle_box.set_policy(TRUE, TRUE, TRUE);
  win_handle_box.realize();
  
  vbox = new(GtkVBox);
  win_handle_box.add(vbox);
  vbox.show();
  
  label = new(GtkLabel);
  label.set_text("Above");
  vbox.add(label);
  label.show();
  
  separator = new(GtkHSeparator);
  vbox.add(separator);
  separator.show();
  
  hbox = new(GtkHBox);
  hbox.set_spacing(10);
  vbox.add(hbox);
  hbox.show();
  
  separator = new(GtkHSeparator);
  vbox.add(separator);
  separator.show();
  
  label = new(GtkLabel);
  label.set_text("Below");
  vbox.add(label);
  label.show();
  
  handle_box = new(GtkHandleBox);
  hbox.pack_start(handle_box, FALSE, FALSE, 0);
  hbox.show();
  
  toolbar = new(GtkToolbar);
  toolbar.set_orientation(GTK_ORIENTATION_HORIZONTAL);
  toolbar.set_style(GTK_TOOLBAR_BOTH);
  toolbar.set_button_relief(GTK_RELIEF_NORMAL);

  button = toolbar.append_item("Horizontal", "Horizontal toolbar layout",
			       "Toolbar/Horizontal",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked",
		`((@toolbar).set_orientation(GTK_ORIENTATION_HORIZONTAL)));
  

  button = toolbar.append_item("Vertical", "Vertical toolbar layout",
			       "Toolbar/Vertical",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked",
		`((@toolbar).set_orientation(GTK_ORIENTATION_VERTICAL)));
  
  toolbar.append_space();
  
  button = toolbar.append_item("Icons", "Only show toolbar icons",
			       "Toolbar/Icons",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_style(GTK_TOOLBAR_ICONS)));
  
  button = toolbar.append_item("Text", "Only show toolbar text",
			       "Toolbar/Text",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_style(GTK_TOOLBAR_TEXT)));
  
  button = toolbar.append_item("Both", "Show toolbar icons and text",
			       "Toolbar/Both",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_style(GTK_TOOLBAR_BOTH)));
  
  toolbar.append_space();
  
  button = toolbar.append_item("Small", "Use small spaces",
			       "Toolbar/Small",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_space_size(5)));
  
  button = toolbar.append_item("Big", "Use big spaces",
			       "Toolbar/Big",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_space_size(15)));
  
  toolbar.append_space();
  
  button = toolbar.append_item("Enable", "Enable tooltips",
			       "Toolbar/Enable",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_tooltips(TRUE)));
  
  button = toolbar.append_item("Disable", "Disable tooltips",
			       "Toolbar/Disable",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_tooltips(FALSE)));

  toolbar.append_space();
  
  button.label = "Borders";
  button = toolbar.append_item("Borders", "Show button borders",
			       "Toolbar/Borders",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_button_relief(GTK_RELIEF_NORMAL)));
  
  button = toolbar.append_item("Borderless", "Hide button borders",
			       "Toolbar/Borderless",
			       new_pixmap(win_handle_box, "test.xpm"));
  button.signal("clicked", `((@toolbar).set_button_relief(GTK_RELIEF_NONE)));
  
  toolbar.set_tooltips(TRUE);
  
  handle_box.add(toolbar);
  
  handle_box = new(GtkHandleBox);
  hbox.pack_start( handle_box, FALSE, FALSE, 0);
  handle_box.show();
  
  handle_box2 = new(GtkHandleBox);
  handle_box.add(handle_box2);
  label = new(GtkLabel);
  label.set_text("Fooo!");
  handle_box2.add(label);
  label.show();

  win_handle_box.show_all();
  win_handle_box;
}

function main ()
{
  local window, win_handle_box;
  TRUE=1;
  FALSE=0;
  window = create_handle_box ();
  window.signal ("destroy", #exit_program(0));
  init_ipc("handle_box", "handle_boxq");
  gtk_main ();
}