Advertisement
thecplusplusguy

GTK+ tutorial 8

Jun 27th, 2012
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. //http://www.youtube.com/user/thecplusplusguy
  2. //Thanks for the typed in code to Tapit85
  3. #include <gtk/gtk.h>
  4. #include <cstring>
  5.  
  6. static void toggled_func(GtkWidget* widget, gpointer data)
  7. {
  8.     if(strcmp((char*)data, "1") == 0)
  9.         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
  10.             g_print("Button %s is set to active\n", (char*)data);
  11.         else
  12.             g_print("Button %s is set to deactive\n", (char*)data);
  13.  
  14.     if(strcmp((char*)data, "2") == 0)
  15.         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
  16.             g_print("Button %s is set to active\n", (char*)data);
  17.         else
  18.             g_print("Button %s is set to deactive\n", (char*)data);
  19.  
  20.     if(strcmp((char*)data, "3") == 0)
  21.         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
  22.             g_print("Button %s is set to active\n", (char*)data);
  23.         else
  24.             g_print("Button %s is set to deactive\n", (char*)data);
  25.  
  26.     if(strcmp((char*)data, "4") == 0)
  27.         if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
  28.             g_print("Button %s is set to active\n", (char*)data);
  29.         else
  30.             g_print("Button %s is set to deactive\n", (char*)data);
  31. }
  32.  
  33. int main(int argc, char* argv[])
  34. {
  35.     gtk_init(&argc, &argv);
  36.     GtkWidget *window, *radio, *radio2, *hbox;
  37.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  38.     g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
  39.  
  40.     hbox = gtk_hbox_new(0,0);
  41.  
  42.     radio = gtk_radio_button_new_with_label(NULL, "label 1");
  43.     gtk_box_pack_start(GTK_BOX(hbox), radio, 0,0,0);
  44.     g_signal_connect(radio, "toggled", G_CALLBACK(toggled_func), (gpointer)"1");
  45.  
  46.     radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 2");
  47.     gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
  48.     g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"2");
  49.  
  50.     radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 3");
  51.     gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
  52.     g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"3");
  53.  
  54.     radio2 = gtk_radio_button_new_with_label(gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)), "label 4");
  55.     gtk_container_add(GTK_CONTAINER(window),hbox);
  56.     gtk_box_pack_start(GTK_BOX(hbox), radio2, 0,0,0);
  57.     g_signal_connect(radio2, "toggled", G_CALLBACK(toggled_func), (gpointer)"4");
  58.    
  59. //  gtk_container_add(GTK_CONTAINER(window), hbox); // ? Runtime-Warning ?
  60.  
  61.     gtk_widget_show_all(window);
  62.     gtk_main();
  63.     return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement