/*
  The famous Hello World program
  Now in GTK!!
  Tony Zuliani <zuliani@cs.unr.edu>
  Date: 3/14/00
*/

/* VERY IMPORTANT:
   This file must be included when creating a GTK program */

#include <gtk/gtk.h>

/* CloseMain() takes care of exiting from the gtk program loop,
   and returns control to main() */

gint CloseMain( GtkWidget *widget, gpointer *data)
{
  g_print( "Quitting program...\n" );

  /* Exit the main GTK program loop */
  gtk_main_quit();

  return FALSE;
}

int main(int argc, char **argv)
{
  GtkWidget *mainWindow;
  GtkWidget *okButton;
  GtkWidget *label;
  GtkWidget *vbox;

  /* The very first step you must do for any GTK program:
     Initialize GTK */
  gtk_init( &argc, &argv );

  /* Create a top-level window (the main window)
     Note:  the window is NOT visible yet */
  mainWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL);

  /* Give the top-level window a title */
  gtk_window_set_title( GTK_WINDOW (mainWindow), "Hello World" );

  /* Set the top-level window's geometry */
  gtk_window_set_default_size( GTK_WINDOW (mainWindow),
			       200,   /* width  */
			       150 ); /* height */

  /* Give mainWindow a border around okButton */
  gtk_container_border_width( GTK_CONTAINER (mainWindow), 40 );

  /* Create an event handler for pressing the 'x' button;
     Clean up code when the application exits */
  gtk_signal_connect( GTK_OBJECT (mainWindow), "delete_event",
		      GTK_SIGNAL_FUNC (CloseMain), NULL );

  /* Create the label with the Hello World text */
  label = gtk_label_new( "Hello World" );

  /* Create the OK button */
  okButton = gtk_button_new_with_label( "Quit" );

  /* Create an event handler for the button when it is clicked;
     This event handler will close the application as well */
  gtk_signal_connect( GTK_OBJECT (okButton), "clicked",
		      GTK_SIGNAL_FUNC (CloseMain), NULL );

  /* Create a new vertical packing box, where the label and okButton
     will be stored;
     FALSE means all the elements in the box can have different sizes;
     20 indicates distance between elements in vbox */
  vbox = gtk_vbox_new( FALSE, 20 );

  /* Set vbox to be a vertical box container for label
     The label is NOT visible */
  gtk_box_pack_start( GTK_BOX (vbox), label, FALSE, FALSE, 0 );

  /* Show the label */
  gtk_widget_show( label );

  /* Set vbox to be a vertical box container for okButton
     The okButton is NOT visible */
  gtk_box_pack_start( GTK_BOX (vbox), okButton, FALSE, FALSE, 0 );

  /* Show the okButton */
  gtk_widget_show( okButton );

  /* Add the vbox container to the window */
  gtk_container_add( GTK_CONTAINER (mainWindow), vbox );

  /* First, make the vbox visible, which will make the label
     and okButton visible as well, since they're part of the vbox */
  gtk_widget_show( vbox );  

  /* Second, make the mainWindow visible */
  gtk_widget_show( mainWindow );

  /* This is the event loop in GTK.  Do not return from this
     loop until the user is exiting the program */
  gtk_main();

  /* Normal exit status */
  return 0;
}
