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 | e5a27cf16a0144a534ff07905380af5eedbbb76b (patch) | |
tree | e69c721389467400ac1b88d86d67426b82342114 /win32/ScintillaWin.cxx | |
parent | fe0d39ee1c34dfeada9909af44646ce43f0ef226 (diff) | |
download | scintilla-mirror-e5a27cf16a0144a534ff07905380af5eedbbb76b.tar.gz |
Retry OpenClipboard if it fails as another application may have opened it.
Diffstat (limited to 'win32/ScintillaWin.cxx')
-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; |