2006-08-18

GtkComboBox stuff

#include <gtk/gtk.h>

static gboolean window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer data);
static void cbcb( GtkWidget *widget, gpointer data);

GtkWidget *label;

char *numbers[] ={"Ichi", "Ni", "San", "Shi", "Go", "Roku", "Shichi", "Hachi", NULL};

int main( int argc, char **argv)
{
  GtkWidget *window, *vbox, *combobox;
  int i =0;

  gtk_set_locale( );

  gtk_init( &argc, &argv);

  window =gtk_window_new( GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title( GTK_WINDOW( window), "The Walrus was Paul");
  g_signal_connect( G_OBJECT( window),
      "delete_event",
      G_CALLBACK( window_delete_event), NULL);

  vbox =gtk_vbox_new( FALSE, 8);
  gtk_container_add( GTK_CONTAINER( window), vbox);

  combobox =gtk_combo_box_new_text( );  // the easier way
  while( NULL !=numbers[ i])
    gtk_combo_box_append_text( GTK_COMBO_BOX( combobox), numbers[ i++]);
  g_signal_connect( combobox, "changed", G_CALLBACK( cbcb), NULL);
  gtk_box_pack_start( GTK_BOX( vbox), combobox, FALSE, TRUE, 8);

  label =gtk_label_new( "...");
  gtk_box_pack_start( GTK_BOX( vbox), label, FALSE, TRUE, 8);

  gtk_widget_show_all( window);

  gtk_main( );

  return 0;
}

static gboolean window_delete_event( GtkWidget *widget, GdkEvent *event, gpointer data)
{
  exit( 0);
}

static void cbcb( GtkWidget *widget, gpointer data)
{
  gtk_label_set_text( GTK_LABEL( label),
        gtk_combo_box_get_active_text( GTK_COMBO_BOX( widget)));
}