comparison gtk4/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 cd6a306800f5
children 86286f528adf
comparison
equal deleted inserted replaced
2853:c250764b2f32 2854:8a5131cbbe93
3923 * id: An ID to be used to specify the icon, 3923 * id: An ID to be used to specify the icon,
3924 * (pass 0 if you use the filename param) 3924 * (pass 0 if you use the filename param)
3925 * filename: a path to a file (Bitmap on OS/2 or 3925 * filename: a path to a file (Bitmap on OS/2 or
3926 * Windows and a pixmap on Unix, pass 3926 * Windows and a pixmap on Unix, pass
3927 * NULL if you use the id param) 3927 * NULL if you use the id param)
3928 */ 3928 * Returns:
3929 DW_FUNCTION_DEFINITION(dw_window_set_bitmap, void, HWND handle, unsigned long id, const char *filename) 3929 * DW_ERROR_NONE on success.
3930 * DW_ERROR_UNKNOWN if the parameters were invalid.
3931 * DW_ERROR_GENERAL if the bitmap was unable to be loaded.
3932 */
3933 DW_FUNCTION_DEFINITION(dw_window_set_bitmap, int, HWND handle, unsigned long id, const char *filename)
3930 DW_FUNCTION_ADD_PARAM3(handle, id, filename) 3934 DW_FUNCTION_ADD_PARAM3(handle, id, filename)
3931 DW_FUNCTION_NO_RETURN(dw_window_set_bitmap) 3935 DW_FUNCTION_RETURN(dw_window_set_bitmap, int)
3932 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, id, ULONG, filename, const char *) 3936 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, id, ULONG, filename, const char *)
3933 { 3937 {
3934 GdkPixbuf *tmp = NULL; 3938 GdkPixbuf *tmp = NULL;
3939 int retval = DW_ERROR_UNKNOWN;
3935 3940
3936 if(id) 3941 if(id)
3937 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); 3942 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL);
3938 else 3943 else
3939 { 3944 {
3964 { 3969 {
3965 if(GTK_IS_BUTTON(handle)) 3970 if(GTK_IS_BUTTON(handle))
3966 { 3971 {
3967 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); 3972 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap");
3968 if(pixmap) 3973 if(pixmap)
3974 {
3969 gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp); 3975 gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp);
3976 retval = DW_ERROR_NONE;
3977 }
3970 } 3978 }
3971 else if(GTK_IS_PICTURE(handle)) 3979 else if(GTK_IS_PICTURE(handle))
3980 {
3972 gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp); 3981 gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp);
3973 } 3982 retval = DW_ERROR_NONE;
3974 DW_FUNCTION_RETURN_NOTHING; 3983 }
3984 }
3985 else
3986 retval = DW_ERROR_GENERAL;
3987 DW_FUNCTION_RETURN_THIS(retval);
3975 } 3988 }
3976 3989
3977 /* 3990 /*
3978 * Sets the bitmap used for a given static window. 3991 * Sets the bitmap used for a given static window.
3979 * Parameters: 3992 * Parameters:
3982 * (pass 0 if you use the filename param) 3995 * (pass 0 if you use the filename param)
3983 * data: the image data 3996 * data: the image data
3984 * Bitmap on Windows and a pixmap on Unix, pass 3997 * Bitmap on Windows and a pixmap on Unix, pass
3985 * NULL if you use the id param) 3998 * NULL if you use the id param)
3986 * len: length of data 3999 * len: length of data
3987 */ 4000 * Returns:
3988 DW_FUNCTION_DEFINITION(dw_window_set_bitmap_from_data, void, HWND handle, unsigned long id, const char *data, int len) 4001 * DW_ERROR_NONE on success.
4002 * DW_ERROR_UNKNOWN if the parameters were invalid.
4003 * DW_ERROR_GENERAL if the bitmap was unable to be loaded.
4004 */
4005 DW_FUNCTION_DEFINITION(dw_window_set_bitmap_from_data, int, HWND handle, unsigned long id, const char *data, int len)
3989 DW_FUNCTION_ADD_PARAM4(handle, id, data, len) 4006 DW_FUNCTION_ADD_PARAM4(handle, id, data, len)
3990 DW_FUNCTION_NO_RETURN(dw_window_set_bitmap_from_data) 4007 DW_FUNCTION_RETURN(dw_window_set_bitmap_from_data, int)
3991 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, id, ULONG, data, const char *, len, int) 4008 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, id, ULONG, data, const char *, len, int)
3992 { 4009 {
3993 GdkPixbuf *tmp = NULL; 4010 GdkPixbuf *tmp = NULL;
4011 int retval = DW_ERROR_UNKNOWN;
3994 4012
3995 if(data) 4013 if(data)
3996 { 4014 {
3997 /* 4015 /*
3998 * A real hack; create a temporary file and write the contents 4016 * A real hack; create a temporary file and write the contents
4012 tmp = gdk_pixbuf_new_from_file(template, NULL); 4030 tmp = gdk_pixbuf_new_from_file(template, NULL);
4013 /* remove our temporary file */ 4031 /* remove our temporary file */
4014 unlink(template); 4032 unlink(template);
4015 } 4033 }
4016 } 4034 }
4017 else if (id) 4035 else if(id)
4018 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); 4036 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL);
4019 4037
4020 if(tmp) 4038 if(tmp)
4021 { 4039 {
4022 if(GTK_IS_BUTTON(handle)) 4040 if(GTK_IS_BUTTON(handle))
4023 { 4041 {
4024 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); 4042 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap");
4025 4043
4026 if(pixmap) 4044 if(pixmap)
4045 {
4027 gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp); 4046 gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp);
4047 retval = DW_ERROR_NONE;
4048 }
4028 } 4049 }
4029 else if(GTK_IS_PICTURE(handle)) 4050 else if(GTK_IS_PICTURE(handle))
4051 {
4030 gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp); 4052 gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp);
4031 } 4053 retval = DW_ERROR_NONE;
4032 DW_FUNCTION_RETURN_NOTHING; 4054 }
4055 }
4056 else
4057 retval = DW_ERROR_GENERAL;
4058 DW_FUNCTION_RETURN_THIS(retval);
4033 } 4059 }
4034 4060
4035 /* 4061 /*
4036 * Sets the text used for a given window. 4062 * Sets the text used for a given window.
4037 * Parameters: 4063 * Parameters: