From 741325b86aa4322b66e8a1cc2fec8dbbee3d87b1 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Jun 2002 19:20:43 +0000 Subject: [PATCH] Make sure edit and listbox controls are of same ASCII/Unicode style as the combo box. Fixed a few MBCS issues with WM_GETTEXTLENGTH handling. --- controls/combo.c | 64 ++++++++++++++++++++++++++++------------------ controls/edit.c | 4 ++- controls/listbox.c | 6 +++-- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/controls/combo.c b/controls/combo.c index cb1ac9b798..49215e7261 100644 --- a/controls/combo.c +++ b/controls/combo.c @@ -492,7 +492,8 @@ static LRESULT COMBO_WindowPosChanging( /*********************************************************************** * COMBO_Create */ -static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style ) +static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG style, + BOOL unicode ) { static const WCHAR clbName[] = {'C','o','m','b','o','L','B','o','x',0}; static const WCHAR editName[] = {'E','d','i','t',0}; @@ -574,16 +575,22 @@ static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG } } - lphc->hWndLBox = CreateWindowExW(lbeExStyle, - clbName, - NULL, - lbeStyle, - lphc->droppedRect.left, - lphc->droppedRect.top, - lphc->droppedRect.right - lphc->droppedRect.left, - lphc->droppedRect.bottom - lphc->droppedRect.top, - hwnd, (HMENU)ID_CB_LISTBOX, - GetWindowLongA( hwnd, GWL_HINSTANCE ), lphc ); + if (unicode) + lphc->hWndLBox = CreateWindowExW(lbeExStyle, clbName, NULL, lbeStyle, + lphc->droppedRect.left, + lphc->droppedRect.top, + lphc->droppedRect.right - lphc->droppedRect.left, + lphc->droppedRect.bottom - lphc->droppedRect.top, + hwnd, (HMENU)ID_CB_LISTBOX, + GetWindowLongA( hwnd, GWL_HINSTANCE ), lphc ); + else + lphc->hWndLBox = CreateWindowExA(lbeExStyle, "ComboLBox", NULL, lbeStyle, + lphc->droppedRect.left, + lphc->droppedRect.top, + lphc->droppedRect.right - lphc->droppedRect.left, + lphc->droppedRect.bottom - lphc->droppedRect.top, + hwnd, (HMENU)ID_CB_LISTBOX, + GetWindowLongA( hwnd, GWL_HINSTANCE ), lphc ); if( lphc->hWndLBox ) { @@ -610,15 +617,20 @@ static LRESULT COMBO_Create( HWND hwnd, LPHEADCOMBO lphc, HWND hwndParent, LONG if (!IsWindowEnabled(hwnd)) lbeStyle |= WS_DISABLED; - lphc->hWndEdit = CreateWindowExW(0, - editName, - NULL, - lbeStyle, - lphc->textRect.left, lphc->textRect.top, - lphc->textRect.right - lphc->textRect.left, - lphc->textRect.bottom - lphc->textRect.top, - hwnd, (HMENU)ID_CB_EDIT, - GetWindowLongA( hwnd, GWL_HINSTANCE ), NULL ); + if (unicode) + lphc->hWndEdit = CreateWindowExW(0, editName, NULL, lbeStyle, + lphc->textRect.left, lphc->textRect.top, + lphc->textRect.right - lphc->textRect.left, + lphc->textRect.bottom - lphc->textRect.top, + hwnd, (HMENU)ID_CB_EDIT, + GetWindowLongA( hwnd, GWL_HINSTANCE ), NULL ); + else + lphc->hWndEdit = CreateWindowExA(0, "Edit", NULL, lbeStyle, + lphc->textRect.left, lphc->textRect.top, + lphc->textRect.right - lphc->textRect.left, + lphc->textRect.bottom - lphc->textRect.top, + hwnd, (HMENU)ID_CB_EDIT, + GetWindowLongA( hwnd, GWL_HINSTANCE ), NULL ); if( !lphc->hWndEdit ) bEdit = FALSE; @@ -1907,7 +1919,7 @@ static LRESULT ComboWndProc_common( HWND hwnd, UINT message, hwndParent = ((LPCREATESTRUCTA)lParam)->hwndParent; style = ((LPCREATESTRUCTA)lParam)->style; } - return COMBO_Create(hwnd, lphc, hwndParent, style); + return COMBO_Create(hwnd, lphc, hwndParent, style, unicode); } case WM_PRINTCLIENT: @@ -1973,9 +1985,10 @@ static LRESULT ComboWndProc_common( HWND hwnd, UINT message, case WM_CLEAR: if ((message == WM_GETTEXTLENGTH) && !ISWIN31 && !(lphc->wState & CBF_EDIT)) { - int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0); - if (j == -1) return 0; - return SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0); + int j = SendMessageW(lphc->hWndLBox, LB_GETCURSEL, 0, 0); + if (j == -1) return 0; + return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, j, 0) : + SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, j, 0); } else if( lphc->wState & CBF_EDIT ) { @@ -2218,7 +2231,8 @@ static LRESULT ComboWndProc_common( HWND hwnd, UINT message, wParam = (INT)(INT16)wParam; /* fall through */ case CB_GETLBTEXTLEN: - return SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0); + return unicode ? SendMessageW(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0) : + SendMessageA(lphc->hWndLBox, LB_GETTEXTLEN, wParam, 0); case CB_GETITEMDATA16: wParam = (INT)(INT16)wParam; /* fall through */ diff --git a/controls/edit.c b/controls/edit.c index 2209a15ebe..68f66aba07 100644 --- a/controls/edit.c +++ b/controls/edit.c @@ -969,7 +969,9 @@ static LRESULT WINAPI EditWndProc_common( HWND hwnd, UINT msg, case WM_GETTEXTLENGTH: DPRINTF_EDIT_MSG32("WM_GETTEXTLENGTH"); - result = strlenW(es->text); + if (unicode) result = strlenW(es->text); + else result = WideCharToMultiByte( CP_ACP, 0, es->text, strlenW(es->text), + NULL, 0, NULL, NULL ); break; case WM_HSCROLL: diff --git a/controls/listbox.c b/controls/listbox.c index 951f548357..e537a5eb8a 100644 --- a/controls/listbox.c +++ b/controls/listbox.c @@ -2608,8 +2608,10 @@ static LRESULT WINAPI ListBoxWndProc_common( HWND hwnd, UINT msg, case LB_GETTEXTLEN: if ((INT)wParam >= descr->nb_items || (INT)wParam < 0) return LB_ERR; - return (HAS_STRINGS(descr) ? strlenW(descr->items[wParam].str) - : sizeof(DWORD)); + if (!HAS_STRINGS(descr)) return sizeof(DWORD); + if (unicode) return strlenW( descr->items[wParam].str ); + return WideCharToMultiByte( CP_ACP, 0, descr->items[wParam].str, + strlenW(descr->items[wParam].str), NULL, 0, NULL, NULL ); case LB_GETCURSEL16: case LB_GETCURSEL: -- 2.32.0.93.g670b81a890