From a2318373259757ecc23f8971a032b31b10fa488c Mon Sep 17 00:00:00 2001 From: "masayuki%d-toybox.com" Date: Thu, 17 Nov 2005 16:33:57 +0000 Subject: [PATCH] Bug 316638 Sould not use obsoleted API(WINNLSEnableIME) patch by Masatoshi Kimura (emk) r=masayuki+timeless, sr=neil git-svn-id: svn://10.0.0.236/trunk@184821 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/windows/nsToolkit.cpp | 112 +++-------------------- mozilla/widget/src/windows/nsToolkit.h | 45 +++------ mozilla/widget/src/windows/nsWindow.cpp | 35 +++---- mozilla/widget/src/windows/nsWindow.h | 5 +- 4 files changed, 41 insertions(+), 156 deletions(-) diff --git a/mozilla/widget/src/windows/nsToolkit.cpp b/mozilla/widget/src/windows/nsToolkit.cpp index c47df381577..75720ddf4eb 100644 --- a/mozilla/widget/src/windows/nsToolkit.cpp +++ b/mozilla/widget/src/windows/nsToolkit.cpp @@ -1129,6 +1129,11 @@ nsIMM::nsIMM(const char* aModuleName /* = "IMM32.DLL" */) (SetOpenStatusPtr)GetProcAddress(mInstance,"ImmSetOpenStatus"); NS_ASSERTION(mSetOpenStatus != NULL, "nsIMM.ImmSetOpenStatus failed."); + + mAssociateContext = + (AssociateContextPtr)GetProcAddress(mInstance,"ImmAssociateContext"); + NS_ASSERTION(mAssociateContext != NULL, + "nsIMM.ImmAssociateContext failed."); } else { mGetCompositionStringA=NULL; mGetCompositionStringW=NULL; @@ -1142,6 +1147,7 @@ nsIMM::nsIMM(const char* aModuleName /* = "IMM32.DLL" */) mGetDefaultIMEWnd=NULL; mGetOpenStatus=NULL; mSetOpenStatus=NULL; + mAssociateContext=NULL; } #else // WinCE @@ -1159,6 +1165,7 @@ nsIMM::nsIMM(const char* aModuleName /* = "IMM32.DLL" */) mGetDefaultIMEWnd=(GetDefaultIMEWndPtr)ImmGetDefaultIMEWnd; mGetOpenStatus=(GetOpenStatusPtr)ImmGetOpenStatus; mSetOpenStatus=(SetOpenStatusPtr)ImmSetOpenStatus; + mAssociateContext=(AssociateContextPtr)ImmAssociateContext; #endif } @@ -1183,6 +1190,7 @@ nsIMM::~nsIMM() mGetDefaultIMEWnd=NULL; mGetOpenStatus=NULL; mSetOpenStatus=NULL; + mAssociateContext=NULL; } //------------------------------------------------------------------------- @@ -1314,109 +1322,11 @@ nsIMM::SetOpenStatus(HIMC aIMC, BOOL aStatus) //------------------------------------------------------------------------- // -// nsWinNLS class(Native WinNLS wrapper) // //------------------------------------------------------------------------- -nsWinNLS& -nsWinNLS::LoadModule() +HIMC +nsIMM::AssociateContext(HWND aWnd, HIMC aIMC) { - static nsWinNLS gWinNLS; - return gWinNLS; -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -nsWinNLS::nsWinNLS(const char* aModuleName /* = "USER32.DLL" */) -{ -#ifndef WINCE - mInstance=::LoadLibrary(aModuleName); - - if (mInstance) { - mWINNLSEnableIME = - (WINNLSEnableIMEPtr)GetProcAddress(mInstance, "WINNLSEnableIME"); - NS_ASSERTION(mWINNLSEnableIME != NULL, - "nsWinNLS.WINNLSEnableIME failed."); - - mWINNLSGetEnableStatus = - (WINNLSGetEnableStatusPtr)GetProcAddress(mInstance, - "WINNLSGetEnableStatus"); - NS_ASSERTION(mWINNLSGetEnableStatus != NULL, - "nsWinNLS.WINNLSGetEnableStatus failed."); - } else { - mWINNLSEnableIME = NULL; - mWINNLSGetEnableStatus = NULL; - } -#else // WinCE - mInstance = NULL; - - mWINNLSEnableIME = NULL; - mWINNLSGetEnableStatus = NULL; - - // XXX If WINNLSEnableIME and WINNLSGetEnableStatus can be used on WinCE, - // Should use these. - // - // mWINNLSGetEnableStatus = (WINNLSGetEnableStatusPtr)WINNLSGetEnableStatus; -#endif -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -nsWinNLS::~nsWinNLS() -{ - if(mInstance) - ::FreeLibrary(mInstance); - - mWINNLSEnableIME = NULL; - mWINNLSGetEnableStatus = NULL; -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -PRBool -nsWinNLS::SetIMEEnableStatus(HWND aWnd, PRBool aState) -{ - // If mWINNLSEnableIME wasn't loaded, we should return PR_TRUE. - // If we cannot load it, we cannot disable the IME. So, the IME enable state - // is *always* TRUE. - return (mWINNLSEnableIME) ? !!mWINNLSEnableIME(aWnd, aState) : PR_TRUE; -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -PRBool -nsWinNLS::GetIMEEnableStatus(HWND aWnd) -{ - // If mWINNLSGetEnableStatus wasn't loaded, we should return PR_TRUE. - // If we cannot load it, maybe we cannot load mWINNLSEnableIME too. - // So, if mWINNLSEnableIME wasn't loaded, the IME enable state is always TRUE. - return (mWINNLSGetEnableStatus) ? !!mWINNLSGetEnableStatus(aWnd) : PR_TRUE; -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -PRBool -nsWinNLS::CanUseSetIMEEnableStatus() -{ - return (mWINNLSEnableIME) ? PR_TRUE : PR_FALSE; -} - -//------------------------------------------------------------------------- -// -// -//------------------------------------------------------------------------- -PRBool -nsWinNLS::CanUseGetIMEEnableStatus() -{ - return (mWINNLSGetEnableStatus) ? PR_TRUE : PR_FALSE; + return (mAssociateContext) ? mAssociateContext(aWnd, aIMC) : NULL; } diff --git a/mozilla/widget/src/windows/nsToolkit.h b/mozilla/widget/src/windows/nsToolkit.h index bd838b064bb..66d021f15ae 100644 --- a/mozilla/widget/src/windows/nsToolkit.h +++ b/mozilla/widget/src/windows/nsToolkit.h @@ -210,6 +210,7 @@ class nsIMM typedef LONG (CALLBACK *GetDefaultIMEWndPtr) (HWND); typedef BOOL (CALLBACK *GetOpenStatusPtr) (HIMC); typedef BOOL (CALLBACK *SetOpenStatusPtr) (HIMC, BOOL); + typedef HIMC (CALLBACK *AssociateContextPtr) (HWND, HIMC); public: static nsIMM& LoadModule(); @@ -231,6 +232,7 @@ public: LONG GetDefaultIMEWnd(HWND aWnd); BOOL GetOpenStatus(HIMC aIMC); BOOL SetOpenStatus(HIMC aIMC, BOOL aStatus); + HIMC AssociateContext(HWND aWnd, HIMC aIMC); private: HINSTANCE mInstance; @@ -246,36 +248,7 @@ private: GetDefaultIMEWndPtr mGetDefaultIMEWnd; GetOpenStatusPtr mGetOpenStatus; SetOpenStatusPtr mSetOpenStatus; -}; - -//------------------------------------------------------------------------- -// -// Native WinNLS wrapper -// -//------------------------------------------------------------------------- -class nsWinNLS -{ - //prototypes for DLL function calls... - typedef LONG (CALLBACK *WINNLSEnableIMEPtr) (HWND, BOOL); - typedef LONG (CALLBACK *WINNLSGetEnableStatusPtr) (HWND); -public: - - static nsWinNLS& LoadModule(); - - nsWinNLS(const char* aModuleName = "USER32.DLL"); - ~nsWinNLS(); - - PRBool SetIMEEnableStatus(HWND aWnd, PRBool aState); - PRBool GetIMEEnableStatus(HWND aWnd); - - PRBool CanUseSetIMEEnableStatus(); - PRBool CanUseGetIMEEnableStatus(); - -private: - - HINSTANCE mInstance; - WINNLSEnableIMEPtr mWINNLSEnableIME; - WINNLSGetEnableStatusPtr mWINNLSGetEnableStatus; + AssociateContextPtr mAssociateContext; }; //------------------------------------------------------------------------- @@ -391,7 +364,7 @@ private: #define NS_IMM_GETDEFAULTIMEWND(hWnd, phDefWnd) \ { \ if (nsToolkit::gAIMMApp) \ - return nsToolkit::gAIMMApp->GetDefaultIMEWnd(hWnd, phDefWnd); \ + nsToolkit::gAIMMApp->GetDefaultIMEWnd(hWnd, phDefWnd); \ else { \ nsIMM& theIMM = nsIMM::LoadModule(); \ *(phDefWnd) = (HWND)theIMM.GetDefaultIMEWnd(hWnd); \ @@ -418,6 +391,16 @@ private: } \ } +#define NS_IMM_ASSOCIATECONTEXT(hWnd, hIMC, phOldIMC) \ +{ \ + if (nsToolkit::gAIMMApp) \ + nsToolkit::gAIMMApp->AssociateContext(hWnd, hIMC, phOldIMC); \ + else { \ + nsIMM& theIMM = nsIMM::LoadModule(); \ + *(phOldIMC) = theIMM.AssociateContext(hWnd, hIMC); \ + } \ +} + //------------------------------------------------------------------------- // // Macro for Input Method A/W conversion. diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 8b0a5e77858..cd7d682d3cf 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -836,6 +836,7 @@ nsWindow::nsWindow() : nsBaseWidget() mOldStyle = 0; mOldExStyle = 0; mPainting = 0; + mOldIMC = NULL; mLeadByte = '\0'; mBlurEventSuppressionLevel = 0; @@ -1631,6 +1632,12 @@ NS_METHOD nsWindow::Destroy() if (gAttentionTimerMonitor) gAttentionTimerMonitor->KillTimer(mWnd); + // if IME is disabled, restore it. + if (mOldIMC) { + NS_IMM_ASSOCIATECONTEXT(mWnd, mOldIMC, &mOldIMC); + NS_ASSERTION(!mOldIMC, "Another IMC was associated"); + } + HICON icon; icon = (HICON) nsToolkit::mSendMessage(mWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM) 0); if (icon) @@ -4623,15 +4630,6 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result = PR_TRUE; break; - case WM_ENABLE: - if (!wParam) { - // We must enable IME for common dialogs. - // NOTE: we don't need to recover IME status in nsWindow. - // Because when this window will be enabled, we will get focus event. - SetIMEEnabled(PR_TRUE); - } - break; - case WM_ACTIVATE: if (mEventCallback) { PRInt32 fActive = LOWORD(wParam); @@ -7358,14 +7356,10 @@ NS_IMETHODIMP nsWindow::SetIMEEnabled(PRBool aState) { if (sIMEIsComposing) ResetInputState(); - nsWinNLS &theWinNLS = nsWinNLS::LoadModule(); - if (!theWinNLS.CanUseSetIMEEnableStatus()) { - NS_WARNING("WINNLSEnableIME API is not loaded."); - return NS_ERROR_FAILURE; - } - PRBool lastStatus = theWinNLS.SetIMEEnableStatus(mWnd, aState); - if (aState && !lastStatus) - ::SendMessage(mWnd, WM_IME_NOTIFY, IMN_OPENSTATUSWINDOW, 0L); + if (!aState != !mOldIMC) + return NS_OK; + NS_IMM_ASSOCIATECONTEXT(mWnd, aState ? mOldIMC : NULL, &mOldIMC); + NS_ASSERTION(!aState || !mOldIMC, "Another IMC was associated"); return NS_OK; } @@ -7373,12 +7367,7 @@ NS_IMETHODIMP nsWindow::SetIMEEnabled(PRBool aState) //========================================================================== NS_IMETHODIMP nsWindow::GetIMEEnabled(PRBool* aState) { - nsWinNLS &theWinNLS = nsWinNLS::LoadModule(); - if (!theWinNLS.CanUseGetIMEEnableStatus()) { - NS_WARNING("WINNLSGetEnableStatus API is not loaded."); - return NS_ERROR_FAILURE; - } - *aState = !!theWinNLS.GetIMEEnableStatus(mWnd); + *aState = !mOldIMC; return NS_OK; } diff --git a/mozilla/widget/src/windows/nsWindow.h b/mozilla/widget/src/windows/nsWindow.h index b7af232e472..5b5fd24f342 100644 --- a/mozilla/widget/src/windows/nsWindow.h +++ b/mozilla/widget/src/windows/nsWindow.h @@ -428,10 +428,13 @@ protected: PRInt32 mMenuCmdId; - // Window styles used by this window before chrome was hidden + // Window styles used by this window before chrome was hidden DWORD mOldStyle; DWORD mOldExStyle; + // To enable/disable IME + HIMC mOldIMC; + static UINT gCurrentKeyboardCP; static HKL gKeyboardLayout; static PRBool gSwitchKeyboardLayout;