From e82c30b205a8c82cd7cdec81eb89b9da9fd53bfd Mon Sep 17 00:00:00 2001 From: kojima Date: Sun, 3 Oct 1999 03:47:21 +0000 Subject: [PATCH] replaced linked list with WMBag in WMList replaced WMAddSorted*** with WMSort*** fixed crash bug in icon chooser --- WINGs/ChangeLog | 5 +- WINGs/Makefile.in | 2 +- WINGs/Resources/Makefile.in | 2 +- WINGs/WINGs.h | 13 +- WINGs/WINGsP.h | 2 +- WINGs/wbrowser.c | 14 +- WINGs/wfilepanel.c | 28 +- WINGs/wfontpanel.c | 3 +- WINGs/wlist.c | 265 +++++++---------- WINGs/wprogressindicator.c | 597 +++++++++++++++++++-------------------- WindowMaker/IconSets/Makefile.in | 2 +- WindowMaker/Makefile.in | 2 +- src/dialog.c | 10 +- wrlib/Makefile.in | 2 +- 14 files changed, 436 insertions(+), 511 deletions(-) rewrite WINGs/wprogressindicator.c (69%) diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index e232f303..52208c78 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -5,7 +5,10 @@ changes since wmaker 0.61.0: - escape key in panels (craig nellist ) - applied patch with fixes and enhancements to textfield (Franck Wolff ) - +- changed WMList to use WMBag internally, instead of a linked list +- replaced WMAddSortedListItem() with WMSortListItems() +- replaced WMAddSortedBrowserItem() with WMSortBrowserColumn() +- added WMGetListItems() changes since wmaker 0.60.0: ............................ diff --git a/WINGs/Makefile.in b/WINGs/Makefile.in index fbbda38c..9c384268 100644 --- a/WINGs/Makefile.in +++ b/WINGs/Makefile.in @@ -206,7 +206,7 @@ DIST_COMMON = README ChangeLog Makefile.am Makefile.in TODO DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = tar +TAR = gtar GZIP_ENV = --best SOURCES = $(libWINGs_a_SOURCES) $(libWUtil_a_SOURCES) $(wtest_SOURCES) $(wmquery_SOURCES) $(wmfile_SOURCES) $(fontl_SOURCES) $(testmywidget_SOURCES) $(testcolorpanel_SOURCES) OBJECTS = $(libWINGs_a_OBJECTS) $(libWUtil_a_OBJECTS) $(wtest_OBJECTS) $(wmquery_OBJECTS) $(wmfile_OBJECTS) $(fontl_OBJECTS) $(testmywidget_OBJECTS) $(testcolorpanel_OBJECTS) diff --git a/WINGs/Resources/Makefile.in b/WINGs/Resources/Makefile.in index 41f26f6e..4a9eaa07 100644 --- a/WINGs/Resources/Makefile.in +++ b/WINGs/Resources/Makefile.in @@ -107,7 +107,7 @@ DIST_COMMON = Makefile.am Makefile.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = tar +TAR = gtar GZIP_ENV = --best all: all-redirect .SUFFIXES: diff --git a/WINGs/WINGs.h b/WINGs/WINGs.h index 7f4d3ba8..be2b2861 100644 --- a/WINGs/WINGs.h +++ b/WINGs/WINGs.h @@ -7,7 +7,7 @@ #include #include -#define WINGS_H_VERSION 990516 +#define WINGS_H_VERSION 991003 #ifdef __cplusplus @@ -327,8 +327,6 @@ typedef struct W_ColorPanel WMColorPanel; typedef struct WMListItem { char *text; void *clientData; /* ptr for user clientdata. */ - - struct WMListItem *nextPtr; unsigned int uflags:16; /* flags for the user */ unsigned int selected:1; @@ -950,12 +948,15 @@ WMList *WMCreateList(WMWidget *parent); WMListItem *WMInsertListItem(WMList *lPtr, int row, char *text); -WMListItem *WMAddSortedListItem(WMList *lPtr, char *text); +void WMSortListItems(WMList *lPtr); int WMFindRowOfListItemWithTitle(WMList *lPtr, char *title); WMListItem *WMGetListItem(WMList *lPtr, int row); +WMBag *WMGetListItems(WMList *lPtr); + + void WMRemoveListItem(WMList *lPtr, int row); void WMSelectListItem(WMList *lPtr, int row); @@ -1006,10 +1007,10 @@ void WMSetBrowserMaxVisibleColumns(WMBrowser *bPtr, int columns); void WMSetBrowserColumnTitle(WMBrowser *bPtr, int column, char *title); -WMListItem *WMAddSortedBrowserItem(WMBrowser *bPtr, int column, char *text, Bool isBranch); - WMListItem *WMInsertBrowserItem(WMBrowser *bPtr, int column, int row, char *text, Bool isBranch); +void WMSortBrowserColumn(WMBrowser *bPtr, int column); + /* Don't free the returned string. */ char* WMSetBrowserPath(WMBrowser *bPtr, char *path); diff --git a/WINGs/WINGsP.h b/WINGs/WINGsP.h index 35e45052..4d252051 100644 --- a/WINGs/WINGsP.h +++ b/WINGs/WINGsP.h @@ -8,7 +8,7 @@ #include "WINGs.h" -#if WINGS_H_VERSION < 990516 +#if WINGS_H_VERSION < 991003 #error There_is_an_old_WINGs.h_file_somewhere_in_your_system._Please_remove_it. #endif diff --git a/WINGs/wbrowser.c b/WINGs/wbrowser.c index 261e89d7..0f5df33a 100644 --- a/WINGs/wbrowser.c +++ b/WINGs/wbrowser.c @@ -433,18 +433,10 @@ WMSetBrowserTitled(WMBrowser *bPtr, Bool flag) } -WMListItem* -WMAddSortedBrowserItem(WMBrowser *bPtr, int column, char *text, Bool isBranch) +void +WMSortBrowserColumn(WMBrowser *bPtr, int column) { - WMListItem *item; - - if (column < 0 || column >= bPtr->columnCount) - return NULL; - - item = WMAddSortedListItem(bPtr->columns[column], text); - item->isBranch = isBranch; - - return item; + WMSortListItems(bPtr->columns[column]); } diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index de907649..97ee2ae4 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -102,22 +102,24 @@ static WMBrowserDelegate browserDelegate = { static int closestListItem(WMList *list, char *text, Bool exact) { - WMListItem *item = WMGetListItem(list, 0); - int i = 0; + WMListItem *item; + WMBag *items = WMGetListItems(list); + int i; int len = strlen(text); if (len==0) return -1; - while (item) { + for (i = 0; i < WMGetBagItemCount(items); i++) { + item = WMGetFromBag(items, i); + if (strlen(item->text) >= len && ((exact && strcmp(item->text, text)==0) || (!exact && strncmp(item->text, text, len)==0))) { return i; } - item = item->nextPtr; - i++; } + return -1; } @@ -576,10 +578,10 @@ listDirectoryOnColumn(WMFilePanel *panel, int column, char *path) isDirectory = S_ISDIR(stat_buf.st_mode); if (filterFileName(panel, dentry->d_name, isDirectory)) - WMAddSortedBrowserItem(bPtr, column, dentry->d_name, - isDirectory); + WMInsertBrowserItem(bPtr, column, -1, dentry->d_name, isDirectory); } } + WMSortBrowserColumn(bPtr, column); closedir(dir); } @@ -646,7 +648,6 @@ createDir(WMButton *bPre, WMFilePanel *panel) char *directory; char *file; char *s; - char *err_str; WMScreen *scr = WMWidgetScreen(panel->win); WMInputPanel *_panel; @@ -680,14 +681,14 @@ createDir(WMButton *bPre, WMFilePanel *panel) if (directory_name[0] == '/') { directory[0] = 0; } else { - while (s = strstr(directory,"//")) { + while ((s = strstr(directory,"//"))) { int i; for (i = 2;s[i] == '/';i++); strcpy(s, &s[i-1]); } if ((s = strrchr(directory, '/')) && !s[1]) s[0] = 0; } - while (s = strstr(directory_name,"//")) { + while ((s = strstr(directory_name,"//"))) { int i; for (i = 2;s[i] == '/';i++); strcpy(s, &s[i-1]); @@ -696,7 +697,7 @@ createDir(WMButton *bPre, WMFilePanel *panel) file = wmalloc(strlen(directory_name)+strlen(directory)+1); sprintf(file, "%s/%s", directory, directory_name); - while (s = strstr(file,"//")) { + while ((s = strstr(file,"//"))) { int i; for (i = 2;s[i] == '/';i++); strcpy(s, &s[i-1]); @@ -727,13 +728,12 @@ deleteFile(WMButton *bPre, WMFilePanel *panel) { char *file; char *buffer, *s; - char *err_str; struct stat filestat; WMScreen *scr = WMWidgetScreen(panel->win); file = getCurrentFileName(panel); - while (s = strstr(file,"//")) { + while ((s = strstr(file,"//"))) { int i; for (i = 2;s[i] == '/';i++); strcpy(s, &s[i-1]); @@ -835,7 +835,7 @@ goUnmount(WMButton *bPtr, WMFilePanel *panel) static void goFloppy(WMButton *bPtr, WMFilePanel *panel) { - char *file, *err_str; + char *file; struct stat filestat; WMScreen *scr = WMWidgetScreen(panel->win); diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c index 2261457a..85e90824 100644 --- a/WINGs/wfontpanel.c +++ b/WINGs/wfontpanel.c @@ -748,12 +748,13 @@ listFamilies(WMScreen *scr, WMFontPanel *panel) strcat(buffer, fam->encoding); strcat(buffer, ")"); } - item = WMAddSortedListItem(panel->famLs, buffer); + item = WMAddListItem(panel->famLs, buffer); item->clientData = fam; } WMFreeBag(bag); } + WMSortListItems(panel->famLs); WMFreeHashTable(families); } diff --git a/WINGs/wlist.c b/WINGs/wlist.c index d86de02f..94144665 100644 --- a/WINGs/wlist.c +++ b/WINGs/wlist.c @@ -11,8 +11,7 @@ typedef struct W_List { W_Class widgetClass; W_View *view; - WMListItem *items; /* array of items */ - short itemCount; + WMBag *items; /* list of WMListItem */ short selectedItem; @@ -107,7 +106,9 @@ WMCreateList(WMWidget *parent) handleActionEvents, lPtr); lPtr->itemHeight = WMFontHeight(scrPtr->normalFont) + 1; - + + lPtr->items = WMCreateBag(4); + /* create the vertical scroller */ lPtr->vScroller = WMCreateScroller(lPtr); WMMoveWidget(lPtr->vScroller, 1, 1); @@ -126,60 +127,27 @@ WMCreateList(WMWidget *parent) } - -WMListItem* -WMAddSortedListItem(WMList *lPtr, char *text) +static int +comparator(const void *a, const void *b) { - WMListItem *item; - WMListItem *tmp; - int index; - - item = wmalloc(sizeof(WMListItem)); - memset(item, 0, sizeof(WMListItem)); - item->text = wstrdup(text); - if (!lPtr->items) { - lPtr->items = item; - index = 0; - } else if (strcmp(lPtr->items->text, text) > 0) { - item->nextPtr = lPtr->items; - lPtr->items = item; - index = 1; - } else { - int added = 0; - - index = 0; - tmp = lPtr->items; - while (tmp->nextPtr) { - if (strcmp(tmp->nextPtr->text, text) >= 0) { - item->nextPtr = tmp->nextPtr; - tmp->nextPtr = item; - added = 1; - break; - } - index++; - tmp = tmp->nextPtr; - } - if (!added) { - tmp->nextPtr = item; - } - } - - if (index < lPtr->fullFitLines+lPtr->flags.dontFitAll-lPtr->topItem) { - paintList(lPtr); - } - - lPtr->itemCount++; + WMListItem *item1 = (WMListItem*)a; + WMListItem *item2 = (WMListItem*)b; - if (lPtr->selectedItem >= index) - lPtr->selectedItem++; + if (strcmp(item1->text, item2->text) < 0) + return -1; + else if (strcmp(item1->text, item2->text) > 0) + return 1; + else + return 0; +} - /* update the scroller when idle, so that we don't waste time - * updating it when another item is going to be added later */ - if (!lPtr->idleID) { - lPtr->idleID = WMAddIdleHandler((WMCallback*)updateScroller, lPtr); - } - return item; +void +WMSortListItems(WMList *lPtr) +{ + WMSortBag(lPtr->items, comparator); + + paintList(lPtr); } @@ -188,7 +156,6 @@ WMListItem* WMInsertListItem(WMList *lPtr, int row, char *text) { WMListItem *item; - WMListItem *tmp = lPtr->items; CHECK_CLASS(lPtr, WC_List); @@ -200,32 +167,16 @@ WMInsertListItem(WMList *lPtr, int row, char *text) if (lPtr->selectedItem >= row && lPtr->selectedItem >= 0 && row >= 0) lPtr->selectedItem++; + + if (row < 0) + row = WMGetBagItemCount(lPtr->items); - if (lPtr->items==NULL) { - lPtr->items = item; - } else if (row == 0) { - item->nextPtr = lPtr->items; - lPtr->items = item; - } else if (row < 0) { - while (tmp->nextPtr) - tmp = tmp->nextPtr; - - tmp->nextPtr = item; - row = lPtr->itemCount; - } else { - while (--row > 0) - tmp = tmp->nextPtr; - - item->nextPtr = tmp->nextPtr; - tmp->nextPtr = item; - } + WMInsertInBag(lPtr->items, row, item); if (row < lPtr->fullFitLines+lPtr->flags.dontFitAll-lPtr->topItem) { paintList(lPtr); } - lPtr->itemCount++; - /* update the scroller when idle, so that we don't waste time * updating it when another item is going to be added later */ if (!lPtr->idleID) { @@ -239,14 +190,13 @@ WMInsertListItem(WMList *lPtr, int row, char *text) void WMRemoveListItem(WMList *lPtr, int row) { - WMListItem *llist; - WMListItem *tmp; + WMListItem *item; int topItem = lPtr->topItem; int selNotify = 0; CHECK_CLASS(lPtr, WC_List); - if (row < 0 || row >= lPtr->itemCount) + if (row < 0 || row >= WMGetBagItemCount(lPtr->items)) return; if (lPtr->selectedItem == row) { @@ -261,28 +211,12 @@ WMRemoveListItem(WMList *lPtr, int row) if (lPtr->topItem < 0) lPtr->topItem = 0; - if (row == 0) { - if (lPtr->items->text) - free(lPtr->items->text); - - tmp = lPtr->items->nextPtr; - free(lPtr->items); - - lPtr->items = tmp; - } else { - llist = lPtr->items; - while (--row > 0) - llist = llist->nextPtr; - tmp = llist->nextPtr; - llist->nextPtr = llist->nextPtr->nextPtr; - - if (tmp->text) - free(tmp->text); + item = WMGetFromBag(lPtr->items, row); + if (item->text) + free(item->text); + free(item); - free(tmp); - } - - lPtr->itemCount--; + WMDeleteFromBag(lPtr->items, row); if (!lPtr->idleID) { lPtr->idleID = WMAddIdleHandler((WMCallback*)updateScroller, lPtr); @@ -299,14 +233,14 @@ WMRemoveListItem(WMList *lPtr, int row) WMListItem* WMGetListItem(WMList *lPtr, int row) { - WMListItem *listPtr; + return WMGetFromBag(lPtr->items, row); +} - listPtr = lPtr->items; - - while (row-- > 0) - listPtr = listPtr->nextPtr; - - return listPtr; + +WMBag* +WMGetListItems(WMList *lPtr) +{ + return lPtr->items; } @@ -334,18 +268,17 @@ WMSetListUserDrawItemHeight(WMList *lPtr, unsigned short height) void WMClearList(WMList *lPtr) { - WMListItem *item, *tmp; + WMListItem *item; int oldSelected = lPtr->selectedItem; + int i; - item = lPtr->items; - while (item) { + for (i = 0; i < WMGetBagItemCount(lPtr->items); i++) { + item = WMGetFromBag(lPtr->items, i); free(item->text); - tmp = item->nextPtr; free(item); - item = tmp; } - lPtr->items = NULL; - lPtr->itemCount = 0; + WMEmptyBag(lPtr->items); + lPtr->topItem = 0; lPtr->selectedItem = -1; @@ -380,18 +313,11 @@ WMSetListDoubleAction(WMList *lPtr, WMAction *action, void *clientData) WMListItem* WMGetListSelectedItem(WMList *lPtr) -{ - int i = lPtr->selectedItem; - WMListItem *item; - +{ if (lPtr->selectedItem < 0) return NULL; - - item = lPtr->items; - while (i-- > 0) { - item = item->nextPtr; - } - return item; + + return WMGetFromBag(lPtr->items, lPtr->selectedItem); } @@ -413,8 +339,8 @@ void WMSetListPosition(WMList *lPtr, int row) { lPtr->topItem = row; - if (lPtr->topItem + lPtr->fullFitLines > lPtr->itemCount) - lPtr->topItem = lPtr->itemCount - lPtr->fullFitLines; + if (lPtr->topItem + lPtr->fullFitLines > WMGetBagItemCount(lPtr->items)) + lPtr->topItem = WMGetBagItemCount(lPtr->items) - lPtr->fullFitLines; if (lPtr->topItem < 0) lPtr->topItem = 0; @@ -427,7 +353,7 @@ WMSetListPosition(WMList *lPtr, int row) void WMSetListBottomPosition(WMList *lPtr, int row) { - if (lPtr->itemCount > lPtr->fullFitLines) { + if (WMGetBagItemCount(lPtr->items) > lPtr->fullFitLines) { lPtr->topItem = row - lPtr->fullFitLines; if (lPtr->topItem < 0) lPtr->topItem = 0; @@ -440,7 +366,7 @@ WMSetListBottomPosition(WMList *lPtr, int row) int WMGetListNumberOfRows(WMList *lPtr) { - return lPtr->itemCount; + return WMGetBagItemCount(lPtr->items); } int @@ -457,6 +383,7 @@ vScrollCallBack(WMWidget *scroller, void *self) WMScroller *sPtr = (WMScroller*)scroller; int height; int topItem = lPtr->topItem; + int itemCount = WMGetBagItemCount(lPtr->items); height = lPtr->view->size.height - 4; @@ -481,7 +408,7 @@ vScrollCallBack(WMWidget *scroller, void *self) case WSIncrementLine: - if (lPtr->topItem + lPtr->fullFitLines < lPtr->itemCount) { + if (lPtr->topItem + lPtr->fullFitLines < itemCount) { lPtr->topItem++; updateScroller(lPtr); @@ -489,11 +416,11 @@ vScrollCallBack(WMWidget *scroller, void *self) break; case WSIncrementPage: - if (lPtr->topItem + lPtr->fullFitLines < lPtr->itemCount) { + if (lPtr->topItem + lPtr->fullFitLines < itemCount) { lPtr->topItem += lPtr->fullFitLines-(1-lPtr->flags.dontFitAll)-1; - if (lPtr->topItem + lPtr->fullFitLines > lPtr->itemCount) - lPtr->topItem = lPtr->itemCount - lPtr->fullFitLines; + if (lPtr->topItem + lPtr->fullFitLines > itemCount) + lPtr->topItem = itemCount - lPtr->fullFitLines; updateScroller(lPtr); } @@ -504,7 +431,7 @@ vScrollCallBack(WMWidget *scroller, void *self) int oldTopItem = lPtr->topItem; lPtr->topItem = WMGetScrollerValue(lPtr->vScroller) * - (float)(lPtr->itemCount - lPtr->fullFitLines); + (float)(itemCount - lPtr->fullFitLines); if (oldTopItem != lPtr->topItem) paintList(lPtr); @@ -529,12 +456,10 @@ paintItem(List *lPtr, int index) W_Screen *scr = view->screen; int width, height, x, y; WMListItem *itemPtr; - int i; - i = index; - itemPtr = lPtr->items; - while (i-- > 0) - itemPtr = itemPtr->nextPtr; + + itemPtr = WMGetFromBag(lPtr->items, index); + width = lPtr->view->size.width - 2 - 19; height = lPtr->itemHeight; @@ -567,7 +492,7 @@ paintItem(List *lPtr, int index) width, height); else XClearArea(scr->display, view->window, x, y, width, height, False); - + W_PaintText(view, view->window, scr->normalFont, x+4, y, width, WALeft, WMColorGC(scr->black), False, itemPtr->text, strlen(itemPtr->text)); @@ -585,9 +510,11 @@ paintList(List *lPtr) if (!lPtr->view->flags.mapped) return; - if (lPtr->itemCount>0) { - if (lPtr->topItem+lPtr->fullFitLines+lPtr->flags.dontFitAll > lPtr->itemCount) { - lim = lPtr->itemCount - lPtr->topItem; + if (WMGetBagItemCount(lPtr->items) > 0) { + if (lPtr->topItem+lPtr->fullFitLines+lPtr->flags.dontFitAll + > WMGetBagItemCount(lPtr->items)) { + + lim = WMGetBagItemCount(lPtr->items) - lPtr->topItem; XClearArea(scrPtr->display, lPtr->view->window, 19, 2+lim*lPtr->itemHeight, lPtr->view->size.width-21, lPtr->view->size.height-lim*lPtr->itemHeight-3, False); @@ -616,6 +543,7 @@ static void updateScroller(List *lPtr) { float knobProportion, floatValue, tmp; + int count = WMGetBagItemCount(lPtr->items); if (lPtr->idleID) WMDeleteIdleHandler(lPtr->idleID); @@ -623,14 +551,14 @@ updateScroller(List *lPtr) paintList(lPtr); - if (lPtr->itemCount == 0 || lPtr->itemCount <= lPtr->fullFitLines) + if (count == 0 || count <= lPtr->fullFitLines) WMSetScrollerParameters(lPtr->vScroller, 0, 1); else { tmp = lPtr->fullFitLines; - knobProportion = tmp/(float)lPtr->itemCount; - - floatValue = (float)lPtr->topItem/(float)(lPtr->itemCount - lPtr->fullFitLines); - + knobProportion = tmp/(float)count; + + floatValue = (float)lPtr->topItem/(float)(count - lPtr->fullFitLines); + WMSetScrollerParameters(lPtr->vScroller, floatValue, knobProportion); } } @@ -666,7 +594,8 @@ WMFindRowOfListItemWithTitle(WMList *lPtr, char *title) int i; int ok = 0; - for (i=0, item=lPtr->items; item!=NULL; item=item->nextPtr, i++) { + for (i=0; i < WMGetBagItemCount(lPtr->items); i++) { + item = WMGetFromBag(lPtr->items, i); if (strcmp(item->text, title)==0) { ok = 1; break; @@ -681,9 +610,9 @@ void WMSelectListItem(WMList *lPtr, int row) { WMListItem *itemPtr; - int i, notify = 0; + int notify = 0; - if (row >= lPtr->itemCount) + if (row >= WMGetBagItemCount(lPtr->items)) return; /* the check below must be changed when the multiple selection is @@ -697,15 +626,15 @@ WMSelectListItem(WMList *lPtr, int row) if (!lPtr->flags.allowMultipleSelection) { /* unselect previous selected item */ if (lPtr->selectedItem >= 0) { - itemPtr = lPtr->items; - for (i=0; iselectedItem; i++) - itemPtr = itemPtr->nextPtr; - + itemPtr = WMGetFromBag(lPtr->items, lPtr->selectedItem); + if (itemPtr->selected) { itemPtr->selected = 0; - if (lPtr->view->flags.mapped && i>=lPtr->topItem - && i<=lPtr->topItem+lPtr->fullFitLines) - paintItem(lPtr, i); + if (lPtr->view->flags.mapped + && lPtr->selectedItem>=lPtr->topItem + && lPtr->selectedItem<=lPtr->topItem+lPtr->fullFitLines) { + paintItem(lPtr, lPtr->selectedItem); + } } } } @@ -721,9 +650,8 @@ WMSelectListItem(WMList *lPtr, int row) } /* select item */ - itemPtr = lPtr->items; - for (i=0; inextPtr; + itemPtr = WMGetFromBag(lPtr->items, row); + if (lPtr->flags.allowMultipleSelection) itemPtr->selected = !itemPtr->selected; else @@ -752,7 +680,7 @@ getItemIndexAt(List *lPtr, int clickY) index = (clickY - 2) / lPtr->itemHeight + lPtr->topItem; - if (index < 0 || index >= lPtr->itemCount) + if (index < 0 || index >= WMGetBagItemCount(lPtr->items)) return -1; return index; @@ -830,8 +758,8 @@ updateGeometry(WMList *lPtr) lPtr->flags.dontFitAll = 0; } - if (lPtr->itemCount - lPtr->topItem <= lPtr->fullFitLines) { - lPtr->topItem = lPtr->itemCount - lPtr->fullFitLines; + if (WMGetBagItemCount(lPtr->items) - lPtr->topItem <= lPtr->fullFitLines) { + lPtr->topItem = WMGetBagItemCount(lPtr->items) - lPtr->fullFitLines; if (lPtr->topItem < 0) lPtr->topItem = 0; } @@ -854,20 +782,19 @@ didResizeList(W_ViewDelegate *self, WMView *view) static void destroyList(List *lPtr) { - WMListItem *itemPtr; + WMListItem *item; + int i; if (lPtr->idleID) WMDeleteIdleHandler(lPtr->idleID); lPtr->idleID = NULL; - while (lPtr->items!=NULL) { - itemPtr = lPtr->items; - if (itemPtr->text) - free(itemPtr->text); - - lPtr->items = itemPtr->nextPtr; - free(itemPtr); + for (i = 0; i < WMGetBagItemCount(lPtr->items); i++) { + item = WMGetFromBag(lPtr->items, i); + free(item->text); + free(item); } + WMFreeBag(lPtr->items); free(lPtr); } diff --git a/WINGs/wprogressindicator.c b/WINGs/wprogressindicator.c dissimilarity index 69% index 14a762c7..572212cc 100644 --- a/WINGs/wprogressindicator.c +++ b/WINGs/wprogressindicator.c @@ -1,299 +1,298 @@ -/* - * Original idea and implementation by Frederik Schueler - * Rewritten by Pascal Hofstee - * - Added options to set min/max values - * - centralized drawing into one pain function - */ - -#include "WINGsP.h" - -typedef struct W_ProgressIndicator { - W_Class widgetClass; - W_View *view; - - int value; - int minValue; - int maxValue; - - void *clientData; -} ProgressIndicator; - - -#define DEFAULT_PROGRESS_INDICATOR_WIDTH 276 -#define DEFAULT_PROGRESS_INDICATOR_HEIGHT 16 - -/* define if only the ticks within the progress region should be displayed */ -#define SHOW_PROGRESS_TICKS_ONLY - - -static void didResizeProgressIndicator(); - - -W_ViewDelegate _ProgressIndicatorDelegate = { - NULL, - NULL, - didResizeProgressIndicator, - NULL, - NULL -}; - - -static void destroyProgressIndicator(ProgressIndicator *pPtr); -static void paintProgressIndicator(ProgressIndicator *pPtr); -static void realizeProgressIndicator(ProgressIndicator *pPtr); -static void handleEvents(XEvent *event, void *data); - -static void realizeObserver(void *self, WMNotification *not) { - - realizeProgressIndicator(self); -} - - - -WMProgressIndicator* -WMCreateProgressIndicator(WMWidget *parent) -{ - ProgressIndicator *pPtr; - W_Screen *scrPtr = W_VIEW(parent)->screen; - - pPtr = wmalloc(sizeof(ProgressIndicator)); - memset(pPtr, 0, sizeof(ProgressIndicator)); - - pPtr->widgetClass = WC_ProgressIndicator; - - pPtr->view = W_CreateView(W_VIEW(parent)); - if (!pPtr->view) { - free(pPtr); - return NULL; - } - - pPtr->view->self = pPtr; - - pPtr->view->delegate = &_ProgressIndicatorDelegate; - - WMCreateEventHandler(pPtr->view, ExposureMask|StructureNotifyMask, - handleEvents, pPtr); - - - W_ResizeView(pPtr->view, DEFAULT_PROGRESS_INDICATOR_WIDTH, - DEFAULT_PROGRESS_INDICATOR_HEIGHT); - - /* Initialize ProgressIndicator Values */ - pPtr->value = 0; - pPtr->minValue = 0; - pPtr->maxValue = 100; - - WMAddNotificationObserver(realizeObserver, pPtr, - WMViewRealizedNotification, pPtr->view); - - return pPtr; -} - - -void -WMSetProgressIndicatorMinValue(WMProgressIndicator *progressindicator, int value) -{ - CHECK_CLASS(progressindicator, WC_ProgressIndicator); - - progressindicator->minValue = value; - if (progressindicator->value < value) { - progressindicator->value = value; - if (progressindicator->view->flags.mapped) { - paintProgressIndicator(progressindicator); - } - } -} - - -void -WMSetProgressIndicatorMaxValue(WMProgressIndicator *progressindicator, int value) -{ - CHECK_CLASS(progressindicator, WC_ProgressIndicator); - - progressindicator->maxValue = value; - if (progressindicator->value > value) { - progressindicator->value = value; - if (progressindicator->view->flags.mapped) { - paintProgressIndicator(progressindicator); - } - } -} - - -void -WMSetProgressIndicatorValue(WMProgressIndicator *progressindicator, int value) -{ - CHECK_CLASS(progressindicator, WC_ProgressIndicator); - - progressindicator->value = value; - - /* Check if value is within min/max-range */ - if (progressindicator->minValue > value) - progressindicator->value = progressindicator->minValue; - - if (progressindicator->maxValue < value) - progressindicator->value = progressindicator->maxValue; - - - if (progressindicator->view->flags.mapped) { - paintProgressIndicator(progressindicator); - } -} - - -int -WMGetProgressIndicatorMinValue(WMProgressIndicator *progressindicator) -{ - CHECK_CLASS(progressindicator, WC_ProgressIndicator); - - return progressindicator->minValue; -} - - -int -WMGetProgressIndicatorMaxValue(WMProgressIndicator *progressindicator) -{ - CHECK_CLASS(progressindicator, WC_ProgressIndicator); - - return progressindicator->maxValue; -} - - -int -WMGetProgressIndicatorValue(WMProgressIndicator *progressindicator) -{ - CHECK_CLASS(progressindicator, WC_ProgressIndicator); - - return progressindicator->value; -} - - -static void -realizeProgressIndicator(ProgressIndicator *pPtr) -{ - W_RealizeView(pPtr->view); -} - - -static void -didResizeProgressIndicator(W_ViewDelegate *self, WMView *view) -{ - WMProgressIndicator *pPtr = (WMProgressIndicator*)view->self; - int width = pPtr->view->size.width; - int height = pPtr->view->size.height; - - assert(width > 0); - assert(height > 0); -} - - -static void -paintProgressIndicator(ProgressIndicator *pPtr) -{ - W_Screen *scr = pPtr->view->screen; - GC bgc; - GC wgc; - GC lgc; - GC dgc; - WMSize size = pPtr->view->size; - int perc, w, h; - double unit, i; - Pixmap buffer; - - bgc = WMColorGC(scr->black); - wgc = WMColorGC(scr->white); - lgc = WMColorGC(scr->gray); - dgc = WMColorGC(scr->darkGray); - - unit = (double)(size.width - 3.0) / 100; - - buffer = XCreatePixmap(scr->display, pPtr->view->window, - size.width, size.height, scr->depth); - - XFillRectangle(scr->display, buffer, lgc, 0, 0, size.width, size.height); - - /* Calculate size of Progress to draw and paint ticks*/ - perc = (pPtr->value - pPtr->minValue) * 100 / (pPtr->maxValue - pPtr->minValue); - - w = (int)((double)(perc * unit)); - h = size.height - 2; - - if (w > (size.width - 3)) - w = size.width - 3; - - if (w > 0) { - XFillRectangle(scr->display, buffer, lgc, 2, 1, w, h); - XFillRectangle(scr->display, buffer, scr->stippleGC, 2, 1, w, h); - W_DrawRelief(scr, buffer, 2, 1, w, h, WRFlat); - - /* Draw Progress Marks */ - i=(5.0*unit); - -#ifdef SHOW_PROGRESS_TICKS_ONLY - while((int)idisplay, buffer, dgc, (int)i+2, h-1, i+2, h-3); - - i+=(5.0*unit); - -#ifdef SHOW_PROGRESS_TICKS_ONLY - if((int)i>=w) - break; -#endif - - XDrawLine(scr->display, buffer, dgc, (int)i+2, h-1, i+2, h-6); - - i+=(5.0*unit); - } - } - - XDrawLine(scr->display, buffer, bgc, w+2, 1, w+2, h+1); - XDrawLine(scr->display, buffer, lgc, 2, h, w+2, h); - - - XDrawLine(scr->display, buffer, dgc, 0, 0, 0, size.height-1); - XDrawLine(scr->display, buffer, dgc, 0, 0, size.width, 0); - XDrawLine(scr->display, buffer, bgc, 1, 1, 1, size.height-1); - XDrawLine(scr->display, buffer, bgc, 1, 1, size.width-1, 1); - - XDrawLine(scr->display, buffer, wgc, size.width-1, 0, - size.width-1, size.height-1); - XDrawLine(scr->display, buffer, wgc, 0, size.height-1, - size.width-1, size.height-1); - - XCopyArea(scr->display, buffer, pPtr->view->window, scr->copyGC, 0, 0, - size.width, size.height, 0, 0); - - XFreePixmap(scr->display, buffer); -} - -static void -handleEvents(XEvent *event, void *data) -{ - ProgressIndicator *pPtr = (ProgressIndicator*)data; - - CHECK_CLASS(data, WC_ProgressIndicator); - - switch (event->type) { - case Expose: - if (event->xexpose.count!=0) - break; - paintProgressIndicator(pPtr); - break; - case DestroyNotify: - destroyProgressIndicator(pPtr); - break; - } -} - - -static void -destroyProgressIndicator(ProgressIndicator *pPtr) -{ - WMRemoveNotificationObserver(pPtr); - - free(pPtr); -} - +/* + * Original idea and implementation by Frederik Schueler + * Rewritten by Pascal Hofstee + * - Added options to set min/max values + * - centralized drawing into one pain function + */ + +#include "WINGsP.h" + +typedef struct W_ProgressIndicator { + W_Class widgetClass; + W_View *view; + + int value; + int minValue; + int maxValue; + + void *clientData; +} ProgressIndicator; + + +#define DEFAULT_PROGRESS_INDICATOR_WIDTH 276 +#define DEFAULT_PROGRESS_INDICATOR_HEIGHT 16 + +/* define if only the ticks within the progress region should be displayed */ +#define SHOW_PROGRESS_TICKS_ONLY + + +static void didResizeProgressIndicator(); + + +W_ViewDelegate _ProgressIndicatorDelegate = { + NULL, + NULL, + didResizeProgressIndicator, + NULL, + NULL +}; + + +static void destroyProgressIndicator(ProgressIndicator *pPtr); +static void paintProgressIndicator(ProgressIndicator *pPtr); +static void realizeProgressIndicator(ProgressIndicator *pPtr); +static void handleEvents(XEvent *event, void *data); + +static void realizeObserver(void *self, WMNotification *not) { + + realizeProgressIndicator(self); +} + + + +WMProgressIndicator* + WMCreateProgressIndicator(WMWidget *parent) +{ + ProgressIndicator *pPtr; + + pPtr = wmalloc(sizeof(ProgressIndicator)); + memset(pPtr, 0, sizeof(ProgressIndicator)); + + pPtr->widgetClass = WC_ProgressIndicator; + + pPtr->view = W_CreateView(W_VIEW(parent)); + if (!pPtr->view) { + free(pPtr); + return NULL; + } + + pPtr->view->self = pPtr; + + pPtr->view->delegate = &_ProgressIndicatorDelegate; + + WMCreateEventHandler(pPtr->view, ExposureMask|StructureNotifyMask, + handleEvents, pPtr); + + + W_ResizeView(pPtr->view, DEFAULT_PROGRESS_INDICATOR_WIDTH, + DEFAULT_PROGRESS_INDICATOR_HEIGHT); + + /* Initialize ProgressIndicator Values */ + pPtr->value = 0; + pPtr->minValue = 0; + pPtr->maxValue = 100; + + WMAddNotificationObserver(realizeObserver, pPtr, + WMViewRealizedNotification, pPtr->view); + + return pPtr; +} + + +void +WMSetProgressIndicatorMinValue(WMProgressIndicator *progressindicator, int value) +{ + CHECK_CLASS(progressindicator, WC_ProgressIndicator); + + progressindicator->minValue = value; + if (progressindicator->value < value) { + progressindicator->value = value; + if (progressindicator->view->flags.mapped) { + paintProgressIndicator(progressindicator); + } + } +} + + +void +WMSetProgressIndicatorMaxValue(WMProgressIndicator *progressindicator, int value) +{ + CHECK_CLASS(progressindicator, WC_ProgressIndicator); + + progressindicator->maxValue = value; + if (progressindicator->value > value) { + progressindicator->value = value; + if (progressindicator->view->flags.mapped) { + paintProgressIndicator(progressindicator); + } + } +} + + +void +WMSetProgressIndicatorValue(WMProgressIndicator *progressindicator, int value) +{ + CHECK_CLASS(progressindicator, WC_ProgressIndicator); + + progressindicator->value = value; + + /* Check if value is within min/max-range */ + if (progressindicator->minValue > value) + progressindicator->value = progressindicator->minValue; + + if (progressindicator->maxValue < value) + progressindicator->value = progressindicator->maxValue; + + + if (progressindicator->view->flags.mapped) { + paintProgressIndicator(progressindicator); + } +} + + +int +WMGetProgressIndicatorMinValue(WMProgressIndicator *progressindicator) +{ + CHECK_CLASS(progressindicator, WC_ProgressIndicator); + + return progressindicator->minValue; +} + + +int +WMGetProgressIndicatorMaxValue(WMProgressIndicator *progressindicator) +{ + CHECK_CLASS(progressindicator, WC_ProgressIndicator); + + return progressindicator->maxValue; +} + + +int +WMGetProgressIndicatorValue(WMProgressIndicator *progressindicator) +{ + CHECK_CLASS(progressindicator, WC_ProgressIndicator); + + return progressindicator->value; +} + + +static void +realizeProgressIndicator(ProgressIndicator *pPtr) +{ + W_RealizeView(pPtr->view); +} + + +static void +didResizeProgressIndicator(W_ViewDelegate *self, WMView *view) +{ + WMProgressIndicator *pPtr = (WMProgressIndicator*)view->self; + int width = pPtr->view->size.width; + int height = pPtr->view->size.height; + + assert(width > 0); + assert(height > 0); +} + + +static void +paintProgressIndicator(ProgressIndicator *pPtr) +{ + W_Screen *scr = pPtr->view->screen; + GC bgc; + GC wgc; + GC lgc; + GC dgc; + WMSize size = pPtr->view->size; + int perc, w, h; + double unit, i; + Pixmap buffer; + + bgc = WMColorGC(scr->black); + wgc = WMColorGC(scr->white); + lgc = WMColorGC(scr->gray); + dgc = WMColorGC(scr->darkGray); + + unit = (double)(size.width - 3.0) / 100; + + buffer = XCreatePixmap(scr->display, pPtr->view->window, + size.width, size.height, scr->depth); + + XFillRectangle(scr->display, buffer, lgc, 0, 0, size.width, size.height); + + /* Calculate size of Progress to draw and paint ticks*/ + perc = (pPtr->value - pPtr->minValue) * 100 / (pPtr->maxValue - pPtr->minValue); + + w = (int)((double)(perc * unit)); + h = size.height - 2; + + if (w > (size.width - 3)) + w = size.width - 3; + + if (w > 0) { + XFillRectangle(scr->display, buffer, lgc, 2, 1, w, h); + XFillRectangle(scr->display, buffer, scr->stippleGC, 2, 1, w, h); + W_DrawRelief(scr, buffer, 2, 1, w, h, WRFlat); + + /* Draw Progress Marks */ + i=(5.0*unit); + +#ifdef SHOW_PROGRESS_TICKS_ONLY + while((int)idisplay, buffer, dgc, (int)i+2, h-1, i+2, h-3); + + i+=(5.0*unit); + +#ifdef SHOW_PROGRESS_TICKS_ONLY + if((int)i>=w) + break; +#endif + + XDrawLine(scr->display, buffer, dgc, (int)i+2, h-1, i+2, h-6); + + i+=(5.0*unit); + } + } + + XDrawLine(scr->display, buffer, bgc, w+2, 1, w+2, h+1); + XDrawLine(scr->display, buffer, lgc, 2, h, w+2, h); + + + XDrawLine(scr->display, buffer, dgc, 0, 0, 0, size.height-1); + XDrawLine(scr->display, buffer, dgc, 0, 0, size.width, 0); + XDrawLine(scr->display, buffer, bgc, 1, 1, 1, size.height-1); + XDrawLine(scr->display, buffer, bgc, 1, 1, size.width-1, 1); + + XDrawLine(scr->display, buffer, wgc, size.width-1, 0, + size.width-1, size.height-1); + XDrawLine(scr->display, buffer, wgc, 0, size.height-1, + size.width-1, size.height-1); + + XCopyArea(scr->display, buffer, pPtr->view->window, scr->copyGC, 0, 0, + size.width, size.height, 0, 0); + + XFreePixmap(scr->display, buffer); +} + +static void +handleEvents(XEvent *event, void *data) +{ + ProgressIndicator *pPtr = (ProgressIndicator*)data; + + CHECK_CLASS(data, WC_ProgressIndicator); + + switch (event->type) { + case Expose: + if (event->xexpose.count!=0) + break; + paintProgressIndicator(pPtr); + break; + case DestroyNotify: + destroyProgressIndicator(pPtr); + break; + } +} + + +static void +destroyProgressIndicator(ProgressIndicator *pPtr) +{ + WMRemoveNotificationObserver(pPtr); + + free(pPtr); +} + diff --git a/WindowMaker/IconSets/Makefile.in b/WindowMaker/IconSets/Makefile.in index 77d3975e..710770f9 100755 --- a/WindowMaker/IconSets/Makefile.in +++ b/WindowMaker/IconSets/Makefile.in @@ -109,7 +109,7 @@ DIST_COMMON = Makefile.am Makefile.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = tar +TAR = gtar GZIP_ENV = --best all: all-redirect .SUFFIXES: diff --git a/WindowMaker/Makefile.in b/WindowMaker/Makefile.in index 643b0bb5..5a0871c4 100755 --- a/WindowMaker/Makefile.in +++ b/WindowMaker/Makefile.in @@ -110,7 +110,7 @@ DIST_COMMON = README Makefile.am Makefile.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = tar +TAR = gtar GZIP_ENV = --best all: all-redirect .SUFFIXES: diff --git a/src/dialog.c b/src/dialog.c index a1a5bb26..94c5ffb2 100644 --- a/src/dialog.c +++ b/src/dialog.c @@ -250,9 +250,10 @@ listPixmaps(WScreen *scr, WMList *lPtr, char *path) if (statb.st_mode & (S_IRUSR|S_IRGRP|S_IROTH) && statb.st_mode & (S_IFREG|S_IFLNK)) { - WMAddSortedListItem(lPtr, dentry->d_name); + WMAddListItem(lPtr, dentry->d_name); } } + WMSortListItems(lPtr); closedir(dir); free(apath); @@ -374,10 +375,11 @@ drawIconProc(WMList *lPtr, int index, Drawable d, char *text, blackcolor = WMBlackColor(wmscr); whitecolor = WMWhiteColor(wmscr); - dirfile = WMGetListSelectedItem(panel->dirList)->text; + dirfile = wexpandpath(WMGetListSelectedItem(panel->dirList)->text); buffer = wmalloc(strlen(dirfile)+strlen(text)+4); - sprintf(buffer,"%s/%s" ,dirfile,text); - + sprintf(buffer, "%s/%s", dirfile, text); + free(dirfile); + pixmap = WMCreatePixmapFromFile(WMWidgetScreen(panel->win), buffer); free(buffer); if (!pixmap) { diff --git a/wrlib/Makefile.in b/wrlib/Makefile.in index 3f010033..384c727c 100644 --- a/wrlib/Makefile.in +++ b/wrlib/Makefile.in @@ -169,7 +169,7 @@ Makefile.in NEWS TODO alloca.c configure.in DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) -TAR = tar +TAR = gtar GZIP_ENV = --best SOURCES = $(libwraster_la_SOURCES) $(testgrad_SOURCES) $(testdraw_SOURCES) $(view_SOURCES) OBJECTS = $(libwraster_la_OBJECTS) $(testgrad_OBJECTS) $(testdraw_OBJECTS) $(view_OBJECTS) -- 2.11.4.GIT