summaryrefslogtreecommitdiff
path: root/alf/alfcombobox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alf/alfcombobox.cpp')
-rw-r--r--alf/alfcombobox.cpp60
1 files changed, 33 insertions, 27 deletions
diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp
index 0444b14..4624f3a 100644
--- a/alf/alfcombobox.cpp
+++ b/alf/alfcombobox.cpp
@@ -1,7 +1,17 @@
#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)
+
+TCHAR *_alf_comboClass = NULL;
+
typedef struct {
- ALFAPP app;
DWORD comboStyle;
} ALFComboCreateParams;
@@ -38,12 +48,6 @@ ALF__ComboItemHeight(HWND hwnd)
static LRESULT CALLBACK
ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- if (uMsg == WM_NCCREATE) {
- ALFComboCreateParams *params = (ALFComboCreateParams*)((CREATESTRUCT*)lParam)->lpCreateParams;
-
- SetWindowLongPtr(hwnd, 0, (LONG_PTR)params->app);
- }
-
HWND hwndChild = (HWND)GetWindowLongPtr(hwnd, 0);
if (uMsg == WM_CREATE) {
@@ -69,7 +73,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (uMsg == WM_SETTEXT && hwndChild) {
LRESULT index = SendMessage(hwndChild, CB_FINDSTRINGEXACT, (WPARAM)-1, lParam);
if (index >= 0) {
- SendMessage(hwnd, CB_SETCURSEL, (WPARAM)index, 0);
+ SendMessage(hwnd, ALF_CB_SETCURSEL, (WPARAM)index, 0);
} else {
return SendMessage(hwndChild, WM_SETTEXT, wParam, lParam);
}
@@ -104,16 +108,19 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
if (uMsg == WM_GETFONT && hwndChild) {
return SendMessage(hwndChild, WM_GETFONT, wParam, lParam);
}
- if (uMsg == CB_ADDSTRING && hwndChild) {
+ if ((uMsg == ALF_CB_ADDSTRING || uMsg == CB_ADDSTRING) && hwndChild) {
return SendMessage(hwndChild, CB_ADDSTRING, wParam, lParam);
}
- if (uMsg == CB_INSERTSTRING && hwndChild) {
+ if ((uMsg == ALF_CB_INSERTSTRING || uMsg == CB_INSERTSTRING) && hwndChild) {
return SendMessage(hwndChild, CB_INSERTSTRING, wParam, lParam);
}
- if (uMsg == CB_GETCURSEL && hwndChild) {
+ if ((uMsg == ALF_CB_DELETESTRING || uMsg == CB_DELETESTRING) && hwndChild) {
+ return SendMessage(hwndChild, CB_DELETESTRING, wParam, lParam);
+ }
+ if ((uMsg == ALF_CB_GETCURSEL || uMsg == CB_GETCURSEL) && hwndChild) {
return SendMessage(hwndChild, CB_GETCURSEL, wParam, lParam);
}
- if (uMsg == CB_SETCURSEL && hwndChild) {
+ if ((uMsg == ALF_CB_SETCURSEL || uMsg == CB_SETCURSEL) && hwndChild) {
LRESULT curSel = SendMessage(hwndChild, CB_GETCURSEL, wParam, lParam);
if ((WPARAM)curSel != wParam) {
LRESULT newSel = SendMessage(hwndChild, CB_SETCURSEL, wParam, lParam);
@@ -121,10 +128,10 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return newSel;
}
}
- if (uMsg == CB_GETLBTEXTLEN && hwndChild) {
+ if ((uMsg == ALF_CB_GETLBTEXTLEN || uMsg == CB_GETLBTEXTLEN) && hwndChild) {
return SendMessage(hwndChild, CB_GETLBTEXTLEN, wParam, lParam);
}
- if (uMsg == CB_GETLBTEXT && hwndChild) {
+ if ((uMsg == ALF_CB_GETLBTEXT || uMsg == CB_GETLBTEXT) && hwndChild) {
return SendMessage(hwndChild, CB_GETLBTEXT, wParam, lParam);
}
@@ -264,7 +271,7 @@ ALF__ComboWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
void
-ALF_RegisterComboClass(ALFAPP app)
+ALF_RegisterComboClass(void)
{
WNDCLASS cls;
ZeroMemory(&cls, sizeof(cls));
@@ -272,7 +279,7 @@ ALF_RegisterComboClass(ALFAPP app)
TCHAR classNameBuf[256];
ALF_BuildRandomClassName(TEXT("ALFComboBox"), classNameBuf, 256);
- cls.hInstance = app->hInstance;
+ cls.hInstance = ALF_HINSTANCE;
cls.hCursor = LoadCursor(NULL, (LPTSTR)IDC_ARROW);
if (LOBYTE(LOWORD(GetVersion())) >= 4) {
cls.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
@@ -288,18 +295,17 @@ ALF_RegisterComboClass(ALFAPP app)
if (!classatom)
MessageBox(NULL, TEXT("FATAL: Could not register Combo class"), NULL, MB_OK);
- app->comboClass = MAKEINTATOM(classatom);
+ _alf_comboClass = MAKEINTATOM(classatom);
}
static HWND
ALF_InternalAddComboBox(HWND win, WORD id, UINT x, UINT y, DWORD style, const TCHAR *defaultText)
{
ALFComboCreateParams cp;
- cp.app = ALF_ApplicationFromWindow(win);
cp.comboStyle = style;
HWND hwndCombo = CreateWindowEx(WS_EX_CONTROLPARENT,
- cp.app->comboClass,
+ _alf_comboClass,
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN,
0, 0, 0, 0,
@@ -340,7 +346,7 @@ ALF_AddSelectionOnlyComboBox(HWND win, WORD id, UINT x, UINT y)
int /* index */
ALF_ComboBoxAddString(HWND combo, const TCHAR *text)
{
- return (int)SendMessage(combo, CB_ADDSTRING, 0, (LPARAM)text);
+ return (int)SendMessage(combo, ALF_CB_ADDSTRING, 0, (LPARAM)text);
}
TCHAR *
@@ -352,28 +358,28 @@ ALF_ComboBoxCurrentText(HWND combo)
void
ALF_ComboBoxSetText(HWND combo, const TCHAR *text)
{
- ALF_SetText(combo, text);
+ ALF_SetText(combo, text);
}
int
ALF_ComboBoxCurrentIndex(HWND combo)
{
- return (int)SendMessage(combo, CB_GETCURSEL, 0, 0);
+ return (int)SendMessage(combo, ALF_CB_GETCURSEL, 0, 0);
}
void
ALF_ComboBoxSetCurrentIndex(HWND combo, int index)
{
- SendMessage(combo, CB_SETCURSEL, (WPARAM)index, 0);
+ SendMessage(combo, ALF_CB_SETCURSEL, (WPARAM)index, 0);
}
TCHAR * // free with ALF_Free
ALF_ComboBoxStringForIndex(HWND combo, int index)
{
- int len = (int)SendMessage(combo, CB_GETLBTEXTLEN, (WPARAM)index, 0);
+ int len = (int)SendMessage(combo, ALF_CB_GETLBTEXTLEN, (WPARAM)index, 0);
if (len > 0) {
TCHAR* buf = ALF_New(TCHAR, len + 1);
- if (SendMessage(combo, CB_GETLBTEXT, (WPARAM)index, (LPARAM)buf)) {
+ if (SendMessage(combo, ALF_CB_GETLBTEXT, (WPARAM)index, (LPARAM)buf)) {
return buf;
} else {
ALF_Free(buf);
@@ -386,11 +392,11 @@ ALF_ComboBoxStringForIndex(HWND combo, int index)
void
ALF_ComboBoxInsertString(HWND combo, int index, const TCHAR *text)
{
- SendMessage(combo, CB_INSERTSTRING, (WPARAM)index, (LPARAM)text);
+ SendMessage(combo, ALF_CB_INSERTSTRING, (WPARAM)index, (LPARAM)text);
}
void
ALF_ComboBoxRemoveString(HWND combo, int index)
{
- SendMessage(combo, CB_DELETESTRING, (WPARAM)index, 0);
+ SendMessage(combo, ALF_CB_DELETESTRING, (WPARAM)index, 0);
}