comparison gtk/dw.c @ 265:84471d53ab58

Changes to dw_main_* so that the _dw_thread is set to -1 when the message loop isn't running. Also changed dw_icon_load_from_file() to do more error checks and use unsigned long for returning.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 27 Feb 2003 06:09:06 +0000
parents 20becf7df38a
children bf8b907f8a29
comparison
equal deleted inserted replaced
264:20becf7df38a 265:84471d53ab58
836 /* 836 /*
837 * Runs a message loop for Dynamic Windows. 837 * Runs a message loop for Dynamic Windows.
838 */ 838 */
839 void dw_main(void) 839 void dw_main(void)
840 { 840 {
841 gdk_threads_enter();
841 _dw_thread = pthread_self(); 842 _dw_thread = pthread_self();
842 _dw_thread_add(_dw_thread); 843 _dw_thread_add(_dw_thread);
843 gdk_threads_enter();
844 gtk_main(); 844 gtk_main();
845 _dw_thread = (pthread_t)-1;
845 gdk_threads_leave(); 846 gdk_threads_leave();
846 } 847 }
847 848
848 /* 849 /*
849 * Runs a message loop for Dynamic Windows, for a period of milliseconds. 850 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
878 /* 879 /*
879 * Processes a single message iteration and returns. 880 * Processes a single message iteration and returns.
880 */ 881 */
881 void dw_main_iteration(void) 882 void dw_main_iteration(void)
882 { 883 {
884 gdk_threads_enter();
883 _dw_thread = pthread_self(); 885 _dw_thread = pthread_self();
884 _dw_thread_add(_dw_thread); 886 _dw_thread_add(_dw_thread);
885 gdk_threads_enter();
886 gtk_main_iteration(); 887 gtk_main_iteration();
888 _dw_thread = (pthread_t)-1;
887 gdk_threads_leave(); 889 gdk_threads_leave();
888 } 890 }
889 891
890 /* 892 /*
891 * Free's memory allocated by dynamic windows. 893 * Free's memory allocated by dynamic windows.
4150 * DW pick the appropriate file extension. 4152 * DW pick the appropriate file extension.
4151 * (ICO on OS/2 or Windows, XPM on Unix) 4153 * (ICO on OS/2 or Windows, XPM on Unix)
4152 */ 4154 */
4153 unsigned long API dw_icon_load_from_file(char *filename) 4155 unsigned long API dw_icon_load_from_file(char *filename)
4154 { 4156 {
4155 int z, found = -1, _locked_by_me = FALSE; 4157 int found = -1, _locked_by_me = FALSE;
4156 #if GTK_MAJOR_VERSION > 1 4158 #if GTK_MAJOR_VERSION > 1
4157 GdkPixbuf *pixbuf; 4159 GdkPixbuf *pixbuf;
4158 #elif defined(USE_IMLIB) 4160 #elif defined(USE_IMLIB)
4159 GdkImlibImage *image; 4161 GdkImlibImage *image;
4160 #endif 4162 #endif
4161 char *file = alloca(strlen(filename) + 5); 4163 char *file = alloca(strlen(filename) + 5);
4164 unsigned long z, ret = 0;
4162 4165
4163 if (!file) 4166 if (!file)
4164 return 0; 4167 return 0;
4165 4168
4166 strcpy(file, filename); 4169 strcpy(file, filename);
4178 /* Find a free entry in the array */ 4181 /* Find a free entry in the array */
4179 for(z=0;z<_PixmapCount;z++) 4182 for(z=0;z<_PixmapCount;z++)
4180 { 4183 {
4181 if(!_PixmapArray[z].used) 4184 if(!_PixmapArray[z].used)
4182 { 4185 {
4183 found = z; 4186 ret = found = z;
4184 break; 4187 break;
4185 } 4188 }
4186 } 4189 }
4187 4190
4188 /* If there are no free entries, expand the 4191 /* If there are no free entries, expand the
4190 */ 4193 */
4191 if(found == -1) 4194 if(found == -1)
4192 { 4195 {
4193 DWPrivatePixmap *old = _PixmapArray; 4196 DWPrivatePixmap *old = _PixmapArray;
4194 4197
4195 found = _PixmapCount; 4198 ret = found = _PixmapCount;
4196 _PixmapCount++; 4199 _PixmapCount++;
4197 4200
4198 _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount); 4201 _PixmapArray = malloc(sizeof(DWPrivatePixmap) * _PixmapCount);
4199 4202
4200 if(found) 4203 if(found)
4206 } 4209 }
4207 4210
4208 #if GTK_MAJOR_VERSION > 1 4211 #if GTK_MAJOR_VERSION > 1
4209 pixbuf = gdk_pixbuf_new_from_file(file, NULL); 4212 pixbuf = gdk_pixbuf_new_from_file(file, NULL);
4210 4213
4211 _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf); 4214 if(pixbuf)
4212 _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf); 4215 {
4213 4216 _PixmapArray[found].width = gdk_pixbuf_get_width(pixbuf);
4214 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &_PixmapArray[found].pixmap, &_PixmapArray[found].mask, 1); 4217 _PixmapArray[found].height = gdk_pixbuf_get_height(pixbuf);
4215 g_object_unref(pixbuf); 4218
4219 gdk_pixbuf_render_pixmap_and_mask(pixbuf, &_PixmapArray[found].pixmap, &_PixmapArray[found].mask, 1);
4220 g_object_unref(pixbuf);
4221 }
4216 #elif defined(USE_IMLIB) 4222 #elif defined(USE_IMLIB)
4217 image = gdk_imlib_load_image(file); 4223 image = gdk_imlib_load_image(file);
4218 4224
4219 _PixmapArray[found].width = image->rgb_width; 4225 if(image)
4220 _PixmapArray[found].height = image->rgb_height; 4226 {
4221 4227 _PixmapArray[found].width = image->rgb_width;
4222 gdk_imlib_render(image, image->rgb_width, image->rgb_height); 4228 _PixmapArray[found].height = image->rgb_height;
4223 _PixmapArray[found].pixmap = gdk_imlib_copy_image(image); 4229
4224 _PixmapArray[found].mask = gdk_imlib_copy_mask(image); 4230 gdk_imlib_render(image, image->rgb_width, image->rgb_height);
4225 gdk_imlib_destroy_image(image); 4231 _PixmapArray[found].pixmap = gdk_imlib_copy_image(image);
4232 _PixmapArray[found].mask = gdk_imlib_copy_mask(image);
4233 gdk_imlib_destroy_image(image);
4234 }
4226 #else 4235 #else
4227 _PixmapArray[found].pixmap = gdk_pixmap_create_from_xpm(handle->window, &_PixmapArray[found].mask, &_colors[DW_CLR_PALEGRAY], file); 4236 _PixmapArray[found].pixmap = gdk_pixmap_create_from_xpm(handle->window, &_PixmapArray[found].mask, &_colors[DW_CLR_PALEGRAY], file);
4228 #endif 4237 #endif
4229 DW_MUTEX_UNLOCK; 4238 DW_MUTEX_UNLOCK;
4230 return found | (1 << 31); 4239 if(!_PixmapArray[found].pixmap || !_PixmapArray[found].mask)
4240 {
4241 _PixmapArray[found].used = 0;
4242 _PixmapArray[found].pixmap = _PixmapArray[found].mask = NULL;
4243 return 0;
4244 }
4245 return ret | (1 << 31);
4231 } 4246 }
4232 4247
4233 /* 4248 /*
4234 * Frees a loaded resource in OS/2 and Windows. 4249 * Frees a loaded resource in OS/2 and Windows.
4235 * Parameters: 4250 * Parameters: