Kaydet (Commit) 0755a900 authored tarafından Caolán McNamara's avatar Caolán McNamara Kaydeden (comit) Andras Timar

Resolves: tdf#93198 gtk3: support PRIMARY as well as CLIPBOARD

Change-Id: Ia8c7da1e321f363efee2d60b29078b35fcbe1dcd
Reviewed-on: https://gerrit.libreoffice.org/17571Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 06e0e0e5
...@@ -97,8 +97,15 @@ class GtkTransferable : public ::cppu::WeakImplHelper1 < ...@@ -97,8 +97,15 @@ class GtkTransferable : public ::cppu::WeakImplHelper1 <
css::datatransfer::XTransferable > css::datatransfer::XTransferable >
{ {
private: private:
GdkAtom m_nSelection;
std::map<OUString, GdkAtom> m_aMimeTypeToAtom; std::map<OUString, GdkAtom> m_aMimeTypeToAtom;
public: public:
GtkTransferable(GdkAtom nSelection)
: m_nSelection(nSelection)
{
}
/* /*
* XTransferable * XTransferable
*/ */
...@@ -109,7 +116,7 @@ public: ...@@ -109,7 +116,7 @@ public:
css::uno::RuntimeException, std::exception css::uno::RuntimeException, std::exception
) SAL_OVERRIDE ) SAL_OVERRIDE
{ {
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
if (rFlavor.MimeType == "text/plain;charset=utf-16") if (rFlavor.MimeType == "text/plain;charset=utf-16")
{ {
OUString aStr; OUString aStr;
...@@ -142,7 +149,7 @@ public: ...@@ -142,7 +149,7 @@ public:
{ {
std::vector<css::datatransfer::DataFlavor> aVector; std::vector<css::datatransfer::DataFlavor> aVector;
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
GdkAtom *targets; GdkAtom *targets;
gint n_targets; gint n_targets;
...@@ -270,6 +277,7 @@ class VclGtkClipboard : ...@@ -270,6 +277,7 @@ class VclGtkClipboard :
datatransfer::clipboard::XSystemClipboard, datatransfer::clipboard::XSystemClipboard,
XServiceInfo> XServiceInfo>
{ {
GdkAtom m_nSelection;
osl::Mutex m_aMutex; osl::Mutex m_aMutex;
ClipboardOwner* m_pOwner; ClipboardOwner* m_pOwner;
gulong m_nOwnerChangedSignalId; gulong m_nOwnerChangedSignalId;
...@@ -281,7 +289,7 @@ class VclGtkClipboard : ...@@ -281,7 +289,7 @@ class VclGtkClipboard :
public: public:
VclGtkClipboard(); VclGtkClipboard(GdkAtom nSelection);
virtual ~VclGtkClipboard(); virtual ~VclGtkClipboard();
/* /*
...@@ -366,7 +374,7 @@ Reference< css::datatransfer::XTransferable > VclGtkClipboard::getContents() thr ...@@ -366,7 +374,7 @@ Reference< css::datatransfer::XTransferable > VclGtkClipboard::getContents() thr
{ {
if (!m_aContents.is()) if (!m_aContents.is())
{ {
m_aContents = new GtkTransferable(); m_aContents = new GtkTransferable(m_nSelection);
} }
return m_aContents; return m_aContents;
} }
...@@ -489,11 +497,12 @@ namespace ...@@ -489,11 +497,12 @@ namespace
} }
} }
VclGtkClipboard::VclGtkClipboard() VclGtkClipboard::VclGtkClipboard(GdkAtom nSelection)
: cppu::WeakComponentImplHelper<datatransfer::clipboard::XSystemClipboard, XServiceInfo> : cppu::WeakComponentImplHelper<datatransfer::clipboard::XSystemClipboard, XServiceInfo>
(m_aMutex) (m_aMutex)
, m_nSelection(nSelection)
{ {
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
m_nOwnerChangedSignalId = g_signal_connect(clipboard, "owner-change", m_nOwnerChangedSignalId = g_signal_connect(clipboard, "owner-change",
G_CALLBACK(handle_owner_change), this); G_CALLBACK(handle_owner_change), this);
m_pOwner = CLIPBOARD_OWNER(g_object_new(CLIPBOARD_OWNER_OBJECT, NULL)); m_pOwner = CLIPBOARD_OWNER(g_object_new(CLIPBOARD_OWNER_OBJECT, NULL));
...@@ -502,7 +511,7 @@ VclGtkClipboard::VclGtkClipboard() ...@@ -502,7 +511,7 @@ VclGtkClipboard::VclGtkClipboard()
VclGtkClipboard::~VclGtkClipboard() VclGtkClipboard::~VclGtkClipboard()
{ {
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
g_signal_handler_disconnect(clipboard, m_nOwnerChangedSignalId); g_signal_handler_disconnect(clipboard, m_nOwnerChangedSignalId);
g_object_unref(m_pOwner); g_object_unref(m_pOwner);
} }
...@@ -562,7 +571,7 @@ void VclGtkClipboard::setContents( ...@@ -562,7 +571,7 @@ void VclGtkClipboard::setContents(
//if there was a previous gtk_clipboard_set_with_data call then //if there was a previous gtk_clipboard_set_with_data call then
//ClipboardClearFunc will be called now //ClipboardClearFunc will be called now
GtkClipboard* clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); GtkClipboard* clipboard = gtk_clipboard_get(m_nSelection);
//use with_owner with m_pOwner so we can distinguish in handle_owner_change //use with_owner with m_pOwner so we can distinguish in handle_owner_change
//if we have gained or lost ownership of the clipboard //if we have gained or lost ownership of the clipboard
gtk_clipboard_set_with_owner(clipboard, aGtkTargets.data(), aGtkTargets.size(), gtk_clipboard_set_with_owner(clipboard, aGtkTargets.data(), aGtkTargets.size(),
...@@ -618,15 +627,9 @@ Reference< XInterface > GtkInstance::CreateClipboard(const Sequence< Any >& argu ...@@ -618,15 +627,9 @@ Reference< XInterface > GtkInstance::CreateClipboard(const Sequence< Any >& argu
css::uno::Reference<css::uno::XInterface>(), -1); css::uno::Reference<css::uno::XInterface>(), -1);
} }
//see window.cxx HAVE_FEATURE_X11 hack, for now just support the GdkAtom nSelection = (sel == "CLIPBOARD") ? GDK_SELECTION_CLIPBOARD : GDK_SELECTION_PRIMARY;
//system clipboard and not the primary selection
if (sel != "CLIPBOARD")
{
Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
return xContext->getServiceManager()->createInstanceWithContext("com.sun.star.datatransfer.clipboard.GenericClipboard", xContext);
}
return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new VclGtkClipboard()) ); return Reference< XInterface >( static_cast<cppu::OWeakObject *>(new VclGtkClipboard(nSelection)) );
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment