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