summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-11-24 00:52:12 +0100
committerMichael Stahl <mstahl@redhat.com>2013-12-03 20:40:59 +0100
commite4747d8149313039d0912f18380b033e3caf9e37 (patch)
treeaf946ec4aa06d8c0eeb44b3f840feac5a87982d9
parentffc77f555aee05d5abde16be0265fac877cc6ca3 (diff)
winaccessibility: replace CoCreateInstance with direct instantiation
This is an alternative (to 732ec36edfd09d2091d70c4d71b5f182fe279c45) solution to the "CoCreateInstance does not work" problem: replace all CoCreateInstance calls with equivalent calls to create the components directly. Since the only reason why this COM stuff needs to be registered at all is that AccObject uses CoCreateInstance() to create its COM objects, another possible solution appears to be to simply link the libraries and instantiate the COM objects directly, without COM. The only difference appears to be that CoCreateInstance would automatically add proxy objects in case the COM objects reside in a single-threaded appartment; not sure if that is relevant here. Reviewed-on: https://gerrit.libreoffice.org/6792 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Michael Meeks <michael.meeks@collabora.com> (cherry picked from commit 3b86569fcba210eb6570fabef7ff8abf6aff91f0) Conflicts: winaccessibility/source/UAccCOM/AccHypertext.cxx winaccessibility/source/UAccCOM/AccTable.cxx winaccessibility/source/UAccCOM/EnumVariant.cxx winaccessibility/source/UAccCOM/MAccessible.cxx winaccessibility/source/service/AccObject.cxx Change-Id: I8ffb8af501f6084f3145fa4d4f53366a070e1691
-rw-r--r--winaccessibility/Library_uacccom.mk1
-rw-r--r--winaccessibility/Library_winaccessibility.mk1
-rw-r--r--winaccessibility/inc/UAccCOMdllapi.h24
-rw-r--r--winaccessibility/inc/accHelper.hxx4
-rw-r--r--winaccessibility/source/UAccCOM/AccHypertext.cxx6
-rw-r--r--winaccessibility/source/UAccCOM/AccTable.cxx10
-rw-r--r--winaccessibility/source/UAccCOM/EnumVariant.cxx3
-rw-r--r--winaccessibility/source/UAccCOM/MAccessible.cxx67
-rw-r--r--winaccessibility/source/UAccCOM/UAccCOM.cxx9
-rw-r--r--winaccessibility/source/UAccCOM/acccommon.h6
-rw-r--r--winaccessibility/source/service/AccObject.cxx16
11 files changed, 114 insertions, 33 deletions
diff --git a/winaccessibility/Library_uacccom.mk b/winaccessibility/Library_uacccom.mk
index 1bcdba6619aa..6c81dcb4ec52 100644
--- a/winaccessibility/Library_uacccom.mk
+++ b/winaccessibility/Library_uacccom.mk
@@ -20,6 +20,7 @@ $(eval $(call gb_Library_set_include,UAccCOM,\
))
$(eval $(call gb_Library_add_defs,UAccCOM,\
+ -DUACCCOM_DLLIMPLEMENTATION \
-D_UNICODE=1 \
))
diff --git a/winaccessibility/Library_winaccessibility.mk b/winaccessibility/Library_winaccessibility.mk
index 55057c39ddd6..45a86f3c917c 100644
--- a/winaccessibility/Library_winaccessibility.mk
+++ b/winaccessibility/Library_winaccessibility.mk
@@ -53,6 +53,7 @@ $(eval $(call gb_Library_use_externals,winaccessibility,\
))
$(eval $(call gb_Library_use_libraries,winaccessibility,\
+ UAccCOM \
cppu \
cppuhelper \
vcl \
diff --git a/winaccessibility/inc/UAccCOMdllapi.h b/winaccessibility/inc/UAccCOMdllapi.h
new file mode 100644
index 000000000000..aca29b6678be
--- /dev/null
+++ b/winaccessibility/inc/UAccCOMdllapi.h
@@ -0,0 +1,24 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_UACCCOM_UACCCOMDLLAPI_H
+#define INCLUDED_UACCCOM_UACCCOMDLLAPI_H
+
+#include <sal/types.h>
+
+#if defined(UACCCOM_DLLIMPLEMENTATION)
+#define UACCCOM_DLLPUBLIC SAL_DLLPUBLIC_EXPORT
+#else
+#define UACCCOM_DLLPUBLIC SAL_DLLPUBLIC_IMPORT
+#endif
+#define UACCCOM_DLLPRIVATE SAL_DLLPRIVATE
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/inc/accHelper.hxx b/winaccessibility/inc/accHelper.hxx
index 772393a0768d..f0dd29bae440 100644
--- a/winaccessibility/inc/accHelper.hxx
+++ b/winaccessibility/inc/accHelper.hxx
@@ -20,6 +20,8 @@
#ifndef __ACCHELPER_HXX
#define __ACCHELPER_HXX
+#include <UAccCOMdllapi.h>
+
enum DIRECTION
{
FIRST_CHILD=0,
@@ -30,6 +32,8 @@ enum DIRECTION
#define UNO_MSAA_UNMAPPING 0x00000000
+struct IMAccessible;
+UACCCOM_DLLPUBLIC IMAccessible * UAccCOMCreateInstance();
#endif
diff --git a/winaccessibility/source/UAccCOM/AccHypertext.cxx b/winaccessibility/source/UAccCOM/AccHypertext.cxx
index 1c69aad9560f..40e14d2b140c 100644
--- a/winaccessibility/source/UAccCOM/AccHypertext.cxx
+++ b/winaccessibility/source/UAccCOM/AccHypertext.cxx
@@ -20,6 +20,8 @@
#include "stdafx.h"
#include "UAccCOM.h"
#include "AccHypertext.h"
+#include "AccHyperLink.h"
+#include "acccommon.h"
using namespace com::sun::star::accessibility;
@@ -324,9 +326,7 @@ STDMETHODIMP CAccHypertext::get_hyperlink(long index,IAccessibleHyperlink **hype
}
IAccessibleHyperlink* plink = NULL;
- HRESULT hr = CoCreateInstance( CLSID_AccHyperLink, NULL, CLSCTX_SERVER ,
- IID_IAccessibleHyperlink,
- (void **)&plink);
+ HRESULT hr = createInstance<CAccHyperLink>(IID_IAccessibleHyperlink, &plink);
if( SUCCEEDED(hr) )
{
IUNOXWrapper* wrapper = NULL;
diff --git a/winaccessibility/source/UAccCOM/AccTable.cxx b/winaccessibility/source/UAccCOM/AccTable.cxx
index 4a78c0e22394..095b56bd612c 100644
--- a/winaccessibility/source/UAccCOM/AccTable.cxx
+++ b/winaccessibility/source/UAccCOM/AccTable.cxx
@@ -213,10 +213,7 @@ STDMETHODIMP CAccTable::get_columnHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *
*startingRowIndex = 0 ;
IMAccessible* pIMacc = NULL;
- HRESULT hr = CoCreateInstance( CLSID_MAccessible, NULL, CLSCTX_ALL ,
- IID_IMAccessible,
- (void **)&pIMacc
- );
+ HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMacc);
if (!SUCCEEDED(hr))
{
return E_FAIL;
@@ -444,10 +441,7 @@ STDMETHODIMP CAccTable::get_rowHeader(IAccessibleTable __RPC_FAR *__RPC_FAR *acc
*startingColumnIndex = 0 ;
IMAccessible* pIMacc = NULL;
- HRESULT hr = CoCreateInstance( CLSID_MAccessible, NULL, CLSCTX_ALL ,
- IID_IMAccessible,
- (void **)&pIMacc
- );
+ HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMacc);
if (!SUCCEEDED(hr))
{
return E_FAIL;
diff --git a/winaccessibility/source/UAccCOM/EnumVariant.cxx b/winaccessibility/source/UAccCOM/EnumVariant.cxx
index 2057624b9384..3f537638d65f 100644
--- a/winaccessibility/source/UAccCOM/EnumVariant.cxx
+++ b/winaccessibility/source/UAccCOM/EnumVariant.cxx
@@ -153,8 +153,7 @@ HRESULT STDMETHODCALLTYPE CEnumVariant::Clone(IEnumVARIANT __RPC_FAR *__RPC_FAR
*/
HRESULT STDMETHODCALLTYPE CEnumVariant::Create(CEnumVariant __RPC_FAR *__RPC_FAR *ppenum)
{
- HRESULT hr = CoCreateInstance(CLSID_EnumVariant,NULL,
- CLSCTX_SERVER,IID_IEnumVariant,(void **)ppenum);
+ HRESULT hr = createInstance<CEnumVariant>(IID_IEnumVariant, ppenum);
if (S_OK != hr)
{
return E_FAIL;
diff --git a/winaccessibility/source/UAccCOM/MAccessible.cxx b/winaccessibility/source/UAccCOM/MAccessible.cxx
index 92b6b0b1afbd..ee86adbd4be7 100644
--- a/winaccessibility/source/UAccCOM/MAccessible.cxx
+++ b/winaccessibility/source/UAccCOM/MAccessible.cxx
@@ -23,6 +23,15 @@
#include <algorithm>
#include "AccAction.h"
+#include "AccRelation.h"
+#include "AccComponent.h"
+#include "AccText.h"
+#include "AccEditableText.h"
+#include "AccImage.h"
+#include "AccTable.h"
+#include "AccValue.h"
+#include "AccHypertext.h"
+#include "AccHyperLink.h"
#include <com/sun/star/accessibility/XAccessibleText.hpp>
#include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
@@ -1719,9 +1728,8 @@ STDMETHODIMP CMAccessible::get_relation( long relationIndex, IAccessibleRelation
}
IAccessibleRelation* pRelation = NULL;
- HRESULT hr = CoCreateInstance( CLSID_AccRelation, NULL, CLSCTX_SERVER ,
- IID_IAccessibleRelation,
- (void **)&pRelation);
+ HRESULT hr = createInstance<CAccRelation>(IID_IAccessibleRelation,
+ &pRelation);
if(SUCCEEDED(hr))
{
IUNOXWrapper* wrapper = NULL;
@@ -1781,9 +1789,8 @@ STDMETHODIMP CMAccessible::get_relations( long, IAccessibleRelation __RPC_FAR *_
for(int i=0; i<nCount ; i++)
{
IAccessibleRelation* pRelation = NULL;
- HRESULT hr = CoCreateInstance( CLSID_AccRelation, NULL, CLSCTX_SERVER ,
- IID_IAccessibleRelation,
- (void **)&pRelation);
+ HRESULT hr = createInstance<CAccRelation>(IID_IAccessibleRelation,
+ &pRelation);
if(SUCCEEDED(hr))
{
IUNOXWrapper* wrapper = NULL;
@@ -2552,7 +2559,18 @@ BOOL CMAccessible::GetXInterfaceFromXAccessible(XAccessible* pXAcc, XInterface**
return FALSE;
}
-HRESULT WINAPI CMAccessible::SmartQI(void* pv, REFIID iid, void** ppvObject)
+template<typename T> HRESULT
+createAggInstance(CMAccessible &rOuter, REFIID iid, void ** ppvObject)
+{
+// return CComCreator< CComAggObject<T> >::CreateInstance(
+// XXX: do not use CComAggObject - the aggregation is hand-crafted!
+// the SmartQI method must not call itself recursively -
+// which it will do if CComAggObject redirects QueryInterface.
+ return CComCreator< CComObject<T> >::CreateInstance(
+ rOuter.GetControllingUnknown(), iid, ppvObject);
+}
+
+HRESULT WINAPI CMAccessible::SmartQI(void* /*pv*/, REFIID iid, void** ppvObject)
{
ENTER_PROTECTED_BLOCK
ISDESTROY()
@@ -2584,7 +2602,40 @@ HRESULT WINAPI CMAccessible::SmartQI(void* pv, REFIID iid, void** ppvObject)
}
else
{
- HRESULT hr = pMap->pfnCreateInstance(pv, iid, ppvObject);
+ HRESULT hr(REGDB_E_CLASSNOTREG);
+ switch (pMap->XIFIndex)
+ {
+ case XI_COMPONENT:
+ hr = createAggInstance<CAccComponent>(*this, iid, ppvObject);
+ break;
+ case XI_TEXT:
+ hr = createAggInstance<CAccText>(*this, iid, ppvObject);
+ break;
+ case XI_EDITABLETEXT:
+ hr = createAggInstance<CAccEditableText>(*this, iid, ppvObject);
+ break;
+ case XI_IMAGE:
+ hr = createAggInstance<CAccImage>(*this, iid, ppvObject);
+ break;
+ case XI_TABLE:
+ hr = createAggInstance<CAccTable>(*this, iid, ppvObject);
+ break;
+ case XI_ACTION:
+ hr = createAggInstance<CAccAction>(*this, iid, ppvObject);
+ break;
+ case XI_VALUE:
+ hr = createAggInstance<CAccValue>(*this, iid, ppvObject);
+ break;
+ case XI_HYPERTEXT:
+ hr = createAggInstance<CAccHypertext>(*this, iid, ppvObject);
+ break;
+ case XI_HYPERLINK:
+ hr = createAggInstance<CAccHyperLink>(*this, iid, ppvObject);
+ break;
+ default:
+ assert(false);
+ }
+ assert(hr == S_OK);
if(hr == S_OK)
{
m_containedObjects.insert(XGUIDToComObjHash::value_type(*pMap->piid,(IUnknown*)*ppvObject));
diff --git a/winaccessibility/source/UAccCOM/UAccCOM.cxx b/winaccessibility/source/UAccCOM/UAccCOM.cxx
index 52b40a017b3e..637b944af43f 100644
--- a/winaccessibility/source/UAccCOM/UAccCOM.cxx
+++ b/winaccessibility/source/UAccCOM/UAccCOM.cxx
@@ -21,6 +21,7 @@
#include "resource.h"
#include <initguid.h>
#include "UAccCOM.h"
+#include <accHelper.hxx>
#include "UAccCOM_i.c"
#include "ia2_api_all_i.c"
@@ -94,4 +95,12 @@ STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
}
+
+IMAccessible * UAccCOMCreateInstance()
+{
+ IMAccessible * pIMA = 0;
+ HRESULT hr = createInstance<CMAccessible>(IID_IMAccessible, &pIMA);
+ return (S_OK == hr) ? pIMA : 0;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/source/UAccCOM/acccommon.h b/winaccessibility/source/UAccCOM/acccommon.h
index 61c876aa7e38..22112ad97eac 100644
--- a/winaccessibility/source/UAccCOM/acccommon.h
+++ b/winaccessibility/source/UAccCOM/acccommon.h
@@ -85,6 +85,12 @@ inline BOOL ImplIsEqualGUID(REFGUID rguid1, REFGUID rguid2)
static DWORD GetMSAAStateFromUNO(short xState);
+template<typename T, typename Ifc> HRESULT
+createInstance(REFIID iid, Ifc ** ppIfc)
+{
+ return CComCreator< CComObject<T> >::CreateInstance(0, iid, (void**)ppIfc);
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/source/service/AccObject.cxx b/winaccessibility/source/service/AccObject.cxx
index 8c8649848cdf..b8ea002f57b1 100644
--- a/winaccessibility/source/service/AccObject.cxx
+++ b/winaccessibility/source/service/AccObject.cxx
@@ -243,19 +243,11 @@ void AccObject::UpdateValidWindow()
*/
sal_Bool AccObject::ImplInitializeCreateObj()
{
- HRESULT hr = CoCreateInstance( CLSID_MAccessible, NULL, CLSCTX_ALL,
- IID_IMAccessible,
- (void **)&m_pIMAcc);
- SAL_WARN_IF(
- m_pIMAcc == 0, "iacc2",
- "Failed to create IAccessible2 instance: 0x" << std::hex << hr);
-
- if ( S_OK != hr )
- {
- return sal_False;
- }
+ m_pIMAcc = UAccCOMCreateInstance();
- return sal_True;
+ assert(m_pIMAcc);
+
+ return m_pIMAcc != 0;
}
/**