diff options
author | Neil <nyamatongwe@gmail.com> | 2016-02-23 11:17:05 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2016-02-23 11:17:05 +1100 |
commit | 92b6a5aa31c305a9ad5c7abb50d4384a5205336c (patch) | |
tree | 47277b9ffcbb073b828b49f3cdef08ffdc257cd1 /win32 | |
parent | b7a58f9c9c4067714b2118c2ee96e0867d0c0190 (diff) | |
download | scintilla-mirror-92b6a5aa31c305a9ad5c7abb50d4384a5205336c.tar.gz |
Retry OpenClipboard if it fails as another application may have opened it.
Diffstat (limited to 'win32')
-rw-r--r-- | win32/ScintillaWin.cxx | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index c9a712df2..2e9cce34a 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -2184,9 +2184,25 @@ public: } }; +// OpenClipboard may fail if another application has opened the clipboard. +// Try up to 8 times, with an initial delay of 1 ms and an exponential back off +// for a maximum total delay of 127 ms (1+2+4+8+16+32+64). +static bool OpenClipboardRetry(HWND hwnd) { + for (int attempt=0; attempt<8; attempt++) { + if (attempt > 0) { + ::Sleep(1 << (attempt-1)); + } + if (::OpenClipboard(hwnd)) { + return true; + } + } + return false; +} + void ScintillaWin::Paste() { - if (!::OpenClipboard(MainHWND())) + if (!::OpenClipboardRetry(MainHWND())) { return; + } UndoGroup ug(pdoc); const bool isLine = SelectionEmpty() && (::IsClipboardFormatAvailable(cfLineSelect) || ::IsClipboardFormatAvailable(cfVSLineTag)); @@ -2737,8 +2753,9 @@ void ScintillaWin::GetIntelliMouseParameters() { } void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) { - if (!::OpenClipboard(MainHWND())) + if (!::OpenClipboardRetry(MainHWND())) { return; + } ::EmptyClipboard(); GlobalMemory uniText; |