void selection_received (GtkWidget *widget, GtkSelectionData *data) { int position; int i; SelType seltype; char *str; if (data->length < 0) { g_print("Error retrieving selection\n"); return; } seltype = SEL_TYPE_NONE; for (i=0; i<LAST_SEL_TYPE; i++) { if (seltypes[i] == data->type) { seltype = i; break; } } if (seltype == SEL_TYPE_NONE) { char *name = gdk_atom_name (data->type); g_print("Don't know how to handle type: %s\n", name?name:"<unknown>"); return; } if (selection_string != NULL) g_string_free (selection_string, TRUE); selection_string = g_string_new (NULL); gtk_text_freeze (GTK_TEXT (selection_text)); gtk_text_set_point (GTK_TEXT (selection_text), 0); gtk_text_forward_delete (GTK_TEXT (selection_text), gtk_text_get_length (GTK_TEXT (selection_text))); position = 0; while (position < data->length) { switch (seltype) { case ATOM: str = stringify_atom (data->data, &position); break; case COMPOUND_TEXT: case STRING: case TEXT: str = stringify_text (data->data, &position); break; case BITMAP: case DRAWABLE: case PIXMAP: case WINDOW: case COLORMAP: str = stringify_xid (data->data, &position); break; case INTEGER: case PIXEL: str = stringify_integer (data->data, &position); break; case SPAN: str = stringify_span (data->data, &position); break; default: { char *name = gdk_atom_name (data->type); g_print("Can't convert type %s to string\n", name?name:"<unknown>"); position = data->length; continue; } } gtk_text_insert (GTK_TEXT (selection_text), NULL, &selection_text->style->black, NULL, str, -1); gtk_text_insert (GTK_TEXT (selection_text), NULL, &selection_text->style->black, NULL, "\n", -1); g_string_append (selection_string, str); g_free (str); } gtk_text_thaw (GTK_TEXT (selection_text)); }
void selection_received (GtkWidget *widget, GtkSelectionData *selection_data) { int position; int i; SelType seltype; char *str; guchar *data; GtkTextBuffer *buffer; GdkAtom type; if (gtk_selection_data_get_length (selection_data) < 0) { g_print("Error retrieving selection\n"); return; } type = gtk_selection_data_get_data_type (selection_data); seltype = SEL_TYPE_NONE; for (i=0; i<LAST_SEL_TYPE; i++) { if (seltypes[i] == type) { seltype = i; break; } } if (seltype == SEL_TYPE_NONE) { char *name = gdk_atom_name (type); g_print("Don't know how to handle type: %s\n", name?name:"<unknown>"); return; } if (selection_string != NULL) g_string_free (selection_string, TRUE); selection_string = g_string_new (NULL); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (selection_text)); gtk_text_buffer_set_text (buffer, "", -1); position = 0; while (position < gtk_selection_data_get_length (selection_data)) { data = (guchar *) gtk_selection_data_get_data (selection_data); switch (seltype) { case ATOM: str = stringify_atom (data, &position); break; case COMPOUND_TEXT: case STRING: case TEXT: str = stringify_text (data, &position); break; case BITMAP: case DRAWABLE: case PIXMAP: case WINDOW: case COLORMAP: str = stringify_xid (data, &position); break; case INTEGER: case PIXEL: str = stringify_integer (data, &position); break; case SPAN: str = stringify_span (data, &position); break; default: { char *name = gdk_atom_name (gtk_selection_data_get_data_type (selection_data)); g_print("Can't convert type %s to string\n", name?name:"<unknown>"); position = gtk_selection_data_get_length (selection_data); continue; } } gtk_text_buffer_insert_at_cursor (buffer, str, -1); gtk_text_buffer_insert_at_cursor (buffer, "\n", -1); g_string_append (selection_string, str); g_free (str); } }