# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1304649322 0 # Node ID ab244c6f9386c111fa39ada9bf3e6405a7291d0a # Parent 52cd98b7e45c54cc0cbddeebe846b219f5e77384 Changed HICN to be a pointer type and simplified the icon code. Except when using resource IDs as HICN parameters HICN will be a pixbuf handle. diff -r 52cd98b7e45c -r ab244c6f9386 gtk3/dw.c --- a/gtk3/dw.c Fri May 06 01:46:27 2011 +0000 +++ b/gtk3/dw.c Fri May 06 02:35:22 2011 +0000 @@ -28,9 +28,6 @@ #include #include #include -#ifdef USE_IMLIB -#include -#endif #ifdef USE_GTKMOZEMBED # include @@ -207,15 +204,6 @@ # endif #endif -typedef struct -{ - GdkPixbuf *pixbuf; - int used; - unsigned long width, height; -} DWPrivatePixmap; - -static DWPrivatePixmap *_PixmapArray = NULL; -static int _PixmapCount = 0; GObject *_DWObject = NULL; typedef struct @@ -1786,26 +1774,22 @@ return FALSE; } -static GdkPixbuf *_find_private_pixbuf(long id, unsigned long *userwidth, unsigned long *userheight) -{ - if(id < _PixmapCount && _PixmapArray[id].used) - { - if(userwidth) - *userwidth = _PixmapArray[id].width; - if(userheight) - *userheight = _PixmapArray[id].height; - return _PixmapArray[id].pixbuf; - } - return NULL; -} - -static GdkPixbuf *_find_pixbuf(long id, unsigned long *userwidth, unsigned long *userheight) +static GdkPixbuf *_find_pixbuf(HICN icon, unsigned long *userwidth, unsigned long *userheight) { char *data = NULL; - int z; - - if(id & (1 << 31)) - return _find_private_pixbuf((id & 0xFFFFFF), userwidth, userheight); + int z, id = (int)icon; + + if(id > 65535) + { + GdkPixbuf *icon_pixbuf = icon; + + if(userwidth) + *userwidth = gdk_pixbuf_get_width(icon_pixbuf); + if(userheight) + *userheight = gdk_pixbuf_get_height(icon_pixbuf); + + return icon; + } for(z=0;z<_resources.resource_max;z++) { @@ -2745,9 +2729,9 @@ GdkCursor *cursor; DW_MUTEX_LOCK; - if(pointertype & (1 << 31)) - { - GdkPixbuf *pixbuf = _find_private_pixbuf((pointertype & 0xFFFFFF), NULL, NULL); + if(pointertype > 65535) + { + GdkPixbuf *pixbuf = _find_pixbuf((HICN)pointertype, NULL, NULL); cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 8, 8); } else if(!pointertype) @@ -4046,7 +4030,7 @@ DW_MUTEX_LOCK; if(id) - tmp = _find_pixbuf(id, NULL, NULL); + tmp = _find_pixbuf((HICN)id, NULL, NULL); else { char *file = alloca(strlen(filename) + 5); @@ -4120,7 +4104,7 @@ DW_MUTEX_LOCK; if (id) - tmp = _find_pixbuf(id, NULL, NULL); + tmp = _find_pixbuf((HICN)id, NULL, NULL); else { GdkPixbuf *pixbuf; @@ -4909,8 +4893,6 @@ gtk_tree_store_insert_after(store, iter, (GtkTreeIter *)parent, (GtkTreeIter *)item); gtk_tree_store_set (store, iter, 0, title, 1, pixbuf, 2, itemdata, 3, iter, -1); - if(pixbuf && !(icon & (1 << 31))) - g_object_unref(pixbuf); retval = (HTREEITEM)iter; } DW_MUTEX_UNLOCK; @@ -4950,8 +4932,6 @@ gtk_tree_store_append (store, iter, (GtkTreeIter *)parent); gtk_tree_store_set (store, iter, 0, title, 1, pixbuf, 2, itemdata, 3, iter, -1); - if(pixbuf && !(icon & (1 << 31))) - g_object_unref(pixbuf); retval = (HTREEITEM)iter; } DW_MUTEX_UNLOCK; @@ -4985,8 +4965,6 @@ pixbuf = _find_pixbuf(icon, NULL, NULL); gtk_tree_store_set(store, (GtkTreeIter *)item, 0, title, 1, pixbuf, -1); - if(pixbuf && !(icon & (1 << 31))) - g_object_unref(pixbuf); } DW_MUTEX_UNLOCK; } @@ -5450,55 +5428,7 @@ */ HICN dw_icon_load(unsigned long module, unsigned long id) { - return id; -} - -HICN _dw_icon_load_internal(GdkPixbuf *pixbuf) -{ - unsigned long z, ret = 0; - int found = -1; - - /* Find a free entry in the array */ - for (z=0;z<_PixmapCount;z++) - { - if (!_PixmapArray[z].used) - { - ret = found = z; - break; - } - } - - /* If there are no free entries, expand the - * array. - */ - if (found == -1) - { - DWPrivatePixmap *old = _PixmapArray; - - ret = found = _PixmapCount; - _PixmapCount++; - - _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount); - - if (found) - memcpy(_PixmapArray, old, sizeof(DWPrivatePixmap) * found); - if (old) - free(old); - _PixmapArray[found].used = 1; - _PixmapArray[found].pixbuf = NULL; - } - - _PixmapArray[found].pixbuf = pixbuf; - _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf); - _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf); - - if (!_PixmapArray[found].pixbuf) - { - _PixmapArray[found].used = 0; - _PixmapArray[found].pixbuf = NULL; - return 0; - } - return (HICN)ret | (1 << 31); + return (HICN)id; } /* @@ -5511,10 +5441,9 @@ HICN API dw_icon_load_from_file(char *filename) { int _locked_by_me = FALSE; - GdkPixbuf *pixbuf; char *file = alloca(strlen(filename) + 5); - int found_ext = 0; - int i, ret = 0; + int i, found_ext = 0; + HICN ret = 0; if (!file) return 0; @@ -5542,11 +5471,7 @@ } DW_MUTEX_LOCK; - pixbuf = gdk_pixbuf_new_from_file(file, NULL); - if (pixbuf) - { - ret = _dw_icon_load_internal(pixbuf); - } + ret = gdk_pixbuf_new_from_file(file, NULL); DW_MUTEX_UNLOCK; return ret; } @@ -5562,8 +5487,7 @@ int _locked_by_me = FALSE; char *file; FILE *fp; - GdkPixbuf *pixbuf; - unsigned long ret = 0; + HICN ret = 0; /* * A real hack; create a temporary file and write the contents @@ -5581,11 +5505,7 @@ return 0; } DW_MUTEX_LOCK; - pixbuf = gdk_pixbuf_new_from_file(file, NULL); - if (pixbuf) - { - ret = _dw_icon_load_internal(pixbuf); - } + ret = gdk_pixbuf_new_from_file(file, NULL); DW_MUTEX_UNLOCK; return ret; } @@ -5597,23 +5517,11 @@ */ void dw_icon_free(HICN handle) { - /* If it is a private icon, find the item - * free the associated structures and set - * the entry to unused. - */ - if(handle & (1 << 31)) - { - unsigned long id = handle & 0xFFFFFF; - - if(id < _PixmapCount && _PixmapArray[id].used) - { - if(_PixmapArray[id].pixbuf) - { - g_object_unref(_PixmapArray[id].pixbuf); - _PixmapArray[id].pixbuf = NULL; - } - _PixmapArray[id].used = 0; - } + int iicon = (int)handle; + + if(iicon > 65535) + { + g_object_unref(handle); } } @@ -5689,7 +5597,7 @@ if(flag & DW_CFA_STRINGANDICON) { void **thisdata = (void **)data; - long hicon = *((long *)thisdata[0]); + HICN hicon = *((HICN *)thisdata[0]); char *tmp = (char *)thisdata[1]; GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); @@ -5700,7 +5608,7 @@ } else if(flag & DW_CFA_BITMAPORICON) { - long hicon = *((long *)data); + HICN hicon = *((HICN *)data); GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); if(pixbuf) @@ -7087,7 +6995,7 @@ DW_MUTEX_LOCK; - pixmap->pixbuf = gdk_pixbuf_copy(_find_pixbuf(id, &pixmap->width, &pixmap->height)); + pixmap->pixbuf = gdk_pixbuf_copy(_find_pixbuf((HICN)id, &pixmap->width, &pixmap->height)); DW_MUTEX_UNLOCK; return pixmap; }