1 /* example-start selection gettargets.c */
5 void selection_received (GtkWidget *widget,
6 GtkSelectionData *selection_data,
9 /* Signal handler invoked when user clicks on the "Get Targets" button */
11 get_targets (GtkWidget *widget, gpointer data)
13 static GdkAtom targets_atom = GDK_NONE;
15 /* Get the atom corresponding to the string "TARGETS" */
16 if (targets_atom == GDK_NONE)
17 targets_atom = gdk_atom_intern ("TARGETS", FALSE);
19 /* And request the "TARGETS" target for the primary selection */
20 gtk_selection_convert (widget, GDK_SELECTION_PRIMARY, targets_atom,
24 /* Signal handler called when the selections owner returns the data */
26 selection_received (GtkWidget *widget, GtkSelectionData *selection_data,
33 /* **** IMPORTANT **** Check to see if retrieval succeeded */
34 if (selection_data->length < 0)
36 g_print ("Selection retrieval failed\n");
39 /* Make sure we got the data in the expected form */
40 if (selection_data->type != GDK_SELECTION_TYPE_ATOM)
42 g_print ("Selection \"TARGETS\" was not returned as atoms!\n");
46 /* Print out the atoms we received */
47 atoms = (GdkAtom *)selection_data->data;
50 for (i=0; i<selection_data->length/sizeof(GdkAtom); i++)
53 name = gdk_atom_name (atoms[i]);
55 g_print ("%s\n",name);
57 g_print ("(bad atom)\n");
64 main (int argc, char *argv[])
69 gtk_init (&argc, &argv);
71 /* Create the toplevel window */
73 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
74 gtk_window_set_title (GTK_WINDOW (window), "Event Box");
75 gtk_container_set_border_width (GTK_CONTAINER (window), 10);
77 gtk_signal_connect (GTK_OBJECT (window), "destroy",
78 GTK_SIGNAL_FUNC (gtk_exit), NULL);
80 /* Create a button the user can click to get targets */
82 button = gtk_button_new_with_label ("Get Targets");
83 gtk_container_add (GTK_CONTAINER (window), button);
85 gtk_signal_connect (GTK_OBJECT(button), "clicked",
86 GTK_SIGNAL_FUNC (get_targets), NULL);
87 gtk_signal_connect (GTK_OBJECT(button), "selection_received",
88 GTK_SIGNAL_FUNC (selection_received), NULL);
90 gtk_widget_show (button);
91 gtk_widget_show (window);