dtrans/Library_ftransl.mk                    |    1 
 dtrans/source/win32/ftransl/ftransl.cxx      |   29 +++++----
 dtrans/source/win32/ftransl/ftranslentry.cxx |   79 ---------------------------
 dtrans/util/ftransl.component                |    5 +
 4 files changed, 18 insertions(+), 96 deletions(-)

New commits:
commit 838a106c1c1debf95345cf15f246d0e0bf0eda0e
Author:     Noel Grandin <[email protected]>
AuthorDate: Tue Jul 21 14:57:09 2020 +0200
Commit:     Balazs Varga <[email protected]>
CommitDate: Thu Nov 24 12:24:23 2022 +0100

    dtrans/ftransl: create instances with uno constructors
    
    See tdf#74608 for motivation.
    
    Change-Id: I7068fd727d57258a21001d24d2f6b14fa51f9870
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99159
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143153
    Tested-by: Balazs Varga <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>

diff --git a/dtrans/Library_ftransl.mk b/dtrans/Library_ftransl.mk
index 5a16ee83c419..f418af318d3f 100644
--- a/dtrans/Library_ftransl.mk
+++ b/dtrans/Library_ftransl.mk
@@ -42,7 +42,6 @@ $(eval $(call gb_Library_use_static_libraries,ftransl,\
 
 $(eval $(call gb_Library_add_exception_objects,ftransl,\
        dtrans/source/win32/ftransl/ftransl \
-       dtrans/source/win32/ftransl/ftranslentry \
 ))
 
 $(eval $(call gb_Library_set_include,ftransl,\
diff --git a/dtrans/source/win32/ftransl/ftransl.cxx 
b/dtrans/source/win32/ftransl/ftransl.cxx
index 4cc1897059a3..f2c5d6487e48 100644
--- a/dtrans/source/win32/ftransl/ftransl.cxx
+++ b/dtrans/source/win32/ftransl/ftransl.cxx
@@ -26,16 +26,13 @@
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <cppuhelper/supportsservice.hxx>
+#include <rtl/ref.hxx>
 #include "../misc/ImplHelper.hxx"
 
 #include <shlobj.h>
 
-#define IMPL_NAME  "com.sun.star.datatransfer.DataFormatTranslator"
-
 #define CPPUTYPE_SEQSALINT8       cppu::UnoType<Sequence< sal_Int8 >>::get()
 #define CPPUTYPE_DEFAULT          CPPUTYPE_SEQSALINT8
-#define CPPUTYPE_OUSTR            cppu::UnoType<OUString>::get()
-#define CPPUTYPE_SALINT32         cppu::UnoType<sal_Int32>::get()
 
 const OUString Windows_FormatName ("windows_formatname");
 const css::uno::Type CppuType_ByteSequence = 
cppu::UnoType<css::uno::Sequence<sal_Int8>>::get();
@@ -51,12 +48,6 @@ using namespace com::sun::star::container;
 
 namespace
 {
-    Sequence< OUString > DataFormatTranslator_getSupportedServiceNames( )
-    {
-        Sequence< OUString > aRet { 
"com.sun.star.datatransfer.DataFormatTranslator" };
-        return aRet;
-    }
-}
 
 struct FormatEntry
 {
@@ -73,6 +64,8 @@ struct FormatEntry
     sal_Int32                     aStandardFormatId;
 };
 
+}
+
 FormatEntry::FormatEntry(
     const char *mime_content_type,
     const char *human_presentable_name,
@@ -506,14 +499,14 @@ DataFlavor SAL_CALL 
CDataFormatTranslatorUNO::getDataFlavorFromSystemDataType( c
 
     DataFlavor aFlavor = mkDataFlv( OUString(), OUString(), 
CPPUTYPE_SEQSALINT8 );
 
-    if ( aSysDataType.getValueType( ) == CPPUTYPE_SALINT32 )
+    if ( aSysDataType.getValueType( ) == cppu::UnoType<sal_Int32>::get() )
     {
         sal_Int32 clipformat = CF_INVALID;
         aSysDataType >>= clipformat;
         if ( CF_INVALID != clipformat )
             findDataFlavorForStandardFormatId( clipformat, aFlavor );
     }
-    else if ( aSysDataType.getValueType( ) == CPPUTYPE_OUSTR )
+    else if ( aSysDataType.getValueType( ) == cppu::UnoType<OUString>::get() )
     {
         OUString nativeFormatName;
         aSysDataType >>= nativeFormatName;
@@ -530,7 +523,7 @@ DataFlavor SAL_CALL 
CDataFormatTranslatorUNO::getDataFlavorFromSystemDataType( c
 
 OUString SAL_CALL CDataFormatTranslatorUNO::getImplementationName(  )
 {
-    return IMPL_NAME;
+    return "com.sun.star.datatransfer.DataFormatTranslator";
 }
 
 sal_Bool SAL_CALL CDataFormatTranslatorUNO::supportsService( const OUString& 
ServiceName )
@@ -540,7 +533,15 @@ sal_Bool SAL_CALL 
CDataFormatTranslatorUNO::supportsService( const OUString& Ser
 
 Sequence< OUString > SAL_CALL 
CDataFormatTranslatorUNO::getSupportedServiceNames( )
 {
-    return DataFormatTranslator_getSupportedServiceNames( );
+    return { "com.sun.star.datatransfer.DataFormatTranslator" };
 }
 
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+dtrans_CDataFormatTranslatorUNO_get_implementation(
+    css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> 
const&)
+{
+    static rtl::Reference<CDataFormatTranslatorUNO> g_Instance(new 
CDataFormatTranslatorUNO(context));
+    g_Instance->acquire();
+    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dtrans/source/win32/ftransl/ftranslentry.cxx 
b/dtrans/source/win32/ftransl/ftranslentry.cxx
deleted file mode 100644
index cdcfda46b10c..000000000000
--- a/dtrans/source/win32/ftransl/ftranslentry.cxx
+++ /dev/null
@@ -1,79 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <cppuhelper/factory.hxx>
-#include <comphelper/processfactory.hxx>
-#include <com/sun/star/container/XSet.hpp>
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-
-#include <com/sun/star/datatransfer/XDataFormatTranslator.hpp>
-#include "ftransl.hxx"
-
-#define SERVICE_NAME  "com.sun.star.datatransfer.DataFormatTranslator"
-
-#define IMPL_NAME  "com.sun.star.datatransfer.DataFormatTranslator"
-
-using namespace ::cppu;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::registry;
-using namespace ::com::sun::star::lang;
-using namespace ::com::sun::star::datatransfer;
-
-namespace
-{
-
-    // functions to create a new Clipboard instance; is needed by factory 
helper implementation
-    // @param rServiceManager - service manager, useful if the component needs 
other uno services
-    // so we should give it to every UNO-Implementation component
-
-    Reference< XInterface > createInstance( const Reference< 
XMultiServiceFactory >& rServiceManager )
-    {
-        return Reference< XInterface >( static_cast< XDataFormatTranslator* >( 
new CDataFormatTranslatorUNO( comphelper::getComponentContext(rServiceManager) 
) ) );
-    }
-}
-
-extern "C"
-{
-
-SAL_DLLPUBLIC_EXPORT void* ftransl_component_getFactory( const sal_Char* 
pImplName, void* pSrvManager, void* /*pRegistryKey*/ )
-{
-    void* pRet = nullptr;
-
-    if ( pSrvManager && ( 0 == rtl_str_compare( pImplName, IMPL_NAME ) ) )
-    {
-        Sequence< OUString > aSNS { SERVICE_NAME };
-
-        Reference< XSingleServiceFactory > xFactory ( createOneInstanceFactory(
-            static_cast< XMultiServiceFactory* > ( pSrvManager ),
-            OUString::createFromAscii( pImplName ),
-            createInstance,
-            aSNS ) );
-        if ( xFactory.is() )
-        {
-            xFactory->acquire();
-            pRet = xFactory.get();
-        }
-    }
-
-    return pRet;
-}
-
-} // extern "C"
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/dtrans/util/ftransl.component b/dtrans/util/ftransl.component
index b1fe4b006460..e97a897f7437 100644
--- a/dtrans/util/ftransl.component
+++ b/dtrans/util/ftransl.component
@@ -18,8 +18,9 @@
  -->
 
 <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
-    prefix="ftransl" xmlns="http://openoffice.org/2010/uno-components";>
-  <implementation name="com.sun.star.datatransfer.DataFormatTranslator">
+    xmlns="http://openoffice.org/2010/uno-components";>
+  <implementation name="com.sun.star.datatransfer.DataFormatTranslator"
+       constructor="dtrans_CDataFormatTranslatorUNO_get_implementation">
     <service name="com.sun.star.datatransfer.DataFormatTranslator"/>
   </implementation>
 </component>

Reply via email to