summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2018-03-27 12:30:45 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2018-03-28 14:15:51 +0200
commit1b1839d325014c6607cc1e2410b98839602ee2b2 (patch)
tree60fd27981924008b51cdc61bc63ebe417e0843c1
parent04151aeb553ac65de3530dab83353f47052b6608 (diff)
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@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
-rw-r--r--fpicker/source/win32/folderpicker/MtaFop.cxx122
1 files changed, 44 insertions, 78 deletions
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;
}