Mercurial > emacs
comparison src/gtkutil.c @ 75009:6ec19c8cca02
(update_frame_tool_bar): Connect create-menu-proxy with
xg_tool_bar_menu_proxy.
(xg_tool_bar_menu_proxy): New function.
(xg_tool_bar_proxy_callback): New function.
author | Jan Djärv <jan.h.d@swipnet.se> |
---|---|
date | Sun, 31 Dec 2006 18:31:38 +0000 |
parents | de706755c4d7 |
children | 37202e2fc35f 17e0dd217877 bc10a33dd40b |
comparison
equal
deleted
inserted
replaced
75008:7ef4e78d5b6a | 75009:6ec19c8cca02 |
---|---|
3348 | 3348 |
3349 /* The key for storing the latest modifiers so the activate callback can | 3349 /* The key for storing the latest modifiers so the activate callback can |
3350 get them. */ | 3350 get them. */ |
3351 #define XG_TOOL_BAR_LAST_MODIFIER "emacs-tool-bar-modifier" | 3351 #define XG_TOOL_BAR_LAST_MODIFIER "emacs-tool-bar-modifier" |
3352 | 3352 |
3353 /* The key for storing the button widget in its proxy menu item. */ | |
3354 #define XG_TOOL_BAR_PROXY_BUTTON "emacs-tool-bar-proxy-button" | |
3353 | 3355 |
3354 static gboolean | 3356 static gboolean |
3355 xg_tool_bar_button_cb (widget, event, user_data) | 3357 xg_tool_bar_button_cb (widget, event, user_data) |
3356 GtkWidget *widget; | 3358 GtkWidget *widget; |
3357 GdkEventButton *event; | 3359 GdkEventButton *event; |
3402 /* Convert between the modifier bits GDK uses and the modifier bits | 3404 /* Convert between the modifier bits GDK uses and the modifier bits |
3403 Emacs uses. This assumes GDK an X masks are the same, which they are when | 3405 Emacs uses. This assumes GDK an X masks are the same, which they are when |
3404 this is written. */ | 3406 this is written. */ |
3405 event.modifiers = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), mod); | 3407 event.modifiers = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), mod); |
3406 kbd_buffer_store_event (&event); | 3408 kbd_buffer_store_event (&event); |
3409 } | |
3410 | |
3411 /* Callback function invoked when a tool bar item is pressed in a detached | |
3412 tool bar or the overflow drop down menu. | |
3413 We just call xg_tool_bar_callback. | |
3414 W is the menu item widget that got pressed, | |
3415 CLIENT_DATA is an integer that is the index of the button in the | |
3416 tool bar. 0 is the first button. */ | |
3417 | |
3418 static void | |
3419 xg_tool_bar_proxy_callback (w, client_data) | |
3420 GtkWidget *w; | |
3421 gpointer client_data; | |
3422 { | |
3423 GtkWidget *wbutton = GTK_WIDGET (g_object_get_data (G_OBJECT (w), | |
3424 XG_TOOL_BAR_PROXY_BUTTON)); | |
3425 xg_tool_bar_callback (wbutton, client_data); | |
3426 } | |
3427 | |
3428 /* This callback is called when a tool item should create a proxy item, | |
3429 such as for the overflow menu. Also called when the tool bar is detached. | |
3430 If we don't create a proxy menu item, the detached tool bar will be | |
3431 blank. */ | |
3432 | |
3433 static gboolean | |
3434 xg_tool_bar_menu_proxy (toolitem, user_data) | |
3435 GtkToolItem *toolitem; | |
3436 gpointer user_data; | |
3437 { | |
3438 GtkWidget *weventbox = gtk_bin_get_child (GTK_BIN (toolitem)); | |
3439 GtkButton *wbutton = GTK_BUTTON (gtk_bin_get_child (GTK_BIN (weventbox))); | |
3440 GtkWidget *wmenuitem = gtk_image_menu_item_new (); | |
3441 GtkWidget *wmenuimage; | |
3442 | |
3443 if (gtk_button_get_use_stock (wbutton)) | |
3444 wmenuimage = gtk_image_new_from_stock (gtk_button_get_label (wbutton), | |
3445 GTK_ICON_SIZE_MENU); | |
3446 else | |
3447 { | |
3448 GtkImage *wimage = GTK_IMAGE (gtk_bin_get_child (GTK_BIN (wbutton))); | |
3449 GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (wbutton)); | |
3450 GtkImageType store_type = gtk_image_get_storage_type (wimage); | |
3451 if (store_type == GTK_IMAGE_STOCK) | |
3452 { | |
3453 gchar *stock_id; | |
3454 gtk_image_get_stock (wimage, &stock_id, NULL); | |
3455 wmenuimage = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU); | |
3456 } | |
3457 else if (store_type == GTK_IMAGE_ICON_SET) | |
3458 { | |
3459 GtkIconSet *icon_set; | |
3460 gtk_image_get_icon_set (wimage, &icon_set, NULL); | |
3461 wmenuimage = gtk_image_new_from_icon_set (icon_set, | |
3462 GTK_ICON_SIZE_MENU); | |
3463 } | |
3464 else if (store_type == GTK_IMAGE_PIXBUF) | |
3465 { | |
3466 gint width, height; | |
3467 | |
3468 if (settings && | |
3469 gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, | |
3470 &width, &height)) | |
3471 { | |
3472 GdkPixbuf *src_pixbuf, *dest_pixbuf; | |
3473 | |
3474 src_pixbuf = gtk_image_get_pixbuf (wimage); | |
3475 dest_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, width, height, | |
3476 GDK_INTERP_BILINEAR); | |
3477 | |
3478 wmenuimage = gtk_image_new_from_pixbuf (dest_pixbuf); | |
3479 } | |
3480 } | |
3481 } | |
3482 if (wmenuimage) | |
3483 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (wmenuitem), wmenuimage); | |
3484 | |
3485 g_signal_connect (G_OBJECT (wmenuitem), | |
3486 "activate", | |
3487 GTK_SIGNAL_FUNC (xg_tool_bar_proxy_callback), | |
3488 user_data); | |
3489 | |
3490 g_object_set_data (G_OBJECT (wmenuitem), XG_TOOL_BAR_PROXY_BUTTON, | |
3491 (gpointer) wbutton); | |
3492 gtk_tool_item_set_proxy_menu_item (toolitem, "Emacs toolbar item", wmenuitem); | |
3493 | |
3494 return TRUE; | |
3407 } | 3495 } |
3408 | 3496 |
3409 /* This callback is called when a tool bar is detached. We must set | 3497 /* This callback is called when a tool bar is detached. We must set |
3410 the height of the tool bar to zero when this happens so frame sizes | 3498 the height of the tool bar to zero when this happens so frame sizes |
3411 are correctly calculated. | 3499 are correctly calculated. |
3725 else | 3813 else |
3726 { | 3814 { |
3727 /* Insert an empty (non-image) button */ | 3815 /* Insert an empty (non-image) button */ |
3728 weventbox = gtk_event_box_new (); | 3816 weventbox = gtk_event_box_new (); |
3729 wbutton = gtk_button_new (); | 3817 wbutton = gtk_button_new (); |
3818 gtk_button_set_focus_on_click (GTK_BUTTON (wbutton), FALSE); | |
3730 gtk_button_set_relief (GTK_BUTTON (wbutton), GTK_RELIEF_NONE); | 3819 gtk_button_set_relief (GTK_BUTTON (wbutton), GTK_RELIEF_NONE); |
3731 gtk_container_add (GTK_CONTAINER (weventbox), wbutton); | 3820 gtk_container_add (GTK_CONTAINER (weventbox), wbutton); |
3732 ti = gtk_tool_item_new (); | 3821 ti = gtk_tool_item_new (); |
3733 gtk_container_add (GTK_CONTAINER (ti), weventbox); | 3822 gtk_container_add (GTK_CONTAINER (ti), weventbox); |
3734 gtk_toolbar_insert (GTK_TOOLBAR (x->toolbar_widget), ti, i); | 3823 gtk_toolbar_insert (GTK_TOOLBAR (x->toolbar_widget), ti, i); |
3739 if (ti == NULL) | 3828 if (ti == NULL) |
3740 { | 3829 { |
3741 GtkWidget *w = xg_get_image_for_pixmap (f, img, x->widget, NULL); | 3830 GtkWidget *w = xg_get_image_for_pixmap (f, img, x->widget, NULL); |
3742 gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin); | 3831 gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin); |
3743 wbutton = gtk_button_new (); | 3832 wbutton = gtk_button_new (); |
3833 gtk_button_set_focus_on_click (GTK_BUTTON (wbutton), FALSE); | |
3744 gtk_button_set_relief (GTK_BUTTON (wbutton), GTK_RELIEF_NONE); | 3834 gtk_button_set_relief (GTK_BUTTON (wbutton), GTK_RELIEF_NONE); |
3745 gtk_container_add (GTK_CONTAINER (wbutton), w); | 3835 gtk_container_add (GTK_CONTAINER (wbutton), w); |
3746 weventbox = gtk_event_box_new (); | 3836 weventbox = gtk_event_box_new (); |
3747 gtk_container_add (GTK_CONTAINER (weventbox), wbutton); | 3837 gtk_container_add (GTK_CONTAINER (weventbox), wbutton); |
3748 ti = gtk_tool_item_new (); | 3838 ti = gtk_tool_item_new (); |
3749 gtk_container_add (GTK_CONTAINER (ti), weventbox); | 3839 gtk_container_add (GTK_CONTAINER (ti), weventbox); |
3750 gtk_toolbar_insert (GTK_TOOLBAR (x->toolbar_widget), ti, i); | 3840 gtk_toolbar_insert (GTK_TOOLBAR (x->toolbar_widget), ti, i); |
3751 | 3841 |
3752 | 3842 |
3753 /* The EMACS_INT cast avoids a warning. */ | 3843 /* The EMACS_INT cast avoids a warning. */ |
3754 g_signal_connect (wbutton, "clicked", | 3844 g_signal_connect (G_OBJECT (ti), "create-menu-proxy", |
3845 GTK_SIGNAL_FUNC (xg_tool_bar_menu_proxy), | |
3846 (gpointer) (EMACS_INT) i); | |
3847 | |
3848 g_signal_connect (G_OBJECT (wbutton), "clicked", | |
3755 GTK_SIGNAL_FUNC (xg_tool_bar_callback), | 3849 GTK_SIGNAL_FUNC (xg_tool_bar_callback), |
3756 (gpointer) (EMACS_INT) i); | 3850 (gpointer) (EMACS_INT) i); |
3757 | 3851 |
3758 gtk_widget_show_all (GTK_WIDGET (ti)); | 3852 gtk_widget_show_all (GTK_WIDGET (ti)); |
3759 | 3853 |