gtk/qt: Implement XClipboard::getName in base class
Refactor a bit to let the ClipboardBase hold the ClipboardSelectionType and implement XClipboard::getName there, instead of having the logic in both, the gtk and qt specific implementations. Change-Id: I676f2406e420aacca24841805e7c59630d8f63e2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200643 Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Tested-by: Jenkins
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ClipboardSelectionType.hxx"
|
||||
|
||||
#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
|
||||
#include <com/sun/star/lang/XServiceInfo.hpp>
|
||||
#include <cppuhelper/compbase.hxx>
|
||||
@@ -21,17 +23,24 @@ class VCL_DLLPUBLIC ClipboardBase
|
||||
: public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
|
||||
css::lang::XServiceInfo>
|
||||
{
|
||||
const ClipboardSelectionType m_eSelectionType;
|
||||
|
||||
protected:
|
||||
osl::Mutex m_aMutex;
|
||||
|
||||
ClipboardBase();
|
||||
explicit ClipboardBase(ClipboardSelectionType eSelectionType);
|
||||
virtual ~ClipboardBase() override;
|
||||
|
||||
ClipboardSelectionType GetSelectionType() { return m_eSelectionType; }
|
||||
|
||||
public:
|
||||
// XServiceInfo
|
||||
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
|
||||
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
|
||||
|
||||
// XClipboard
|
||||
virtual OUString SAL_CALL getName() override;
|
||||
|
||||
// XClipboardEx
|
||||
virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
|
||||
};
|
||||
|
||||
@@ -59,7 +59,7 @@ signals:
|
||||
void clearClipboard();
|
||||
|
||||
public:
|
||||
explicit QtClipboard(const QClipboard::Mode eMode);
|
||||
explicit QtClipboard(ClipboardSelectionType eSelection);
|
||||
|
||||
static bool isSupported(const QClipboard::Mode eMode);
|
||||
|
||||
@@ -72,7 +72,6 @@ public:
|
||||
const css::uno::Reference<css::datatransfer::XTransferable>& xTrans,
|
||||
const css::uno::Reference<css::datatransfer::clipboard::XClipboardOwner>& xClipboardOwner)
|
||||
override;
|
||||
virtual OUString SAL_CALL getName() override;
|
||||
|
||||
// XFlushableClipboard
|
||||
virtual void SAL_CALL flushClipboard() override;
|
||||
|
||||
+4
-17
@@ -17,6 +17,7 @@
|
||||
#include <QtWidgets/QApplication>
|
||||
|
||||
#include <QtInstance.hxx>
|
||||
#include <QtTools.hxx>
|
||||
#include <QtTransferable.hxx>
|
||||
|
||||
#include <cassert>
|
||||
@@ -29,9 +30,9 @@
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
QtClipboard::QtClipboard(const QClipboard::Mode eMode)
|
||||
: ImplInheritanceHelper()
|
||||
, m_eClipboardMode(eMode)
|
||||
QtClipboard::QtClipboard(ClipboardSelectionType eSelectionType)
|
||||
: ImplInheritanceHelper(eSelectionType)
|
||||
, m_eClipboardMode(toQClipboardMode(eSelectionType))
|
||||
, m_bOwnClipboardChange(false)
|
||||
, m_bDoClear(false)
|
||||
{
|
||||
@@ -234,20 +235,6 @@ OUString QtClipboard::getImplementationName()
|
||||
return u"com.sun.star.datatransfer.QtClipboard"_ustr;
|
||||
}
|
||||
|
||||
OUString QtClipboard::getName()
|
||||
{
|
||||
switch (m_eClipboardMode)
|
||||
{
|
||||
case QClipboard::Clipboard:
|
||||
return u"CLIPBOARD"_ustr;
|
||||
case QClipboard::Selection:
|
||||
return u"PRIMARY"_ustr;
|
||||
default:
|
||||
assert(false && "unexpected clipboard mode");
|
||||
return OUString();
|
||||
}
|
||||
}
|
||||
|
||||
void QtClipboard::addClipboardListener(
|
||||
const css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
|
||||
{
|
||||
|
||||
@@ -660,10 +660,9 @@ QtInstance::CreateClipboard(ClipboardSelectionType eSelection)
|
||||
rtl::Reference<QtClipboard> pClipboard = EmscriptenLightweightRunInMainThread([&eSelection] {
|
||||
assert(QApplication::clipboard()->thread() == qApp->thread());
|
||||
|
||||
const QClipboard::Mode eClipboardMode = toQClipboardMode(eSelection);
|
||||
if (QtClipboard::isSupported(eClipboardMode))
|
||||
return rtl::Reference<QtClipboard>(new QtClipboard(eClipboardMode));
|
||||
SAL_WARN("vcl.qt", "Ignoring unsupported clipboard mode: '" << eClipboardMode << "'");
|
||||
if (QtClipboard::isSupported(toQClipboardMode(eSelection)))
|
||||
return rtl::Reference<QtClipboard>(new QtClipboard(eSelection));
|
||||
SAL_WARN("vcl.qt", "Ignoring unsupported selection type");
|
||||
return rtl::Reference<QtClipboard>();
|
||||
});
|
||||
if (pClipboard.is())
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
|
||||
#include <cppuhelper/supportsservice.hxx>
|
||||
|
||||
ClipboardBase::ClipboardBase()
|
||||
ClipboardBase::ClipboardBase(ClipboardSelectionType eSelectionType)
|
||||
: cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
|
||||
css::lang::XServiceInfo>(m_aMutex)
|
||||
, m_eSelectionType(eSelectionType)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -29,6 +30,20 @@ sal_Bool ClipboardBase::supportsService(const OUString& ServiceName)
|
||||
return cppu::supportsService(this, ServiceName);
|
||||
}
|
||||
|
||||
OUString ClipboardBase::getName()
|
||||
{
|
||||
switch (m_eSelectionType)
|
||||
{
|
||||
case ClipboardSelectionType::Clipboard:
|
||||
return u"CLIPBOARD"_ustr;
|
||||
case ClipboardSelectionType::Primary:
|
||||
return u"PRIMARY"_ustr;
|
||||
default:
|
||||
assert(false && "unhandled clipboard selection type");
|
||||
return OUString();
|
||||
}
|
||||
}
|
||||
|
||||
sal_Int8 ClipboardBase::getRenderingCapabilities() { return 0; }
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|
||||
|
||||
@@ -950,7 +950,6 @@ class VclGtkClipboard
|
||||
: public cppu::ImplInheritanceHelper<ClipboardBase,
|
||||
datatransfer::clipboard::XFlushableClipboard>
|
||||
{
|
||||
ClipboardSelectionType m_eSelection;
|
||||
gulong m_nOwnerChangedSignalId;
|
||||
ImplSVEvent* m_pSetClipboardEvent;
|
||||
Reference<css::datatransfer::XTransferable> m_aContents;
|
||||
@@ -989,8 +988,6 @@ public:
|
||||
const Reference< css::datatransfer::XTransferable >& xTrans,
|
||||
const Reference< css::datatransfer::clipboard::XClipboardOwner >& xClipboardOwner ) override;
|
||||
|
||||
virtual OUString SAL_CALL getName() override;
|
||||
|
||||
/*
|
||||
* XFlushableClipboard
|
||||
*/
|
||||
@@ -1027,7 +1024,7 @@ Reference< css::datatransfer::XTransferable > VclGtkClipboard::getContents()
|
||||
{
|
||||
//tdf#93887 This is the system clipboard/selection. We fetch it when we are not
|
||||
//the owner of the clipboard and have not already fetched it.
|
||||
m_aContents = new GtkClipboardTransferable(m_eSelection);
|
||||
m_aContents = new GtkClipboardTransferable(GetSelectionType());
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
if (m_pClipboardContent)
|
||||
transerable_content_set_transferable(m_pClipboardContent, m_aContents.get());
|
||||
@@ -1367,14 +1364,13 @@ void VclToGtkHelper::setSelectionData(const Reference<css::datatransfer::XTransf
|
||||
#endif
|
||||
|
||||
VclGtkClipboard::VclGtkClipboard(ClipboardSelectionType eSelection)
|
||||
: ImplInheritanceHelper()
|
||||
, m_eSelection(eSelection)
|
||||
: ImplInheritanceHelper(eSelection)
|
||||
, m_pSetClipboardEvent(nullptr)
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
, m_pClipboardContent(nullptr)
|
||||
#endif
|
||||
{
|
||||
GdkClipboard* clipboard = clipboard_get(m_eSelection);
|
||||
GdkClipboard* clipboard = clipboard_get(GetSelectionType());
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
m_nOwnerChangedSignalId = g_signal_connect(clipboard, "changed",
|
||||
G_CALLBACK(handle_owner_change), this);
|
||||
@@ -1389,17 +1385,17 @@ void VclGtkClipboard::flushClipboard()
|
||||
#if !GTK_CHECK_VERSION(4, 0, 0)
|
||||
SolarMutexGuard aGuard;
|
||||
|
||||
if (m_eSelection != ClipboardSelectionType::Clipboard)
|
||||
if (GetSelectionType() != ClipboardSelectionType::Clipboard)
|
||||
return;
|
||||
|
||||
GdkClipboard* clipboard = clipboard_get(m_eSelection);
|
||||
GdkClipboard* clipboard = clipboard_get(GetSelectionType());
|
||||
gtk_clipboard_store(clipboard);
|
||||
#endif
|
||||
}
|
||||
|
||||
VclGtkClipboard::~VclGtkClipboard()
|
||||
{
|
||||
GdkClipboard* clipboard = clipboard_get(m_eSelection);
|
||||
GdkClipboard* clipboard = clipboard_get(GetSelectionType());
|
||||
g_signal_handler_disconnect(clipboard, m_nOwnerChangedSignalId);
|
||||
if (!m_aGtkTargets.empty())
|
||||
{
|
||||
@@ -1481,7 +1477,7 @@ void VclGtkClipboard::SyncGtkClipboard()
|
||||
|
||||
void VclGtkClipboard::SetGtkClipboard()
|
||||
{
|
||||
GdkClipboard* clipboard = clipboard_get(m_eSelection);
|
||||
GdkClipboard* clipboard = clipboard_get(GetSelectionType());
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
m_pClipboardContent = TRANSFERABLE_CONTENT(transerable_content_new(&m_aConversionHelper, m_aContents.get()));
|
||||
transerable_content_set_detach_clipboard_link(m_pClipboardContent, LINK(this, VclGtkClipboard, DetachClipboard));
|
||||
@@ -1516,7 +1512,7 @@ void VclGtkClipboard::setContents(
|
||||
std::vector< Reference< datatransfer::clipboard::XClipboardListener > > aListeners( m_aListeners );
|
||||
datatransfer::clipboard::ClipboardEvent aEv;
|
||||
|
||||
GdkClipboard* clipboard = clipboard_get(m_eSelection);
|
||||
GdkClipboard* clipboard = clipboard_get(GetSelectionType());
|
||||
if (!m_aGtkTargets.empty())
|
||||
{
|
||||
#if GTK_CHECK_VERSION(4, 0, 0)
|
||||
@@ -1564,12 +1560,6 @@ void VclGtkClipboard::setContents(
|
||||
}
|
||||
}
|
||||
|
||||
OUString VclGtkClipboard::getName()
|
||||
{
|
||||
return (m_eSelection == ClipboardSelectionType::Clipboard) ? u"CLIPBOARD"_ustr
|
||||
: u"PRIMARY"_ustr;
|
||||
}
|
||||
|
||||
void VclGtkClipboard::addClipboardListener( const Reference< datatransfer::clipboard::XClipboardListener >& listener )
|
||||
{
|
||||
osl::Guard aGuard( m_aMutex );
|
||||
|
||||
Reference in New Issue
Block a user