diff --git a/WINGs/Resources/Makefile.in b/WINGs/Resources/Makefile.in new file mode 100644 index 00000000..15907e2f --- /dev/null +++ b/WINGs/Resources/Makefile.in @@ -0,0 +1,231 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = ../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ +AS = @AS@ +CC = @CC@ +CPP_PATH = @CPP_PATH@ +DFLAGS = @DFLAGS@ +DLLIBS = @DLLIBS@ +DLLTOOL = @DLLTOOL@ +GFXLIBS = @GFXLIBS@ +HEADER_SEARCH_PATH = @HEADER_SEARCH_PATH@ +ICONEXT = @ICONEXT@ +INTLIBS = @INTLIBS@ +LD = @LD@ +LIBPL = @LIBPL@ +LIBRARY_SEARCH_PATH = @LIBRARY_SEARCH_PATH@ +LIBTOOL = @LIBTOOL@ +LITE = @LITE@ +LN_S = @LN_S@ +MAKEINFO = @MAKEINFO@ +MOFILES = @MOFILES@ +NETLIBS = @NETLIBS@ +NLSDIR = @NLSDIR@ +NM = @NM@ +OBJDUMP = @OBJDUMP@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +VERSION = @VERSION@ +WPMOFILES = @WPMOFILES@ +XCFLAGS = @XCFLAGS@ +XGETTEXT = @XGETTEXT@ +XLFLAGS = @XLFLAGS@ +XLIBS = @XLIBS@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_LIBRARY_PATH = @X_LIBRARY_PATH@ +supported_locales = @supported_locales@ +wprefsdir = @wprefsdir@ + +resdatadir = $(datadir)/WINGs + +resdata_DATA = Images.tiff Images.xpm defaultIcon.tiff defaultIcon.xpm + +EXTRA_DIST = $(resdata_DATA) Images.xcf +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_HEADER = ../../src/config.h +CONFIG_CLEAN_FILES = +DATA = $(resdata_DATA) + +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +all: all-redirect +.SUFFIXES: +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && $(AUTOMAKE) --gnu WINGs/Resources/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status $(BUILT_SOURCES) + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +install-resdataDATA: $(resdata_DATA) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(resdatadir) + @list='$(resdata_DATA)'; for p in $$list; do \ + if test -f $(srcdir)/$$p; then \ + echo " $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(resdatadir)/$$p"; \ + $(INSTALL_DATA) $(srcdir)/$$p $(DESTDIR)$(resdatadir)/$$p; \ + else if test -f $$p; then \ + echo " $(INSTALL_DATA) $$p $(DESTDIR)$(resdatadir)/$$p"; \ + $(INSTALL_DATA) $$p $(DESTDIR)$(resdatadir)/$$p; \ + fi; fi; \ + done + +uninstall-resdataDATA: + @$(NORMAL_UNINSTALL) + list='$(resdata_DATA)'; for p in $$list; do \ + rm -f $(DESTDIR)$(resdatadir)/$$p; \ + done +tags: TAGS +TAGS: + + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = WINGs/Resources + +distdir: $(DISTFILES) + here=`cd $(top_builddir) && pwd`; \ + top_distdir=`cd $(top_distdir) && pwd`; \ + distdir=`cd $(distdir) && pwd`; \ + cd $(top_srcdir) \ + && $(AUTOMAKE) --include-deps --build-dir=$$here --srcdir-name=$(top_srcdir) --output-dir=$$top_distdir --gnu WINGs/Resources/Makefile + @for file in $(DISTFILES); do \ + d=$(srcdir); \ + if test -d $$d/$$file; then \ + cp -pr $$/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: all-am +check: check-am +installcheck-am: +installcheck: installcheck-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: install-resdataDATA +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: uninstall-resdataDATA +uninstall: uninstall-am +all-am: Makefile $(DATA) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + $(mkinstalldirs) $(DESTDIR)$(resdatadir) + + +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-generic mostlyclean-am + +clean: clean-am + +distclean-am: distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-generic distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: uninstall-resdataDATA install-resdataDATA tags distdir info-am \ +info dvi-am dvi check check-am installcheck-am installcheck \ +install-exec-am install-exec install-data-am install-data install-am \ +install uninstall-am uninstall all-redirect all-am all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/WINGs/WINGsP.h b/WINGs/WINGsP.h index a66fc0b4..9250d868 100644 --- a/WINGs/WINGsP.h +++ b/WINGs/WINGsP.h @@ -102,8 +102,10 @@ struct W_DraggingInfo { WMPoint imageLocation; Time timestamp; - + int protocolVersion; + + WMView *destView; /* only valid if in the same app.. should be treated as internal data */ // WMView *destination; diff --git a/WINGs/WUtil.h b/WINGs/WUtil.h index 1630b9b4..19b25c66 100644 --- a/WINGs/WUtil.h +++ b/WINGs/WUtil.h @@ -103,7 +103,7 @@ typedef enum { enum { - WBNotFound = INT_MAX /* element was not found in bag */ + WBNotFound = INT_MIN /* element was not found in bag */ }; @@ -153,6 +153,7 @@ typedef struct W_BagFunctions { int (*putInBag)(WMBag *self, void *item); int (*insertInBag)(WMBag *self, int index, void *item); int (*removeFromBag)(WMBag *bag, void *item); + int (*eraseFromBag)(WMBag *bag, int index); int (*deleteFromBag)(WMBag *bag, int index); void *(*getFromBag)(WMBag *bag, int index); int (*firstInBag)(WMBag *bag, void *item); @@ -359,9 +360,16 @@ WMBag *WMCreateTreeBagWithDestructor(void (*destructor)(void*)); #define WMPutInBag(bag, item) bag->func.putInBag(bag, item) +/* insert will increment the index of elements after it by 1 */ #define WMInsertInBag(bag, index, item) bag->func.insertInBag(bag, index, item) /* this is slow */ +/* erase will remove the element from the bag, + * but will keep the index of the other elements unchanged */ +#define WMEraseFromBag(bag, index) bag->func.deleteFromBag(bag, index) + +/* delete and remove will remove the elements and cause the elements + * after them to decrement their indexes by 1 */ #define WMRemoveFromBag(bag, item) bag->func.removeFromBag(bag, item) #define WMDeleteFromBag(bag, index) bag->func.deleteFromBag(bag, index) @@ -405,6 +413,17 @@ WMBag *WMCreateTreeBagWithDestructor(void (*destructor)(void*)); #define WMBagIndexForIterator(bag, ptr) bag->func.indexForIterator(bag, ptr) + +#define WM_ITERATE_BAG(bag, var, i) \ + for (var = WMBagFirst(bag, &(i)); (i) != NULL; \ + var = WMBagNext(bag, &(i))) + +#define WM_ETARETI_BAG(bag, var, i) \ + for (var = WMBagLast(bag, &(i)); (i) != NULL; \ + var = WMBagPrevious(bag, &(i))) + + + /*-------------------------------------------------------------------------*/ /* WMData handling */ diff --git a/WINGs/bagarray.c b/WINGs/bagarray.c index 1d521bcc..1e66ff18 100644 --- a/WINGs/bagarray.c +++ b/WINGs/bagarray.c @@ -7,7 +7,7 @@ #include "WUtil.h" - +#if 0 typedef struct W_ArrayBag { void **items; @@ -50,6 +50,7 @@ static W_BagFunctions arrayFunctions = { insertInBag, removeFromBag, deleteFromBag, + deleteFromBag, getFromBag, firstInBag, countInBag, @@ -81,7 +82,7 @@ WMCreateArrayBagWithDestructor(int initialSize, void (*destructor)(void*)) W_ArrayBag *array; int size; - + assert(0&&"array bag is not working"); bag = wmalloc(sizeof(WMBag)); array = wmalloc(sizeof(W_ArrayBag)); @@ -414,3 +415,5 @@ indexForIterator(WMBag *bag, WMBagIterator ptr) { } + +#endif diff --git a/WINGs/bagtree.c b/WINGs/bagtree.c index 0f330489..5d8eb672 100644 --- a/WINGs/bagtree.c +++ b/WINGs/bagtree.c @@ -34,6 +34,7 @@ static int appendBag(WMBag *self, WMBag *bag); static int putInBag(WMBag *self, void *item); static int insertInBag(WMBag *self, int index, void *item); static int removeFromBag(WMBag *bag, void *item); +static int eraseFromBag(WMBag *bag, int index); static int deleteFromBag(WMBag *bag, int index); static void *getFromBag(WMBag *bag, int index); static int countInBag(WMBag *bag, void *item); @@ -58,6 +59,7 @@ static W_BagFunctions bagFunctions = { putInBag, insertInBag, removeFromBag, + eraseFromBag, deleteFromBag, getFromBag, firstInBag, @@ -503,7 +505,7 @@ static int putInBag(WMBag *self, void *item) static int insertInBag(WMBag *self, int index, void *item) { W_Node *ptr; - + ptr = wmalloc(sizeof(W_Node)); ptr->data = item; @@ -514,7 +516,7 @@ static int insertInBag(WMBag *self, int index, void *item) rbTreeInsert(SELF, ptr); - while ((ptr = treeSuccessor(ptr, SELF->nil))) { + while ((ptr = treeSuccessor(ptr, SELF->nil)) != SELF->nil) { ptr->index++; } @@ -530,6 +532,32 @@ static int removeFromBag(WMBag *self, void *item) { W_Node *ptr = treeFind(SELF->root, SELF->nil, item); + if (ptr != SELF->nil) { + W_Node *tmp; + + SELF->count--; + + tmp = treeSuccessor(ptr, SELF->nil); + while (tmp != SELF->nil) { + tmp->index--; + tmp = treeSuccessor(tmp, SELF->nil); + } + + ptr = rbTreeDelete(SELF, ptr); + free(ptr); + + return 1; + } else { + return 0; + } +} + + + +static int eraseFromBag(WMBag *self, int index) +{ + W_Node *ptr = treeSearch(SELF->root, SELF->nil, index); + if (ptr != SELF->nil) { SELF->count--; @@ -549,9 +577,16 @@ static int deleteFromBag(WMBag *self, int index) W_Node *ptr = treeSearch(SELF->root, SELF->nil, index); if (ptr != SELF->nil) { + W_Node *tmp; SELF->count--; + tmp = treeSuccessor(ptr, SELF->nil); + while (tmp != SELF->nil) { + tmp->index--; + tmp = treeSuccessor(tmp, SELF->nil); + } + ptr = rbTreeDelete(SELF, ptr); free(ptr); @@ -565,10 +600,7 @@ static int deleteFromBag(WMBag *self, int index) static void *getFromBag(WMBag *self, int index) { W_Node *node; - - if (SELF->count>0) - assert(SELF->root != SELF->nil); - + node = treeSearch(SELF->root, SELF->nil, index); if (node != SELF->nil) return node->data; @@ -627,12 +659,24 @@ static void *replaceInBag(WMBag *self, int index, void *item) SELF->count--; ptr = rbTreeDelete(SELF, ptr); - free(ptr); + free(ptr); } else if (ptr != SELF->nil) { old = ptr->data; ptr->data = item; } else { - insertInBag(self, index, item); + W_Node *ptr; + + ptr = wmalloc(sizeof(W_Node)); + + ptr->data = item; + ptr->index = index; + ptr->left = SELF->nil; + ptr->right = SELF->nil; + ptr->parent = SELF->nil; + + rbTreeInsert(SELF, ptr); + + SELF->count++; } return old; diff --git a/WINGs/connection.c b/WINGs/connection.c index 3bad3587..ff82fb17 100644 --- a/WINGs/connection.c +++ b/WINGs/connection.c @@ -353,8 +353,9 @@ WMCreateConnectionWithSocket(int sock, Bool closeOnRelease) /*FOLD00*/ cPtr->wasNonBlocking = WMIsConnectionNonBlocking(cPtr); cPtr->isNonBlocking = cPtr->wasNonBlocking; - // some way to find out if it is connected, and binded. can't find - // if it listens though!!! + /* some way to find out if it is connected, and binded. can't find + if it listens though!!! + */ size = sizeof(clientname); n = getpeername(sock, (struct sockaddr*) &clientname, &size); diff --git a/WINGs/dragsource.c b/WINGs/dragsource.c index 6b12bba6..2411ec8d 100644 --- a/WINGs/dragsource.c +++ b/WINGs/dragsource.c @@ -130,12 +130,12 @@ findChildInWindow(Display *dpy, Window toplevel, int x, int y) Window *children; unsigned nchildren; int i; - + if (!XQueryTree(dpy, toplevel, &foo, &bar, &children, &nchildren) || children == NULL) { return None; } - + /* first window that contains the point is the one */ for (i = nchildren-1; i >= 0; i--) { XWindowAttributes attr; @@ -150,8 +150,8 @@ findChildInWindow(Display *dpy, Window toplevel, int x, int y) x - attr.x, y - attr.y); XFree(children); - - if (!child) + + if (child == None) return toplevel; else return child; @@ -167,7 +167,7 @@ static WMView* findViewInToplevel(Display *dpy, Window toplevel, int x, int y) { Window child; - + child = findChildInWindow(dpy, toplevel, x, y); if (child != None) @@ -376,6 +376,16 @@ notifyDragEnter(WMScreen *scr, WMDraggingInfo *info) } +static void +translateCoordinates(WMScreen *scr, Window target, int fromX, int fromY, + int *x, int *y) +{ + Window child; + + XTranslateCoordinates(scr->display, scr->rootWin, target, + fromX, fromY, x, y, &child); +} + static void updateDraggingInfo(WMScreen *scr, WMDraggingInfo *info, @@ -912,10 +922,10 @@ getTypeList(Window window, XClientMessageEvent *event) types[i++] = event->data.l[3]; if (event->data.l[4] != None) types[i++] = event->data.l[4]; - types[i] = NULL; + types[i] = 0; } - if (types[0] == NULL) { + if (types[0] == 0) { wwarning("received invalid drag & drop type list"); //XXX return; } @@ -924,16 +934,16 @@ getTypeList(Window window, XClientMessageEvent *event) } - void W_HandleDNDClientMessage(WMView *toplevel, XClientMessageEvent *event) { +#if 0 WMScreen *scr = W_VIEW_SCREEN(toplevel); - WMView *view; - int operation; + WMView *oldView = NULL, *newView = NULL; + unsigned operation = 0; + int x, y; if (event->message_type == scr->xdndEnterAtom) { - Atom *types; Window foo, bar; int bla; unsigned ble; @@ -952,38 +962,54 @@ W_HandleDNDClientMessage(WMView *toplevel, XClientMessageEvent *event) return; } - info.protocolVersion = event->data.l[0] >> 24; - - info.sourceWindow = event->data.l[0]; - info.destinationWindow = event->window; + scr->dragInfo.protocolVersion = event->data.l[1] >> 24; + scr->dragInfo.sourceWindow = event->data.l[0]; + scr->dragInfo.destinationWindow = event->window; /* XXX */ - info.image = NULL; + scr->dragInfo.image = NULL; XQueryPointer(scr->display, scr->rootWin, &foo, &bar, - &event->location.x, &event->location.y, + &scr->dragInfo.location.x, &scr->dragInfo.location.y, &bla, &bla, &ble); - view = findViewInToplevel(scr->display, - scr->dragInfo.destinationWindow, - scr->dragInfo.location.x, - scr->dragInfo.location.y); + translateCoordinates(scr, scr->dragInfo.destinationWindow, + scr->dragInfo.location.x, + scr->dragInfo.location.y, &x, &y); + + + newView = findViewInToplevel(scr->display, + scr->dragInfo.destinationWindow, + x, y); if (IS_DROPPABLE(view)) { + + scr->dragInfo.destinationView = view; + operation = view->dragDestinationProcs->draggingEntered(view, &scr->dragInfo); - } else { - operation = 0; } - + if (operation > 0) { + Atom action; + + switch (operation) { + default: + action = 0; + break; + } + + sendClientMessage(scr->display, scr->dragInfo.sourceWindow, + scr->xdndStatusAtom, + scr->dragInfo.destinationWindow, + 1, 0, 0, action); + } } else if (event->message_type == scr->xdndPositionAtom && scr->dragInfo.sourceWindow == event->data.l[0]) { - unsigned operation = 0; scr->dragInfo.location.x = event->data.l[2] >> 16; - scr->dragInfo.location.y = event->data.l[2] 0xffff; + scr->dragInfo.location.y = event->data.l[2] & 0xffff; if (scr->dragInfo.protocolVersion >= 1) { scr->dragInfo.timestamp = event->data.l[3]; @@ -992,25 +1018,36 @@ W_HandleDNDClientMessage(WMView *toplevel, XClientMessageEvent *event) scr->dragInfo.timestamp = CurrentTime; scr->dragInfo.sourceOperation = 0; /*XXX*/ } + + translateCoordinates(scr, scr->dragInfo.destinationWindow, + scr->dragInfo.location.x, + scr->dragInfo.location.y, &x, &y); + + view = findViewInToplevel(scr->display, + scr->dragInfo.destinationWindow, + x, y); - child = findChildInWindow(scr->display, scr->dragInfo.destinationWindow, - scr->dragInfo.location.x, - scr->dragInfo.location.y); - if (child != None) { - view = W_GetViewForXWindow(scr->display, child); - } else { - view = NULL; + if (scr->dragInfo.destinationView != view) { + WMView *oldVIew = scr->dragInfo.destinationView; + + oldView->dragDestinationProcs->draggingExited(oldView, + &scr->dragInfo); + + scr->dragInfo.destinationView = NULL; } + if (IS_DROPPABLE(view)) { + + operation = - view->dragDestinationProcs->draggingUpdated(view, + view->dragDestinationProcs->draggingUpdated(view, &scr->dragInfo); } if (operation == 0) { - sendClientMessage(scr->display, scr->xdndStatusAtom, - scr->dragInfo.sourceWindow, + sendClientMessage(scr->display, scr->dragInfo.sourceWindow, + scr->xdndStatusAtom, scr->dragInfo.destinationWindow, 0, 0, 0, None); } else { @@ -1018,25 +1055,30 @@ W_HandleDNDClientMessage(WMView *toplevel, XClientMessageEvent *event) switch (operation) { default: - action =; + action = 0; break; } - - sendClientMessage(scr->display, scr->xdndStatusAtom, - scr->dragInfo.sourceWindow, + + sendClientMessage(scr->display, scr->dragInfo.sourceWindow, + scr->xdndStatusAtom, scr->dragInfo.destinationWindow, 1, 0, 0, action); } - puts("position"); +// puts("position"); } else if (event->message_type == scr->xdndLeaveAtom && scr->dragInfo.sourceWindow == event->data.l[0]) { + void (*draggingExited)(WMView *self, WMDraggingInfo *info); + puts("leave"); } else if (event->message_type == scr->xdndDropAtom && scr->dragInfo.sourceWindow == event->data.l[0]) { + + puts("drop"); } +#endif } diff --git a/WINGs/notification.c b/WINGs/notification.c index a328d84a..c9bb1772 100644 --- a/WINGs/notification.c +++ b/WINGs/notification.c @@ -431,13 +431,11 @@ void WMDequeueNotificationMatching(WMNotificationQueue *queue, WMNotification *notification, unsigned mask) { - int i; + WMBagIterator i; WMNotification *tmp; if ((mask & WNCOnName) && (mask & WNCOnSender)) { - for (i = 0; i < WMGetBagItemCount(queue->asapQueue); i++) { - tmp = WMGetFromBag(queue->asapQueue, i); - + WM_ITERATE_BAG(queue->asapQueue, tmp, i) { if (notification->object == tmp->object && strcmp(notification->name, tmp->name) == 0) { WMRemoveFromBag(queue->asapQueue, tmp); @@ -445,9 +443,7 @@ WMDequeueNotificationMatching(WMNotificationQueue *queue, break; } } - for (i = 0; i < WMGetBagItemCount(queue->idleQueue); i++) { - tmp = WMGetFromBag(queue->idleQueue, i); - + WM_ITERATE_BAG(queue->idleQueue, tmp, i) { if (notification->object == tmp->object && strcmp(notification->name, tmp->name) == 0) { WMRemoveFromBag(queue->idleQueue, tmp); @@ -456,18 +452,14 @@ WMDequeueNotificationMatching(WMNotificationQueue *queue, } } } else if (mask & WNCOnName) { - for (i = 0; i < WMGetBagItemCount(queue->asapQueue); i++) { - tmp = WMGetFromBag(queue->asapQueue, i); - + WM_ITERATE_BAG(queue->asapQueue, tmp, i) { if (strcmp(notification->name, tmp->name) == 0) { WMRemoveFromBag(queue->asapQueue, tmp); WMReleaseNotification(tmp); break; } } - for (i = 0; i < WMGetBagItemCount(queue->idleQueue); i++) { - tmp = WMGetFromBag(queue->idleQueue, i); - + WM_ITERATE_BAG(queue->idleQueue, tmp, i) { if (strcmp(notification->name, tmp->name) == 0) { WMRemoveFromBag(queue->idleQueue, tmp); WMReleaseNotification(tmp); @@ -475,18 +467,14 @@ WMDequeueNotificationMatching(WMNotificationQueue *queue, } } } else if (mask & WNCOnSender) { - for (i = 0; i < WMGetBagItemCount(queue->asapQueue); i++) { - tmp = WMGetFromBag(queue->asapQueue, i); - + WM_ITERATE_BAG(queue->asapQueue, tmp, i) { if (notification->object == tmp->object) { WMRemoveFromBag(queue->asapQueue, tmp); WMReleaseNotification(tmp); break; } } - for (i = 0; i < WMGetBagItemCount(queue->idleQueue); i++) { - tmp = WMGetFromBag(queue->idleQueue, i); - + WM_ITERATE_BAG(queue->idleQueue, tmp, i) { if (notification->object == tmp->object) { WMRemoveFromBag(queue->idleQueue, tmp); WMReleaseNotification(tmp); diff --git a/WINGs/wcolorwell.c b/WINGs/wcolorwell.c index d5a2091d..fb7b3356 100644 --- a/WINGs/wcolorwell.c +++ b/WINGs/wcolorwell.c @@ -46,43 +46,18 @@ static void willResizeColorWell(); W_ViewDelegate _ColorWellViewDelegate = { NULL, - NULL, - NULL, - NULL, - willResizeColorWell + NULL, + NULL, + NULL, + willResizeColorWell }; -static unsigned draggingSourceOperation(WMView *self, Bool local); -static void beganDragImage(WMView *self, WMPixmap *image, WMPoint point); -static void endedDragImage(WMView *self, WMPixmap *image, WMPoint point, - Bool deposited); - - -static WMDragSourceProcs _DragSourceProcs = { - draggingSourceOperation, - beganDragImage, - endedDragImage, - NULL +#if 0 +static WMDragSourceProcs dragProcs = { + }; - - -static unsigned draggingEntered(WMView *self, WMDraggingInfo *info); -static unsigned draggingUpdated(WMView *self, WMDraggingInfo *info); -static void draggingExited(WMView *self, WMDraggingInfo *info); -static Bool prepareForDragOperation(WMView *self, WMDraggingInfo *info); -static Bool performDragOperation(WMView *self, WMDraggingInfo *info); -static void concludeDragOperation(WMView *self, WMDraggingInfo *info); - -static WMDragDestinationProcs _DragDestinationProcs = { - draggingEntered, - draggingUpdated, - draggingExited, - prepareForDragOperation, - performDragOperation, - concludeDragOperation -}; - +#endif #define DEFAULT_WIDTH 60 #define DEFAULT_HEIGHT 30 @@ -193,16 +168,7 @@ WMCreateColorWell(WMWidget *parent) WMAddNotificationObserver(colorChangedObserver, cPtr, WMColorPanelColorChangedNotification, NULL); - - // WMSetViewDragSourceProcs(cPtr->view, &_DragSourceProcs); - // WMSetViewDragDestinationProcs(cPtr->view, &_DragDestinationProcs); - { - char *types[2] = {"application/X-color", NULL}; - - //WMRegisterViewForDraggedTypes(cPtr->view, types); - } - return cPtr; } @@ -310,32 +276,6 @@ handleEvents(XEvent *event, void *data) } -static unsigned -draggingSourceOperation(WMView *self, Bool local) -{ - puts("DRAG SOURCE"); - return 0; -} - - -static void -beganDragImage(WMView *self, WMPixmap *image, WMPoint point) -{ - puts("BEGAN DRAG"); -} - - -static void -endedDragImage(WMView *self, WMPixmap *image, WMPoint point, Bool deposited) -{ - if (deposited) - puts("ENDED DRAG SUCCESS"); - else - puts("ENDED DRAG CANCEL"); -} - - - static WMPixmap* makeDragPixmap(WMColorWell *cPtr) { @@ -352,6 +292,221 @@ makeDragPixmap(WMColorWell *cPtr) } +static void +slideView(WMView *view, int srcX, int srcY, int dstX, int dstY) +{ + double x, y, dx, dy; + int i; + + srcX -= 8; + srcY -= 8; + dstX -= 8; + dstY -= 8; + + x = srcX; + y = srcY; + + dx = (double)(dstX-srcX)/20.0; + dy = (double)(dstY-srcY)/20.0; + + for (i = 0; i < 20; i++) { + W_MoveView(view, x, y); + XFlush(view->screen->display); + + x += dx; + y += dy; + } +} + + + +static Window +findChildInWindow(Display *dpy, Window toplevel, int x, int y) +{ + Window foo, bar; + Window *children; + unsigned nchildren; + int i; + + if (!XQueryTree(dpy, toplevel, &foo, &bar, + &children, &nchildren) || children == NULL) { + return None; + } + + /* first window that contains the point is the one */ + for (i = nchildren-1; i >= 0; i--) { + XWindowAttributes attr; + + if (XGetWindowAttributes(dpy, children[i], &attr) + && attr.map_state == IsViewable + && x >= attr.x && y >= attr.y + && x < attr.x + attr.width && y < attr.y + attr.height) { + Window child; + + child = findChildInWindow(dpy, children[i], + x - attr.x, y - attr.y); + + XFree(children); + + if (!child) + return toplevel; + else + return child; + } + } + + XFree(children); + return None; +} + + +static Window +findWindowUnderDragPointer(WMScreen *scr, int x, int y, Window iconWindow) +{ + Window foo, bar; + Window *children; + unsigned nchildren; + int i; + + if (!XQueryTree(scr->display, scr->rootWin, &foo, &bar, + &children, &nchildren) || children == NULL) { + return None; + } + + /* try to find the window below the iconWindow by traversing + * the whole window list */ + + /* first find the position of the iconWindow */ + for (i = nchildren-1; i >= 0; i--) { + if (children[i] == iconWindow) { + i--; + break; + } + } + if (i <= 0) { + XFree(children); + return scr->rootWin; + } + + /* first window that contains the point is the one */ + for (; i >= 0; i--) { + XWindowAttributes attr; + Window child; + + if (XGetWindowAttributes(scr->display, children[i], &attr) + && attr.map_state == IsViewable + && x >= attr.x && y >= attr.y + && x < attr.x + attr.width && y < attr.y + attr.height + && (child = findChildInWindow(scr->display, children[i], + x - attr.x, y - attr.y))) { + XFree(children); + return child; + } + } + + XFree(children); + return None; +} + + + +static void +dragColor(ColorWell *cPtr, XEvent *event, WMPixmap *image) +{ + WMView *dragView; + WMScreen *scr = cPtr->view->screen; + Display *dpy = scr->display; + XColor black = {0, 0,0,0, DoRed|DoGreen|DoBlue}; + XColor green = {0x0045b045, 0x4500,0xb000,0x4500, DoRed|DoGreen|DoBlue}; + XColor back = {0, 0xffff,0xffff,0xffff, DoRed|DoGreen|DoBlue}; + Bool done = False; + WMColorWell *activeWell = NULL; + + dragView = W_CreateTopView(scr); + + W_ResizeView(dragView, 16, 16); + dragView->attribFlags |= CWOverrideRedirect | CWSaveUnder; + dragView->attribs.event_mask = StructureNotifyMask; + dragView->attribs.override_redirect = True; + dragView->attribs.save_under = True; + + W_MoveView(dragView, event->xmotion.x_root-8, event->xmotion.y_root-8); + + W_RealizeView(dragView); + + W_MapView(dragView); + + XSetWindowBackgroundPixmap(dpy, dragView->window, WMGetPixmapXID(image)); + XClearWindow(dpy, dragView->window); + + + XGrabPointer(dpy, scr->rootWin, True, + ButtonMotionMask|ButtonReleaseMask, + GrabModeSync, GrabModeAsync, + scr->rootWin, scr->defaultCursor, CurrentTime); + + while (!done) { + XEvent ev; + WMView *view; + Window win; + + XAllowEvents(dpy, SyncPointer, CurrentTime); + WMNextEvent(dpy, &ev); + + switch (ev.type) { + case ButtonRelease: + if (activeWell != NULL) { + WMSetColorWellColor(activeWell, cPtr->color); + WMPostNotificationName(WMColorWellDidChangeNotification, + activeWell, NULL); + } else { + slideView(dragView, ev.xbutton.x_root, ev.xbutton.y_root, + event->xmotion.x_root, event->xmotion.y_root); + } + + done = True; + break; + + case MotionNotify: + while (XCheckTypedEvent(dpy, MotionNotify, &ev)) ; + + W_MoveView(dragView, ev.xmotion.x_root-8, ev.xmotion.y_root-8); + + win = findWindowUnderDragPointer(scr, ev.xmotion.x_root, + ev.xmotion.y_root, + dragView->window); + + if (win != None && win != scr->rootWin) { + view = W_GetViewForXWindow(dpy, win); + } else { + view = NULL; + } + + if (view && view->self && W_CLASS(view->self) == WC_ColorWell + && view->self != activeWell && view->self != cPtr) { + + activeWell = view->self; + XRecolorCursor(dpy, scr->defaultCursor, &green, &back); + + } else if (!view || view->self != activeWell) { + + XRecolorCursor(dpy, scr->defaultCursor, &black, &back); + activeWell = NULL; + } + break; + + default: + WMHandleEvent(&ev); + break; + } + } + XUngrabPointer(dpy, CurrentTime); + XRecolorCursor(dpy, scr->defaultCursor, &black, &back); + + W_DestroyView(dragView); +} + + static void handleDragEvents(XEvent *event, void *data) { @@ -371,17 +526,17 @@ handleDragEvents(XEvent *event, void *data) || abs(cPtr->ipoint.y - event->xmotion.y) > 4) { WMSize offs; WMPixmap *pixmap; - char *types[2] = {"application/X-color", NULL}; offs.width = 2; offs.height = 2; pixmap = makeDragPixmap(cPtr); -/* - WMDragImageFromView(cPtr->view, pixmap, types, - wmkpoint(event->xmotion.x_root, - event->xmotion.y_root), - offs, event, True); - */ + + /* + WMDragImageFromView(cPtr->view, pixmap, cPtr->view->pos, + offs, event, True); + * */ + + dragColor(cPtr, event, pixmap); WMReleasePixmap(pixmap); } @@ -430,76 +585,3 @@ destroyColorWell(ColorWell *cPtr) wfree(cPtr); } - - -static unsigned -draggingEntered(WMView *self, WMDraggingInfo *info) -{ - WMPoint point = WMGetViewScreenPosition(self); - - printf("%i %i || %i %i %i %i\n", info->location.x, info->location.y, - point.x, point.y, W_VIEW_WIDTH(self), W_VIEW_HEIGHT(self)); - - if (info->location.x >= point.x - && info->location.y >= point.y - && info->location.x < point.x + W_VIEW_WIDTH(self) - && info->location.y < point.y + W_VIEW_HEIGHT(self)) { - /* self */ - puts("ENTERED 0"); - return 0; - } else { - puts("ENTERED 1"); - return 1; - } -} - - -static unsigned -draggingUpdated(WMView *self, WMDraggingInfo *info) -{ - - WMPoint point = WMGetViewScreenPosition(self); - - puts("UPDATED"); - if (info->location.x >= point.x - && info->location.y >= point.y - && info->location.x < point.x + W_VIEW_WIDTH(self) - && info->location.y < point.y + W_VIEW_WIDTH(self)) { - return 0; - } else { - return 1; - } -} - - -static void -draggingExited(WMView *self, WMDraggingInfo *info) -{ - puts("EXITED"); -} - - -static Bool -prepareForDragOperation(WMView *self, WMDraggingInfo *info) -{ - puts("PREPARING"); - return True; -} - - -static Bool -performDragOperation(WMView *self, WMDraggingInfo *info) -{ - WMData *data; - - // data = WMGetDroppedData(self); - puts("DROPPED"); - return True; -} - - -static void -concludeDragOperation(WMView *self, WMDraggingInfo *info) -{ - puts("FINISHED"); -} diff --git a/WINGs/wevent.c b/WINGs/wevent.c index 96716063..b2055aca 100644 --- a/WINGs/wevent.c +++ b/WINGs/wevent.c @@ -252,7 +252,7 @@ WMDeleteIdleHandler(WMHandlerID handlerID) return; pos = WMGetFirstInBag(idleHandler, handler); - if (pos >= 0) { + if (pos != WBNotFound) { wfree(handler); WMDeleteFromBag(idleHandler, pos); } @@ -291,7 +291,7 @@ WMDeleteInputHandler(WMHandlerID handlerID) return; pos = WMGetFirstInBag(inputHandler, handler); - if (pos >= 0) { + if (pos != WBNotFound) { wfree(handler); WMDeleteFromBag(inputHandler, pos); } @@ -588,7 +588,7 @@ WMHandleEvent(XEvent *event) } else if (event->type == ClientMessage) { - //W_HandleDNDClientMessage(toplevel, &event->xclient); + W_HandleDNDClientMessage(toplevel, &event->xclient); } /* if it's a key event, redispatch it to the focused control */ @@ -786,7 +786,7 @@ W_WaitForEvent(Display *dpy, unsigned long xeventmask) handler = WMGetFromBag(handlerCopy, i); /* check if the handler still exist or was removed by a callback */ - if (WMGetFirstInBag(inputHandler, handler)<0) + if (WMGetFirstInBag(inputHandler, handler) == WBNotFound) continue; mask = 0; @@ -891,7 +891,7 @@ W_WaitForEvent(Display *dpy, unsigned long xeventmask) handler = WMGetFromBag(handlerCopy, i); /* check if the handler still exist or was removed by a callback */ - if (WMGetFirstInBag(inputHandler, handler)<0) + if (WMGetFirstInBag(inputHandler, handler) == WBNotFound) continue; mask = 0; diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index 8535f3bd..6852020c 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -104,19 +104,17 @@ closestListItem(WMList *list, char *text, Bool exact) { WMListItem *item; WMBag *items = WMGetListItems(list); - int i; + WMBagIterator i; int len = strlen(text); if (len==0) return -1; - for (i = 0; i < WMGetBagItemCount(items); i++) { - item = WMGetFromBag(items, i); - + WM_ITERATE_BAG(items, item, i) { if (strlen(item->text) >= len && ((exact && strcmp(item->text, text)==0) || (!exact && strncmp(item->text, text, len)==0))) { - return i; + return WMBagIndexForIterator(items, i); } } diff --git a/WINGs/wfontpanel.c b/WINGs/wfontpanel.c index f7ef4c1a..bf577fd2 100644 --- a/WINGs/wfontpanel.c +++ b/WINGs/wfontpanel.c @@ -534,14 +534,14 @@ static void addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256]) { Typeface *face; - int i; + WMBagIterator i; if (family->typefaces) { - for (i = 0; i < WMGetBagItemCount(family->typefaces); i++) { + for (face = WMBagFirst(family->typefaces, &i); + face != NULL; + face = WMBagNext(family->typefaces, &i)) { int size; - - face = WMGetFromBag(family->typefaces, i); - + if (strcmp(face->weight, fontFields[WEIGHT]) != 0) { continue; } @@ -584,7 +584,7 @@ addTypefaceToFamily(Family *family, char fontFields[NUM_FIELDS][256]) static void addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256]) { - int i; + WMBagIterator i; Family *fam; WMBag *family; @@ -593,11 +593,11 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256]) if (family) { /* look for same encoding/registry and foundry */ - for (i = 0; i < WMGetBagItemCount(family); i++) { + for (fam = WMBagFirst(family, &i); + fam != NULL; + fam = WMBagNext(family, &i)) { int enc, reg, found; - - fam = WMGetFromBag(family, i); - + enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0); reg = (strcmp(fam->registry, fontFields[REGISTRY]) == 0); found = (strcmp(fam->foundry, fontFields[FOUNDRY]) == 0); @@ -608,11 +608,11 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256]) } } /* look for same encoding/registry */ - for (i = 0; i < WMGetBagItemCount(family); i++) { + for (fam = WMBagFirst(family, &i); + fam != NULL; + fam = WMBagNext(family, &i)) { int enc, reg; - fam = WMGetFromBag(family, i); - enc = (strcmp(fam->encoding, fontFields[ENCODING]) == 0); reg = (strcmp(fam->registry, fontFields[REGISTRY]) == 0); @@ -636,11 +636,11 @@ addFontToFamily(WMHashTable *families, char fontFields[NUM_FIELDS][256]) } } /* look for same foundry */ - for (i = 0; i < WMGetBagItemCount(family); i++) { + for (fam = WMBagFirst(family, &i); + fam != NULL; + fam = WMBagNext(family, &i)) { int found; - fam = WMGetFromBag(family, i); - found = (strcmp(fam->foundry, fontFields[FOUNDRY]) == 0); if (found) { @@ -740,13 +740,14 @@ listFamilies(WMScreen *scr, WMFontPanel *panel) enumer = WMEnumerateHashTable(families); while ((bag = WMNextHashEnumeratorItem(&enumer))) { - int i; + WMBagIterator i; Family *fam; char buffer[256]; WMListItem *item; - for (i = 0; i < WMGetBagItemCount(bag); i++) { - fam = WMGetFromBag(bag, i); + for (fam = WMBagFirst(bag, &i); + fam != NULL; + fam = WMBagNext(bag, &i)) { strcpy(buffer, fam->name); @@ -834,7 +835,7 @@ familyClick(WMWidget *w, void *data) Family *family; FontPanel *panel = (FontPanel*)data; Typeface *face; - int i; + WMBagIterator i; /* current typeface and size */ char *oface = NULL; char *osize = NULL; @@ -854,12 +855,13 @@ familyClick(WMWidget *w, void *data) WMClearList(panel->typLs); - for (i = 0; i < WMGetBagItemCount(family->typefaces); i++) { + + for (face = WMBagFirst(family->typefaces, &i); + face != NULL; + face = WMBagNext(family->typefaces, &i)) { char buffer[256]; int top=0; WMListItem *fitem; - - face = WMGetFromBag(family->typefaces, i); if (strcmp(face->weight, "medium") == 0) { buffer[0] = 0; @@ -931,11 +933,12 @@ typefaceClick(WMWidget *w, void *data) FontPanel *panel = (FontPanel*)data; WMListItem *item; Typeface *face; - int i; + WMBagIterator i; char buffer[32]; char *osize = NULL; int sizei = -1; + int size; osize = WMGetTextFieldText(panel->sizT); @@ -945,11 +948,10 @@ typefaceClick(WMWidget *w, void *data) WMClearList(panel->sizLs); - for (i = 0; i < WMGetBagItemCount(face->sizes); i++) { - int size; + for (size = (int)WMBagFirst(face->sizes, &i); + i != NULL; + size = (int)WMBagNext(face->sizes, &i)) { - size = (int)WMGetFromBag(face->sizes, i); - if (size != 0) { sprintf(buffer, "%i", size); diff --git a/WINGs/wlist.c b/WINGs/wlist.c index 88d34fcd..f46f49f3 100644 --- a/WINGs/wlist.c +++ b/WINGs/wlist.c @@ -171,9 +171,9 @@ WMInsertListItem(WMList *lPtr, int row, char *text) lPtr->selectedItem++; if (row < 0) - row = WMGetBagItemCount(lPtr->items); - - WMInsertInBag(lPtr->items, row, item); + WMPutInBag(lPtr->items, item); + else + WMInsertInBag(lPtr->items, row, item); /* update the scroller when idle, so that we don't waste time * updating it when another item is going to be added later */ @@ -589,18 +589,17 @@ int WMFindRowOfListItemWithTitle(WMList *lPtr, char *title) { WMListItem *item; - int i; + WMBagIterator i; int ok = 0; - for (i=0; i < WMGetBagItemCount(lPtr->items); i++) { - item = WMGetFromBag(lPtr->items, i); + WM_ITERATE_BAG(lPtr->items, item, i) { if (strcmp(item->text, title)==0) { ok = 1; break; } } - return ok ? i : -1; + return ok ? WMBagIndexForIterator(lPtr->items, i) : -1; } @@ -781,14 +780,13 @@ static void destroyList(List *lPtr) { WMListItem *item; - int i; + WMBagIterator i; if (lPtr->idleID) WMDeleteIdleHandler(lPtr->idleID); lPtr->idleID = NULL; - for (i = 0; i < WMGetBagItemCount(lPtr->items); i++) { - item = WMGetFromBag(lPtr->items, i); + WM_ITERATE_BAG(lPtr->items, item, i) { wfree(item->text); wfree(item); } diff --git a/WINGs/wpopupbutton.c b/WINGs/wpopupbutton.c index 170b8ecb..2353594e 100644 --- a/WINGs/wpopupbutton.c +++ b/WINGs/wpopupbutton.c @@ -307,7 +307,7 @@ WMGetPopUpButtonItem(WMPopUpButton *bPtr, int index) return NULL; item = WMGetFromBag(bPtr->items, index); - if (!item) + if (item == NULL) return NULL; return WMGetMenuItemTitle(item); @@ -464,8 +464,9 @@ makeMenuPixmap(PopUpButton *bPtr) { Pixmap pixmap; W_Screen *scr = bPtr->view->screen; - int i; - int yo; + WMMenuItem *item; + WMBagIterator iter; + int yo, i; int width, height, itemHeight; itemHeight = bPtr->view->size.height; @@ -479,12 +480,11 @@ makeMenuPixmap(PopUpButton *bPtr) XFillRectangle(scr->display, pixmap, WMColorGC(scr->gray), 0, 0, width, height); - for (i = 0; i < WMGetBagItemCount(bPtr->items); i++) { + i = 0; + WM_ITERATE_BAG(bPtr->items, item, iter) { GC gc; - WMMenuItem *item; char *text; - item = (WMMenuItem*)WMGetFromBag(bPtr->items, i); text = WMGetMenuItemTitle(item); W_DrawRelief(scr, pixmap, 0, i*itemHeight, width, itemHeight, @@ -506,6 +506,8 @@ makeMenuPixmap(PopUpButton *bPtr) width-scr->popUpIndicator->width-4, i*itemHeight+(itemHeight-scr->popUpIndicator->height)/2); } + + i++; } return pixmap; @@ -758,14 +760,13 @@ static void destroyPopUpButton(PopUpButton *bPtr) { WMMenuItem *item; - int i; + WMBagIterator i; if (bPtr->timer) { WMDeleteTimerHandler(bPtr->timer); } - for (i = 0; i < WMGetBagItemCount(bPtr->items); i++) { - item = WMGetFromBag(bPtr->items, i); + WM_ITERATE_BAG(bPtr->items, item, i) { WMDestroyMenuItem(item); } WMFreeBag(bPtr->items); diff --git a/WINGs/wtabview.c b/WINGs/wtabview.c index 6c1b2aa0..e46afd48 100644 --- a/WINGs/wtabview.c +++ b/WINGs/wtabview.c @@ -32,9 +32,6 @@ typedef struct W_TabView { unsigned tabbed:1; unsigned dontFitAll:1; - - unsigned leftDown:1; // scrolling button state - unsigned rightDown:1; } flags; } TabView; diff --git a/WINGs/wview.c b/WINGs/wview.c index 15ad177a..0d7b5fcc 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -403,7 +403,7 @@ destroyView(W_View *view) W_CleanUpEvents(view); - // WMUnregisterViewDraggedTypes(view); + WMUnregisterViewDraggedTypes(view); #if 0 if (view->dragSourceProcs)