rem: item = WMGetFromArray(lPtr->items, tmp); if (item && item->selected) { WMUnselectListItem(lPtr, tmp); } else { WMSelectListItem(lPtr, tmp); }
add: toggleItemSelection(lPtr, tmp);
context: handleActionEvents(XEvent *event, void *data){    List *lPtr = (List*)data;    int tmp;    int topItem = lPtr->topItem;    static int lastClicked = -1, prevItem = -1;    CHECK_CLASS(data, WC_List);    switch (event->type) {    case ButtonRelease:        /* Ignore mouse wheel events, they're not "real" button events */        if (event->xbutton.button == WINGsConfiguration.mouseWheelUp ||            event->xbutton.button == WINGsConfiguration.mouseWheelDown) {            break;        }        lPtr->flags.buttonPressed = 0;        tmp = getItemIndexAt(lPtr, event->xbutton.y);        if (tmp >= 0) {            if (lPtr->action)                (*lPtr->action)(lPtr, lPtr->clientData);        }        if (!(event->xbutton.state & ShiftMask))            lastClicked = prevItem = tmp;        break;    case EnterNotify:        lPtr->flags.buttonPressed = lPtr->flags.buttonWasPressed;        lPtr->flags.buttonWasPressed = 0;        break;    case LeaveNotify:        lPtr->flags.buttonWasPressed = lPtr->flags.buttonPressed;        lPtr->flags.buttonPressed = 0;        break;    case ButtonPress:        if (event->xbutton.x <= WMWidgetWidth(lPtr->vScroller))            break;        if (event->xbutton.button == WINGsConfiguration.mouseWheelDown ||            event->xbutton.button == WINGsConfiguration.mouseWheelUp) {            int amount = 0;            if (event->xbutton.state & ControlMask) {                amount = lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1;            } else if (event->xbutton.state & ShiftMask) {                amount = 1;            } else {                amount = lPtr->fullFitLines / 3;                if (amount == 0)                    amount++;            }            if (event->xbutton.button == WINGsConfiguration.mouseWheelUp)                amount = -amount;            scrollByAmount(lPtr, amount);            break;        }        tmp = getItemIndexAt(lPtr, event->xbutton.y);        lPtr->flags.buttonPressed = 1;        if (tmp >= 0) {            if (tmp == lastClicked && WMIsDoubleClick(event)) {                WMSelectListItem(lPtr, tmp);                if (lPtr->doubleAction)                    (*lPtr->doubleAction)(lPtr, lPtr->doubleClientData);            } else {                if (!lPtr->flags.allowMultipleSelection) {                    WMSelectListItem(lPtr, tmp);                } else {                    WMRange range;                    WMListItem *item, *lastSel;                    if (event->xbutton.state & ControlMask) {                        item = WMGetFromArray(lPtr->items, tmp);                        if (item && item->selected) {                            WMUnselectListItem(lPtr, tmp);                        } else {                            WMSelectListItem(lPtr, tmp);                        }                    } else if (event->xbutton.state & ShiftMask) {                        if (WMGetArrayItemCount(lPtr->selectedItems) == 0) {                            WMSelectListItem(lPtr, tmp);                        } else {                            lastSel = WMGetFromArray(lPtr->items, lastClicked);                            range.position = WMGetFirstInArray(lPtr->items,                                                               lastSel);                            if (tmp >= range.position)                                range.count = tmp - range.position + 1;                            else                                range.count = tmp - range.position - 1;                            WMSetListSelectionToRange(lPtr, range);                        }                    } else {                        range.position = tmp;                        range.count = 1;                        WMSetListSelectionToRange(lPtr, range);                    }                }            }        }        if (!(event->xbutton.state & ShiftMask))            lastClicked = prevItem = tmp;        break;    case MotionNotify:        if (lPtr->flags.buttonPressed) {            tmp = getItemIndexAt(lPtr, event->xmotion.y);            if (tmp>=0 && tmp!=prevItem) {                if (lPtr->flags.allowMultipleSelection) {                    WMRange range;                    range.position = lastClicked;                    if (tmp >= lastClicked)                        range.count = tmp - lastClicked + 1;                    else                        range.count = tmp - lastClicked - 1;                    WMSetListSelectionToRange(lPtr, range);                } else {                    WMSelectListItem(lPtr, tmp);                }            }            prevItem = tmp;        }        break;    }    if (lPtr->topItem != topItem)        WMPostNotificationName(WMListDidScrollNotification, lPtr, NULL);}