diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c index 980fc5fac76..034403e82ef 100644 --- a/dlls/comdlg32/filedlg.c +++ b/dlls/comdlg32/filedlg.c @@ -3740,7 +3740,7 @@ static void MemFree(void *mem) * by a 32 bits application * */ -static BOOL FD32_GetTemplate(PFD31_DATA lfs) +BOOL FD32_GetTemplate(PFD31_DATA lfs) { LPOPENFILENAMEW ofnW = lfs->ofnW; LPOPENFILENAMEA ofnA = lfs->ofnA; @@ -3796,145 +3796,6 @@ static BOOL FD32_GetTemplate(PFD31_DATA lfs) } -/************************************************************************ - * FD32_Init [internal] - * called from the common 16/32 code to initialize 32 bit data - */ -static BOOL CALLBACK FD32_Init(LPARAM lParam, PFD31_DATA lfs, DWORD data) -{ - BOOL IsUnicode = (BOOL) data; - - if (IsUnicode) - { - lfs->ofnA = NULL; - lfs->ofnW = (LPOPENFILENAMEW) lParam; - if (lfs->ofnW->Flags & OFN_ENABLEHOOK) - if (lfs->ofnW->lpfnHook) - lfs->hook = TRUE; - } - else - { - lfs->ofnA = (LPOPENFILENAMEA) lParam; - if (lfs->ofnA->Flags & OFN_ENABLEHOOK) - if (lfs->ofnA->lpfnHook) - lfs->hook = TRUE; - lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lfs->ofnW)); - FD31_MapOfnStructA(lfs->ofnA, lfs->ofnW, lfs->open); - } - - if (! FD32_GetTemplate(lfs)) return FALSE; - - return TRUE; -} - -/*********************************************************************** - * FD32_CallWindowProc [internal] - * - * called from the common 16/32 code to call the appropriate hook - */ -static BOOL CALLBACK FD32_CallWindowProc(const FD31_DATA *lfs, UINT wMsg, WPARAM wParam, - LPARAM lParam) -{ - BOOL ret; - - if (lfs->ofnA) - { - TRACE("Call hookA %p (%p, %04x, %08lx, %08lx)\n", - lfs->ofnA->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); - ret = lfs->ofnA->lpfnHook(lfs->hwnd, wMsg, wParam, lParam); - TRACE("ret hookA %p (%p, %04x, %08lx, %08lx)\n", - lfs->ofnA->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); - return ret; - } - - TRACE("Call hookW %p (%p, %04x, %08lx, %08lx)\n", - lfs->ofnW->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); - ret = lfs->ofnW->lpfnHook(lfs->hwnd, wMsg, wParam, lParam); - TRACE("Ret hookW %p (%p, %04x, %08lx, %08lx)\n", - lfs->ofnW->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); - return ret; -} - -/*********************************************************************** - * FD32_UpdateResult [internal] - * update the real client structures if any - */ -static void CALLBACK FD32_UpdateResult(const FD31_DATA *lfs) -{ - LPOPENFILENAMEW ofnW = lfs->ofnW; - LPOPENFILENAMEA ofnA = lfs->ofnA; - - if (ofnA) - { - LPSTR lpszTemp; - if (ofnW->nMaxFile && - !WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1, - ofnA->lpstrFile, ofnA->nMaxFile, NULL, NULL )) - ofnA->lpstrFile[ofnA->nMaxFile-1] = 0; - - /* offsets are not guaranteed to be the same in WCHAR to MULTIBYTE conversion */ - /* set filename offset */ - lpszTemp = PathFindFileNameA(ofnA->lpstrFile); - ofnA->nFileOffset = (lpszTemp - ofnA->lpstrFile); - - /* set extension offset */ - lpszTemp = PathFindExtensionA(ofnA->lpstrFile); - ofnA->nFileExtension = (*lpszTemp) ? (lpszTemp - ofnA->lpstrFile) + 1 : 0; - } -} - -/*********************************************************************** - * FD32_UpdateFileTitle [internal] - * update the real client structures if any - */ -static void CALLBACK FD32_UpdateFileTitle(const FD31_DATA *lfs) -{ - LPOPENFILENAMEW ofnW = lfs->ofnW; - LPOPENFILENAMEA ofnA = lfs->ofnA; - - if (ofnA) - { - if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1, - ofnA->lpstrFileTitle, ofnA->nMaxFileTitle, NULL, NULL )) - ofnA->lpstrFileTitle[ofnA->nMaxFileTitle-1] = 0; - } -} - - -/*********************************************************************** - * FD32_SendLbGetCurSel [internal] - * retrieve selected listbox item - */ -static LRESULT CALLBACK FD32_SendLbGetCurSel(const FD31_DATA *lfs) -{ - return SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0); -} - - -/************************************************************************ - * FD32_Destroy [internal] - * called from the common 16/32 code to cleanup 32 bit data - */ -static void CALLBACK FD32_Destroy(const FD31_DATA *lfs) -{ - /* if ofnW has been allocated, have to free everything in it */ - if (lfs->ofnA) - { - FD31_FreeOfnW(lfs->ofnW); - HeapFree(GetProcessHeap(), 0, lfs->ofnW); - } -} - -static void FD32_SetupCallbacks(PFD31_CALLBACKS callbacks) -{ - callbacks->Init = FD32_Init; - callbacks->CWP = FD32_CallWindowProc; - callbacks->UpdateResult = FD32_UpdateResult; - callbacks->UpdateFileTitle = FD32_UpdateFileTitle; - callbacks->SendLbGetCurSel = FD32_SendLbGetCurSel; - callbacks->Destroy = FD32_Destroy; -} - /*********************************************************************** * FD32_WMMeasureItem [internal] */ @@ -4009,13 +3870,11 @@ static BOOL GetFileName31A(LPOPENFILENAMEA lpofn, /* address of structure with d HINSTANCE hInst; BOOL bRet = FALSE; PFD31_DATA lfs; - FD31_CALLBACKS callbacks; if (!lpofn || !FD31_Init()) return FALSE; TRACE("ofn flags %08x\n", lpofn->Flags); - FD32_SetupCallbacks(&callbacks); - lfs = FD31_AllocPrivate((LPARAM) lpofn, dlgType, &callbacks, (DWORD) FALSE); + lfs = FD31_AllocPrivate((LPARAM) lpofn, dlgType, FALSE); if (lfs) { hInst = (HINSTANCE)GetWindowLongPtrW( lpofn->hwndOwner, GWLP_HINSTANCE ); @@ -4040,12 +3899,10 @@ static BOOL GetFileName31W(LPOPENFILENAMEW lpofn, /* address of structure with d HINSTANCE hInst; BOOL bRet = FALSE; PFD31_DATA lfs; - FD31_CALLBACKS callbacks; if (!lpofn || !FD31_Init()) return FALSE; - FD32_SetupCallbacks(&callbacks); - lfs = FD31_AllocPrivate((LPARAM) lpofn, dlgType, &callbacks, (DWORD) TRUE); + lfs = FD31_AllocPrivate((LPARAM) lpofn, dlgType, TRUE); if (lfs) { hInst = (HINSTANCE)GetWindowLongPtrW( lpofn->hwndOwner, GWLP_HINSTANCE ); diff --git a/dlls/comdlg32/filedlg31.c b/dlls/comdlg32/filedlg31.c index 4fab38ffc7d..afe5f317a2a 100644 --- a/dlls/comdlg32/filedlg31.c +++ b/dlls/comdlg32/filedlg31.c @@ -109,7 +109,24 @@ static void FD31_StripEditControl(HWND hwnd) BOOL FD31_CallWindowProc(const FD31_DATA *lfs, UINT wMsg, WPARAM wParam, LPARAM lParam) { - return lfs->callbacks->CWP(lfs, wMsg, wParam, lParam); + BOOL ret; + + if (lfs->ofnA) + { + TRACE("Call hookA %p (%p, %04x, %08lx, %08lx)\n", + lfs->ofnA->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); + ret = lfs->ofnA->lpfnHook(lfs->hwnd, wMsg, wParam, lParam); + TRACE("ret hookA %p (%p, %04x, %08lx, %08lx)\n", + lfs->ofnA->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); + return ret; + } + + TRACE("Call hookW %p (%p, %04x, %08lx, %08lx)\n", + lfs->ofnW->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); + ret = lfs->ofnW->lpfnHook(lfs->hwnd, wMsg, wParam, lParam); + TRACE("Ret hookW %p (%p, %04x, %08lx, %08lx)\n", + lfs->ofnW->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); + return ret; } /*********************************************************************** @@ -300,6 +317,7 @@ static void FD31_UpdateResult(const FD31_DATA *lfs, const WCHAR *tmpstr) { int lenstr2; LPOPENFILENAMEW ofnW = lfs->ofnW; + LPOPENFILENAMEA ofnA = lfs->ofnA; WCHAR tmpstr2[BUFFILE]; WCHAR *p; @@ -329,7 +347,23 @@ static void FD31_UpdateResult(const FD31_DATA *lfs, const WCHAR *tmpstr) debugstr_w(ofnW->lpstrFile), ofnW->nFileOffset, ofnW->nFileExtension); /* update the real client structures if any */ - lfs->callbacks->UpdateResult(lfs); + if (ofnA) + { + LPSTR lpszTemp; + if (ofnW->nMaxFile && + !WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1, + ofnA->lpstrFile, ofnA->nMaxFile, NULL, NULL )) + ofnA->lpstrFile[ofnA->nMaxFile-1] = 0; + + /* offsets are not guaranteed to be the same in WCHAR to MULTIBYTE conversion */ + /* set filename offset */ + lpszTemp = PathFindFileNameA(ofnA->lpstrFile); + ofnA->nFileOffset = (lpszTemp - ofnA->lpstrFile); + + /* set extension offset */ + lpszTemp = PathFindExtensionA(ofnA->lpstrFile); + ofnA->nFileExtension = (*lpszTemp) ? (lpszTemp - ofnA->lpstrFile) + 1 : 0; + } } /*********************************************************************** @@ -340,12 +374,19 @@ static void FD31_UpdateFileTitle(const FD31_DATA *lfs) { LONG lRet; LPOPENFILENAMEW ofnW = lfs->ofnW; + LPOPENFILENAMEA ofnA = lfs->ofnA; + if (ofnW->lpstrFileTitle != NULL) { lRet = SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0); SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETTEXT, lRet, (LPARAM)ofnW->lpstrFileTitle ); - lfs->callbacks->UpdateFileTitle(lfs); + if (ofnA) + { + if (!WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFileTitle, -1, + ofnA->lpstrFileTitle, ofnA->nMaxFileTitle, NULL, NULL )) + ofnA->lpstrFileTitle[ofnA->nMaxFileTitle-1] = 0; + } } } @@ -396,7 +437,7 @@ static LRESULT FD31_FileListSelect( const FD31_DATA *lfs ) HWND hWnd = lfs->hwnd; LPWSTR pstr; - lRet = lfs->callbacks->SendLbGetCurSel(lfs); + lRet = SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0); if (lRet == LB_ERR) return TRUE; @@ -774,7 +815,13 @@ void FD31_DestroyPrivate(PFD31_DATA lfs) if (!lfs) return; hwnd = lfs->hwnd; TRACE("destroying private allocation %p\n", lfs); - lfs->callbacks->Destroy(lfs); + + /* if ofnW has been allocated, have to free everything in it */ + if (lfs->ofnA) + { + FD31_FreeOfnW(lfs->ofnW); + HeapFree(GetProcessHeap(), 0, lfs->ofnW); + } HeapFree(GetProcessHeap(), 0, lfs); RemovePropA(hwnd, FD31_OFN_PROP); } @@ -787,8 +834,7 @@ void FD31_DestroyPrivate(PFD31_DATA lfs) * On entry : type = dialog procedure type (16,32A,32W) * dlgType = dialog type (open or save) */ -PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, - PFD31_CALLBACKS callbacks, DWORD data) +PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, BOOL IsUnicode) { PFD31_DATA lfs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(FD31_DATA)); @@ -797,8 +843,26 @@ PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, lfs->hook = FALSE; lfs->lParam = lParam; lfs->open = (dlgType == OPEN_DIALOG); - lfs->callbacks = callbacks; - if (! lfs->callbacks->Init(lParam, lfs, data)) + + if (IsUnicode) + { + lfs->ofnA = NULL; + lfs->ofnW = (LPOPENFILENAMEW) lParam; + if (lfs->ofnW->Flags & OFN_ENABLEHOOK) + if (lfs->ofnW->lpfnHook) + lfs->hook = TRUE; + } + else + { + lfs->ofnA = (LPOPENFILENAMEA) lParam; + if (lfs->ofnA->Flags & OFN_ENABLEHOOK) + if (lfs->ofnA->lpfnHook) + lfs->hook = TRUE; + lfs->ofnW = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*lfs->ofnW)); + FD31_MapOfnStructA(lfs->ofnA, lfs->ofnW, lfs->open); + } + + if (! FD32_GetTemplate(lfs)) { FD31_DestroyPrivate(lfs); return NULL; diff --git a/dlls/comdlg32/filedlg31.h b/dlls/comdlg32/filedlg31.h index ed7a173f3a4..79faed75e50 100644 --- a/dlls/comdlg32/filedlg31.h +++ b/dlls/comdlg32/filedlg31.h @@ -21,21 +21,7 @@ #define FD31_OFN_PROP "FILEDLG_OFN" -/* Forward declare */ -typedef struct tagFD31_DATA FD31_DATA, *PFD31_DATA; - -typedef struct tagFD31_CALLBACKS -{ - BOOL (CALLBACK *Init)(LPARAM lParam, PFD31_DATA lfs, DWORD data); - BOOL (CALLBACK *CWP)(const FD31_DATA *lfs, UINT wMsg, WPARAM wParam, - LPARAM lParam); /* CWP instead of CallWindowProc to avoid macro expansion */ - void (CALLBACK *UpdateResult)(const FD31_DATA *lfs); - void (CALLBACK *UpdateFileTitle)(const FD31_DATA *lfs); - LRESULT (CALLBACK *SendLbGetCurSel)(const FD31_DATA *lfs); - void (CALLBACK *Destroy)(const FD31_DATA *lfs); -} FD31_CALLBACKS, *PFD31_CALLBACKS; - -struct tagFD31_DATA +typedef struct tagFD31_DATA { HWND hwnd; /* file dialog window handle */ BOOL hook; /* TRUE if the dialog is hooked */ @@ -47,12 +33,12 @@ struct tagFD31_DATA LPOPENFILENAMEW ofnW; /* pointer either to the original structure or a W copy for A/16 API */ LPOPENFILENAMEA ofnA; /* original structure if 32bits ansi dialog */ - PFD31_CALLBACKS callbacks; /* callbacks to handle 16/32 bit differences */ -}; +} FD31_DATA, *PFD31_DATA; + +extern BOOL FD32_GetTemplate(PFD31_DATA lfs); extern BOOL FD31_Init(void); -extern PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, - PFD31_CALLBACKS callbacks, DWORD data); +extern PFD31_DATA FD31_AllocPrivate(LPARAM lParam, UINT dlgType, BOOL IsUnicode); extern void FD31_DestroyPrivate(PFD31_DATA lfs); extern void FD31_MapOfnStructA(const OPENFILENAMEA *ofnA, LPOPENFILENAMEW ofnW, BOOL open); extern void FD31_FreeOfnW(OPENFILENAMEW *ofnW);