a11y: Port to GdkClipboard

This commit is contained in:
Benjamin Otte 2017-11-26 07:35:19 +01:00
parent 54c8a4b3b7
commit 825612b419
2 changed files with 28 additions and 22 deletions

View File

@ -1257,7 +1257,7 @@ gtk_entry_accessible_copy_text (AtkEditableText *text,
GtkWidget *widget; GtkWidget *widget;
GtkEditable *editable; GtkEditable *editable;
gchar *str; gchar *str;
GtkClipboard *clipboard; GdkClipboard *clipboard;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL) if (widget == NULL)
@ -1265,8 +1265,8 @@ gtk_entry_accessible_copy_text (AtkEditableText *text,
editable = GTK_EDITABLE (widget); editable = GTK_EDITABLE (widget);
str = gtk_editable_get_chars (editable, start_pos, end_pos); str = gtk_editable_get_chars (editable, start_pos, end_pos);
clipboard = gtk_widget_get_old_clipboard (widget, GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (widget);
gtk_clipboard_set_text (clipboard, str, -1); gdk_clipboard_set_text (clipboard, str);
g_free (str); g_free (str);
} }
@ -1278,7 +1278,7 @@ gtk_entry_accessible_cut_text (AtkEditableText *text,
GtkWidget *widget; GtkWidget *widget;
GtkEditable *editable; GtkEditable *editable;
gchar *str; gchar *str;
GtkClipboard *clipboard; GdkClipboard *clipboard;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL) if (widget == NULL)
@ -1289,8 +1289,8 @@ gtk_entry_accessible_cut_text (AtkEditableText *text,
return; return;
str = gtk_editable_get_chars (editable, start_pos, end_pos); str = gtk_editable_get_chars (editable, start_pos, end_pos);
clipboard = gtk_widget_get_old_clipboard (widget, GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (widget);
gtk_clipboard_set_text (clipboard, str, -1); gdk_clipboard_set_text (clipboard, str);
gtk_editable_delete_text (editable, start_pos, end_pos); gtk_editable_delete_text (editable, start_pos, end_pos);
} }
@ -1320,18 +1320,21 @@ typedef struct
} PasteData; } PasteData;
static void static void
paste_received_cb (GtkClipboard *clipboard, paste_received_cb (GObject *clipboard,
const gchar *text, GAsyncResult *result,
gpointer data) gpointer data)
{ {
PasteData *paste = data; PasteData *paste = data;
char *text;
text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (clipboard), result, NULL);
if (text) if (text)
gtk_editable_insert_text (GTK_EDITABLE (paste->entry), text, -1, gtk_editable_insert_text (GTK_EDITABLE (paste->entry), text, -1,
&paste->position); &paste->position);
g_object_unref (paste->entry); g_object_unref (paste->entry);
g_free (paste); g_free (paste);
g_free (text);
} }
static void static void
@ -1341,7 +1344,7 @@ gtk_entry_accessible_paste_text (AtkEditableText *text,
GtkWidget *widget; GtkWidget *widget;
GtkEditable *editable; GtkEditable *editable;
PasteData *paste; PasteData *paste;
GtkClipboard *clipboard; GdkClipboard *clipboard;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL) if (widget == NULL)
@ -1356,8 +1359,8 @@ gtk_entry_accessible_paste_text (AtkEditableText *text,
paste->position = position; paste->position = position;
g_object_ref (paste->entry); g_object_ref (paste->entry);
clipboard = gtk_widget_get_old_clipboard (widget, GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (widget);
gtk_clipboard_request_text (clipboard, paste_received_cb, paste); gdk_clipboard_read_text_async (clipboard, NULL, paste_received_cb, paste);
} }
static void static void

View File

@ -1600,7 +1600,7 @@ gtk_text_view_accessible_copy_text (AtkEditableText *text,
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
GtkTextIter start, end; GtkTextIter start, end;
gchar *str; gchar *str;
GtkClipboard *clipboard; GdkClipboard *clipboard;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL) if (widget == NULL)
@ -1612,8 +1612,8 @@ gtk_text_view_accessible_copy_text (AtkEditableText *text,
gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos); gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
clipboard = gtk_widget_get_old_clipboard (widget, GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (widget);
gtk_clipboard_set_text (clipboard, str, -1); gdk_clipboard_set_text (clipboard, str);
} }
static void static void
@ -1626,7 +1626,7 @@ gtk_text_view_accessible_cut_text (AtkEditableText *text,
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
GtkTextIter start, end; GtkTextIter start, end;
gchar *str; gchar *str;
GtkClipboard *clipboard; GdkClipboard *clipboard;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL) if (widget == NULL)
@ -1640,8 +1640,8 @@ gtk_text_view_accessible_cut_text (AtkEditableText *text,
gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos); gtk_text_buffer_get_iter_at_offset (buffer, &start, start_pos);
gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos); gtk_text_buffer_get_iter_at_offset (buffer, &end, end_pos);
str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE); str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
clipboard = gtk_widget_get_old_clipboard (widget, GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (widget);
gtk_clipboard_set_text (clipboard, str, -1); gdk_clipboard_set_text (clipboard, str);
gtk_text_buffer_delete (buffer, &start, &end); gtk_text_buffer_delete (buffer, &start, &end);
} }
@ -1677,17 +1677,20 @@ typedef struct
} PasteData; } PasteData;
static void static void
paste_received (GtkClipboard *clipboard, paste_received (GObject *clipboard,
const gchar *text, GAsyncResult *result,
gpointer data) gpointer data)
{ {
PasteData* paste = data; PasteData* paste = data;
GtkTextIter pos_itr; GtkTextIter pos_itr;
char *text;
text = gdk_clipboard_read_text_finish (GDK_CLIPBOARD (clipboard), result, NULL);
if (text) if (text)
{ {
gtk_text_buffer_get_iter_at_offset (paste->buffer, &pos_itr, paste->position); gtk_text_buffer_get_iter_at_offset (paste->buffer, &pos_itr, paste->position);
gtk_text_buffer_insert (paste->buffer, &pos_itr, text, -1); gtk_text_buffer_insert (paste->buffer, &pos_itr, text, -1);
g_free (text);
} }
g_object_unref (paste->buffer); g_object_unref (paste->buffer);
@ -1701,7 +1704,7 @@ gtk_text_view_accessible_paste_text (AtkEditableText *text,
GtkWidget *widget; GtkWidget *widget;
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
PasteData paste; PasteData paste;
GtkClipboard *clipboard; GdkClipboard *clipboard;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL) if (widget == NULL)
@ -1716,8 +1719,8 @@ gtk_text_view_accessible_paste_text (AtkEditableText *text,
paste.position = position; paste.position = position;
g_object_ref (paste.buffer); g_object_ref (paste.buffer);
clipboard = gtk_widget_get_old_clipboard (widget, GDK_SELECTION_CLIPBOARD); clipboard = gtk_widget_get_clipboard (widget);
gtk_clipboard_request_text (clipboard, paste_received, &paste); gdk_clipboard_read_text_async (clipboard, NULL, paste_received, &paste);
} }
static void static void