From 0bcc06b0a563da08ccf1704b2f51376f27f51f62 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Sun, 23 May 2021 14:20:34 +0100 Subject: gtk4: implement basic text paste MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit not used yet Change-Id: I7d7877e66976732356ef7541fce33fc9455fdb0b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116020 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- vcl/unx/gtk3/gtkinst.cxx | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) (limited to 'vcl') diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index ea3c0062249d..a5e97e95856d 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -654,6 +654,29 @@ GdkClipboard* clipboard_get(SelectionType eSelection) #endif } +#if GTK_CHECK_VERSION(4, 0, 0) + +struct text_paste_result +{ + OUString sText; + bool bDone = false; +}; + +void text_async_completed(GObject* source, GAsyncResult* res, gpointer data) +{ + GdkClipboard* clipboard = GDK_CLIPBOARD(source); + text_paste_result* pRes = static_cast(data); + + gchar* pText = gdk_clipboard_read_text_finish(clipboard, res, nullptr); + pRes->sText = OUString(pText, pText ? strlen(pText) : 0, RTL_TEXTENCODING_UTF8); + g_free(pText); + + pRes->bDone = true; + + g_main_context_wakeup(nullptr); +} +#endif + class GtkClipboardTransferable : public GtkTransferable { private: @@ -677,15 +700,17 @@ public: if (rFlavor.MimeType == "text/plain;charset=utf-16") { #if !GTK_CHECK_VERSION(4, 0, 0) - OUString aStr; gchar *pText = gtk_clipboard_wait_for_text(clipboard); - if (pText) - aStr = OUString(pText, strlen(pText), RTL_TEXTENCODING_UTF8); + OUString aStr(pText, pText ? strlen(pText) : 0, RTL_TEXTENCODING_UTF8); g_free(pText); aRet <<= aStr.replaceAll("\r\n", "\n"); #else - (void)clipboard; - //TODO gdk_clipboard_read_text_async + SalInstance* pInstance = GetSalData()->m_pInstance; + text_paste_result aRes; + gdk_clipboard_read_text_async(clipboard, nullptr, text_async_completed, &aRes); + while (!aRes.bDone) + pInstance->DoYield(true, false); + aRet <<= aRes.sText.replaceAll("\r\n", "\n"); #endif return aRet; } -- cgit