Mercurial > dwindows
comparison gtk3/dw.c @ 976:ab244c6f9386
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.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 06 May 2011 02:35:22 +0000 |
parents | 32830f1683c9 |
children | 87dc0f5f96d0 |
comparison
equal
deleted
inserted
replaced
975:52cd98b7e45c | 976:ab244c6f9386 |
---|---|
26 #include <sys/stat.h> | 26 #include <sys/stat.h> |
27 #include <signal.h> | 27 #include <signal.h> |
28 #include <fcntl.h> | 28 #include <fcntl.h> |
29 #include <unistd.h> | 29 #include <unistd.h> |
30 #include <gdk/gdkkeysyms.h> | 30 #include <gdk/gdkkeysyms.h> |
31 #ifdef USE_IMLIB | |
32 #include <gdk_imlib.h> | |
33 #endif | |
34 | 31 |
35 #ifdef USE_GTKMOZEMBED | 32 #ifdef USE_GTKMOZEMBED |
36 # include <gtkmozembed.h> | 33 # include <gtkmozembed.h> |
37 # undef GTK_TYPE_MOZ_EMBED | 34 # undef GTK_TYPE_MOZ_EMBED |
38 # define GTK_TYPE_MOZ_EMBED (_dw_moz_embed_get_type()) | 35 # define GTK_TYPE_MOZ_EMBED (_dw_moz_embed_get_type()) |
205 WEBKIT_API WebKitWebFrame *(*_webkit_web_view_get_focused_frame)(WebKitWebView *) = NULL; | 202 WEBKIT_API WebKitWebFrame *(*_webkit_web_view_get_focused_frame)(WebKitWebView *) = NULL; |
206 # endif | 203 # endif |
207 # endif | 204 # endif |
208 #endif | 205 #endif |
209 | 206 |
210 typedef struct | |
211 { | |
212 GdkPixbuf *pixbuf; | |
213 int used; | |
214 unsigned long width, height; | |
215 } DWPrivatePixmap; | |
216 | |
217 static DWPrivatePixmap *_PixmapArray = NULL; | |
218 static int _PixmapCount = 0; | |
219 GObject *_DWObject = NULL; | 207 GObject *_DWObject = NULL; |
220 | 208 |
221 typedef struct | 209 typedef struct |
222 { | 210 { |
223 void *func; | 211 void *func; |
1784 } | 1772 } |
1785 } | 1773 } |
1786 return FALSE; | 1774 return FALSE; |
1787 } | 1775 } |
1788 | 1776 |
1789 static GdkPixbuf *_find_private_pixbuf(long id, unsigned long *userwidth, unsigned long *userheight) | 1777 static GdkPixbuf *_find_pixbuf(HICN icon, unsigned long *userwidth, unsigned long *userheight) |
1790 { | 1778 { |
1791 if(id < _PixmapCount && _PixmapArray[id].used) | 1779 char *data = NULL; |
1792 { | 1780 int z, id = (int)icon; |
1781 | |
1782 if(id > 65535) | |
1783 { | |
1784 GdkPixbuf *icon_pixbuf = icon; | |
1785 | |
1793 if(userwidth) | 1786 if(userwidth) |
1794 *userwidth = _PixmapArray[id].width; | 1787 *userwidth = gdk_pixbuf_get_width(icon_pixbuf); |
1795 if(userheight) | 1788 if(userheight) |
1796 *userheight = _PixmapArray[id].height; | 1789 *userheight = gdk_pixbuf_get_height(icon_pixbuf); |
1797 return _PixmapArray[id].pixbuf; | 1790 |
1798 } | 1791 return icon; |
1799 return NULL; | 1792 } |
1800 } | |
1801 | |
1802 static GdkPixbuf *_find_pixbuf(long id, unsigned long *userwidth, unsigned long *userheight) | |
1803 { | |
1804 char *data = NULL; | |
1805 int z; | |
1806 | |
1807 if(id & (1 << 31)) | |
1808 return _find_private_pixbuf((id & 0xFFFFFF), userwidth, userheight); | |
1809 | 1793 |
1810 for(z=0;z<_resources.resource_max;z++) | 1794 for(z=0;z<_resources.resource_max;z++) |
1811 { | 1795 { |
1812 if(_resources.resource_id[z] == id) | 1796 if(_resources.resource_id[z] == id) |
1813 { | 1797 { |
2743 { | 2727 { |
2744 int _locked_by_me = FALSE; | 2728 int _locked_by_me = FALSE; |
2745 GdkCursor *cursor; | 2729 GdkCursor *cursor; |
2746 | 2730 |
2747 DW_MUTEX_LOCK; | 2731 DW_MUTEX_LOCK; |
2748 if(pointertype & (1 << 31)) | 2732 if(pointertype > 65535) |
2749 { | 2733 { |
2750 GdkPixbuf *pixbuf = _find_private_pixbuf((pointertype & 0xFFFFFF), NULL, NULL); | 2734 GdkPixbuf *pixbuf = _find_pixbuf((HICN)pointertype, NULL, NULL); |
2751 cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 8, 8); | 2735 cursor = gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf, 8, 8); |
2752 } | 2736 } |
2753 else if(!pointertype) | 2737 else if(!pointertype) |
2754 cursor = NULL; | 2738 cursor = NULL; |
2755 else | 2739 else |
4044 if(!id && !filename) | 4028 if(!id && !filename) |
4045 return; | 4029 return; |
4046 | 4030 |
4047 DW_MUTEX_LOCK; | 4031 DW_MUTEX_LOCK; |
4048 if(id) | 4032 if(id) |
4049 tmp = _find_pixbuf(id, NULL, NULL); | 4033 tmp = _find_pixbuf((HICN)id, NULL, NULL); |
4050 else | 4034 else |
4051 { | 4035 { |
4052 char *file = alloca(strlen(filename) + 5); | 4036 char *file = alloca(strlen(filename) + 5); |
4053 | 4037 |
4054 if (!file) | 4038 if (!file) |
4118 if (!id && !data) | 4102 if (!id && !data) |
4119 return; | 4103 return; |
4120 | 4104 |
4121 DW_MUTEX_LOCK; | 4105 DW_MUTEX_LOCK; |
4122 if (id) | 4106 if (id) |
4123 tmp = _find_pixbuf(id, NULL, NULL); | 4107 tmp = _find_pixbuf((HICN)id, NULL, NULL); |
4124 else | 4108 else |
4125 { | 4109 { |
4126 GdkPixbuf *pixbuf; | 4110 GdkPixbuf *pixbuf; |
4127 if (!data) | 4111 if (!data) |
4128 { | 4112 { |
4907 | 4891 |
4908 pixbuf = _find_pixbuf(icon, NULL, NULL); | 4892 pixbuf = _find_pixbuf(icon, NULL, NULL); |
4909 | 4893 |
4910 gtk_tree_store_insert_after(store, iter, (GtkTreeIter *)parent, (GtkTreeIter *)item); | 4894 gtk_tree_store_insert_after(store, iter, (GtkTreeIter *)parent, (GtkTreeIter *)item); |
4911 gtk_tree_store_set (store, iter, 0, title, 1, pixbuf, 2, itemdata, 3, iter, -1); | 4895 gtk_tree_store_set (store, iter, 0, title, 1, pixbuf, 2, itemdata, 3, iter, -1); |
4912 if(pixbuf && !(icon & (1 << 31))) | |
4913 g_object_unref(pixbuf); | |
4914 retval = (HTREEITEM)iter; | 4896 retval = (HTREEITEM)iter; |
4915 } | 4897 } |
4916 DW_MUTEX_UNLOCK; | 4898 DW_MUTEX_UNLOCK; |
4917 | 4899 |
4918 return retval; | 4900 return retval; |
4948 | 4930 |
4949 pixbuf = _find_pixbuf(icon, NULL, NULL); | 4931 pixbuf = _find_pixbuf(icon, NULL, NULL); |
4950 | 4932 |
4951 gtk_tree_store_append (store, iter, (GtkTreeIter *)parent); | 4933 gtk_tree_store_append (store, iter, (GtkTreeIter *)parent); |
4952 gtk_tree_store_set (store, iter, 0, title, 1, pixbuf, 2, itemdata, 3, iter, -1); | 4934 gtk_tree_store_set (store, iter, 0, title, 1, pixbuf, 2, itemdata, 3, iter, -1); |
4953 if(pixbuf && !(icon & (1 << 31))) | |
4954 g_object_unref(pixbuf); | |
4955 retval = (HTREEITEM)iter; | 4935 retval = (HTREEITEM)iter; |
4956 } | 4936 } |
4957 DW_MUTEX_UNLOCK; | 4937 DW_MUTEX_UNLOCK; |
4958 | 4938 |
4959 return retval; | 4939 return retval; |
4983 (store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(tree)))) | 4963 (store = (GtkTreeStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(tree)))) |
4984 { | 4964 { |
4985 pixbuf = _find_pixbuf(icon, NULL, NULL); | 4965 pixbuf = _find_pixbuf(icon, NULL, NULL); |
4986 | 4966 |
4987 gtk_tree_store_set(store, (GtkTreeIter *)item, 0, title, 1, pixbuf, -1); | 4967 gtk_tree_store_set(store, (GtkTreeIter *)item, 0, title, 1, pixbuf, -1); |
4988 if(pixbuf && !(icon & (1 << 31))) | |
4989 g_object_unref(pixbuf); | |
4990 } | 4968 } |
4991 DW_MUTEX_UNLOCK; | 4969 DW_MUTEX_UNLOCK; |
4992 } | 4970 } |
4993 | 4971 |
4994 /* | 4972 /* |
5448 * Windows, on GTK this is converted to a pointer | 5426 * Windows, on GTK this is converted to a pointer |
5449 * to an embedded XPM. | 5427 * to an embedded XPM. |
5450 */ | 5428 */ |
5451 HICN dw_icon_load(unsigned long module, unsigned long id) | 5429 HICN dw_icon_load(unsigned long module, unsigned long id) |
5452 { | 5430 { |
5453 return id; | 5431 return (HICN)id; |
5454 } | |
5455 | |
5456 HICN _dw_icon_load_internal(GdkPixbuf *pixbuf) | |
5457 { | |
5458 unsigned long z, ret = 0; | |
5459 int found = -1; | |
5460 | |
5461 /* Find a free entry in the array */ | |
5462 for (z=0;z<_PixmapCount;z++) | |
5463 { | |
5464 if (!_PixmapArray[z].used) | |
5465 { | |
5466 ret = found = z; | |
5467 break; | |
5468 } | |
5469 } | |
5470 | |
5471 /* If there are no free entries, expand the | |
5472 * array. | |
5473 */ | |
5474 if (found == -1) | |
5475 { | |
5476 DWPrivatePixmap *old = _PixmapArray; | |
5477 | |
5478 ret = found = _PixmapCount; | |
5479 _PixmapCount++; | |
5480 | |
5481 _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount); | |
5482 | |
5483 if (found) | |
5484 memcpy(_PixmapArray, old, sizeof(DWPrivatePixmap) * found); | |
5485 if (old) | |
5486 free(old); | |
5487 _PixmapArray[found].used = 1; | |
5488 _PixmapArray[found].pixbuf = NULL; | |
5489 } | |
5490 | |
5491 _PixmapArray[found].pixbuf = pixbuf; | |
5492 _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf); | |
5493 _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf); | |
5494 | |
5495 if (!_PixmapArray[found].pixbuf) | |
5496 { | |
5497 _PixmapArray[found].used = 0; | |
5498 _PixmapArray[found].pixbuf = NULL; | |
5499 return 0; | |
5500 } | |
5501 return (HICN)ret | (1 << 31); | |
5502 } | 5432 } |
5503 | 5433 |
5504 /* | 5434 /* |
5505 * Obtains an icon from a file. | 5435 * Obtains an icon from a file. |
5506 * Parameters: | 5436 * Parameters: |
5509 * (ICO on OS/2 or Windows, XPM on Unix) | 5439 * (ICO on OS/2 or Windows, XPM on Unix) |
5510 */ | 5440 */ |
5511 HICN API dw_icon_load_from_file(char *filename) | 5441 HICN API dw_icon_load_from_file(char *filename) |
5512 { | 5442 { |
5513 int _locked_by_me = FALSE; | 5443 int _locked_by_me = FALSE; |
5514 GdkPixbuf *pixbuf; | |
5515 char *file = alloca(strlen(filename) + 5); | 5444 char *file = alloca(strlen(filename) + 5); |
5516 int found_ext = 0; | 5445 int i, found_ext = 0; |
5517 int i, ret = 0; | 5446 HICN ret = 0; |
5518 | 5447 |
5519 if (!file) | 5448 if (!file) |
5520 return 0; | 5449 return 0; |
5521 | 5450 |
5522 strcpy(file, filename); | 5451 strcpy(file, filename); |
5540 return 0; | 5469 return 0; |
5541 } | 5470 } |
5542 } | 5471 } |
5543 | 5472 |
5544 DW_MUTEX_LOCK; | 5473 DW_MUTEX_LOCK; |
5545 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | 5474 ret = gdk_pixbuf_new_from_file(file, NULL); |
5546 if (pixbuf) | |
5547 { | |
5548 ret = _dw_icon_load_internal(pixbuf); | |
5549 } | |
5550 DW_MUTEX_UNLOCK; | 5475 DW_MUTEX_UNLOCK; |
5551 return ret; | 5476 return ret; |
5552 } | 5477 } |
5553 | 5478 |
5554 /* | 5479 /* |
5560 HICN API dw_icon_load_from_data(char *data, int len) | 5485 HICN API dw_icon_load_from_data(char *data, int len) |
5561 { | 5486 { |
5562 int _locked_by_me = FALSE; | 5487 int _locked_by_me = FALSE; |
5563 char *file; | 5488 char *file; |
5564 FILE *fp; | 5489 FILE *fp; |
5565 GdkPixbuf *pixbuf; | 5490 HICN ret = 0; |
5566 unsigned long ret = 0; | |
5567 | 5491 |
5568 /* | 5492 /* |
5569 * A real hack; create a temporary file and write the contents | 5493 * A real hack; create a temporary file and write the contents |
5570 * of the data to the file | 5494 * of the data to the file |
5571 */ | 5495 */ |
5579 else | 5503 else |
5580 { | 5504 { |
5581 return 0; | 5505 return 0; |
5582 } | 5506 } |
5583 DW_MUTEX_LOCK; | 5507 DW_MUTEX_LOCK; |
5584 pixbuf = gdk_pixbuf_new_from_file(file, NULL); | 5508 ret = gdk_pixbuf_new_from_file(file, NULL); |
5585 if (pixbuf) | |
5586 { | |
5587 ret = _dw_icon_load_internal(pixbuf); | |
5588 } | |
5589 DW_MUTEX_UNLOCK; | 5509 DW_MUTEX_UNLOCK; |
5590 return ret; | 5510 return ret; |
5591 } | 5511 } |
5592 | 5512 |
5593 /* | 5513 /* |
5595 * Parameters: | 5515 * Parameters: |
5596 * handle: Handle to icon returned by dw_icon_load(). | 5516 * handle: Handle to icon returned by dw_icon_load(). |
5597 */ | 5517 */ |
5598 void dw_icon_free(HICN handle) | 5518 void dw_icon_free(HICN handle) |
5599 { | 5519 { |
5600 /* If it is a private icon, find the item | 5520 int iicon = (int)handle; |
5601 * free the associated structures and set | 5521 |
5602 * the entry to unused. | 5522 if(iicon > 65535) |
5603 */ | 5523 { |
5604 if(handle & (1 << 31)) | 5524 g_object_unref(handle); |
5605 { | |
5606 unsigned long id = handle & 0xFFFFFF; | |
5607 | |
5608 if(id < _PixmapCount && _PixmapArray[id].used) | |
5609 { | |
5610 if(_PixmapArray[id].pixbuf) | |
5611 { | |
5612 g_object_unref(_PixmapArray[id].pixbuf); | |
5613 _PixmapArray[id].pixbuf = NULL; | |
5614 } | |
5615 _PixmapArray[id].used = 0; | |
5616 } | |
5617 } | 5525 } |
5618 } | 5526 } |
5619 | 5527 |
5620 /* | 5528 /* |
5621 * Allocates memory used to populate a container. | 5529 * Allocates memory used to populate a container. |
5687 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, row)) | 5595 if(gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store), &iter, NULL, row)) |
5688 { | 5596 { |
5689 if(flag & DW_CFA_STRINGANDICON) | 5597 if(flag & DW_CFA_STRINGANDICON) |
5690 { | 5598 { |
5691 void **thisdata = (void **)data; | 5599 void **thisdata = (void **)data; |
5692 long hicon = *((long *)thisdata[0]); | 5600 HICN hicon = *((HICN *)thisdata[0]); |
5693 char *tmp = (char *)thisdata[1]; | 5601 char *tmp = (char *)thisdata[1]; |
5694 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); | 5602 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); |
5695 | 5603 |
5696 if(pixbuf) | 5604 if(pixbuf) |
5697 gtk_list_store_set(store, &iter, 1, pixbuf, -1); | 5605 gtk_list_store_set(store, &iter, 1, pixbuf, -1); |
5698 | 5606 |
5699 gtk_list_store_set(store, &iter, 2, tmp, -1); | 5607 gtk_list_store_set(store, &iter, 2, tmp, -1); |
5700 } | 5608 } |
5701 else if(flag & DW_CFA_BITMAPORICON) | 5609 else if(flag & DW_CFA_BITMAPORICON) |
5702 { | 5610 { |
5703 long hicon = *((long *)data); | 5611 HICN hicon = *((HICN *)data); |
5704 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); | 5612 GdkPixbuf *pixbuf = _find_pixbuf(hicon, NULL, NULL); |
5705 | 5613 |
5706 if(pixbuf) | 5614 if(pixbuf) |
5707 gtk_list_store_set(store, &iter, column + 2, pixbuf, -1); | 5615 gtk_list_store_set(store, &iter, column + 2, pixbuf, -1); |
5708 } | 5616 } |
7085 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6993 if (!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
7086 return NULL; | 6994 return NULL; |
7087 | 6995 |
7088 | 6996 |
7089 DW_MUTEX_LOCK; | 6997 DW_MUTEX_LOCK; |
7090 pixmap->pixbuf = gdk_pixbuf_copy(_find_pixbuf(id, &pixmap->width, &pixmap->height)); | 6998 pixmap->pixbuf = gdk_pixbuf_copy(_find_pixbuf((HICN)id, &pixmap->width, &pixmap->height)); |
7091 DW_MUTEX_UNLOCK; | 6999 DW_MUTEX_UNLOCK; |
7092 return pixmap; | 7000 return pixmap; |
7093 } | 7001 } |
7094 | 7002 |
7095 /* Call this after drawing to the screen to make sure | 7003 /* Call this after drawing to the screen to make sure |