1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-19 04:20:27 +01:00

- added WMRemoveFromArrayMatching(array, match, cdata), which will remove the

first element in the array that is matched by match(item, cdata)==True.
- added WMArrayFirst(), WMArrayLast(), WMArrayNext() and WMArrayPrevious()
  functions and also WM_ITERATE_ARRAY() and WM_ETARETI_ARRAY() macros, to make
  interfaces to WMBag and WMArray similar and to make life a little simpler
  when iterating through all elements of an array.
- replaced bags with arrays wherever appropriate. This will improve
  performance a bit.
- replaced some recursive code with iterative code in WINGs/selection.c
- some code cleanup is src/
This commit is contained in:
dan
2001-04-15 01:22:56 +00:00
parent a41b8993e5
commit 046403dbbb
27 changed files with 581 additions and 662 deletions

View File

@@ -20,6 +20,8 @@ Changes since version 0.64.0:
desktop level. desktop level.
- Fixed incorrect parsing of display and screen number from $DISPLAY. - Fixed incorrect parsing of display and screen number from $DISPLAY.
- Organized the inspector panel a bit better. - Organized the inspector panel a bit better.
- Replaced bags with arrays wherever appropriate. This will improve
performance a bit.
Changes since version 0.63.1: Changes since version 0.63.1:

View File

@@ -19,6 +19,15 @@ Changes since wmaker 0.64.0:
- fixed secure textfields not to allow text selection, to avoid compromising - fixed secure textfields not to allow text selection, to avoid compromising
sensitive information by pasting it to a terminal. sensitive information by pasting it to a terminal.
- replaced wmkrange(), wmkpoint() and wmksize() functions with macros. - replaced wmkrange(), wmkpoint() and wmksize() functions with macros.
- added WMRemoveFromArrayMatching(array, match, cdata), which will remove the
first element in the array that is matched by match(item, cdata)==True.
- added WMArrayFirst(), WMArrayLast(), WMArrayNext() and WMArrayPrevious()
functions and also WM_ITERATE_ARRAY() and WM_ETARETI_ARRAY() macros, to make
interfaces to WMBag and WMArray similar and to make life a little simpler
when iterating through all elements of an array.
- replaced bags with arrays wherever appropriate. This will improve
performance a bit.
- replaced some recursive code with iterative code in selection.c
changes since wmaker 0.63.1: changes since wmaker 0.63.1:

View File

@@ -337,7 +337,7 @@ typedef struct W_View {
struct W_View *nextSister; /* next on parent's children list */ struct W_View *nextSister; /* next on parent's children list */
WMBag *eventHandlers; /* event handlers for this window */ WMArray *eventHandlers; /* event handlers for this window */
unsigned long attribFlags; unsigned long attribFlags;
XSetWindowAttributes attribs; XSetWindowAttributes attribs;
@@ -481,8 +481,6 @@ void W_DrawReliefWithGC(W_Screen *scr, Drawable d, int x, int y,
WMReliefType relief, WMReliefType relief,
GC black, GC dark, GC light, GC white); GC black, GC dark, GC light, GC white);
void W_CleanUpEvents(W_View *view);
void W_CallDestroyHandlers(W_View *view); void W_CallDestroyHandlers(W_View *view);
void W_PaintTextAndImage(W_View *view, int wrap, GC textGC, W_Font *font, void W_PaintTextAndImage(W_View *view, int wrap, GC textGC, W_Font *font,

View File

@@ -178,6 +178,7 @@ typedef struct {
} WMHashTableCallbacks; } WMHashTableCallbacks;
typedef int WMArrayIterator;
typedef void *WMBagIterator; typedef void *WMBagIterator;
@@ -415,7 +416,9 @@ void* WMReplaceInArray(WMArray *array, int index, void *item);
*/ */
int WMDeleteFromArray(WMArray *array, int index); int WMDeleteFromArray(WMArray *array, int index);
int WMRemoveFromArray(WMArray *array, void *item); #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
void* WMGetFromArray(WMArray *array, int index); void* WMGetFromArray(WMArray *array, int index);
@@ -442,6 +445,24 @@ void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange); WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
/* The following 2 functions assume that the array doesn't change between calls */
void* WMArrayNext(WMArray *array, WMArrayIterator *iter);
void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
/* The following 2 macros assume that the array doesn't change in the for loop */
#define WM_ITERATE_ARRAY(array, var, i) \
for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
var = WMArrayNext(array, &(i)))
#define WM_ETARETI_ARRAY(array, var, i) \
for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
var = WMArrayPrevious(array, &(i)))
/*..........................................................................*/ /*..........................................................................*/
@@ -514,6 +535,7 @@ void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
void* WMBagLast(WMBag *bag, WMBagIterator *ptr); void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
/* The following 4 functions assume that the bag doesn't change between calls */
void* WMBagNext(WMBag *bag, WMBagIterator *ptr); void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr); void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
@@ -523,6 +545,7 @@ void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr); int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
/* The following 2 macros assume that the bag doesn't change in the for loop */
#define WM_ITERATE_BAG(bag, var, i) \ #define WM_ITERATE_BAG(bag, var, i) \
for (var = WMBagFirst(bag, &(i)); (i) != NULL; \ for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
var = WMBagNext(bag, &(i))) var = WMBagNext(bag, &(i)))

View File

@@ -193,16 +193,25 @@ WMDeleteFromArray(WMArray *array, int index)
int int
WMRemoveFromArray(WMArray *array, void *item) WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata)
{ {
int i; int i;
if (match != NULL) {
for (i = 0; i < array->itemCount; i++) { for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == item) { if ((*match)(array->items[i], cdata)) {
WMDeleteFromArray(array, i); WMDeleteFromArray(array, i);
return 1; return 1;
} }
} }
} else {
for (i = 0; i < array->itemCount; i++) {
if (array->items[i] == cdata) {
WMDeleteFromArray(array, i);
return 1;
}
}
}
return 0; return 0;
} }
@@ -304,3 +313,54 @@ WMGetSubarrayWithRange(WMArray* array, WMRange aRange)
} }
void*
WMArrayFirst(WMArray *array, WMArrayIterator *iter)
{
if (array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = 0;
return array->items[0];
}
}
void*
WMArrayLast(WMArray *array, WMArrayIterator *iter)
{
if (array->itemCount == 0) {
*iter = WANotFound;
return NULL;
} else {
*iter = array->itemCount-1;
return array->items[*iter];
}
}
void*
WMArrayNext(WMArray *array, WMArrayIterator *iter)
{
if (*iter >= 0 && *iter < array->itemCount-1) {
return array->items[++(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}
void*
WMArrayPrevious(WMArray *array, WMArrayIterator *iter)
{
if (*iter > 0 && *iter < array->itemCount) {
return array->items[--(*iter)];
} else {
*iter = WANotFound;
return NULL;
}
}

View File

@@ -23,8 +23,7 @@
* TODO: * TODO:
* - decide if we want to support connections with external sockets, else * - decide if we want to support connections with external sockets, else
* clean up the structure of the unneeded members. * clean up the structure of the unneeded members.
* - decide what to do with all wsyserror() and wwarning() calls that are * - decide what to do with all wwarning() calls that are still there.
* still there.
* *
*/ */

View File

@@ -51,9 +51,9 @@ typedef struct InputHandler {
/* queue of timer event handlers */ /* queue of timer event handlers */
static TimerHandler *timerHandler=NULL; static TimerHandler *timerHandler=NULL;
static WMBag *idleHandler=NULL; static WMArray *idleHandler=NULL;
static WMBag *inputHandler=NULL; static WMArray *inputHandler=NULL;
#define timerPending() (timerHandler) #define timerPending() (timerHandler)
@@ -248,9 +248,9 @@ WMAddIdleHandler(WMCallback *callback, void *cdata)
handler->clientData = cdata; handler->clientData = cdata;
/* add handler at end of queue */ /* add handler at end of queue */
if (!idleHandler) { if (!idleHandler) {
idleHandler = WMCreateBag(16); idleHandler = WMCreateArrayWithDestructor(16, wfree);
} }
WMPutInBag(idleHandler, handler); WMAddToArray(idleHandler, handler);
return handler; return handler;
} }
@@ -265,11 +265,7 @@ WMDeleteIdleHandler(WMHandlerID handlerID)
if (!handler || !idleHandler) if (!handler || !idleHandler)
return; return;
pos = WMGetFirstInBag(idleHandler, handler); WMRemoveFromArray(idleHandler, handler);
if (pos != WBNotFound) {
wfree(handler);
WMDeleteFromBag(idleHandler, pos);
}
} }
@@ -287,8 +283,8 @@ WMAddInputHandler(int fd, int condition, WMInputProc *proc, void *clientData)
handler->clientData = clientData; handler->clientData = clientData;
if (!inputHandler) if (!inputHandler)
inputHandler = WMCreateBag(16); inputHandler = WMCreateArrayWithDestructor(16, wfree);
WMPutInBag(inputHandler, handler); WMAddToArray(inputHandler, handler);
return handler; return handler;
} }
@@ -304,11 +300,7 @@ WMDeleteInputHandler(WMHandlerID handlerID)
if (!handler || !inputHandler) if (!handler || !inputHandler)
return; return;
pos = WMGetFirstInBag(inputHandler, handler); WMRemoveFromArray(inputHandler, handler);
if (pos != WBNotFound) {
wfree(handler);
WMDeleteFromBag(inputHandler, pos);
}
} }
@@ -316,35 +308,32 @@ Bool
W_CheckIdleHandlers(void) W_CheckIdleHandlers(void)
{ {
IdleHandler *handler; IdleHandler *handler;
WMBag *handlerCopy; WMArray *handlerCopy;
WMBagIterator iter; WMArrayIterator iter;
if (!idleHandler || WMGetBagItemCount(idleHandler)==0) { if (!idleHandler || WMGetArrayItemCount(idleHandler)==0) {
W_FlushIdleNotificationQueue(); W_FlushIdleNotificationQueue();
/* make sure an observer in queue didn't added an idle handler */ /* make sure an observer in queue didn't added an idle handler */
return (idleHandler!=NULL && WMGetBagItemCount(idleHandler)>0); return (idleHandler!=NULL && WMGetArrayItemCount(idleHandler)>0);
} }
handlerCopy = WMCreateBag(WMGetBagItemCount(idleHandler)); handlerCopy = WMDuplicateArray(idleHandler);
WMAppendBag(handlerCopy, idleHandler);
for (handler = WMBagFirst(handlerCopy, &iter); WM_ITERATE_ARRAY(handlerCopy, handler, iter) {
iter != NULL;
handler = WMBagNext(handlerCopy, &iter)) {
/* check if the handler still exist or was removed by a callback */ /* check if the handler still exist or was removed by a callback */
if (WMGetFirstInBag(idleHandler, handler) == WBNotFound) if (WMGetFirstInArray(idleHandler, handler) == WANotFound)
continue; continue;
(*handler->callback)(handler->clientData); (*handler->callback)(handler->clientData);
WMDeleteIdleHandler(handler); WMDeleteIdleHandler(handler);
} }
WMFreeBag(handlerCopy); WMFreeArray(handlerCopy);
W_FlushIdleNotificationQueue(); W_FlushIdleNotificationQueue();
/* this is not necesarrily False, because one handler can re-add itself */ /* this is not necesarrily False, because one handler can re-add itself */
return (WMGetBagItemCount(idleHandler)>0); return (WMGetArrayItemCount(idleHandler)>0);
} }
@@ -433,7 +422,7 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
extrafd = (inputfd < 0) ? 0 : 1; extrafd = (inputfd < 0) ? 0 : 1;
if (inputHandler) if (inputHandler)
nfds = WMGetBagItemCount(inputHandler); nfds = WMGetArrayItemCount(inputHandler);
else else
nfds = 0; nfds = 0;
@@ -449,8 +438,9 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
fds[nfds].events = POLLIN; fds[nfds].events = POLLIN;
} }
/* use WM_ITERATE_ARRAY() here */
for (i = 0; i<nfds; i++) { for (i = 0; i<nfds; i++) {
handler = WMGetFromBag(inputHandler, i); handler = WMGetFromArray(inputHandler, i);
fds[i].fd = handler->fd; fds[i].fd = handler->fd;
fds[i].events = 0; fds[i].events = 0;
if (handler->mask & WIReadMask) if (handler->mask & WIReadMask)
@@ -482,17 +472,14 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
count = poll(fds, nfds+extrafd, timeout); count = poll(fds, nfds+extrafd, timeout);
if (count>0 && nfds>0) { if (count>0 && nfds>0) {
WMBag *handlerCopy = WMCreateBag(nfds); WMArray *handlerCopy = WMDuplicateArray(inputHandler);
for (i=0; i<nfds; i++)
WMPutInBag(handlerCopy, WMGetFromBag(inputHandler, i));
for (i=0; i<nfds; i++) {
int mask; int mask;
handler = WMGetFromBag(handlerCopy, i); /* use WM_ITERATE_ARRAY() here */
for (i=0; i<nfds; i++) {
handler = WMGetFromArray(handlerCopy, i);
/* check if the handler still exist or was removed by a callback */ /* check if the handler still exist or was removed by a callback */
if (WMGetFirstInBag(inputHandler, handler) == WBNotFound) if (WMGetFirstInArray(inputHandler, handler) == WANotFound)
continue; continue;
mask = 0; mask = 0;
@@ -515,12 +502,9 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
} }
} }
WMFreeBag(handlerCopy); WMFreeArray(handlerCopy);
} }
/* --oldway-- retval = ((inputfd < 0) ? (count > 0) :
fds[nfds].revents & (POLLIN|POLLRDNORM|POLLRDBAND|POLLPRI));*/
wfree(fds); wfree(fds);
W_FlushASAPNotificationQueue(); W_FlushASAPNotificationQueue();
@@ -536,7 +520,7 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
InputHandler *handler; InputHandler *handler;
if (inputHandler) if (inputHandler)
nfds = WMGetBagItemCount(inputHandler); nfds = WMGetArrayItemCount(inputHandler);
else else
nfds = 0; nfds = 0;
@@ -556,8 +540,9 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
maxfd = inputfd; maxfd = inputfd;
} }
/* use WM_ITERATE_ARRAY() here */
for (i=0; i<nfds; i++) { for (i=0; i<nfds; i++) {
handler = WMGetFromBag(inputHandler, i); handler = WMGetFromArray(inputHandler, i);
if (handler->mask & WIReadMask) if (handler->mask & WIReadMask)
FD_SET(handler->fd, &rset); FD_SET(handler->fd, &rset);
@@ -588,17 +573,14 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr); count = select(1 + maxfd, &rset, &wset, &eset, timeoutPtr);
if (count>0 && nfds>0) { if (count>0 && nfds>0) {
WMBag *handlerCopy = WMCreateBag(nfds); WMArray *handlerCopy = WMDuplicateArray(inputHandler);
for (i=0; i<nfds; i++)
WMPutInBag(handlerCopy, WMGetFromBag(inputHandler, i));
for (i=0; i<nfds; i++) {
int mask; int mask;
handler = WMGetFromBag(handlerCopy, i); /* use WM_ITERATE_ARRAY() here */
for (i=0; i<nfds; i++) {
handler = WMGetFromArray(handlerCopy, i);
/* check if the handler still exist or was removed by a callback */ /* check if the handler still exist or was removed by a callback */
if (WMGetFirstInBag(inputHandler, handler) == WBNotFound) if (WMGetFirstInArray(inputHandler, handler) == WANotFound)
continue; continue;
mask = 0; mask = 0;
@@ -618,7 +600,7 @@ W_HandleInputEvents(Bool waitForInput, int inputfd)
} }
} }
WMFreeBag(handlerCopy); WMFreeArray(handlerCopy);
} }
W_FlushASAPNotificationQueue(); W_FlushASAPNotificationQueue();

View File

@@ -385,8 +385,8 @@ WMPostNotificationName(const char *name, void *object, void *clientData)
typedef struct W_NotificationQueue { typedef struct W_NotificationQueue {
WMBag *asapQueue; WMArray *asapQueue;
WMBag *idleQueue; WMArray *idleQueue;
struct W_NotificationQueue *next; struct W_NotificationQueue *next;
} NotificationQueue; } NotificationQueue;
@@ -415,8 +415,10 @@ WMCreateNotificationQueue(void)
queue = wmalloc(sizeof(NotificationQueue)); queue = wmalloc(sizeof(NotificationQueue));
queue->asapQueue = WMCreateBag(8); queue->asapQueue =
queue->idleQueue = WMCreateBag(8); WMCreateArrayWithDestructor(8, (WMFreeDataProc*)WMReleaseNotification);
queue->idleQueue =
WMCreateArrayWithDestructor(8, (WMFreeDataProc*)WMReleaseNotification);
queue->next = notificationQueueList; queue->next = notificationQueueList;
notificationQueueList = queue; notificationQueueList = queue;
@@ -435,62 +437,50 @@ WMEnqueueNotification(WMNotificationQueue *queue, WMNotification *notification,
} }
#define NOTIF ((WMNotification*)cdata)
#define ITEM ((WMNotification*)item)
static int
matchSenderAndName(void *item, void *cdata)
{
return (NOTIF->object==ITEM->object && strcmp(NOTIF->name, ITEM->name)==0);
}
static int
matchSender(void *item, void *cdata)
{
return (NOTIF->object == ITEM->object);
}
static int
matchName(void *item, void *cdata)
{
return (strcmp(NOTIF->name, ITEM->name)==0);
}
#undef NOTIF
#undef ITEM
void void
WMDequeueNotificationMatching(WMNotificationQueue *queue, WMDequeueNotificationMatching(WMNotificationQueue *queue,
WMNotification *notification, unsigned mask) WMNotification *notification, unsigned mask)
{ {
WMBagIterator i; WMMatchDataProc *matchFunc;
WMNotification *tmp;
if ((mask & WNCOnName) && (mask & WNCOnSender)) { if ((mask & WNCOnName) && (mask & WNCOnSender))
WM_ITERATE_BAG(queue->asapQueue, tmp, i) { matchFunc = matchSenderAndName;
if (notification->object == tmp->object && else if (mask & WNCOnName)
strcmp(notification->name, tmp->name) == 0) { matchFunc = matchName;
WMRemoveFromBag(queue->asapQueue, tmp); else if (mask & WNCOnSender)
WMReleaseNotification(tmp); matchFunc = matchSender;
break; else
} return;
}
WM_ITERATE_BAG(queue->idleQueue, tmp, i) { WMRemoveFromArrayMatching(queue->asapQueue, matchFunc, notification);
if (notification->object == tmp->object && WMRemoveFromArrayMatching(queue->idleQueue, matchFunc, notification);
strcmp(notification->name, tmp->name) == 0) {
WMRemoveFromBag(queue->idleQueue, tmp);
WMReleaseNotification(tmp);
break;
}
}
} else if (mask & WNCOnName) {
WM_ITERATE_BAG(queue->asapQueue, tmp, i) {
if (strcmp(notification->name, tmp->name) == 0) {
WMRemoveFromBag(queue->asapQueue, tmp);
WMReleaseNotification(tmp);
break;
}
}
WM_ITERATE_BAG(queue->idleQueue, tmp, i) {
if (strcmp(notification->name, tmp->name) == 0) {
WMRemoveFromBag(queue->idleQueue, tmp);
WMReleaseNotification(tmp);
break;
}
}
} else if (mask & WNCOnSender) {
WM_ITERATE_BAG(queue->asapQueue, tmp, i) {
if (notification->object == tmp->object) {
WMRemoveFromBag(queue->asapQueue, tmp);
WMReleaseNotification(tmp);
break;
}
}
WM_ITERATE_BAG(queue->idleQueue, tmp, i) {
if (notification->object == tmp->object) {
WMRemoveFromBag(queue->idleQueue, tmp);
WMReleaseNotification(tmp);
break;
}
}
}
} }
@@ -510,11 +500,11 @@ WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
break; break;
case WMPostASAP: case WMPostASAP:
WMPutInBag(queue->asapQueue, notification); WMAddToArray(queue->asapQueue, notification);
break; break;
case WMPostWhenIdle: case WMPostWhenIdle:
WMPutInBag(queue->idleQueue, notification); WMAddToArray(queue->idleQueue, notification);
break; break;
} }
} }
@@ -526,12 +516,9 @@ W_FlushASAPNotificationQueue()
WMNotificationQueue *queue = notificationQueueList; WMNotificationQueue *queue = notificationQueueList;
while (queue) { while (queue) {
while (WMGetBagItemCount(queue->asapQueue)) { while (WMGetArrayItemCount(queue->asapQueue)) {
WMNotification *tmp = WMGetFromBag(queue->asapQueue, 0); WMPostNotification(WMGetFromArray(queue->asapQueue, 0));
WMDeleteFromArray(queue->asapQueue, 0);
WMPostNotification(tmp);
WMReleaseNotification(tmp);
WMDeleteFromBag(queue->asapQueue, 0);
} }
queue = queue->next; queue = queue->next;
@@ -545,12 +532,9 @@ W_FlushIdleNotificationQueue()
WMNotificationQueue *queue = notificationQueueList; WMNotificationQueue *queue = notificationQueueList;
while (queue) { while (queue) {
while (WMGetBagItemCount(queue->idleQueue)) { while (WMGetArrayItemCount(queue->idleQueue)) {
WMNotification *tmp = WMGetFromBag(queue->idleQueue, 0); WMPostNotification(WMGetFromArray(queue->idleQueue, 0));
WMDeleteFromArray(queue->idleQueue, 0);
WMPostNotification(tmp);
WMReleaseNotification(tmp);
WMDeleteFromBag(queue->idleQueue, 0);
} }
queue = queue->next; queue = queue->next;

View File

@@ -38,9 +38,9 @@ typedef struct SelectionCallback {
} SelectionCallback; } SelectionCallback;
WMBag *selCallbacks = NULL; WMArray *selCallbacks = NULL;
WMBag *selHandlers = NULL; WMArray *selHandlers = NULL;
void void
@@ -49,13 +49,13 @@ WMDeleteSelectionHandler(WMView *view, Atom selection, Time timestamp)
SelectionHandler *handler; SelectionHandler *handler;
Display *dpy = W_VIEW_SCREEN(view)->display; Display *dpy = W_VIEW_SCREEN(view)->display;
Window win = W_VIEW_DRAWABLE(view); Window win = W_VIEW_DRAWABLE(view);
WMBagIterator iter; WMArrayIterator iter;
if (!selHandlers) if (!selHandlers)
return; return;
WM_ITERATE_BAG(selHandlers, handler, iter) { WM_ITERATE_ARRAY(selHandlers, handler, iter) {
if (handler->view == view if (handler->view == view
&& (handler->selection == selection || selection == None) && (handler->selection == selection || selection == None)
&& (handler->timestamp == timestamp || timestamp == CurrentTime)) { && (handler->timestamp == timestamp || timestamp == CurrentTime)) {
@@ -64,8 +64,7 @@ WMDeleteSelectionHandler(WMView *view, Atom selection, Time timestamp)
handler->flags.delete_pending = 1; handler->flags.delete_pending = 1;
return; return;
} }
WMRemoveFromBag(selHandlers, handler); WMRemoveFromArray(selHandlers, handler);
wfree(handler);
break; break;
} }
} }
@@ -83,12 +82,12 @@ void
WMDeleteSelectionCallback(WMView *view, Atom selection, Time timestamp) WMDeleteSelectionCallback(WMView *view, Atom selection, Time timestamp)
{ {
SelectionCallback *handler; SelectionCallback *handler;
WMBagIterator iter; WMArrayIterator iter;
if (!selCallbacks) if (!selCallbacks)
return; return;
WM_ITERATE_BAG(selCallbacks, handler, iter) { WM_ITERATE_ARRAY(selCallbacks, handler, iter) {
if (handler->view == view if (handler->view == view
&& (handler->selection == selection || selection == 0) && (handler->selection == selection || selection == 0)
&& (handler->timestamp == timestamp || timestamp == CurrentTime)) { && (handler->timestamp == timestamp || timestamp == CurrentTime)) {
@@ -97,8 +96,7 @@ WMDeleteSelectionCallback(WMView *view, Atom selection, Time timestamp)
handler->flags.delete_pending = 1; handler->flags.delete_pending = 1;
return; return;
} }
WMRemoveFromBag(selCallbacks, handler); WMRemoveFromArray(selCallbacks, handler);
wfree(handler);
break; break;
} }
} }
@@ -170,38 +168,15 @@ notifySelection(XEvent *event, Atom prop)
} }
static void
deleteHandlers(WMBagIterator iter)
{
SelectionHandler *handler;
if (iter == NULL)
handler = WMBagFirst(selHandlers, &iter);
else
handler = WMBagNext(selHandlers, &iter);
if (handler == NULL)
return;
deleteHandlers(iter);
if (handler->flags.delete_pending) {
WMDeleteSelectionHandler(handler->view, handler->selection,
handler->timestamp);
}
}
static void static void
handleRequestEvent(XEvent *event) handleRequestEvent(XEvent *event)
{ {
SelectionHandler *handler; SelectionHandler *handler;
WMBagIterator iter; WMArrayIterator iter;
WMArray *copy;
Bool handledRequest = False; Bool handledRequest = False;
WM_ITERATE_BAG(selHandlers, handler, iter) { WM_ITERATE_ARRAY(selHandlers, handler, iter) {
switch (event->type) { switch (event->type) {
case SelectionClear: case SelectionClear:
@@ -285,35 +260,18 @@ handleRequestEvent(XEvent *event)
} }
} }
deleteHandlers(NULL); /* delete handlers */
} copy = WMDuplicateArray(selHandlers);
WM_ITERATE_ARRAY(copy, handler, iter) {
if (handler && handler->flags.delete_pending) {
WMDeleteSelectionHandler(handler->view, handler->selection,
static void
deleteCallbacks(WMBagIterator iter)
{
SelectionCallback *handler;
if (iter == NULL)
handler = WMBagFirst(selCallbacks, &iter);
else
handler = WMBagNext(selCallbacks, &iter);
if (handler == NULL)
return;
deleteCallbacks(iter);
if (handler->flags.delete_pending) {
WMDeleteSelectionCallback(handler->view, handler->selection,
handler->timestamp); handler->timestamp);
} }
}
WMFreeArray(copy);
} }
static WMData* static WMData*
getSelectionData(Display *dpy, Window win, Atom where) getSelectionData(Display *dpy, Window win, Atom where)
{ {
@@ -344,10 +302,11 @@ static void
handleNotifyEvent(XEvent *event) handleNotifyEvent(XEvent *event)
{ {
SelectionCallback *handler; SelectionCallback *handler;
WMBagIterator iter; WMArrayIterator iter;
WMArray *copy;
WMData *data; WMData *data;
WM_ITERATE_BAG(selCallbacks, handler, iter) { WM_ITERATE_ARRAY(selCallbacks, handler, iter) {
if (W_VIEW_DRAWABLE(handler->view) != event->xselection.requestor if (W_VIEW_DRAWABLE(handler->view) != event->xselection.requestor
&& handler->selection == event->xselection.selection) { && handler->selection == event->xselection.selection) {
@@ -373,7 +332,16 @@ handleNotifyEvent(XEvent *event)
handler->flags.done_pending = 0; handler->flags.done_pending = 0;
handler->flags.delete_pending = 1; handler->flags.delete_pending = 1;
} }
deleteCallbacks(NULL);
/* delete callbacks */
copy = WMDuplicateArray(selCallbacks);
WM_ITERATE_ARRAY(copy, handler, iter) {
if (handler && handler->flags.delete_pending) {
WMDeleteSelectionCallback(handler->view, handler->selection,
handler->timestamp);
}
}
WMFreeArray(copy);
} }
@@ -414,10 +382,10 @@ WMCreateSelectionHandler(WMView *view, Atom selection, Time timestamp,
memset(&handler->flags, 0, sizeof(handler->flags)); memset(&handler->flags, 0, sizeof(handler->flags));
if (selHandlers == NULL) { if (selHandlers == NULL) {
selHandlers = WMCreateTreeBag(); selHandlers = WMCreateArrayWithDestructor(4, wfree);
} }
WMPutInBag(selHandlers, handler); WMAddToArray(selHandlers, handler);
return True; return True;
} }
@@ -444,10 +412,10 @@ WMRequestSelection(WMView *view, Atom selection, Atom target, Time timestamp,
memset(&handler->flags, 0, sizeof(handler->flags)); memset(&handler->flags, 0, sizeof(handler->flags));
if (selCallbacks == NULL) { if (selCallbacks == NULL) {
selCallbacks = WMCreateTreeBag(); selCallbacks = WMCreateArrayWithDestructor(4, wfree);
} }
WMPutInBag(selCallbacks, handler); WMAddToArray(selCallbacks, handler);
if (!XConvertSelection(W_VIEW_SCREEN(view)->display, selection, target, if (!XConvertSelection(W_VIEW_SCREEN(view)->display, selection, target,
W_VIEW_SCREEN(view)->clipboardAtom, W_VIEW_SCREEN(view)->clipboardAtom,

View File

@@ -71,13 +71,13 @@ WMCreateEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc,
{ {
W_EventHandler *handler, *ptr; W_EventHandler *handler, *ptr;
unsigned long eventMask; unsigned long eventMask;
WMBagIterator iter; WMArrayIterator iter;
handler = NULL; handler = NULL;
eventMask = mask; eventMask = mask;
WM_ITERATE_BAG(view->eventHandlers, ptr, iter) { WM_ITERATE_ARRAY(view->eventHandlers, ptr, iter) {
if (ptr->clientData == clientData && ptr->proc == eventProc) { if (ptr->clientData == clientData && ptr->proc == eventProc) {
handler = ptr; handler = ptr;
eventMask |= ptr->eventMask; eventMask |= ptr->eventMask;
@@ -86,7 +86,7 @@ WMCreateEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc,
if (!handler) { if (!handler) {
handler = wmalloc(sizeof(W_EventHandler)); handler = wmalloc(sizeof(W_EventHandler));
WMPutInBag(view->eventHandlers, handler); WMAddToArray(view->eventHandlers, handler);
} }
/* select events for window */ /* select events for window */
handler->eventMask = eventMask; handler->eventMask = eventMask;
@@ -95,6 +95,17 @@ WMCreateEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc,
} }
static int
matchHandler(void *item, void *cdata)
{
#define H1 ((W_EventHandler*)item)
#define H2 ((W_EventHandler*)cdata)
return (H1->eventMask==H2->eventMask && H1->proc==H2->proc &&
H1->clientData==H2->clientData);
}
/* /*
* WMDeleteEventHandler-- * WMDeleteEventHandler--
* Delete event handler matching arguments from windows * Delete event handler matching arguments from windows
@@ -105,42 +116,15 @@ void
WMDeleteEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc, WMDeleteEventHandler(WMView *view, unsigned long mask, WMEventProc *eventProc,
void *clientData) void *clientData)
{ {
W_EventHandler *handler, *ptr; W_EventHandler tmp;
WMBagIterator iter;
handler = NULL; tmp.eventMask = mask;
tmp.proc = eventProc;
WM_ITERATE_BAG(view->eventHandlers, ptr, iter) { tmp.clientData = clientData;
if (ptr->eventMask == mask && ptr->proc == eventProc WMRemoveFromArrayMatching(view->eventHandlers, matchHandler, (void*)&tmp);
&& ptr->clientData == clientData) {
handler = ptr;
break;
}
}
if (!handler)
return;
WMRemoveFromBag(view->eventHandlers, handler);
wfree(handler);
} }
void
W_CleanUpEvents(WMView *view)
{
W_EventHandler *ptr;
WMBagIterator iter;
WM_ITERATE_BAG(view->eventHandlers, ptr, iter) {
wfree(ptr);
}
}
static Time static Time
getEventTime(WMScreen *screen, XEvent *event) getEventTime(WMScreen *screen, XEvent *event)
{ {
@@ -174,14 +158,15 @@ void
W_CallDestroyHandlers(W_View *view) W_CallDestroyHandlers(W_View *view)
{ {
XEvent event; XEvent event;
WMBagIterator iter; WMArrayIterator iter;
W_EventHandler *hPtr; W_EventHandler *hPtr;
event.type = DestroyNotify; event.type = DestroyNotify;
event.xdestroywindow.window = view->window; event.xdestroywindow.window = view->window;
event.xdestroywindow.event = view->window; event.xdestroywindow.event = view->window;
WM_ITERATE_BAG(view->eventHandlers, hPtr, iter) { WM_ITERATE_ARRAY(view->eventHandlers, hPtr, iter) {
if (hPtr->eventMask & StructureNotifyMask) { if (hPtr->eventMask & StructureNotifyMask) {
(*hPtr->proc)(&event, hPtr->clientData); (*hPtr->proc)(&event, hPtr->clientData);
} }
@@ -208,9 +193,9 @@ WMRelayToNextResponder(WMView *view, XEvent *event)
if (view->nextResponder) { if (view->nextResponder) {
WMView *next = view->nextResponder; WMView *next = view->nextResponder;
W_EventHandler *hPtr; W_EventHandler *hPtr;
WMBagIterator iter; WMArrayIterator iter;
WM_ITERATE_BAG(next->eventHandlers, hPtr, iter) { WM_ITERATE_ARRAY(next->eventHandlers, hPtr, iter) {
if ((hPtr->eventMask & mask)) { if ((hPtr->eventMask & mask)) {
(*hPtr->proc)(event, hPtr->clientData); (*hPtr->proc)(event, hPtr->clientData);
} }
@@ -226,7 +211,7 @@ WMHandleEvent(XEvent *event)
W_View *view, *vPtr, *toplevel; W_View *view, *vPtr, *toplevel;
unsigned long mask; unsigned long mask;
Window window; Window window;
WMBagIterator iter; WMArrayIterator iter;
if (event->type == MappingNotify) { if (event->type == MappingNotify) {
XRefreshKeyboardMapping(&event->xmapping); XRefreshKeyboardMapping(&event->xmapping);
@@ -318,7 +303,7 @@ WMHandleEvent(XEvent *event)
* might destroy the widget. */ * might destroy the widget. */
W_RetainView(toplevel); W_RetainView(toplevel);
WM_ITERATE_BAG(view->eventHandlers, hPtr, iter) { WM_ITERATE_ARRAY(view->eventHandlers, hPtr, iter) {
if ((hPtr->eventMask & mask)) { if ((hPtr->eventMask & mask)) {
(*hPtr->proc)(event, hPtr->clientData); (*hPtr->proc)(event, hPtr->clientData);
} }
@@ -331,7 +316,7 @@ WMHandleEvent(XEvent *event)
while (vPtr->parent != NULL) while (vPtr->parent != NULL)
vPtr = vPtr->parent; vPtr = vPtr->parent;
WM_ITERATE_BAG(vPtr->eventHandlers, hPtr, iter) { WM_ITERATE_ARRAY(vPtr->eventHandlers, hPtr, iter) {
if (hPtr->eventMask & mask) { if (hPtr->eventMask & mask) {
(*hPtr->proc)(event, hPtr->clientData); (*hPtr->proc)(event, hPtr->clientData);
} }

View File

@@ -471,7 +471,7 @@ typedef struct {
char showSetWidth; /* when duplicated */ char showSetWidth; /* when duplicated */
char showAddStyle; /* when duplicated */ char showAddStyle; /* when duplicated */
WMBag *sizes; WMArray *sizes;
} Typeface; } Typeface;
@@ -484,7 +484,7 @@ typedef struct {
char showFoundry; /* when duplicated */ char showFoundry; /* when duplicated */
char showRegistry; /* when duplicated */ char showRegistry; /* when duplicated */
WMBag *typefaces; WMArray *typefaces;
} Family; } Family;
@@ -515,15 +515,15 @@ addSizeToTypeface(Typeface *face, int size)
for (j = 0; j < sizeof(scalableFontSizes)/sizeof(int); j++) { for (j = 0; j < sizeof(scalableFontSizes)/sizeof(int); j++) {
size = scalableFontSizes[j]; size = scalableFontSizes[j];
if (!WMCountInBag(face->sizes, (void*)size)) { if (!WMCountInArray(face->sizes, (void*)size)) {
WMPutInBag(face->sizes, (void*)size); WMAddToArray(face->sizes, (void*)size);
} }
} }
WMSortBag(face->sizes, compare_int); WMSortArray(face->sizes, compare_int);
} else { } else {
if (!WMCountInBag(face->sizes, (void*)size)) { if (!WMCountInArray(face->sizes, (void*)size)) {
WMPutInBag(face->sizes, (void*)size); WMAddToArray(face->sizes, (void*)size);
WMSortBag(face->sizes, compare_int); WMSortArray(face->sizes, compare_int);
} }
} }
} }
@@ -534,12 +534,10 @@ static void
addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256]) addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256])
{ {
Typeface *face; Typeface *face;
WMBagIterator i; WMArrayIterator i;
if (family->typefaces) { if (family->typefaces) {
for (face = WMBagFirst(family->typefaces, &i); WM_ITERATE_ARRAY(family->typefaces, face, i) {
face != NULL;
face = WMBagNext(family->typefaces, &i)) {
int size; int size;
if (strcmp(face->weight, fontFields[WEIGHT]) != 0) { if (strcmp(face->weight, fontFields[WEIGHT]) != 0) {
@@ -556,7 +554,7 @@ addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256])
return; return;
} }
} else { } else {
family->typefaces = WMCreateBag(4); family->typefaces = WMCreateArray(4);
} }
face = wmalloc(sizeof(Typeface)); face = wmalloc(sizeof(Typeface));
@@ -567,16 +565,16 @@ addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256])
face->setWidth = wstrdup(fontFields[SETWIDTH]); face->setWidth = wstrdup(fontFields[SETWIDTH]);
face->addStyle = wstrdup(fontFields[ADD_STYLE]); face->addStyle = wstrdup(fontFields[ADD_STYLE]);
face->sizes = WMCreateBag(4); face->sizes = WMCreateArray(4);
addSizeToTypeface(face, atoi(fontFields[PIXEL_SIZE])); addSizeToTypeface(face, atoi(fontFields[PIXEL_SIZE]));
WMPutInBag(family->typefaces, face); WMAddToArray(family->typefaces, face);
} }
/* /*
* families (same family name) (Hashtable of family -> bag) * families (same family name) (Hashtable of family -> array)
* registries (same family but different registries) * registries (same family but different registries)
* *
*/ */
@@ -584,18 +582,16 @@ addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256])
static void static void
addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256]) addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256])
{ {
WMBagIterator i; WMArrayIterator i;
Family *fam; Family *fam;
WMBag *family; WMArray *family;
family = WMHashGet(families, fontFields[FAMILY]); family = WMHashGet(families, fontFields[FAMILY]);
if (family) { if (family) {
/* look for same encoding/registry and foundry */ /* look for same encoding/registry and foundry */
for (fam = WMBagFirst(family, &i); WM_ITERATE_ARRAY(family, fam, i) {
fam != NULL;
fam = WMBagNext(family, &i)) {
int enc, reg, found; int enc, reg, found;
enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0); enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0);
@@ -608,9 +604,7 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256])
} }
} }
/* look for same encoding/registry */ /* look for same encoding/registry */
for (fam = WMBagFirst(family, &i); WM_ITERATE_ARRAY(family, fam, i) {
fam != NULL;
fam = WMBagNext(family, &i)) {
int enc, reg; int enc, reg;
enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0); enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0);
@@ -631,14 +625,12 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256])
addTypefaceToFamily(fam, fontFields); addTypefaceToFamily(fam, fontFields);
WMPutInBag(family, fam); WMAddToArray(family, fam);
return; return;
} }
} }
/* look for same foundry */ /* look for same foundry */
for (fam = WMBagFirst(family, &i); WM_ITERATE_ARRAY(family, fam, i) {
fam != NULL;
fam = WMBagNext(family, &i)) {
int found; int found;
found = (strcmp(fam->foundry, fontFields[FOUNDRY]) == 0); found = (strcmp(fam->foundry, fontFields[FOUNDRY]) == 0);
@@ -658,7 +650,7 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256])
addTypefaceToFamily(fam, fontFields); addTypefaceToFamily(fam, fontFields);
WMPutInBag(family, fam); WMAddToArray(family, fam);
return; return;
} }
} }
@@ -675,11 +667,11 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256])
addTypefaceToFamily(fam, fontFields); addTypefaceToFamily(fam, fontFields);
WMPutInBag(family, fam); WMAddToArray(family, fam);
return; return;
} }
family = WMCreateBag(8); family = WMCreateArray(8);
fam = wmalloc(sizeof(Family)); fam = wmalloc(sizeof(Family));
memset(fam, 0, sizeof(Family)); memset(fam, 0, sizeof(Family));
@@ -691,7 +683,7 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256])
addTypefaceToFamily(fam, fontFields); addTypefaceToFamily(fam, fontFields);
WMPutInBag(family, fam); WMAddToArray(family, fam);
WMHashInsert(families, fam->name, family); WMHashInsert(families, fam->name, family);
} }
@@ -707,7 +699,7 @@ listFamilies(WMScreen *scr, WMFontPanel *panel)
WMHashTable *families = WMCreateHashTable(WMStringPointerHashCallbacks); WMHashTable *families = WMCreateHashTable(WMStringPointerHashCallbacks);
char fields[NUM_FIELDS][256]; char fields[NUM_FIELDS][256];
WMHashEnumerator enumer; WMHashEnumerator enumer;
WMBag *bag; WMArray *array;
fontList = XListFonts(scr->display, ALL_FONTS_MASK, MAX_FONTS_TO_RETRIEVE, fontList = XListFonts(scr->display, ALL_FONTS_MASK, MAX_FONTS_TO_RETRIEVE,
&count); &count);
@@ -739,16 +731,13 @@ listFamilies(WMScreen *scr, WMFontPanel *panel)
enumer = WMEnumerateHashTable(families); enumer = WMEnumerateHashTable(families);
while ((bag = WMNextHashEnumeratorItem(&enumer))) { while ((array = WMNextHashEnumeratorItem(&enumer))) {
WMBagIterator i; WMArrayIterator i;
Family *fam; Family *fam;
char buffer[256]; char buffer[256];
WMListItem *item; WMListItem *item;
for (fam = WMBagFirst(bag, &i); WM_ITERATE_ARRAY(array, fam, i) {
fam != NULL;
fam = WMBagNext(bag, &i)) {
strcpy(buffer, fam->name); strcpy(buffer, fam->name);
if (fam->showFoundry) { if (fam->showFoundry) {
@@ -767,7 +756,8 @@ listFamilies(WMScreen *scr, WMFontPanel *panel)
item->clientData = fam; item->clientData = fam;
} }
WMFreeBag(bag); /* Isn't this going to memleak since items weren't released? --Dan */
WMFreeArray(array);
} }
WMSortListItems(panel->famLs); WMSortListItems(panel->famLs);
@@ -835,7 +825,7 @@ familyClick(WMWidget *w, void *data)
Family *family; Family *family;
FontPanel *panel = (FontPanel*)data; FontPanel *panel = (FontPanel*)data;
Typeface *face; Typeface *face;
WMBagIterator i; WMArrayIterator i;
/* current typeface and size */ /* current typeface and size */
char *oface = NULL; char *oface = NULL;
char *osize = NULL; char *osize = NULL;
@@ -856,9 +846,7 @@ familyClick(WMWidget *w, void *data)
WMClearList(panel->typLs); WMClearList(panel->typLs);
for (face = WMBagFirst(family->typefaces, &i); WM_ITERATE_ARRAY(family->typefaces, face, i) {
face != NULL;
face = WMBagNext(family->typefaces, &i)) {
char buffer[256]; char buffer[256];
int top=0; int top=0;
WMListItem *fitem; WMListItem *fitem;
@@ -933,12 +921,12 @@ typefaceClick(WMWidget *w, void *data)
FontPanel *panel = (FontPanel*)data; FontPanel *panel = (FontPanel*)data;
WMListItem *item; WMListItem *item;
Typeface *face; Typeface *face;
WMBagIterator i; WMArrayIterator i;
char buffer[32]; char buffer[32];
char *osize = NULL; char *osize = NULL;
int sizei = -1; int sizei = -1;
int size; void *size;
osize = WMGetTextFieldText(panel->sizT); osize = WMGetTextFieldText(panel->sizT);
@@ -948,12 +936,9 @@ typefaceClick(WMWidget *w, void *data)
WMClearList(panel->sizLs); WMClearList(panel->sizLs);
for (size = (int)WMBagFirst(face->sizes, &i); WM_ITERATE_ARRAY(face->sizes, size, i) {
i != NULL; if ((int)size != 0) {
size = (int)WMBagNext(face->sizes, &i)) { sprintf(buffer, "%i", (int)size);
if (size != 0) {
sprintf(buffer, "%i", size);
WMAddListItem(panel->sizLs, buffer); WMAddListItem(panel->sizLs, buffer);
} }

View File

@@ -14,7 +14,7 @@ typedef struct W_PopUpButton {
char *caption; char *caption;
WMBag *items; WMArray *items;
short selectedItemIndex; short selectedItemIndex;
@@ -91,7 +91,8 @@ WMCreatePopUpButton(WMWidget *parent)
bPtr->flags.enabled = 1; bPtr->flags.enabled = 1;
bPtr->items = WMCreateBag(4); bPtr->items =
WMCreateArrayWithDestructor(4, (WMFreeDataProc*)WMDestroyMenuItem);
bPtr->selectedItemIndex = -1; bPtr->selectedItemIndex = -1;
@@ -128,7 +129,7 @@ WMAddPopUpButtonItem(WMPopUpButton *bPtr, char *title)
item = WMCreateMenuItem(); item = WMCreateMenuItem();
WMSetMenuItemTitle(item, title); WMSetMenuItemTitle(item, title);
WMPutInBag(bPtr->items, item); WMAddToArray(bPtr->items, item);
if (bPtr->menuView && bPtr->menuView->flags.realized) if (bPtr->menuView && bPtr->menuView->flags.realized)
resizeMenu(bPtr); resizeMenu(bPtr);
@@ -147,7 +148,7 @@ WMInsertPopUpButtonItem(WMPopUpButton *bPtr, int index, char *title)
item = WMCreateMenuItem(); item = WMCreateMenuItem();
WMSetMenuItemTitle(item, title); WMSetMenuItemTitle(item, title);
WMInsertInBag(bPtr->items, index, item); WMInsertInArray(bPtr->items, index, item);
/* if there is an selected item, update it's index to match the new /* if there is an selected item, update it's index to match the new
* position */ * position */
@@ -164,17 +165,12 @@ WMInsertPopUpButtonItem(WMPopUpButton *bPtr, int index, char *title)
void void
WMRemovePopUpButtonItem(WMPopUpButton *bPtr, int index) WMRemovePopUpButtonItem(WMPopUpButton *bPtr, int index)
{ {
WMMenuItem *item;
CHECK_CLASS(bPtr, WC_PopUpButton); CHECK_CLASS(bPtr, WC_PopUpButton);
wassertr(index >= 0 && index < WMGetBagItemCount(bPtr->items)); wassertr(index >= 0 && index < WMGetArrayItemCount(bPtr->items));
item = WMGetFromBag(bPtr->items, index); WMDeleteFromArray(bPtr->items, index);
WMDeleteFromBag(bPtr->items, index);
WMDestroyMenuItem(item);
if (bPtr->selectedItemIndex >= 0 && !bPtr->flags.pullsDown) { if (bPtr->selectedItemIndex >= 0 && !bPtr->flags.pullsDown) {
if (index < bPtr->selectedItemIndex) if (index < bPtr->selectedItemIndex)
@@ -213,9 +209,9 @@ void
WMSetPopUpButtonSelectedItem(WMPopUpButton *bPtr, int index) WMSetPopUpButtonSelectedItem(WMPopUpButton *bPtr, int index)
{ {
wassertr(index < WMGetBagItemCount(bPtr->items)); wassertr(index < WMGetArrayItemCount(bPtr->items));
/* if (index >= WMGetBagCount(bPtr->items)) /* if (index >= WMGetArrayCount(bPtr->items))
index = -1;*/ index = -1;*/
bPtr->selectedItemIndex = index; bPtr->selectedItemIndex = index;
@@ -256,24 +252,14 @@ WMSetPopUpButtonText(WMPopUpButton *bPtr, char *text)
void void
WMSetPopUpButtonItemEnabled(WMPopUpButton *bPtr, int index, Bool flag) WMSetPopUpButtonItemEnabled(WMPopUpButton *bPtr, int index, Bool flag)
{ {
WMMenuItem *item; WMSetMenuItemEnabled(WMGetFromArray(bPtr->items, index), flag);
item = WMGetFromBag(bPtr->items, index);
wassertr(item != NULL);
WMSetMenuItemEnabled(item, flag);
} }
Bool Bool
WMGetPopUpButtonItemEnabled(WMPopUpButton *bPtr, int index) WMGetPopUpButtonItemEnabled(WMPopUpButton *bPtr, int index)
{ {
WMMenuItem *item; return WMGetMenuItemEnabled(WMGetFromArray(bPtr->items, index));
item = WMGetFromBag(bPtr->items, index);
wassertrv(item != NULL, False);
return WMGetMenuItemEnabled(item);
} }
@@ -293,34 +279,24 @@ WMSetPopUpButtonPullsDown(WMPopUpButton *bPtr, Bool flag)
int int
WMGetPopUpButtonNumberOfItems(WMPopUpButton *bPtr) WMGetPopUpButtonNumberOfItems(WMPopUpButton *bPtr)
{ {
return WMGetBagItemCount(bPtr->items); return WMGetArrayItemCount(bPtr->items);
} }
char* char*
WMGetPopUpButtonItem(WMPopUpButton *bPtr, int index) WMGetPopUpButtonItem(WMPopUpButton *bPtr, int index)
{ {
WMMenuItem *item; if (index >= WMGetArrayItemCount(bPtr->items) || index < 0)
if (index >= WMGetBagItemCount(bPtr->items) || index < 0)
return NULL; return NULL;
item = WMGetFromBag(bPtr->items, index); return WMGetMenuItemTitle(WMGetFromArray(bPtr->items, index));
if (item == NULL)
return NULL;
return WMGetMenuItemTitle(item);
} }
WMMenuItem* WMMenuItem*
WMGetPopUpButtonMenuItem(WMPopUpButton *bPtr, int index) WMGetPopUpButtonMenuItem(WMPopUpButton *bPtr, int index)
{ {
WMMenuItem *item; return WMGetFromArray(bPtr->items, index);
item = WMGetFromBag(bPtr->items, index);
return item;
} }
@@ -419,7 +395,7 @@ paintMenuEntry(PopUpButton *bPtr, int index, int highlight)
int width, height, itemHeight, itemCount; int width, height, itemHeight, itemCount;
char *title; char *title;
itemCount = WMGetBagItemCount(bPtr->items); itemCount = WMGetArrayItemCount(bPtr->items);
if (index < 0 || index >= itemCount) if (index < 0 || index >= itemCount)
return; return;
@@ -464,13 +440,13 @@ makeMenuPixmap(PopUpButton *bPtr)
Pixmap pixmap; Pixmap pixmap;
W_Screen *scr = bPtr->view->screen; W_Screen *scr = bPtr->view->screen;
WMMenuItem *item; WMMenuItem *item;
WMBagIterator iter; WMArrayIterator iter;
int yo, i; int yo, i;
int width, height, itemHeight; int width, height, itemHeight;
itemHeight = bPtr->view->size.height; itemHeight = bPtr->view->size.height;
width = bPtr->view->size.width; width = bPtr->view->size.width;
height = itemHeight * WMGetBagItemCount(bPtr->items); height = itemHeight * WMGetArrayItemCount(bPtr->items);
yo = (itemHeight - WMFontHeight(scr->normalFont))/2; yo = (itemHeight - WMFontHeight(scr->normalFont))/2;
pixmap = XCreatePixmap(scr->display, bPtr->view->window, width, height, pixmap = XCreatePixmap(scr->display, bPtr->view->window, width, height,
@@ -480,7 +456,7 @@ makeMenuPixmap(PopUpButton *bPtr)
width, height); width, height);
i = 0; i = 0;
WM_ITERATE_BAG(bPtr->items, item, iter) { WM_ITERATE_ARRAY(bPtr->items, item, iter) {
GC gc; GC gc;
char *text; char *text;
@@ -518,7 +494,7 @@ resizeMenu(PopUpButton *bPtr)
{ {
int height; int height;
height = WMGetBagItemCount(bPtr->items) * bPtr->view->size.height; height = WMGetArrayItemCount(bPtr->items) * bPtr->view->size.height;
if (height > 0) if (height > 0)
W_ResizeView(bPtr->menuView, bPtr->view->size.width, height); W_ResizeView(bPtr->menuView, bPtr->view->size.width, height);
} }
@@ -539,7 +515,7 @@ popUpMenu(PopUpButton *bPtr)
resizeMenu(bPtr); resizeMenu(bPtr);
} }
if (WMGetBagItemCount(bPtr->items) < 1) if (WMGetArrayItemCount(bPtr->items) < 1)
return; return;
XTranslateCoordinates(scr->display, bPtr->view->window, scr->rootWin, XTranslateCoordinates(scr->display, bPtr->view->window, scr->rootWin,
@@ -619,7 +595,7 @@ autoScroll(void *data)
paintMenuEntry(bPtr, oldItem, False); paintMenuEntry(bPtr, oldItem, False);
if (bPtr->highlightedItem >= 0 && if (bPtr->highlightedItem >= 0 &&
bPtr->highlightedItem < WMGetBagItemCount(bPtr->items)) { bPtr->highlightedItem < WMGetArrayItemCount(bPtr->items)) {
item = WMGetPopUpButtonMenuItem(bPtr, bPtr->highlightedItem); item = WMGetPopUpButtonMenuItem(bPtr, bPtr->highlightedItem);
paintMenuEntry(bPtr, bPtr->highlightedItem, paintMenuEntry(bPtr, bPtr->highlightedItem,
WMGetMenuItemEnabled(item)); WMGetMenuItemEnabled(item));
@@ -653,7 +629,7 @@ wheelScrollUp(PopUpButton *bPtr)
static void static void
wheelScrollDown(PopUpButton *bPtr) wheelScrollDown(PopUpButton *bPtr)
{ {
int itemCount = WMGetBagItemCount(bPtr->items); int itemCount = WMGetArrayItemCount(bPtr->items);
int testIndex = bPtr->selectedItemIndex + 1; int testIndex = bPtr->selectedItemIndex + 1;
while (testIndex<itemCount && !WMGetPopUpButtonItemEnabled(bPtr, testIndex)) while (testIndex<itemCount && !WMGetPopUpButtonItemEnabled(bPtr, testIndex))
@@ -675,7 +651,7 @@ handleActionEvents(XEvent *event, void *data)
CHECK_CLASS(data, WC_PopUpButton); CHECK_CLASS(data, WC_PopUpButton);
if (WMGetBagItemCount(bPtr->items) < 1) if (WMGetArrayItemCount(bPtr->items) < 1)
return; return;
switch (event->type) { switch (event->type) {
@@ -704,7 +680,7 @@ handleActionEvents(XEvent *event, void *data)
paintMenuEntry(bPtr, oldItem, False); paintMenuEntry(bPtr, oldItem, False);
if (bPtr->highlightedItem >= 0 && if (bPtr->highlightedItem >= 0 &&
bPtr->highlightedItem < WMGetBagItemCount(bPtr->items)) { bPtr->highlightedItem < WMGetArrayItemCount(bPtr->items)) {
item = WMGetPopUpButtonMenuItem(bPtr, bPtr->highlightedItem); item = WMGetPopUpButtonMenuItem(bPtr, bPtr->highlightedItem);
paintMenuEntry(bPtr, bPtr->highlightedItem, paintMenuEntry(bPtr, bPtr->highlightedItem,
WMGetMenuItemEnabled(item)); WMGetMenuItemEnabled(item));
@@ -807,16 +783,12 @@ static void
destroyPopUpButton(PopUpButton *bPtr) destroyPopUpButton(PopUpButton *bPtr)
{ {
WMMenuItem *item; WMMenuItem *item;
WMBagIterator i;
if (bPtr->timer) { if (bPtr->timer) {
WMDeleteTimerHandler(bPtr->timer); WMDeleteTimerHandler(bPtr->timer);
} }
WM_ITERATE_BAG(bPtr->items, item, i) { WMFreeArray(bPtr->items);
WMDestroyMenuItem(item);
}
WMFreeBag(bPtr->items);
if (bPtr->caption) if (bPtr->caption)
wfree(bPtr->caption); wfree(bPtr->caption);

View File

@@ -11,20 +11,20 @@ char *WMSplitViewWillResizeSubviewsNotification
= "WMSplitViewWillResizeSubviewsNotification"; = "WMSplitViewWillResizeSubviewsNotification";
*/ */
typedef struct _T_SplitViewSubview { typedef struct W_SplitViewSubview {
WMView *view; WMView *view;
int minSize; int minSize;
int maxSize; int maxSize;
int size; int size;
int pos; int pos;
} T_SplitViewSubview; } W_SplitViewSubview;
typedef struct W_SplitView { typedef struct W_SplitView {
W_Class widgetClass; W_Class widgetClass;
W_View *view; W_View *view;
WMBag *subviewsBag; WMArray *subviews;
WMSplitViewConstrainProc *constrainProc; WMSplitViewConstrainProc *constrainProc;
@@ -36,7 +36,7 @@ typedef struct W_SplitView {
/* WMSplitViewResizeSubviewsProc *resizeSubviewsProc; */ /* WMSplitViewResizeSubviewsProc *resizeSubviewsProc; */
} SplitView; } W_SplitView;
#define DIVIDER_THICKNESS 8 #define DIVIDER_THICKNESS 8
@@ -44,41 +44,42 @@ typedef struct W_SplitView {
#define MAX_SUBVIEW_SIZE -1 #define MAX_SUBVIEW_SIZE -1
#define _GetSubviewsCount() WMGetBagItemCount(sPtr->subviewsBag) /* TODO: rewrite --Dan */
#define _GetSubviewsCount() WMGetArrayItemCount(sPtr->subviews)
#define _AddPSubviewStruct(P) \ #define _AddPSubviewStruct(P) \
(WMPutInBag(sPtr->subviewsBag,((void*)P))) (WMAddToArray(sPtr->subviews,((void*)P)))
#define _GetPSubviewStructAt(i) \ #define _GetPSubviewStructAt(i) \
((T_SplitViewSubview*)WMGetFromBag(sPtr->subviewsBag,(i))) ((W_SplitViewSubview*)WMGetFromArray(sPtr->subviews,(i)))
#define _GetSubviewAt(i) \ #define _GetSubviewAt(i) \
(((T_SplitViewSubview*)WMGetFromBag(sPtr->subviewsBag,(i)))->view) (((W_SplitViewSubview*)WMGetFromArray(sPtr->subviews,(i)))->view)
#define _GetMinSizeAt(i) \ #define _GetMinSizeAt(i) \
(((T_SplitViewSubview*)WMGetFromBag(sPtr->subviewsBag,(i)))->minSize) (((W_SplitViewSubview*)WMGetFromArray(sPtr->subviews,(i)))->minSize)
#define _GetMaxSizeAt(i) \ #define _GetMaxSizeAt(i) \
(((T_SplitViewSubview*)WMGetFromBag(sPtr->subviewsBag,(i)))->maxSize) (((W_SplitViewSubview*)WMGetFromArray(sPtr->subviews,(i)))->maxSize)
#define _GetSizeAt(i) \ #define _GetSizeAt(i) \
(((T_SplitViewSubview*)WMGetFromBag(sPtr->subviewsBag,(i)))->size) (((W_SplitViewSubview*)WMGetFromArray(sPtr->subviews,(i)))->size)
#define _GetPosAt(i) \ #define _GetPosAt(i) \
(((T_SplitViewSubview*)WMGetFromBag(sPtr->subviewsBag,(i)))->pos) (((W_SplitViewSubview*)WMGetFromArray(sPtr->subviews,(i)))->pos)
#define _GetSplitViewSize() \ #define _GetSplitViewSize() \
((sPtr->flags.vertical) ? sPtr->view->size.width : sPtr->view->size.height) ((sPtr->flags.vertical) ? sPtr->view->size.width : sPtr->view->size.height)
static void destroySplitView(SplitView *sPtr); static void destroySplitView(WMSplitView *sPtr);
static void paintSplitView(SplitView *sPtr); static void paintSplitView(WMSplitView *sPtr);
static void handleEvents(XEvent *event, void *data); static void handleEvents(XEvent *event, void *data);
static void handleActionEvents(XEvent *event, void *data); static void handleActionEvents(XEvent *event, void *data);
static void static void
getConstraints(SplitView *sPtr, int index, int *minSize, int *maxSize) getConstraints(WMSplitView *sPtr, int index, int *minSize, int *maxSize)
{ {
*minSize = MIN_SUBVIEW_SIZE; *minSize = MIN_SUBVIEW_SIZE;
*maxSize = MAX_SUBVIEW_SIZE; *maxSize = MAX_SUBVIEW_SIZE;
@@ -97,9 +98,9 @@ getConstraints(SplitView *sPtr, int index, int *minSize, int *maxSize)
static void static void
updateConstraints(SplitView *sPtr) updateConstraints(WMSplitView *sPtr)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
int i, count; int i, count;
count = _GetSubviewsCount(); count = _GetSubviewsCount();
@@ -111,7 +112,7 @@ updateConstraints(SplitView *sPtr)
static void static void
resizeView(SplitView *sPtr, WMView *view, int size) resizeView(WMSplitView *sPtr, WMView *view, int size)
{ {
int width, height; int width, height;
@@ -131,7 +132,7 @@ resizeView(SplitView *sPtr, WMView *view, int size)
static void static void
reparentView(SplitView *sPtr, WMView *view, int pos) reparentView(WMSplitView *sPtr, WMView *view, int pos)
{ {
int x, y; int x, y;
@@ -148,7 +149,7 @@ reparentView(SplitView *sPtr, WMView *view, int pos)
static void static void
moveView(SplitView *sPtr, WMView *view, int pos) moveView(WMSplitView *sPtr, WMView *view, int pos)
{ {
int x, y; int x, y;
@@ -168,10 +169,10 @@ moveView(SplitView *sPtr, WMView *view, int pos)
static int static int
checkSizes(SplitView *sPtr) checkSizes(WMSplitView *sPtr)
{ {
int i, count, offset; int i, count, offset;
T_SplitViewSubview *p; W_SplitViewSubview *p;
count = _GetSubviewsCount(); count = _GetSubviewsCount();
offset = 0; offset = 0;
@@ -191,10 +192,10 @@ checkSizes(SplitView *sPtr)
static void static void
checkPositions(SplitView *sPtr) checkPositions(WMSplitView *sPtr)
{ {
int i, count, pos; int i, count, pos;
T_SplitViewSubview *p; W_SplitViewSubview *p;
count = _GetSubviewsCount(); count = _GetSubviewsCount();
pos = 0; pos = 0;
@@ -207,10 +208,10 @@ checkPositions(SplitView *sPtr)
static void static void
updateSubviewsGeom(SplitView *sPtr) updateSubviewsGeom(WMSplitView *sPtr)
{ {
int i, count; int i, count;
T_SplitViewSubview *p; W_SplitViewSubview *p;
count = _GetSubviewsCount(); count = _GetSubviewsCount();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
@@ -222,7 +223,7 @@ updateSubviewsGeom(SplitView *sPtr)
static int static int
getTotalSize(SplitView *sPtr) getTotalSize(WMSplitView *sPtr)
{ {
int i, count, totSize; int i, count, totSize;
@@ -239,9 +240,9 @@ getTotalSize(SplitView *sPtr)
static Bool static Bool
distributeOffsetEqually(SplitView *sPtr, int offset) distributeOffsetEqually(WMSplitView *sPtr, int offset)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
int i, count, sizeChanged, forced; int i, count, sizeChanged, forced;
if ((count = _GetSubviewsCount()) < 1) if ((count = _GetSubviewsCount()) < 1)
@@ -280,9 +281,9 @@ distributeOffsetEqually(SplitView *sPtr, int offset)
static Bool static Bool
distributeOffsetFormEnd(SplitView *sPtr, int offset) distributeOffsetFormEnd(WMSplitView *sPtr, int offset)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
int i, count, sizeTmp; int i, count, sizeTmp;
if ((count = _GetSubviewsCount()) < 1) if ((count = _GetSubviewsCount()) < 1)
@@ -312,7 +313,7 @@ distributeOffsetFormEnd(SplitView *sPtr, int offset)
static void static void
adjustSplitViewSubviews(WMSplitView *sPtr) adjustSplitViewSubviews(WMSplitView *sPtr)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
int i, count, adjSize, adjPad; int i, count, adjSize, adjPad;
CHECK_CLASS(sPtr, WC_SplitView); CHECK_CLASS(sPtr, WC_SplitView);
@@ -349,12 +350,12 @@ adjustSplitViewSubviews(WMSplitView *sPtr)
static void static void
handleSubviewResized(void *self, WMNotification *notif) handleSubviewResized(void *self, WMNotification *notif)
{ {
SplitView *sPtr = (SplitView*)self; WMSplitView *sPtr = (WMSplitView*)self;
CHECK_CLASS(sPtr, WC_SplitView); CHECK_CLASS(sPtr, WC_SplitView);
if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) { if (WMGetNotificationName(notif) == WMViewSizeDidChangeNotification) {
T_SplitViewSubview *p; W_SplitViewSubview *p;
int i, count, done; int i, count, done;
WMView *view = WMGetNotificationObject(notif); WMView *view = WMGetNotificationObject(notif);
@@ -380,7 +381,7 @@ handleSubviewResized(void *self, WMNotification *notif)
static void static void
handleViewResized(void *self, WMNotification *notification) handleViewResized(void *self, WMNotification *notification)
{ {
SplitView *sPtr = (SplitView*)self; WMSplitView *sPtr = (WMSplitView*)self;
#if 0 #if 0
printf("---- (handleViewResized - 1) ----\n"); printf("---- (handleViewResized - 1) ----\n");
@@ -407,9 +408,9 @@ handleViewResized(void *self, WMNotification *notification)
static void static void
paintSplitView(SplitView *sPtr) paintSplitView(WMSplitView *sPtr)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
W_Screen *scr = sPtr->view->screen; W_Screen *scr = sPtr->view->screen;
int x, y, i, count; int x, y, i, count;
WMPixmap *dimple = scr->scrollerDimple; WMPixmap *dimple = scr->scrollerDimple;
@@ -469,7 +470,7 @@ paintSplitView(SplitView *sPtr)
static void static void
drawDragingRectangle(SplitView *sPtr, int pos) drawDragingRectangle(WMSplitView *sPtr, int pos)
{ {
int x, y, w, h; int x, y, w, h;
@@ -491,7 +492,7 @@ drawDragingRectangle(SplitView *sPtr, int pos)
static void static void
getMinMaxDividerCoord(SplitView *sPtr, int divider, int *minC, int *maxC) getMinMaxDividerCoord(WMSplitView *sPtr, int divider, int *minC, int *maxC)
{ {
int relMinC, relMaxC; int relMinC, relMaxC;
int totSize = _GetSizeAt(divider) + _GetSizeAt(divider+1); int totSize = _GetSizeAt(divider) + _GetSizeAt(divider+1);
@@ -512,7 +513,7 @@ getMinMaxDividerCoord(SplitView *sPtr, int divider, int *minC, int *maxC)
static void static void
dragDivider(SplitView *sPtr, int clickX, int clickY) dragDivider(WMSplitView *sPtr, int clickX, int clickY)
{ {
int divider, pos, ofs, done, dragging; int divider, pos, ofs, done, dragging;
int i, count; int i, count;
@@ -585,7 +586,7 @@ dragDivider(SplitView *sPtr, int clickX, int clickY)
} }
if (dragging) { if (dragging) {
T_SplitViewSubview *p1, *p2; W_SplitViewSubview *p1, *p2;
int totSize; int totSize;
p1 = _GetPSubviewStructAt(divider); p1 = _GetPSubviewStructAt(divider);
@@ -608,7 +609,7 @@ dragDivider(SplitView *sPtr, int clickX, int clickY)
static void static void
handleEvents(XEvent *event, void *data) handleEvents(XEvent *event, void *data)
{ {
SplitView *sPtr = (SplitView*)data; WMSplitView *sPtr = (WMSplitView*)data;
CHECK_CLASS(data, WC_SplitView); CHECK_CLASS(data, WC_SplitView);
@@ -644,14 +645,9 @@ handleActionEvents(XEvent *event, void *data)
static void static void
destroySplitView(SplitView *sPtr) destroySplitView(WMSplitView *sPtr)
{ {
int i, count; WMFreeArray(sPtr->subviews);
count = _GetSubviewsCount();
for (i = 0; i < count; i++)
wfree(WMGetFromBag(sPtr->subviewsBag, i));
WMFreeBag(sPtr->subviewsBag);
WMRemoveNotificationObserver(sPtr); WMRemoveNotificationObserver(sPtr);
@@ -661,10 +657,10 @@ destroySplitView(SplitView *sPtr)
WMSplitView* WMSplitView*
WMCreateSplitView(WMWidget *parent) WMCreateSplitView(WMWidget *parent)
{ {
SplitView *sPtr; WMSplitView *sPtr;
sPtr = wmalloc(sizeof(SplitView)); sPtr = wmalloc(sizeof(WMSplitView));
memset(sPtr, 0, sizeof(SplitView)); memset(sPtr, 0, sizeof(WMSplitView));
sPtr->widgetClass = WC_SplitView; sPtr->widgetClass = WC_SplitView;
@@ -689,7 +685,7 @@ WMCreateSplitView(WMWidget *parent)
WMAddNotificationObserver(handleViewResized, sPtr, WMAddNotificationObserver(handleViewResized, sPtr,
WMViewSizeDidChangeNotification, sPtr->view); WMViewSizeDidChangeNotification, sPtr->view);
sPtr->subviewsBag = WMCreateBag(8); sPtr->subviews = WMCreateArrayWithDestructor(8, wfree);
return sPtr; return sPtr;
} }
@@ -712,11 +708,11 @@ void
WMAddSplitViewSubview(WMSplitView *sPtr, WMView *subview) WMAddSplitViewSubview(WMSplitView *sPtr, WMView *subview)
{ {
int wasMapped, count; int wasMapped, count;
T_SplitViewSubview *p; W_SplitViewSubview *p;
CHECK_CLASS(sPtr, WC_SplitView); CHECK_CLASS(sPtr, WC_SplitView);
if (!(p = (T_SplitViewSubview*)wmalloc(sizeof(T_SplitViewSubview)))) if (!(p = (W_SplitViewSubview*)wmalloc(sizeof(W_SplitViewSubview))))
return; return;
wasMapped = subview->flags.mapped; wasMapped = subview->flags.mapped;
@@ -731,7 +727,7 @@ WMAddSplitViewSubview(WMSplitView *sPtr, WMView *subview)
else else
p->size = subview->size.height; p->size = subview->size.height;
WMPutInBag(sPtr->subviewsBag,(void*)p); WMAddToArray(sPtr->subviews, p);
reparentView(sPtr, subview, 0); reparentView(sPtr, subview, 0);
/* /*
@@ -772,17 +768,17 @@ WMGetSplitViewSubviewAt(WMSplitView *sPtr, int index)
void void
WMRemoveSplitViewSubview(WMSplitView *sPtr, WMView *view) WMRemoveSplitViewSubview(WMSplitView *sPtr, WMView *view)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
int i, count; int i, count;
CHECK_CLASS(sPtr, WC_SplitView); CHECK_CLASS(sPtr, WC_SplitView);
/* TODO: rewrite this. This code with macros is getting more complex than it worths */
count = _GetSubviewsCount(); count = _GetSubviewsCount();
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
p = _GetPSubviewStructAt(i); p = _GetPSubviewStructAt(i);
if (p->view == view) { if (p->view == view) {
wfree(p); WMDeleteFromArray(sPtr->subviews, i);
WMDeleteFromBag(sPtr->subviewsBag, i);
sPtr->flags.adjustOnPaint = 1; sPtr->flags.adjustOnPaint = 1;
paintSplitView(sPtr); paintSplitView(sPtr);
break; break;
@@ -794,14 +790,14 @@ WMRemoveSplitViewSubview(WMSplitView *sPtr, WMView *view)
void void
WMRemoveSplitViewSubviewAt(WMSplitView *sPtr, int index) WMRemoveSplitViewSubviewAt(WMSplitView *sPtr, int index)
{ {
T_SplitViewSubview *p; W_SplitViewSubview *p;
CHECK_CLASS(sPtr, WC_SplitView); CHECK_CLASS(sPtr, WC_SplitView);
/* TODO: same about rewrite */
if (index >= 0 && index < _GetSubviewsCount()) { if (index >= 0 && index < _GetSubviewsCount()) {
p = _GetPSubviewStructAt(index); p = _GetPSubviewStructAt(index);
wfree(p); WMDeleteFromArray(sPtr->subviews, index);
WMDeleteFromBag(sPtr->subviewsBag, index);
sPtr->flags.adjustOnPaint = 1; sPtr->flags.adjustOnPaint = 1;
paintSplitView(sPtr); paintSplitView(sPtr);
} }

View File

@@ -132,7 +132,7 @@ createView(W_Screen *screen, W_View *parent)
view->refCount = 1; view->refCount = 1;
view->eventHandlers = WMCreateBag(4); view->eventHandlers = WMCreateArrayWithDestructor(4, wfree);
return view; return view;
} }
@@ -441,9 +441,8 @@ destroyView(W_View *view)
/* remove self from parent's children list */ /* remove self from parent's children list */
unparentView(view); unparentView(view);
W_CleanUpEvents(view); /* the array has a wfree() destructor that will be called automatically */
WMFreeArray(view->eventHandlers);
WMFreeBag(view->eventHandlers);
view->eventHandlers = NULL; view->eventHandlers = NULL;
WMUnregisterViewDraggedTypes(view); WMUnregisterViewDraggedTypes(view);

View File

@@ -56,7 +56,7 @@ typedef struct W_EditMenu {
struct W_EditMenu *parent; struct W_EditMenu *parent;
WMBag *items; /* EditMenuItem */ WMArray *items; /* EditMenuItem */
EditMenuItem *selectedItem; EditMenuItem *selectedItem;
@@ -457,7 +457,7 @@ makeEditMenu(WMScreen *scr, WMWidget *parent, char *title)
WMAddNotificationObserver(itemSelectObserver, mPtr, WMAddNotificationObserver(itemSelectObserver, mPtr,
"EditMenuItemSelected", NULL); "EditMenuItemSelected", NULL);
mPtr->items = WMCreateBag(4); mPtr->items = WMCreateArray(4);
WMCreateEventHandler(mPtr->view, ExposureMask|StructureNotifyMask, WMCreateEventHandler(mPtr->view, ExposureMask|StructureNotifyMask,
handleEvents, mPtr); handleEvents, mPtr);
@@ -467,7 +467,7 @@ makeEditMenu(WMScreen *scr, WMWidget *parent, char *title)
item = WCreateEditMenuItem(mPtr, title, True); item = WCreateEditMenuItem(mPtr, title, True);
WMMapWidget(item); WMMapWidget(item);
WMPutInBag(mPtr->items, item); WMAddToArray(mPtr->items, item);
mPtr->flags.isTitled = 1; mPtr->flags.isTitled = 1;
} }
@@ -511,14 +511,14 @@ WInsertMenuItemWithTitle(WEditMenu *mPtr, int index, char *title)
WMMapWidget(item); WMMapWidget(item);
if (index >= WMGetBagItemCount(mPtr->items)) { if (index >= WMGetArrayItemCount(mPtr->items)) {
WMPutInBag(mPtr->items, item); WMAddToArray(mPtr->items, item);
} else { } else {
if (index < 0) if (index < 0)
index = 0; index = 0;
if (mPtr->flags.isTitled) if (mPtr->flags.isTitled)
index++; index++;
WMInsertInBag(mPtr->items, index, item); WMInsertInArray(mPtr->items, index, item);
} }
updateMenuContents(mPtr); updateMenuContents(mPtr);
@@ -530,17 +530,17 @@ WInsertMenuItemWithTitle(WEditMenu *mPtr, int index, char *title)
WEditMenuItem* WEditMenuItem*
WGetEditMenuItem(WEditMenu *mPtr, int index) WGetEditMenuItem(WEditMenu *mPtr, int index)
{ {
if (index >= WMGetBagItemCount(mPtr->items)) if (index >= WMGetArrayItemCount(mPtr->items))
return NULL; return NULL;
else
return WMGetFromBag(mPtr->items, index + (mPtr->flags.isTitled ? 1 : 0)); return WMGetFromArray(mPtr->items, index + (mPtr->flags.isTitled ? 1 : 0));
} }
WEditMenuItem* WEditMenuItem*
WAddMenuItemWithTitle(WEditMenu *mPtr, char *title) WAddMenuItemWithTitle(WEditMenu *mPtr, char *title)
{ {
return WInsertMenuItemWithTitle(mPtr, WMGetBagItemCount(mPtr->items), return WInsertMenuItemWithTitle(mPtr, WMGetArrayItemCount(mPtr->items),
title); title);
} }
@@ -551,7 +551,7 @@ WSetEditMenuTitle(WEditMenu *mPtr, char *title)
{ {
WEditMenuItem *item; WEditMenuItem *item;
item = WMGetFromBag(mPtr->items, 0); item = WMGetFromArray(mPtr->items, 0);
wfree(item->label); wfree(item->label);
item->label = wstrdup(title); item->label = wstrdup(title);
@@ -568,7 +568,7 @@ WGetEditMenuTitle(WEditMenu *mPtr)
{ {
WEditMenuItem *item; WEditMenuItem *item;
item = WMGetFromBag(mPtr->items, 0); item = WMGetFromArray(mPtr->items, 0);
return item->label; return item->label;
} }
@@ -598,27 +598,12 @@ WGetEditMenuSubmenu(WEditMenu *mPtr, WEditMenuItem *item)
} }
static int
simpleMatch(void *a, void *b)
{
return ((a == b) ? 1 : 0);
}
void void
WRemoveEditMenuItem(WEditMenu *mPtr, WEditMenuItem *item) WRemoveEditMenuItem(WEditMenu *mPtr, WEditMenuItem *item)
{ {
int index; if (WMRemoveFromArray(mPtr->items, item) != 0) {
index = WMFindInBag(mPtr->items, simpleMatch, item);
if (index == WBNotFound) {
return;
}
WMDeleteFromBag(mPtr->items, index);
updateMenuContents(mPtr); updateMenuContents(mPtr);
}
} }
@@ -662,7 +647,7 @@ WSetEditMenuMaxSize(WEditMenu *mPtr, WMSize size)
WMPoint WMPoint
WGetEditMenuLocationForSubmenu(WEditMenu *mPtr, WEditMenu *submenu) WGetEditMenuLocationForSubmenu(WEditMenu *mPtr, WEditMenu *submenu)
{ {
WMBagIterator iter; WMArrayIterator iter;
WEditMenuItem *item; WEditMenuItem *item;
int y; int y;
@@ -670,7 +655,7 @@ WGetEditMenuLocationForSubmenu(WEditMenu *mPtr, WEditMenu *submenu)
y = -mPtr->titleHeight; y = -mPtr->titleHeight;
else else
y = 0; y = 0;
WM_ITERATE_BAG(mPtr->items, item, iter) { WM_ITERATE_ARRAY(mPtr->items, item, iter) {
if (item->submenu == submenu) { if (item->submenu == submenu) {
WMPoint pt = WMGetViewScreenPosition(mPtr->view); WMPoint pt = WMGetViewScreenPosition(mPtr->view);
@@ -705,7 +690,7 @@ WTearOffEditMenu(WEditMenu *menu, WEditMenu *submenu)
submenu->flags.isTornOff = 1; submenu->flags.isTornOff = 1;
item = (WEditMenuItem*)WMGetFromBag(submenu->items, 0); item = (WEditMenuItem*)WMGetFromArray(submenu->items, 0);
submenu->closeB = WMCreateCommandButton(item); submenu->closeB = WMCreateCommandButton(item);
WMResizeWidget(submenu->closeB, 15, 15); WMResizeWidget(submenu->closeB, 15, 15);
@@ -802,14 +787,14 @@ updateMenuContents(WEditMenu *mPtr)
int i; int i;
int iheight = mPtr->itemHeight; int iheight = mPtr->itemHeight;
int offs = 1; int offs = 1;
WMBagIterator iter; WMArrayIterator iter;
WEditMenuItem *item; WEditMenuItem *item;
newW = 0; newW = 0;
newH = offs; newH = offs;
i = 0; i = 0;
WM_ITERATE_BAG(mPtr->items, item, iter) { WM_ITERATE_ARRAY(mPtr->items, item, iter) {
w = getItemTextWidth(item); w = getItemTextWidth(item);
newW = WMAX(w, newW); newW = WMAX(w, newW);
@@ -847,7 +832,7 @@ updateMenuContents(WEditMenu *mPtr)
newW -= 2*offs; newW -= 2*offs;
i = 0; i = 0;
WM_ITERATE_BAG(mPtr->items, item, iter) { WM_ITERATE_ARRAY(mPtr->items, item, iter) {
if (i == 0 && mPtr->flags.isTitled) { if (i == 0 && mPtr->flags.isTitled) {
WMResizeWidget(item, newW, mPtr->titleHeight); WMResizeWidget(item, newW, mPtr->titleHeight);
} else { } else {
@@ -999,8 +984,8 @@ textEndedEditing(struct WMTextFieldDelegate *self, WMNotification *notif)
case WMTabTextMovement: case WMTabTextMovement:
stopEditItem(menu, True); stopEditItem(menu, True);
i = WMFindInBag(menu->items, simpleMatch, menu->selectedItem); i = WMGetFirstInArray(menu->items, menu->selectedItem);
item = WMGetFromBag(menu->items, i+1); item = WMGetFromArray(menu->items, i+1);
if (item != NULL) { if (item != NULL) {
selectItem(menu, item); selectItem(menu, item);
editItemLabel(item); editItemLabel(item);
@@ -1010,8 +995,8 @@ textEndedEditing(struct WMTextFieldDelegate *self, WMNotification *notif)
case WMBacktabTextMovement: case WMBacktabTextMovement:
stopEditItem(menu, True); stopEditItem(menu, True);
i = WMFindInBag(menu->items, simpleMatch, menu->selectedItem); i = WMGetFirstInArray(menu->items, menu->selectedItem);
item = WMGetFromBag(menu->items, i-1); item = WMGetFromArray(menu->items, i-1);
if (item != NULL) { if (item != NULL) {
selectItem(menu, item); selectItem(menu, item);
editItemLabel(item); editItemLabel(item);
@@ -1037,7 +1022,6 @@ editItemLabel(WEditMenuItem *item)
{ {
WEditMenu *mPtr = item->parent; WEditMenu *mPtr = item->parent;
WMTextField *tf; WMTextField *tf;
int i;
if (!mPtr->flags.isEditable) { if (!mPtr->flags.isEditable) {
return; return;
@@ -1058,8 +1042,6 @@ editItemLabel(WEditMenuItem *item)
} }
tf = mPtr->tfield; tf = mPtr->tfield;
i = WMFindInBag(mPtr->items, simpleMatch, item);
WMSetTextFieldText(tf, item->label); WMSetTextFieldText(tf, item->label);
WMSelectTextFieldRange(tf, wmkrange(0, strlen(item->label))); WMSelectTextFieldRange(tf, wmkrange(0, strlen(item->label)));
WMResizeWidget(tf, mPtr->view->size.width, mPtr->itemHeight); WMResizeWidget(tf, mPtr->view->size.width, mPtr->itemHeight);
@@ -1210,10 +1192,10 @@ handleItemDrop(WEditMenu *menu, WEditMenuItem *item, int x, int y)
index++; index++;
} }
if (index > WMGetBagItemCount(menu->items)) { if (index > WMGetArrayItemCount(menu->items)) {
WMPutInBag(menu->items, item); WMAddToArray(menu->items, item);
} else { } else {
WMInsertInBag(menu->items, index, item); WMInsertInArray(menu->items, index, item);
} }
W_ReparentView(item->view, menu->view, 0, index*menu->itemHeight); W_ReparentView(item->view, menu->view, 0, index*menu->itemHeight);
@@ -1300,7 +1282,7 @@ duplicateMenu(WEditMenu *menu)
{ {
WEditMenu *nmenu; WEditMenu *nmenu;
WEditMenuItem *item; WEditMenuItem *item;
WMBagIterator iter; WMArrayIterator iter;
Bool first = menu->flags.isTitled; Bool first = menu->flags.isTitled;
nmenu = WCreateEditMenu(WMWidgetScreen(menu), WGetEditMenuTitle(menu)); nmenu = WCreateEditMenu(WMWidgetScreen(menu), WGetEditMenuTitle(menu));
@@ -1308,7 +1290,7 @@ duplicateMenu(WEditMenu *menu)
memcpy(&nmenu->flags, &menu->flags, sizeof(menu->flags)); memcpy(&nmenu->flags, &menu->flags, sizeof(menu->flags));
nmenu->delegate = menu->delegate; nmenu->delegate = menu->delegate;
WM_ITERATE_BAG(menu->items, item, iter) { WM_ITERATE_ARRAY(menu->items, item, iter) {
WEditMenuItem *nitem; WEditMenuItem *nitem;
if (first) { if (first) {
@@ -1536,17 +1518,17 @@ static void
destroyEditMenu(WEditMenu *mPtr) destroyEditMenu(WEditMenu *mPtr)
{ {
WEditMenuItem *item; WEditMenuItem *item;
WMBagIterator iter; WMArrayIterator iter;
WMRemoveNotificationObserver(mPtr); WMRemoveNotificationObserver(mPtr);
WM_ITERATE_BAG(mPtr->items, item, iter) { WM_ITERATE_ARRAY(mPtr->items, item, iter) {
if (item->submenu) { if (item->submenu) {
WMDestroyWidget(item->submenu); WMDestroyWidget(item->submenu);
} }
} }
WMFreeBag(mPtr->items); WMFreeArray(mPtr->items);
wfree(mPtr->tdelegate); wfree(mPtr->tdelegate);

View File

@@ -58,7 +58,7 @@ struct _ImageBrowser {
ImageBrowserDelegate *delegate; ImageBrowserDelegate *delegate;
WMBag *previews; WMArray *previews;
}; };

View File

@@ -1699,8 +1699,8 @@ wSelectWindow(WWindow *wwin, Bool flag)
} }
if (!scr->selected_windows) if (!scr->selected_windows)
scr->selected_windows = WMCreateBag(4); scr->selected_windows = WMCreateArray(4);
WMPutInBag(scr->selected_windows, wwin); WMAddToArray(scr->selected_windows, wwin);
} else { } else {
wwin->flags.selected = 0; wwin->flags.selected = 0;
XSetWindowBorder(dpy, wwin->frame->core->window, XSetWindowBorder(dpy, wwin->frame->core->window,
@@ -1711,7 +1711,7 @@ wSelectWindow(WWindow *wwin, Bool flag)
} }
if (scr->selected_windows) { if (scr->selected_windows) {
WMRemoveFromBag(scr->selected_windows, wwin); WMRemoveFromArray(scr->selected_windows, wwin);
} }
} }
} }

View File

@@ -292,17 +292,17 @@ numberOfSelectedIcons(WDock *dock)
} }
static WMBag* static WMArray*
getSelected(WDock *dock) getSelected(WDock *dock)
{ {
WMBag *ret = WMCreateBag(8); WMArray *ret = WMCreateArray(8);
WAppIcon *btn; WAppIcon *btn;
int i; int i;
for (i=1; i<dock->max_icons; i++) { for (i=1; i<dock->max_icons; i++) {
btn = dock->icon_array[i]; btn = dock->icon_array[i];
if (btn && btn->icon->selected) { if (btn && btn->icon->selected) {
WMPutInBag(ret, btn); WMAddToArray(ret, btn);
} }
} }
@@ -461,9 +461,9 @@ omnipresentCallback(WMenu *menu, WMenuEntry *entry)
WAppIcon *clickedIcon = entry->clientdata; WAppIcon *clickedIcon = entry->clientdata;
WAppIcon *aicon; WAppIcon *aicon;
WDock *dock; WDock *dock;
WMBag *selectedIcons; WMArray *selectedIcons;
WMArrayIterator iter;
int failed; int failed;
int i;
assert(entry->clientdata!=NULL); assert(entry->clientdata!=NULL);
@@ -471,19 +471,17 @@ omnipresentCallback(WMenu *menu, WMenuEntry *entry)
selectedIcons = getSelected(dock); selectedIcons = getSelected(dock);
if (!WMGetBagItemCount(selectedIcons)) if (!WMGetArrayItemCount(selectedIcons))
WMPutInBag(selectedIcons, clickedIcon); WMAddToArray(selectedIcons, clickedIcon);
failed = 0; failed = 0;
for (i = 0; i < WMGetBagItemCount(selectedIcons); i++) { WM_ITERATE_ARRAY(selectedIcons, aicon, iter) {
aicon = WMGetFromBag(selectedIcons, i);
if (wClipMakeIconOmnipresent(aicon, !aicon->omnipresent) == WO_FAILED) if (wClipMakeIconOmnipresent(aicon, !aicon->omnipresent) == WO_FAILED)
failed++; failed++;
else if (aicon->icon->selected) else if (aicon->icon->selected)
wIconSelect(aicon->icon); wIconSelect(aicon->icon);
} }
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
if (failed > 1) { if (failed > 1) {
wMessageDialog(dock->screen_ptr, _("Warning"), wMessageDialog(dock->screen_ptr, _("Warning"),
@@ -511,9 +509,9 @@ removeIconsCallback(WMenu *menu, WMenuEntry *entry)
WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata; WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
WDock *dock; WDock *dock;
WAppIcon *aicon; WAppIcon *aicon;
WMBag *selectedIcons; WMArray *selectedIcons;
int keepit; int keepit;
WMBagIterator it; WMArrayIterator it;
assert(clickedIcon!=NULL); assert(clickedIcon!=NULL);
@@ -521,22 +519,22 @@ removeIconsCallback(WMenu *menu, WMenuEntry *entry)
selectedIcons = getSelected(dock); selectedIcons = getSelected(dock);
if (WMGetBagItemCount(selectedIcons)) { if (WMGetArrayItemCount(selectedIcons)) {
if (wMessageDialog(dock->screen_ptr, _("Workspace Clip"), if (wMessageDialog(dock->screen_ptr, _("Workspace Clip"),
_("All selected icons will be removed!"), _("All selected icons will be removed!"),
_("OK"), _("Cancel"), NULL)!=WAPRDefault) { _("OK"), _("Cancel"), NULL)!=WAPRDefault) {
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
return; return;
} }
} else { } else {
if (clickedIcon->xindex==0 && clickedIcon->yindex==0) { if (clickedIcon->xindex==0 && clickedIcon->yindex==0) {
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
return; return;
} }
WMPutInBag(selectedIcons, clickedIcon); WMAddToArray(selectedIcons, clickedIcon);
} }
WM_ITERATE_BAG(selectedIcons, aicon, it) { WM_ITERATE_ARRAY(selectedIcons, aicon, it) {
keepit = aicon->running && wApplicationOf(aicon->main_window); keepit = aicon->running && wApplicationOf(aicon->main_window);
wDockDetach(dock, aicon); wDockDetach(dock, aicon);
if (keepit) { if (keepit) {
@@ -547,7 +545,7 @@ removeIconsCallback(WMenu *menu, WMenuEntry *entry)
XMapWindow(dpy, aicon->icon->core->window); XMapWindow(dpy, aicon->icon->core->window);
} }
} }
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
if (wPreferences.auto_arrange_icons) if (wPreferences.auto_arrange_icons)
wArrangeIcons(dock->screen_ptr, True); wArrangeIcons(dock->screen_ptr, True);
@@ -560,15 +558,15 @@ keepIconsCallback(WMenu *menu, WMenuEntry *entry)
WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata; WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
WDock *dock; WDock *dock;
WAppIcon *aicon; WAppIcon *aicon;
WMBag *selectedIcons; WMArray *selectedIcons;
WMBagIterator it; WMArrayIterator it;
assert(clickedIcon!=NULL); assert(clickedIcon!=NULL);
dock = clickedIcon->dock; dock = clickedIcon->dock;
selectedIcons = getSelected(dock); selectedIcons = getSelected(dock);
if (!WMGetBagItemCount(selectedIcons) if (!WMGetArrayItemCount(selectedIcons)
&& clickedIcon!=dock->screen_ptr->clip_icon) { && clickedIcon!=dock->screen_ptr->clip_icon) {
char *command = NULL; char *command = NULL;
@@ -588,15 +586,15 @@ keepIconsCallback(WMenu *menu, WMenuEntry *entry)
clickedIcon->editing = 0; clickedIcon->editing = 0;
if (command) if (command)
wfree(command); wfree(command);
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
return; return;
} }
} }
WMPutInBag(selectedIcons, clickedIcon); WMAddToArray(selectedIcons, clickedIcon);
} }
WM_ITERATE_BAG(selectedIcons, aicon, it) { WM_ITERATE_ARRAY(selectedIcons, aicon, it) {
if (aicon->icon->selected) if (aicon->icon->selected)
wIconSelect(aicon->icon); wIconSelect(aicon->icon);
if (aicon && aicon->attracted && aicon->command) { if (aicon && aicon->attracted && aicon->command) {
@@ -608,7 +606,7 @@ keepIconsCallback(WMenu *menu, WMenuEntry *entry)
} }
} }
} }
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
} }
@@ -695,7 +693,8 @@ selectIconsCallback(WMenu *menu, WMenuEntry *entry)
{ {
WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata; WAppIcon *clickedIcon = (WAppIcon*)entry->clientdata;
WDock *dock; WDock *dock;
WMBag *selectedIcons; WMArray *selectedIcons;
WMArrayIterator iter;
WAppIcon *btn; WAppIcon *btn;
int i; int i;
@@ -704,7 +703,7 @@ selectIconsCallback(WMenu *menu, WMenuEntry *entry)
selectedIcons = getSelected(dock); selectedIcons = getSelected(dock);
if (!WMGetBagItemCount(selectedIcons)) { if (!WMGetArrayItemCount(selectedIcons)) {
for (i=1; i<dock->max_icons; i++) { for (i=1; i<dock->max_icons; i++) {
btn = dock->icon_array[i]; btn = dock->icon_array[i];
if (btn && !btn->icon->selected) { if (btn && !btn->icon->selected) {
@@ -712,12 +711,11 @@ selectIconsCallback(WMenu *menu, WMenuEntry *entry)
} }
} }
} else { } else {
for (i = 0; i < WMGetBagItemCount(selectedIcons); i++) { WM_ITERATE_ARRAY(selectedIcons, btn, iter) {
btn = WMGetFromBag(selectedIcons, i);
wIconSelect(btn->icon); wIconSelect(btn->icon);
} }
} }
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
wMenuPaint(menu); wMenuPaint(menu);
} }
@@ -861,7 +859,7 @@ switchWSCommand(WMenu *menu, WMenuEntry *entry)
WAppIcon *btn, *icon = (WAppIcon*) entry->clientdata; WAppIcon *btn, *icon = (WAppIcon*) entry->clientdata;
WScreen *scr = icon->icon->core->screen_ptr; WScreen *scr = icon->icon->core->screen_ptr;
WDock *src, *dest; WDock *src, *dest;
WMBag *selectedIcons; WMArray *selectedIcons;
int x, y; int x, y;
if (entry->order == scr->current_workspace) if (entry->order == scr->current_workspace)
@@ -871,10 +869,10 @@ switchWSCommand(WMenu *menu, WMenuEntry *entry)
selectedIcons = getSelected(src); selectedIcons = getSelected(src);
if (WMGetBagItemCount(selectedIcons)) { if (WMGetArrayItemCount(selectedIcons)) {
int i; WMArrayIterator iter;
for (i = 0; i < WMGetBagItemCount(selectedIcons); i++) {
btn = WMGetFromBag(selectedIcons, i); WM_ITERATE_ARRAY(selectedIcons, btn, iter) {
if (wDockFindFreeSlot(dest, &x, &y)) { if (wDockFindFreeSlot(dest, &x, &y)) {
moveIconBetweenDocks(src, dest, btn, x, y); moveIconBetweenDocks(src, dest, btn, x, y);
XUnmapWindow(dpy, btn->icon->core->window); XUnmapWindow(dpy, btn->icon->core->window);
@@ -886,7 +884,7 @@ switchWSCommand(WMenu *menu, WMenuEntry *entry)
XUnmapWindow(dpy, icon->icon->core->window); XUnmapWindow(dpy, icon->icon->core->window);
} }
} }
WMFreeBag(selectedIcons); WMFreeArray(selectedIcons);
} }

View File

@@ -302,7 +302,7 @@ ShowDockAppSettingsPanel(WAppIcon *aicon)
WMResizeWidget(panel->autoLaunchBtn, PWIDTH-30, 20); WMResizeWidget(panel->autoLaunchBtn, PWIDTH-30, 20);
WMMoveWidget(panel->autoLaunchBtn, 15, 80); WMMoveWidget(panel->autoLaunchBtn, 15, 80);
WMSetButtonText(panel->autoLaunchBtn, WMSetButtonText(panel->autoLaunchBtn,
_("Start when WindowMaker is started")); _("Start when Window Maker is started"));
WMSetButtonSelected(panel->autoLaunchBtn, aicon->auto_launch); WMSetButtonSelected(panel->autoLaunchBtn, aicon->auto_launch);
panel->lockBtn = WMCreateSwitchButton(panel->win); panel->lockBtn = WMCreateSwitchButton(panel->win);

View File

@@ -156,7 +156,7 @@ typedef struct DeathHandler {
void *client_data; void *client_data;
} DeathHandler; } DeathHandler;
static WMBag *deathHandlers=NULL; static WMArray *deathHandlers=NULL;
@@ -174,9 +174,9 @@ wAddDeathHandler(pid_t pid, WDeathHandler *callback, void *cdata)
handler->client_data = cdata; handler->client_data = cdata;
if (!deathHandlers) if (!deathHandlers)
deathHandlers = WMCreateBag(8); deathHandlers = WMCreateArrayWithDestructor(8, wfree);
WMPutInBag(deathHandlers, handler); WMAddToArray(deathHandlers, handler);
return handler; return handler;
} }
@@ -191,9 +191,8 @@ wDeleteDeathHandler(WMagicNumber id)
if (!handler || !deathHandlers) if (!handler || !deathHandlers)
return; return;
WMRemoveFromBag(deathHandlers, handler); /* array destructor will call wfree(handler) */
WMRemoveFromArray(deathHandlers, handler);
wfree(handler);
} }
@@ -384,8 +383,8 @@ handleDeadProcess(void *foo)
while (deadProcessPtr>0) { while (deadProcessPtr>0) {
deadProcessPtr--; deadProcessPtr--;
for (i = WMGetBagItemCount(deathHandlers)-1; i >= 0; i--) { for (i = WMGetArrayItemCount(deathHandlers)-1; i >= 0; i--) {
tmp = WMGetFromBag(deathHandlers, i); tmp = WMGetFromArray(deathHandlers, i);
if (!tmp) if (!tmp)
continue; continue;
@@ -1514,25 +1513,20 @@ handleKeyPress(XEvent *event)
case WKBD_WINDOW9: case WKBD_WINDOW9:
case WKBD_WINDOW10: case WKBD_WINDOW10:
#define INITBAG(bag) if (bag) WMEmptyBag(bag); else bag = WMCreateBag(4)
index = command-WKBD_WINDOW1; index = command-WKBD_WINDOW1;
if (scr->shortcutWindows[index]) { if (scr->shortcutWindows[index]) {
WMBag *list = scr->shortcutWindows[index]; WMArray *list = scr->shortcutWindows[index];
int cw; int cw;
int count = WMGetBagItemCount(list); int count = WMGetArrayItemCount(list);
WWindow *twin; WWindow *twin;
WMBagIterator iter; WMArrayIterator iter;
WWindow *wwin; WWindow *wwin;
wUnselectWindows(scr); wUnselectWindows(scr);
cw = scr->current_workspace; cw = scr->current_workspace;
for (wwin = WMBagLast(list, &iter); WM_ETARETI_ARRAY(list, wwin, iter) {
iter != NULL;
wwin = WMBagPrevious(list, &iter)) {
if (count > 1) if (count > 1)
wWindowChangeWorkspace(wwin, cw); wWindowChangeWorkspace(wwin, cw);
@@ -1543,26 +1537,26 @@ handleKeyPress(XEvent *event)
} }
/* rotate the order of windows, to create a cycling effect */ /* rotate the order of windows, to create a cycling effect */
twin = WMBagFirst(list, &iter); twin = WMGetFromArray(list, 0);
WMRemoveFromBag(list, twin); WMDeleteFromArray(list, 0);
WMPutInBag(list, twin); WMAddToArray(list, twin);
} else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) { } else if (wwin && ISMAPPED(wwin) && ISFOCUSED(wwin)) {
if (scr->shortcutWindows[index]) {
INITBAG(scr->shortcutWindows[index]); WMFreeArray(scr->shortcutWindows[index]);
WMPutInBag(scr->shortcutWindows[index], wwin); scr->shortcutWindows[index] = NULL;
}
if (wwin->flags.selected && scr->selected_windows) { if (wwin->flags.selected && scr->selected_windows) {
WMBag *selwins = scr->selected_windows; scr->shortcutWindows[index] =
int i; WMDuplicateArray(scr->selected_windows);
/*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
for (i = 0; i < WMGetBagItemCount(selwins); i++) { WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
WWindow *tmp = WMGetFromBag(selwins, i); } else {
scr->shortcutWindows[index] = WMCreateArray(4);
if (tmp != wwin) WMAddToArray(scr->shortcutWindows[index], wwin);
WMPutInBag(scr->shortcutWindows[index], tmp);
}
} }
wSelectWindow(wwin, !wwin->flags.selected); wSelectWindow(wwin, !wwin->flags.selected);
XFlush(dpy); XFlush(dpy);
wusleep(3000); wusleep(3000);
@@ -1570,22 +1564,16 @@ handleKeyPress(XEvent *event)
XFlush(dpy); XFlush(dpy);
} else if (scr->selected_windows } else if (scr->selected_windows
&& WMGetBagItemCount(scr->selected_windows)) { && WMGetArrayItemCount(scr->selected_windows)) {
if (wwin->flags.selected && scr->selected_windows) { if (wwin->flags.selected && scr->selected_windows) {
WMBag *selwins = scr->selected_windows; if (scr->shortcutWindows[index]) {
int i; WMFreeArray(scr->shortcutWindows[index]);
}
INITBAG(scr->shortcutWindows[index]); scr->shortcutWindows[index] =
WMDuplicateArray(scr->selected_windows);
for (i = 0; i < WMGetBagItemCount(selwins); i++) {
WWindow *tmp = WMGetFromBag(selwins, i);
WMPutInBag(scr->shortcutWindows[index], tmp);
} }
} }
}
#undef INITBAG
break; break;

View File

@@ -390,19 +390,19 @@ mapGeometryDisplay(WWindow *wwin, int x, int y, int w, int h)
static void static void
doWindowMove(WWindow *wwin, WMBag *bag, int dx, int dy) doWindowMove(WWindow *wwin, WMArray *array, int dx, int dy)
{ {
WWindow *tmpw; WWindow *tmpw;
int x, y; int x, y;
int scr_width = wwin->screen_ptr->scr_width; int scr_width = wwin->screen_ptr->scr_width;
int scr_height = wwin->screen_ptr->scr_height; int scr_height = wwin->screen_ptr->scr_height;
if (!bag || !WMGetBagItemCount(bag)) { if (!array || !WMGetArrayItemCount(array)) {
wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy); wWindowMove(wwin, wwin->frame_x + dx, wwin->frame_y + dy);
} else { } else {
int i; WMArrayIterator iter;
for (i = 0; i < WMGetBagItemCount(bag); i++) {
tmpw = WMGetFromBag(bag, i); WM_ITERATE_ARRAY(array, tmpw, iter) {
x = tmpw->frame_x + dx; x = tmpw->frame_x + dx;
y = tmpw->frame_y + dy; y = tmpw->frame_y + dy;
@@ -455,14 +455,14 @@ drawTransparentFrame(WWindow *wwin, int x, int y, int width, int height)
static void static void
drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy) drawFrames(WWindow *wwin, WMArray *array, int dx, int dy)
{ {
WWindow *tmpw; WWindow *tmpw;
int scr_width = wwin->screen_ptr->scr_width; int scr_width = wwin->screen_ptr->scr_width;
int scr_height = wwin->screen_ptr->scr_height; int scr_height = wwin->screen_ptr->scr_height;
int x, y; int x, y;
if (!bag) { if (!array) {
x = wwin->frame_x + dx; x = wwin->frame_x + dx;
y = wwin->frame_y + dy; y = wwin->frame_y + dy;
@@ -472,9 +472,9 @@ drawFrames(WWindow *wwin, WMBag *bag, int dx, int dy)
wwin->frame->core->height); wwin->frame->core->height);
} else { } else {
int i; WMArrayIterator iter;
for (i = 0; i < WMGetBagItemCount(bag); i++) {
tmpw = WMGetFromBag(bag, i); WM_ITERATE_ARRAY(array, tmpw, iter) {
x = tmpw->frame_x + dx; x = tmpw->frame_x + dx;
y = tmpw->frame_y + dy; y = tmpw->frame_y + dy;
@@ -1492,11 +1492,13 @@ wKeyboardMoveResizeWindow(WWindow *wwin)
wWindowMove(wwin, src_x+off_x, src_y+off_y); wWindowMove(wwin, src_x+off_x, src_y+off_y);
wWindowSynthConfigureNotify(wwin); wWindowSynthConfigureNotify(wwin);
} else { } else {
int i; WMArrayIterator iter;
WMBag *bag = scr->selected_windows; WWindow *foo;
doWindowMove(wwin,scr->selected_windows,off_x,off_y);
for (i = 0; i < WMGetBagItemCount(bag); i++) { doWindowMove(wwin, scr->selected_windows, off_x, off_y);
wWindowSynthConfigureNotify(WMGetFromBag(bag, i));
WM_ITERATE_ARRAY(scr->selected_windows, foo, iter) {
wWindowSynthConfigureNotify(foo);
} }
} }
} else { } else {
@@ -2096,16 +2098,14 @@ wUnselectWindows(WScreen *scr)
if (!scr->selected_windows) if (!scr->selected_windows)
return; return;
while (WMGetBagItemCount(scr->selected_windows)) { while (WMGetArrayItemCount(scr->selected_windows)) {
WMBagIterator dummy; wwin = WMGetFromArray(scr->selected_windows, 0);
wwin = WMBagFirst(scr->selected_windows, &dummy);
if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected) if (wwin->flags.miniaturized && wwin->icon && wwin->icon->selected)
wIconSelect(wwin->icon); wIconSelect(wwin->icon);
wSelectWindow(wwin, False); wSelectWindow(wwin, False);
} }
WMFreeBag(scr->selected_windows); WMFreeArray(scr->selected_windows);
scr->selected_windows = NULL; scr->selected_windows = NULL;
} }

View File

@@ -601,7 +601,7 @@ static void
separateCommand(char *line, char ***file, char **command) separateCommand(char *line, char ***file, char **command)
{ {
char *token, *tmp = line; char *token, *tmp = line;
WMBag *bag = WMCreateBag(4); WMArray *array = WMCreateArray(4);
int count, i; int count, i;
*file = NULL; *file = NULL;
@@ -616,19 +616,19 @@ separateCommand(char *line, char ***file, char **command)
wwarning(_("%s: missing command"), line); wwarning(_("%s: missing command"), line);
break; break;
} }
WMPutInBag(bag, token); WMAddToArray(array, token);
} }
} while (token!=NULL && tmp!=NULL); } while (token!=NULL && tmp!=NULL);
count = WMGetBagItemCount(bag); count = WMGetArrayItemCount(array);
if (count>0) { if (count>0) {
*file = wmalloc(sizeof(char*)*(count+1)); *file = wmalloc(sizeof(char*)*(count+1));
(*file)[count] = NULL; (*file)[count] = NULL;
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
(*file)[i] = WMGetFromBag(bag, i); (*file)[i] = WMGetFromArray(array, i);
} }
} }
WMFreeBag(bag); WMFreeArray(array);
} }
@@ -1334,14 +1334,15 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
struct stat stat_buf; struct stat stat_buf;
WMenu *menu=NULL; WMenu *menu=NULL;
char *buffer; char *buffer;
WMBag *dirs = NULL, *files = NULL; WMArray *dirs = NULL, *files = NULL;
WMArrayIterator iter;
int length, i, have_space=0; int length, i, have_space=0;
dir_data *data; dir_data *data;
int stripExtension = 0; int stripExtension = 0;
dirs = WMCreateBag(16); dirs = WMCreateArray(16);
files = WMCreateBag(16); files = WMCreateArray(16);
i=0; i=0;
while (path[i]!=NULL) { while (path[i]!=NULL) {
@@ -1395,7 +1396,7 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
data->name = wstrdup(dentry->d_name); data->name = wstrdup(dentry->d_name);
data->index = i; data->index = i;
WMPutInBag(dirs, data); WMAddToArray(dirs, data);
} }
} else if (S_ISREG(stat_buf.st_mode) || isFilePack) { } else if (S_ISREG(stat_buf.st_mode) || isFilePack) {
/* Hack because access always returns X_OK success for user root */ /* Hack because access always returns X_OK success for user root */
@@ -1408,7 +1409,7 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
data->name = wstrdup(dentry->d_name); data->name = wstrdup(dentry->d_name);
data->index = i; data->index = i;
WMPutInBag(files, data); WMAddToArray(files, data);
} }
} }
} }
@@ -1419,24 +1420,22 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
i++; i++;
} }
if (!WMGetBagItemCount(dirs) && !WMGetBagItemCount(files)) { if (!WMGetArrayItemCount(dirs) && !WMGetArrayItemCount(files)) {
WMFreeBag(dirs); WMFreeArray(dirs);
WMFreeBag(files); WMFreeArray(files);
return NULL; return NULL;
} }
WMSortBag(dirs, myCompare); WMSortArray(dirs, myCompare);
WMSortBag(files, myCompare); WMSortArray(files, myCompare);
menu = wMenuCreate(scr, title, False); menu = wMenuCreate(scr, title, False);
menu->on_destroy = removeShortcutsForMenu; menu->on_destroy = removeShortcutsForMenu;
for (i = 0; i < WMGetBagItemCount(dirs); i++) { WM_ITERATE_ARRAY(dirs, data, iter) {
/* New directory. Use same OPEN_MENU command that was used /* New directory. Use same OPEN_MENU command that was used
* for the current directory. */ * for the current directory. */
dir_data *d = (dir_data*)WMGetFromBag(dirs, i); length = strlen(path[data->index])+strlen(data->name)+6;
length = strlen(path[d->index])+strlen(d->name)+6;
if (stripExtension) if (stripExtension)
length += 7; length += 7;
if (command) if (command)
@@ -1444,7 +1443,7 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
buffer = malloc(length); buffer = malloc(length);
if (!buffer) { if (!buffer) {
wsyserror(_("out of memory while constructing directory menu %s"), wsyserror(_("out of memory while constructing directory menu %s"),
path[d->index]); path[data->index]);
break; break;
} }
@@ -1452,15 +1451,15 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
if (stripExtension) if (stripExtension)
strcat(buffer, "-noext "); strcat(buffer, "-noext ");
have_space = strchr(path[d->index], ' ')!=NULL || have_space = strchr(path[data->index], ' ')!=NULL ||
strchr(d->name, ' ')!=NULL; strchr(data->name, ' ')!=NULL;
if (have_space) if (have_space)
strcat(buffer, "\""); strcat(buffer, "\"");
strcat(buffer, path[d->index]); strcat(buffer, path[data->index]);
strcat(buffer, "/"); strcat(buffer, "/");
strcat(buffer, d->name); strcat(buffer, data->name);
if (have_space) if (have_space)
strcat(buffer, "\""); strcat(buffer, "\"");
if (command) { if (command) {
@@ -1468,66 +1467,64 @@ readMenuDirectory(WScreen *scr, char *title, char **path, char *command)
strcat(buffer, command); strcat(buffer, command);
} }
addMenuEntry(menu, d->name, NULL, "OPEN_MENU", buffer, path[d->index]); addMenuEntry(menu, data->name, NULL, "OPEN_MENU", buffer, path[data->index]);
wfree(buffer); wfree(buffer);
if (d->name) if (data->name)
wfree(d->name); wfree(data->name);
wfree(d); wfree(data);
} }
for (i = 0; i < WMGetBagItemCount(files); i++) { WM_ITERATE_ARRAY(files, data, iter) {
/* executable: add as entry */ /* executable: add as entry */
dir_data *f = (dir_data*)WMGetFromBag(files, i); length = strlen(path[data->index])+strlen(data->name)+6;
length = strlen(path[f->index])+strlen(f->name)+6;
if (command) if (command)
length += strlen(command); length += strlen(command);
buffer = malloc(length); buffer = malloc(length);
if (!buffer) { if (!buffer) {
wsyserror(_("out of memory while constructing directory menu %s"), wsyserror(_("out of memory while constructing directory menu %s"),
path[f->index]); path[data->index]);
break; break;
} }
have_space = strchr(path[f->index], ' ')!=NULL || have_space = strchr(path[data->index], ' ')!=NULL ||
strchr(f->name, ' ')!=NULL; strchr(data->name, ' ')!=NULL;
if (command!=NULL) { if (command!=NULL) {
strcpy(buffer, command); strcpy(buffer, command);
strcat(buffer, " "); strcat(buffer, " ");
if (have_space) if (have_space)
strcat(buffer, "\""); strcat(buffer, "\"");
strcat(buffer, path[f->index]); strcat(buffer, path[data->index]);
} else { } else {
if (have_space) { if (have_space) {
buffer[0] = '"'; buffer[0] = '"';
buffer[1] = 0; buffer[1] = 0;
strcat(buffer, path[f->index]); strcat(buffer, path[data->index]);
} else { } else {
strcpy(buffer, path[f->index]); strcpy(buffer, path[data->index]);
} }
} }
strcat(buffer, "/"); strcat(buffer, "/");
strcat(buffer, f->name); strcat(buffer, data->name);
if (have_space) if (have_space)
strcat(buffer, "\""); strcat(buffer, "\"");
if (stripExtension) { if (stripExtension) {
char *ptr = strrchr(f->name, '.'); char *ptr = strrchr(data->name, '.');
if (ptr && ptr!=f->name) if (ptr && ptr!=data->name)
*ptr = 0; *ptr = 0;
} }
addMenuEntry(menu, f->name, NULL, "SHEXEC", buffer, path[f->index]); addMenuEntry(menu, data->name, NULL, "SHEXEC", buffer, path[data->index]);
wfree(buffer); wfree(buffer);
if (f->name) if (data->name)
wfree(f->name); wfree(data->name);
wfree(f); wfree(data);
} }
WMFreeBag(files); WMFreeArray(files);
WMFreeBag(dirs); WMFreeArray(dirs);
return menu; return menu;
} }

View File

@@ -108,7 +108,7 @@ typedef struct _WScreen {
* traverse the entire window list * traverse the entire window list
*/ */
WMBag *selected_windows; WMArray *selected_windows;
struct WAppIcon *app_icon_list; /* list of all app-icons on screen */ struct WAppIcon *app_icon_list; /* list of all app-icons on screen */
@@ -291,7 +291,7 @@ typedef struct _WScreen {
scrolled down for titlebar access */ scrolled down for titlebar access */
/* for window shortcuts */ /* for window shortcuts */
WMBag *shortcutWindows[MAX_WINDOW_SHORTCUTS]; WMArray *shortcutWindows[MAX_WINDOW_SHORTCUTS];
#ifdef XDND #ifdef XDND
char *xdestring; char *xdestring;

View File

@@ -256,7 +256,7 @@ makeWindowState(WWindow *wwin, WApplication *wapp)
for (mask = 0, i = 0; i < MAX_WINDOW_SHORTCUTS; i++) { for (mask = 0, i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
if (scr->shortcutWindows[i] != NULL && if (scr->shortcutWindows[i] != NULL &&
WMGetFirstInBag(scr->shortcutWindows[i], wwin) != WBNotFound) { WMGetFirstInArray(scr->shortcutWindows[i], wwin) != WANotFound) {
mask |= 1<<i; mask |= 1<<i;
} }
} }
@@ -314,7 +314,7 @@ wSessionSaveState(WScreen *scr)
WWindow *wwin = scr->focused_window; WWindow *wwin = scr->focused_window;
proplist_t win_info, wks; proplist_t win_info, wks;
proplist_t list=NULL; proplist_t list=NULL;
WMBag *wapp_list=NULL; WMArray *wapp_list=NULL;
make_keys(); make_keys();
@@ -327,13 +327,13 @@ wSessionSaveState(WScreen *scr)
list = PLMakeArrayFromElements(NULL); list = PLMakeArrayFromElements(NULL);
wapp_list = WMCreateBag(16); wapp_list = WMCreateArray(16);
while (wwin) { while (wwin) {
WApplication *wapp=wApplicationOf(wwin->main_window); WApplication *wapp=wApplicationOf(wwin->main_window);
if (wwin->transient_for==None if (wwin->transient_for==None
&& WMGetFirstInBag(wapp_list, wapp)==WBNotFound && WMGetFirstInArray(wapp_list, wapp)==WANotFound
&& !WFLAGP(wwin, dont_save_session)) { && !WFLAGP(wwin, dont_save_session)) {
/* A entry for this application was not yet saved. Save one. */ /* A entry for this application was not yet saved. Save one. */
if ((win_info = makeWindowState(wwin, wapp))!=NULL) { if ((win_info = makeWindowState(wwin, wapp))!=NULL) {
@@ -344,7 +344,7 @@ wSessionSaveState(WScreen *scr)
* application list, so no multiple entries for the same * application list, so no multiple entries for the same
* application are saved. * application are saved.
*/ */
WMPutInBag(wapp_list, wapp); WMAddToArray(wapp_list, wapp);
} }
} }
wwin = wwin->prev; wwin = wwin->prev;
@@ -357,7 +357,7 @@ wSessionSaveState(WScreen *scr)
PLInsertDictionaryEntry(scr->session_state, sWorkspace, wks); PLInsertDictionaryEntry(scr->session_state, sWorkspace, wks);
PLRelease(wks); PLRelease(wks);
WMFreeBag(wapp_list); WMFreeArray(wapp_list);
} }

View File

@@ -227,10 +227,10 @@ wWindowDestroy(WWindow *wwin)
if (!wwin->screen_ptr->shortcutWindows[i]) if (!wwin->screen_ptr->shortcutWindows[i])
continue; continue;
WMRemoveFromBag(wwin->screen_ptr->shortcutWindows[i], wwin); WMRemoveFromArray(wwin->screen_ptr->shortcutWindows[i], wwin);
if (!WMGetBagItemCount(wwin->screen_ptr->shortcutWindows[i])) { if (!WMGetArrayItemCount(wwin->screen_ptr->shortcutWindows[i])) {
WMFreeBag(wwin->screen_ptr->shortcutWindows[i]); WMFreeArray(wwin->screen_ptr->shortcutWindows[i]);
wwin->screen_ptr->shortcutWindows[i] = NULL; wwin->screen_ptr->shortcutWindows[i] = NULL;
} }
} }
@@ -862,9 +862,9 @@ wManageWindow(WScreen *scr, Window window)
for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) { for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
if (mask & (1<<i)) { if (mask & (1<<i)) {
if (!scr->shortcutWindows[i]) if (!scr->shortcutWindows[i])
scr->shortcutWindows[i] = WMCreateBag(4); scr->shortcutWindows[i] = WMCreateArray(4);
WMPutInBag(scr->shortcutWindows[i], wwin); WMAddToArray(scr->shortcutWindows[i], wwin);
} }
} }
} }
@@ -2372,7 +2372,7 @@ wWindowSaveState(WWindow *wwin)
for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) { for (i = 0; i < MAX_WINDOW_SHORTCUTS; i++) {
if (wwin->screen_ptr->shortcutWindows[i] && if (wwin->screen_ptr->shortcutWindows[i] &&
WMCountInBag(wwin->screen_ptr->shortcutWindows[i], wwin)) WMCountInArray(wwin->screen_ptr->shortcutWindows[i], wwin))
data[9] |= 1<<i; data[9] |= 1<<i;
} }
XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE, XChangeProperty(dpy, wwin->client_win, _XA_WINDOWMAKER_STATE,

View File

@@ -203,25 +203,17 @@ makeShortcutCommand(WMenu *menu, WMenuEntry *entry)
int index = entry->order-WO_ENTRIES; int index = entry->order-WO_ENTRIES;
if (scr->shortcutWindows[index]) { if (scr->shortcutWindows[index]) {
WMFreeBag(scr->shortcutWindows[index]); WMFreeArray(scr->shortcutWindows[index]);
scr->shortcutWindows[index] = NULL; scr->shortcutWindows[index] = NULL;
} }
if (wwin->flags.selected && scr->selected_windows) { if (wwin->flags.selected && scr->selected_windows) {
WMBag *selwin = scr->selected_windows; scr->shortcutWindows[index] = WMDuplicateArray(scr->selected_windows);
int i; /*WMRemoveFromArray(scr->shortcutWindows[index], wwin);
WMInsertInArray(scr->shortcutWindows[index], 0, wwin);*/
scr->shortcutWindows[index] = WMCreateBag(4);
for (i = 0; i < WMGetBagItemCount(selwin); i++) {
WWindow *tmp = WMGetFromBag(selwin, i);
WMPutInBag(scr->shortcutWindows[index], tmp);
}
} else { } else {
scr->shortcutWindows[index] = WMCreateBag(4); scr->shortcutWindows[index] = WMCreateArray(4);
WMAddToArray(scr->shortcutWindows[index], wwin);
WMPutInBag(scr->shortcutWindows[index], wwin);
} }
wSelectWindow(wwin, !wwin->flags.selected); wSelectWindow(wwin, !wwin->flags.selected);
@@ -281,7 +273,7 @@ updateMakeShortcutMenu(WMenu *menu, WWindow *wwin)
char *tmp; char *tmp;
int shortcutNo = i-WO_ENTRIES; int shortcutNo = i-WO_ENTRIES;
WMenuEntry *entry = smenu->entries[i]; WMenuEntry *entry = smenu->entries[i];
WMBag *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo]; WMArray *shortSelWindows = wwin->screen_ptr->shortcutWindows[shortcutNo];
sprintf(buffer, "%s %i", _("Set Shortcut"), shortcutNo+1); sprintf(buffer, "%s %i", _("Set Shortcut"), shortcutNo+1);
@@ -289,7 +281,7 @@ updateMakeShortcutMenu(WMenu *menu, WWindow *wwin)
entry->flags.indicator_on = 0; entry->flags.indicator_on = 0;
} else { } else {
entry->flags.indicator_on = 1; entry->flags.indicator_on = 1;
if (WMCountInBag(shortSelWindows, wwin)) if (WMCountInArray(shortSelWindows, wwin))
entry->flags.indicator_type = MI_DIAMOND; entry->flags.indicator_type = MI_DIAMOND;
else else
entry->flags.indicator_type = MI_CHECK; entry->flags.indicator_type = MI_CHECK;

View File

@@ -102,7 +102,7 @@ wXDNDProcessSelection(XEvent *event)
char * delme; char * delme;
XEvent xevent; XEvent xevent;
Window selowner = XGetSelectionOwner(dpy,_XA_XdndSelection); Window selowner = XGetSelectionOwner(dpy,_XA_XdndSelection);
WMBag *items; WMArray *items;
XGetWindowProperty(dpy, event->xselection.requestor, XGetWindowProperty(dpy, event->xselection.requestor,
@@ -125,11 +125,12 @@ wXDNDProcessSelection(XEvent *event)
/*process dropping*/ /*process dropping*/
if (scr->xdestring) { if (scr->xdestring) {
WMArrayIterator iter;
int length, str_size; int length, str_size;
int total_size = 0; int total_size = 0;
char *tmp; char *tmp;
items = WMCreateBag(1); items = WMCreateArray(4);
retain = wstrdup(scr->xdestring); retain = wstrdup(scr->xdestring);
XFree(scr->xdestring); /* since xdestring was created by Xlib */ XFree(scr->xdestring); /* since xdestring was created by Xlib */
@@ -143,24 +144,23 @@ wXDNDProcessSelection(XEvent *event)
if (retain[length] == '\n') { if (retain[length] == '\n') {
str_size = strlen(&retain[length + 1]); str_size = strlen(&retain[length + 1]);
if(str_size) { if(str_size) {
WMPutInBag(items, wstrdup(&retain[length + 1])); WMAddToArray(items, wstrdup(&retain[length + 1]));
total_size += str_size + 3; /* reserve for " \"\"" */ total_size += str_size + 3; /* reserve for " \"\"" */
if (length) /* this is nonsense -- if (length)
WMAppendBag(items, WMCreateBag(1)); WMAppendArray(items, WMCreateArray(1));*/
} }
retain[length] = 0; retain[length] = 0;
} }
} }
/* final one */ /* final one */
WMPutInBag(items, wstrdup(retain)); WMAddToArray(items, wstrdup(retain));
total_size += strlen(retain) + 3; total_size += strlen(retain) + 3;
wfree(retain); wfree(retain);
/* now pack new string */ /* now pack new string */
scr->xdestring = wmalloc(total_size); scr->xdestring = wmalloc(total_size);
scr->xdestring[0]=0; /* empty string */ scr->xdestring[0]=0; /* empty string */
for(length = WMGetBagItemCount(items)-1; length >=0; length--) { WM_ETARETI_ARRAY(items, tmp, iter) {
tmp = WMGetFromBag(items, length);
if (!strncmp(tmp,"file:",5)) { if (!strncmp(tmp,"file:",5)) {
/* add more 2 chars while removing 5 is harmless */ /* add more 2 chars while removing 5 is harmless */
strcat(scr->xdestring, " \""); strcat(scr->xdestring, " \"");
@@ -172,7 +172,7 @@ wXDNDProcessSelection(XEvent *event)
} }
wfree(tmp); wfree(tmp);
} }
WMFreeBag(items); WMFreeArray(items);
wDockReceiveDNDDrop(scr,event); wDockReceiveDNDDrop(scr,event);
/* /*
printf("free "); printf("free ");