summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--alf/alf.cpp53
-rw-r--r--alf/alf.h22
-rw-r--r--alf/alfcombobox.cpp94
-rw-r--r--widgetfactory.cpp33
4 files changed, 194 insertions, 8 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;
+}
diff --git a/alf/alf.h b/alf/alf.h
index c6a7b77..62f4563 100644
--- a/alf/alf.h
+++ b/alf/alf.h
@@ -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);
+}
diff --git a/widgetfactory.cpp b/widgetfactory.cpp
index 57d987e..e2d631c 100644
--- a/widgetfactory.cpp
+++ b/widgetfactory.cpp
@@ -13,6 +13,7 @@ enum {
ID_LBL4,
ID_COMBO2,
ID_LBL5,
+ ID_LBL6,
ID__MAX
};
@@ -51,6 +52,26 @@ handleMessage(void *closure, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
return ALF_DefWindowProc(hwnd, msg, wparam, lparam);
}
+static LRESULT
+handleCommand(void *closure, HWND window, WORD notificationcode, WORD sourceid, HWND control)
+{
+ (void)closure;
+
+ if (notificationcode == CBN_SELCHANGE && sourceid == ID_COMBO2) {
+ TCHAR *text = ALF_ComboBoxCurrentText(control);
+
+ ALF_SetWidgetText(window, ID_LBL6, text);
+
+ HeapFree(GetProcessHeap(), 0, text);
+ }
+ if (control != NULL && sourceid == ID_B4) {
+ HWND combo = ALF_WidgetHwndById(window, ID_COMBO2);
+ ALF_ComboBoxSetCurrentIndex(combo, -1);
+ }
+
+ return 0;
+}
+
int CALLBACK
#ifdef UNICODE
wWinMain
@@ -75,6 +96,7 @@ WinMain
//cparams.className = TEXT("DummyClass");
cparams.vtbl.message = handleMessage;
+ cparams.vtbl.command = handleCommand;
ALFAPP app = ALF_CreateApplication(hInstance);
@@ -106,9 +128,9 @@ WinMain
HWND hwndCombo1 = ALF_AddEditableComboBox(win, ID_COMBO1, 1, 3, TEXT("Hello!"));
ALF_AddButton(win, ID_B3, 2, 3, TEXT("Ok"));
- ALF_ComboBoxAddString(hwndCombo1, TEXT("Hello World!"));
- ALF_ComboBoxAddString(hwndCombo1, TEXT("Goodbye World!"));
- ALF_ComboBoxAddString(hwndCombo1, TEXT("The quick brown fox jumps over the lazy dog"));
+ ALF_ComboBoxInsertString(hwndCombo1, 0, TEXT("Hello World!"));
+ ALF_ComboBoxInsertString(hwndCombo1, -1, TEXT("Goodbye World!"));
+ ALF_ComboBoxInsertString(hwndCombo1, 1, TEXT("The quick brown fox jumps over the lazy dog"));
ALF_AddLabel(win, ID_LBL5, 0, 4, TEXT("Selection-Only Combo Box:"));
HWND hwndCombo2 = ALF_AddSelectionOnlyComboBox(win, ID_COMBO2, 1, 4);
@@ -118,9 +140,14 @@ WinMain
ALF_ComboBoxAddString(hwndCombo2, TEXT("Goodbye World!"));
ALF_ComboBoxAddString(hwndCombo2, TEXT("The quick brown fox jumps over the lazy dog"));
+ ALF_AddLabel(win, ID_LBL6, 0, 5, TEXT("[ComboBox2 value]"));
+
ALF_RecalculateLayout(win);
ALF_SetDefaultButton(win, ID_B1);
+ ALF_ComboBoxSetText(hwndCombo2, TEXT("Goodbye World!"));
+
+
//EnableWindow(ALF_WidgetHwndById(win, ID_LBL3), FALSE);
ALF_ResizeWindow(win, 1, 1);