diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-11-05 18:23:40 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-11-05 19:30:16 +0100 |
commit | a30dbe34a14906933cfd47e29a4df69a628ab517 (patch) | |
tree | a4bbb20ffa1db24a7d85f4a0b1b98f8416387ec0 /dtrans/source | |
parent | 994cf675adac2e9afb48b49b38a36658b3115204 (diff) |
Win: implement Clipboard Format Listener instead of obsolete Viewer
https://docs.microsoft.com/en-us/windows/desktop/dataxchg/using-the-clipboard
discusses the techniques to monitor clipboard contents on Windows, and
recommends Clipboard Format Listener for Vista+.
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setclipboardviewer
further mentions that using the current "Clipboard Viewer Window" approach,
"The clipboard viewer chain can be broken by an application that fails to
handle the clipboard chain messages properly".
This change reimplements our listener to use recommended way; this
should make our clipboard handling more robust, avoiding the need to
handle the chain with other applications' windows.
Change-Id: Ib33b27a57d7a6af2ab7e3e59d030aa55329694f9
Reviewed-on: https://gerrit.libreoffice.org/62909
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'dtrans/source')
-rw-r--r-- | dtrans/source/win32/clipb/MtaOleClipb.cxx | 65 | ||||
-rw-r--r-- | dtrans/source/win32/clipb/MtaOleClipb.hxx | 6 |
2 files changed, 10 insertions, 61 deletions
diff --git a/dtrans/source/win32/clipb/MtaOleClipb.cxx b/dtrans/source/win32/clipb/MtaOleClipb.cxx index 79983edd5b16..d935713b8e43 100644 --- a/dtrans/source/win32/clipb/MtaOleClipb.cxx +++ b/dtrans/source/win32/clipb/MtaOleClipb.cxx @@ -161,7 +161,6 @@ CMtaOleClipboard::CMtaOleClipboard( ) : m_hEvtThrdReady( nullptr ), m_hwndMtaOleReqWnd( nullptr ), m_MtaOleReqWndClassAtom( 0 ), - m_hwndNextClipViewer( nullptr ), m_pfncClipViewerCallback( nullptr ), m_bRunClipboardNotifierThread( true ), m_hClipboardChangedEvent( m_hClipboardChangedNotifierEvents[0] ), @@ -238,8 +237,7 @@ CMtaOleClipboard::~CMtaOleClipboard( ) if ( m_MtaOleReqWndClassAtom ) UnregisterClassW( g_szWndClsName, nullptr ); - OSL_ENSURE( ( nullptr == m_pfncClipViewerCallback ) && - !IsWindow( m_hwndNextClipViewer ), + OSL_ENSURE( ( nullptr == m_pfncClipViewerCallback ), "Clipboard viewer not properly unregistered" ); } @@ -354,7 +352,7 @@ bool CMtaOleClipboard::registerClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipV bool CMtaOleClipboard::onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback ) { - bool bRet = true; + bool bRet = false; // we need exclusive access because the clipboard changed notifier // thread also accesses this variable @@ -366,13 +364,9 @@ bool CMtaOleClipboard::onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncCli // SetClipboardViewer sends a WM_DRAWCLIPBOARD message we ignore // this message if we register ourself as clip viewer m_bInRegisterClipViewer = true; - m_hwndNextClipViewer = SetClipboardViewer( m_hwndMtaOleReqWnd ); + bRet = AddClipboardFormatListener(m_hwndMtaOleReqWnd); m_bInRegisterClipViewer = false; - // if there is no other cb-viewer the - // return value is NULL!!! - bRet = IsWindow( m_hwndNextClipViewer ); - // save the new callback function m_pfncClipViewerCallback = pfncClipViewerCallback; } @@ -382,8 +376,7 @@ bool CMtaOleClipboard::onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncCli // unregister if input parameter is NULL and we previously registered // as clipboard viewer - ChangeClipboardChain( m_hwndMtaOleReqWnd, m_hwndNextClipViewer ); - m_hwndNextClipViewer = nullptr; + bRet = RemoveClipboardFormatListener(m_hwndMtaOleReqWnd); } return bRet; @@ -417,32 +410,9 @@ LRESULT CMtaOleClipboard::onFlushClipboard( ) return static_cast<LRESULT>( OleFlushClipboard( ) ); } -// handle clipboard chain change event +// handle clipboard update event -LRESULT CMtaOleClipboard::onChangeCBChain( HWND hWndRemove, HWND hWndNext ) -{ - if ( hWndRemove == m_hwndNextClipViewer ) - m_hwndNextClipViewer = hWndNext; - else if ( IsWindow( m_hwndNextClipViewer ) ) - { - // forward the message to the next one - DWORD_PTR dwpResult; - SendMessageTimeoutW( - m_hwndNextClipViewer, - WM_CHANGECBCHAIN, - reinterpret_cast<WPARAM>(hWndRemove), - reinterpret_cast<LPARAM>(hWndNext), - SMTO_BLOCK, - MAX_CLIPEVENT_PROCESSING_TIME, - &dwpResult ); - } - - return 0; -} - -// handle draw clipboard event - -LRESULT CMtaOleClipboard::onDrawClipboard( ) +LRESULT CMtaOleClipboard::onClipboardUpdate() { // we don't send a notification if we are // registering ourself as clipboard @@ -456,20 +426,6 @@ LRESULT CMtaOleClipboard::onDrawClipboard( ) aGuard.clear( ); } - // forward the message to the next viewer in the chain - if ( IsWindow( m_hwndNextClipViewer ) ) - { - DWORD_PTR dwpResult; - SendMessageTimeoutW( - m_hwndNextClipViewer, - WM_DRAWCLIPBOARD, - static_cast< WPARAM >( 0 ), - static_cast< LPARAM >( 0 ), - SMTO_BLOCK, - MAX_CLIPEVENT_PROCESSING_TIME, - &dwpResult ); - } - return 0; } @@ -543,13 +499,8 @@ LRESULT CALLBACK CMtaOleClipboard::mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARA reinterpret_cast<CMtaOleClipboard::LPFNC_CLIPVIEWER_CALLBACK_t>(wParam)); break; - case WM_CHANGECBCHAIN: - lResult = pImpl->onChangeCBChain( - reinterpret_cast< HWND >( wParam ), reinterpret_cast< HWND >( lParam ) ); - break; - - case WM_DRAWCLIPBOARD: - lResult = pImpl->onDrawClipboard( ); + case WM_CLIPBOARDUPDATE: + lResult = pImpl->onClipboardUpdate(); break; case MSG_SHUTDOWN: diff --git a/dtrans/source/win32/clipb/MtaOleClipb.hxx b/dtrans/source/win32/clipb/MtaOleClipb.hxx index abab29bf9717..fdd00088dbe8 100644 --- a/dtrans/source/win32/clipb/MtaOleClipb.hxx +++ b/dtrans/source/win32/clipb/MtaOleClipb.hxx @@ -72,9 +72,8 @@ private: static LRESULT onFlushClipboard( ); bool onRegisterClipViewer( LPFNC_CLIPVIEWER_CALLBACK_t pfncClipViewerCallback ); - // win32 clipboard-viewer support - LRESULT onChangeCBChain( HWND hWndRemove, HWND hWndNext ); - LRESULT onDrawClipboard( ); + // win32 clipboard listener support + LRESULT onClipboardUpdate(); static LRESULT CALLBACK mtaOleReqWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); static unsigned int WINAPI oleThreadProc( LPVOID pParam ); @@ -89,7 +88,6 @@ private: HANDLE m_hEvtThrdReady; HWND m_hwndMtaOleReqWnd; ATOM m_MtaOleReqWndClassAtom; - HWND m_hwndNextClipViewer; LPFNC_CLIPVIEWER_CALLBACK_t m_pfncClipViewerCallback; bool m_bInRegisterClipViewer; |