Mercurial > dwindows
comparison gtk4/dw.c @ 2282:b045bb67922d
GTK4: Implement resizing of images in the layout manager.
Make dw_window_set_style() partially work on menus.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 03 Feb 2021 08:35:06 +0000 |
parents | 0e93b09ed0e1 |
children | 3361ce6070ce |
comparison
equal
deleted
inserted
replaced
2281:0e93b09ed0e1 | 2282:b045bb67922d |
---|---|
3078 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); | 3078 tmp = _dw_find_pixbuf((HICN)id, NULL, NULL); |
3079 else | 3079 else |
3080 { | 3080 { |
3081 char *file = alloca(strlen(filename) + 6); | 3081 char *file = alloca(strlen(filename) + 6); |
3082 | 3082 |
3083 if (!file) | 3083 if(!file) |
3084 return; | 3084 return; |
3085 | 3085 |
3086 strcpy(file, filename); | 3086 strcpy(file, filename); |
3087 | 3087 |
3088 /* check if we can read from this file (it exists and read permission) */ | 3088 /* check if we can read from this file (it exists and read permission) */ |
3089 if ( access(file, 04 ) != 0 ) | 3089 if(access(file, 04) != 0) |
3090 { | 3090 { |
3091 /* Try with various extentions */ | 3091 /* Try with various extentions */ |
3092 for ( i = 0; i < NUM_EXTS; i++ ) | 3092 for(i=0; i<NUM_EXTS; i++) |
3093 { | 3093 { |
3094 strcpy( file, filename ); | 3094 strcpy(file, filename); |
3095 strcat( file, image_exts[i] ); | 3095 strcat(file, image_exts[i]); |
3096 if ( access( file, 04 ) == 0 ) | 3096 if(access(file, 04) == 0) |
3097 { | 3097 { |
3098 found_ext = 1; | 3098 found_ext = 1; |
3099 break; | 3099 break; |
3100 } | 3100 } |
3101 } | 3101 } |
3102 if ( found_ext == 0 ) | 3102 if(found_ext == 0) |
3103 return; | 3103 return; |
3104 } | 3104 } |
3105 tmp = gdk_pixbuf_new_from_file(file, NULL ); | 3105 tmp = gdk_pixbuf_new_from_file(file, NULL); |
3106 } | 3106 } |
3107 | 3107 |
3108 if (tmp) | 3108 if(tmp) |
3109 { | 3109 { |
3110 if ( GTK_IS_BUTTON(handle) ) | 3110 if(GTK_IS_BUTTON(handle)) |
3111 { | 3111 { |
3112 GtkWidget *pixmap = (GtkWidget *)g_object_get_data( G_OBJECT(handle), "_dw_bitmap" ); | 3112 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); |
3113 if(pixmap) | 3113 if(pixmap) |
3114 { | 3114 { |
3115 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); | 3115 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); |
3116 g_object_set_data(G_OBJECT(pixmap), "_dw_pixbuf", tmp); | |
3116 } | 3117 } |
3117 } | 3118 } |
3118 else | 3119 else |
3119 { | 3120 { |
3120 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); | 3121 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); |
3122 g_object_set_data(G_OBJECT(handle), "_dw_pixbuf", tmp); | |
3121 } | 3123 } |
3122 } | 3124 } |
3123 } | 3125 } |
3124 | 3126 |
3125 /* | 3127 /* |
3170 if(GTK_IS_BUTTON(handle)) | 3172 if(GTK_IS_BUTTON(handle)) |
3171 { | 3173 { |
3172 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); | 3174 GtkWidget *pixmap = (GtkWidget *)g_object_get_data(G_OBJECT(handle), "_dw_bitmap"); |
3173 | 3175 |
3174 if(pixmap) | 3176 if(pixmap) |
3177 { | |
3175 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); | 3178 gtk_image_set_from_pixbuf(GTK_IMAGE(pixmap), tmp); |
3179 g_object_set_data(G_OBJECT(pixmap), "_dw_pixbuf", tmp); | |
3180 } | |
3176 } | 3181 } |
3177 else | 3182 else |
3183 { | |
3178 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); | 3184 gtk_image_set_from_pixbuf(GTK_IMAGE(handle), tmp); |
3185 g_object_set_data(G_OBJECT(handle), "_dw_pixbuf", tmp); | |
3186 } | |
3179 } | 3187 } |
3180 } | 3188 } |
3181 | 3189 |
3182 /* | 3190 /* |
3183 * Sets the text used for a given window. | 3191 * Sets the text used for a given window. |
7212 /* Due to GTK3 minimum size limitations, if we are packing a widget | 7220 /* Due to GTK3 minimum size limitations, if we are packing a widget |
7213 * with an image, we need to scale the image down to fit the packed size. | 7221 * with an image, we need to scale the image down to fit the packed size. |
7214 */ | 7222 */ |
7215 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) | 7223 else if((image = g_object_get_data(G_OBJECT(item), "_dw_bitmap"))) |
7216 { | 7224 { |
7217 /* TODO: Figure out how to do this in GTK4 since gtk_image_get_pixbif() is gone... | 7225 GdkPixbuf *pixbuf = g_object_get_data(G_OBJECT(image), "_dw_pixbuf"); |
7218 * Might need to save the pixbuf in the window data manually. | |
7219 */ | |
7220 #if GTK3 | |
7221 GdkPixbuf *pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(image)); | |
7222 | 7226 |
7223 if(pixbuf) | 7227 if(pixbuf) |
7224 { | 7228 { |
7225 int pwidth = gdk_pixbuf_get_width(pixbuf); | 7229 int pwidth = gdk_pixbuf_get_width(pixbuf); |
7226 int pheight = gdk_pixbuf_get_height(pixbuf); | 7230 int pheight = gdk_pixbuf_get_height(pixbuf); |
7231 height = pheight; | 7235 height = pheight; |
7232 | 7236 |
7233 if(pwidth > width || pheight > height) | 7237 if(pwidth > width || pheight > height) |
7234 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); | 7238 pixbuf = gdk_pixbuf_scale_simple(pixbuf, pwidth > width ? width : pwidth, pheight > height ? height : pheight, GDK_INTERP_BILINEAR); |
7235 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); | 7239 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); |
7236 } | 7240 g_object_set_data(G_OBJECT(image), "_dw_pixbuf", pixbuf); |
7237 #endif | 7241 } |
7238 } | 7242 } |
7239 | 7243 |
7240 /* Check if the item to be packed is a special box */ | 7244 /* Check if the item to be packed is a special box */ |
7241 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); | 7245 tmpitem = (GtkWidget *)g_object_get_data(G_OBJECT(item), "_dw_boxhandle"); |
7242 | 7246 |
7738 gtk_label_set_xalign(GTK_LABEL(handle2), x); | 7742 gtk_label_set_xalign(GTK_LABEL(handle2), x); |
7739 gtk_label_set_yalign(GTK_LABEL(handle2), y); | 7743 gtk_label_set_yalign(GTK_LABEL(handle2), y); |
7740 if(style & DW_DT_WORDBREAK) | 7744 if(style & DW_DT_WORDBREAK) |
7741 gtk_label_set_wrap(GTK_LABEL(handle), TRUE); | 7745 gtk_label_set_wrap(GTK_LABEL(handle), TRUE); |
7742 } | 7746 } |
7747 if(G_IS_MENU_ITEM(handle2) && (mask & (DW_MIS_ENABLED | DW_MIS_DISABLED))) | |
7748 { | |
7749 GSimpleAction *action = g_object_get_data(G_OBJECT(handle2), "_dw_action"); | |
7750 | |
7751 if((style & DW_MIS_ENABLED) || (style & DW_MIS_DISABLED)) | |
7752 { | |
7753 if(style & DW_MIS_ENABLED) | |
7754 g_simple_action_set_enabled(action, TRUE); | |
7755 else | |
7756 g_simple_action_set_enabled(action, FALSE); | |
7757 } | |
7758 } | |
7743 /* TODO: Convert to GMenuModel */ | 7759 /* TODO: Convert to GMenuModel */ |
7744 #if GTK3 | 7760 #if GTK3 |
7745 if(GTK_IS_CHECK_MENU_ITEM(handle2) && (mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED)) | 7761 if(GTK_IS_CHECK_MENU_ITEM(handle2) && (mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED)) |
7746 { | 7762 { |
7747 int check = 0; | 7763 int check = 0; |
7750 check = 1; | 7766 check = 1; |
7751 | 7767 |
7752 _dw_ignore_click = 1; | 7768 _dw_ignore_click = 1; |
7753 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(handle2)) != check) | 7769 if(gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(handle2)) != check) |
7754 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(handle2), check); | 7770 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(handle2), check); |
7755 _dw_ignore_click = 0; | |
7756 } | |
7757 if((GTK_IS_CHECK_MENU_ITEM(handle2) || GTK_IS_MENU_ITEM(handle2)) && (mask & (DW_MIS_ENABLED | DW_MIS_DISABLED))) | |
7758 { | |
7759 _dw_ignore_click = 1; | |
7760 if ( style & DW_MIS_ENABLED ) | |
7761 gtk_widget_set_sensitive(handle2, TRUE); | |
7762 else | |
7763 gtk_widget_set_sensitive(handle2, FALSE); | |
7764 _dw_ignore_click = 0; | 7771 _dw_ignore_click = 0; |
7765 } | 7772 } |
7766 #endif | 7773 #endif |
7767 } | 7774 } |
7768 | 7775 |