From 399439d338d46e63726e80667488e49868eb29b0 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 2 Oct 2000 11:43:28 +0000 Subject: [PATCH] Better behavior for the multiple selection in lists. --- WINGs/Tests/wtest.c | 6 +---- WINGs/wlist.c | 59 ++++++++++++++++++++++++++++++--------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index 9886b95e..9d717d68 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -130,10 +130,6 @@ doubleClick(WMWidget *self, void *data) char buf[255]; WMSelectAllListItems(lPtr); - - //sprintf(buf, "Selected items: %d", - // WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));; - //WMSetLabelText(label, buf); } @@ -145,7 +141,7 @@ listSelectionObserver(void *observer, WMNotification *notification) char buf[255]; sprintf(buf, "Selected items: %d", - WMGetArrayItemCount(WMGetListSelectedItems(lPtr)));; + WMGetArrayItemCount(WMGetListSelectedItems(lPtr))); WMSetLabelText(label, buf); } diff --git a/WINGs/wlist.c b/WINGs/wlist.c index 27cbcb0c..aeaa7d85 100644 --- a/WINGs/wlist.c +++ b/WINGs/wlist.c @@ -62,6 +62,8 @@ static void vScrollCallBack(WMWidget *scroller, void *self); static void updateGeometry(WMList *lPtr); static void didResizeList(); +static void unselectAllListItems(WMList *lPtr, WMListItem *exceptThis); + W_ViewDelegate _ListViewDelegate = { NULL, @@ -650,11 +652,7 @@ WMSelectListItem(WMList *lPtr, int row) if (!lPtr->flags.allowMultipleSelection) { /* unselect previous selected items */ - int foo = lPtr->flags.allowEmptySelection; - - lPtr->flags.allowEmptySelection = 1; - WMUnselectAllListItems(lPtr); - lPtr->flags.allowEmptySelection = foo; + unselectAllListItems(lPtr, NULL); } /* select item */ @@ -838,23 +836,25 @@ WMSelectAllListItems(WMList *lPtr) WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL); } - -void -WMUnselectAllListItems(WMList *lPtr) +/* + * Be careful from where you call this function! It doesn't honor the + * allowEmptySelection flag and doesn't send a notification about selection + * change! You need to manage these in the functions from where you call it. + * + * This will unselect all items if exceptThis is NULL, else will keep + * exceptThis selected. + * Make sure that exceptThis is one of the already selected items if not NULL! + * + */ +static void +unselectAllListItems(WMList *lPtr, WMListItem *exceptThis) { - int i, keep; - WMListItem *item, *keepItem; - - keep = lPtr->flags.allowEmptySelection ? 0 : 1; - - if (WMGetArrayItemCount(lPtr->selectedItems) == keep) - return; - - keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL); + int i; + WMListItem *item; for (i=0; iitems); i++) { item = WMGetFromArray(lPtr->items, i); - if (item!=keepItem && item->selected) { + if (item!=exceptThis && item->selected) { item->selected = 0; if (lPtr->view->flags.mapped && i>=lPtr->topItem && i<=lPtr->topItem+lPtr->fullFitLines) { @@ -864,8 +864,27 @@ WMUnselectAllListItems(WMList *lPtr) } WMEmptyArray(lPtr->selectedItems); - if (keepItem!=NULL) - WMAddToArray(lPtr->selectedItems, keepItem); + if (exceptThis!=NULL) { + exceptThis->selected = 1; + WMAddToArray(lPtr->selectedItems, exceptThis); + } +} + + +void +WMUnselectAllListItems(WMList *lPtr) +{ + int keep; + WMListItem *keepItem; + + keep = lPtr->flags.allowEmptySelection ? 0 : 1; + + if (WMGetArrayItemCount(lPtr->selectedItems) == keep) + return; + + keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL); + + unselectAllListItems(lPtr, keepItem); WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL); }