A.17. Modal Window

function cmw_file (parent)
{
  local fs, vbox, hbuttonbox2, ok_button, cancel_button;
  
  fs = new(GtkFileSelection);
  fs.title = "This is a modal file selection dialog";
  fs.set_modal(TRUE);
  fs.set_transient_for(parent);
  fs.signal("destroy", #gtk_main_quit());

  vbox = car(fs.children());
  hbuttonbox2 = caddr(cdddr(vbox.children()));
  ok_button = car(hbuttonbox2.children());
  cancel_button = cadr(hbuttonbox2.children());

  ok_button.signal("clicked", #fs.destroy());
  cancel_button.signal("clicked", #fs.destroy());

  fs.show();
  init_ipc("modal_win1", "modal_win1q");
  gtk_main();

}


function create_modal_window ()
{
  local box1, frame1, box2, btnFile, btnClose, separator;
  
  win_modal_window = new (GtkWindow);
  win_modal_window.signal ("destroy", #win_modal_window = nil);
  win_modal_window.title = "This window is modal";
  win_modal_window.set_modal(TRUE);
  
  box1 = new(GtkVBox);
  box1.border_width = 5;
  frame1 = new(GtkFrame);
  frame1.label = "A standard dialog in modal form";
  box2 = new(GtkVBox);
  box2.border_width = 5;
  btnFile = new(GtkButton);
  btnFile.label = "File Selection";
  btnClose = new(GtkButton);
  btnClose.label = "Close";
  separator = new(GtkHSeparator);
  
  box1.border_width = 3;
  box2.border_width = 3;
  
  win_modal_window.add(box1);
  box1.pack_start(frame1, TRUE, TRUE, 4);
  frame1.add(box2);
  box2.pack_start(btnFile, FALSE, FALSE, 4);
  box1.pack_start(separator, FALSE, FALSE, 4);
  box1.pack_start(btnClose, FALSE, FALSE, 4);
  
  btnClose.signal("clicked", `(@win_modal_window).destroy());
  win_modal_window.signal("destroy", #gtk_main_quit());
  btnFile.signal("clicked", #cmw_file(win_modal_window));
  
  win_modal_window.show_all();
  win_modal_window;
  init_ipc("modal_win2", "modal_win2q");
  gtk_main();
}


function main ()
{
  local window, win_modal_window;
  TRUE=1;
  FALSE=0;
  window = create_modal_window ();
  window.signal ("destroy", #exit_program(0));
  init_ipc("modal_win3", "modal_win3q");
  gtk_main ();
}