diff --git a/ChangeLog b/ChangeLog index 4b5a6c8c5..4f1b0b029 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Dec 24 01:12:53 2003 Matthias Clasen + + * gtk/gtkclipboard.[hc]: Add GtkClipboardTargetReceivedFunc, + gtk_clipboard_request_targets() and + gtk_clipboard_wait_for_targets(). (#101774, Dom Lachowicz) + Mon Dec 22 00:40:39 2003 Matthias Clasen * gtk/gtkcalendar.c (gtk_calendar_paint_arrow): Use diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 4b5a6c8c5..4f1b0b029 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,9 @@ +Wed Dec 24 01:12:53 2003 Matthias Clasen + + * gtk/gtkclipboard.[hc]: Add GtkClipboardTargetReceivedFunc, + gtk_clipboard_request_targets() and + gtk_clipboard_wait_for_targets(). (#101774, Dom Lachowicz) + Mon Dec 22 00:40:39 2003 Matthias Clasen * gtk/gtkcalendar.c (gtk_calendar_paint_arrow): Use diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 4b5a6c8c5..4f1b0b029 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,9 @@ +Wed Dec 24 01:12:53 2003 Matthias Clasen + + * gtk/gtkclipboard.[hc]: Add GtkClipboardTargetReceivedFunc, + gtk_clipboard_request_targets() and + gtk_clipboard_wait_for_targets(). (#101774, Dom Lachowicz) + Mon Dec 22 00:40:39 2003 Matthias Clasen * gtk/gtkcalendar.c (gtk_calendar_paint_arrow): Use diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 4b5a6c8c5..4f1b0b029 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,9 @@ +Wed Dec 24 01:12:53 2003 Matthias Clasen + + * gtk/gtkclipboard.[hc]: Add GtkClipboardTargetReceivedFunc, + gtk_clipboard_request_targets() and + gtk_clipboard_wait_for_targets(). (#101774, Dom Lachowicz) + Mon Dec 22 00:40:39 2003 Matthias Clasen * gtk/gtkcalendar.c (gtk_calendar_paint_arrow): Use diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 4b5a6c8c5..4f1b0b029 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,9 @@ +Wed Dec 24 01:12:53 2003 Matthias Clasen + + * gtk/gtkclipboard.[hc]: Add GtkClipboardTargetReceivedFunc, + gtk_clipboard_request_targets() and + gtk_clipboard_wait_for_targets(). (#101774, Dom Lachowicz) + Mon Dec 22 00:40:39 2003 Matthias Clasen * gtk/gtkcalendar.c (gtk_calendar_paint_arrow): Use diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index a39ee8eae..3c319711f 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,12 @@ +Wed Dec 24 01:12:12 2003 Matthias Clasen + + * gtk/gtk-sections.txt: Add GtkClipboardTargetReceivedFunc, + gtk_clipboard_request_targets, gtk_clipboard_wait_for_targets. + +Wed Dec 24 01:11:36 2003 Matthias Clasen + + * gtk/tmpl/gtkclipboard.sgml: Document GtkClipboardTargetReceivedFunc. + Sun Dec 21 01:58:33 2003 Matthias Clasen * gtk/gtk-sections.txt: Add gtk_menu_shell_cancel. diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 98673762d..66d918f05 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -4743,6 +4743,7 @@ gtk_selection_data_get_type GtkClipboard GtkClipboardReceivedFunc GtkClipboardTextReceivedFunc +GtkClipboardTargetsReceivedFunc GtkClipboardGetFunc GtkClipboardClearFunc gtk_clipboard_get @@ -4755,9 +4756,11 @@ gtk_clipboard_clear gtk_clipboard_set_text gtk_clipboard_request_contents gtk_clipboard_request_text +gtk_clipboard_request_targets gtk_clipboard_wait_for_contents gtk_clipboard_wait_for_text gtk_clipboard_wait_is_text_available +gtk_clipboard_wait_for_targets GTK_CLIPBOARD GTK_TYPE_CLIPBOARD diff --git a/docs/reference/gtk/tmpl/gtkclipboard.sgml b/docs/reference/gtk/tmpl/gtkclipboard.sgml index 93fffa8be..a04634dc8 100644 --- a/docs/reference/gtk/tmpl/gtkclipboard.sgml +++ b/docs/reference/gtk/tmpl/gtkclipboard.sgml @@ -115,6 +115,20 @@ Storing data on clipboards @data: the @user_data supplied to gtk_clipboard_request_text(). + + + A function to be called when the results of gtk_clipboard_request_targets() + are received, or when the request fails. + + +@clipboard: the #GtkClipboard +@atoms: the supported targets, as array of #GdkAtom, or %NULL + if retrieving the data failed. +@n_atoms: the length of the @atoms array. +@data: the @user_data supplied to gtk_clipboard_request_targets(). +@Since: 2.4 + + A function that will be called to provide the contents of the selection. @@ -253,6 +267,16 @@ will not be used again. @user_data: + + + + + +@clipboard: +@callback: +@user_data: + + @@ -269,12 +293,7 @@ will not be used again. @clipboard: -@Returns: +@Returns: @@ -286,3 +305,20 @@ End: @Returns: + + + + + +@clipboard: +@targets: +@n_targets: +@Returns: + + + diff --git a/gtk/gtkclipboard.c b/gtk/gtkclipboard.c index 1b5d37c80..921b831a9 100644 --- a/gtk/gtkclipboard.c +++ b/gtk/gtkclipboard.c @@ -37,6 +37,7 @@ typedef struct _GtkClipboardClass GtkClipboardClass; typedef struct _RequestContentsInfo RequestContentsInfo; typedef struct _RequestTextInfo RequestTextInfo; +typedef struct _RequestTargetsInfo RequestTargetsInfo; struct _GtkClipboard { @@ -72,6 +73,12 @@ struct _RequestTextInfo gpointer user_data; }; +struct _RequestTargetsInfo +{ + GtkClipboardTargetsReceivedFunc callback; + gpointer user_data; +}; + static void gtk_clipboard_class_init (GtkClipboardClass *class); static void gtk_clipboard_finalize (GObject *object); @@ -833,6 +840,57 @@ gtk_clipboard_request_text (GtkClipboard *clipboard, info); } +static void +request_targets_received_func (GtkClipboard *clipboard, + GtkSelectionData *selection_data, + gpointer data) +{ + RequestTargetsInfo *info = data; + GdkAtom *targets = NULL; + gint n_targets = 0; + + gtk_selection_data_get_targets (selection_data, &targets, &n_targets); + + info->callback (clipboard, targets, n_targets, info->user_data); + + g_free (info); + g_free (targets); +} + +/** + * gtk_clipboard_request_targets: + * @clipboard: a #GtkClipboard + * @callback: a function to call when the targets are received, + * or the retrieval fails. (It will always be called + * one way or the other.) + * @user_data: user data to pass to @callback. + * + * Requests the contents of the clipboard as list of supported targets. + * When the list is later received, @callback will be called. + * + * The @targets parameter to @callback will contain the resulting targets if + * the request succeeded, or %NULL if it failed. + * + * Since: 2.4 + **/ +void +gtk_clipboard_request_targets (GtkClipboard *clipboard, + GtkClipboardTargetsReceivedFunc callback, + gpointer user_data) +{ + RequestTargetsInfo *info; + + g_return_if_fail (clipboard != NULL); + g_return_if_fail (callback != NULL); + + info = g_new (RequestTargetsInfo, 1); + info->callback = callback; + info->user_data = user_data; + + gtk_clipboard_request_contents (clipboard, gdk_atom_intern ("TARGETS", FALSE), + request_targets_received_func, + info); +} typedef struct { @@ -1000,3 +1058,49 @@ gtk_clipboard_wait_is_text_available (GtkClipboard *clipboard) return result; } + +/** + * gtk_clipboard_wait_for_targets + * @clipboard: a #GtkClipboard + * @targets: location to store an array of targets. The result + * stored here must be freed with g_free(). + * @n_targets: location to store number of items in @targets. + * + * Returns a list of targets that are present on the clipboard, or %NULL + * if there aren't any targets available. The returned list must be + * freed with g_free(). + * This function waits for the data to be received using the main + * loop, so events, timeouts, etc, may be dispatched during the wait. + * + * Return value: %TRUE if any targets are present on the clipboard, + * otherwise %FALSE. + * + * Since: 2.4 + */ +gboolean +gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, + GdkAtom **targets, + gint *n_targets) +{ + GtkSelectionData *data; + gboolean result = FALSE; + + g_return_val_if_fail (clipboard != NULL, FALSE); + + /* TODO: see http://bugzilla.gnome.org/show_bug.cgi?id=101774 with regard to XFIXES */ + + if (n_targets) + *n_targets = 0; + + targets = NULL; + + data = gtk_clipboard_wait_for_contents (clipboard, gdk_atom_intern ("TARGETS", FALSE)); + + if (data) + { + result = gtk_selection_data_get_targets (data, targets, n_targets); + gtk_selection_data_free (data); + } + + return result; +} diff --git a/gtk/gtkclipboard.h b/gtk/gtkclipboard.h index b18421bca..3d2268393 100644 --- a/gtk/gtkclipboard.h +++ b/gtk/gtkclipboard.h @@ -38,6 +38,10 @@ typedef void (* GtkClipboardReceivedFunc) (GtkClipboard *clipboard, typedef void (* GtkClipboardTextReceivedFunc) (GtkClipboard *clipboard, const gchar *text, gpointer data); +typedef void (* GtkClipboardTargetsReceivedFunc) (GtkClipboard *clipboard, + GdkAtom *atoms, + gint n_atoms, + gpointer data); /* Should these functions have GtkClipboard *clipboard as the first argument? * right now for ClearFunc, you may have trouble determining _which_ clipboard @@ -86,6 +90,9 @@ void gtk_clipboard_request_contents (GtkClipboard *clipboard, void gtk_clipboard_request_text (GtkClipboard *clipboard, GtkClipboardTextReceivedFunc callback, gpointer user_data); +void gtk_clipboard_request_targets (GtkClipboard *clipboard, + GtkClipboardTargetsReceivedFunc callback, + gpointer user_data); GtkSelectionData *gtk_clipboard_wait_for_contents (GtkClipboard *clipboard, GdkAtom target); @@ -93,6 +100,10 @@ gchar * gtk_clipboard_wait_for_text (GtkClipboard *clipboard); gboolean gtk_clipboard_wait_is_text_available (GtkClipboard *clipboard); +gboolean gtk_clipboard_wait_for_targets (GtkClipboard *clipboard, + GdkAtom **targets, + gint *n_targets); + #ifdef __cplusplus } #endif /* __cplusplus */