vcl/Library_vcl.mk               |    1 +
 vcl/inc/ClipboardBase.hxx        |   39 +++++++++++++++++++++++++++++++++++++++
 vcl/inc/qt5/QtClipboard.hxx      |   14 ++++----------
 vcl/qt5/QtClipboard.cxx          |   16 +---------------
 vcl/source/app/ClipboardBase.cxx |   34 ++++++++++++++++++++++++++++++++++
 vcl/unx/gtk3/gtkinst.cxx         |   39 +++++----------------------------------
 6 files changed, 84 insertions(+), 59 deletions(-)

New commits:
commit 07db26d566c546072d547b1735fc26cc3bf3e932
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Feb 27 15:43:24 2026 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Feb 28 09:23:15 2026 +0100

    gtk/qt: Extract ClipboardBase base class
    
    Introduce new abstract base class
    ClipboardBase to deduplicate (at least)
    the existing VclGtkClipboard and QtClipboard
    implementations
    
    Initially, move some trivial logic there.
    More will follow in upcoming commits.
    
    Change-Id: Iea174866194bc0566d6fa91a4c2780835439d776
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200642
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index d1cfab76dea7..eef03c29b47a 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -456,6 +456,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/app/customweld \
     vcl/source/app/dbggui \
     vcl/source/app/dndhelp \
+    vcl/source/app/ClipboardBase \
     vcl/source/app/DropTarget \
     vcl/source/app/help \
     vcl/source/app/i18nhelp \
diff --git a/vcl/inc/ClipboardBase.hxx b/vcl/inc/ClipboardBase.hxx
new file mode 100644
index 000000000000..6bfd66cacaca
--- /dev/null
+++ b/vcl/inc/ClipboardBase.hxx
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#pragma once
+
+#include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <cppuhelper/compbase.hxx>
+#include <osl/mutex.hxx>
+#include <vcl/dllapi.h>
+
+#pragma once
+
+class VCL_DLLPUBLIC ClipboardBase
+    : public 
cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
+                                           css::lang::XServiceInfo>
+{
+protected:
+    osl::Mutex m_aMutex;
+
+    ClipboardBase();
+    virtual ~ClipboardBase() override;
+
+public:
+    // XServiceInfo
+    virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) 
override;
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() 
override;
+
+    // XClipboardEx
+    virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/inc/qt5/QtClipboard.hxx b/vcl/inc/qt5/QtClipboard.hxx
index e1185aff3eb1..c4331e0bf1b9 100644
--- a/vcl/inc/qt5/QtClipboard.hxx
+++ b/vcl/inc/qt5/QtClipboard.hxx
@@ -10,7 +10,8 @@
 
 #pragma once
 
-#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <ClipboardBase.hxx>
+
 #include <com/sun/star/datatransfer/XTransferable.hpp>
 #include <com/sun/star/datatransfer/clipboard/XSystemClipboard.hpp>
 #include <com/sun/star/datatransfer/clipboard/XFlushableClipboard.hpp>
@@ -30,13 +31,11 @@
  **/
 class QtClipboard final
     : public QObject,
-      public 
cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
-                                           
css::datatransfer::clipboard::XFlushableClipboard,
-                                           css::lang::XServiceInfo>
+      public cppu::ImplInheritanceHelper<ClipboardBase,
+                                         
css::datatransfer::clipboard::XFlushableClipboard>
 {
     Q_OBJECT
 
-    osl::Mutex m_aMutex;
     const QClipboard::Mode m_eClipboardMode;
     // has to be set, if LO changes the QClipboard itself, so it won't 
instantly lose
     // ownership by it's self-triggered QClipboard::changed handler
@@ -66,8 +65,6 @@ public:
 
     // XServiceInfo
     virtual OUString SAL_CALL getImplementationName() override;
-    virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) 
override;
-    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() 
override;
 
     // XClipboard
     virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL 
getContents() override;
@@ -77,9 +74,6 @@ public:
         override;
     virtual OUString SAL_CALL getName() override;
 
-    // XClipboardEx
-    virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
-
     // XFlushableClipboard
     virtual void SAL_CALL flushClipboard() override;
 
diff --git a/vcl/qt5/QtClipboard.cxx b/vcl/qt5/QtClipboard.cxx
index defd2ab5d391..85aecf496129 100644
--- a/vcl/qt5/QtClipboard.cxx
+++ b/vcl/qt5/QtClipboard.cxx
@@ -30,9 +30,7 @@
 #endif
 
 QtClipboard::QtClipboard(const QClipboard::Mode eMode)
-    : 
cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
-                                    
css::datatransfer::clipboard::XFlushableClipboard,
-                                    XServiceInfo>(m_aMutex)
+    : ImplInheritanceHelper()
     , m_eClipboardMode(eMode)
     , m_bOwnClipboardChange(false)
     , m_bDoClear(false)
@@ -236,16 +234,6 @@ OUString QtClipboard::getImplementationName()
     return u"com.sun.star.datatransfer.QtClipboard"_ustr;
 }
 
-css::uno::Sequence<OUString> QtClipboard::getSupportedServiceNames()
-{
-    return { u"com.sun.star.datatransfer.clipboard.SystemClipboard"_ustr };
-}
-
-sal_Bool QtClipboard::supportsService(const OUString& ServiceName)
-{
-    return cppu::supportsService(this, ServiceName);
-}
-
 OUString QtClipboard::getName()
 {
     switch (m_eClipboardMode)
@@ -260,8 +248,6 @@ OUString QtClipboard::getName()
     }
 }
 
-sal_Int8 QtClipboard::getRenderingCapabilities() { return 0; }
-
 void QtClipboard::addClipboardListener(
     const 
css::uno::Reference<css::datatransfer::clipboard::XClipboardListener>& listener)
 {
diff --git a/vcl/source/app/ClipboardBase.cxx b/vcl/source/app/ClipboardBase.cxx
new file mode 100644
index 000000000000..636d88962e72
--- /dev/null
+++ b/vcl/source/app/ClipboardBase.cxx
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <ClipboardBase.hxx>
+
+#include <cppuhelper/supportsservice.hxx>
+
+ClipboardBase::ClipboardBase()
+    : 
cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard,
+                                    css::lang::XServiceInfo>(m_aMutex)
+{
+}
+
+ClipboardBase::~ClipboardBase() {}
+
+css::uno::Sequence<OUString> ClipboardBase::getSupportedServiceNames()
+{
+    return { u"com.sun.star.datatransfer.clipboard.SystemClipboard"_ustr };
+}
+
+sal_Bool ClipboardBase::supportsService(const OUString& ServiceName)
+{
+    return cppu::supportsService(this, ServiceName);
+}
+
+sal_Int8 ClipboardBase::getRenderingCapabilities() { return 0; }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index f0033194248f..6a0f894bd454 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -15,6 +15,7 @@
 #include <string.h>
 #include <string_view>
 
+#include <ClipboardBase.hxx>
 #include <dndhelper.hxx>
 #include <tools/date.hxx>
 #include <o3tl/test_info.hxx>
@@ -945,14 +946,11 @@ public:
     }
 };
 
-class VclGtkClipboard :
-        public cppu::WeakComponentImplHelper<
-        datatransfer::clipboard::XSystemClipboard,
-        datatransfer::clipboard::XFlushableClipboard,
-        XServiceInfo>
+class VclGtkClipboard
+    : public cppu::ImplInheritanceHelper<ClipboardBase,
+                                         
datatransfer::clipboard::XFlushableClipboard>
 {
     ClipboardSelectionType m_eSelection;
-    osl::Mutex                                               m_aMutex;
     gulong                                                   
m_nOwnerChangedSignalId;
     ImplSVEvent*                                             
m_pSetClipboardEvent;
     Reference<css::datatransfer::XTransferable>              m_aContents;
@@ -979,10 +977,7 @@ public:
     /*
      * XServiceInfo
      */
-
     virtual OUString SAL_CALL getImplementationName() override;
-    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) 
override;
-    virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
 
     /*
      * XClipboard
@@ -996,12 +991,6 @@ public:
 
     virtual OUString SAL_CALL getName() override;
 
-    /*
-     * XClipboardEx
-     */
-
-    virtual sal_Int8 SAL_CALL getRenderingCapabilities() override;
-
     /*
      * XFlushableClipboard
      */
@@ -1032,17 +1021,6 @@ OUString VclGtkClipboard::getImplementationName()
     return u"com.sun.star.datatransfer.VclGtkClipboard"_ustr;
 }
 
-Sequence< OUString > VclGtkClipboard::getSupportedServiceNames()
-{
-    Sequence<OUString> aRet { 
u"com.sun.star.datatransfer.clipboard.SystemClipboard"_ustr };
-    return aRet;
-}
-
-sal_Bool VclGtkClipboard::supportsService( const OUString& ServiceName )
-{
-    return cppu::supportsService(this, ServiceName);
-}
-
 Reference< css::datatransfer::XTransferable > VclGtkClipboard::getContents()
 {
     if (!m_aContents.is())
@@ -1389,9 +1367,7 @@ void VclToGtkHelper::setSelectionData(const 
Reference<css::datatransfer::XTransf
 #endif
 
 VclGtkClipboard::VclGtkClipboard(ClipboardSelectionType eSelection)
-    : cppu::WeakComponentImplHelper<datatransfer::clipboard::XSystemClipboard,
-                                    
datatransfer::clipboard::XFlushableClipboard, XServiceInfo>
-        (m_aMutex)
+    : ImplInheritanceHelper()
     , m_eSelection(eSelection)
     , m_pSetClipboardEvent(nullptr)
 #if GTK_CHECK_VERSION(4, 0, 0)
@@ -1594,11 +1570,6 @@ OUString VclGtkClipboard::getName()
                                                                : 
u"PRIMARY"_ustr;
 }
 
-sal_Int8 VclGtkClipboard::getRenderingCapabilities()
-{
-    return 0;
-}
-
 void VclGtkClipboard::addClipboardListener( const Reference< 
datatransfer::clipboard::XClipboardListener >& listener )
 {
     osl::Guard aGuard( m_aMutex );

Reply via email to