changeset 371:e856f80e0520

Check for comboboxes in listbox functions, and handle missing events, or return if invalid for comboboxes.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 27 Apr 2003 18:50:58 +0000
parents e5156e7e5f19
children 3ef2cf70ee07
files win/dw.c
diffstat 1 files changed, 46 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Sun Apr 27 18:43:14 2003 +0000
+++ b/win/dw.c	Sun Apr 27 18:50:58 2003 +0000
@@ -5112,7 +5112,7 @@
 
 	GetClassName(handle, tmpbuf, 99);
 
-	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 		SendMessage(handle,
 					CB_ADDSTRING,
 					0, (LPARAM)text);
@@ -5133,7 +5133,7 @@
 
 	GetClassName(handle, tmpbuf, 99);
 
-	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 	{
 		char *buf = dw_window_get_text(handle);
 
@@ -5160,11 +5160,23 @@
  */
 void API dw_listbox_set_text(HWND handle, unsigned int index, char *buffer)
 {
-	unsigned int sel = (unsigned int)SendMessage(handle, LB_GETCURSEL, 0, 0);
-	SendMessage(handle,	LB_DELETESTRING, (WPARAM)index, 0);
-	SendMessage(handle, LB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer);
-	SendMessage(handle, LB_SETCURSEL, (WPARAM)sel, 0);
-	SendMessage(handle, LB_SETSEL, (WPARAM)TRUE, (LPARAM)sel);
+	char tmpbuf[100];
+
+	GetClassName(handle, tmpbuf, 99);
+
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
+	{
+		SendMessage(handle,	CB_DELETESTRING, (WPARAM)index, 0);
+		SendMessage(handle, CB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer);
+	}
+	else
+	{
+		unsigned int sel = (unsigned int)SendMessage(handle, LB_GETCURSEL, 0, 0);
+		SendMessage(handle,	LB_DELETESTRING, (WPARAM)index, 0);
+		SendMessage(handle, LB_INSERTSTRING, (WPARAM)index, (LPARAM)buffer);
+		SendMessage(handle, LB_SETCURSEL, (WPARAM)sel, 0);
+		SendMessage(handle, LB_SETSEL, (WPARAM)TRUE, (LPARAM)sel);
+	}
 }
 
 /*
@@ -5187,7 +5199,7 @@
 
 	GetClassName(handle, tmpbuf, 99);
 
-	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 	{
 		len = (int)SendMessage(handle, CB_GETLBTEXTLEN, (WPARAM)index, 0);
 
@@ -5216,7 +5228,7 @@
 
 	GetClassName(handle, tmpbuf, 99);
 
-	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 		return (unsigned int)SendMessage(handle,
 										 CB_GETCURSEL,
 										 0, 0);
@@ -5235,6 +5247,13 @@
 int API dw_listbox_selected_multi(HWND handle, int where)
 {
 	int *array, count, z;
+	char tmpbuf[100];
+
+	GetClassName(handle, tmpbuf, 99);
+
+	/* This doesn't work on comboboxes */
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
+		return -1;
 
 	count = (int)SendMessage(handle, LB_GETSELCOUNT, 0, 0);
 	if(count > 0)
@@ -5275,7 +5294,7 @@
 
 	GetClassName(handle, tmpbuf, 99);
 
-	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 		SendMessage(handle, CB_SETCURSEL, (WPARAM)index, 0);
 	else
 	{
@@ -5293,7 +5312,14 @@
  */
 void API dw_listbox_delete(HWND handle, int index)
 {
-	SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0);
+	char tmpbuf[100];
+
+	GetClassName(handle, tmpbuf, 99);
+
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
+		SendMessage(handle, CB_DELETESTRING, (WPARAM)index, 0);
+	else
+		SendMessage(handle, LB_DELETESTRING, (WPARAM)index, 0);
 }
 
 /*
@@ -5307,7 +5333,7 @@
 
 	GetClassName(handle, tmpbuf, 99);
 
-	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME))==0)
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
 		return (int)SendMessage(handle,
 								CB_GETCOUNT,0L, 0L);
 
@@ -5323,6 +5349,14 @@
  */
 void API dw_listbox_set_top(HWND handle, int top)
 {
+	char tmpbuf[100];
+
+	GetClassName(handle, tmpbuf, 99);
+
+	/* This doesn't work on comboboxes */
+	if(strnicmp(tmpbuf, COMBOBOXCLASSNAME, strlen(COMBOBOXCLASSNAME)+1)==0)
+		return;
+
 	SendMessage(handle, LB_SETTOPINDEX, (WPARAM)top, 0);
 }