Mercurial > dwindows
comparison gtk4/dw.c @ 2366:b3efaae95735
GTK4: Apparenlty on GTK4 GtkImage is used for icons, switch to GtkPicture.
GtkPicture has an option to allow it to shrink, so we can eliminate the code
to shrink the pixbufs on GtkImages used in GTK3.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 14 Mar 2021 00:12:04 +0000 |
parents | 77686ad495ba |
children | 0f340646a2ca |
comparison
equal
deleted
inserted
replaced
2365:77686ad495ba | 2366:b3efaae95735 |
---|---|
2638 DW_FUNCTION_DEFINITION(dw_bitmap_new, HWND, ULONG cid) | 2638 DW_FUNCTION_DEFINITION(dw_bitmap_new, HWND, ULONG cid) |
2639 DW_FUNCTION_ADD_PARAM1(cid) | 2639 DW_FUNCTION_ADD_PARAM1(cid) |
2640 DW_FUNCTION_RETURN(dw_bitmap_new, HWND) | 2640 DW_FUNCTION_RETURN(dw_bitmap_new, HWND) |
2641 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) | 2641 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) |
2642 { | 2642 { |
2643 GtkWidget *tmp = gtk_image_new(); | 2643 GtkWidget *tmp = gtk_picture_new(); |
2644 gtk_picture_set_can_shrink(GTK_PICTURE(tmp), TRUE); | |
2644 gtk_widget_show(tmp); | 2645 gtk_widget_show(tmp); |
2645 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(cid)); | 2646 g_object_set_data(G_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(cid)); |
2646 DW_FUNCTION_RETURN_THIS(tmp); | 2647 DW_FUNCTION_RETURN_THIS(tmp); |
2647 } | 2648 } |
2648 | 2649 |
3858 { | 3859 { |
3859 if(GTK_IS_BUTTON(handle)) | 3860 if(GTK_IS_BUTTON(handle)) |
3860 { | 3861 { |
3861 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); | 3862 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); |
3862 if(pixmap) | 3863 if(pixmap) |
3863 { | 3864 gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp); |
3864 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); | 3865 } |
3865 g_object_set_data(G_OBJECT(pixmap), "_dw_pixbuf", tmp); | 3866 else if(GTK_IS_PICTURE(handle)) |
3866 } | 3867 gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp); |
3867 } | |
3868 else | |
3869 { | |
3870 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); | |
3871 g_object_set_data(G_OBJECT(handle), "_dw_pixbuf", tmp); | |
3872 } | |
3873 } | 3868 } |
3874 DW_FUNCTION_RETURN_NOTHING; | 3869 DW_FUNCTION_RETURN_NOTHING; |
3875 } | 3870 } |
3876 | 3871 |
3877 /* | 3872 /* |
3922 if(GTK_IS_BUTTON(handle)) | 3917 if(GTK_IS_BUTTON(handle)) |
3923 { | 3918 { |
3924 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); | 3919 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); |
3925 | 3920 |
3926 if(pixmap) | 3921 if(pixmap) |
3927 { | 3922 gtk_picture_set_pixbuf(GTK_PICTURE(pixmap), tmp); |
3928 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); | 3923 } |
3929 g_object_set_data(G_OBJECT(pixmap), "_dw_pixbuf", tmp); | 3924 else if(GTK_IS_PICTURE(handle)) |
3930 } | 3925 gtk_picture_set_pixbuf(GTK_PICTURE(handle), tmp); |
3931 } | |
3932 else | |
3933 { | |
3934 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); | |
3935 g_object_set_data(G_OBJECT(handle), "_dw_pixbuf", tmp); | |
3936 } | |
3937 } | 3926 } |
3938 DW_FUNCTION_RETURN_NOTHING; | 3927 DW_FUNCTION_RETURN_NOTHING; |
3939 } | 3928 } |
3940 | 3929 |
3941 /* | 3930 /* |
8212 } | 8201 } |
8213 | 8202 |
8214 /* Internal box packing function called by the other 3 functions */ | 8203 /* Internal box packing function called by the other 3 functions */ |
8215 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) | 8204 void _dw_box_pack(HWND box, HWND item, int index, int width, int height, int hsize, int vsize, int pad, char *funcname) |
8216 { | 8205 { |
8217 GtkWidget *tmp, *tmpitem, *image = NULL; | 8206 GtkWidget *tmp, *tmpitem; |
8218 | 8207 |
8219 if(!box) | 8208 if(!box) |
8220 return; | 8209 return; |
8221 | 8210 |
8222 /* | 8211 /* |
8239 if(!item) | 8228 if(!item) |
8240 { | 8229 { |
8241 item = gtk_label_new(""); | 8230 item = gtk_label_new(""); |
8242 g_object_set_data(G_OBJECT(item), "_dw_padding", GINT_TO_POINTER(1)); | 8231 g_object_set_data(G_OBJECT(item), "_dw_padding", GINT_TO_POINTER(1)); |
8243 gtk_widget_show(item); | 8232 gtk_widget_show(item); |
8244 } | |
8245 /* Due to GTK3 minimum size limitations, if we are packing a widget | |
8246 * with an image, we need to scale the image down to fit the packed size. | |
8247 */ | |
8248 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) | |
8249 { | |
8250 GdkPixbuf *pixbuf = g_object_get_data(G_OBJECT(image), "_dw_pixbuf"); | |
8251 | |
8252 if(pixbuf) | |
8253 { | |
8254 int pwidth = gdk_pixbuf_get_width(pixbuf); | |
8255 int pheight = gdk_pixbuf_get_height(pixbuf); | |
8256 | |
8257 if(width == -1) | |
8258 width = pwidth; | |
8259 if(height == -1) | |
8260 height = pheight; | |
8261 | |
8262 if(pwidth > width || pheight > height) | |
8263 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); | |
8264 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); | |
8265 g_object_set_data(G_OBJECT(image), "_dw_pixbuf", pixbuf); | |
8266 } | |
8267 } | 8233 } |
8268 | 8234 |
8269 /* Check if the item to be packed is a special box */ | 8235 /* Check if the item to be packed is a special box */ |
8270 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); | 8236 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); |
8271 | 8237 |