comparison src/winclip.c @ 15957:209f65bb155f v8.1.0984

patch 8.1.0984: unnecessary #ifdefs commit https://github.com/vim/vim/commit/c69efcb42fd98d9fcd5f7e01e3b029b0b777df0f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Feb 27 14:12:01 2019 +0100 patch 8.1.0984: unnecessary #ifdefs Problem: Unnecessary #ifdefs. Solution: Remove the #ifdefs. (Ken Takata)
author Bram Moolenaar <Bram@vim.org>
date Wed, 27 Feb 2019 14:15:11 +0100
parents 7fad90423bd2
children ef00b6bc186b
comparison
equal deleted inserted replaced
15956:1207fa46617e 15957:209f65bb155f
20 /* 20 /*
21 * Compile only the clipboard handling features when compiling for cygwin 21 * Compile only the clipboard handling features when compiling for cygwin
22 * posix environment. 22 * posix environment.
23 */ 23 */
24 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD 24 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD
25 # define MSWIN
26 # define WIN32_LEAN_AND_MEAN 25 # define WIN32_LEAN_AND_MEAN
27 # include <windows.h> 26 # include <windows.h>
28 # include "winclip.pro" 27 # include "winclip.pro"
29 #endif 28 #endif
30 29
297 clip_mch_request_selection(VimClipboard *cbd) 296 clip_mch_request_selection(VimClipboard *cbd)
298 { 297 {
299 VimClipType_t metadata = { -1, -1, -1, -1 }; 298 VimClipType_t metadata = { -1, -1, -1, -1 };
300 HGLOBAL hMem = NULL; 299 HGLOBAL hMem = NULL;
301 char_u *str = NULL; 300 char_u *str = NULL;
302 #if defined(MSWIN)
303 char_u *to_free = NULL; 301 char_u *to_free = NULL;
304 #endif
305 HGLOBAL rawh = NULL; 302 HGLOBAL rawh = NULL;
306 int str_size = 0; 303 int str_size = 0;
307 int maxlen; 304 int maxlen;
308 size_t n; 305 size_t n;
309 306
359 } 356 }
360 } 357 }
361 } 358 }
362 if (str == NULL) 359 if (str == NULL)
363 { 360 {
364 #if defined(MSWIN)
365 /* Try to get the clipboard in Unicode if it's not an empty string. */ 361 /* Try to get the clipboard in Unicode if it's not an empty string. */
366 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0) 362 if (IsClipboardFormatAvailable(CF_UNICODETEXT) && metadata.ucslen != 0)
367 { 363 {
368 HGLOBAL hMemW; 364 HGLOBAL hMemW;
369 365
389 } 385 }
390 to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size); 386 to_free = str = utf16_to_enc((short_u *)hMemWstr, &str_size);
391 GlobalUnlock(hMemW); 387 GlobalUnlock(hMemW);
392 } 388 }
393 } 389 }
394 else 390 /* Get the clipboard in the Active codepage. */
395 #endif 391 else if (IsClipboardFormatAvailable(CF_TEXT))
396 /* Get the clipboard in the Active codepage. */
397 if (IsClipboardFormatAvailable(CF_TEXT))
398 { 392 {
399 if ((hMem = GetClipboardData(CF_TEXT)) != NULL) 393 if ((hMem = GetClipboardData(CF_TEXT)) != NULL)
400 { 394 {
401 str = (char_u *)GlobalLock(hMem); 395 str = (char_u *)GlobalLock(hMem);
402 396
415 for (str_size = 0; str_size < maxlen; ++str_size) 409 for (str_size = 0; str_size < maxlen; ++str_size)
416 if (str[str_size] == NUL) 410 if (str[str_size] == NUL)
417 break; 411 break;
418 } 412 }
419 413
420 #if defined(MSWIN)
421 /* The text is in the active codepage. Convert to 414 /* The text is in the active codepage. Convert to
422 * 'encoding', going through UTF-16. */ 415 * 'encoding', going through UTF-16. */
423 acp_to_enc(str, str_size, &to_free, &maxlen); 416 acp_to_enc(str, str_size, &to_free, &maxlen);
424 if (to_free != NULL) 417 if (to_free != NULL)
425 { 418 {
426 str_size = maxlen; 419 str_size = maxlen;
427 str = to_free; 420 str = to_free;
428 } 421 }
429 #endif
430 } 422 }
431 } 423 }
432 } 424 }
433 425
434 if (str != NULL && *str != NUL) 426 if (str != NULL && *str != NUL)
452 if (hMem != NULL) 444 if (hMem != NULL)
453 GlobalUnlock(hMem); 445 GlobalUnlock(hMem);
454 if (rawh != NULL) 446 if (rawh != NULL)
455 GlobalUnlock(rawh); 447 GlobalUnlock(rawh);
456 CloseClipboard(); 448 CloseClipboard();
457 #if defined(MSWIN)
458 vim_free(to_free); 449 vim_free(to_free);
459 #endif
460 } 450 }
461 451
462 /* 452 /*
463 * Send the current selection to the clipboard. 453 * Send the current selection to the clipboard.
464 */ 454 */
469 VimClipType_t metadata; 459 VimClipType_t metadata;
470 long_u txtlen; 460 long_u txtlen;
471 HGLOBAL hMemRaw = NULL; 461 HGLOBAL hMemRaw = NULL;
472 HGLOBAL hMem = NULL; 462 HGLOBAL hMem = NULL;
473 HGLOBAL hMemVim = NULL; 463 HGLOBAL hMemVim = NULL;
474 # if defined(MSWIN)
475 HGLOBAL hMemW = NULL; 464 HGLOBAL hMemW = NULL;
476 # endif
477 465
478 /* If the '*' register isn't already filled in, fill it in now */ 466 /* If the '*' register isn't already filled in, fill it in now */
479 cbd->owned = TRUE; 467 cbd->owned = TRUE;
480 clip_get_selection(cbd); 468 clip_get_selection(cbd);
481 cbd->owned = FALSE; 469 cbd->owned = FALSE;
506 } 494 }
507 else 495 else
508 metadata.rawlen = 0; 496 metadata.rawlen = 0;
509 } 497 }
510 498
511 # if defined(MSWIN)
512 { 499 {
513 WCHAR *out; 500 WCHAR *out;
514 int len = metadata.txtlen; 501 int len = metadata.txtlen;
515 502
516 /* Convert the text to UTF-16. This is put on the clipboard as 503 /* Convert the text to UTF-16. This is put on the clipboard as
548 } 535 }
549 vim_free(out); 536 vim_free(out);
550 metadata.ucslen = len; 537 metadata.ucslen = len;
551 } 538 }
552 } 539 }
553 # endif
554 540
555 /* Allocate memory for the text, add one NUL byte to terminate the string. 541 /* Allocate memory for the text, add one NUL byte to terminate the string.
556 */ 542 */
557 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1); 543 hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1);
558 { 544 {
588 { 574 {
589 if (EmptyClipboard()) 575 if (EmptyClipboard())
590 { 576 {
591 SetClipboardData(cbd->format, hMemVim); 577 SetClipboardData(cbd->format, hMemVim);
592 hMemVim = 0; 578 hMemVim = 0;
593 # if defined(MSWIN)
594 if (hMemW != NULL) 579 if (hMemW != NULL)
595 { 580 {
596 if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL) 581 if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL)
597 hMemW = NULL; 582 hMemW = NULL;
598 } 583 }
599 # endif
600 /* Always use CF_TEXT. On Win98 Notepad won't obtain the 584 /* Always use CF_TEXT. On Win98 Notepad won't obtain the
601 * CF_UNICODETEXT text, only CF_TEXT. */ 585 * CF_UNICODETEXT text, only CF_TEXT. */
602 SetClipboardData(CF_TEXT, hMem); 586 SetClipboardData(CF_TEXT, hMem);
603 hMem = 0; 587 hMem = 0;
604 } 588 }
609 /* Free any allocations we didn't give to the clipboard: */ 593 /* Free any allocations we didn't give to the clipboard: */
610 if (hMemRaw) 594 if (hMemRaw)
611 GlobalFree(hMemRaw); 595 GlobalFree(hMemRaw);
612 if (hMem) 596 if (hMem)
613 GlobalFree(hMem); 597 GlobalFree(hMem);
614 # if defined(MSWIN)
615 if (hMemW) 598 if (hMemW)
616 GlobalFree(hMemW); 599 GlobalFree(hMemW);
617 # endif
618 if (hMemVim) 600 if (hMemVim)
619 GlobalFree(hMemVim); 601 GlobalFree(hMemVim);
620 } 602 }
621 603
622 #endif /* FEAT_CLIPBOARD */ 604 #endif /* FEAT_CLIPBOARD */
744 } 726 }
745 727
746 return enc_str; 728 return enc_str;
747 } 729 }
748 730
749 #if defined(MSWIN) || defined(PROTO)
750 /* 731 /*
751 * Convert from the active codepage to 'encoding'. 732 * Convert from the active codepage to 'encoding'.
752 * Input is "str[str_size]". 733 * Input is "str[str_size]".
753 * The result is in allocated memory: "out[outlen]". With terminating NUL. 734 * The result is in allocated memory: "out[outlen]". With terminating NUL.
754 */ 735 */
794 WideCharToMultiByte_alloc(GetACP(), 0, widestr, len, 775 WideCharToMultiByte_alloc(GetACP(), 0, widestr, len,
795 (LPSTR *)out, outlen, 0, 0); 776 (LPSTR *)out, outlen, 0, 0);
796 vim_free(widestr); 777 vim_free(widestr);
797 } 778 }
798 } 779 }
799 #endif