* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include <stdarg.h>
#include <string.h>
#include "gdk.h"
#include "gtkmain.h"
+#include "gtkdebug.h"
#include "gtkselection.h"
#include "gtktextbufferrichtext.h"
#include "gtkintl.h"
#include "win32/gdkwin32.h"
#endif
-#include "gtkalias.h"
-
#undef DEBUG_SELECTION
/* Maximum size of a sent chunk, in bytes. Also the default size of
MULTIPLE,
TARGETS,
TIMESTAMP,
+ SAVE_TARGETS,
LAST_ATOM
};
/**
* gtk_selection_owner_set_for_display:
- * @display: the #Gdkdisplay where the selection is set
- * @widget: new selection owner (a #GdkWidget), or %NULL.
+ * @display: the #Gdkdisplay where the selection is set
+ * @widget: (allow-none): new selection owner (a #GdkWidget), or %NULL.
* @selection: an interned atom representing the selection to claim.
* @time_: timestamp with which to claim the selection
*
g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
g_return_val_if_fail (selection != GDK_NONE, FALSE);
- g_return_val_if_fail (widget == NULL || GTK_WIDGET_REALIZED (widget), FALSE);
+ g_return_val_if_fail (widget == NULL || gtk_widget_get_realized (widget), FALSE);
g_return_val_if_fail (widget == NULL || gtk_widget_get_display (widget) == display, FALSE);
if (widget == NULL)
window = NULL;
else
- window = widget->window;
+ window = gtk_widget_get_window (widget);
tmp_list = current_selections;
while (tmp_list)
if (old_owner && old_owner != widget)
{
GdkEvent *event = gdk_event_new (GDK_SELECTION_CLEAR);
-
- event->selection.window = g_object_ref (old_owner->window);
+
+ event->selection.window = g_object_ref (gtk_widget_get_window (old_owner));
event->selection.selection = selection;
event->selection.time = time;
/**
* gtk_selection_owner_set:
- * @widget: a #GtkWidget, or %NULL.
+ * @widget: (allow-none): a #GtkWidget, or %NULL.
* @selection: an interned atom representing the selection to claim
* @time_: timestamp with which to claim the selection
*
{
GdkDisplay *display;
- g_return_val_if_fail (widget == NULL || GTK_WIDGET_REALIZED (widget), FALSE);
+ g_return_val_if_fail (widget == NULL || gtk_widget_get_realized (widget), FALSE);
g_return_val_if_fail (selection != GDK_NONE, FALSE);
if (widget)
list = gtk_selection_target_list_get (widget, selection);
gtk_target_list_add (list, target, 0, info);
#ifdef GDK_WINDOWING_WIN32
- gdk_win32_selection_add_targets (widget->window, selection, 1, &target);
+ gdk_win32_selection_add_targets (gtk_widget_get_window (widget), selection, 1, &target);
#endif
}
for (i = 0; i < ntargets; ++i)
atoms[i] = gdk_atom_intern (targets[i].target, FALSE);
- gdk_win32_selection_add_targets (widget->window, selection, ntargets, atoms);
+ gdk_win32_selection_add_targets (gtk_widget_get_window (widget), selection, ntargets, atoms);
g_free (atoms);
}
#endif
In emergency, you could use #GDK_CURRENT_TIME
*
* Requests the contents of a selection. When received,
- * a "selection_received" signal will be generated.
+ * a "selection-received" signal will be generated.
*
* Return value: %TRUE if requested succeeded. %FALSE if we could not process
* request. (e.g., there was already a request in process for
if (initialize)
gtk_selection_init ();
- if (!GTK_WIDGET_REALIZED (widget))
+ if (!gtk_widget_get_realized (widget))
gtk_widget_realize (widget);
/* Check to see if there are already any retrievals in progress for
if (owner_window != NULL)
{
GtkWidget *owner_widget;
+ gpointer owner_widget_ptr;
GtkSelectionData selection_data;
selection_data.selection = selection;
selection_data.length = -1;
selection_data.display = display;
- gdk_window_get_user_data (owner_window, (gpointer *)&owner_widget);
+ gdk_window_get_user_data (owner_window, &owner_widget_ptr);
+ owner_widget = owner_widget_ptr;
if (owner_widget != NULL)
{
/* Otherwise, we need to go through X */
current_retrievals = g_list_append (current_retrievals, info);
- gdk_selection_convert (widget->window, selection, target, time_);
+ gdk_selection_convert (gtk_widget_get_window (widget), selection, target, time_);
gdk_threads_add_timeout (1000,
(GSourceFunc) gtk_selection_retrieval_timeout, info);
}
/**
- * gtk_selection_data_set_target:
+ * gtk_selection_data_get_selection:
* @selection_data: a pointer to a #GtkSelectionData structure.
- * @target: target of the selection
*
- * Sets the target of the selection.
+ * Retrieves the selection #GdkAtom of the selection data.
+ *
+ * Returns: the selection #GdkAtom of the selection data.
*
- * Since: GSEAL-branch
+ * Since: 2.16
**/
-void
-gtk_selection_data_set_target (GtkSelectionData *selection_data,
- GdkAtom target)
+GdkAtom
+gtk_selection_data_get_selection (GtkSelectionData *selection_data)
{
- g_return_if_fail (selection_data != NULL);
+ g_return_val_if_fail (selection_data != NULL, 0);
- selection_data->target = target;
+ return selection_data->selection;
}
/**
*
* Retrieves the target of the selection.
*
- * Since: GSEAL-branch
+ * Returns: the target of the selection.
+ *
+ * Since: 2.14
**/
GdkAtom
gtk_selection_data_get_target (GtkSelectionData *selection_data)
return selection_data->target;
}
-/**
- * gtk_selection_data_set_data_type:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @data_type: data type of the selection
- *
- * Sets the data type of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_data_type (GtkSelectionData *selection_data,
- GdkAtom data_type)
-{
- g_return_if_fail (selection_data != NULL);
-
- selection_data->type = data_type;
-}
-
/**
* gtk_selection_data_get_data_type:
* @selection_data: a pointer to a #GtkSelectionData structure.
*
* Retrieves the data type of the selection.
*
- * Since: GSEAL-branch
+ * Returns: the data type of the selection.
+ *
+ * Since: 2.14
**/
GdkAtom
gtk_selection_data_get_data_type (GtkSelectionData *selection_data)
return selection_data->type;
}
-/**
- * gtk_selection_data_set_format:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @format: format of the selection
- *
- * Sets the format of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_format (GtkSelectionData *selection_data,
- gint format)
-{
- g_return_if_fail (selection_data != NULL);
-
- selection_data->format = format;
-}
-
/**
* gtk_selection_data_get_format:
* @selection_data: a pointer to a #GtkSelectionData structure.
*
* Retrieves the format of the selection.
*
- * Since: GSEAL-branch
+ * Returns: the format of the selection.
+ *
+ * Since: 2.14
**/
gint
gtk_selection_data_get_format (GtkSelectionData *selection_data)
return selection_data->format;
}
-/**
- * gtk_selection_data_set_data:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @data: data of the selection
- *
- * Sets the raw data of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_data (GtkSelectionData *selection_data,
- const guchar *data)
-{
- g_return_if_fail (selection_data != NULL);
-
- g_free (selection_data->data);
- selection_data->data = (guchar*) g_strdup (data);
-}
-
/**
* gtk_selection_data_get_data:
* @selection_data: a pointer to a #GtkSelectionData structure.
*
* Retrieves the raw data of the selection.
*
- * Since: GSEAL-branch
+ * Returns: the raw data of the selection.
+ *
+ * Since: 2.14
**/
const guchar*
gtk_selection_data_get_data (GtkSelectionData *selection_data)
return selection_data->data;
}
-/**
- * gtk_selection_data_set_target:
- * @selection_data: a pointer to a #GtkSelectionData structure.
- * @length: length of the selection
- *
- * Sets the length of the selection.
- *
- * Since: GSEAL-branch
- **/
-void
-gtk_selection_data_set_length (GtkSelectionData *selection_data,
- gint length)
-{
- g_return_if_fail (selection_data != NULL);
-
- selection_data->length = length;
-}
-
/**
* gtk_selection_data_get_length:
* @selection_data: a pointer to a #GtkSelectionData structure.
*
- * Retrieves the length of the selection.
+ * Retrieves the length of the raw data of the selection.
*
- * Since: GSEAL-branch
- **/
+ * Returns: the length of the data of the selection.
+ *
+ * Since: 2.14
+ */
gint
gtk_selection_data_get_length (GtkSelectionData *selection_data)
{
- g_return_val_if_fail (selection_data != NULL, 0);
+ g_return_val_if_fail (selection_data != NULL, -1);
return selection_data->length;
}
*
* Retrieves the display of the selection.
*
- * Since: GSEAL-branch
+ * Returns: (transfer none): the display of the selection.
+ *
+ * Since: 2.14
**/
GdkDisplay *
gtk_selection_data_get_display (GtkSelectionData *selection_data)
*
* Gets the contents of the selection data as a #GdkPixbuf.
*
- * Return value: if the selection data contained a recognized
+ * Return value: (transfer full): if the selection data contained a recognized
* image type and it could be converted to a #GdkPixbuf, a
* newly allocated pixbuf is returned, otherwise %NULL.
* If the result is non-%NULL it must be freed with g_object_unref().
/**
* gtk_selection_data_set_uris:
* @selection_data: a #GtkSelectionData
- * @uris: a %NULL-terminated array of strings hilding URIs
+ * @uris: a %NULL-terminated array of strings holding URIs
*
* Sets the contents of the selection from a list of URIs.
* The string is converted to the form determined by
* @selection_data: a #GtkSelectionData
*
* Gets the contents of the selection data as array of URIs.
- *
- * Return value: if the selection data contains a list of
+ *
+ * Return value: (array zero-terminated=1) (element-type utf8) (transfer full): if
+ * the selection data contains a list of
* URIs, a newly allocated %NULL-terminated string array
- * containing the URIs, otherwise %NULL. If the result is
+ * containing the URIs, otherwise %NULL. If the result is
* non-%NULL it must be freed with g_strfreev().
*
* Since: 2.6
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_clear:
+ * _gtk_selection_clear:
* @widget: a #GtkWidget
* @event: the event
*
- * The default handler for the GtkWidget::selection_clear_event
+ * The default handler for the #GtkWidget::selection-clear-event
* signal.
*
* Return value: %TRUE if the event was handled, otherwise false
- *
- * Since: 2.2
- *
- * Deprecated: 2.4: Instead of calling this function, chain up from
- * your selection_clear_event handler. Calling this function
- * from any other context is illegal.
**/
gboolean
-gtk_selection_clear (GtkWidget *widget,
+_gtk_selection_clear (GtkWidget *widget,
GdkEventSelection *event)
{
/* Note that we filter clear events in gdkselection-x11.c, so
event->time);
g_free (mult_atoms);
g_slice_free (GtkIncrInfo, info);
- gdk_error_trap_pop ();
+ gdk_error_trap_pop_ignored ();
return TRUE;
}
- gdk_error_trap_pop ();
+ gdk_error_trap_pop_ignored ();
/* This is annoying; the ICCCM doesn't specify the property type
* used for the property contents, so the autoconversion for
#endif
gtk_selection_invoke_handler (widget, &data, event->time);
-
if (data.length < 0)
{
info->conversions[i].property = GDK_NONE;
g_message ("PropertyDelete, property %ld", event->atom);
#endif
- selection_max_size = GTK_SELECTION_MAX_SIZE (gdk_drawable_get_display (window));
+ selection_max_size = GTK_SELECTION_MAX_SIZE (gdk_window_get_display (window));
/* Now find the appropriate ongoing INCR */
tmp_list = current_incrs;
/*************************************************************
* _gtk_selection_notify:
- * Handler for "selection_notify_event" signals on windows
+ * 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:
*************************************************************/
gboolean
-_gtk_selection_notify (GtkWidget *widget,
+_gtk_selection_notify (GtkWidget *widget,
GdkEventSelection *event)
{
GList *tmp_list;
GtkRetrievalInfo *info = NULL;
+ GdkWindow *window;
guchar *buffer = NULL;
gint length;
GdkAtom type;
gint format;
-
+
#ifdef DEBUG_SELECTION
g_message ("Initial receipt of selection %ld, target %ld (property = %ld)",
event->selection, event->target, event->property);
#endif
-
+
+ window = gtk_widget_get_window (widget);
+
tmp_list = current_retrievals;
while (tmp_list)
{
return FALSE;
if (event->property != GDK_NONE)
- length = gdk_selection_property_get (widget->window, &buffer,
+ length = gdk_selection_property_get (window, &buffer,
&type, &format);
else
length = 0; /* silence gcc */
info->notify_time = event->time;
info->idle_time = 0;
info->offset = 0; /* Mark as OK to proceed */
- gdk_window_set_events (widget->window,
- gdk_window_get_events (widget->window)
+ gdk_window_set_events (window,
+ gdk_window_get_events (window)
| GDK_PROPERTY_CHANGE_MASK);
}
else
type, format,
buffer, length, event->time);
}
-
- gdk_property_delete (widget->window, event->property);
-
+
+ gdk_property_delete (window, event->property);
+
g_free (buffer);
return TRUE;
/*************************************************************
* _gtk_selection_property_notify:
- * Handler for "property_notify_event" signals on windows
+ * Handler for "property-notify-event" signals on windows
* where a retrieval is currently in process. The selection
* owner has added more data.
* arguments:
{
GList *tmp_list;
GtkRetrievalInfo *info = NULL;
+ GdkWindow *window;
guchar *new_buffer;
int length;
GdkAtom type;
return FALSE;
info->idle_time = 0;
-
- length = gdk_selection_property_get (widget->window, &new_buffer,
+
+ window = gtk_widget_get_window (widget);
+ length = gdk_selection_property_get (window, &new_buffer,
&type, &format);
- gdk_property_delete (widget->window, event->atom);
-
+ gdk_property_delete (window, event->atom);
+
/* 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
/*************************************************************
* gtk_selection_retrieval_report:
- * Emits a "selection_received" signal.
+ * Emits a "selection-received" signal.
* arguments:
* info: information about the retrieval that completed
* buffer: buffer containing data (NULL => errror)
data.display = gtk_widget_get_display (info->widget);
g_signal_emit_by_name (info->widget,
- "selection_received",
+ "selection-received",
&data, time);
}
g_return_if_fail (widget != NULL);
target_list = gtk_selection_target_list_get (widget, data->selection);
- if (target_list &&
+ if (data->target != gtk_selection_atoms[SAVE_TARGETS] &&
+ target_list &&
gtk_target_list_find (target_list, data->target, &info))
{
g_signal_emit_by_name (widget,
- "selection_get",
+ "selection-get",
data,
info, time);
}
tmp_list = tmp_list->next;
}
}
+ else if (data->target == gtk_selection_atoms[SAVE_TARGETS])
+ {
+ gtk_selection_data_set (data,
+ gdk_atom_intern_static_string ("NULL"),
+ 32, NULL, 0);
+ }
else
{
data->length = -1;
g_slice_free (GtkSelectionData, data);
}
-GType
-gtk_selection_data_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static (I_("GtkSelectionData"),
- (GBoxedCopyFunc) gtk_selection_data_copy,
- (GBoxedFreeFunc) gtk_selection_data_free);
-
- return our_type;
-}
-
-GType
-gtk_target_list_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static (I_("GtkTargetList"),
- (GBoxedCopyFunc) gtk_target_list_ref,
- (GBoxedFreeFunc) gtk_target_list_unref);
+G_DEFINE_BOXED_TYPE (GtkSelectionData, gtk_selection_data,
+ gtk_selection_data_copy,
+ gtk_selection_data_free)
- return our_type;
-}
+G_DEFINE_BOXED_TYPE (GtkTargetList, gtk_target_list,
+ gtk_target_list_ref,
+ gtk_target_list_unref)
static int
gtk_selection_bytes_per_item (gint format)
}
return 0;
}
-
-#define __GTK_SELECTION_C__
-#include "gtkaliasdef.c"