8b9a1c
To: vim_dev@googlegroups.com
8b9a1c
Subject: Patch 7.4.137
8b9a1c
Fcc: outbox
8b9a1c
From: Bram Moolenaar <Bram@moolenaar.net>
8b9a1c
Mime-Version: 1.0
8b9a1c
Content-Type: text/plain; charset=UTF-8
8b9a1c
Content-Transfer-Encoding: 8bit
8b9a1c
------------
8b9a1c
8b9a1c
Patch 7.4.137
8b9a1c
Problem:    Cannot use IME with Windows 8 console.
8b9a1c
Solution:   Change the user of ReadConsoleInput() and PeekConsoleInput().
8b9a1c
	    (Nobuhiro Takasaki)
8b9a1c
Files:	    src/os_win32.c
8b9a1c
8b9a1c
8b9a1c
*** ../vim-7.4.136/src/os_win32.c	2014-01-10 13:05:12.000000000 +0100
8b9a1c
--- src/os_win32.c	2014-01-10 13:42:19.000000000 +0100
8b9a1c
***************
8b9a1c
*** 232,237 ****
8b9a1c
--- 232,306 ----
8b9a1c
  
8b9a1c
  static char_u *exe_path = NULL;
8b9a1c
  
8b9a1c
+ /*
8b9a1c
+  * Version of ReadConsoleInput() that works with IME.
8b9a1c
+  */
8b9a1c
+     static BOOL
8b9a1c
+ read_console_input(
8b9a1c
+     HANDLE hConsoleInput,
8b9a1c
+     PINPUT_RECORD lpBuffer,
8b9a1c
+     DWORD nLength,
8b9a1c
+     LPDWORD lpNumberOfEventsRead)
8b9a1c
+ {
8b9a1c
+     enum
8b9a1c
+     {
8b9a1c
+ 	IRSIZE = 10, /* rough value */
8b9a1c
+     };
8b9a1c
+     static INPUT_RECORD irCache[IRSIZE];
8b9a1c
+     static DWORD s_dwIndex = 0;
8b9a1c
+     static DWORD s_dwMax = 0;
8b9a1c
+ 
8b9a1c
+     if (hConsoleInput == NULL || lpBuffer == NULL)
8b9a1c
+ 	return ReadConsoleInput(hConsoleInput, lpBuffer, nLength,
8b9a1c
+ 							lpNumberOfEventsRead);
8b9a1c
+ 
8b9a1c
+     if (nLength == -1)
8b9a1c
+     {
8b9a1c
+ 	if (s_dwMax == 0)
8b9a1c
+ 	{
8b9a1c
+ 	    PeekConsoleInput(hConsoleInput, lpBuffer, 1, lpNumberOfEventsRead);
8b9a1c
+ 	    if (*lpNumberOfEventsRead == 0)
8b9a1c
+ 		return FALSE;
8b9a1c
+ 	    ReadConsoleInput(hConsoleInput, irCache, IRSIZE, &s_dwMax);
8b9a1c
+ 	    s_dwIndex = 0;
8b9a1c
+ 	}
8b9a1c
+ 	((PINPUT_RECORD)lpBuffer)[0] = irCache[s_dwIndex];
8b9a1c
+ 	*lpNumberOfEventsRead = 1;
8b9a1c
+ 	return TRUE;
8b9a1c
+     }
8b9a1c
+ 
8b9a1c
+     if (s_dwMax == 0)
8b9a1c
+     {
8b9a1c
+ 	ReadConsoleInput(hConsoleInput, irCache, IRSIZE, &s_dwMax);
8b9a1c
+ 	s_dwIndex = 0;
8b9a1c
+ 	if (s_dwMax == 0)
8b9a1c
+ 	{
8b9a1c
+ 	    *lpNumberOfEventsRead = 0;
8b9a1c
+ 	    return FALSE;
8b9a1c
+ 	}
8b9a1c
+     }
8b9a1c
+ 
8b9a1c
+     ((PINPUT_RECORD)lpBuffer)[0] = irCache[s_dwIndex];
8b9a1c
+     if (++s_dwIndex == s_dwMax)
8b9a1c
+ 	s_dwMax = 0;
8b9a1c
+     *lpNumberOfEventsRead = 1;
8b9a1c
+     return TRUE;
8b9a1c
+ }
8b9a1c
+ 
8b9a1c
+ /*
8b9a1c
+  * Version of PeekConsoleInput() that works with IME.
8b9a1c
+  */
8b9a1c
+     static BOOL
8b9a1c
+ peek_console_input(
8b9a1c
+     HANDLE hConsoleInput,
8b9a1c
+     PINPUT_RECORD lpBuffer,
8b9a1c
+     DWORD nLength,
8b9a1c
+     LPDWORD lpNumberOfEventsRead)
8b9a1c
+ {
8b9a1c
+     return read_console_input(hConsoleInput, lpBuffer, -1,
8b9a1c
+ 							lpNumberOfEventsRead);
8b9a1c
+ }
8b9a1c
+ 
8b9a1c
      static void
8b9a1c
  get_exe_name(void)
8b9a1c
  {
8b9a1c
***************
8b9a1c
*** 1117,1123 ****
8b9a1c
  			INPUT_RECORD ir;
8b9a1c
  			MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent;
8b9a1c
  
8b9a1c
! 			PeekConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  			if (cRecords == 0 || ir.EventType != MOUSE_EVENT
8b9a1c
  				|| !(pmer2->dwButtonState & LEFT_RIGHT))
8b9a1c
--- 1186,1192 ----
8b9a1c
  			INPUT_RECORD ir;
8b9a1c
  			MOUSE_EVENT_RECORD* pmer2 = &ir.Event.MouseEvent;
8b9a1c
  
8b9a1c
! 			peek_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  			if (cRecords == 0 || ir.EventType != MOUSE_EVENT
8b9a1c
  				|| !(pmer2->dwButtonState & LEFT_RIGHT))
8b9a1c
***************
8b9a1c
*** 1126,1132 ****
8b9a1c
  			{
8b9a1c
  			    if (pmer2->dwEventFlags != MOUSE_MOVED)
8b9a1c
  			    {
8b9a1c
! 				ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  				return decode_mouse_event(pmer2);
8b9a1c
  			    }
8b9a1c
--- 1195,1201 ----
8b9a1c
  			{
8b9a1c
  			    if (pmer2->dwEventFlags != MOUSE_MOVED)
8b9a1c
  			    {
8b9a1c
! 				read_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  				return decode_mouse_event(pmer2);
8b9a1c
  			    }
8b9a1c
***************
8b9a1c
*** 1134,1143 ****
8b9a1c
  				     s_yOldMouse == pmer2->dwMousePosition.Y)
8b9a1c
  			    {
8b9a1c
  				/* throw away spurious mouse move */
8b9a1c
! 				ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  				/* are there any more mouse events in queue? */
8b9a1c
! 				PeekConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  				if (cRecords==0 || ir.EventType != MOUSE_EVENT)
8b9a1c
  				    break;
8b9a1c
--- 1203,1212 ----
8b9a1c
  				     s_yOldMouse == pmer2->dwMousePosition.Y)
8b9a1c
  			    {
8b9a1c
  				/* throw away spurious mouse move */
8b9a1c
! 				read_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  				/* are there any more mouse events in queue? */
8b9a1c
! 				peek_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  				if (cRecords==0 || ir.EventType != MOUSE_EVENT)
8b9a1c
  				    break;
8b9a1c
***************
8b9a1c
*** 1374,1380 ****
8b9a1c
  	}
8b9a1c
  
8b9a1c
  	cRecords = 0;
8b9a1c
! 	PeekConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  #ifdef FEAT_MBYTE_IME
8b9a1c
  	if (State & CMDLINE && msg_row == Rows - 1)
8b9a1c
--- 1443,1449 ----
8b9a1c
  	}
8b9a1c
  
8b9a1c
  	cRecords = 0;
8b9a1c
! 	peek_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  #ifdef FEAT_MBYTE_IME
8b9a1c
  	if (State & CMDLINE && msg_row == Rows - 1)
8b9a1c
***************
8b9a1c
*** 1405,1411 ****
8b9a1c
  		if (ir.Event.KeyEvent.uChar.UnicodeChar == 0
8b9a1c
  			&& ir.Event.KeyEvent.wVirtualKeyCode == 13)
8b9a1c
  		{
8b9a1c
! 		    ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  		    continue;
8b9a1c
  		}
8b9a1c
  #endif
8b9a1c
--- 1474,1480 ----
8b9a1c
  		if (ir.Event.KeyEvent.uChar.UnicodeChar == 0
8b9a1c
  			&& ir.Event.KeyEvent.wVirtualKeyCode == 13)
8b9a1c
  		{
8b9a1c
! 		    read_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  		    continue;
8b9a1c
  		}
8b9a1c
  #endif
8b9a1c
***************
8b9a1c
*** 1414,1420 ****
8b9a1c
  		    return TRUE;
8b9a1c
  	    }
8b9a1c
  
8b9a1c
! 	    ReadConsoleInput(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  	    if (ir.EventType == FOCUS_EVENT)
8b9a1c
  		handle_focus_event(ir);
8b9a1c
--- 1483,1489 ----
8b9a1c
  		    return TRUE;
8b9a1c
  	    }
8b9a1c
  
8b9a1c
! 	    read_console_input(g_hConIn, &ir, 1, &cRecords);
8b9a1c
  
8b9a1c
  	    if (ir.EventType == FOCUS_EVENT)
8b9a1c
  		handle_focus_event(ir);
8b9a1c
***************
8b9a1c
*** 1484,1490 ****
8b9a1c
  	    return 0;
8b9a1c
  # endif
8b9a1c
  #endif
8b9a1c
! 	if (ReadConsoleInput(g_hConIn, &ir, 1, &cRecords) == 0)
8b9a1c
  	{
8b9a1c
  	    if (did_create_conin)
8b9a1c
  		read_error_exit();
8b9a1c
--- 1553,1559 ----
8b9a1c
  	    return 0;
8b9a1c
  # endif
8b9a1c
  #endif
8b9a1c
! 	if (read_console_input(g_hConIn, &ir, 1, &cRecords) == 0)
8b9a1c
  	{
8b9a1c
  	    if (did_create_conin)
8b9a1c
  		read_error_exit();
8b9a1c
*** ../vim-7.4.136/src/version.c	2014-01-10 13:05:12.000000000 +0100
8b9a1c
--- src/version.c	2014-01-10 13:42:34.000000000 +0100
8b9a1c
***************
8b9a1c
*** 740,741 ****
8b9a1c
--- 740,743 ----
8b9a1c
  {   /* Add new patch number below this line */
8b9a1c
+ /**/
8b9a1c
+     137,
8b9a1c
  /**/
8b9a1c
8b9a1c
-- 
8b9a1c
hundred-and-one symptoms of being an internet addict:
8b9a1c
131. You challenge authority and society by portnuking people
8b9a1c
8b9a1c
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
8b9a1c
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
8b9a1c
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
8b9a1c
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///