[Libreoffice-commits] core.git: fpicker/source

Jan-Marek Glogowski glogow at fbihome.de
Wed Mar 28 12:16:15 UTC 2018


 fpicker/source/win32/folderpicker/MtaFop.cxx |  122 +++++++++------------------
 1 file changed, 44 insertions(+), 78 deletions(-)

New commits:
commit 1b1839d325014c6607cc1e2410b98839602ee2b2
Author: Jan-Marek Glogowski <glogow at fbihome.de>
Date:   Tue Mar 27 12:30:45 2018 +0200

    tdf#116615 WIN process messages using Reschedule
    
    Since LO message processing loop is a little more complex then
    PeekMessageW and DispatchMessageW, use Reschedule( true ) to
    process all pending events. Processing all event is important,
    because MsgWaitForMultipleObjects will just trigger for new
    messages since its call and will ignore already pending
    messages.
    
    Which leaves the IsMTA() call. I know of the COM STA / MTA
    stuff, but I don't understand how this might be related here.
    The call to SHBrowseForFolderW definitly block, but we already
    use multiple threads, so I don't understand, how this has
    worked before...
    
    Change-Id: Id348f26155571b3ddb31233d0bcd2c4fd2003819
    Reviewed-on: https://gerrit.libreoffice.org/51940
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/fpicker/source/win32/folderpicker/MtaFop.cxx b/fpicker/source/win32/folderpicker/MtaFop.cxx
index 6f8af44c358a..ba951039edeb 100644
--- a/fpicker/source/win32/folderpicker/MtaFop.cxx
+++ b/fpicker/source/win32/folderpicker/MtaFop.cxx
@@ -20,6 +20,7 @@
 #include <osl/diagnose.h>
 #include <osl/thread.h>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <vcl/svapp.hxx>
 
 #include "MtaFop.hxx"
 #include <wchar.h>
@@ -70,23 +71,6 @@ namespace
         OSL_ASSERT( aRequestContext && aRequestContext->hEvent );
         CloseHandle( aRequestContext->hEvent );
     }
-
-
-    // Determine if current thread is
-    // an MTA or STA thread
-
-    bool IsMTA()
-    {
-        HRESULT hr = CoInitialize(nullptr);
-
-        if (RPC_E_CHANGED_MODE == hr)
-            return true;
-
-        if(SUCCEEDED(hr))
-            CoUninitialize();
-
-        return false;
-    }
 }
 
 
@@ -224,80 +208,62 @@ bool CMtaFolderPicker::browseForFolder( )
 {
     bool bRet = false;
 
-    if (IsMTA())
-    {
+    OSL_ASSERT( m_hEvtThrdReady );
 
-        OSL_ASSERT( m_hEvtThrdReady );
+    if ( WaitForSingleObject( m_hEvtThrdReady, MAX_WAITTIME ) != WAIT_OBJECT_0 )
+    {
+        OSL_FAIL( "sta thread not ready" );
+        return false;
+    }
 
-        if ( WaitForSingleObject( m_hEvtThrdReady, MAX_WAITTIME ) != WAIT_OBJECT_0 )
-        {
-            OSL_FAIL( "sta thread not ready" );
-            return false;
-        }
+    RequestContext aReqCtx;
 
-        RequestContext aReqCtx;
+    if ( !InitializeRequestContext( &aReqCtx ) )
+    {
+        OSL_ASSERT( false );
+        return false;
+    }
 
-        if ( !InitializeRequestContext( &aReqCtx ) )
-        {
-            OSL_ASSERT( false );
-            return false;
-        }
+    // marshall request into the sta thread
+    BOOL const ret = PostMessageW(
+        m_hwndStaRequestWnd,
+        MSG_BROWSEFORFOLDER,
+        0,
+        reinterpret_cast< LPARAM >( &aReqCtx ) );
+    SAL_WARN_IF(0 == ret, "fpicker", "ERROR: PostMessage() failed!");
 
-        // marshall request into the sta thread
-        BOOL const ret = PostMessageW(
-            m_hwndStaRequestWnd,
-            MSG_BROWSEFORFOLDER,
-            0,
-            reinterpret_cast< LPARAM >( &aReqCtx ) );
-        SAL_WARN_IF(0 == ret, "fpicker", "ERROR: PostMessage() failed!");
+    // waiting for the event to be signaled or
+    // window messages so that we don't block
+    // our parent window
 
-        // waiting for the event to be signaled or
-        // window messages so that we don't block
-        // our parent window
+    bool bContinue = true;
 
-        bool bContinue = true;
+    while ( bContinue )
+    {
+        DWORD dwResult = MsgWaitForMultipleObjects(
+            1, &aReqCtx.hEvent, false, INFINITE, QS_ALLEVENTS );
 
-        while ( bContinue )
+        switch ( dwResult )
         {
-            DWORD dwResult = MsgWaitForMultipleObjects(
-                1, &aReqCtx.hEvent, false, INFINITE, QS_ALLEVENTS );
+        // the request context event is signaled
+        case WAIT_OBJECT_0:
+            bContinue = false;
+            break;
 
-            switch ( dwResult )
-            {
-            // the request context event is signaled
-            case WAIT_OBJECT_0:
-                bContinue = false;
-                break;
-
-            // a window message has arrived
-            case WAIT_OBJECT_0 + 1:
-                {
-                    // dispatching all messages but we expect to
-                    // receive only paint or timer messages that's
-                    // why we don't need to call TranslateMessage or
-                    // TranslateAccelerator, because keyboard or
-                    // mouse messages are for the FolderPicker which
-                    // is in the foreground and should not arrive here
-                    MSG msg;
-                    while ( PeekMessageW( &msg, nullptr, 0, 0, PM_REMOVE ) )
-                        DispatchMessageW(&msg);
-                }
-                break;
-
-            // should not happen
-            default:
-                OSL_ASSERT( false );
-            }
-        }
+        // a window message has arrived
+        case WAIT_OBJECT_0 + 1:
+            Application::Reschedule( true );
+            break;
 
-        /*sal_Bool*/ bRet = aReqCtx.bRet;
-        DeinitializeRequestContext( &aReqCtx );
-    }
-    else
-    {
-        bRet = onBrowseForFolder();
+        // should not happen
+        default:
+            OSL_ASSERT( false );
+        }
     }
 
+    /*sal_Bool*/ bRet = aReqCtx.bRet;
+    DeinitializeRequestContext( &aReqCtx );
+
     return bRet;
 }
 


More information about the Libreoffice-commits mailing list