1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-09 15:24:12 +01:00

- 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().
This commit is contained in:
dan
2000-10-02 06:59:18 +00:00
parent b2478b634f
commit de99155948
6 changed files with 98 additions and 30 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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);
/* ....................................................................... */

View File

@@ -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; i<bPtr->columnCount; i++) {
WMSetListAllowMultipleSelection(bPtr->columns[i], flag);
}
}
void
WMSetBrowserAllowEmptySelection(WMBrowser *bPtr, Bool flag)
{
int i;
bPtr->flags.allowEmptySelection = flag ? 1 : 0;
for (i=0; i<bPtr->columnCount; 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; i<bPtr->columnCount; 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);

View File

@@ -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);

View File

@@ -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;
int i, keep;
WMListItem *item, *keepItem;
// FIXME: check for allowEmptySelection
keep = lPtr->flags.allowEmptySelection ? 0 : 1;
//keep = lPtr->flags.allowEmptySelection ? 0 : 1;
if (WMGetArrayItemCount(lPtr->selectedItems) == keep)
return;
//if (WMGetArrayItemCount(lPtr->selectedItems) == keep)
// return 1; /* Nothing selected so return */
//keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL);
keepItem = (keep==1 ? WMGetFromArray(lPtr->selectedItems, 0) : NULL);
for (i=0; i<WMGetArrayItemCount(lPtr->items); 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);
}
@@ -881,6 +885,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)
{
@@ -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);