Blame SOURCES/7.4.137

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