From f6dad4900a82c58a6666cdcdd46150b28bc2aa23 Mon Sep 17 00:00:00 2001 From: Jonas Kümmerlin Date: Wed, 1 May 2019 16:25:24 +0200 Subject: reorganize how combobox text is being handled. fixes some weird issues with MSLU. --- alf/alfcombobox.cpp | 60 ++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'alf/alfcombobox.cpp') diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp index 4624f3a..6dbc15a 100644 --- a/alf/alfcombobox.cpp +++ b/alf/alfcombobox.cpp @@ -1,13 +1,15 @@ #include "alfpriv.h" // Win32s doesn't like using the original message numbers for custom messages -#define ALF_CB_INSERTSTRING (ALF_WM__BASE + 200) -#define ALF_CB_ADDSTRING (ALF_WM__BASE + 201) -#define ALF_CB_GETCURSEL (ALF_WM__BASE + 202) -#define ALF_CB_SETCURSEL (ALF_WM__BASE + 203) -#define ALF_CB_GETLBTEXTLEN (ALF_WM__BASE + 204) -#define ALF_CB_GETLBTEXT (ALF_WM__BASE + 205) -#define ALF_CB_DELETESTRING (ALF_WM__BASE + 206) +#define ALF_CB_INSERTSTRING (ALF_WM__BASE + 200) +#define ALF_CB_ADDSTRING (ALF_WM__BASE + 201) +#define ALF_CB_GETCURSEL (ALF_WM__BASE + 202) +#define ALF_CB_SETCURSEL (ALF_WM__BASE + 203) +#define ALF_CB_GETLBTEXTLEN (ALF_WM__BASE + 204) +#define ALF_CB_GETLBTEXT (ALF_WM__BASE + 205) +#define ALF_CB_DELETESTRING (ALF_WM__BASE + 206) +#define ALF_CB_GETSTYLE (ALF_WM__BASE + 207) +#define ALF_CB_FINDSTRINGEXACT (ALF_WM__BASE + 208) TCHAR *_alf_comboClass = NULL; @@ -71,30 +73,13 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; } if (uMsg == WM_SETTEXT && hwndChild) { - LRESULT index = SendMessage(hwndChild, CB_FINDSTRINGEXACT, (WPARAM)-1, lParam); - if (index >= 0) { - SendMessage(hwnd, ALF_CB_SETCURSEL, (WPARAM)index, 0); - } else { - return SendMessage(hwndChild, WM_SETTEXT, wParam, lParam); - } + SetWindowText(hwndChild, (TCHAR*)lParam); } if (uMsg == WM_GETTEXTLENGTH && hwndChild) { - if ((GetWindowLong(hwndChild, GWL_STYLE) & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) { - int index = SendMessage(hwndChild, CB_GETCURSEL, 0, 0); - if (index != CB_ERR) { - return SendMessage(hwndChild, CB_GETLBTEXTLEN, (WPARAM)index, 0); - } - } - return SendMessage(hwndChild, WM_GETTEXTLENGTH, wParam, lParam); + return (LRESULT)GetWindowTextLength(hwndChild); } if (uMsg == WM_GETTEXT && hwndChild) { - if ((GetWindowLong(hwndChild, GWL_STYLE) & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) { - int index = SendMessage(hwndChild, CB_GETCURSEL, 0, 0); - if (index != CB_ERR) { - return SendMessage(hwndChild, CB_GETLBTEXT, (WPARAM)index, lParam); - } - } - return SendMessage(hwndChild, WM_GETTEXT, wParam, lParam); + return GetWindowText(hwndChild, (TCHAR*)lParam, (int)wParam); } if (uMsg == WM_SETFONT && hwndChild) { SendMessage(hwndChild, WM_SETFONT, wParam, lParam); @@ -108,6 +93,12 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (uMsg == WM_GETFONT && hwndChild) { return SendMessage(hwndChild, WM_GETFONT, wParam, lParam); } + if (uMsg == ALF_CB_GETSTYLE && hwndChild) { + return GetWindowLong(hwndChild, GWL_STYLE); + } + if ((uMsg == ALF_CB_FINDSTRINGEXACT || uMsg == CB_FINDSTRINGEXACT) && hwndChild) { + return SendMessage(hwndChild, CB_FINDSTRINGEXACT, wParam, lParam); + } if ((uMsg == ALF_CB_ADDSTRING || uMsg == CB_ADDSTRING) && hwndChild) { return SendMessage(hwndChild, CB_ADDSTRING, wParam, lParam); } @@ -352,13 +343,26 @@ ALF_ComboBoxAddString(HWND combo, const TCHAR *text) TCHAR * ALF_ComboBoxCurrentText(HWND combo) { + LRESULT style = SendMessage(combo, ALF_CB_GETSTYLE, 0, 0); + if (style & CBS_DROPDOWNLIST) { + int i = ALF_ComboBoxCurrentIndex(combo); + if (i >= 0) { + return ALF_ComboBoxStringForIndex(combo, i); + } + } + return ALF_Text(combo); } void ALF_ComboBoxSetText(HWND combo, const TCHAR *text) { - ALF_SetText(combo, text); + LRESULT index = SendMessage(combo, ALF_CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)text); + if (index >= 0) { + SendMessage(combo, ALF_CB_SETCURSEL, (WPARAM)index, 0); + } else { + SetWindowText(combo, text); + } } int -- cgit v1.2.3