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

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Sun May 30 14:06:16 UTC 2021


 vcl/inc/unx/gtk/gtkinst.hxx |   10 +++++-
 vcl/unx/gtk3/gtkinst.cxx    |   66 +++++++++++++++++++++++++++++++++++---------
 2 files changed, 61 insertions(+), 15 deletions(-)

New commits:
commit a7779c6dd428bb9997aaf3c43e6a4258223c751e
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sat May 29 21:21:45 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Sun May 30 16:05:40 2021 +0200

    gtk4: inch towards providing clipboard content
    
    inheriting from GdkContentProvider and implementing a replacement
    get_value like gtk_text_buffer_content looks the way to go.
    
    Change-Id: Ic376a586b77b7f00385e5744c0bc2923f2a72c94
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116397
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/inc/unx/gtk/gtkinst.hxx b/vcl/inc/unx/gtk/gtkinst.hxx
index 3202d87196ad..f389c6433b9c 100644
--- a/vcl/inc/unx/gtk/gtkinst.hxx
+++ b/vcl/inc/unx/gtk/gtkinst.hxx
@@ -57,17 +57,23 @@ class GtkSalFrame;
 gint gtk_dialog_run(GtkDialog *dialog);
 #endif
 
-#if !GTK_CHECK_VERSION(4, 0, 0)
 struct VclToGtkHelper
 {
     std::vector<css::datatransfer::DataFlavor> aInfoToFlavor;
+#if GTK_CHECK_VERSION(4, 0, 0)
+    std::vector<OString> FormatsToGtk(const css::uno::Sequence<css::datatransfer::DataFlavor> &rFormats);
+#else
     std::vector<GtkTargetEntry> FormatsToGtk(const css::uno::Sequence<css::datatransfer::DataFlavor> &rFormats);
+#endif
+#if !GTK_CHECK_VERSION(4, 0, 0)
     void setSelectionData(const css::uno::Reference<css::datatransfer::XTransferable> &rTrans,
                           GtkSelectionData *selection_data, guint info);
+#endif
 private:
+#if !GTK_CHECK_VERSION(4, 0, 0)
     GtkTargetEntry makeGtkTargetEntry(const css::datatransfer::DataFlavor& rFlavor);
-};
 #endif
+};
 
 class GtkTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
 {
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index 951468d66c20..a60f33790505 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -836,10 +836,12 @@ class VclGtkClipboard :
     Reference<css::datatransfer::XTransferable>              m_aContents;
     Reference<css::datatransfer::clipboard::XClipboardOwner> m_aOwner;
     std::vector< Reference<css::datatransfer::clipboard::XClipboardListener> > m_aListeners;
-#if !GTK_CHECK_VERSION(4, 0, 0)
+#if GTK_CHECK_VERSION(4, 0, 0)
+    std::vector<OString> m_aGtkTargets;
+#else
     std::vector<GtkTargetEntry> m_aGtkTargets;
-    VclToGtkHelper m_aConversionHelper;
 #endif
+    VclToGtkHelper m_aConversionHelper;
 
     DECL_LINK(AsyncSetGtkClipboard, void*, void);
 public:
@@ -937,7 +939,6 @@ void VclGtkClipboard::ClipboardGet(GtkSelectionData *selection_data, guint info)
 }
 #endif
 
-#if !GTK_CHECK_VERSION(4, 0, 0)
 namespace
 {
     const OString& getPID()
@@ -956,6 +957,7 @@ namespace
     }
 }
 
+#if !GTK_CHECK_VERSION(4, 0, 0)
 namespace
 {
     void ClipboardGetFunc(GdkClipboard* /*clipboard*/, GtkSelectionData *selection_data,
@@ -1047,8 +1049,8 @@ void VclGtkClipboard::ClipboardClear()
 #if !GTK_CHECK_VERSION(4, 0, 0)
     for (auto &a : m_aGtkTargets)
         g_free(a.target);
-    m_aGtkTargets.clear();
 #endif
+    m_aGtkTargets.clear();
 }
 
 #if !GTK_CHECK_VERSION(4, 0, 0)
@@ -1163,21 +1165,30 @@ VclGtkClipboard::~VclGtkClipboard()
 {
     GdkClipboard* clipboard = clipboard_get(m_eSelection);
     g_signal_handler_disconnect(clipboard, m_nOwnerChangedSignalId);
-#if !GTK_CHECK_VERSION(4, 0, 0)
     if (!m_aGtkTargets.empty())
     {
+#if GTK_CHECK_VERSION(4, 0, 0)
+        gdk_clipboard_set_content(clipboard, nullptr);
+#else
         gtk_clipboard_clear(clipboard);
+#endif
         ClipboardClear();
     }
     assert(!m_pSetClipboardEvent);
     assert(m_aGtkTargets.empty());
-#endif
 }
 
-#if !GTK_CHECK_VERSION(4, 0, 0)
+#if GTK_CHECK_VERSION(4, 0, 0)
+std::vector<OString> VclToGtkHelper::FormatsToGtk(const css::uno::Sequence<css::datatransfer::DataFlavor> &rFormats)
+#else
 std::vector<GtkTargetEntry> VclToGtkHelper::FormatsToGtk(const css::uno::Sequence<css::datatransfer::DataFlavor> &rFormats)
+#endif
 {
+#if GTK_CHECK_VERSION(4, 0, 0)
+    std::vector<OString> aGtkTargets;
+#else
     std::vector<GtkTargetEntry> aGtkTargets;
+#endif
 
     bool bHaveText(false), bHaveUTF8(false);
     for (const css::datatransfer::DataFlavor& rFlavor : rFormats)
@@ -1192,28 +1203,42 @@ std::vector<GtkTargetEntry> VclToGtkHelper::FormatsToGtk(const css::uno::Sequenc
                 bHaveUTF8 = true;
             }
         }
+#if GTK_CHECK_VERSION(4, 0, 0)
+        aGtkTargets.push_back(OUStringToOString(rFlavor.MimeType, RTL_TEXTENCODING_UTF8));
+#else
         GtkTargetEntry aEntry(makeGtkTargetEntry(rFlavor));
         aGtkTargets.push_back(aEntry);
+#endif
     }
 
     if (bHaveText)
     {
+#if !GTK_CHECK_VERSION(4, 0, 0)
         css::datatransfer::DataFlavor aFlavor;
         aFlavor.DataType = cppu::UnoType<Sequence< sal_Int8 >>::get();
+#endif
         if (!bHaveUTF8)
         {
+#if GTK_CHECK_VERSION(4, 0, 0)
+            aGtkTargets.push_back("text/plain;charset=utf-8");
+#else
             aFlavor.MimeType = "text/plain;charset=utf-8";
             aGtkTargets.push_back(makeGtkTargetEntry(aFlavor));
+#endif
         }
+#if GTK_CHECK_VERSION(4, 0, 0)
+        aGtkTargets.push_back("UTF8_STRING");
+        aGtkTargets.push_back("STRING");
+#else
         aFlavor.MimeType = "UTF8_STRING";
         aGtkTargets.push_back(makeGtkTargetEntry(aFlavor));
         aFlavor.MimeType = "STRING";
         aGtkTargets.push_back(makeGtkTargetEntry(aFlavor));
+#endif
     }
 
     return aGtkTargets;
 }
-#endif
 
 IMPL_LINK_NOARG(VclGtkClipboard, AsyncSetGtkClipboard, void*, void)
 {
@@ -1235,8 +1260,14 @@ void VclGtkClipboard::SyncGtkClipboard()
 
 void VclGtkClipboard::SetGtkClipboard()
 {
-#if !GTK_CHECK_VERSION(4, 0, 0)
     GdkClipboard* clipboard = clipboard_get(m_eSelection);
+#if GTK_CHECK_VERSION(4, 0, 0)
+    GdkContentFormatsBuilder* pBuilder = gdk_content_formats_builder_new();
+    for (const auto& rFormat : m_aGtkTargets)
+        gdk_content_formats_builder_add_mime_type(pBuilder, rFormat.getStr());
+    GdkContentFormats* pFormats = gdk_content_formats_builder_free_to_formats(pBuilder);
+    //TODO pFormats needs a place to call home
+#else
     gtk_clipboard_set_with_data(clipboard, m_aGtkTargets.data(), m_aGtkTargets.size(),
                                 ClipboardGetFunc, ClipboardClearFunc, this);
     gtk_clipboard_set_can_store(clipboard, m_aGtkTargets.data(), m_aGtkTargets.size());
@@ -1262,33 +1293,42 @@ void VclGtkClipboard::setContents(
     std::vector< Reference< datatransfer::clipboard::XClipboardListener > > aListeners( m_aListeners );
     datatransfer::clipboard::ClipboardEvent aEv;
 
-#if !GTK_CHECK_VERSION(4, 0, 0)
     GdkClipboard* clipboard = clipboard_get(m_eSelection);
     if (!m_aGtkTargets.empty())
     {
+#if GTK_CHECK_VERSION(4, 0, 0)
+        gdk_clipboard_set_content(clipboard, nullptr);
+#else
         gtk_clipboard_clear(clipboard);
+#endif
         ClipboardClear();
     }
     assert(m_aGtkTargets.empty());
     if (m_aContents.is())
     {
+#if GTK_CHECK_VERSION(4, 0, 0)
+        std::vector<OString> aGtkTargets(m_aConversionHelper.FormatsToGtk(aFormats));
+#else
         std::vector<GtkTargetEntry> aGtkTargets(m_aConversionHelper.FormatsToGtk(aFormats));
+#endif
         if (!aGtkTargets.empty())
         {
-            GtkTargetEntry aEntry;
             OString sTunnel = "application/x-libreoffice-internal-id-" + getPID();
+#if GTK_CHECK_VERSION(4, 0, 0)
+            aGtkTargets.push_back(sTunnel);
+#else
+            GtkTargetEntry aEntry;
             aEntry.target = g_strdup(sTunnel.getStr());
             aEntry.flags = 0;
             aEntry.info = 0;
             aGtkTargets.push_back(aEntry);
-
+#endif
             m_aGtkTargets = aGtkTargets;
 
             if (!m_pSetClipboardEvent)
                 m_pSetClipboardEvent = Application::PostUserEvent(LINK(this, VclGtkClipboard, AsyncSetGtkClipboard));
         }
     }
-#endif
 
     aEv.Contents = getContents();
 


More information about the Libreoffice-commits mailing list