comparison src/gui_w48.c @ 1443:69bcc0c891d7 v7.1.158

updated for version 7.1-158
author vimboss
date Tue, 20 Nov 2007 16:22:16 +0000
parents 0e6b369b9760
children 159d87361e4b
comparison
equal deleted inserted replaced
1442:bce7c73fd56d 1443:69bcc0c891d7
484 dead_key = 1; 484 dead_key = 1;
485 } 485 }
486 486
487 /* 487 /*
488 * Convert Unicode character "ch" to bytes in "string[slen]". 488 * Convert Unicode character "ch" to bytes in "string[slen]".
489 * When "had_alt" is TRUE the ALT key was included in "ch".
489 * Return the length. 490 * Return the length.
490 */ 491 */
491 static int 492 static int
492 char_to_string(int ch, char_u *string, int slen) 493 char_to_string(int ch, char_u *string, int slen, int had_alt)
493 { 494 {
494 int len; 495 int len;
495 int i; 496 int i;
496 #ifdef FEAT_MBYTE 497 #ifdef FEAT_MBYTE
497 WCHAR wstring[2]; 498 WCHAR wstring[2];
520 { 521 {
521 /* "ch" is a UTF-16 character. Convert it to a string of bytes. When 522 /* "ch" is a UTF-16 character. Convert it to a string of bytes. When
522 * "enc_codepage" is non-zero use the standard Win32 function, 523 * "enc_codepage" is non-zero use the standard Win32 function,
523 * otherwise use our own conversion function (e.g., for UTF-8). */ 524 * otherwise use our own conversion function (e.g., for UTF-8). */
524 if (enc_codepage > 0) 525 if (enc_codepage > 0)
526 {
525 len = WideCharToMultiByte(enc_codepage, 0, wstring, len, 527 len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
526 string, slen, 0, NULL); 528 string, slen, 0, NULL);
529 /* If we had included the ALT key into the character but now the
530 * upper bit is no longer set, that probably means the conversion
531 * failed. Convert the original character and set the upper bit
532 * afterwards. */
533 if (had_alt && len == 1 && ch >= 0x80 && string[0] < 0x80)
534 {
535 wstring[0] = ch & 0x7f;
536 len = WideCharToMultiByte(enc_codepage, 0, wstring, len,
537 string, slen, 0, NULL);
538 if (len == 1) /* safety check */
539 string[0] |= 0x80;
540 }
541 }
527 else 542 else
528 { 543 {
529 len = 1; 544 len = 1;
530 ws = ucs2_to_enc(wstring, &len); 545 ws = ucs2_to_enc(wstring, &len);
531 if (ws == NULL) 546 if (ws == NULL)
571 int cRepeat) 586 int cRepeat)
572 { 587 {
573 char_u string[40]; 588 char_u string[40];
574 int len = 0; 589 int len = 0;
575 590
576 len = char_to_string(ch, string, 40); 591 len = char_to_string(ch, string, 40, FALSE);
577 if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts) 592 if (len == 1 && string[0] == Ctrl_C && ctrl_c_interrupts)
578 { 593 {
579 trash_input_buf(); 594 trash_input_buf();
580 got_int = TRUE; 595 got_int = TRUE;
581 } 596 }
638 } 653 }
639 else 654 else
640 { 655 {
641 /* Although the documentation isn't clear about it, we assume "ch" is 656 /* Although the documentation isn't clear about it, we assume "ch" is
642 * a Unicode character. */ 657 * a Unicode character. */
643 len += char_to_string(ch, string + len, 40 - len); 658 len += char_to_string(ch, string + len, 40 - len, TRUE);
644 } 659 }
645 660
646 add_to_input_buf(string, len); 661 add_to_input_buf(string, len);
647 } 662 }
648 663
1773 else 1788 else
1774 { 1789 {
1775 int len; 1790 int len;
1776 1791
1777 /* Handle "key" as a Unicode character. */ 1792 /* Handle "key" as a Unicode character. */
1778 len = char_to_string(key, string, 40); 1793 len = char_to_string(key, string, 40, FALSE);
1779 add_to_input_buf(string, len); 1794 add_to_input_buf(string, len);
1780 } 1795 }
1781 break; 1796 break;
1782 } 1797 }
1783 } 1798 }