Simplify a bit

Change-Id: Ibb0165d0ce1ec1159a7d5446f746c4cdfcd0d748
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168916
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
This commit is contained in:
Mike Kaganski 2024-06-16 10:33:53 +05:00
parent 52a2c19fc4
commit 47efcbdcb4
7 changed files with 92 additions and 102 deletions

View file

@ -198,7 +198,7 @@ uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForLoading_Imp
uno::Sequence< beans::PropertyValue > aArgs( xStream.is() ? 3 : 2 );
auto pArgs = aArgs.getArray();
pArgs[0].Name = "FilterName";
pArgs[0].Value <<= getFilterNameFromGUID_Impl( &m_guid );
pArgs[0].Value <<= getFilterNameFromGUID_Impl( m_guid );
if ( xStream.is() )
{
@ -237,7 +237,7 @@ uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForStoring_Imp
uno::Sequence< beans::PropertyValue > aArgs( xStream.is() ? 2 : 1 );
auto pArgs = aArgs.getArray();
pArgs[0].Name = "FilterName";
pArgs[0].Value <<= getFilterNameFromGUID_Impl( &m_guid );
pArgs[0].Value <<= getFilterNameFromGUID_Impl( m_guid );
if ( xStream.is() )
{
@ -394,7 +394,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg )
if ( m_xFactory.is() && pStg )
{
uno::Reference< frame::XModel > aDocument(
m_xFactory->createInstance( OUString(getServiceNameFromGUID_Impl( &m_guid )) ),
m_xFactory->createInstance( OUString(getServiceNameFromGUID_Impl( m_guid )) ),
uno::UNO_QUERY );
if ( aDocument.is() )
{
@ -416,7 +416,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg )
if ( hr == S_OK )
{
wchar_t const * aCurType = getStorageTypeFromGUID_Impl( &m_guid ); // ???
wchar_t const * aCurType = getStorageTypeFromGUID_Impl( m_guid ); // ???
CLIPFORMAT cf = static_cast<CLIPFORMAT>(RegisterClipboardFormatW( L"Embedded Object" ));
hr = WriteFmtUserTypeStg( pStg,
cf, // ???
@ -529,7 +529,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg )
if ( xTempIn.is() )
{
uno::Reference< frame::XModel > aDocument(
m_xFactory->createInstance( OUString(getServiceNameFromGUID_Impl( &m_guid )) ),
m_xFactory->createInstance( OUString(getServiceNameFromGUID_Impl( m_guid )) ),
uno::UNO_QUERY );
if ( aDocument.is() )
{
@ -736,7 +736,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileNam
if ( FAILED( hr ) || !m_pMasterStorage ) return E_FAIL;
std::u16string_view aCurType = getServiceNameFromGUID_Impl( &m_guid ); // ???
std::u16string_view aCurType = getServiceNameFromGUID_Impl( m_guid ); // ???
CLIPFORMAT cf = static_cast<CLIPFORMAT>(RegisterClipboardFormatW( L"Embedded Object" ));
hr = WriteFmtUserTypeStg( m_pMasterStorage,
cf, // ???
@ -762,7 +762,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileNam
uno::Reference< frame::XModel > aDocument(
m_xFactory->createInstance( OUString(getServiceNameFromGUID_Impl( &m_guid )) ),
m_xFactory->createInstance( OUString(getServiceNameFromGUID_Impl( m_guid )) ),
uno::UNO_QUERY );
if ( aDocument.is() )
{
@ -787,7 +787,7 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileNam
if ( hr == S_OK )
{
aCurType = getServiceNameFromGUID_Impl( &m_guid ); // ???
aCurType = getServiceNameFromGUID_Impl( m_guid ); // ???
cf = static_cast<CLIPFORMAT>(RegisterClipboardFormatW( L"Embedded Object" ));
hr = WriteFmtUserTypeStg( m_pMasterStorage,
cf, // ???

View file

@ -23,106 +23,106 @@
#include "guid.hxx"
wchar_t const * getStorageTypeFromGUID_Impl( GUID const * guid )
wchar_t const * getStorageTypeFromGUID_Impl( GUID const & guid )
{
if ( *guid == OID_WriterTextServer )
if ( guid == OID_WriterTextServer )
return L"soffice.StarWriterDocument.6";
if ( *guid == OID_WriterOASISTextServer )
if ( guid == OID_WriterOASISTextServer )
return L"LibreOffice.WriterDocument.1";
if ( *guid == OID_CalcServer )
if ( guid == OID_CalcServer )
return L"soffice.StarCalcDocument.6";
if ( *guid == OID_CalcOASISServer )
if ( guid == OID_CalcOASISServer )
return L"LibreOffice.CalcDocument.1";
if ( *guid == OID_DrawingServer )
if ( guid == OID_DrawingServer )
return L"soffice.StarDrawDocument.6";
if ( *guid == OID_DrawingOASISServer )
if ( guid == OID_DrawingOASISServer )
return L"LibreOffice.DrawDocument.1";
if ( *guid == OID_PresentationServer )
if ( guid == OID_PresentationServer )
return L"soffice.StarImpressDocument.6";
if ( *guid == OID_PresentationOASISServer )
if ( guid == OID_PresentationOASISServer )
return L"LibreOffice.ImpressDocument.1";
if ( *guid == OID_MathServer )
if ( guid == OID_MathServer )
return L"soffice.StarMathDocument.6";
if ( *guid == OID_MathOASISServer )
if ( guid == OID_MathOASISServer )
return L"LibreOffice.MathDocument.1";
return L"";
}
std::u16string_view getServiceNameFromGUID_Impl( GUID const * guid )
std::u16string_view getServiceNameFromGUID_Impl( GUID const & guid )
{
if ( *guid == OID_WriterTextServer )
if ( guid == OID_WriterTextServer )
return u"com.sun.star.comp.Writer.TextDocument";
if ( *guid == OID_WriterOASISTextServer )
if ( guid == OID_WriterOASISTextServer )
return u"com.sun.star.comp.Writer.TextDocument";
if ( *guid == OID_CalcServer )
if ( guid == OID_CalcServer )
return u"com.sun.star.comp.Calc.SpreadsheetDocument";
if ( *guid == OID_CalcOASISServer )
if ( guid == OID_CalcOASISServer )
return u"com.sun.star.comp.Calc.SpreadsheetDocument";
if ( *guid == OID_DrawingServer )
if ( guid == OID_DrawingServer )
return u"com.sun.star.comp.Draw.DrawingDocument";
if ( *guid == OID_DrawingOASISServer )
if ( guid == OID_DrawingOASISServer )
return u"com.sun.star.comp.Draw.DrawingDocument";
if ( *guid == OID_PresentationServer )
if ( guid == OID_PresentationServer )
return u"com.sun.star.comp.Draw.PresentationDocument";
if ( *guid == OID_PresentationOASISServer )
if ( guid == OID_PresentationOASISServer )
return u"com.sun.star.comp.Draw.PresentationDocument";
if ( *guid == OID_MathServer )
if ( guid == OID_MathServer )
return u"com.sun.star.comp.Math.FormulaDocument";
if ( *guid == OID_MathOASISServer )
if ( guid == OID_MathOASISServer )
return u"com.sun.star.comp.Math.FormulaDocument";
return u"";
}
OUString getFilterNameFromGUID_Impl( GUID const * guid )
OUString getFilterNameFromGUID_Impl( GUID const & guid )
{
if ( *guid == OID_WriterTextServer )
if ( guid == OID_WriterTextServer )
return "StarOffice XML (Writer)";
if ( *guid == OID_WriterOASISTextServer )
if ( guid == OID_WriterOASISTextServer )
return "writer8";
if ( *guid == OID_CalcServer )
if ( guid == OID_CalcServer )
return "StarOffice XML (Calc)";
if ( *guid == OID_CalcOASISServer )
if ( guid == OID_CalcOASISServer )
return "calc8";
if ( *guid == OID_DrawingServer )
if ( guid == OID_DrawingServer )
return "StarOffice XML (Draw)";
if ( *guid == OID_DrawingOASISServer )
if ( guid == OID_DrawingOASISServer )
return "draw8";
if ( *guid == OID_PresentationServer )
if ( guid == OID_PresentationServer )
return "StarOffice XML (Impress)";
if ( *guid == OID_PresentationOASISServer )
if ( guid == OID_PresentationOASISServer )
return "impress8";
if ( *guid == OID_MathServer )
if ( guid == OID_MathServer )
return "StarOffice XML (Math)";
if ( *guid == OID_MathOASISServer )
if ( guid == OID_MathOASISServer )
return "math8";
return OUString();

View file

@ -26,10 +26,10 @@
#include <common.h>
OUString getFilterNameFromGUID_Impl(GUID const*);
OUString getFilterNameFromGUID_Impl(GUID const&);
std::u16string_view getServiceNameFromGUID_Impl(GUID const*);
std::u16string_view getServiceNameFromGUID_Impl(GUID const&);
wchar_t const* getStorageTypeFromGUID_Impl(GUID const* guid);
wchar_t const* getStorageTypeFromGUID_Impl(GUID const& guid);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -28,19 +28,17 @@
#include <osl/thread.h>
#include <sal/log.hxx>
using namespace com::sun::star;
const GUID* const guidList[ SUPPORTED_FACTORIES_NUM ] = {
&OID_WriterTextServer,
&OID_WriterOASISTextServer,
&OID_CalcServer,
&OID_CalcOASISServer,
&OID_DrawingServer,
&OID_DrawingOASISServer,
&OID_PresentationServer,
&OID_PresentationOASISServer,
&OID_MathServer,
&OID_MathOASISServer
static constexpr GUID guidList[] = {
OID_WriterTextServer,
OID_WriterOASISTextServer,
OID_CalcServer,
OID_CalcOASISServer,
OID_DrawingServer,
OID_DrawingOASISServer,
OID_PresentationServer,
OID_PresentationOASISServer,
OID_MathServer,
OID_MathOASISServer
};
static void o2u_attachCurrentThread()
@ -61,23 +59,18 @@ static void o2u_attachCurrentThread()
// EmbedServer_Impl
EmbedServer_Impl::EmbedServer_Impl( const uno::Reference<lang::XMultiServiceFactory>& xFactory):
EmbedServer_Impl::EmbedServer_Impl( const css::uno::Reference<css::lang::XMultiServiceFactory>& xFactory):
m_xFactory( xFactory)
{
for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
{
m_pOLEFactories[nInd] = new EmbedProviderFactory_Impl( m_xFactory, guidList[nInd] );
m_pOLEFactories[nInd]->registerClass();
}
m_pOLEFactories.reserve(std::size(guidList));
std::transform(std::begin(guidList), std::end(guidList), std::back_inserter(m_pOLEFactories),
[this](auto& guid) { return new EmbedProviderFactory_Impl(m_xFactory, guid); });
}
EmbedServer_Impl::~EmbedServer_Impl()
{
for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
{
if ( m_pOLEFactories[nInd] )
m_pOLEFactories[nInd]->deregisterClass();
}
for (auto& factory : m_pOLEFactories)
factory->deregisterClass();
}
OUString EmbedServer_Impl::getImplementationName()
@ -98,9 +91,9 @@ css::uno::Sequence<OUString> EmbedServer_Impl::getSupportedServiceNames()
// EmbedProviderFactory_Impl
EmbedProviderFactory_Impl::EmbedProviderFactory_Impl(const uno::Reference<lang::XMultiServiceFactory>& xFactory, const GUID* pGuid)
EmbedProviderFactory_Impl::EmbedProviderFactory_Impl(const css::uno::Reference<css::lang::XMultiServiceFactory>& xFactory, const GUID& guid)
: m_refCount( 0 )
, m_guid( *pGuid )
, m_guid( guid )
, m_xFactory( xFactory )
{
}
@ -186,7 +179,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
embedserv_EmbedServer(
css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
{
auto msf = uno::Reference<lang::XMultiServiceFactory>(context->getServiceManager(), css::uno::UNO_QUERY_THROW);
auto msf = css::uno::Reference<css::lang::XMultiServiceFactory>(context->getServiceManager(), css::uno::UNO_QUERY_THROW);
return cppu::acquire(new EmbedServer_Impl(msf));
}

View file

@ -24,24 +24,20 @@
#include <comphelper/classids.hxx>
#define SUPPORTED_FACTORIES_NUM 10
inline constexpr GUID OID_WriterTextServer = { SO3_SW_OLE_EMBED_CLASSID_60 };
inline constexpr GUID OID_WriterOASISTextServer = { SO3_SW_OLE_EMBED_CLASSID_8 };
extern "C" const GUID DECLSPEC_SELECTANY OID_WriterTextServer = { SO3_SW_OLE_EMBED_CLASSID_60 };
extern "C" const GUID DECLSPEC_SELECTANY OID_WriterOASISTextServer = { SO3_SW_OLE_EMBED_CLASSID_8 };
inline constexpr GUID OID_CalcServer = { SO3_SC_OLE_EMBED_CLASSID_60 };
inline constexpr GUID OID_CalcOASISServer = { SO3_SC_OLE_EMBED_CLASSID_8 };
extern "C" const GUID DECLSPEC_SELECTANY OID_CalcServer = { SO3_SC_OLE_EMBED_CLASSID_60 };
extern "C" const GUID DECLSPEC_SELECTANY OID_CalcOASISServer = { SO3_SC_OLE_EMBED_CLASSID_8 };
inline constexpr GUID OID_DrawingServer = { SO3_SDRAW_OLE_EMBED_CLASSID_60 };
inline constexpr GUID OID_DrawingOASISServer = { SO3_SDRAW_OLE_EMBED_CLASSID_8 };
extern "C" const GUID DECLSPEC_SELECTANY OID_DrawingServer = { SO3_SDRAW_OLE_EMBED_CLASSID_60 };
extern "C" const GUID DECLSPEC_SELECTANY OID_DrawingOASISServer = { SO3_SDRAW_OLE_EMBED_CLASSID_8 };
inline constexpr GUID OID_PresentationServer = { SO3_SIMPRESS_OLE_EMBED_CLASSID_60 };
inline constexpr GUID OID_PresentationOASISServer = { SO3_SIMPRESS_OLE_EMBED_CLASSID_8 };
extern "C" const GUID DECLSPEC_SELECTANY OID_PresentationServer
= { SO3_SIMPRESS_OLE_EMBED_CLASSID_60 };
extern "C" const GUID DECLSPEC_SELECTANY OID_PresentationOASISServer
= { SO3_SIMPRESS_OLE_EMBED_CLASSID_8 };
extern "C" const GUID DECLSPEC_SELECTANY OID_MathServer = { SO3_SM_OLE_EMBED_CLASSID_60 };
extern "C" const GUID DECLSPEC_SELECTANY OID_MathOASISServer = { SO3_SM_OLE_EMBED_CLASSID_8 };
inline constexpr GUID OID_MathServer = { SO3_SM_OLE_EMBED_CLASSID_60 };
inline constexpr GUID OID_MathOASISServer = { SO3_SM_OLE_EMBED_CLASSID_8 };
#endif

View file

@ -27,6 +27,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/implbase.hxx>
#include <vector>
class EmbedProviderFactory_Impl;
@ -44,7 +45,7 @@ public:
protected:
CComPtr< EmbedProviderFactory_Impl > m_pOLEFactories[ SUPPORTED_FACTORIES_NUM ];
std::vector<CComPtr<EmbedProviderFactory_Impl>> m_pOLEFactories;
css::uno::Reference< css::lang::XMultiServiceFactory > m_xFactory;
};
@ -52,7 +53,7 @@ class EmbedProviderFactory_Impl : public IClassFactory
{
public:
EmbedProviderFactory_Impl( const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory, const GUID* pGuid);
EmbedProviderFactory_Impl(const css::uno::Reference<css::lang::XMultiServiceFactory>& xFactory, const GUID& guid);
virtual ~EmbedProviderFactory_Impl();
bool registerClass();

View file

@ -27,17 +27,17 @@
#include <olectl.h> // declarations of DllRegisterServer/DllUnregisterServer
static const GUID* guidList[ SUPPORTED_FACTORIES_NUM ] = {
&OID_WriterTextServer,
&OID_WriterOASISTextServer,
&OID_CalcServer,
&OID_CalcOASISServer,
&OID_DrawingServer,
&OID_DrawingOASISServer,
&OID_PresentationServer,
&OID_PresentationOASISServer,
&OID_MathServer,
&OID_MathOASISServer
static constexpr GUID guidList[] = {
OID_WriterTextServer,
OID_WriterOASISTextServer,
OID_CalcServer,
OID_CalcOASISServer,
OID_DrawingServer,
OID_DrawingOASISServer,
OID_PresentationServer,
OID_PresentationOASISServer,
OID_MathServer,
OID_MathOASISServer
};
static HINSTANCE g_hInstance = nullptr;
@ -52,7 +52,7 @@ namespace {
if ( pLibrary && nLen )
{
hRes = S_OK;
for ( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
for (auto& guid : guidList)
{
constexpr std::wstring_view prefix(L"Software\\Classes\\CLSID\\");
constexpr std::wstring_view suffix(L"\\InprocHandler32");
@ -62,7 +62,7 @@ namespace {
wchar_t pSubKey[bufsize];
wchar_t *pos = pSubKey, *end = pSubKey + std::size(pSubKey);
pos += prefix.copy(pos, prefix.size());
int nGuidLen = StringFromGUID2(*guidList[nInd], pos, end - pos);
int nGuidLen = StringFromGUID2(guid, pos, end - pos);
bool bLocalSuccess = false;
if (nGuidLen == guidStringSize)
@ -136,8 +136,8 @@ extern "C" BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lp
STDAPI DllGetClassObject( REFCLSID rclsid, REFIID riid, LPVOID* ppv )
{
for( int nInd = 0; nInd < SUPPORTED_FACTORIES_NUM; nInd++ )
if ( *guidList[nInd] == rclsid )
for (auto& guid : guidList)
if ( guid == rclsid )
{
if ( !IsEqualIID( riid, IID_IUnknown ) && !IsEqualIID( riid, IID_IClassFactory ) )
return E_NOINTERFACE;