Mercurial > emacs
comparison src/gtkutil.c @ 83849:b1cecfd7014f
(update_frame_tool_bar): Handle stock name as a named icon
if it starts with "n:".
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Sun, 02 Sep 2007 16:47:18 +0000 |
parents | 33f2ff3dc08b |
children | d514db1d656b |
comparison
equal
deleted
inserted
replaced
83848:465c19a81b24 | 83849:b1cecfd7014f |
---|---|
3343 | 3343 |
3344 /* The key for the data we put in the GtkImage widgets. The data is | 3344 /* The key for the data we put in the GtkImage widgets. The data is |
3345 the stock name used by Emacs. We use this to see if we need to update | 3345 the stock name used by Emacs. We use this to see if we need to update |
3346 the GtkImage with a new image. */ | 3346 the GtkImage with a new image. */ |
3347 #define XG_TOOL_BAR_STOCK_NAME "emacs-tool-bar-stock-name" | 3347 #define XG_TOOL_BAR_STOCK_NAME "emacs-tool-bar-stock-name" |
3348 | |
3349 /* As above, but this is used for named theme widgets, as opposed to | |
3350 stock items. */ | |
3351 #define XG_TOOL_BAR_ICON_NAME "emacs-tool-bar-icon-name" | |
3348 | 3352 |
3349 /* Callback function invoked when a tool bar item is pressed. | 3353 /* Callback function invoked when a tool bar item is pressed. |
3350 W is the button widget in the tool bar that got pressed, | 3354 W is the button widget in the tool bar that got pressed, |
3351 CLIENT_DATA is an integer that is the index of the button in the | 3355 CLIENT_DATA is an integer that is the index of the button in the |
3352 tool bar. 0 is the first button. */ | 3356 tool bar. 0 is the first button. */ |
3807 struct image *img = NULL; | 3811 struct image *img = NULL; |
3808 Lisp_Object image; | 3812 Lisp_Object image; |
3809 Lisp_Object stock; | 3813 Lisp_Object stock; |
3810 GtkStockItem stock_item; | 3814 GtkStockItem stock_item; |
3811 char *stock_name = NULL; | 3815 char *stock_name = NULL; |
3816 char *icon_name = NULL; | |
3812 Lisp_Object rtl; | 3817 Lisp_Object rtl; |
3813 GtkWidget *wbutton = NULL; | 3818 GtkWidget *wbutton = NULL; |
3814 GtkWidget *weventbox; | 3819 GtkWidget *weventbox; |
3815 Lisp_Object func = intern ("x-gtk-map-stock"); | 3820 Lisp_Object func = intern ("x-gtk-map-stock"); |
3816 | 3821 |
3832 } | 3837 } |
3833 | 3838 |
3834 if (EQ (Qt, Ffboundp (func))) | 3839 if (EQ (Qt, Ffboundp (func))) |
3835 stock = call1 (func, file_for_image (image)); | 3840 stock = call1 (func, file_for_image (image)); |
3836 | 3841 |
3837 if (! NILP (stock) && STRINGP (stock) | 3842 if (! NILP (stock) && STRINGP (stock)) |
3838 && gtk_stock_lookup (SSDATA (stock), &stock_item)) | |
3839 { | 3843 { |
3840 stock_name = SSDATA (stock); | 3844 stock_name = SSDATA (stock); |
3841 icon_size = gtk_toolbar_get_icon_size (wtoolbar); | 3845 if (stock_name[0] == 'n' && stock_name[1] == ':') |
3846 { | |
3847 GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (wtoolbar)); | |
3848 GtkIconTheme *icon_theme = gtk_icon_theme_get_for_screen (screen); | |
3849 | |
3850 icon_name = stock_name + 2; | |
3851 stock_name = NULL; | |
3852 stock = Qnil; | |
3853 | |
3854 if (! gtk_icon_theme_has_icon (icon_theme, icon_name)) | |
3855 icon_name = NULL; | |
3856 else | |
3857 icon_size = gtk_toolbar_get_icon_size (wtoolbar); | |
3858 } | |
3859 else if (gtk_stock_lookup (SSDATA (stock), &stock_item)) | |
3860 icon_size = gtk_toolbar_get_icon_size (wtoolbar); | |
3861 else | |
3862 { | |
3863 stock = Qnil; | |
3864 stock_name = NULL; | |
3865 } | |
3842 } | 3866 } |
3843 else | 3867 |
3868 if (stock_name == NULL && icon_name == NULL) | |
3844 { | 3869 { |
3845 /* No stock image, or stock item not known. Try regular image. */ | 3870 /* No stock image, or stock item not known. Try regular image. */ |
3846 | 3871 |
3847 /* If image is a vector, choose the image according to the | 3872 /* If image is a vector, choose the image according to the |
3848 button state. */ | 3873 button state. */ |
3903 w = gtk_image_new_from_stock (stock_name, icon_size); | 3928 w = gtk_image_new_from_stock (stock_name, icon_size); |
3904 g_object_set_data_full (G_OBJECT (w), XG_TOOL_BAR_STOCK_NAME, | 3929 g_object_set_data_full (G_OBJECT (w), XG_TOOL_BAR_STOCK_NAME, |
3905 (gpointer) xstrdup (stock_name), | 3930 (gpointer) xstrdup (stock_name), |
3906 (GDestroyNotify) xfree); | 3931 (GDestroyNotify) xfree); |
3907 } | 3932 } |
3933 else if (icon_name) | |
3934 { | |
3935 w = gtk_image_new_from_icon_name (icon_name, icon_size); | |
3936 g_object_set_data_full (G_OBJECT (w), XG_TOOL_BAR_ICON_NAME, | |
3937 (gpointer) xstrdup (icon_name), | |
3938 (GDestroyNotify) xfree); | |
3939 } | |
3908 else | 3940 else |
3909 { | 3941 { |
3910 w = xg_get_image_for_pixmap (f, img, x->widget, NULL); | 3942 w = xg_get_image_for_pixmap (f, img, x->widget, NULL); |
3911 /* Save the image so we can see if an update is needed when | 3943 /* Save the image so we can see if an update is needed when |
3912 this function is called again. */ | 3944 this function is called again. */ |
3978 GtkWidget *wimage = gtk_bin_get_child (GTK_BIN (wbutton)); | 4010 GtkWidget *wimage = gtk_bin_get_child (GTK_BIN (wbutton)); |
3979 Pixmap old_img = (Pixmap)g_object_get_data (G_OBJECT (wimage), | 4011 Pixmap old_img = (Pixmap)g_object_get_data (G_OBJECT (wimage), |
3980 XG_TOOL_BAR_IMAGE_DATA); | 4012 XG_TOOL_BAR_IMAGE_DATA); |
3981 gpointer old_stock_name = g_object_get_data (G_OBJECT (wimage), | 4013 gpointer old_stock_name = g_object_get_data (G_OBJECT (wimage), |
3982 XG_TOOL_BAR_STOCK_NAME); | 4014 XG_TOOL_BAR_STOCK_NAME); |
4015 gpointer old_icon_name = g_object_get_data (G_OBJECT (wimage), | |
4016 XG_TOOL_BAR_ICON_NAME); | |
3983 if (stock_name && | 4017 if (stock_name && |
3984 (! old_stock_name || strcmp (old_stock_name, stock_name) != 0)) | 4018 (! old_stock_name || strcmp (old_stock_name, stock_name) != 0)) |
3985 { | 4019 { |
3986 gtk_image_set_from_stock (GTK_IMAGE (wimage), | 4020 gtk_image_set_from_stock (GTK_IMAGE (wimage), |
3987 stock_name, icon_size); | 4021 stock_name, icon_size); |
3988 g_object_set_data_full (G_OBJECT (wimage), XG_TOOL_BAR_STOCK_NAME, | 4022 g_object_set_data_full (G_OBJECT (wimage), XG_TOOL_BAR_STOCK_NAME, |
3989 (gpointer) xstrdup (stock_name), | 4023 (gpointer) xstrdup (stock_name), |
3990 (GDestroyNotify) xfree); | 4024 (GDestroyNotify) xfree); |
3991 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, | 4025 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, |
3992 NULL); | 4026 NULL); |
4027 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_ICON_NAME, NULL); | |
4028 } | |
4029 else if (icon_name && | |
4030 (! old_icon_name || strcmp (old_icon_name, icon_name) != 0)) | |
4031 { | |
4032 gtk_image_set_from_icon_name (GTK_IMAGE (wimage), | |
4033 icon_name, icon_size); | |
4034 g_object_set_data_full (G_OBJECT (wimage), XG_TOOL_BAR_ICON_NAME, | |
4035 (gpointer) xstrdup (icon_name), | |
4036 (GDestroyNotify) xfree); | |
4037 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, | |
4038 NULL); | |
4039 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_STOCK_NAME, | |
4040 NULL); | |
3993 } | 4041 } |
3994 else if (img && old_img != img->pixmap) | 4042 else if (img && old_img != img->pixmap) |
3995 { | 4043 { |
3996 (void) xg_get_image_for_pixmap (f, img, x->widget, wimage); | 4044 (void) xg_get_image_for_pixmap (f, img, x->widget, wimage); |
3997 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, | 4045 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_IMAGE_DATA, |
3998 (gpointer)img->pixmap); | 4046 (gpointer)img->pixmap); |
3999 | 4047 |
4000 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_STOCK_NAME, | 4048 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_STOCK_NAME, |
4001 NULL); | 4049 NULL); |
4050 g_object_set_data (G_OBJECT (wimage), XG_TOOL_BAR_ICON_NAME, NULL); | |
4002 } | 4051 } |
4003 | 4052 |
4004 gtk_misc_set_padding (GTK_MISC (wimage), hmargin, vmargin); | 4053 gtk_misc_set_padding (GTK_MISC (wimage), hmargin, vmargin); |
4005 | 4054 |
4006 gtk_widget_set_sensitive (wbutton, enabled_p); | 4055 gtk_widget_set_sensitive (wbutton, enabled_p); |