Bug 170969,104934,171228,170707

#ifdef MOZ_UNICODE fix
Affect in //widget/src/windows only
/r=shanjian;/sr=kin;/a=asa
This commit is contained in:
yokoyama%netscape.com 2002-10-16 23:28:18 +00:00
parent 8bab2e8969
commit efd5a5a283
5 changed files with 185 additions and 87 deletions

View File

@ -126,9 +126,9 @@ NS_IMETHODIMP nsFilePicker::ShowW(PRInt16 *aReturnVal)
browserInfo.iImage = nsnull;
// XXX UNICODE support is needed here --> DONE
LPITEMIDLIST list = ::SHBrowseForFolderW(&browserInfo);
LPITEMIDLIST list = nsToolkit::mSHBrowseForFolder(&browserInfo);
if (list != NULL) {
result = ::SHGetPathFromIDListW(list, (LPWSTR)fileBuffer);
result = nsToolkit::mSHGetPathFromIDList(list, (LPWSTR)fileBuffer);
if (result) {
mUnicodeFile.Append(fileBuffer);
}

View File

@ -49,24 +49,6 @@
#include "aimm.h"
#endif
#ifdef MOZ_UNICODE
#include "nsWindowAPI.h"
NS_DefWindowProc nsToolkit::mDefWindowProc = &DefWindowProcW;
NS_CallWindowProc nsToolkit::mCallWindowProc = &CallWindowProcW;
NS_SetWindowLong nsToolkit::mSetWindowLong = &SetWindowLongW;
NS_SendMessage nsToolkit::mSendMessage = &SendMessageW;
NS_DispatchMessage nsToolkit::mDispatchMessage = &DispatchMessageW;
NS_GetMessage nsToolkit::mGetMessage = &GetMessageW;
NS_PeekMessage nsToolkit::mPeekMessage = &PeekMessageW;
NS_GetOpenFileName nsToolkit::mGetOpenFileName = &GetOpenFileNameW;
NS_GetSaveFileName nsToolkit::mGetSaveFileName = &GetSaveFileNameW;
NS_GetClassName nsToolkit::mGetClassName = &GetClassNameW;
NS_CreateWindowEx nsToolkit::mCreateWindowEx = &CreateWindowExW;
NS_RegisterClass nsToolkit::mRegisterClass = &RegisterClassW;
#endif
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
// Cached reference to event queue service
@ -144,42 +126,6 @@ struct ThreadInitInfo {
nsToolkit *toolkit;
};
void RunPump(void* arg)
{
ThreadInitInfo *info = (ThreadInitInfo*)arg;
::PR_EnterMonitor(info->monitor);
#ifdef MOZ_AIMM
// Start Active Input Method Manager on this thread
if(nsToolkit::gAIMMApp)
nsToolkit::gAIMMApp->Activate(TRUE);
#endif
// do registration and creation in this thread
info->toolkit->CreateInternalWindow(PR_GetCurrentThread());
gThreadState = PR_TRUE;
::PR_Notify(info->monitor);
::PR_ExitMonitor(info->monitor);
delete info;
// Process messages
MSG msg;
#ifdef MOZ_UNICODE
while (nsToolkit::mGetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
nsToolkit::mDispatchMessage(&msg);
}
#else
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#endif
}
/* Detect when the user is moving a top-level window */
LRESULT CALLBACK DetectWindowMove(int code, WPARAM wParam, LPARAM lParam)
@ -213,6 +159,8 @@ LRESULT CALLBACK DetectWindowMove(int code, WPARAM wParam, LPARAM lParam)
#ifdef MOZ_UNICODE
#include "nsWindowAPI.h"
#define MAX_CLASS_NAME 128
#define MAX_MENU_NAME 128
#define MAX_FILTER_NAME 128
@ -425,8 +373,106 @@ ATOM WINAPI nsRegisterClass(const WNDCLASSW *aClassW)
return RegisterClassA(&wClass);
}
BOOL WINAPI nsSHGetPathFromIDList(LPCITEMIDLIST aIdList, LPWSTR aPathW)
{
char pathA[MAX_PATH+1];
if (aPathW) {
ConvertWtoA(aPathW, MAX_PATH, pathA);
if (SHGetPathFromIDListA(aIdList, pathA)) {
ConvertAtoW(pathA, MAX_PATH, aPathW);
return TRUE;
}
}
return FALSE;
}
LPITEMIDLIST WINAPI nsSHBrowseForFolder(LPBROWSEINFOW aBiW)
{
BROWSEINFO biA;
LPITEMIDLIST itemIdList;
char displayNameA[MAX_PATH];
char titleA[MAX_PATH];
memset(&biA, 0, sizeof(BROWSEINFO));
biA.hwndOwner = aBiW->hwndOwner;
biA.pidlRoot = aBiW->pidlRoot;
if (aBiW->pszDisplayName) {
ConvertWtoA(aBiW->pszDisplayName, MAX_PATH, displayNameA);
biA.pszDisplayName = displayNameA;
}
if (aBiW->lpszTitle) {
ConvertWtoA(aBiW->lpszTitle, MAX_PATH, titleA);
biA.lpszTitle = titleA;
}
biA.ulFlags = aBiW->ulFlags;
biA.lpfn = aBiW->lpfn;
biA.lParam = aBiW->lParam;
biA.iImage = aBiW->iImage;
itemIdList = SHBrowseForFolderA(&biA);
if (biA.pszDisplayName) {
ConvertAtoW(biA.pszDisplayName, MAX_PATH, aBiW->pszDisplayName);
}
return itemIdList;
}
NS_DefWindowProc nsToolkit::mDefWindowProc = DefWindowProcA;
NS_CallWindowProc nsToolkit::mCallWindowProc = CallWindowProcA;
NS_SetWindowLong nsToolkit::mSetWindowLong = SetWindowLongA;
NS_GetWindowLong nsToolkit::mGetWindowLong = GetWindowLongA;
NS_SendMessage nsToolkit::mSendMessage = nsSendMessage;
NS_DispatchMessage nsToolkit::mDispatchMessage = DispatchMessageA;
NS_GetMessage nsToolkit::mGetMessage = GetMessageA;
NS_PeekMessage nsToolkit::mPeekMessage = PeekMessageA;
NS_GetOpenFileName nsToolkit::mGetOpenFileName = nsGetOpenFileName;
NS_GetSaveFileName nsToolkit::mGetSaveFileName = nsGetSaveFileName;
NS_GetClassName nsToolkit::mGetClassName = nsGetClassName;
NS_CreateWindowEx nsToolkit::mCreateWindowEx = nsCreateWindowEx;
NS_RegisterClass nsToolkit::mRegisterClass = nsRegisterClass;
NS_SHGetPathFromIDList nsToolkit::mSHGetPathFromIDList = nsSHGetPathFromIDList;
NS_SHBrowseForFolder nsToolkit::mSHBrowseForFolder = nsSHBrowseForFolder;
#endif /* MOZ_UNICODE */
void RunPump(void* arg)
{
ThreadInitInfo *info = (ThreadInitInfo*)arg;
::PR_EnterMonitor(info->monitor);
#ifdef MOZ_AIMM
// Start Active Input Method Manager on this thread
if(nsToolkit::gAIMMApp)
nsToolkit::gAIMMApp->Activate(TRUE);
#endif
// do registration and creation in this thread
info->toolkit->CreateInternalWindow(PR_GetCurrentThread());
gThreadState = PR_TRUE;
::PR_Notify(info->monitor);
::PR_ExitMonitor(info->monitor);
delete info;
// Process messages
MSG msg;
#ifdef MOZ_UNICODE
while (nsToolkit::mGetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
nsToolkit::mDispatchMessage(&msg);
}
#else
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
#endif
}
//-------------------------------------------------------------------------
//
// constructor
@ -527,6 +573,34 @@ nsToolkit::Startup(HMODULE hModule)
nsToolkit::mIsNT = (osversion.dwPlatformId == VER_PLATFORM_WIN32_NT);
if (nsToolkit::mIsNT) {
#ifdef MOZ_UNICODE
// For Windows 9x base OS nsFoo is already pointing to A functions
// However on NT base OS we should point them to respective W functions
nsToolkit::mDefWindowProc = DefWindowProcW;
nsToolkit::mCallWindowProc = CallWindowProcW;
nsToolkit::mSetWindowLong = SetWindowLongW;
nsToolkit::mGetWindowLong = GetWindowLongW;
nsToolkit::mSendMessage = SendMessageW;
nsToolkit::mDispatchMessage = DispatchMessageW;
nsToolkit::mGetMessage = GetMessageW;
nsToolkit::mPeekMessage = PeekMessageW;
nsToolkit::mGetOpenFileName = GetOpenFileNameW;
nsToolkit::mGetSaveFileName = GetSaveFileNameW;
nsToolkit::mGetClassName = GetClassNameW;
nsToolkit::mCreateWindowEx = CreateWindowExW;
nsToolkit::mRegisterClass = RegisterClassW;
// Explicit call of SHxxxW in Win95 makes moz fails to run (170969)
// we use GetProcAddress() to hide
HMODULE module = ::LoadLibrary("Shell32.dll");
if (module) {
nsToolkit::mSHGetPathFromIDList = (NS_SHGetPathFromIDList)GetProcAddress(module, "SHGetPathFromIDListW");
if (!nsToolkit::mSHGetPathFromIDList)
nsToolkit::mSHGetPathFromIDList = &nsSHGetPathFromIDList;
nsToolkit::mSHBrowseForFolder = (NS_SHBrowseForFolder)GetProcAddress(module, "SHBrowseForFolderW");
if (!nsToolkit::mSHBrowseForFolder)
nsToolkit::mSHBrowseForFolder = &nsSHBrowseForFolder;
}
#endif /* MOZ_UNICODE */
nsToolkit::mUseImeApiW = PR_TRUE;
// XXX Hack for stopping the crash (125573)
if (osversion.dwMajorVersion == 5 && (osversion.dwMinorVersion == 0 || osversion.dwMinorVersion == 1)) {
@ -538,25 +612,6 @@ nsToolkit::Startup(HMODULE hModule)
}
}
}
#ifdef MOZ_UNICODE
else {
// On NT base OS, nsFoo is already pointing to respective W functions
// However, in Windows 9x base OS, we need them to point to A functions
nsToolkit::mDefWindowProc = &DefWindowProcA;
nsToolkit::mCallWindowProc = &CallWindowProcA;
nsToolkit::mSetWindowLong = &SetWindowLongA;
nsToolkit::mSendMessage = &nsSendMessage;
nsToolkit::mDispatchMessage = &DispatchMessageA;
nsToolkit::mGetMessage = &GetMessageA;
nsToolkit::mPeekMessage = &PeekMessageA;
nsToolkit::mGetOpenFileName = &nsGetOpenFileName;
nsToolkit::mGetSaveFileName = &nsGetSaveFileName;
nsToolkit::mGetClassName = &nsGetClassName;
nsToolkit::mCreateWindowEx = &nsCreateWindowEx;
nsToolkit::mRegisterClass = &nsRegisterClass;
}
#endif /* MOZ_UNICODE */
nsToolkit::mDllInstance = hModule;
//

View File

@ -117,6 +117,7 @@ public:
static NS_DefWindowProc mDefWindowProc;
static NS_CallWindowProc mCallWindowProc;
static NS_SetWindowLong mSetWindowLong;
static NS_GetWindowLong mGetWindowLong;
static NS_SendMessage mSendMessage;
static NS_DispatchMessage mDispatchMessage;
static NS_GetMessage mGetMessage;
@ -126,6 +127,8 @@ public:
static NS_GetClassName mGetClassName;
static NS_CreateWindowEx mCreateWindowEx;
static NS_RegisterClass mRegisterClass;
static NS_SHGetPathFromIDList mSHGetPathFromIDList;
static NS_SHBrowseForFolder mSHBrowseForFolder;
#endif
};

View File

@ -688,16 +688,21 @@ static nsAttentionTimerMonitor *gAttentionTimerMonitor = 0;
BOOL CALLBACK nsWindow::BroadcastMsgToChildren(HWND aWnd, LPARAM aMsg)
{
LONG proc = ::GetWindowLong(aWnd, GWL_WNDPROC);
if (proc == (LONG)&nsWindow::WindowProc) {
// its one of our windows so go ahead and send a message to it
WNDPROC winProc = (WNDPROC)GetWindowLong(aWnd, GWL_WNDPROC);
#ifdef MOZ_UNICODE
nsToolkit::mCallWindowProc(winProc, aWnd, aMsg, 0, 0);
#else
::CallWindowProc(winProc, aWnd, aMsg, 0, 0);
#endif
}
#ifdef MOZ_UNICODE
LONG proc = nsToolkit::mGetWindowLong(aWnd, GWL_WNDPROC);
if (proc == (LONG)&nsWindow::WindowProc) {
// its one of our windows so go ahead and send a message to it
WNDPROC winProc = (WNDPROC)nsToolkit::mGetWindowLong(aWnd, GWL_WNDPROC);
nsToolkit::mCallWindowProc(winProc, aWnd, aMsg, 0, 0);
}
#else
LONG proc = ::GetWindowLong(aWnd, GWL_WNDPROC);
if (proc == (LONG)&nsWindow::WindowProc) {
// its one of our windows so go ahead and send a message to it
WNDPROC winProc = (WNDPROC)GetWindowLong(aWnd, GWL_WNDPROC);
::CallWindowProc(winProc, aWnd, aMsg, 0, 0);
}
#endif
return TRUE;
}
@ -1535,11 +1540,13 @@ nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent,
// Show nsIDocShellTreeItem::contentType in GWL_ID
// This way 3rd part apps can check if a window is chrome (0) or content (1)
LONG contentType = aInitData? aInitData->mContentType: (parent? ::GetWindowLong(parent, GWL_ID): -1);
LONG isContent = (contentType == 1 || contentType == 2);
#ifdef MOZ_UNICODE
LONG contentType = aInitData? aInitData->mContentType: (parent? nsToolkit::mGetWindowLong(parent, GWL_ID): -1);
LONG isContent = (contentType == 1 || contentType == 2);
nsToolkit::mSetWindowLong(mWnd, GWL_ID, contentType);
#else
LONG contentType = aInitData? aInitData->mContentType: (parent? ::GetWindowLong(parent, GWL_ID): -1);
LONG isContent = (contentType == 1 || contentType == 2);
::SetWindowLong(mWnd, GWL_ID, contentType);
#endif
@ -1847,7 +1854,11 @@ NS_METHOD nsWindow::ModalEventFilter(PRBool aRealEvent, void *aEvent,
// if not, accept events for any window that hasn't been
// disabled.
if (!acceptEvent) {
#ifdef MOZ_UNICODE
LONG proc = nsToolkit::mGetWindowLong(msgWindow, GWL_WNDPROC);
#else
LONG proc = ::GetWindowLong(msgWindow, GWL_WNDPROC);
#endif /* MOZ_UNICODE */
if (proc == (LONG)&nsWindow::WindowProc) {
nsWindow *msgWin = GetNSWindowPtr(msgWindow);
msgWin->IsEnabled(&acceptEvent);
@ -2486,8 +2497,13 @@ NS_IMETHODIMP nsWindow::HideWindowChrome(PRBool aShouldHide)
DWORD style, exStyle;
if (aShouldHide) {
#ifdef MOZ_UNICODE
DWORD tempStyle = nsToolkit::mGetWindowLong(hwnd, GWL_STYLE);
DWORD tempExStyle = nsToolkit::mGetWindowLong(hwnd, GWL_EXSTYLE);
#else
DWORD tempStyle = ::GetWindowLong(hwnd, GWL_STYLE);
DWORD tempExStyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
#endif /* MOZ_UNICODE */
style = WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
exStyle = 0;
@ -2497,8 +2513,13 @@ NS_IMETHODIMP nsWindow::HideWindowChrome(PRBool aShouldHide)
}
else {
if (!mOldStyle || !mOldExStyle) {
#ifdef MOZ_UNICODE
mOldStyle = nsToolkit::mGetWindowLong(hwnd, GWL_STYLE);
mOldExStyle = nsToolkit::mGetWindowLong(hwnd, GWL_EXSTYLE);
#else
mOldStyle = ::GetWindowLong(hwnd, GWL_STYLE);
mOldExStyle = ::GetWindowLong(hwnd, GWL_EXSTYLE);
#endif /* MOZ_UNICODE */
}
style = mOldStyle;
@ -3062,7 +3083,11 @@ BOOL nsWindow::OnChar( UINT mbcsCharCode, UINT virtualKeyCode, bool isMultiByte
}
else
{ // 0x20 - SPACE, 0x3D - EQUALS
#ifdef MOZ_UNICODE
if(mbcsCharCode < 0x20 || (virtualKeyCode == 0x3D && mIsControlDown))
#else
if(virtualKeyCode < 0x20 || (virtualKeyCode == 0x3D && mIsControlDown))
#endif /* MOZ_UNICODE */
{
uniChar = 0;
}
@ -3589,7 +3614,11 @@ static nsresult HeapDump(const char *filename, const char *heading)
BOOL CALLBACK nsWindow::DispatchStarvedPaints(HWND aWnd, LPARAM aMsg)
{
#ifdef MOZ_UNICODE
LONG proc = nsToolkit::mGetWindowLong(aWnd, GWL_WNDPROC);
#else
LONG proc = ::GetWindowLong(aWnd, GWL_WNDPROC);
#endif /* MOZ_UNICODE */
if (proc == (LONG)&nsWindow::WindowProc) {
// its one of our windows so check to see if it has a
// invalidated rect. If it does. Dispatch a synchronous
@ -4503,7 +4532,11 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT
break;
}
#ifdef MOZ_UNICODE
LONG proc = nsToolkit::mGetWindowLong(destWnd, GWL_WNDPROC);
#else
LONG proc = ::GetWindowLong(destWnd, GWL_WNDPROC);
#endif /* MOZ_UNICODE */
if (proc != (LONG)&nsWindow::WindowProc) {
// Some other app, or a plugin window.
// Windows directs WM_MOUSEWHEEL to the focused window.

View File

@ -38,9 +38,14 @@
#ifndef WindowAPI_h__
#define WindowAPI_h__
#include <windows.h>
#include <commdlg.h>
#include <shlobj.h>
typedef LRESULT (WINAPI *NS_DefWindowProc) (HWND, UINT, WPARAM, LPARAM);
typedef LRESULT (WINAPI *NS_CallWindowProc) (WNDPROC, HWND, UINT, WPARAM, LPARAM);
typedef LONG (WINAPI *NS_SetWindowLong) (HWND, int, LONG);
typedef LONG (WINAPI *NS_GetWindowLong) (HWND, int);
typedef LRESULT (WINAPI *NS_SendMessage) (HWND, UINT, WPARAM, LPARAM ) ;
typedef LONG (WINAPI *NS_DispatchMessage) (CONST MSG *);
typedef BOOL (WINAPI *NS_GetMessage) (LPMSG, HWND, UINT, UINT);
@ -51,5 +56,7 @@ typedef int (WINAPI *NS_GetClassName) (HWND, LPWSTR, int);
typedef HWND (WINAPI *NS_CreateWindowEx)
(DWORD, LPCWSTR, LPCWSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID);
typedef ATOM (WINAPI *NS_RegisterClass) (CONST WNDCLASSW *);
typedef BOOL (WINAPI *NS_SHGetPathFromIDList) (LPCITEMIDLIST, LPWSTR);
typedef LPITEMIDLIST (WINAPI *NS_SHBrowseForFolder) (LPBROWSEINFOW);
#endif /* WindowAPI_h__ */