Appendix A. Example Code

Table of Contents
A.1. Main Window
A.2. Button Box
A.3. Buttons
A.4. Check Buttons
A.5. Dialog
A.6. Entry
A.7. File Selection
A.8. Font Selection
A.9. Gamma Curve
A.10. Labels
A.11. Radio Buttons
A.12. Range Controls
A.13. Reparent
A.14. Scrolled Windows
A.15. Spin Button
A.16. Text
A.17. Toggle Buttons
A.18. Timers

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 =
[
 [ "timertest2", #create_timertest2 ],
 [ "button box", #create_button_box ],
 [ "buttons", #create_buttons ],
 [ "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 ]
];

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)))
	{
	  eval(fname)();
	}
      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("Gtk+ v1.2.8");
  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();
}
    

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.