Appendix A. Example Code

Table of Contents

A.1. Main Window
A.2. Button Box
A.3. Buttons
A.4. Calendar
A.5. Check Buttons
A.6. Color Selection
A.7. Dialog
A.8. Entry
A.9. Event Watcher
A.10. File Selection
A.11. Font Selection
A.12. Handle Box
A.13. Gamma Curve
A.14. Labels
A.15. List
A.16. Menus
A.17. Modal Window
A.18. Panes
A.19. Pixmap
A.20. Progress Bar
A.21. Radio Buttons
A.22. Range Controls
A.23. Reparent
A.24. Rulers
A.25. Saved Position
A.26. Scrolled Windows
A.27. Spin Button
A.28. Status Bar
A.29. Test Mainloop
A.30. Text
A.31. Toggle Buttons
A.32. Tool Bar
A.33. Trees
A.34. Timers
A.35. Wrapping Functions

A.1. Main Window

/*
 * Test program for Gamma/GTK mappings
 */

FALSE := 0;
TRUE  := 1;

function main ()
{
  cd (root_path(absolute_path(car(argv))));

  gtk_rc_parse ("testgtkrc");

  create_main_window ();
  init_ipc("gtktesting", "gtktestingq");
  gtk_main ();
}

TestWindows =
[
 [ "button box", #create_button_box ],
 [ "buttons", #create_buttons ],
 [ "calendar", #create_calendar ],
 [ "check buttons", #create_check_buttons ],
 [ "clist", #create_clist],
 [ "color selection", #create_color_selection ],
 [ "ctree", #create_ctree ],
 [ "cursors", #create_cursors ],
 [ "dialog", #create_dialog ],
 [ "entry", #create_entry ],
 [ "event watcher", #create_event_watcher ],
 [ "file selection", #create_file_selection ],
 [ "font selection", #create_font_selection ],
 [ "gamma curve", #create_gamma_curve ],
 [ "handle box", #create_handle_box ],
 [ "item factory", #create_item_factory ],
 [ "labels", #create_labels ],
 [ "layout", #create_layout ],
 [ "list", #create_list ],
 [ "menus", #create_menus ],
 [ "modal window", #create_modal_window ],
 [ "notebook", #create_notebook ],
 [ "panes", #create_panes ],
 [ "pixmap", #create_pixmap ],
 [ "preview color", #create_color_preview ],
 [ "preview gray", #create_gray_preview ],
 [ "progress bar", #create_progress_bar ],
 [ "radio buttons", #create_radio_buttons ],
 [ "range controls", #create_range_controls ],
 [ "rc file", #create_rc_file ],
 [ "reparent", #create_reparent ],
 [ "rulers", #create_rulers ],
 [ "saved position", #create_saved_position ],
 [ "scrolled windows", #create_scrolled_windows ],
 [ "shapes", #create_shapes ],
 [ "spinbutton", #create_spins ],
 [ "statusbar", #create_statusbar ],
 [ "test idle", #create_idle_test ],
 [ "test mainloop", #create_mainloop ],
 [ "test scrolling", #create_scroll_test ],
 [ "test selection", #create_selection_test ],
 [ "test timeout", #create_timeout_test ],
 [ "text", #create_text ],
 [ "toggle buttons", #create_toggle_buttons ],
 [ "toolbar", #create_toolbar ],
 [ "tooltips", #create_tooltips ],
 [ "tree", #create_tree_mode_window],
 [ "WM hints", #create_wmhints ],
 [ "timer test", #create_timertest ],
 [ "timertest2", #create_timertest2 ]
];

function new_function (fname)
{
  local subname = substr(string(fname),7,-1);
  local wname = parse_string(string("win_", subname));

  if(load (string ("testfns/", subname)))
    {
      if (!(undefined_p(eval(fname))) && (function_p (eval(fname))) &&
	  (undefined_p(eval(wname)) || (eval(wname) == nil)))
	{
	  try
	  {
	    eval(fname)();
	  }
	  catch
	  {
	    princ (_last_error_, "\n");
	    print_stack ();
	  }
	}
      else if (instance_p(eval(wname)))
	eval(wname).destroy();
    }
  else
    princ("No example exists.\n");
}


function _ivar_filter (cls, !ivar)
{
  if ((car (ivar) == #_callbacks) ||
      (car (ivar) == #_exceptions))
    nil;
  else
    t;
}
	 
function create_main_window ()
{
  local	box1, label, window, scrolled_window, box2,
  button, separator;

  window = new (GtkWindow);
  window.type = GTK_WINDOW_TOPLEVEL;
  window.allow_grow = 0;
  window.allow_shrink = 0;
  window.auto_shrink = 0;
  window.name = "main window";
  window.title = "Gamma/GTK Test";
  window.width = 200;
  window.height = 400;
  window.x = window.y = 20;
  window.signal ("destroy", #exit_program (0));
  
  box1 = new (GtkVBox);
  window.add (box1);
  
  label = new (GtkLabel);
  label.set_text(string("Gtk+ v", gtk_major_version_get(), ".",
						gtk_minor_version_get(), ".",
						gtk_micro_version_get()));
  box1.pack_start (label, FALSE, FALSE, 0);
  
  scrolled_window = new (GtkScrolledWindow);
  scrolled_window.border_width = 10;
  
  box1.pack_start (scrolled_window, TRUE, TRUE, 0);
  
  box2 = new (GtkVBox);
  box2.border_width = 10;
  scrolled_window.add_with_viewport (box2);
  scrolled_window.vadjustment.lower = 0;
  scrolled_window.vadjustment.upper = 100;
  scrolled_window.vadjustment.step_increment = 40;
  scrolled_window.vadjustment.changed();
  scrolled_window.set_policy(GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  box2.set_focus_vadjustment(scrolled_window.vadjustment);
  box2.show();
  
  with spec in TestWindows do
    {
      button = new (GtkButton);
      button.label = spec[0];
      if (spec[1])
	button.signal ("clicked", `new_function (#@spec[1]));
      else
	button.sensitive = 0;
      box2.pack_start (button, TRUE, TRUE, 0);
    }

  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", #exit_program(0));
  
  box2.pack_start (button, TRUE, TRUE, 0);
  button.can_default = TRUE;
  button.grab_default();
  window.show_all();
}