Bug 482797, 482739. A few fixes for Windows Mobile Software Keyboard handling. r=blassey, sr=vlad
authorDoug Turner <dougt@meer.net>
Mon, 23 Mar 2009 18:10:36 -0700
changeset 24833 894d3286f108e9d36a9caf7f37dafbc0ee9bc1d7
parent 24832 e9032baaad921e8c8061fd55d0945ebea870f6f6
child 24834 59ebaed79dc6022d44c825b1d4dbb9e45028192e
push id1245
push userdgottwald@mozilla.com
push dateFri, 17 Apr 2009 08:02:57 +0000
reviewersblassey, vlad
bugs482797, 482739
milestone1.9.1b4pre
Bug 482797, 482739. A few fixes for Windows Mobile Software Keyboard handling. r=blassey, sr=vlad
widget/src/windows/nsWindow.cpp
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -167,33 +167,46 @@
 
 /*
  * WinCE helpers
  */
 #ifdef WINCE
 
 #ifdef WINCE_HAVE_SOFTKB
 static PRBool gSoftKeyMenuBar = PR_FALSE;
+static PRBool gSoftKeyboardState = PR_FALSE;
+
+static void ToggleSoftKB(PRBool show)
+{
+  HWND hWndSIP = FindWindowW(L"SipWndClass", NULL );
+  if (hWndSIP)
+    ::ShowWindow(hWndSIP, show ? SW_SHOW: SW_HIDE);
+
+  hWndSIP = FindWindowW(L"MS_SIPBUTTON", NULL ); 
+  if (hWndSIP)
+    ShowWindow(hWndSIP, show ? SW_SHOW: SW_HIDE);
+
+  SHSipPreference(NULL, show ? SIP_UP: SIP_DOWN);
+}
 
 static void CreateSoftKeyMenuBar(HWND wnd)
 {
   if (!wnd)
     return;
   
   static HWND gSoftKeyMenuBar = nsnull;
   
   if (gSoftKeyMenuBar != nsnull)
     return;
   
   SHMENUBARINFO mbi;
   ZeroMemory(&mbi, sizeof(SHMENUBARINFO));
   mbi.cbSize = sizeof(SHMENUBARINFO);
   mbi.hwndParent = wnd;
   
-  
   //  On windows ce smartphone, events never occur if the
   //  menubar is empty.  This doesn't work: 
   //  mbi.dwFlags = SHCMBF_EMPTYBAR;
   
   mbi.nToolBarId = IDC_DUMMY_CE_MENUBAR;
   mbi.hInstRes   = GetModuleHandle(NULL);
   
   if (!SHCreateMenuBar(&mbi))
@@ -4762,23 +4775,30 @@ PRBool nsWindow::ProcessMessage(UINT msg
 
       result = PR_TRUE;
       break;
 
     case WM_ACTIVATE:
       if (mEventCallback) {
         PRInt32 fActive = LOWORD(wParam);
 
+#if defined(WINCE_HAVE_SOFTKB)
+        if (mIsTopWidgetWindow && gSoftKeyboardState)
+          ToggleSoftKB(fActive);
+#endif
+
         if (WA_INACTIVE == fActive) {
           gJustGotDeactivate = PR_TRUE;
 #ifndef WINCE
           if (mIsTopWidgetWindow)
             mLastKeyboardLayout = gKbdLayout.GetLayout();
 #endif
+
         } else {
+
           gJustGotActivate = PR_TRUE;
           nsMouseEvent event(PR_TRUE, NS_MOUSE_ACTIVATE, this,
                              nsMouseEvent::eReal);
           InitEvent(event);
 
           event.acceptActivation = PR_TRUE;
   
           PRBool result = DispatchWindowEvent(&event);
@@ -4855,17 +4875,16 @@ PRBool nsWindow::ProcessMessage(UINT msg
 #endif
       break;
 
     case WM_KILLFOCUS:
 #if defined(WINCE_HAVE_SOFTKB)
       {
         HIMC hC = ImmGetContext(mWnd);
         ImmSetOpenStatus(hC, FALSE);
-        SetIMEEnabled(nsIWidget::IME_STATUS_DISABLED);        
       }
 #endif
       WCHAR className[kMaxClassNameLength];
       ::GetClassNameW((HWND)wParam, className, kMaxClassNameLength);
       if (wcscmp(className, kWClassNameUI) &&
           wcscmp(className, kWClassNameContent) &&
           wcscmp(className, kWClassNameContentFrame) &&
           wcscmp(className, kWClassNameDialog) &&
@@ -7771,25 +7790,18 @@ NS_IMETHODIMP nsWindow::SetIMEEnabled(PR
 #endif 
   if (sIMEIsComposing)
     ResetInputState();
   mIMEEnabled = aState;
   PRBool enable = (aState == nsIWidget::IME_STATUS_ENABLED ||
                    aState == nsIWidget::IME_STATUS_PLUGIN);
 
 #if defined(WINCE_HAVE_SOFTKB)
-  HWND hWndSIP = FindWindowW(L"SipWndClass", NULL );
-  if (hWndSIP)
-    ::ShowWindow( hWndSIP, enable? SW_SHOW: SW_HIDE);
-
-  hWndSIP = FindWindowW(L"MS_SIPBUTTON", NULL );  
-  if (hWndSIP)
-    ShowWindow(hWndSIP, enable? SW_SHOW: SW_HIDE); 
-  
-  SHSipPreference(NULL, enable? SIP_UP: SIP_DOWN);
+  gSoftKeyboardState = (aState != nsIWidget::IME_STATUS_DISABLED);
+  ToggleSoftKB(gSoftKeyboardState);
 #endif
 
   if (!enable != !mOldIMC)
     return NS_OK;
   mOldIMC = ::ImmAssociateContext(mWnd, enable ? mOldIMC : NULL);
   NS_ASSERTION(!enable || !mOldIMC, "Another IMC was associated");
 
   return NS_OK;