[Libreoffice-commits] core.git: vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Sun May 23 18:37:25 UTC 2021


 vcl/unx/gtk3/gtkinst.cxx |   35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

New commits:
commit 0bcc06b0a563da08ccf1704b2f51376f27f51f62
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sun May 23 14:20:34 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Sun May 23 20:36:40 2021 +0200

    gtk4: implement basic text paste
    
    not used yet
    
    Change-Id: I7d7877e66976732356ef7541fce33fc9455fdb0b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116020
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

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<text_paste_result*>(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;
         }


More information about the Libreoffice-commits mailing list