[Libreoffice-commits] core.git: Branch 'libreoffice-4-2' - 6 commits - vcl/source vcl/win winaccessibility/inc winaccessibility/Library_uacccom.mk winaccessibility/Library_winaccessibility.mk winaccessibility/source

Michael Stahl mstahl at redhat.com
Tue Dec 3 11:47:56 PST 2013


 vcl/source/app/svdata.cxx                                 |   33 ++++--
 vcl/win/source/window/salframe.cxx                        |   20 +++-
 winaccessibility/Library_uacccom.mk                       |    1 
 winaccessibility/Library_winaccessibility.mk              |    1 
 winaccessibility/inc/AccObjectManagerAgent.hxx            |    9 +
 winaccessibility/inc/AccObjectWinManager.hxx              |    2 
 winaccessibility/inc/AccTopWindowListener.hxx             |    2 
 winaccessibility/inc/UAccCOMdllapi.h                      |   24 ++++
 winaccessibility/inc/accHelper.hxx                        |    4 
 winaccessibility/inc/g_msacc.hxx                          |   27 -----
 winaccessibility/source/UAccCOM/AccHypertext.cxx          |    6 -
 winaccessibility/source/UAccCOM/AccTable.cxx              |   10 --
 winaccessibility/source/UAccCOM/EnumVariant.cxx           |    3 
 winaccessibility/source/UAccCOM/MAccessible.cxx           |   68 ++++++++++++--
 winaccessibility/source/UAccCOM/UAccCOM.cxx               |   13 +-
 winaccessibility/source/UAccCOM/acccommon.h               |    6 +
 winaccessibility/source/service/AccObject.cxx             |   16 ---
 winaccessibility/source/service/AccObjectManagerAgent.cxx |   22 ++--
 winaccessibility/source/service/AccObjectWinManager.cxx   |   33 ------
 winaccessibility/source/service/AccTopWindowListener.cxx  |    6 +
 winaccessibility/source/service/msaaservice_impl.cxx      |   41 +-------
 21 files changed, 187 insertions(+), 160 deletions(-)

New commits:
commit 36dd638c53188b7606484f31d6a4cd6170850083
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Nov 29 23:03:37 2013 +0100

    vcl: check if AT is running before loading the library
    
    ... which should result in faster startup if it's disabled.
    
    Change-Id: I39774b0a56f186d08270c2f17b2b20a823f21dc2
    (cherry picked from commit b44ed4c408d92f7a1a3f2390c056d518c137ddd0)

diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index 97116d4..aa58484 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -297,6 +297,9 @@ com::sun::star::uno::Any AccessBridgeCurrentContext::getValueByName( const OUStr
     return ret;
 }
 
+#ifdef _WIN32
+bool HasAtHook();
+#endif
 
 bool ImplInitAccessBridge(bool bAllowCancel, bool &rCancelled)
 {
@@ -324,25 +327,35 @@ bool ImplInitAccessBridge(bool bAllowCancel, bool &rCancelled)
         {
             css::uno::Reference< XComponentContext > xContext(comphelper::getProcessComponentContext());
 
+#ifdef _WIN32
             bool bTryIAcc2 = ( officecfg::Office::Common::Misc::ExperimentalMode::get( xContext ) &&
                                !getenv ("SAL_DISABLE_IACCESSIBLE2") );
 
             if ( bTryIAcc2 ) // Windows only really
             {
-                try {
-                    pSVData->mxAccessBridge
-                        = css::accessibility::MSAAService::create(xContext);
-                    SAL_INFO("vcl", "got IAccessible2 bridge");
-                    return true;
-                } catch (css::uno::DeploymentException & e) {
-                    SAL_INFO(
-                        "vcl",
-                        "got no IAccessible2 bridge, \"" << e.Message
-                            << "\", falling back to java");
+                if (!HasAtHook() && !getenv("SAL_FORCE_IACCESSIBLE2"))
+                {
+                    SAL_INFO("vcl", "Apparently no running AT -> "
+                            "not enabling IAccessible2 integration");
+                }
+                else
+                {
+                    try {
+                        pSVData->mxAccessBridge
+                            = css::accessibility::MSAAService::create(xContext);
+                        SAL_INFO("vcl", "got IAccessible2 bridge");
+                        return true;
+                    } catch (css::uno::DeploymentException & e) {
+                        SAL_INFO(
+                            "vcl",
+                            "got no IAccessible2 bridge, \"" << e.Message
+                                << "\", falling back to java");
+                    }
                 }
             }
             else
                 SAL_INFO( "vcl", "IAccessible2 disabled, falling back to java" );
+#endif
 
             css::uno::Reference< XExtendedToolkit > xToolkit =
                 css::uno::Reference< XExtendedToolkit >(Application::GetVCLToolkit(), UNO_QUERY);
diff --git a/vcl/win/source/window/salframe.cxx b/vcl/win/source/window/salframe.cxx
index 913d539..f7c3086 100644
--- a/vcl/win/source/window/salframe.cxx
+++ b/vcl/win/source/window/salframe.cxx
@@ -6257,4 +6257,14 @@ sal_Bool ImplWriteLastError( DWORD lastError, const char *szApiCall )
 
 // -----------------------------------------------------------------------
 
+#ifdef _WIN32
+bool HasAtHook()
+{
+    BOOL bIsRunning = FALSE;
+    // pvParam must be BOOL
+    return SystemParametersInfo(SPI_GETSCREENREADER, 0, &bIsRunning, 0)
+        && bIsRunning;
+}
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/source/service/msaaservice_impl.cxx b/winaccessibility/source/service/msaaservice_impl.cxx
index c9ea14c..fe3c163 100644
--- a/winaccessibility/source/service/msaaservice_impl.cxx
+++ b/winaccessibility/source/service/msaaservice_impl.cxx
@@ -237,21 +237,6 @@ static void AccessBridgeUpdateOldTopWindows( const Reference< XMSAAService > &xA
     }
 }
 
-static bool HasAtHook()
-{
-    sal_Int32 bIsRuning=0;
-    // BOOL WINAPI SystemParametersInfo(
-    //    __in     UINT uiAction,
-    //    __in     UINT uiParam,
-    //    __inout  PVOID pvParam,
-    //    __in     UINT fWinIni
-    //  );
-    // pvParam must be BOOL (defined in MFC as int)
-    // End
-    return SystemParametersInfo( SPI_GETSCREENREADER, 0,
-                                 &bIsRuning, 0) && bIsRuning;
-}
-
 /**
  * Static method that can create an entity of our MSAA Service
  * @param xContext No use here.
@@ -259,17 +244,6 @@ static bool HasAtHook()
  */
 Reference< XInterface > SAL_CALL create_MSAAServiceImpl( Reference< XComponentContext > const & /*xContext*/ ) SAL_THROW( () )
 {
-    bool bRunWithoutAt = getenv("SAL_FORCE_IACCESSIBLE2");
-
-    if ( !HasAtHook() )
-    {
-        if ( !bRunWithoutAt )
-        {
-            SAL_INFO("iacc2", "Apparently no running AT -> not enabling IAccessible2 integration");
-            return Reference< XMSAAService >();
-        }
-    }
-
     Reference< XMSAAService > xAccMgr( new MSAAServiceImpl() );
 
     AccessBridgeUpdateOldTopWindows( xAccMgr );
commit dcbf2c405870bdf8d7f94e1ea64c91ce685c22e4
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Nov 29 22:39:33 2013 +0100

    winaccessibility: remove global g_acc_manager
    
    It is possible to retrieve it via the AccTopWindowListener.
    
    Change-Id: I6cc5ab25bc937d0d9f4de54a1bed09a76ce27491
    (cherry picked from commit fabca7370e22f96ae041dc179475b35c87ac53ec)

diff --git a/winaccessibility/inc/AccObjectManagerAgent.hxx b/winaccessibility/inc/AccObjectManagerAgent.hxx
index fd61c40..5aa9f81 100644
--- a/winaccessibility/inc/AccObjectManagerAgent.hxx
+++ b/winaccessibility/inc/AccObjectManagerAgent.hxx
@@ -20,9 +20,9 @@
 #ifndef __ACCOBJECTMANAGERAGENT_HXX
 #define __ACCOBJECTMANAGERAGENT_HXX
 
-#ifndef _COM_SUN_STAR_ACCESSIBILITY_XACCESSIBLE_HPP_
+#include <boost/scoped_ptr.hpp>
+
 #include <com/sun/star/accessibility/XAccessible.hpp>
-#endif
 
 struct IMAccessible;
 struct IAccessible;
@@ -37,7 +37,7 @@ class AccObjectManagerAgent
 {
 private:
 
-    AccObjectWinManager* pWinManager;
+    boost::scoped_ptr<AccObjectWinManager> pWinManager;
 
 public:
 
@@ -96,6 +96,9 @@ public:
     bool IsTopWinAcc( com::sun::star::accessibility::XAccessible* pXAcc );
 
     bool IsStateManageDescendant(com::sun::star::accessibility::XAccessible* pXAcc);
+
+    sal_Int64 Get_ToATInterface(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam);
+
 };
 
 #endif
diff --git a/winaccessibility/inc/AccObjectWinManager.hxx b/winaccessibility/inc/AccObjectWinManager.hxx
index f58a858..84bfca6 100644
--- a/winaccessibility/inc/AccObjectWinManager.hxx
+++ b/winaccessibility/inc/AccObjectWinManager.hxx
@@ -97,8 +97,6 @@ public:
     void DeleteAccObj( com::sun::star::accessibility::XAccessible* pXAcc );
     void DeleteChildrenAccObj(com::sun::star::accessibility::XAccessible* pAccObj);
 
-    static  AccObjectWinManager* CreateAccObjectWinManagerInstance(AccObjectManagerAgent* Agent);
-
     sal_Bool NotifyAccEvent( com::sun::star::accessibility::XAccessible* pXAcc,short state = 0 );
 
     LPARAM Get_ToATInterface(HWND hWnd, long lParam, WPARAM wParam);
diff --git a/winaccessibility/inc/AccTopWindowListener.hxx b/winaccessibility/inc/AccTopWindowListener.hxx
index 9babd67..2782320 100644
--- a/winaccessibility/inc/AccTopWindowListener.hxx
+++ b/winaccessibility/inc/AccTopWindowListener.hxx
@@ -59,6 +59,8 @@ public:
     virtual void AddAllListeners(com::sun::star::accessibility::XAccessible* pAccessible,com::sun::star::accessibility::XAccessible* pParentXAcc,HWND pWND );
     //for On-Demand load.
     virtual void HandleWindowOpened( com::sun::star::accessibility::XAccessible* pAccessible );
+
+    sal_Int64 GetMSComPtr(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam);
 };
 
 #endif
diff --git a/winaccessibility/inc/g_msacc.hxx b/winaccessibility/inc/g_msacc.hxx
deleted file mode 100644
index b9670cf..0000000
--- a/winaccessibility/inc/g_msacc.hxx
+++ /dev/null
@@ -1,27 +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 .
- */
-
-#ifndef __G_MSACC_HXX
-#define __G_MSACC_HXX
-
-extern sal_Int64 GetMSComPtr(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam);
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/source/service/AccObjectManagerAgent.cxx b/winaccessibility/source/service/AccObjectManagerAgent.cxx
index 1c76360..d4f4dab 100644
--- a/winaccessibility/source/service/AccObjectManagerAgent.cxx
+++ b/winaccessibility/source/service/AccObjectManagerAgent.cxx
@@ -30,19 +30,13 @@ using namespace com::sun::star::accessibility;
    * @param
    * @return
    */
-AccObjectManagerAgent::AccObjectManagerAgent():
-        pWinManager(NULL)
+AccObjectManagerAgent::AccObjectManagerAgent()
+    : pWinManager(new AccObjectWinManager(this))
 {
-    if( pWinManager == NULL )
-    {
-        pWinManager = AccObjectWinManager::CreateAccObjectWinManagerInstance(this);
-    }
 }
 
 AccObjectManagerAgent::~AccObjectManagerAgent()
 {
-    delete pWinManager;
-    pWinManager = NULL;
 }
 
 /**
@@ -388,4 +382,16 @@ bool AccObjectManagerAgent::IsStateManageDescendant(XAccessible* pXAcc)
     return false;
 }
 
+/**
+ *  Implementation of interface XMSAAService's method getAccObjectPtr()
+ *  that returns the corresponding COM interface with the MS event.
+ *  @return  Com interface.
+ */
+sal_Int64 AccObjectManagerAgent::Get_ToATInterface(
+        sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
+{
+    return static_cast<sal_Int64>(pWinManager->Get_ToATInterface(
+            static_cast<HWND>(reinterpret_cast<void*>(hWnd)), lParam, wParam));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/source/service/AccObjectWinManager.cxx b/winaccessibility/source/service/AccObjectWinManager.cxx
index 4bcc8df..8559e2b 100644
--- a/winaccessibility/source/service/AccObjectWinManager.cxx
+++ b/winaccessibility/source/service/AccObjectWinManager.cxx
@@ -53,23 +53,6 @@ using namespace com::sun::star::accessibility::AccessibleRole;
 using namespace com::sun::star::accessibility::AccessibleStateType;
 using namespace com::sun::star::uno;
 
-AccObjectWinManager* g_acc_manager = NULL;
-
-/**
-   * Implementation of interface XMSAAService's method getAccObjectPtr() that return the
-   * corresponding com interface with the MS event.
-   *
-   * @param
-   * @return  Com interface.
-   */
-sal_Int64 GetMSComPtr(sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
-{
-    if (!g_acc_manager)
-        return 0;
-    return static_cast<sal_Int64>(g_acc_manager->Get_ToATInterface(
-            static_cast<HWND>(reinterpret_cast<void*>(hWnd)), lParam, wParam));
-}
-
 /**
    * constructor
    * @param   Agent The agent kept in all listeners,it's the sole interface by which
@@ -89,22 +72,6 @@ AccObjectWinManager::AccObjectWinManager( AccObjectManagerAgent* Agent ):
 }
 
 /**
-   * Public method to produce manager
-   * @param   Agent The agent kept in all listeners,it's the sole interface by which
-   *          listener communicate with windows manager.
-   * @return
-   */
-AccObjectWinManager* AccObjectWinManager::CreateAccObjectWinManagerInstance( AccObjectManagerAgent* Agent )
-{
-    if (!g_acc_manager)
-    {
-        g_acc_manager = new AccObjectWinManager( Agent );
-    }
-    return g_acc_manager;
-}
-
-
-/**
    * Destructor,clear all resource.
    * @param
    * @return
diff --git a/winaccessibility/source/service/AccTopWindowListener.cxx b/winaccessibility/source/service/AccTopWindowListener.cxx
index ca8a1c0..db87f23 100644
--- a/winaccessibility/source/service/AccTopWindowListener.cxx
+++ b/winaccessibility/source/service/AccTopWindowListener.cxx
@@ -255,4 +255,10 @@ void AccTopWindowListener::disposing( const ::com::sun::star::lang::EventObject&
 {
 }
 
+sal_Int64 AccTopWindowListener::GetMSComPtr(
+        sal_Int64 hWnd, sal_Int64 lParam, sal_Int64 wParam)
+{
+    return accManagerAgent.Get_ToATInterface(hWnd, lParam, wParam);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/winaccessibility/source/service/msaaservice_impl.cxx b/winaccessibility/source/service/msaaservice_impl.cxx
index e5e1231..c9ea14c 100644
--- a/winaccessibility/source/service/msaaservice_impl.cxx
+++ b/winaccessibility/source/service/msaaservice_impl.cxx
@@ -41,7 +41,6 @@ using namespace ::com::sun::star::accessibility;
 using namespace ::com::sun::star::awt;
 
 #include "AccTopWindowListener.hxx"
-#include "g_msacc.hxx"
 
 namespace my_sc_impl
 {
@@ -95,7 +94,11 @@ throw (RuntimeException)
 {
     SolarMutexGuard g;
 
-    return GetMSComPtr( hWnd, lParam, wParam );
+    if (!m_pTopWindowListener.is())
+    {
+        return 0;
+    }
+    return m_pTopWindowListener->GetMSComPtr(hWnd, lParam, wParam);
 }
 
 /**
commit 97e4c624024dc2afbbbcfe13caf4470908c95390
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Nov 29 21:43:42 2013 +0100

    Revert "winaccessibility: let CoCreateInstance calls find the components"
    
    This only works partially: the ClassObjects are only registered on the
    main thread; CoCreateInstance on other threads still fails.
    
    This reverts commit 29c6216af8c502f220bb84857d3dda901ddfd234.
    
    (cherry picked from commit b54d441ad728ffce8e543de10bd897f0900422b5)

diff --git a/winaccessibility/source/UAccCOM/UAccCOM.cxx b/winaccessibility/source/UAccCOM/UAccCOM.cxx
index 637b944..b9e823d 100644
--- a/winaccessibility/source/UAccCOM/UAccCOM.cxx
+++ b/winaccessibility/source/UAccCOM/UAccCOM.cxx
@@ -67,14 +67,10 @@ extern "C"
     if (dwReason == DLL_PROCESS_ATTACH)
     {
         _Module.Init(ObjectMap, hInstance, &LIBID_UACCCOMLib);
-        _Module.RegisterClassObjects(CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE);
         DisableThreadLibraryCalls(hInstance);
     }
     else if (dwReason == DLL_PROCESS_DETACH)
-    {
-        _Module.RevokeClassObjects();
         _Module.Term();
-    }
     return TRUE;    // ok
 }
 
diff --git a/winaccessibility/source/service/msaaservice_impl.cxx b/winaccessibility/source/service/msaaservice_impl.cxx
index 5f3d5fc..e5e1231 100644
--- a/winaccessibility/source/service/msaaservice_impl.cxx
+++ b/winaccessibility/source/service/msaaservice_impl.cxx
@@ -267,14 +267,6 @@ Reference< XInterface > SAL_CALL create_MSAAServiceImpl( Reference< XComponentCo
         }
     }
 
-    // load UAccCOM library so its DllMain can register its COM components
-    static HMODULE h = LoadLibrary("UAccCOM.dll");
-    if (!h)
-    {
-        assert(false);
-        return 0;
-    }
-
     Reference< XMSAAService > xAccMgr( new MSAAServiceImpl() );
 
     AccessBridgeUpdateOldTopWindows( xAccMgr );
commit ba2c68241df89608cdf0fef335a9f158256c7146
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Nov 29 19:17:33 2013 +0100

    winaccessibility: fix my stupid mistake in createAggInstance
    
    Change-Id: I7701021befcf1dbad85557c2095fe4bf0b4e0ff1
    (cherry picked from commit d0e8e6e3cd51736583603e37f0ba2ff7bdf29f5c)

diff --git a/winaccessibility/source/UAccCOM/MAccessible.cxx b/winaccessibility/source/UAccCOM/MAccessible.cxx
index ee86adb..6c909f9 100644
--- a/winaccessibility/source/UAccCOM/MAccessible.cxx
+++ b/winaccessibility/source/UAccCOM/MAccessible.cxx
@@ -2560,14 +2560,15 @@ BOOL CMAccessible::GetXInterfaceFromXAccessible(XAccessible* pXAcc, XInterface**
 }
 
 template<typename T> HRESULT
-createAggInstance(CMAccessible &rOuter, REFIID iid, void ** ppvObject)
+createAggInstance(CMAccessible &rOuter, 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);
+    // Note: CComAggObject has special handling for IUnknown - must
+    // query for that when creating it! Otherwise we get a T member of it
+    // which will redirect QueryInterface back to CMAccessible infinitely.
+    // (CComAggObject has its own ref-count too which is not a problem
+    //  since it is inserted in m_containedObjects.)
+    return CComCreator< CComAggObject<T> >::CreateInstance(
+            rOuter.GetControllingUnknown(), IID_IUnknown, ppvObject);
 }
 
 HRESULT WINAPI CMAccessible::SmartQI(void* /*pv*/, REFIID iid, void** ppvObject)
@@ -2606,31 +2607,31 @@ HRESULT WINAPI CMAccessible::SmartQI(void* /*pv*/, REFIID iid, void** ppvObject)
                 switch (pMap->XIFIndex)
                 {
                     case XI_COMPONENT:
-                        hr = createAggInstance<CAccComponent>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccComponent>(*this, ppvObject);
                         break;
                     case XI_TEXT:
-                        hr = createAggInstance<CAccText>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccText>(*this, ppvObject);
                         break;
                     case XI_EDITABLETEXT:
-                        hr = createAggInstance<CAccEditableText>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccEditableText>(*this, ppvObject);
                         break;
                     case XI_IMAGE:
-                        hr = createAggInstance<CAccImage>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccImage>(*this, ppvObject);
                         break;
                     case XI_TABLE:
-                        hr = createAggInstance<CAccTable>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccTable>(*this, ppvObject);
                         break;
                     case XI_ACTION:
-                        hr = createAggInstance<CAccAction>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccAction>(*this, ppvObject);
                         break;
                     case XI_VALUE:
-                        hr = createAggInstance<CAccValue>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccValue>(*this, ppvObject);
                         break;
                     case XI_HYPERTEXT:
-                        hr = createAggInstance<CAccHypertext>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccHypertext>(*this, ppvObject);
                         break;
                     case XI_HYPERLINK:
-                        hr = createAggInstance<CAccHyperLink>(*this, iid, ppvObject);
+                        hr = createAggInstance<CAccHyperLink>(*this, ppvObject);
                         break;
                     default:
                         assert(false);
commit e4747d8149313039d0912f18380b033e3caf9e37
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sun Nov 24 00:52:12 2013 +0100

    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 at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at 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

diff --git a/winaccessibility/Library_uacccom.mk b/winaccessibility/Library_uacccom.mk
index 1bcdba6..6c81dcb 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 55057c3..45a86f3 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 0000000..aca29b6
--- /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 772393a..f0dd29b 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 1c69aad..40e14d2 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 4a78c0e..095b56b 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 2057624b..3f53763 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 92b6b0b..ee86adb 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 52b40a0..637b944 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 61c876a..22112ad 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 8c86498..b8ea002 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;
 }
 
 /**
commit ffc77f555aee05d5abde16be0265fac877cc6ca3
Author: Michael Stahl <mstahl at redhat.com>
Date:   Thu Nov 28 20:12:12 2013 +0100

    vcl: fix crashes when retrieving objects for MSAA
    
    The ImplHandleGetObject() function modifies the Application Settings and
    must take the SolarMutex for this; otherwise we get crashes when another
    thread calls StyleSettings::GetPersonaHeader() during some unoapi test.
    
    Also fix another HWND to long cast; use LRESULT which is Win32 for intptr_t.
    
    Change-Id: I5580f88ed0a8e9955697655ace94584e2307982d
    (cherry picked from commit db214684057e3ff2fa32d57c00507309dd6c24d6)

diff --git a/vcl/win/source/window/salframe.cxx b/vcl/win/source/window/salframe.cxx
index 8ee2cae..913d539 100644
--- a/vcl/win/source/window/salframe.cxx
+++ b/vcl/win/source/window/salframe.cxx
@@ -5484,7 +5484,8 @@ static void ImplHandleIMENotify( HWND hWnd, WPARAM wParam )
 
 // -----------------------------------------------------------------------
 
-static bool ImplHandleGetObject( HWND hWnd, LPARAM lParam, WPARAM wParam, long &nRet )
+static bool
+ImplHandleGetObject(HWND hWnd, LPARAM lParam, WPARAM wParam, LRESULT & nRet)
 {
     // IA2 should be enabled automatically
     AllSettings aSettings = Application::GetSettings();
@@ -5514,7 +5515,8 @@ static bool ImplHandleGetObject( HWND hWnd, LPARAM lParam, WPARAM wParam, long &
         // mhOnSetTitleWnd not set to reasonable value anywhere...
         if ( lParam == OBJID_CLIENT )
         {
-            nRet = xMSAA->getAccObjectPtr( (long)hWnd, lParam, wParam );
+            nRet = xMSAA->getAccObjectPtr(
+                    reinterpret_cast<sal_Int64>(hWnd), lParam, wParam);
             if( nRet != 0 )
                 return true;
         }
@@ -6053,12 +6055,12 @@ LRESULT CALLBACK SalFrameWndProc( HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lP
             break;
 
         case WM_GETOBJECT:
-            long nRet;
+            ImplSalYieldMutexAcquireWithWait();
             if ( ImplHandleGetObject( hWnd, lParam, wParam, nRet ) )
             {
                 rDef = false;
-                return (HRESULT) nRet;
             }
+            ImplSalYieldMutexRelease();
             break;
 
         case WM_APPCOMMAND:


More information about the Libreoffice-commits mailing list