diff options
Diffstat (limited to 'alf')
| -rw-r--r-- | alf/alf.cpp | 53 | ||||
| -rw-r--r-- | alf/alf.h | 22 | ||||
| -rw-r--r-- | alf/alfcombobox.cpp | 94 |
3 files changed, 164 insertions, 5 deletions
diff --git a/alf/alf.cpp b/alf/alf.cpp index b711085..36e17ac 100644 --- a/alf/alf.cpp +++ b/alf/alf.cpp @@ -360,6 +360,20 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) return 0; } + if (msg == WM_COMMAND) { + HWND source = (HWND)lparam; + WORD code = HIWORD(wparam); + WORD id = LOWORD(wparam); + LRESULT ret = 0; + if (source != 0) + ret = SendMessage(source, 0x2000 + WM_COMMAND, wparam, lparam); + + if (ret == 0 && priv->vtbl->command) + ret = priv->vtbl->command(priv->closure, hwnd, code, id, source); + + return ret; + } + if (msg == WM_ACTIVATE) { if (!HIWORD(wparam)) { // if !minimized if (LOWORD(wparam)) { @@ -706,3 +720,42 @@ ALF_WidgetHwndById(HWND win, WORD id) return closure.result; } +void +ALF_SetText(HWND hwnd, const TCHAR *text) +{ + SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)text); +} + +void +ALF_SetWidgetText(HWND parent, WORD id, const TCHAR *text) +{ + HWND h = ALF_WidgetHwndById(parent, id); + if (h) + ALF_SetText(h, text); +} + +TCHAR * // free with HeapFree +ALF_Text(HWND hwnd) +{ + int len = (int)SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0); + if (len > 0) { + TCHAR *buf = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY, (len + 1)*sizeof(TCHAR)); + if (SendMessage(hwnd, WM_GETTEXT, 0, (LPARAM)buf)) { + return buf; + } else { + HeapFree(GetProcessHeap(), 0, buf); + } + } + + return NULL; +} + +TCHAR * // free with HeapFree +ALF_WidgetText(HWND parent, WORD id) +{ + HWND h = ALF_WidgetHwndById(parent, id); + if (h) + return ALF_Text(h); + + return NULL; +} @@ -20,7 +20,7 @@ typedef struct { void (*postdestroy)(void * /*closure*/); void (*updatefonts)(void * /*closure*/, HWND /*window*/, const ALFWindowFonts *fonts); LRESULT (*message)(void * /*closure*/, HWND, UINT, WPARAM, LPARAM); - LRESULT (*command)(void * /*closure*/, HWND /*window*/, UINT /*sourceid*/, UINT /*notificationcode*/, LPARAM); + LRESULT (*command)(void * /*closure*/, HWND /*window*/, WORD /*notificationcode*/, WORD /*sourceid*/, HWND /*control*/); LRESULT (*notify)(void * /*closure*/, HWND /*window*/, WPARAM /*sourceid*/, NMHDR *); } ALFWindowVTable; @@ -142,6 +142,18 @@ ALF_SetModalResult(HWND win, int result); int ALF_GetModalResult(HWND win); +void +ALF_SetText(HWND hwnd, const TCHAR *text); + +void +ALF_SetWidgetText(HWND parent, WORD id, const TCHAR *text); + +TCHAR * // free with HeapFree +ALF_Text(HWND hwnd); + +TCHAR * // free with HeapFree +ALF_WidgetText(HWND parent, WORD id); + // combo box HWND @@ -159,14 +171,16 @@ ALF_ComboBoxInsertString(HWND combo, int index, const TCHAR *text); void ALF_ComboBoxRemoveString(HWND combo, int index); +TCHAR * // free with HeapFree +ALF_ComboBoxStringForIndex(HWND combo, int index); + int ALF_ComboBoxCurrentIndex(HWND combo); void -ALF_ComboBoxSetCurrentIndex(HWND combo); +ALF_ComboBoxSetCurrentIndex(HWND combo, int index); -// NOTE: call HeapFree -TCHAR * +TCHAR * // free with HeapFree ALF_ComboBoxCurrentText(HWND combo); void diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp index 43c547a..ce6eba9 100644 --- a/alf/alfcombobox.cpp +++ b/alf/alfcombobox.cpp @@ -59,12 +59,29 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; } if (uMsg == WM_SETTEXT && hwndChild) { - return SendMessage(hwndChild, WM_SETTEXT, wParam, lParam); + LRESULT index = SendMessage(hwndChild, CB_FINDSTRINGEXACT, (WPARAM)-1, lParam); + if (index >= 0) { + SendMessage(hwnd, CB_SETCURSEL, (WPARAM)index, 0); + } else { + return SendMessage(hwndChild, WM_SETTEXT, wParam, 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); } 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); } if (uMsg == WM_SETFONT && hwndChild) { @@ -82,6 +99,30 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (uMsg == CB_ADDSTRING && hwndChild) { return SendMessage(hwndChild, CB_ADDSTRING, wParam, lParam); } + if (uMsg == CB_INSERTSTRING && hwndChild) { + return SendMessage(hwndChild, CB_INSERTSTRING, wParam, lParam); + } + if (uMsg == CB_GETCURSEL && hwndChild) { + return SendMessage(hwndChild, CB_GETCURSEL, wParam, lParam); + } + if (uMsg == CB_SETCURSEL && hwndChild) { + LRESULT curSel = SendMessage(hwndChild, CB_GETCURSEL, wParam, lParam); + if ((WPARAM)curSel != wParam) { + LRESULT newSel = SendMessage(hwndChild, CB_SETCURSEL, wParam, lParam); + SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(GetWindowLong(hwndChild, GWL_ID), CBN_SELCHANGE), (LPARAM)hwndChild); + return newSel; + } + } + if (uMsg == CB_GETLBTEXTLEN && hwndChild) { + return SendMessage(hwndChild, CB_GETLBTEXTLEN, wParam, lParam); + } + if (uMsg == CB_GETLBTEXT && hwndChild) { + return SendMessage(hwndChild, CB_GETLBTEXT, wParam, lParam); + } + + if (uMsg == WM_COMMAND && (HWND)lParam == hwndChild) { + return SendMessage(GetParent(hwnd), WM_COMMAND, wParam, (LPARAM)hwnd); + } if (uMsg == ALF_WM_QUERYSIZE) { HDC hDc = GetDC(hwnd); @@ -268,3 +309,54 @@ ALF_ComboBoxAddString(HWND combo, const TCHAR *text) return (int)SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)text); } +TCHAR * +ALF_ComboBoxCurrentText(HWND combo) +{ + return ALF_Text(combo); +} + +void +ALF_ComboBoxSetText(HWND combo, const TCHAR *text) +{ + return ALF_SetText(combo, text); +} + +int +ALF_ComboBoxCurrentIndex(HWND combo) +{ + return (int)SendMessage(combo, CB_GETCURSEL, 0, 0); +} + +void +ALF_ComboBoxSetCurrentIndex(HWND combo, int index) +{ + SendMessage(combo, CB_SETCURSEL, (WPARAM)index, 0); +} + +TCHAR * // free with HeapFree +ALF_ComboBoxStringForIndex(HWND combo, int index) +{ + int len = (int)SendMessage(combo, CB_GETLBTEXTLEN, (WPARAM)index, 0); + if (len > 0) { + TCHAR* buf = (TCHAR*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY|HEAP_GENERATE_EXCEPTIONS, (len + 1)*sizeof(WCHAR)); + if (SendMessage(combo, CB_GETLBTEXT, (WPARAM)index, (LPARAM)buf)) { + return buf; + } else { + HeapFree(GetProcessHeap(), 0, buf); + } + } + + return NULL; +} + +void +ALF_ComboBoxInsertString(HWND combo, int index, const TCHAR *text) +{ + SendMessage(combo, CB_INSERTSTRING, (WPARAM)index, (LPARAM)text); +} + +void +ALF_ComboBoxRemoveString(HWND combo, int index) +{ + SendMessage(combo, CB_DELETESTRING, (WPARAM)index, 0); +} |
