summaryrefslogtreecommitdiff
path: root/gtk/gtkselection.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2017-12-14 00:43:19 +0100
committerBenjamin Otte <otte@redhat.com>2017-12-14 00:44:26 +0100
commit54f9aef0d43299c9a5c02b45641a80f3657e9981 (patch)
tree043c75c17891a667aae64e400c8a0a424c93c2a5 /gtk/gtkselection.c
parentca5f859dc8134eca53c328eaa35b6d5c1dca1856 (diff)
downloadgtk+-54f9aef0d43299c9a5c02b45641a80f3657e9981.tar.gz
gdk: Remove gdk_selection_convert()
It's not used anymore.
Diffstat (limited to 'gtk/gtkselection.c')
-rw-r--r--gtk/gtkselection.c660
1 files changed, 0 insertions, 660 deletions
diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c
index fad6aec4f9..0c7cd566a6 100644
--- a/gtk/gtkselection.c
+++ b/gtk/gtkselection.c
@@ -104,96 +104,6 @@
#include <gdk/wayland/gdkwayland.h>
#endif
-#undef DEBUG_SELECTION
-
-/* Maximum size of a sent chunk, in bytes. Also the default size of
- our buffers */
-#ifdef GDK_WINDOWING_X11
-#define GTK_SELECTION_MAX_SIZE(display) \
- GDK_IS_X11_DISPLAY (display) ? \
- MIN(262144, \
- XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0 \
- ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100 \
- : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)\
- : G_MAXINT
-#else
-/* No chunks on Win32 */
-#define GTK_SELECTION_MAX_SIZE(display) G_MAXINT
-#endif
-
-#define IDLE_ABORT_TIME 30
-
-enum {
- INCR,
- MULTIPLE,
- TARGETS,
- TIMESTAMP,
- SAVE_TARGETS,
- LAST_ATOM
-};
-
-typedef struct _GtkIncrConversion GtkIncrConversion;
-typedef struct _GtkIncrInfo GtkIncrInfo;
-typedef struct _GtkRetrievalInfo GtkRetrievalInfo;
-
-struct _GtkIncrConversion
-{
- GdkAtom target; /* Requested target */
- GdkAtom property; /* Property to store in */
- GtkSelectionData data; /* The data being supplied */
- gint offset; /* Current offset in sent selection.
- * -1 => All done
- * -2 => Only the final (empty) portion
- * left to send */
-};
-
-struct _GtkIncrInfo
-{
- GdkWindow *requestor; /* Requestor window - we create a GdkWindow
- so we can receive events */
- GdkAtom selection; /* Selection we're sending */
-
- GtkIncrConversion *conversions; /* Information about requested conversions -
- * With MULTIPLE requests (benighted 1980's
- * hardware idea), there can be more than
- * one */
- gint num_conversions;
- gint num_incrs; /* number of remaining INCR style transactions */
- guint32 idle_time;
-};
-
-
-struct _GtkRetrievalInfo
-{
- GtkWidget *widget;
- GdkAtom selection; /* Selection being retrieved. */
- GdkAtom target; /* Form of selection that we requested */
- guint32 idle_time; /* Number of seconds since we last heard
- from selection owner */
- guchar *buffer; /* Buffer in which to accumulate results */
- gint offset; /* Current offset in buffer, -1 indicates
- not yet started */
- guint32 notify_time; /* Timestamp from SelectionNotify */
-};
-
-/* Local Functions */
-static void gtk_selection_init (void);
-static gboolean gtk_selection_retrieval_timeout (GtkRetrievalInfo *info);
-static void gtk_selection_retrieval_report (GtkRetrievalInfo *info,
- GdkAtom type,
- gint format,
- guchar *buffer,
- gint length,
- guint32 time);
-static int gtk_selection_bytes_per_item (gint format);
-
-/* Local Data */
-static gint initialize = TRUE;
-static GList *current_retrievals = NULL;
-static GList *current_incrs = NULL;
-
-static GdkAtom gtk_selection_atoms[LAST_ATOM];
-
/****************
* Target Lists *
****************/
@@ -364,110 +274,6 @@ gtk_content_formats_add_uri_targets (GdkContentFormats *list)
}
/**
- * gtk_selection_remove_all:
- * @widget: a #GtkWidget
- *
- * Removes all handlers and unsets ownership of all
- * selections for a widget. Called when widget is being
- * destroyed. This function will not generally be
- * called by applications.
- **/
-void
-gtk_selection_remove_all (GtkWidget *widget)
-{
- GList *tmp_list;
- GList *next;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
-
- /* Remove pending requests/incrs for this widget */
-
- tmp_list = current_retrievals;
- while (tmp_list)
- {
- next = tmp_list->next;
- if (((GtkRetrievalInfo *)tmp_list->data)->widget == widget)
- {
- current_retrievals = g_list_remove_link (current_retrievals,
- tmp_list);
- /* structure will be freed in timeout */
- g_list_free (tmp_list);
- }
- tmp_list = next;
- }
-}
-
-
-/**
- * gtk_selection_convert:
- * @widget: The widget which acts as requestor
- * @selection: Which selection to get
- * @target: Form of information desired (e.g., STRING)
- * @time_: Time of request (usually of triggering event)
- In emergency, you could use #GDK_CURRENT_TIME
- *
- * Requests the contents of a selection. When received,
- * a “selection-received” signal will be generated.
- *
- * Returns: %TRUE if requested succeeded. %FALSE if we could not process
- * request. (e.g., there was already a request in process for
- * this widget).
- **/
-gboolean
-gtk_selection_convert (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
- guint32 time_)
-{
- GtkRetrievalInfo *info;
- GList *tmp_list;
- guint id;
-
- g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
- g_return_val_if_fail (selection != NULL, FALSE);
-
- if (initialize)
- gtk_selection_init ();
-
- if (!gtk_widget_get_realized (widget))
- gtk_widget_realize (widget);
-
- /* Check to see if there are already any retrievals in progress for
- this widget. If we changed GDK to use the selection for the
- window property in which to store the retrieved information, then
- we could support multiple retrievals for different selections.
- This might be useful for DND. */
-
- tmp_list = current_retrievals;
- while (tmp_list)
- {
- info = (GtkRetrievalInfo *)tmp_list->data;
- if (info->widget == widget)
- return FALSE;
- tmp_list = tmp_list->next;
- }
-
- info = g_slice_new (GtkRetrievalInfo);
-
- info->widget = widget;
- info->selection = selection;
- info->target = target;
- info->idle_time = 0;
- info->buffer = NULL;
- info->offset = -1;
-
- /* Otherwise, we need to go through X */
-
- current_retrievals = g_list_append (current_retrievals, info);
- gdk_selection_convert (gtk_widget_get_window (widget), selection, target, time_);
- id = gdk_threads_add_timeout (1000,
- (GSourceFunc) gtk_selection_retrieval_timeout, info);
- g_source_set_name_by_id (id, "[gtk+] gtk_selection_retrieval_timeout");
-
- return TRUE;
-}
-
-/**
* gtk_selection_data_get_selection:
* @selection_data: a pointer to a #GtkSelectionData-struct.
*
@@ -1570,453 +1376,6 @@ gtk_selection_data_targets_include_uri (const GtkSelectionData *selection_data)
return result;
}
-
-/*************************************************************
- * gtk_selection_init:
- * Initialize local variables
- * arguments:
- *
- * results:
- *************************************************************/
-
-static void
-gtk_selection_init (void)
-{
- gtk_selection_atoms[INCR] = gdk_atom_intern_static_string ("INCR");
- gtk_selection_atoms[MULTIPLE] = gdk_atom_intern_static_string ("MULTIPLE");
- gtk_selection_atoms[TIMESTAMP] = gdk_atom_intern_static_string ("TIMESTAMP");
- gtk_selection_atoms[TARGETS] = gdk_atom_intern_static_string ("TARGETS");
- gtk_selection_atoms[SAVE_TARGETS] = gdk_atom_intern_static_string ("SAVE_TARGETS");
-
- initialize = FALSE;
-}
-
-/*************************************************************
- * _gtk_selection_incr_event:
- * Called whenever an PropertyNotify event occurs for an
- * GdkWindow with user_data == NULL. These will be notifications
- * that a window we are sending the selection to via the
- * INCR protocol has deleted a property and is ready for
- * more data.
- *
- * arguments:
- * window: the requestor window
- * event: the property event structure
- *
- * results:
- *************************************************************/
-
-gboolean
-_gtk_selection_incr_event (GdkWindow *window,
- GdkEventProperty *event)
-{
- GList *tmp_list;
- GtkIncrInfo *info = NULL;
- gint num_bytes;
- guchar *buffer;
- gulong selection_max_size;
- GdkPropertyState state;
- GdkAtom atom;
- int i;
- GdkDisplay *display;
-
- gdk_event_get_property ((GdkEvent *)event, &atom, &state);
- if (state != GDK_PROPERTY_DELETE)
- return FALSE;
-
-#ifdef DEBUG_SELECTION
- g_message ("PropertyDelete, property %ld", atom);
-#endif
-
- display = gdk_window_get_display (window);
- selection_max_size = GTK_SELECTION_MAX_SIZE (display);
-
- /* Now find the appropriate ongoing INCR */
- tmp_list = current_incrs;
- while (tmp_list)
- {
- info = (GtkIncrInfo *)tmp_list->data;
- if (info->requestor == gdk_event_get_window ((GdkEvent *)event))
- break;
-
- tmp_list = tmp_list->next;
- }
-
- if (tmp_list == NULL)
- return FALSE;
-
- /* Find out which target this is for */
- for (i=0; i<info->num_conversions; i++)
- {
- if (info->conversions[i].property == atom &&
- info->conversions[i].offset != -1)
- {
- int bytes_per_item;
-
- info->idle_time = 0;
-
- if (info->conversions[i].offset == -2) /* only the last 0-length
- piece*/
- {
- num_bytes = 0;
- buffer = NULL;
- }
- else
- {
- num_bytes = info->conversions[i].data.length -
- info->conversions[i].offset;
- buffer = info->conversions[i].data.data +
- info->conversions[i].offset;
-
- if (num_bytes > selection_max_size)
- {
- num_bytes = selection_max_size;
- info->conversions[i].offset += selection_max_size;
- }
- else
- info->conversions[i].offset = -2;
- }
-#ifdef DEBUG_SELECTION
- g_message ("INCR: put %d bytes (offset = %d) into window 0x%lx , property %ld",
- num_bytes, info->conversions[i].offset,
- GDK_WINDOW_XID(info->requestor), atom);
-#endif
-
- bytes_per_item = gtk_selection_bytes_per_item (info->conversions[i].data.format);
-
-#ifdef GDK_WINDOWING_X11
- if (GDK_IS_X11_DISPLAY (display))
- gdk_x11_display_error_trap_push (display);
-#endif
-
- gdk_property_change (info->requestor, atom,
- info->conversions[i].data.type,
- info->conversions[i].data.format,
- GDK_PROP_MODE_REPLACE,
- buffer,
- num_bytes / bytes_per_item);
-
-#ifdef GDK_WINDOWING_X11
- if (GDK_IS_X11_DISPLAY (display))
- gdk_x11_display_error_trap_pop_ignored (display);
-#endif
-
- if (info->conversions[i].offset == -2)
- {
- g_free (info->conversions[i].data.data);
- info->conversions[i].data.data = NULL;
- }
-
- if (num_bytes == 0)
- {
- info->num_incrs--;
- info->conversions[i].offset = -1;
- }
- }
- }
-
- /* Check if we're finished with all the targets */
-
- if (info->num_incrs == 0)
- {
- current_incrs = g_list_remove_link (current_incrs, tmp_list);
- g_list_free (tmp_list);
- /* Let the timeout free it */
- }
-
- return TRUE;
-}
-
-/*************************************************************
- * _gtk_selection_notify:
- * Handler for “selection-notify-event” signals on windows
- * where a retrieval is currently in process. The selection
- * owner has responded to our conversion request.
- * arguments:
- * widget: Widget getting signal
- * event: Selection event structure
- * info: Information about this retrieval
- * results:
- * was event handled?
- *************************************************************/
-
-gboolean
-_gtk_selection_notify (GtkWidget *widget,
- GdkEventSelection *event)
-{
- GList *tmp_list;
- GtkRetrievalInfo *info = NULL;
- GdkWindow *window;
- guchar *buffer = NULL;
- gint length;
- GdkAtom type;
- GdkAtom selection;
- GdkAtom property;
- gint format;
- guint32 time;
-
- gdk_event_get_selection ((GdkEvent *)event, &selection);
- gdk_event_get_selection_property ((GdkEvent *)event, &property, NULL, NULL);
- time = gdk_event_get_time ((GdkEvent *)event);
-
-#ifdef DEBUG_SELECTION
- g_message ("Initial receipt of selection %ld, target %ld (property = %ld)",
- selection, target, property);
-#endif
-
- window = gtk_widget_get_window (widget);
-
- tmp_list = current_retrievals;
- while (tmp_list)
- {
- info = (GtkRetrievalInfo *)tmp_list->data;
- if (info->widget == widget && info->selection == selection)
- break;
- tmp_list = tmp_list->next;
- }
-
- if (!tmp_list) /* no retrieval in progress */
- return FALSE;
-
- if (property != NULL)
- length = gdk_selection_property_get (window, &buffer,
- &type, &format);
- else
- length = 0; /* silence gcc */
-
- if (property == NULL || buffer == NULL)
- {
- current_retrievals = g_list_remove_link (current_retrievals, tmp_list);
- g_list_free (tmp_list);
- /* structure will be freed in timeout */
- gtk_selection_retrieval_report (info, NULL, 0, NULL, -1, time);
-
- return TRUE;
- }
-
- if (type == gtk_selection_atoms[INCR])
- {
- /* The remainder of the selection will come through PropertyNotify
- events */
-
- info->notify_time = time;
- info->idle_time = 0;
- info->offset = 0; /* Mark as OK to proceed */
- gdk_window_set_events (window,
- gdk_window_get_events (window)
- | GDK_PROPERTY_CHANGE_MASK);
- }
- else
- {
- /* We don't delete the info structure - that will happen in timeout */
- current_retrievals = g_list_remove_link (current_retrievals, tmp_list);
- g_list_free (tmp_list);
-
- info->offset = length;
- gtk_selection_retrieval_report (info,
- type, format,
- buffer, length, time);
- }
-
- gdk_property_delete (window, property);
-
- g_free (buffer);
-
- return TRUE;
-}
-
-/*************************************************************
- * _gtk_selection_property_notify:
- * Handler for “property-notify-event” signals on windows
- * where a retrieval is currently in process. The selection
- * owner has added more data.
- * arguments:
- * widget: Widget getting signal
- * event: Property event structure
- * info: Information about this retrieval
- * results:
- * was event handled?
- *************************************************************/
-
-gboolean
-_gtk_selection_property_notify (GtkWidget *widget,
- GdkEventProperty *event)
-{
- GList *tmp_list;
- GtkRetrievalInfo *info = NULL;
- GdkWindow *window;
- guchar *new_buffer;
- int length;
- GdkAtom type;
- gint format;
- GdkAtom property;
- GdkPropertyState state;
-
- g_return_val_if_fail (widget != NULL, FALSE);
- g_return_val_if_fail (event != NULL, FALSE);
-
- gdk_event_get_property ((GdkEvent *)event, &property, &state);
-
-#if defined(GDK_WINDOWING_WIN32) || defined(GDK_WINDOWING_X11)
- if ((state != GDK_PROPERTY_NEW_VALUE) || /* property was deleted */
- (property != gdk_atom_intern_static_string ("GDK_SELECTION"))) /* not the right property */
-#endif
- return FALSE;
-
-#ifdef DEBUG_SELECTION
- g_message ("PropertyNewValue, property %ld", property);
-#endif
-
- tmp_list = current_retrievals;
- while (tmp_list)
- {
- info = (GtkRetrievalInfo *)tmp_list->data;
- if (info->widget == widget)
- break;
- tmp_list = tmp_list->next;
- }
-
- if (!tmp_list) /* No retrieval in progress */
- return FALSE;
-
- if (info->offset < 0) /* We haven't got the SelectionNotify
- for this retrieval yet */
- return FALSE;
-
- info->idle_time = 0;
-
- window = gtk_widget_get_window (widget);
- length = gdk_selection_property_get (window, &new_buffer,
- &type, &format);
- gdk_property_delete (window, property);
-
- /* We could do a lot better efficiency-wise by paying attention to
- what length was sent in the initial INCR transaction, instead of
- doing memory allocation at every step. But its only guaranteed to
- be a _lower bound_ (pretty useless!) */
-
- if (length == 0 || type == NULL) /* final zero length portion */
- {
- /* Info structure will be freed in timeout */
- current_retrievals = g_list_remove_link (current_retrievals, tmp_list);
- g_list_free (tmp_list);
- gtk_selection_retrieval_report (info,
- type, format,
- (type == NULL) ? NULL : info->buffer,
- (type == NULL) ? -1 : info->offset,
- info->notify_time);
- }
- else /* append on newly arrived data */
- {
- if (!info->buffer)
- {
-#ifdef DEBUG_SELECTION
- g_message ("Start - Adding %d bytes at offset 0",
- length);
-#endif
- info->buffer = new_buffer;
- info->offset = length;
- }
- else
- {
-
-#ifdef DEBUG_SELECTION
- g_message ("Appending %d bytes at offset %d",
- length,info->offset);
-#endif
- /* We copy length+1 bytes to preserve guaranteed null termination */
- info->buffer = g_realloc (info->buffer, info->offset+length+1);
- memcpy (info->buffer + info->offset, new_buffer, length+1);
- info->offset += length;
- g_free (new_buffer);
- }
- }
-
- return TRUE;
-}
-
-/*************************************************************
- * gtk_selection_retrieval_timeout:
- * Timeout callback while receiving a selection.
- * arguments:
- * info: Information about this retrieval
- * results:
- *************************************************************/
-
-static gboolean
-gtk_selection_retrieval_timeout (GtkRetrievalInfo *info)
-{
- GList *tmp_list;
- gboolean retval;
-
- /* Determine if retrieval has finished by checking if it still in
- list of pending retrievals */
-
- tmp_list = current_retrievals;
- while (tmp_list)
- {
- if (info == (GtkRetrievalInfo *)tmp_list->data)
- break;
- tmp_list = tmp_list->next;
- }
-
- /* If retrieval is finished */
- if (!tmp_list || info->idle_time >= IDLE_ABORT_TIME)
- {
- if (tmp_list && info->idle_time >= IDLE_ABORT_TIME)
- {
- current_retrievals = g_list_remove_link (current_retrievals, tmp_list);
- g_list_free (tmp_list);
- gtk_selection_retrieval_report (info, NULL, 0, NULL, -1, GDK_CURRENT_TIME);
- }
-
- g_free (info->buffer);
- g_slice_free (GtkRetrievalInfo, info);
-
- retval = FALSE; /* remove timeout */
- }
- else
- {
- info->idle_time++;
-
- retval = TRUE; /* timeout will happen again */
- }
-
- return retval;
-}
-
-/*************************************************************
- * gtk_selection_retrieval_report:
- * Emits a “selection-received” signal.
- * arguments:
- * info: information about the retrieval that completed
- * buffer: buffer containing data (NULL => errror)
- * time: timestamp for data in buffer
- * results:
- *************************************************************/
-
-static void
-gtk_selection_retrieval_report (GtkRetrievalInfo *info,
- GdkAtom type, gint format,
- guchar *buffer, gint length,
- guint32 time)
-{
- GtkSelectionData data;
-
- data.selection = info->selection;
- data.target = info->target;
- data.type = type;
- data.format = format;
-
- data.length = length;
- data.data = buffer;
- data.display = gtk_widget_get_display (info->widget);
-
- g_signal_emit_by_name (info->widget,
- "selection-received",
- &data, time);
-}
-
/**
* gtk_selection_data_copy:
* @data: a pointer to a #GtkSelectionData-struct.
@@ -2065,22 +1424,3 @@ G_DEFINE_BOXED_TYPE (GtkSelectionData, gtk_selection_data,
gtk_selection_data_copy,
gtk_selection_data_free)
-static int
-gtk_selection_bytes_per_item (gint format)
-{
- switch (format)
- {
- case 8:
- return sizeof (char);
- break;
- case 16:
- return sizeof (short);
- break;
- case 32:
- return sizeof (long);
- break;
- default:
- g_assert_not_reached();
- }
- return 0;
-}