| 395 | } |
| 396 | |
| 397 | void Clipboard_GetText(cc_string* value) { |
| 398 | HWND hwnd = Window_Main.Handle.ptr; |
| 399 | cc_bool unicode; |
| 400 | HANDLE hGlobal; |
| 401 | SIZE_T size; |
| 402 | void* src; |
| 403 | int i; |
| 404 | |
| 405 | /* retry up to 50 times */ |
| 406 | for (i = 0; i < 50; i++) { |
| 407 | if (!OpenClipboard(hwnd)) { |
| 408 | Thread_Sleep(10); |
| 409 | continue; |
| 410 | } |
| 411 | |
| 412 | unicode = true; |
| 413 | hGlobal = GetClipboardData(CF_UNICODETEXT); |
| 414 | if (!hGlobal) { |
| 415 | hGlobal = GetClipboardData(CF_TEXT); |
| 416 | unicode = false; |
| 417 | } |
| 418 | |
| 419 | if (!hGlobal) { CloseClipboard(); return; } |
| 420 | src = GlobalLock(hGlobal); |
| 421 | size = GlobalSize(hGlobal); |
| 422 | |
| 423 | /* ignore trailing NULL at end */ |
| 424 | /* TODO: Verify it's always there */ |
| 425 | if (unicode) { |
| 426 | String_AppendUtf16(value, src, size - 2); |
| 427 | } else { |
| 428 | String_AppendCP1252(value, src, size - 1); |
| 429 | } |
| 430 | |
| 431 | GlobalUnlock(hGlobal); |
| 432 | CloseClipboard(); |
| 433 | return; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | void Clipboard_SetText(const cc_string* value) { |
| 438 | HWND hwnd = Window_Main.Handle.ptr; |
nothing calls this directly
no test coverage detected