summaryrefslogtreecommitdiff
path: root/alf/alfcombobox.cpp
diff options
context:
space:
mode:
authorJonas Kümmerlin <jonas@kuemmerlin.eu>2019-01-02 16:56:43 +0100
committerJonas Kümmerlin <jonas@kuemmerlin.eu>2019-01-02 16:56:43 +0100
commit89d174ab47af8a31ba316e03e36883e6924171bf (patch)
tree25b21619207cda9a81885b4b17e2933a905453dd /alf/alfcombobox.cpp
parentd19993c9d4891978c0b593eced6376d17aa1ffec (diff)
make combobox implementation more complete
Diffstat (limited to 'alf/alfcombobox.cpp')
-rw-r--r--alf/alfcombobox.cpp94
1 files changed, 93 insertions, 1 deletions
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);
+}