📄 example-3.c
字号:
/* This program displays a couple checkboxes and shows how to change * button labels, how to make widgets sensitive or unsensitive, how to * determine if a checkbox is active, how to provide access keys for * quick keyboard navigation, how to pass other widgets to callbacks * besides the one that receives the event, and how to manually get * gtk+ to update widgets without returning to the main event loop. */#include <gtk/gtk.h>#include <glade/glade.h>voidquit_handler (gpointer user_data, GtkWidget *widget){ /* If the user checked the OohTellMe button, we need to do some work... */ GtkWidget * ooh_tell_me = (GtkWidget*) user_data; if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ooh_tell_me))) { /* Change the checkbutton's label */ gtk_button_set_label (GTK_BUTTON (ooh_tell_me), "M_ock me"); /* Since we don't return to the main event loop, we have to manually tell * gtk+ to process the gtk_button_set_label change (and any other changes * that require processing). */ while (g_main_context_iteration (NULL, FALSE)) ; /* Mock the user and give them some time to notice the change */ printf ("Ha ha, you fell for it! "); printf ("I will not tell you what that checkbutton does!\n"); sleep (1); } gtk_main_quit ();}/* delete_handler merely calls quit_handler (it is needed because this * callback has a different number of parameters than quit_handler) */gbooleandelete_handler (gpointer user_data, GdkEvent *event, GtkWidget *widget){ quit_handler(user_data, widget); /* We have fully handled the signal */ return TRUE;}voidsensitivity_toggled (gpointer user_data, GtkWidget *widget){ gtk_widget_set_sensitive ((GtkWidget*) user_data, gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)));}intmain (int argc, char *argv[]){ GladeXML *main_window; GtkWidget *widget, *ooh_tell_me; gtk_init (&argc, &argv); /* load the interface */ main_window = glade_xml_new ("example-3.glade", NULL, NULL); /* connect the signals for the interface */ ooh_tell_me = glade_xml_get_widget (main_window, "OohTellMe"); widget = glade_xml_get_widget (main_window, "SensitivityCheckButton"); g_signal_connect_swapped (G_OBJECT (widget), "clicked", G_CALLBACK (sensitivity_toggled), G_OBJECT (ooh_tell_me)); widget = glade_xml_get_widget (main_window, "OptionWindow"); g_signal_connect_swapped (G_OBJECT (widget), "delete_event", G_CALLBACK (delete_handler), G_OBJECT (ooh_tell_me)); widget = glade_xml_get_widget (main_window, "QuitButton"); g_signal_connect_swapped (G_OBJECT (widget), "clicked", G_CALLBACK (quit_handler), G_OBJECT (ooh_tell_me)); /* start the event loop */ gtk_main (); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -