From 052ab01c848680eec6068c874d30bcfb79792699 Mon Sep 17 00:00:00 2001 From: kojima Date: Thu, 16 Sep 1999 02:55:56 +0000 Subject: [PATCH] replaced linked lists with WMBag, added progress indicator --- WINGs/ChangeLog | 3 + WINGs/Makefile.am | 7 +- WINGs/Makefile.in | 26 ++-- WINGs/README | 1 + WINGs/Resources/Makefile.in | 5 +- WINGs/WINGs.h | 24 +++- WINGs/WUtil.h | 45 +++++- WINGs/bag.c | 195 +++++++++++++++++++++++++ WINGs/configuration.c | 7 +- WINGs/llist.c | 126 ---------------- WINGs/llist.h | 40 ------ WINGs/memory.c | 2 +- WINGs/notification.c | 101 +++++++------ WINGs/wbutton.c | 6 + WINGs/wcolorpanel.c | 40 +++--- WINGs/wfilepanel.c | 6 +- WINGs/wfontpanel.c | 342 ++++++++++++++++++++++---------------------- WINGs/wprogressindicator.c | 299 ++++++++++++++++++++++++++++++++++++++ WINGs/wtest.c | 34 ++++- WINGs/wtextfield.c | 10 ++ 20 files changed, 882 insertions(+), 437 deletions(-) create mode 100644 WINGs/bag.c delete mode 100644 WINGs/llist.c delete mode 100644 WINGs/llist.h create mode 100644 WINGs/wprogressindicator.c diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index 8aa0f54d..71b75fb4 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -3,6 +3,8 @@ changes since wmaker 0.60.0: - added WMScreenWidth() and WMScreenHeight() functions. - fixed some problems when compiling with non gcc compilers. +- added WMSetButtonImageDefault() (craig nellist ) +- added WMBag (array/list) - added libWUtil, a library that is a subset of libWINGs. It contains utils that can be used in writing non-GUI programs. They include: hashes, notifications, input/idle/timer handlers, user defaults database handling, @@ -47,6 +49,7 @@ changes since wmaker 0.60.0: WMAddInputHandler(int fd, int condition, WMInputProc *proc, void *clientData); WMDeleteInputHandler(WMHandlerID handlerID); +- added progress indicator widget changes since wmaker 0.53.0: diff --git a/WINGs/Makefile.am b/WINGs/Makefile.am index b7f2f946..198e1f61 100644 --- a/WINGs/Makefile.am +++ b/WINGs/Makefile.am @@ -60,8 +60,6 @@ libWINGs_a_SOURCES = \ WINGs.h \ WINGsP.h \ configuration.c \ - llist.h \ - llist.c \ international.c \ notification.c \ selection.c \ @@ -86,6 +84,7 @@ libWINGs_a_SOURCES = \ wpanel.c \ wpixmap.c \ wpopupbutton.c \ + wprogressindicator.c \ wscroller.c \ wscrollview.c \ wslider.c \ @@ -96,6 +95,7 @@ libWINGs_a_SOURCES = \ wview.c \ error.c \ findfile.c \ + bag.c \ hashtable.c \ memory.c \ usleep.c @@ -104,8 +104,7 @@ libWINGs_a_SOURCES = \ libWUtil_a_SOURCES = \ WINGs.h \ WINGsP.h \ - llist.h \ - llist.c \ + bag.c \ international.c \ notification.c \ userdefaults.c \ diff --git a/WINGs/Makefile.in b/WINGs/Makefile.in index d6a6ec7a..72ecf365 100644 --- a/WINGs/Makefile.in +++ b/WINGs/Makefile.in @@ -59,12 +59,10 @@ PRE_UNINSTALL = : POST_UNINSTALL = : host_alias = @host_alias@ host_triplet = @host@ -AS = @AS@ CC = @CC@ CPP_PATH = @CPP_PATH@ DFLAGS = @DFLAGS@ DLLIBS = @DLLIBS@ -DLLTOOL = @DLLTOOL@ GFXLIBS = @GFXLIBS@ HEADER_SEARCH_PATH = @HEADER_SEARCH_PATH@ ICONEXT = @ICONEXT@ @@ -79,7 +77,6 @@ MAKEINFO = @MAKEINFO@ MOFILES = @MOFILES@ NLSDIR = @NLSDIR@ NM = @NM@ -OBJDUMP = @OBJDUMP@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ VERSION = @VERSION@ @@ -143,10 +140,10 @@ wmquery_LDADD = libWINGs.a $(LIBLIST) EXTRA_DIST = logo.xpm BUGS # wbutton.c -libWINGs_a_SOURCES = WINGs.h WINGsP.h configuration.c llist.h llist.c international.c notification.c selection.c userdefaults.c wapplication.c wappresource.c wballoon.c wbrowser.c wbutton.c wcolor.c wcolorpanel.c wcolorwell.c wevent.c wfilepanel.c wframe.c wfont.c wfontpanel.c widgets.c wlabel.c wlist.c wmisc.c wpanel.c wpixmap.c wpopupbutton.c wscroller.c wscrollview.c wslider.c wsplitview.c wtabview.c wtextfield.c wwindow.c wview.c error.c findfile.c hashtable.c memory.c usleep.c +libWINGs_a_SOURCES = WINGs.h WINGsP.h configuration.c international.c notification.c selection.c userdefaults.c wapplication.c wappresource.c wballoon.c wbrowser.c wbutton.c wcolor.c wcolorpanel.c wcolorwell.c wevent.c wfilepanel.c wframe.c wfont.c wfontpanel.c widgets.c wlabel.c wlist.c wmisc.c wpanel.c wpixmap.c wpopupbutton.c wprogressindicator.c wscroller.c wscrollview.c wslider.c wsplitview.c wtabview.c wtextfield.c wwindow.c wview.c error.c findfile.c bag.c hashtable.c memory.c usleep.c -libWUtil_a_SOURCES = WINGs.h WINGsP.h llist.h llist.c international.c notification.c userdefaults.c wapplication.c wutil.c error.c findfile.c hashtable.c memory.c usleep.c +libWUtil_a_SOURCES = WINGs.h WINGsP.h bag.c international.c notification.c userdefaults.c wapplication.c wutil.c error.c findfile.c hashtable.c memory.c usleep.c INCLUDES = -I$(top_srcdir)/wrlib -I$(top_srcdir)/src -DRESOURCE_PATH=\"$(datadir)/WINGs\" @HEADER_SEARCH_PATH@ -DDEBUG @@ -165,15 +162,16 @@ X_CFLAGS = @X_CFLAGS@ X_LIBS = @X_LIBS@ X_PRE_LIBS = @X_PRE_LIBS@ libWINGs_a_LIBADD = -libWINGs_a_OBJECTS = configuration.o llist.o international.o \ -notification.o selection.o userdefaults.o wapplication.o wappresource.o \ -wballoon.o wbrowser.o wbutton.o wcolor.o wcolorpanel.o wcolorwell.o \ -wevent.o wfilepanel.o wframe.o wfont.o wfontpanel.o widgets.o wlabel.o \ -wlist.o wmisc.o wpanel.o wpixmap.o wpopupbutton.o wscroller.o \ -wscrollview.o wslider.o wsplitview.o wtabview.o wtextfield.o wwindow.o \ -wview.o error.o findfile.o hashtable.o memory.o usleep.o +libWINGs_a_OBJECTS = configuration.o international.o notification.o \ +selection.o userdefaults.o wapplication.o wappresource.o wballoon.o \ +wbrowser.o wbutton.o wcolor.o wcolorpanel.o wcolorwell.o wevent.o \ +wfilepanel.o wframe.o wfont.o wfontpanel.o widgets.o wlabel.o wlist.o \ +wmisc.o wpanel.o wpixmap.o wpopupbutton.o wprogressindicator.o \ +wscroller.o wscrollview.o wslider.o wsplitview.o wtabview.o \ +wtextfield.o wwindow.o wview.o error.o findfile.o bag.o hashtable.o \ +memory.o usleep.o libWUtil_a_LIBADD = -libWUtil_a_OBJECTS = llist.o international.o notification.o \ +libWUtil_a_OBJECTS = bag.o international.o notification.o \ userdefaults.o wapplication.o wutil.o error.o findfile.o hashtable.o \ memory.o usleep.o AR = ar @@ -213,7 +211,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) $(testnot_SOURCES) OBJECTS = $(libWINGs_a_OBJECTS) $(libWUtil_a_OBJECTS) $(wtest_OBJECTS) $(wmquery_OBJECTS) $(wmfile_OBJECTS) $(fontl_OBJECTS) $(testmywidget_OBJECTS) $(testcolorpanel_OBJECTS) $(testnot_OBJECTS) diff --git a/WINGs/README b/WINGs/README index b0f0ede4..5494108d 100644 --- a/WINGs/README +++ b/WINGs/README @@ -58,6 +58,7 @@ Widgets provided by WINGs: - color well - split view (only 2 subviews) - tabbed view +- progress indicator - input box - file panel diff --git a/WINGs/Resources/Makefile.in b/WINGs/Resources/Makefile.in index 41f26f6e..aa1e6bc5 100644 --- a/WINGs/Resources/Makefile.in +++ b/WINGs/Resources/Makefile.in @@ -59,12 +59,10 @@ PRE_UNINSTALL = : POST_UNINSTALL = : host_alias = @host_alias@ host_triplet = @host@ -AS = @AS@ CC = @CC@ CPP_PATH = @CPP_PATH@ DFLAGS = @DFLAGS@ DLLIBS = @DLLIBS@ -DLLTOOL = @DLLTOOL@ GFXLIBS = @GFXLIBS@ HEADER_SEARCH_PATH = @HEADER_SEARCH_PATH@ ICONEXT = @ICONEXT@ @@ -79,7 +77,6 @@ MAKEINFO = @MAKEINFO@ MOFILES = @MOFILES@ NLSDIR = @NLSDIR@ NM = @NM@ -OBJDUMP = @OBJDUMP@ PACKAGE = @PACKAGE@ RANLIB = @RANLIB@ VERSION = @VERSION@ @@ -107,7 +104,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 8ff293c4..188cb4b7 100644 --- a/WINGs/WINGs.h +++ b/WINGs/WINGs.h @@ -263,7 +263,8 @@ enum { WC_Slider = 11, WC_Matrix = 12, /* not ready */ WC_SplitView = 13, - WC_TabView = 14 + WC_TabView = 14, + WC_ProgressIndicator = 15 }; /* All widgets must start with the following structure @@ -301,6 +302,7 @@ typedef struct W_ScrollView WMScrollView; typedef struct W_List WMList; typedef struct W_Browser WMBrowser; typedef struct W_PopUpButton WMPopUpButton; +typedef struct W_ProgressIndicator WMProgressIndicator; typedef struct W_ColorWell WMColorWell; typedef struct W_Slider WMSlider; typedef struct W_Matrix WMMatrix; /* not ready */ @@ -385,6 +387,7 @@ typedef void WMAction(WMWidget *self, void *clientData); /* same as WMAction, but for stuff that arent widgets */ typedef void WMAction2(void *self, void *clientData); + typedef void WMCallback(void *data); @@ -796,6 +799,8 @@ WMButton *WMCreateButton(WMWidget *parent, WMButtonType type); WMButton *WMCreateCustomButton(WMWidget *parent, int behaviourMask); +void WMSetButtonImageDefault(WMButton *bPtr); + void WMSetButtonImage(WMButton *bPtr, WMPixmap *image); void WMSetButtonAltImage(WMButton *bPtr, WMPixmap *image); @@ -1053,6 +1058,23 @@ Bool WMGetPopUpButtonEnabled(WMPopUpButton *bPtr); /* ....................................................................... */ +WMProgressIndicator *WMCreateProgressIndicator(WMWidget *parent); + +void WMSetProgressIndicatorMinValue(WMProgressIndicator *progressindicator, int value); + +void WMSetProgressIndicatorMaxValue(WMProgressIndicator *progressindicator, int value); + +void WMSetProgressIndicatorValue(WMProgressIndicator *progressindicator, int value); + +int WMGetProgressIndicatorMinValue(WMProgressIndicator *progressindicator); + +int WMGetProgressIndicatorMaxValue(WMProgressIndicator *progressindicator); + +int WMGetProgressIndicatorValue(WMProgressIndicator *progressindicator); + + +/* ....................................................................... */ + WMColorPanel *WMGetColorPanel(WMScreen *scrPtr); void WMFreeColorPanel(WMColorPanel *panel); diff --git a/WINGs/WUtil.h b/WINGs/WUtil.h index 095fbe1f..a2952e67 100644 --- a/WINGs/WUtil.h +++ b/WINGs/WUtil.h @@ -92,13 +92,14 @@ typedef enum { - +typedef struct W_Bag WMBag; /* equivalent to a linked list or array */ typedef struct W_HashTable WMHashTable; typedef struct W_UserDefaults WMUserDefaults; typedef struct W_Notification WMNotification; typedef struct W_NotificationQueue WMNotificationQueue; + /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */ typedef struct { void *table; @@ -118,6 +119,7 @@ typedef struct { void (*releaseKey)(const void *); } WMHashTableCallbacks; + #if 0 typedef struct { @@ -126,6 +128,7 @@ typedef struct { } WMSEscapes; #endif + typedef void WMNotificationObserverAction(void *observerData, WMNotification *notification); @@ -223,6 +226,46 @@ extern const WMHashTableCallbacks WMStringHashCallbacks; extern const WMHashTableCallbacks WMStringPointerHashCallbacks; /* keys are strings, bug they are not copied */ + +/*......................................................................*/ + + +WMBag *WMCreateBag(int size); + +int WMGetBagItemCount(WMBag *bag); + +void WMAppendBag(WMBag *bag, WMBag *appendedBag); + +void WMPutInBag(WMBag *bag, void *item); + +void WMInsertInBag(WMBag *bag, int index, void *item); + +int WMGetFirstInBag(WMBag *bag, void *item); + +int WMGetLastInBag(WMBag *bag, void *item); + +void WMRemoveFromBag(WMBag *bag, void *item); + +void WMDeleteFromBag(WMBag *bag, int index); + +void *WMGetFromBag(WMBag *bag, int index); + +int WMCountInBag(WMBag *bag, void *item); + + +/* comparer must return: + * < 0 if a < b + * > 0 if a > b + * = 0 if a = b + */ +void WMSortBag(WMBag *bag, int (*comparer)(void*,void*)); + +void WMEmptyBag(WMBag *bag); + +void WMFreeBag(WMBag *bag); + +WMBag *WMMapBag(WMBag *bag, void* (*function)(void*)); + /*......................................................................*/ WMNotification *WMCreateNotification(char *name, void *object, void *clientData); diff --git a/WINGs/bag.c b/WINGs/bag.c new file mode 100644 index 00000000..c15b527b --- /dev/null +++ b/WINGs/bag.c @@ -0,0 +1,195 @@ + + +#include +#include + +#include "WUtil.h" + + + +struct W_Bag { + int size; + int count; + + void **items; +}; + + + + +WMBag* +WMCreateBag(int size) +{ + WMBag *bag; + + wassertrv(size > 0, NULL); + + bag = wmalloc(sizeof(WMBag)); + + bag->items = wmalloc(sizeof(void*) * size); + bag->size = size; + bag->count = 0; + + return bag; +} + + + +int +WMGetBagItemCount(WMBag *bag) +{ + return bag->count; +} + + + +void +WMAppendBag(WMBag *bag, WMBag *appendedBag) +{ + bag->items = wrealloc(bag->items, + sizeof(void*) * (bag->size+appendedBag->count)); + + memcpy(bag->items + bag->count, appendedBag->items, appendedBag->count); + + bag->count += appendedBag->count; +} + + + +void +WMPutInBag(WMBag *bag, void *item) +{ + WMInsertInBag(bag, bag->count, item); +} + + + +void +WMInsertInBag(WMBag *bag, int index, void *item) +{ + if (bag->count == bag->size) { + bag->size += 16; + bag->items = wrealloc(bag->items, sizeof(void*) * bag->size); + } + + bag->items[bag->count++] = item; +} + + +int +WMGetFirstInBag(WMBag *bag, void *item) +{ + int i; + + for (i = 0; i < bag->count; i++) { + if (bag->items[i] == item) { + return i; + } + } + return -1; +} + + +int +WMGetLastInBag(WMBag *bag, void *item) +{ + int i; + + for (i = bag->count-1; i>= 0; i--) { + if (bag->items[i] == item) { + return i; + } + } + return -1; +} + + +void +WMRemoveFromBag(WMBag *bag, void *item) +{ + int i; + + i = WMGetFirstInBag(bag, item); + if (i >= 0) { + WMDeleteFromBag(bag, i); + } +} + + + +void +WMDeleteFromBag(WMBag *bag, int index) +{ + if (index < 0 || index >= bag->count) + return; + + if (index < bag->count-1) { + memmove(&bag->items[index], &bag->items[index + 1], + (bag->count - index - 1) * sizeof(void*)); + } + bag->count--; +} + + +void* +WMGetFromBag(WMBag *bag, int index) +{ + if (index < 0 || index >= bag->count) { + return NULL; + } + + return bag->items[index]; +} + + +int +WMCountInBag(WMBag *bag, void *item) +{ + int i, j; + + for (j = 0, i = 0; j < bag->count; j++) { + if (bag->items[j] == item) + i++; + } + return i; +} + + + +void +WMSortBag(WMBag *bag, int (*comparer)(void*, void*)) +{ + qsort(bag->items, bag->count, sizeof(void*), comparer); +} + + + +void +WMFreeBag(WMBag *bag) +{ + free(bag->items); + free(bag); +} + + +void +WMEmptyBag(WMBag *bag) +{ + bag->count = 0; +} + + + +WMBag* +WMMapBag(WMBag *bag, void *(*function)(void *)) +{ + int i; + WMBag *new = WMCreateBag(bag->size); + + for (i = 0; i < bag->count; i++) { + WMPutInBag(new, (*function)(bag->items[i])); + } + + return new; +} + diff --git a/WINGs/configuration.c b/WINGs/configuration.c index 11387573..c3cfa43c 100644 --- a/WINGs/configuration.c +++ b/WINGs/configuration.c @@ -9,9 +9,10 @@ _WINGsConfiguration WINGsConfiguration; -#define SYSTEM_FONT "-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*" - -#define BOLD_SYSTEM_FONT "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*" +#define SYSTEM_FONT "-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-*-*-%d-*-*-*-*-*-*-*" + +#define BOLD_SYSTEM_FONT "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-bold-r-*-*-%d-*-*-*-*-*-*-*" + diff --git a/WINGs/llist.c b/WINGs/llist.c deleted file mode 100644 index ea2e68a9..00000000 --- a/WINGs/llist.c +++ /dev/null @@ -1,126 +0,0 @@ - -#include "WUtil.h" -#include - -#include "llist.h" - - - -WINLINE void* -lhead(list_t *list) -{ - if (!list) - return NULL; - - return list->head; -} - - -WINLINE list_t* -ltail(list_t *list) -{ - if (!list) - return NULL; - - return list->tail; -} - - -WINLINE list_t* -lcons(void *newHead, list_t *list) -{ - list_t *newNode; - - newNode = wmalloc(sizeof(list_t)); - newNode->head = newHead; - newNode->tail = list; - - return newNode; -} - - -WINLINE list_t* -lappend(list_t *list, list_t *tail) -{ - list_t *ptr; - - if (!list) - return tail; - - for (ptr = list; ptr->tail == NULL; ptr = ptr->tail); - - ptr->tail = tail; - - return ptr; -} - - -WINLINE void -lfree(list_t *list) -{ - if (list) { - lfree(list->tail); - free(list); - } -} - - -WINLINE void* -lfind(void *objeto, list_t *list, int (*compare)(void*, void*)) -{ - while (list) { - if ((*compare)(list->head, objeto)==0) { - return list->head; - } - list = list->tail; - } - return NULL; -} - - -WINLINE int -llength(list_t *list) -{ - int i = 0; - - while (list) { - list = list->tail; - i++; - } - - return i; -} - - -WINLINE list_t* -lremove(list_t *list, void *object) -{ - if (!list) - return NULL; - - if (list->head == object) { - list_t *tmp = list->tail; - - free(list); - - return tmp; - } - - list->tail = lremove(list->tail, object); - - return list; -} - - -WINLINE list_t* -lremovehead(list_t *list) -{ - list_t *tmp = NULL; - - if (list) { - tmp = list->tail; - free(list); - } - return tmp; -} - diff --git a/WINGs/llist.h b/WINGs/llist.h deleted file mode 100644 index d956ae55..00000000 --- a/WINGs/llist.h +++ /dev/null @@ -1,40 +0,0 @@ - - -#if defined(__GNUC__) && !defined(__STRICT_ANSI__) -# define WINLINE inline -#else -# define WINLINE -#endif - -typedef struct list_t { - void *head; - struct list_t *tail; -} list_t; - - -WINLINE void *lhead(list_t *list); - - -WINLINE list_t *ltail(list_t *list); - - -WINLINE list_t *lcons(void *newHead, list_t *list); - - -WINLINE list_t *lappend(list_t *list, list_t *tail); - - -WINLINE void lfree(list_t *list); - - -WINLINE void *lfind(void *object, list_t *list, int (*compare)(void*, void*)); - - -WINLINE int llength(list_t *list); - - -WINLINE list_t *lremove(list_t *list, void *object); - - -WINLINE list_t *lremovehead(list_t *list); - diff --git a/WINGs/memory.c b/WINGs/memory.c index e694f950..0a8317cd 100644 --- a/WINGs/memory.c +++ b/WINGs/memory.c @@ -43,7 +43,7 @@ static void defaultHandler(int bla) { if (bla) - raise(SIGABRT); + kill(getpid(), SIGABRT); else exit(1); } diff --git a/WINGs/notification.c b/WINGs/notification.c index 0607b44a..2fd27afa 100644 --- a/WINGs/notification.c +++ b/WINGs/notification.c @@ -6,7 +6,6 @@ #include "WUtil.h" -#include "llist.h" typedef struct W_Notification { char *name; @@ -379,8 +378,8 @@ WMPostNotificationName(char *name, void *object, void *clientData) typedef struct W_NotificationQueue { - list_t *asapQueue; - list_t *idleQueue; + WMBag *asapQueue; + WMBag *idleQueue; struct W_NotificationQueue *next; } NotificationQueue; @@ -409,8 +408,8 @@ WMCreateNotificationQueue(void) queue = wmalloc(sizeof(NotificationQueue)); - queue->asapQueue = NULL; - queue->idleQueue = NULL; + queue->asapQueue = WMCreateBag(8); + queue->idleQueue = WMCreateBag(8); queue->next = notificationQueueList; notificationQueueList = queue; @@ -429,50 +428,52 @@ WMEnqueueNotification(WMNotificationQueue *queue, WMNotification *notification, } -static int -matchName(void *a, void *b) -{ - WMNotification *n1 = (WMNotification*)a; - WMNotification *n2 = (WMNotification*)b; - - return strcmp(n1->name, n2->name); -} - - -static int -matchSender(void *a, void *b) -{ - WMNotification *n1 = (WMNotification*)a; - WMNotification *n2 = (WMNotification*)b; - - return (n1->object == n2->object); -} - void WMDequeueNotificationMatching(WMNotificationQueue *queue, WMNotification *notification, unsigned mask) { - void *n; + int i; + WMNotification *tmp; if (mask & WNCOnName) { - while ((n = lfind(notification->name, queue->asapQueue, matchName))) { - queue->asapQueue = lremove(queue->asapQueue, n); - WMReleaseNotification((WMNotification*)n); + for (i = 0; i < WMGetBagItemCount(queue->asapQueue); i++) { + tmp = WMGetFromBag(queue->asapQueue, i); + + if (strcmp(notification->name, tmp) == 0) { + WMRemoveFromBag(queue->asapQueue, tmp); + WMReleaseNotification(tmp); + break; + } } - while ((n = lfind(notification->name, queue->idleQueue, matchName))) { - queue->idleQueue = lremove(queue->idleQueue, n); - WMReleaseNotification((WMNotification*)n); + for (i = 0; i < WMGetBagItemCount(queue->idleQueue); i++) { + tmp = WMGetFromBag(queue->idleQueue, i); + + if (strcmp(notification->name, tmp) == 0) { + WMRemoveFromBag(queue->idleQueue, tmp); + WMReleaseNotification(tmp); + break; + } } } if (mask & WNCOnSender) { - while ((n = lfind(notification->name, queue->asapQueue, matchSender))) { - queue->asapQueue = lremove(queue->asapQueue, n); - WMReleaseNotification((WMNotification*)n); + for (i = 0; i < WMGetBagItemCount(queue->asapQueue); i++) { + tmp = WMGetFromBag(queue->asapQueue, i); + + if (notification->object == tmp->object) { + WMRemoveFromBag(queue->asapQueue, tmp); + WMReleaseNotification(tmp); + break; + } } - while ((n = lfind(notification->name, queue->idleQueue, matchSender))) { - queue->idleQueue = lremove(queue->idleQueue, n); - WMReleaseNotification((WMNotification*)n); + for (i = 0; i < WMGetBagItemCount(queue->idleQueue); i++) { + tmp = WMGetFromBag(queue->idleQueue, i); + + if (notification->object == tmp->object) { + WMRemoveFromBag(queue->idleQueue, tmp); + WMReleaseNotification(tmp); + break; + } } } } @@ -493,13 +494,11 @@ WMEnqueueCoalesceNotification(WMNotificationQueue *queue, break; case WMPostASAP: - queue->asapQueue = lappend(queue->asapQueue, - lcons(notification, NULL)); + WMPutInBag(queue->asapQueue, notification); break; case WMPostWhenIdle: - queue->idleQueue = lappend(queue->idleQueue, - lcons(notification, NULL)); + WMPutInBag(queue->idleQueue, notification); break; } } @@ -511,10 +510,14 @@ W_FlushASAPNotificationQueue() WMNotificationQueue *queue = notificationQueueList; while (queue) { - while (queue->asapQueue) { - WMPostNotification((WMNotification*)lhead(queue->asapQueue)); - queue->asapQueue = lremovehead(queue->asapQueue); + while (WMGetBagItemCount(queue->asapQueue)) { + WMNotification *tmp = WMGetFromBag(queue->asapQueue, 0); + + WMPostNotification(tmp); + WMDeleteFromBag(queue->asapQueue, 0); } + + queue = queue->next; } } @@ -525,10 +528,14 @@ W_FlushIdleNotificationQueue() WMNotificationQueue *queue = notificationQueueList; while (queue) { - while (queue->idleQueue) { - WMPostNotification((WMNotification*)lhead(queue->idleQueue)); - queue->idleQueue = lremovehead(queue->idleQueue); + while (WMGetBagItemCount(queue->idleQueue)) { + WMNotification *tmp = WMGetFromBag(queue->idleQueue, 0); + + WMPostNotification(tmp); + WMDeleteFromBag(queue->idleQueue, 0); } + + queue = queue->next; } } diff --git a/WINGs/wbutton.c b/WINGs/wbutton.c index 33ffa11e..062dd382 100644 --- a/WINGs/wbutton.c +++ b/WINGs/wbutton.c @@ -263,6 +263,12 @@ updateDisabledMask(WMButton *bPtr) } } +void +WMSetButtonImageDefault(WMButton *bPtr) +{ + WMSetButtonImage (bPtr, WMWidgetScreen(bPtr)->buttonArrow); + WMSetButtonAltImage (bPtr, WMWidgetScreen(bPtr)->pushedButtonArrow); +} void WMSetButtonImage(WMButton *bPtr, WMPixmap *image) diff --git a/WINGs/wcolorpanel.c b/WINGs/wcolorpanel.c index e9dd181b..714223d9 100644 --- a/WINGs/wcolorpanel.c +++ b/WINGs/wcolorpanel.c @@ -114,7 +114,7 @@ typedef struct W_ColorPanel { WMFont *font8; WMFont *font12; - void *clientData; + void *clientData; WMAction2 *action; /* Common Stuff */ @@ -263,12 +263,12 @@ enum { #define MAX_LENGTH 1024 -static int fetchFile(char* toPath, char *imageSrcFile, +static int fetchFile(char* toPath, char *imageSrcFile, char *imageDestFileName); char *generateNewFilename(char *curName); -static void modeButtonCallback(WMWidget *w, void *data); -static int getPickerPart(W_ColorPanel *panel, int x, int y); +static void modeButtonCallback(WMWidget *w, void *data); +static int getPickerPart(W_ColorPanel *panel, int x, int y); static void readConfiguration(W_ColorPanel *panel); static void readXColors(W_ColorPanel *panel); @@ -282,12 +282,12 @@ static Pixmap magnifyGetStorePixmap(W_ColorPanel *panel, int x1, int y1, int x2, int y2); static Pixmap magnifyGetImage(WMScreen *scr, int x, int y); -static wheelMatrix* wheelCreateMatrix(unsigned int width , unsigned int height); -static void wheelDestroyMatrix(wheelMatrix *matrix); -static wheelMatrix* wheelInitMatrix(W_ColorPanel *panel); -static void wheelRender(W_ColorPanel *panel); -static Bool wheelInsideColorWheel(W_ColorPanel *panel, unsigned long ofs); -static void wheelPaint(W_ColorPanel *panel); +static wheelMatrix* wheelCreateMatrix(unsigned int width , unsigned int height); +static void wheelDestroyMatrix(wheelMatrix *matrix); +static wheelMatrix* wheelInitMatrix(W_ColorPanel *panel); +static void wheelRender(W_ColorPanel *panel); +static Bool wheelInsideColorWheel(W_ColorPanel *panel, unsigned long ofs); +static void wheelPaint(W_ColorPanel *panel); static void wheelHandleEvents(XEvent *event, void *data); static void wheelHandleActionEvents(XEvent *event, void *data); @@ -297,14 +297,14 @@ static void wheelUndrawSelection(W_ColorPanel *panel); static void wheelPositionSelection(W_ColorPanel *panel, int x, int y); static void wheelPositionSelectionOutBounds(W_ColorPanel *panel, int x, int y); -static void wheelUpdateBrightnessGradientFromHSV (W_ColorPanel *panel, +static void wheelUpdateBrightnessGradientFromHSV (W_ColorPanel *panel, RHSVColor topColor); static void wheelUpdateBrightnessGradientFromLocation (W_ColorPanel *panel); static void wheelUpdateBrightnessGradient(W_ColorPanel *panel, RColor topColor); -static void grayBrightnessSliderCallback(WMWidget *w, void *data); +static void grayBrightnessSliderCallback(WMWidget *w, void *data); static void grayPresetButtonCallback(WMWidget *w, void *data); -static void grayBrightnessTextFieldCallback(void *observerData, +static void grayBrightnessTextFieldCallback(void *observerData, WMNotification *notification); static void rgbSliderCallback(WMWidget *w, void *data); @@ -318,9 +318,9 @@ static void cmykTextFieldCallback(void *observerData, static void hsbSliderCallback(WMWidget *w, void *data); static void hsbTextFieldCallback(void *observerData, WMNotification *notification); -static void hsbUpdateBrightnessGradient(W_ColorPanel *panel); -static void hsbUpdateSaturationGradient(W_ColorPanel *panel); -static void hsbUpdateHueGradient(W_ColorPanel *panel); +static void hsbUpdateBrightnessGradient(W_ColorPanel *panel); +static void hsbUpdateSaturationGradient(W_ColorPanel *panel); +static void hsbUpdateHueGradient(W_ColorPanel *panel); static void customRenderSpectrum(W_ColorPanel *panel); static void customSetPalette(W_ColorPanel *panel); @@ -343,10 +343,10 @@ static void colorListColorMenuCallback(WMWidget *w, void *data); static void colorListListMenuCallback(WMWidget *w, void *data); static void colorListListMenuNew(W_ColorPanel *panel); -static void wheelInit(W_ColorPanel *panel); -static void grayInit(W_ColorPanel *panel); -static void rgbInit(W_ColorPanel *panel); -static void cmykInit(W_ColorPanel *panel); +static void wheelInit(W_ColorPanel *panel); +static void grayInit(W_ColorPanel *panel); +static void rgbInit(W_ColorPanel *panel); +static void cmykInit(W_ColorPanel *panel); static void hsbInit(W_ColorPanel *panel); diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 5f702cca..740d42c5 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -694,7 +694,7 @@ createDir(WMButton *bPre, WMFilePanel *panel) if ((s = strrchr(directory_name, '/')) && !s[1]) s[0] = 0; file = wmalloc(strlen(directory_name)+strlen(directory)+1); - sprintf(file, "%s/%s\0", directory, directory_name); + sprintf(file, "%s/%s", directory, directory_name); while (s = strstr(file,"//")) { int i; for (i = 2;s[i] == '/';i++); @@ -762,10 +762,10 @@ deleteFile(WMButton *bPre, WMFilePanel *panel) return; } else if (S_ISDIR(filestat.st_mode)) { buffer = wmalloc(strlen(file)+20); - sprintf(buffer,"Delete directory %s ?\0",file); + sprintf(buffer,"Delete directory %s ?",file); } else { buffer = wmalloc(strlen(file)+15); - sprintf(buffer,"Delete file %s ?\0",file); + sprintf(buffer,"Delete file %s ?",file); } if (!WMRunAlertPanel(WMWidgetScreen(panel->win), panel->win, diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c index 734d2134..02c0e842 100644 --- a/WINGs/wfontpanel.c +++ b/WINGs/wfontpanel.c @@ -70,9 +70,8 @@ static char *scalableFontSizes[] = { static void arrangeLowerFrame(FontPanel *panel); -static proplist_t createFontDatabase(WMScreen *scr); -static void listFamilies(proplist_t fdb, WMList *list); +static void listFamilies(WMScreen *scr, WMFontPanel *panel); static void splitViewConstrainCallback(WMSplitView *sPtr, int divIndex, int *min, int *max) @@ -279,8 +278,9 @@ WMGetFontPanel(WMScreen *scr) WMViewSizeDidChangeNotification, WMWidgetView(panel->lowerF)); - panel->fdb = createFontDatabase(scr); - listFamilies(panel->fdb, panel->famLs); + + listFamilies(scr, panel); + return panel; } @@ -404,8 +404,10 @@ arrangeLowerFrame(FontPanel *panel) #define NUM_FIELDS 14 +#if 1 + static Bool -parseFont(char *font, char **values) +parseFont(char *font, char values[NUM_FIELDS][256]) { char *ptr; int part; @@ -418,7 +420,7 @@ parseFont(char *font, char **values) while (*ptr) { if (*ptr == '-') { *bptr = 0; - values[part]=wstrdup(buffer); + strcpy(values[part], buffer); bptr = buffer; part++; } else { @@ -427,7 +429,7 @@ parseFont(char *font, char **values) ptr++; } *bptr = 0; - values[part]=wstrdup(buffer); + strcpy(values[part], buffer); return True; } @@ -452,203 +454,203 @@ isXLFD(char *font, int *length_ret) -static proplist_t foundryKey = NULL; -static proplist_t typeKey = NULL; -static proplist_t sizeKey, encKey, xlfdKey; +typedef struct { + char *weight; + char *slant; + + char *setWidth; + char *addStyle; + + char showWeight; /* not Medium */ + char showSlant; /* not R */ + char showSetWidth; /* when duplicated */ + char showAddStyle; /* when duplicated */ +} Typeface; + + +typedef struct { + char *name; + + char *foundry; + char *registry, *encoding; + + char showFoundry; /* when duplicated */ + char showRegistry; /* when duplicated */ + + WMBag *typefaces; +} Family; + static void -addSizeToEnc(proplist_t enc, char **fields) +addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256]) { - proplist_t sizel; - sizel = PLGetDictionaryEntry(enc, sizeKey); - if (!sizel) { - sizel = PLMakeArrayFromElements(PLMakeString(fields[PIXEL_SIZE]),NULL); - PLInsertDictionaryEntry(enc, sizeKey, sizel); - } else { - PLAppendArrayElement(sizel, PLMakeString(fields[PIXEL_SIZE])); - } } -static proplist_t -addTypefaceToFont(proplist_t font, char **fields) + +/* + * families (same family name) (Hashtable of family -> bag) + * registries (same family but different registries) + * + */ + +static void +addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256]) { - proplist_t face, encod, facedic, encodic; - char buffer[256]; - - strcpy(buffer, fields[WEIGHT]); + int i; + Family *fam; + WMBag *family; + + family = WMHashGet(families, fontFields[FAMILY]); - if (strcasecmp(fields[SLANT], "R")==0) - strcat(buffer, " Roman "); - else if (strcasecmp(fields[SLANT], "I")==0) - strcat(buffer, " Italic "); - else if (strcasecmp(fields[SLANT], "O")==0) - strcat(buffer, " Oblique "); - else if (strcasecmp(fields[SLANT], "RI")==0) - strcat(buffer, " Reverse Italic "); - else if (strcasecmp(fields[SLANT], "RO")==0) - strcat(buffer, " Reverse Oblique "); - else if (strcasecmp(fields[SLANT], "OT")==0) - strcat(buffer, " ? "); -/* else - * polymorphic fonts - */ - strcat(buffer, fields[SETWIDTH]); - strcat(buffer, " "); - strcat(buffer, fields[ADD_STYLE]); + if (family) { + /* look for same encoding/registry and foundry */ + for (i = 0; i < WMGetBagItemCount(family); i++) { + int enc, reg, found; + + fam = WMGetFromBag(family, i); + + enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0); + reg = (strcmp(fam->registry, fontFields[REGISTRY]) == 0); + found = (strcmp(fam->foundry, fontFields[FOUNDRY]) == 0); + + if (enc && reg && found) { + addTypefaceToFamily(fam, fontFields); + return; + } + } + /* look for same encoding/registry */ + for (i = 0; i < WMGetBagItemCount(family); i++) { + int enc, reg; + + fam = WMGetFromBag(family, i); + + enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0); + reg = (strcmp(fam->registry, fontFields[REGISTRY]) == 0); - face = PLMakeString(buffer); + if (enc && reg) { + /* has the same encoding, but the foundry is different */ + fam->showRegistry = 1; - facedic = PLGetDictionaryEntry(font, face); - if (!facedic) { - facedic = PLMakeDictionaryFromEntries(NULL, NULL, NULL); - PLInsertDictionaryEntry(font, face, facedic); - PLRelease(facedic); - } - PLRelease(face); - - strcpy(buffer, fields[REGISTRY]); - strcat(buffer, "-"); - strcat(buffer, fields[ENCODING]); - encod = PLMakeString(buffer); - - encodic = PLGetDictionaryEntry(facedic, encod); - if (!encodic) { - proplist_t tmp; - sprintf(buffer, "-%s-%s-%s-%s-%s-%s-%%d-0-%s-%s-%s-%s-%s-%s", - fields[FOUNDRY], fields[FAMILY], fields[WEIGHT], - fields[SLANT], fields[SETWIDTH], fields[ADD_STYLE], - fields[RES_X], fields[RES_Y], fields[SPACING], - fields[AV_WIDTH], fields[REGISTRY], fields[ENCODING]); - tmp = PLMakeString(buffer); - - encodic = PLMakeDictionaryFromEntries(xlfdKey, tmp, NULL); - PLRelease(tmp); - PLInsertDictionaryEntry(facedic, encod, encodic); - PLRelease(encodic); + fam = wmalloc(sizeof(Family)); + memset(fam, 0, sizeof(Family)); + + fam->name = wstrdup(fontFields[FAMILY]); + fam->foundry = wstrdup(fontFields[FOUNDRY]); + fam->registry = wstrdup(fontFields[REGISTRY]); + fam->encoding = wstrdup(fontFields[ENCODING]); + fam->showRegistry = 1; + + addTypefaceToFamily(fam, fontFields); + + WMPutInBag(family, fam); + + return; + } + } + /* look for same foundry */ + for (i = 0; i < WMGetBagItemCount(family); i++) { + int found; + + fam = WMGetFromBag(family, i); + + found = (strcmp(fam->foundry, fontFields[FOUNDRY]) == 0); + + if (found) { + /* has the same foundry, but encoding is different */ + fam->showFoundry = 1; + + fam = wmalloc(sizeof(Family)); + memset(fam, 0, sizeof(Family)); + + fam->name = wstrdup(fontFields[FAMILY]); + fam->foundry = wstrdup(fontFields[FOUNDRY]); + fam->registry = wstrdup(fontFields[REGISTRY]); + fam->encoding = wstrdup(fontFields[ENCODING]); + fam->showFoundry = 1; + + addTypefaceToFamily(fam, fontFields); + + WMPutInBag(family, fam); + + return; + } + } + /* foundry and encoding do not match anything known */ + fam = wmalloc(sizeof(Family)); + memset(fam, 0, sizeof(Family)); + + fam->name = wstrdup(fontFields[FAMILY]); + fam->foundry = wstrdup(fontFields[FOUNDRY]); + fam->registry = wstrdup(fontFields[REGISTRY]); + fam->encoding = wstrdup(fontFields[ENCODING]); + + addTypefaceToFamily(fam, fontFields); + + WMPutInBag(family, fam); + + return; } - addSizeToEnc(encodic, fields); - return font; -} + family = WMCreateBag(8); -static proplist_t -makeFontEntry(char **fields) -{ - proplist_t font; - proplist_t value; - proplist_t tmp; - value = PLMakeString(fields[FOUNDRY]); - - tmp = PLMakeDictionaryFromEntries(NULL, NULL, NULL); - - font = PLMakeDictionaryFromEntries(foundryKey, value, - typeKey, tmp, - NULL); - PLRelease(value); - PLRelease(tmp); + fam = wmalloc(sizeof(Family)); + memset(fam, 0, sizeof(Family)); - addTypefaceToFont(font, fields); + fam->name = wstrdup(fontFields[FAMILY]); + fam->foundry = wstrdup(fontFields[FOUNDRY]); + fam->registry = wstrdup(fontFields[REGISTRY]); + fam->encoding = wstrdup(fontFields[ENCODING]); + + addTypefaceToFamily(fam, fontFields); + + WMPutInBag(family, fam); - return font; + WMHashInsert(families, fam->name, family); } -static proplist_t -createFontDatabase(WMScreen *scr) + +static void +listFamilies(WMScreen *scr, WMFontPanel *panel) { char **fontList; int count; - char *fields[NUM_FIELDS]; - int font_name_length; - char buffer[256]; int i; - proplist_t fdb; - proplist_t font; - proplist_t family; - proplist_t foundry; - proplist_t tmp; - - if (!foundryKey) { - foundryKey = PLMakeString("Foundry"); - typeKey = PLMakeString("Typeface"); - encKey = PLMakeString("Encoding"); - sizeKey = PLMakeString("Sizes"); - xlfdKey = PLMakeString("XLFD"); - } + WMHashTable *families = WMCreateHashTable(WMStringHashCallbacks); + char fields[NUM_FIELDS][256]; - /* retrieve a complete listing of the available fonts */ fontList = XListFonts(scr->display, ALL_FONTS_MASK, MAX_FONTS_TO_RETRIEVE, - &count); + &count); if (!fontList) { - wwarning("could not retrieve font list"); - return NULL; + WMRunAlertPanel(scr, panel->win, "Error", + "Could not retrieve font list", "OK", NULL, NULL); + return; } - fdb = PLMakeDictionaryFromEntries(NULL, NULL, NULL); - - for (i=0; i 255) { + wwarning("font name %s is longer than 256, which is invalid.", + fontList[i]); + *fontList[i] = '\0'; + continue; + } + if (!parseFont(fontList[i], fields)) { + *fontList[i] = '\0'; + continue; } + addFontToFamily(families, (char**)fields); } - XFreeFontNames(fontList); - - return fdb; } - - - -static void -listFamilies(proplist_t fdb, WMList *list) -{ - proplist_t arr; - proplist_t fam; - int i; - - arr = PLGetAllDictionaryKeys(fdb); - for (i = 0; i + * 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); +} + diff --git a/WINGs/wtest.c b/WINGs/wtest.c index 6b3732fc..fd1f4cb0 100644 --- a/WINGs/wtest.c +++ b/WINGs/wtest.c @@ -331,6 +331,30 @@ testTextField(WMScreen *scr) void +testProgressIndicator(WMScreen *scr) +{ + WMWindow *win; + WMProgressIndicator *pPtr; + + windowCount++; + + win = WMCreateWindow(scr, "testProgressIndicator"); + WMResizeWidget(win, 292, 32); + + WMSetWindowCloseAction(win, closeAction, NULL); + + pPtr = WMCreateProgressIndicator(win); + WMMoveWidget(pPtr, 8, 8); + WMSetProgressIndicatorValue(pPtr, 75); + + WMRealizeWidget(win); + WMMapSubwidgets(win); + WMMapWidget(win); + +} + + +void testPullDown(WMScreen *scr) { WMWindow *win; @@ -437,14 +461,16 @@ testTabView(WMScreen *scr) } - #include "WUtil.h" + + int main(int argc, char **argv) { WMScreen *scr; WMPixmap *pixmap; + /* Initialize the application */ WMInitializeApplication("Test", &argc, argv); @@ -486,17 +512,19 @@ int main(int argc, char **argv) * Put the testSomething() function you want to test here. */ - testGradientButtons(scr); + testFontPanel(scr); #if 0 + + testProgressIndicator(scr); + testGradientButtons(scr); testColorWell(scr); testTabView(scr); testTextField(scr); testOpenFilePanel(scr); - testFontPanel(scr); testList(scr); testGradientButtons(scr); testScrollView(scr); diff --git a/WINGs/wtextfield.c b/WINGs/wtextfield.c index 4c355d5d..b0a58c67 100644 --- a/WINGs/wtextfield.c +++ b/WINGs/wtextfield.c @@ -983,7 +983,9 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event) if (!control_pressed) { goto normal_key; } +#ifdef XK_KP_Left case XK_KP_Left: +#endif case XK_Left: if (tPtr->cursorPosition > 0) { paintCursor(tPtr); @@ -1010,7 +1012,9 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event) if (!control_pressed) { goto normal_key; } +#ifdef XK_KP_Right case XK_KP_Right: +#endif case XK_Right: if (tPtr->cursorPosition < tPtr->textLen) { paintCursor(tPtr); @@ -1040,7 +1044,9 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event) if (!control_pressed) { goto normal_key; } +#ifdef XK_KP_Home case XK_KP_Home: +#endif case XK_Home: if (tPtr->cursorPosition > 0) { paintCursor(tPtr); @@ -1058,7 +1064,9 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event) if (!control_pressed) { goto normal_key; } +#ifdef XK_KP_End case XK_KP_End: +#endif case XK_End: if (tPtr->cursorPosition < tPtr->textLen) { paintCursor(tPtr); @@ -1104,7 +1112,9 @@ handleTextFieldKeyPress(TextField *tPtr, XEvent *event) if (!control_pressed) { goto normal_key; } +#ifdef XK_KP_Delete case XK_KP_Delete: +#endif case XK_Delete: if (tPtr->cursorPosition < tPtr->textLen || tPtr->prevselection.count) { WMRange range; -- 2.11.4.GIT