# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1668479396 0 # Node ID 8a5131cbbe9320ab8e7f39d7390df4a09a1fe45f # Parent c250764b2f32836a9ce1b5893037e96276fad354 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(). diff -r c250764b2f32 -r 8a5131cbbe93 Makefile.in --- a/Makefile.in Tue Nov 15 01:07:55 2022 +0000 +++ b/Makefile.in Tue Nov 15 02:29:56 2022 +0000 @@ -107,12 +107,12 @@ installdwtest: dwtest $(INSTALL) -d $(prefix)/bin; \ $(INSTALL) -d $(prefix)/share/applications; \ - $(INSTALL) -d $(prefix)/share/dwtest/gtk; \ + $(INSTALL) -d $(prefix)/share/dwtest; \ $(INSTALL) dwtest $(prefix)/bin; \ $(INSTALL) org.dbsoft.dwindows.dwtest.desktop $(prefix)/share/applications/; \ - $(INSTALL) image/test.png $(prefix)/share/dwtest/; \ - $(INSTALL) gtk/file.xpm $(prefix)/share/dwtest/gtk; \ - $(INSTALL) gtk/folder.xpm $(prefix)/share/dwtest/gtk + $(INSTALL) image/test.png $(prefix)/share/dwtest; \ + $(INSTALL) gtk/file.xpm $(prefix)/share/dwtest; \ + $(INSTALL) gtk/folder.xpm $(prefix)/share/dwtest installdwcompat: $(SYSCONF_LINK_TARGET2) $(INSTALL) -d $(prefix)/lib; \ @@ -140,8 +140,8 @@ rm -f $(prefix)/share/applications/org.dbsoft.dwindows.dwtest.desktop rm -f $(prefix)/share/man/man1/dwindows-config.1.gz rm -f $(prefix)/share/dwtest/test.png - rm -f $(prefix)/share/dwtest/gtk/file.xpm - rm -f $(prefix)/share/dwtest/gtk/folder.xpm + rm -f $(prefix)/share/dwtest/file.xpm + rm -f $(prefix)/share/dwtest/folder.xpm deb: dist -rm -fr tmp diff -r c250764b2f32 -r 8a5131cbbe93 dwtest.c --- a/dwtest.c Tue Nov 15 01:07:55 2022 +0000 +++ b/dwtest.c Tue Nov 15 02:29:56 2022 +0000 @@ -2250,11 +2250,11 @@ strncpy(&pathbuff[pos], "folder", 1024-pos); foldericon = dw_icon_load_from_file(pathbuff); if(foldericon) - strncpy(foldericonpath, pathbuff, 1024); + strncpy(foldericonpath, pathbuff, 1025); strncpy(&pathbuff[pos], "file", 1024-pos); fileicon = dw_icon_load_from_file(pathbuff); if(fileicon) - strncpy(fileiconpath, pathbuff, 1024); + strncpy(fileiconpath, pathbuff, 1025); } notebook = dw_notebook_new(1, TRUE); diff -r c250764b2f32 -r 8a5131cbbe93 gtk/dw.c --- 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; } /* diff -r c250764b2f32 -r 8a5131cbbe93 gtk3/dw.c --- a/gtk3/dw.c Tue Nov 15 01:07:55 2022 +0000 +++ b/gtk3/dw.c Tue Nov 15 02:29:56 2022 +0000 @@ -4262,8 +4262,8 @@ bitmap = dw_bitmap_new(id); if(bitmap) { - dw_window_set_bitmap( bitmap, 0, filename ); - gtk_container_add (GTK_CONTAINER(tmp), bitmap); + dw_window_set_bitmap(bitmap, 0, filename); + gtk_container_add(GTK_CONTAINER(tmp), bitmap); g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); } gtk_widget_show(tmp); @@ -4298,7 +4298,7 @@ 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); g_object_set_data(G_OBJECT(tmp), "_dw_bitmap", bitmap); } gtk_widget_show(tmp); @@ -4549,16 +4549,20 @@ * 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) { GdkPixbuf *tmp = NULL; - 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) @@ -4567,53 +4571,56 @@ { char *file = alloca(strlen(filename) + 6); - 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; - } - } - tmp = gdk_pixbuf_new_from_file(file, NULL ); - } - - if (tmp) - { - if ( GTK_IS_BUTTON(handle) ) - { - GtkWidget *pixmap = (GtkWidget *)g_object_get_data( G_OBJECT(handle), "_dw_bitmap" ); + return DW_ERROR_GENERAL; + } + } + tmp = gdk_pixbuf_new_from_file(file, NULL); + } + + if(tmp) + { + if(GTK_IS_BUTTON(handle)) + { + GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); if(pixmap) { gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); - } - } - else + retval = DW_ERROR_NONE; + } + } + else if(GTK_IS_IMAGE(handle)) { gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); - } - } - DW_MUTEX_UNLOCK; + retval = DW_ERROR_NONE; + } + } + DW_MUTEX_UNLOCK; + return retval; } /* @@ -4626,14 +4633,19 @@ * 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) { GdkPixbuf *tmp = NULL; int _dw_locked_by_me = FALSE; + int retval = DW_ERROR_UNKNOWN; if(!id && !data) - return; + return retval; DW_MUTEX_LOCK; if(data) @@ -4654,7 +4666,7 @@ if(fd == -1 || written != len) { DW_MUTEX_UNLOCK; - return; + return DW_ERROR_GENERAL; } tmp = gdk_pixbuf_new_from_file(template, NULL); @@ -4671,12 +4683,19 @@ GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); if(pixmap) + { gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); - } - else + retval = DW_ERROR_NONE; + } + } + else if(GTK_IS_IMAGE(handle)) + { gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); - } - DW_MUTEX_UNLOCK; + retval = DW_ERROR_NONE; + } + } + DW_MUTEX_UNLOCK; + return retval; } /* diff -r c250764b2f32 -r 8a5131cbbe93 gtk4/dw.c --- a/gtk4/dw.c Tue Nov 15 01:07:55 2022 +0000 +++ b/gtk4/dw.c Tue Nov 15 02:29:56 2022 +0000 @@ -3925,13 +3925,18 @@ * 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) - */ -DW_FUNCTION_DEFINITION(dw_window_set_bitmap, void, 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. + */ +DW_FUNCTION_DEFINITION(dw_window_set_bitmap, int, HWND handle, unsigned long id, const char *filename) DW_FUNCTION_ADD_PARAM3(handle, id, filename) -DW_FUNCTION_NO_RETURN(dw_window_set_bitmap) +DW_FUNCTION_RETURN(dw_window_set_bitmap, int) DW_FUNCTION_RESTORE_PARAM3(handle, HWND, id, ULONG, filename, const char *) { GdkPixbuf *tmp = NULL; + int retval = DW_ERROR_UNKNOWN; if(id) tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); @@ -3966,12 +3971,20 @@ { GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); if(pixmap) + { gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp); + retval = DW_ERROR_NONE; + } } else if(GTK_IS_PICTURE(handle)) + { gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp); - } - DW_FUNCTION_RETURN_NOTHING; + retval = DW_ERROR_NONE; + } + } + else + retval = DW_ERROR_GENERAL; + DW_FUNCTION_RETURN_THIS(retval); } /* @@ -3984,13 +3997,18 @@ * Bitmap on Windows and a pixmap on Unix, pass * NULL if you use the id param) * len: length of data - */ -DW_FUNCTION_DEFINITION(dw_window_set_bitmap_from_data, void, 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. + */ +DW_FUNCTION_DEFINITION(dw_window_set_bitmap_from_data, int, HWND handle, unsigned long id, const char *data, int len) DW_FUNCTION_ADD_PARAM4(handle, id, data, len) -DW_FUNCTION_NO_RETURN(dw_window_set_bitmap_from_data) +DW_FUNCTION_RETURN(dw_window_set_bitmap_from_data, int) DW_FUNCTION_RESTORE_PARAM4(handle, HWND, id, ULONG, data, const char *, len, int) { GdkPixbuf *tmp = NULL; + int retval = DW_ERROR_UNKNOWN; if(data) { @@ -4014,7 +4032,7 @@ unlink(template); } } - else if (id) + else if(id) tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); if(tmp) @@ -4024,12 +4042,20 @@ GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); if(pixmap) + { gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp); + retval = DW_ERROR_NONE; + } } else if(GTK_IS_PICTURE(handle)) + { gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp); - } - DW_FUNCTION_RETURN_NOTHING; + retval = DW_ERROR_NONE; + } + } + else + retval = DW_ERROR_GENERAL; + DW_FUNCTION_RETURN_THIS(retval); } /*