#include #include #include void changed_cb (GtkComboBox *widget, gpointer data) { GtkTreeModel *model = NULL; GtkTreeIter iter; gchar *family = NULL; model = gtk_combo_box_get_model (widget); if (gtk_combo_box_get_active_iter (widget, &iter)) { gtk_tree_model_get (model, &iter, 0, &family, -1); printf ("changed - '%s'\n", family); } else { printf ("changed - empty\n"); } } void clicked_cb (GtkButton *widget, gpointer data) { GtkComboBox *combo = GTK_COMBO_BOX (data); gtk_combo_box_set_active (combo, 5); } void clicked2_cb (GtkButton *widget, gpointer data) { GObject *combo = G_OBJECT (data); GValue val = {0,}; g_value_init (&val, G_TYPE_STRING); g_value_set_string (&val, "Arial"); g_object_set_property (combo, "font-family", &val); } void clicked3_cb (GtkButton *widget, gpointer data) { GObject *combo = G_OBJECT (data); GValue val = {0,}; PangoFontDescription *desc; desc = pango_font_description_new (); pango_font_description_set_family (desc, "Verdana"); g_value_init (&val, G_TYPE_POINTER); g_value_set_pointer (&val, desc); g_object_set_property (combo, "font-description", &val); } void clicked4_cb (GtkButton *widget, gpointer data) { GObject *combo = G_OBJECT (data); GValue val = {0,}; g_value_init (&val, G_TYPE_STRING); g_object_get_property (combo, "font-family", &val); printf ("font-family: '%s'\n", g_value_get_string (&val)); } void clicked5_cb (GtkButton *widget, gpointer data) { GObject *combo = G_OBJECT (data); GValue val = {0,}; g_value_init (&val, G_TYPE_POINTER); g_object_get_property (combo, "font-description", &val); printf ("font-description: '%s'\n", pango_font_description_get_family (g_value_get_pointer (&val))); } void clicked6_cb (GtkButton *widget, gpointer data) { GOComboFont *combo = GO_COMBO_FONT (data); gchar *family = "Arial"; go_combo_font_set_family (combo, family); } void clicked7_cb (GtkButton *widget, gpointer data) { GOComboFont *combo = GO_COMBO_FONT (data); PangoFontDescription *desc; desc = pango_font_description_new (); pango_font_description_set_family (desc, "Verdana"); go_combo_font_set_description (combo, desc); } void clicked8_cb (GtkButton *widget, gpointer data) { GOComboFont *combo = GO_COMBO_FONT (data); printf ("font-family: '%s'\n", go_combo_font_get_family (combo)); } void clicked9_cb (GtkButton *widget, gpointer data) { GOComboFont *combo = GO_COMBO_FONT (data); printf ("font-description: '%s'\n", pango_font_description_get_family (go_combo_font_get_description (combo))); } int main (int argc, char *argv[]) { GtkWidget *dlg; GtkWidget *box; GtkWidget *combo; GtkWidget *button; gtk_init (&argc, &argv); dlg = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (dlg, "delete-event", gtk_main_quit, NULL); box = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (dlg), box); combo = go_combo_font_new (); g_signal_connect (combo, "changed", G_CALLBACK (changed_cb), NULL); gtk_box_pack_start (GTK_BOX (box), combo, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Set Font #5"); g_signal_connect (button, "clicked", G_CALLBACK (clicked_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Set family 'Arial'"); g_signal_connect (button, "clicked", G_CALLBACK (clicked2_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Set description 'Verdana'"); g_signal_connect (button, "clicked", G_CALLBACK (clicked3_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Get family"); g_signal_connect (button, "clicked", G_CALLBACK (clicked4_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Get description"); g_signal_connect (button, "clicked", G_CALLBACK (clicked5_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Set family 'Arial' (wrapper)"); g_signal_connect (button, "clicked", G_CALLBACK (clicked6_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Set description 'Verdana' (wrapper)"); g_signal_connect (button, "clicked", G_CALLBACK (clicked7_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Get family (wrapper)"); g_signal_connect (button, "clicked", G_CALLBACK (clicked8_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); button = gtk_button_new_with_label ("Get description (wrapper)"); g_signal_connect (button, "clicked", G_CALLBACK (clicked9_cb), combo); gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0); gtk_widget_show_all (dlg); gtk_main (); return 0; }