From 8aa16f7ae0202a46bd7ef2d1896663b68441fa10 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 21 Jul 2020 14:57:09 +0200 Subject: 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 --- dtrans/Library_ftransl.mk | 1 - dtrans/source/win32/ftransl/ftransl.cxx | 26 ++++----- dtrans/source/win32/ftransl/ftranslentry.cxx | 79 ---------------------------- dtrans/util/ftransl.component | 5 +- 4 files changed, 16 insertions(+), 95 deletions(-) delete mode 100644 dtrans/source/win32/ftransl/ftranslentry.cxx 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 bd189b890f99..f2c5d6487e48 100644 --- a/dtrans/source/win32/ftransl/ftransl.cxx +++ b/dtrans/source/win32/ftransl/ftransl.cxx @@ -26,16 +26,13 @@ #include #include #include +#include #include "../misc/ImplHelper.hxx" #include -#define IMPL_NAME "com.sun.star.datatransfer.DataFormatTranslator" - #define CPPUTYPE_SEQSALINT8 cppu::UnoType>::get() #define CPPUTYPE_DEFAULT CPPUTYPE_SEQSALINT8 -#define CPPUTYPE_OUSTR cppu::UnoType::get() -#define CPPUTYPE_SALINT32 cppu::UnoType::get() const OUString Windows_FormatName ("windows_formatname"); const css::uno::Type CppuType_ByteSequence = cppu::UnoType>::get(); @@ -51,11 +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 { @@ -507,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::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::get() ) { OUString nativeFormatName; aSysDataType >>= nativeFormatName; @@ -531,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 ) @@ -541,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 const&) +{ + static rtl::Reference g_Instance(new CDataFormatTranslatorUNO(context)); + g_Instance->acquire(); + return static_cast(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 2959e589fa29..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 -#include -#include -#include - -#include -#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 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 @@ --> - + xmlns="http://openoffice.org/2010/uno-components"> + -- cgit