Mercurial > dwindows
comparison gtk/dw.c @ 1834:ca6ef85fffc5
Update dw_window_set_bitmap() to use pixbufs on GTK 2.x
instead of pixmap/bitmap pairs for better appearance using
images with alpha channels.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 01 Nov 2012 13:51:35 +0000 |
parents | b35e041fc114 |
children | ff80ad40a5d6 |
comparison
equal
deleted
inserted
replaced
1833:b35e041fc114 | 1834:ca6ef85fffc5 |
---|---|
1947 break; | 1947 break; |
1948 } | 1948 } |
1949 } | 1949 } |
1950 | 1950 |
1951 if(data) | 1951 if(data) |
1952 { | |
1953 if(data[0] == 'G' && data[1] == 'd' && data[2] == 'k' && data[3] == 'P') | |
1954 return gdk_pixbuf_new_from_inline(-1, (const guint8 *)data, FALSE, NULL); | |
1952 return gdk_pixbuf_new_from_xpm_data((const char **)data); | 1955 return gdk_pixbuf_new_from_xpm_data((const char **)data); |
1956 } | |
1953 return NULL; | 1957 return NULL; |
1954 } | 1958 } |
1955 #endif | 1959 #endif |
1956 | 1960 |
1957 #ifdef GDK_WINDOWING_X11 | 1961 #ifdef GDK_WINDOWING_X11 |
4647 | 4651 |
4648 if ( bitmap ) | 4652 if ( bitmap ) |
4649 { | 4653 { |
4650 dw_window_set_bitmap_from_data(bitmap, 0, data, len); | 4654 dw_window_set_bitmap_from_data(bitmap, 0, data, len); |
4651 gtk_container_add (GTK_CONTAINER(tmp), bitmap); | 4655 gtk_container_add (GTK_CONTAINER(tmp), bitmap); |
4652 g_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap); | 4656 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap); |
4653 } | 4657 } |
4654 gtk_widget_show(tmp); | 4658 gtk_widget_show(tmp); |
4655 _create_tooltip(tmp, text); | 4659 _create_tooltip(tmp, text); |
4656 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 4660 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
4657 DW_MUTEX_UNLOCK; | 4661 DW_MUTEX_UNLOCK; |
4881 * Windows and a pixmap on Unix, pass | 4885 * Windows and a pixmap on Unix, pass |
4882 * NULL if you use the id param) | 4886 * NULL if you use the id param) |
4883 */ | 4887 */ |
4884 void dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) | 4888 void dw_window_set_bitmap(HWND handle, unsigned long id, char *filename) |
4885 { | 4889 { |
4890 #if GTK_MAJOR_VERSION > 1 | |
4891 GdkPixbuf *pixbuf = NULL; | |
4892 #else | |
4886 GdkBitmap *bitmap = NULL; | 4893 GdkBitmap *bitmap = NULL; |
4887 GdkPixmap *tmp; | 4894 GdkPixmap *tmp = NULL; |
4895 #endif | |
4888 int found_ext = 0; | 4896 int found_ext = 0; |
4889 int i; | 4897 int i; |
4890 int _locked_by_me = FALSE; | 4898 int _locked_by_me = FALSE; |
4891 | 4899 |
4892 if(!id && !filename) | 4900 if(!id && !filename) |
4893 return; | 4901 return; |
4894 | 4902 |
4895 DW_MUTEX_LOCK; | 4903 DW_MUTEX_LOCK; |
4896 if(id) | 4904 if(id) |
4905 #if GTK_MAJOR_VERSION > 1 | |
4906 pixbuf = _find_pixbuf((HICN)id); | |
4907 #else | |
4897 tmp = _find_pixmap(&bitmap, (HICN)id, handle, NULL, NULL); | 4908 tmp = _find_pixmap(&bitmap, (HICN)id, handle, NULL, NULL); |
4909 #endif | |
4898 else | 4910 else |
4899 { | 4911 { |
4900 char *file = alloca(strlen(filename) + 6); | 4912 char *file = alloca(strlen(filename) + 6); |
4901 #if GTK_MAJOR_VERSION > 1 | 4913 #if defined(USE_IMLIB) |
4902 GdkPixbuf *pixbuf; | |
4903 #elif defined(USE_IMLIB) | |
4904 GdkImlibImage *image; | 4914 GdkImlibImage *image; |
4905 #endif | 4915 #endif |
4906 | 4916 |
4907 if (!file) | 4917 if (!file) |
4908 { | 4918 { |
4932 return; | 4942 return; |
4933 } | 4943 } |
4934 } | 4944 } |
4935 #if GTK_MAJOR_VERSION > 1 | 4945 #if GTK_MAJOR_VERSION > 1 |
4936 pixbuf = gdk_pixbuf_new_from_file(file, NULL ); | 4946 pixbuf = gdk_pixbuf_new_from_file(file, NULL ); |
4937 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &tmp, &bitmap, 1); | |
4938 g_object_unref(pixbuf); | |
4939 #elif defined(USE_IMLIB) | 4947 #elif defined(USE_IMLIB) |
4940 image = gdk_imlib_load_image(file); | 4948 image = gdk_imlib_load_image(file); |
4941 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | 4949 gdk_imlib_render(image, image->rgb_width, image->rgb_height); |
4942 tmp = gdk_imlib_copy_image(image); | 4950 tmp = gdk_imlib_copy_image(image); |
4943 bitmap = gdk_imlib_copy_mask(image); | 4951 bitmap = gdk_imlib_copy_mask(image); |
4945 #else | 4953 #else |
4946 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); | 4954 tmp = gdk_pixmap_create_from_xpm(handle->window, &bitmap, &_colors[DW_CLR_PALEGRAY], file); |
4947 #endif | 4955 #endif |
4948 } | 4956 } |
4949 | 4957 |
4958 #if GTK_MAJOR_VERSION > 1 | |
4959 if (pixbuf) | |
4960 #else | |
4950 if (tmp) | 4961 if (tmp) |
4962 #endif | |
4951 { | 4963 { |
4952 if ( GTK_IS_BUTTON(handle) ) | 4964 if ( GTK_IS_BUTTON(handle) ) |
4953 { | 4965 { |
4954 #if GTK_MAJOR_VERSION < 2 | 4966 #if GTK_MAJOR_VERSION > 1 |
4955 GtkWidget *pixmap = GTK_BUTTON(handle)->child; | |
4956 gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap); | |
4957 #else | |
4958 GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" ); | 4967 GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" ); |
4959 if(pixmap) | 4968 if(pixmap) |
4960 { | 4969 { |
4961 gtk_image_set_from_pixmap(GTK_IMAGE(pixmap), tmp, bitmap); | 4970 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), pixbuf); |
4962 } | 4971 } |
4972 #else | |
4973 GtkWidget *pixmap = GTK_BUTTON(handle)->child; | |
4974 gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap); | |
4963 #endif | 4975 #endif |
4964 } | 4976 } |
4965 else | 4977 else |
4966 { | 4978 { |
4967 #if GTK_MAJOR_VERSION > 1 | 4979 #if GTK_MAJOR_VERSION > 1 |
4968 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); | 4980 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), pixbuf); |
4969 #else | 4981 #else |
4970 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); | 4982 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); |
4971 #endif | 4983 #endif |
4972 } | 4984 } |
4973 } | 4985 } |
4986 #if GTK_MAJOR_VERSION > 1 | |
4987 if(pixbuf) | |
4988 g_object_unref(pixbuf); | |
4989 #endif | |
4974 DW_MUTEX_UNLOCK; | 4990 DW_MUTEX_UNLOCK; |
4975 } | 4991 } |
4976 | 4992 |
4977 /* | 4993 /* |
4978 * Sets the bitmap used for a given static window. | 4994 * Sets the bitmap used for a given static window. |
4985 * NULL if you use the id param) | 5001 * NULL if you use the id param) |
4986 * len: length of data | 5002 * len: length of data |
4987 */ | 5003 */ |
4988 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len) | 5004 void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, char *data, int len) |
4989 { | 5005 { |
5006 #if GTK_MAJOR_VERSION > 1 | |
5007 GdkPixbuf *pixbuf = NULL; | |
5008 #else | |
4990 GdkBitmap *bitmap = NULL; | 5009 GdkBitmap *bitmap = NULL; |
4991 GdkPixmap *tmp; | 5010 GdkPixmap *tmp = NULL; |
5011 #endif | |
4992 int _locked_by_me = FALSE; | 5012 int _locked_by_me = FALSE; |
4993 char *file; | 5013 char *file; |
4994 FILE *fp; | 5014 FILE *fp; |
4995 | 5015 |
4996 if (!id && !data) | 5016 if (!id && !data) |
4997 return; | 5017 return; |
4998 | 5018 |
4999 DW_MUTEX_LOCK; | 5019 DW_MUTEX_LOCK; |
5000 if(data) | 5020 if(data) |
5001 { | 5021 { |
5002 #if GTK_MAJOR_VERSION > 1 | 5022 #if defined(USE_IMLIB) |
5003 GdkPixbuf *pixbuf; | |
5004 #elif defined(USE_IMLIB) | |
5005 GdkImlibImage *image; | 5023 GdkImlibImage *image; |
5006 #endif | 5024 #endif |
5007 /* | 5025 /* |
5008 * A real hack; create a temporary file and write the contents | 5026 * A real hack; create a temporary file and write the contents |
5009 * of the data to the file | 5027 * of the data to the file |
5020 DW_MUTEX_UNLOCK; | 5038 DW_MUTEX_UNLOCK; |
5021 return; | 5039 return; |
5022 } | 5040 } |
5023 #if GTK_MAJOR_VERSION > 1 | 5041 #if GTK_MAJOR_VERSION > 1 |
5024 pixbuf = gdk_pixbuf_new_from_file(file, NULL ); | 5042 pixbuf = gdk_pixbuf_new_from_file(file, NULL ); |
5025 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &tmp, &bitmap, 1); | |
5026 g_object_unref(pixbuf); | |
5027 #elif defined(USE_IMLIB) | 5043 #elif defined(USE_IMLIB) |
5028 image = gdk_imlib_load_image(file); | 5044 image = gdk_imlib_load_image(file); |
5029 gdk_imlib_render(image, image->rgb_width, image->rgb_height); | 5045 gdk_imlib_render(image, image->rgb_width, image->rgb_height); |
5030 tmp = gdk_imlib_copy_image(image); | 5046 tmp = gdk_imlib_copy_image(image); |
5031 bitmap = gdk_imlib_copy_mask(image); | 5047 bitmap = gdk_imlib_copy_mask(image); |
5035 #endif | 5051 #endif |
5036 /* remove our temporary file */ | 5052 /* remove our temporary file */ |
5037 unlink (file ); | 5053 unlink (file ); |
5038 } | 5054 } |
5039 else if (id) | 5055 else if (id) |
5056 #if GTK_MAJOR_VERSION > 1 | |
5057 pixbuf = _find_pixbuf((HICN)id); | |
5058 #else | |
5040 tmp = _find_pixmap(&bitmap, (HICN)id, handle, NULL, NULL); | 5059 tmp = _find_pixmap(&bitmap, (HICN)id, handle, NULL, NULL); |
5041 | 5060 #endif |
5042 if(tmp) | 5061 |
5062 #if GTK_MAJOR_VERSION > 1 | |
5063 if (pixbuf) | |
5064 #else | |
5065 if (tmp) | |
5066 #endif | |
5043 { | 5067 { |
5044 if ( GTK_IS_BUTTON(handle) ) | 5068 if ( GTK_IS_BUTTON(handle) ) |
5045 { | 5069 { |
5046 #if GTK_MAJOR_VERSION < 2 | 5070 #if GTK_MAJOR_VERSION > 1 |
5047 GtkWidget *pixmap = GTK_BUTTON(handle)->child; | |
5048 gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap); | |
5049 #else | |
5050 GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" ); | 5071 GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" ); |
5051 if(pixmap) | 5072 if(pixmap) |
5052 { | 5073 { |
5053 gtk_image_set_from_pixmap(GTK_IMAGE(pixmap), tmp, bitmap); | 5074 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), pixbuf); |
5054 } | 5075 } |
5076 #else | |
5077 GtkWidget *pixmap = GTK_BUTTON(handle)->child; | |
5078 gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap); | |
5055 #endif | 5079 #endif |
5056 } | 5080 } |
5057 else | 5081 else |
5058 { | 5082 { |
5059 #if GTK_MAJOR_VERSION > 1 | 5083 #if GTK_MAJOR_VERSION > 1 |
5060 gtk_image_set_from_pixmap(GTK_IMAGE(handle), tmp, bitmap); | 5084 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), pixbuf); |
5061 #else | 5085 #else |
5062 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); | 5086 gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); |
5063 #endif | 5087 #endif |
5064 } | 5088 } |
5065 } | 5089 } |
5090 #if GTK_MAJOR_VERSION > 1 | |
5091 if(pixbuf) | |
5092 g_object_unref(pixbuf); | |
5093 #endif | |
5066 DW_MUTEX_UNLOCK; | 5094 DW_MUTEX_UNLOCK; |
5067 } | 5095 } |
5068 | 5096 |
5069 /* | 5097 /* |
5070 * Sets the text used for a given window. | 5098 * Sets the text used for a given window. |