From 9105b9cab31678606f19b3d7b48678fa2605d3ab Mon Sep 17 00:00:00 2001 From: "pollmann%netscape.com" Date: Wed, 10 Mar 1999 22:52:55 +0000 Subject: [PATCH] Checking in GetSelectedItem, GetSelectedIndices, and SetSelectedIndices methods. This enables submission of a listbox's value for Linux. (wahoo!) --- widget/src/gtk/nsListBox.cpp | 65 +++++++++++++++++------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/widget/src/gtk/nsListBox.cpp b/widget/src/gtk/nsListBox.cpp index 70f0151a6b3..0e18e5381a4 100644 --- a/widget/src/gtk/nsListBox.cpp +++ b/widget/src/gtk/nsListBox.cpp @@ -187,8 +187,9 @@ PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition) if (text) { anItem.SetLength(0); anItem.Append(text); + result = PR_TRUE; } - return PR_TRUE; + return result; #if 0 XmStringTable list; @@ -216,15 +217,21 @@ PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition) //------------------------------------------------------------------------- NS_METHOD nsListBox::GetSelectedItem(nsString& aItem) { -#if 0 - int * list; - int count; + PRInt32 i=0, index=-1; + GtkCList *clist = GTK_CLIST(mCList); + GList *list = clist->row_list; - if (XmListGetSelectedPos(mCList, &list, &count)) { - GetItemAt(aItem, list[0]-1); - XtFree((char *)list); + for (i=0; i < clist->rows && index == -1; i++, list = list->next) { + if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) { + char *text = nsnull; + gtk_clist_get_text(GTK_CLIST(mCList),i,0,&text); + if (text) { + aItem.SetLength(0); + aItem.Append(text); + } + return NS_OK; + } } -#endif return NS_OK; } @@ -235,24 +242,21 @@ NS_METHOD nsListBox::GetSelectedItem(nsString& aItem) //------------------------------------------------------------------------- PRInt32 nsListBox::GetSelectedIndex() { -#if 0 + PRInt32 i=0, index=-1; if (!mMultiSelect) { - int * list; - int count; + GtkCList *clist = GTK_CLIST(mCList); + GList *list = clist->row_list; - if (XmListGetSelectedPos(mCList, &list, &count)) { - int index = -1; - if (count > 0) { - index = list[0]-1; + for (i=0; i < clist->rows && index == -1; i++, list = list->next) { + if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) { + index = i; } - XtFree((char *)list); - return index; } } else { NS_ASSERTION(PR_FALSE, "Multi selection list box does not support GetSelectedIndex()"); } -#endif - return -1; + + return index; } //------------------------------------------------------------------------- @@ -290,19 +294,16 @@ PRInt32 nsListBox::GetSelectedCount() //------------------------------------------------------------------------- NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) { -#if 0 - int * list; - int count; + PRInt32 i=0, num = 0; + GtkCList *clist = GTK_CLIST(mCList); + GList *list = clist->row_list; - if (XmListGetSelectedPos(mCList, &list, &count)) { - int num = aSize > count?count:aSize; - int i; - for (i=0;irows && num < aSize; i++, list = list->next) { + if (GTK_CLIST_ROW (list)->state == GTK_STATE_SELECTED) { + aIndices[i] = (PRInt32)i; + num++; } - XtFree((char *)list); } -#endif return NS_OK; } @@ -313,15 +314,11 @@ NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) //------------------------------------------------------------------------- NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) { -#if 0 - if (GetSelectedCount() > 0) { - XtVaSetValues(mCList, XmNselectedItemCount, 0, NULL); - } + gtk_clist_unselect_all(GTK_CLIST(mCList)); int i; for (i=0;i