From de991559486514dd186ce690a693114a0ab3744a Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 2 Oct 2000 06:59:18 +0000 Subject: [PATCH] - Fixed some issues with WMBrowser and the file panel that were introduced by the latest changes in the WMList code (multiple and empty selection). - added WMSetBrowserAllowMultipleSelection(), WMSetBrowserAllowEmptySelection() WMBrowserAllowsMultipleSelection() and WMBrowserAllowsEmptySelection(). --- WINGs/TODO | 7 +++++-- WINGs/Tests/wtest.c | 2 ++ WINGs/WINGs.h | 13 +++++++++++-- WINGs/wbrowser.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- WINGs/wfilepanel.c | 1 + WINGs/wlist.c | 52 ++++++++++++++++++++++++++++++++++------------------ 6 files changed, 98 insertions(+), 30 deletions(-) diff --git a/WINGs/TODO b/WINGs/TODO index fc04d50a..acd68062 100644 --- a/WINGs/TODO +++ b/WINGs/TODO @@ -1,7 +1,10 @@ - move paint to idle handlers -- finish the multiple selection code for lists (check for - allowEmptySelection and add handlers for scrolling while drag-selecting). +- finish the multiple selection code for lists (check for add handlers for + scrolling while drag-selecting). - check whether WMDestroyWidget() should first call WMUnmapWidget(). +- check if its useful to add some WMBrowserSelectionDidChangeNotification + (actually a pass-through for WMListSelectionDidChangeNotification). + Or a delegate to be called when the list selection change. - optimize color allocation for repeated colors diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index c30c061e..9886b95e 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -183,6 +183,7 @@ testList(WMScreen *scr) WMSetLabelText(mtitle, "Multiple selection list"); list = WMCreateList(win); + //WMSetListAllowEmptySelection(list, True); WMMoveWidget(list, 10, 40); for (i=0; i<50; i++) { sprintf(text, "Item %i", i); @@ -190,6 +191,7 @@ testList(WMScreen *scr) } mlist = WMCreateList(win); WMSetListAllowMultipleSelection(mlist, True); + //WMSetListAllowEmptySelection(mlist, True); WMMoveWidget(mlist, 210, 40); for (i=0; i<135; i++) { sprintf(text, "Item %i", i); diff --git a/WINGs/WINGs.h b/WINGs/WINGs.h index 1ed9a154..ff562e23 100644 --- a/WINGs/WINGs.h +++ b/WINGs/WINGs.h @@ -1152,6 +1152,10 @@ extern char *WMListSelectionDidChangeNotification; WMBrowser *WMCreateBrowser(WMWidget *parent); +void WMSetBrowserAllowMultipleSelection(WMBrowser *bPtr, Bool flag); + +void WMSetBrowserAllowEmptySelection(WMBrowser *bPtr, Bool flag); + void WMSetBrowserPathSeparator(WMBrowser *bPtr, char *separator); void WMSetBrowserTitled(WMBrowser *bPtr, Bool flag); @@ -1176,9 +1180,9 @@ void WMSortBrowserColumnWithComparer(WMBrowser *bPtr, int column, /* Don't free the returned string. */ char* WMSetBrowserPath(WMBrowser *bPtr, char *path); -/* you can free the returned string */ +/* free the returned string */ char *WMGetBrowserPath(WMBrowser *bPtr); -/* you can free the returned string */ +/* free the returned string */ char *WMGetBrowserPathToColumn(WMBrowser *bPtr, int column); void WMSetBrowserAction(WMBrowser *bPtr, WMAction *action, void *clientData); @@ -1202,6 +1206,11 @@ WMList *WMGetBrowserListInColumn(WMBrowser *bPtr, int column); void WMSetBrowserDelegate(WMBrowser *bPtr, WMBrowserDelegate *delegate); +Bool WMBrowserAllowsMultipleSelection(WMBrowser *bPtr); + +Bool WMBrowserAllowsEmptySelection(WMBrowser *bPtr); + + /* ....................................................................... */ diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c index 3c0c2d08..7c0f21b9 100644 --- a/WINGs/wbrowser.c +++ b/WINGs/wbrowser.c @@ -41,7 +41,8 @@ typedef struct W_Browser { struct { unsigned int isTitled:1; - unsigned int allowMultipleSelection:1; + unsigned int allowMultipleSelection:1; + unsigned int allowEmptySelection:1; unsigned int hasScroller:1; /* */ @@ -150,6 +151,30 @@ WMCreateBrowser(WMWidget *parent) } +void +WMSetBrowserAllowMultipleSelection(WMBrowser *bPtr, Bool flag) +{ + int i; + + bPtr->flags.allowMultipleSelection = flag ? 1 : 0; + for (i=0; icolumnCount; i++) { + WMSetListAllowMultipleSelection(bPtr->columns[i], flag); + } +} + + +void +WMSetBrowserAllowEmptySelection(WMBrowser *bPtr, Bool flag) +{ + int i; + + bPtr->flags.allowEmptySelection = flag ? 1 : 0; + for (i=0; icolumnCount; i++) { + WMSetListAllowEmptySelection(bPtr->columns[i], flag); + } +} + + int WMGetBrowserMaxVisibleColumns(WMBrowser *bPtr) { @@ -794,6 +819,20 @@ WMGetBrowserPathToColumn(WMBrowser *bPtr, int column) } +Bool +WMBrowserAllowsMultipleSelection(WMBrowser *bPtr) +{ + return bPtr->flags.allowMultipleSelection; +} + + +Bool +WMBrowserAllowsEmptySelection(WMBrowser *bPtr) +{ + return bPtr->flags.allowEmptySelection; +} + + static void loadColumn(WMBrowser *bPtr, int column) { @@ -931,12 +970,8 @@ listCallback(void *self, void *clientData) int i; item = WMGetListSelectedItem(lPtr); - if (!item) { - oldItem = item; - return; - } - if (oldItem != item) { + if (oldItem==NULL || oldItem!=item) { for (i=0; icolumnCount; i++) { if (lPtr == bPtr->columns[i]) break; @@ -948,7 +983,7 @@ listCallback(void *self, void *clientData) /* columns at right must be cleared */ removeColumn(bPtr, i+1); /* open directory */ - if (item->isBranch) { + if (item && item->isBranch) { WMAddBrowserColumn(bPtr); } if (bPtr->usedColumnCount < bPtr->maxVisibleColumns) @@ -956,7 +991,7 @@ listCallback(void *self, void *clientData) else i = bPtr->usedColumnCount-bPtr->maxVisibleColumns; scrollToColumn(bPtr, i, True); - if (item->isBranch) { + if (item && item->isBranch) { loadColumn(bPtr, bPtr->usedColumnCount-1); } } @@ -1090,6 +1125,8 @@ WMAddBrowserColumn(WMBrowser *bPtr) bPtr->titles[index] = NULL; list = WMCreateList(bPtr); + WMSetListAllowMultipleSelection(list, bPtr->flags.allowMultipleSelection); + WMSetListAllowEmptySelection(list, bPtr->flags.allowEmptySelection); WMSetListAction(list, listCallback, bPtr); WMSetListDoubleAction(list, listDoubleCallback, bPtr); WMSetListUserDrawProc(list, paintItem); diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 598da262..c8974979 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -214,6 +214,7 @@ makeFilePanel(WMScreen *scrPtr, char *name, char *title) WMSetFrameRelief(fPtr->line, WRGroove); fPtr->browser = WMCreateBrowser(fPtr->win); + WMSetBrowserAllowEmptySelection(fPtr->browser, True); WMSetBrowserDelegate(fPtr->browser, &browserDelegate); WMSetBrowserAction(fPtr->browser, browserClick, fPtr); WMSetBrowserDoubleAction(fPtr->browser, browserDClick, fPtr); diff --git a/WINGs/wlist.c b/WINGs/wlist.c index 9fed3aea..27cbcb0c 100644 --- a/WINGs/wlist.c +++ b/WINGs/wlist.c @@ -135,7 +135,6 @@ void WMSetListAllowMultipleSelection(WMList *lPtr, Bool flag) { lPtr->flags.allowMultipleSelection = flag ? 1 : 0; - } @@ -651,7 +650,11 @@ 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; } /* select item */ @@ -839,21 +842,19 @@ WMSelectAllListItems(WMList *lPtr) void WMUnselectAllListItems(WMList *lPtr) { - int i;//, keep; - WMListItem *item;//, *keepItem; - - // FIXME: check for allowEmptySelection + int i, keep; + WMListItem *item, *keepItem; - //keep = lPtr->flags.allowEmptySelection ? 0 : 1; + keep = lPtr->flags.allowEmptySelection ? 0 : 1; - //if (WMGetArrayItemCount(lPtr->selectedItems) == keep) - // return 1; /* Nothing selected so return */ + if (WMGetArrayItemCount(lPtr->selectedItems) == keep) + return; - //keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL); + keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL); for (i=0; iitems); i++) { item = WMGetFromArray(lPtr->items, i); - if (item->selected) { + if (item!=keepItem && item->selected) { item->selected = 0; if (lPtr->view->flags.mapped && i>=lPtr->topItem && i<=lPtr->topItem+lPtr->fullFitLines) { @@ -863,6 +864,9 @@ WMUnselectAllListItems(WMList *lPtr) } WMEmptyArray(lPtr->selectedItems); + if (keepItem!=NULL) + WMAddToArray(lPtr->selectedItems, keepItem); + WMPostNotificationName(WMListSelectionDidChangeNotification, lPtr, NULL); } @@ -882,6 +886,19 @@ getItemIndexAt(List *lPtr, int clickY) static void +toggleItemSelection(WMList *lPtr, int index) +{ + WMListItem *item = WMGetFromArray(lPtr->items, index); + + if (item && item->selected) { + WMUnselectListItem(lPtr, index); + } else { + WMSelectListItem(lPtr, index); + } +} + + +static void handleActionEvents(XEvent *event, void *data) { List *lPtr = (List*)data; @@ -955,18 +972,17 @@ handleActionEvents(XEvent *event, void *data) (*lPtr->doubleAction)(lPtr, lPtr->doubleClientData); } else { if (!lPtr->flags.allowMultipleSelection) { - WMSelectListItem(lPtr, tmp); + if (event->xbutton.state & ControlMask) { + toggleItemSelection(lPtr, tmp); + } else { + WMSelectListItem(lPtr, tmp); + } } else { WMRange range; - WMListItem *item, *lastSel; + WMListItem *lastSel; if (event->xbutton.state & ControlMask) { - item = WMGetFromArray(lPtr->items, tmp); - if (item && item->selected) { - WMUnselectListItem(lPtr, tmp); - } else { - WMSelectListItem(lPtr, tmp); - } + toggleItemSelection(lPtr, tmp); } else if (event->xbutton.state & ShiftMask) { if (WMGetArrayItemCount(lPtr->selectedItems) == 0) { WMSelectListItem(lPtr, tmp); -- 2.11.4.GIT