Mercurial > dwindows
diff gtk/dw.c @ 2854:8a5131cbbe93
GTK2/3/4: Add return values to dw_window_set_bitmap(_from_data).
Also similar to the other platforms, no longer install XPMs to gtk/.
GTK4 is currently untested, if it doesn't work, may be a follow-up.
Also fix a GCC fortify warning with strncpy().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 15 Nov 2022 02:29:56 +0000 |
parents | ee1cfa7d645e |
children | 86286f528adf |
line wrap: on
line diff
--- a/gtk/dw.c Tue Nov 15 01:07:55 2022 +0000 +++ b/gtk/dw.c Tue Nov 15 02:29:56 2022 +0000 @@ -4609,7 +4609,7 @@ if(bitmap) { dw_window_set_bitmap(bitmap, id, NULL); - gtk_container_add (GTK_CONTAINER(tmp), bitmap); + gtk_container_add(GTK_CONTAINER(tmp), bitmap); gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap); } gtk_widget_show(tmp); @@ -4640,9 +4640,9 @@ tmp = gtk_button_new(); /* Now on to the image stuff */ bitmap = dw_bitmap_new(id); - if ( bitmap ) - { - dw_window_set_bitmap( bitmap, 0, filename ); + if(bitmap) + { + dw_window_set_bitmap(bitmap, 0, filename); gtk_container_add (GTK_CONTAINER(tmp), bitmap); gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap); } @@ -4674,10 +4674,10 @@ tmp = gtk_button_new(); bitmap = dw_bitmap_new(id); - if ( bitmap ) + if(bitmap) { dw_window_set_bitmap_from_data(bitmap, 0, data, len); - gtk_container_add (GTK_CONTAINER(tmp), bitmap); + gtk_container_add(GTK_CONTAINER(tmp), bitmap); gtk_object_set_data(GTK_OBJECT(tmp), "_dw_bitmap", bitmap); } gtk_widget_show(tmp); @@ -4909,8 +4909,12 @@ * filename: a path to a file (Bitmap on OS/2 or * Windows and a pixmap on Unix, pass * NULL if you use the id param) - */ -void dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) + * Returns: + * DW_ERROR_NONE on success. + * DW_ERROR_UNKNOWN if the parameters were invalid. + * DW_ERROR_GENERAL if the bitmap was unable to be loaded. + */ +int dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename) { #if GTK_MAJOR_VERSION > 1 GdkPixbuf *pixbuf = NULL; @@ -4918,12 +4922,12 @@ GdkBitmap *bitmap = NULL; GdkPixmap *tmp = NULL; #endif - int found_ext = 0; - int i; - int _dw_locked_by_me = FALSE; + int i, found_ext = 0; + int _dw_locked_by_me = FALSE; + int retval = DW_ERROR_UNKNOWN; if(!id && !filename) - return; + return retval; DW_MUTEX_LOCK; if(id) @@ -4939,36 +4943,36 @@ GdkImlibImage *image; #endif - if (!file) + if(!file) { DW_MUTEX_UNLOCK; - return; + return DW_ERROR_GENERAL; } strcpy(file, filename); /* check if we can read from this file (it exists and read permission) */ - if ( access(file, 04 ) != 0 ) + if(access(file, 04 ) != 0) { /* Try with various extentions */ - for ( i = 0; i < NUM_EXTS; i++ ) - { - strcpy( file, filename ); - strcat( file, _dw_image_exts[i] ); - if ( access( file, 04 ) == 0 ) + for(i = 0; i < NUM_EXTS; i++) + { + strcpy(file, filename); + strcat(file, _dw_image_exts[i]); + if(access( file, 04 ) == 0) { found_ext = 1; break; } } - if ( found_ext == 0 ) + if(found_ext == 0) { DW_MUTEX_UNLOCK; - return; - } - } -#if GTK_MAJOR_VERSION > 1 - pixbuf = gdk_pixbuf_new_from_file(file, NULL ); + return DW_ERROR_GENERAL; + } + } +#if GTK_MAJOR_VERSION > 1 + pixbuf = gdk_pixbuf_new_from_file(file, NULL); #elif defined(USE_IMLIB) image = gdk_imlib_load_image(file); gdk_imlib_render(image, image->rgb_width, image->rgb_height); @@ -4981,31 +4985,36 @@ } #if GTK_MAJOR_VERSION > 1 - if (pixbuf) -#else - if (tmp) -#endif - { - if ( GTK_IS_BUTTON(handle) ) - { -#if GTK_MAJOR_VERSION > 1 - GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" ); + if(pixbuf) +#else + if(tmp) +#endif + { + if(GTK_IS_BUTTON(handle)) + { +#if GTK_MAJOR_VERSION > 1 + GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data(GTK_OBJECT(handle), "_dw_bitmap"); if(pixmap) { gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), pixbuf); + retval = DW_ERROR_NONE; } #else GtkWidget *pixmap = GTK_BUTTON(handle)->child; gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap); -#endif - } - else - { -#if GTK_MAJOR_VERSION > 1 + retval = DW_ERROR_NONE; +#endif + } +#if GTK_MAJOR_VERSION > 1 + else if(GTK_IS_IMAGE(handle)) + { gtk_image_set_from_pixbuf(GTK_IMAGE(handle), pixbuf); #else + else if(GTK_IS_PIXMAP(handle)) + { gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); #endif + retval = DW_ERROR_NONE; } } #if GTK_MAJOR_VERSION > 1 @@ -5013,6 +5022,7 @@ g_object_unref(pixbuf); #endif DW_MUTEX_UNLOCK; + return retval; } /* @@ -5025,8 +5035,12 @@ * Bitmap on Windows and a pixmap on Unix, pass * NULL if you use the id param) * len: length of data - */ -void dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) + * Returns: + * DW_ERROR_NONE on success. + * DW_ERROR_UNKNOWN if the parameters were invalid. + * DW_ERROR_GENERAL if the bitmap was unable to be loaded. + */ +int dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len) { #if GTK_MAJOR_VERSION > 1 GdkPixbuf *pixbuf = NULL; @@ -5035,9 +5049,10 @@ GdkPixmap *tmp = NULL; #endif int _dw_locked_by_me = FALSE; + int retval = DW_ERROR_UNKNOWN; if(!id && !data) - return; + return retval; DW_MUTEX_LOCK; if(data) @@ -5061,7 +5076,7 @@ if(fd == -1 || written != len) { DW_MUTEX_UNLOCK; - return; + return DW_ERROR_GENERAL; } #if GTK_MAJOR_VERSION > 1 pixbuf = gdk_pixbuf_new_from_file(template, NULL); @@ -5077,7 +5092,7 @@ /* remove our temporary file */ unlink(template); } - else if (id) + else if(id) #if GTK_MAJOR_VERSION > 1 pixbuf = _dw_find_pixbuf((HICN)id); #else @@ -5085,31 +5100,36 @@ #endif #if GTK_MAJOR_VERSION > 1 - if (pixbuf) -#else - if (tmp) -#endif - { - if ( GTK_IS_BUTTON(handle) ) + if(pixbuf) +#else + if(tmp) +#endif + { + if(GTK_IS_BUTTON(handle)) { #if GTK_MAJOR_VERSION > 1 GtkWidget *pixmap = (GtkWidget *)gtk_object_get_data( GTK_OBJECT(handle), "_dw_bitmap" ); if(pixmap) { gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), pixbuf); + retval = DW_ERROR_NONE; } #else GtkWidget *pixmap = GTK_BUTTON(handle)->child; gtk_pixmap_set(GTK_PIXMAP(pixmap), tmp, bitmap); -#endif - } - else - { -#if GTK_MAJOR_VERSION > 1 + retval = DW_ERROR_NONE; +#endif + } +#if GTK_MAJOR_VERSION > 1 + else if(GTK_IS_IMAGE(handle)) + { gtk_image_set_from_pixbuf(GTK_IMAGE(handle), pixbuf); #else + else if(GTK_IS_PIXMAP(handle)) + { gtk_pixmap_set(GTK_PIXMAP(handle), tmp, bitmap); #endif + retval = DW_ERROR_NONE; } } #if GTK_MAJOR_VERSION > 1 @@ -5117,6 +5137,7 @@ g_object_unref(pixbuf); #endif DW_MUTEX_UNLOCK; + return retval; } /*