comparison src/gtkutil.c @ 109581:06384b3caebf

Add ability to put Gtk+ tool bar on the left/right/bottom or top. Default top. * lisp/menu-bar.el (menu-bar-showhide-tool-bar-menu-customize-enable-left) (menu-bar-showhide-tool-bar-menu-customize-disable) (menu-bar-showhide-tool-bar-menu-customize-enable-right) (menu-bar-showhide-tool-bar-menu-customize-enable-top) (menu-bar-showhide-tool-bar-menu-customize-enable-bottom): New functions (menu-bar-showhide-tool-bar-menu): If tool bar is moveable, make a menu for Options => toolbar that can move it. * src/frame.c (Qtool_bar_position): New variable. (make_frame): Set tool_bar_position to Qtop. (frame_parms): Add tool-bar-position. (x_report_frame_params): Store tool_bar_position. (x_set_fringe_width): Reset wm size hint after fringe changes. * src/frame.h (struct frame): Add tool_bar_position. (Qbottom): Declare. * src/gtkutil.c (FRAME_TOTAL_PIXEL_WIDTH): New macro. (xg_frame_set_char_size): Add FRAME_TOOLBAR_WIDTH to pixelwidth. (xg_height_or_width_changed): Use FRAME_TOTAL_PIXEL_WIDTH. (xg_create_frame_widgets): Create a hobox for placing widgets vertically. Use gtk_box_pack_start. (xg_height_or_width_changed): Renamed from xg_height_changed. (x_wm_set_size_hint): Add FRAME_TOOLBAR_WIDTH to base_width. (xg_update_frame_menubar, free_frame_menubar): Change to xg_height_or_width_changed. (xg_tool_bar_detach_callback): Update left/right/top/bottom tool bar size correctly. Remove hardcoded 4, instead use handlebox size - toolbar size. (xg_tool_bar_attach_callback): Update left/right/top/bottom tool bar size correctly. Use handlebox size + toolbar size as additional size. (xg_pack_tool_bar): POS is a new parameter. Set orientation of tool bar based on pos. Only make handlebox_widget if NULL. Check if tool bar goes to vbox or hbox depending on pos. (xg_update_tool_bar_sizes): New function. (update_frame_tool_bar): Remove old_req, new_req. Do not get tool bar height, call xg_update_tool_bar_sizes instead. (free_frame_tool_bar): Remove from hbox or vbox depending on toolbar_in_hbox, Set all FRAME_TOOLBAR_*_(WIDTH|HEIGHT) to zero. (xg_change_toolbar_position): New function. * src/gtkutil.h (xg_change_toolbar_position): Declare. * src/window.c (calc_absolute_offset): Check for FRAME_TOOLBAR_TOP_HEIGHT and FRAME_TOOLBAR_LEFT_WIDTH. * src/xfns.c (x_set_tool_bar_position): New function. (xic_set_statusarea): Use FRAME_TOOLBAR_TOP_HEIGHT. (x_frame_parm_handlers): Add x_set_tool_bar_position. (syms_of_xfns): if USE_GTK, provide move-toolbar. * src/xterm.c (x_set_window_size_1): Add FRAME_TOOLBAR_WIDTH to pixelwidth. * src/xterm.h (struct x_output): Add toolbar_top_height, toolbar_bottom_height, toolbar_left_width, toolbar_right_width. Remove toolbar_height. if USE_GTK: Add hbox_widget and toolbar_in_hbox. (FRAME_TOOLBAR_TOP_HEIGHT, FRAME_TOOLBAR_BOTTOM_HEIGHT) (FRAME_TOOLBAR_LEFT_WIDTH, FRAME_TOOLBAR_RIGHT_WIDTH): New macros. (FRAME_TOOLBAR_HEIGHT): Is now TOP_HEIGHT + BOTTOM_HEIGHT.
author Jan D. <jan.h.d@swipnet.se>
date Thu, 29 Jul 2010 18:49:59 +0200
parents d03bc4a3fced
children 43eca6c9f493
comparison
equal deleted inserted replaced
109580:3021343b766a 109581:06384b3caebf
41 #include <X11/Xft/Xft.h> 41 #include <X11/Xft/Xft.h>
42 #endif 42 #endif
43 43
44 #define FRAME_TOTAL_PIXEL_HEIGHT(f) \ 44 #define FRAME_TOTAL_PIXEL_HEIGHT(f) \
45 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f)) 45 (FRAME_PIXEL_HEIGHT (f) + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f))
46
47 #define FRAME_TOTAL_PIXEL_WIDTH(f) \
48 (FRAME_PIXEL_WIDTH (f) + FRAME_TOOLBAR_WIDTH (f))
46 49
47 /* Avoid "differ in sign" warnings */ 50 /* Avoid "differ in sign" warnings */
48 #define SSDATA(x) ((char *) SDATA (x)) 51 #define SSDATA(x) ((char *) SDATA (x))
49 52
50 #ifndef HAVE_GTK_WIDGET_SET_HAS_WINDOW 53 #ifndef HAVE_GTK_WIDGET_SET_HAS_WINDOW
638 641
639 compute_fringe_widths (f, 0); 642 compute_fringe_widths (f, 0);
640 643
641 /* FRAME_TEXT_COLS_TO_PIXEL_WIDTH uses scroll_bar_actual_width, so call it 644 /* FRAME_TEXT_COLS_TO_PIXEL_WIDTH uses scroll_bar_actual_width, so call it
642 after calculating that value. */ 645 after calculating that value. */
643 pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols); 646 pixelwidth = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, cols)
647 + FRAME_TOOLBAR_WIDTH (f);
644 648
645 649
646 /* Do this before resize, as we don't know yet if we will be resized. */ 650 /* Do this before resize, as we don't know yet if we will be resized. */
647 xg_clear_under_internal_border (f); 651 xg_clear_under_internal_border (f);
648 652
675 FRAME_PIXEL_WIDTH (f) = pixelwidth; 679 FRAME_PIXEL_WIDTH (f) = pixelwidth;
676 FRAME_PIXEL_HEIGHT (f) = pixelheight; 680 FRAME_PIXEL_HEIGHT (f) = pixelheight;
677 } 681 }
678 } 682 }
679 683
680 /* Handle height changes (i.e. add/remove menu/toolbar). 684 /* Handle height/width changes (i.e. add/remove/move menu/toolbar).
681 The policy is to keep the number of editable lines. */ 685 The policy is to keep the number of editable lines. */
682 686
683 static void 687 static void
684 xg_height_changed (FRAME_PTR f) 688 xg_height_or_width_changed (FRAME_PTR f)
685 { 689 {
686 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)), 690 gtk_window_resize (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)),
687 FRAME_PIXEL_WIDTH (f), FRAME_TOTAL_PIXEL_HEIGHT (f)); 691 FRAME_TOTAL_PIXEL_WIDTH (f),
692 FRAME_TOTAL_PIXEL_HEIGHT (f));
688 f->output_data.x->hint_flags = 0; 693 f->output_data.x->hint_flags = 0;
689 x_wm_set_size_hint (f, 0, 0); 694 x_wm_set_size_hint (f, 0, 0);
690 } 695 }
691 696
692 /* Convert an X Window WSESC on display DPY to its corresponding GtkWidget. 697 /* Convert an X Window WSESC on display DPY to its corresponding GtkWidget.
731 736
732 int 737 int
733 xg_create_frame_widgets (FRAME_PTR f) 738 xg_create_frame_widgets (FRAME_PTR f)
734 { 739 {
735 GtkWidget *wtop; 740 GtkWidget *wtop;
736 GtkWidget *wvbox; 741 GtkWidget *wvbox, *whbox;
737 GtkWidget *wfixed; 742 GtkWidget *wfixed;
738 GdkColor bg; 743 GdkColor bg;
739 GtkRcStyle *style; 744 GtkRcStyle *style;
740 char *title = 0; 745 char *title = 0;
741 746
747 wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL); 752 wtop = gtk_window_new (GTK_WINDOW_TOPLEVEL);
748 753
749 xg_set_screen (wtop, f); 754 xg_set_screen (wtop, f);
750 755
751 wvbox = gtk_vbox_new (FALSE, 0); 756 wvbox = gtk_vbox_new (FALSE, 0);
757 whbox = gtk_hbox_new (FALSE, 0);
752 wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */ 758 wfixed = gtk_fixed_new (); /* Must have this to place scroll bars */
753 759
754 if (! wtop || ! wvbox || ! wfixed) 760 if (! wtop || ! wvbox || ! whbox || ! wfixed)
755 { 761 {
756 if (wtop) gtk_widget_destroy (wtop); 762 if (wtop) gtk_widget_destroy (wtop);
757 if (wvbox) gtk_widget_destroy (wvbox); 763 if (wvbox) gtk_widget_destroy (wvbox);
764 if (whbox) gtk_widget_destroy (whbox);
758 if (wfixed) gtk_widget_destroy (wfixed); 765 if (wfixed) gtk_widget_destroy (wfixed);
759 766
760 UNBLOCK_INPUT; 767 UNBLOCK_INPUT;
761 return 0; 768 return 0;
762 } 769 }
773 if (title) gtk_window_set_title (GTK_WINDOW (wtop), title); 780 if (title) gtk_window_set_title (GTK_WINDOW (wtop), title);
774 781
775 FRAME_GTK_OUTER_WIDGET (f) = wtop; 782 FRAME_GTK_OUTER_WIDGET (f) = wtop;
776 FRAME_GTK_WIDGET (f) = wfixed; 783 FRAME_GTK_WIDGET (f) = wfixed;
777 f->output_data.x->vbox_widget = wvbox; 784 f->output_data.x->vbox_widget = wvbox;
785 f->output_data.x->hbox_widget = whbox;
778 786
779 gtk_widget_set_has_window (wfixed, TRUE); 787 gtk_widget_set_has_window (wfixed, TRUE);
780 788
781 gtk_container_add (GTK_CONTAINER (wtop), wvbox); 789 gtk_container_add (GTK_CONTAINER (wtop), wvbox);
782 gtk_box_pack_end (GTK_BOX (wvbox), wfixed, TRUE, TRUE, 0); 790 gtk_box_pack_start (GTK_BOX (wvbox), whbox, TRUE, TRUE, 0);
791 gtk_box_pack_start (GTK_BOX (whbox), wfixed, TRUE, TRUE, 0);
783 792
784 if (FRAME_EXTERNAL_TOOL_BAR (f)) 793 if (FRAME_EXTERNAL_TOOL_BAR (f))
785 update_frame_tool_bar (f); 794 update_frame_tool_bar (f);
786 795
787 /* We don't want this widget double buffered, because we draw on it 796 /* We don't want this widget double buffered, because we draw on it
887 hint_flags |= GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE; 896 hint_flags |= GDK_HINT_RESIZE_INC | GDK_HINT_MIN_SIZE;
888 size_hints.width_inc = FRAME_COLUMN_WIDTH (f); 897 size_hints.width_inc = FRAME_COLUMN_WIDTH (f);
889 size_hints.height_inc = FRAME_LINE_HEIGHT (f); 898 size_hints.height_inc = FRAME_LINE_HEIGHT (f);
890 899
891 hint_flags |= GDK_HINT_BASE_SIZE; 900 hint_flags |= GDK_HINT_BASE_SIZE;
892 base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 0); 901 base_width = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, 0) + FRAME_TOOLBAR_WIDTH (f);
893 base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 0) 902 base_height = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, 0)
894 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f); 903 + FRAME_MENUBAR_HEIGHT (f) + FRAME_TOOLBAR_HEIGHT (f);
895 904
896 check_frame_size (f, &min_rows, &min_cols); 905 check_frame_size (f, &min_rows, &min_cols);
897 906
2826 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->menubar_widget, 0); 2835 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->menubar_widget, 0);
2827 2836
2828 gtk_widget_show_all (x->menubar_widget); 2837 gtk_widget_show_all (x->menubar_widget);
2829 gtk_widget_size_request (x->menubar_widget, &req); 2838 gtk_widget_size_request (x->menubar_widget, &req);
2830 FRAME_MENUBAR_HEIGHT (f) = req.height; 2839 FRAME_MENUBAR_HEIGHT (f) = req.height;
2831 xg_height_changed (f); 2840 xg_height_or_width_changed (f);
2832 UNBLOCK_INPUT; 2841 UNBLOCK_INPUT;
2833 2842
2834 return 1; 2843 return 1;
2835 } 2844 }
2836 2845
2849 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget); 2858 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), x->menubar_widget);
2850 /* The menubar and its children shall be deleted when removed from 2859 /* The menubar and its children shall be deleted when removed from
2851 the container. */ 2860 the container. */
2852 x->menubar_widget = 0; 2861 x->menubar_widget = 0;
2853 FRAME_MENUBAR_HEIGHT (f) = 0; 2862 FRAME_MENUBAR_HEIGHT (f) = 0;
2854 xg_height_changed (f); 2863 xg_height_or_width_changed (f);
2855 UNBLOCK_INPUT; 2864 UNBLOCK_INPUT;
2856 } 2865 }
2857 } 2866 }
2858 2867
2859 int 2868 int
3546 g_object_set (G_OBJECT (w), "show-arrow", !x_gtk_whole_detached_tool_bar, 3555 g_object_set (G_OBJECT (w), "show-arrow", !x_gtk_whole_detached_tool_bar,
3547 NULL); 3556 NULL);
3548 3557
3549 if (f) 3558 if (f)
3550 { 3559 {
3560 GtkRequisition req, req2;
3551 FRAME_X_OUTPUT (f)->toolbar_detached = 1; 3561 FRAME_X_OUTPUT (f)->toolbar_detached = 1;
3552 3562 gtk_widget_size_request (GTK_WIDGET (wbox), &req);
3553 /* When detaching a tool bar, not everything dissapear. There are 3563 gtk_widget_size_request (w, &req2);
3554 a few pixels left that are used to drop the tool bar back into 3564 req.width -= req2.width;
3555 place. */ 3565 req.height -= req2.height;
3556 FRAME_TOOLBAR_HEIGHT (f) = 4; 3566 if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
3557 xg_height_changed (f); 3567 FRAME_TOOLBAR_TOP_HEIGHT (f) = req.height;
3568 else if (FRAME_TOOLBAR_BOTTOM_HEIGHT (f) != 0)
3569 FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = req.height;
3570 else if (FRAME_TOOLBAR_RIGHT_WIDTH (f) != 0)
3571 FRAME_TOOLBAR_RIGHT_WIDTH (f) = req.width;
3572 else if (FRAME_TOOLBAR_LEFT_WIDTH (f) != 0)
3573 FRAME_TOOLBAR_LEFT_WIDTH (f) = req.width;
3574 xg_height_or_width_changed (f);
3558 } 3575 }
3559 } 3576 }
3560 3577
3561 /* This callback is called when a tool bar is reattached. We must set 3578 /* This callback is called when a tool bar is reattached. We must set
3562 the height of the tool bar when this happens so frame sizes 3579 the height of the tool bar when this happens so frame sizes
3573 FRAME_PTR f = (FRAME_PTR) client_data; 3590 FRAME_PTR f = (FRAME_PTR) client_data;
3574 g_object_set (G_OBJECT (w), "show-arrow", TRUE, NULL); 3591 g_object_set (G_OBJECT (w), "show-arrow", TRUE, NULL);
3575 3592
3576 if (f) 3593 if (f)
3577 { 3594 {
3578 GtkRequisition req; 3595 GtkRequisition req, req2;
3579
3580 FRAME_X_OUTPUT (f)->toolbar_detached = 0; 3596 FRAME_X_OUTPUT (f)->toolbar_detached = 0;
3581 3597 gtk_widget_size_request (GTK_WIDGET (wbox), &req);
3582 gtk_widget_size_request (w, &req); 3598 gtk_widget_size_request (w, &req2);
3583 FRAME_TOOLBAR_HEIGHT (f) = req.height; 3599 req.width += req2.width;
3584 xg_height_changed (f); 3600 req.height += req2.height;
3601 if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
3602 FRAME_TOOLBAR_TOP_HEIGHT (f) = req.height;
3603 else if (FRAME_TOOLBAR_BOTTOM_HEIGHT (f) != 0)
3604 FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = req.height;
3605 else if (FRAME_TOOLBAR_RIGHT_WIDTH (f) != 0)
3606 FRAME_TOOLBAR_RIGHT_WIDTH (f) = req.width;
3607 else if (FRAME_TOOLBAR_LEFT_WIDTH (f) != 0)
3608 FRAME_TOOLBAR_LEFT_WIDTH (f) = req.width;
3609 xg_height_or_width_changed (f);
3585 } 3610 }
3586 } 3611 }
3587 3612
3588 /* This callback is called when the mouse enters or leaves a tool bar item. 3613 /* This callback is called when the mouse enters or leaves a tool bar item.
3589 It is used for displaying and hiding the help text. 3614 It is used for displaying and hiding the help text.
3654 event->area.height = max (height, event->area.height); 3679 event->area.height = max (height, event->area.height);
3655 3680
3656 return FALSE; 3681 return FALSE;
3657 } 3682 }
3658 3683
3659 /* Attach a tool bar to frame F. */
3660
3661 static void
3662 xg_pack_tool_bar (FRAME_PTR f)
3663 {
3664 struct x_output *x = f->output_data.x;
3665 int vbox_pos = x->menubar_widget ? 1 : 0;
3666
3667 x->handlebox_widget = gtk_handle_box_new ();
3668 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-detached",
3669 G_CALLBACK (xg_tool_bar_detach_callback), f);
3670 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-attached",
3671 G_CALLBACK (xg_tool_bar_attach_callback), f);
3672
3673 gtk_container_add (GTK_CONTAINER (x->handlebox_widget),
3674 x->toolbar_widget);
3675
3676 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget,
3677 FALSE, FALSE, 0);
3678
3679 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), x->handlebox_widget,
3680 vbox_pos);
3681
3682 gtk_widget_show (x->toolbar_widget);
3683 gtk_widget_show (x->handlebox_widget);
3684 }
3685
3686 /* Create a tool bar for frame F. */
3687 #ifdef HAVE_GTK_ORIENTABLE_SET_ORIENTATION 3684 #ifdef HAVE_GTK_ORIENTABLE_SET_ORIENTATION
3688 #define toolbar_set_orientation(w, o) \ 3685 #define toolbar_set_orientation(w, o) \
3689 gtk_orientable_set_orientation (GTK_ORIENTABLE (w), o) 3686 gtk_orientable_set_orientation (GTK_ORIENTABLE (w), o)
3690 #else 3687 #else
3691 #define toolbar_set_orientation(w, o) \ 3688 #define toolbar_set_orientation(w, o) \
3692 gtk_toolbar_set_orientation (GTK_TOOLBAR (w), o) 3689 gtk_toolbar_set_orientation (GTK_TOOLBAR (w), o)
3693 #endif 3690 #endif
3691
3692 /* Attach a tool bar to frame F. */
3693
3694 static void
3695 xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos)
3696 {
3697 struct x_output *x = f->output_data.x;
3698 int into_hbox = EQ (pos, Qleft) || EQ (pos, Qright);
3699
3700 toolbar_set_orientation (x->toolbar_widget,
3701 into_hbox
3702 ? GTK_ORIENTATION_VERTICAL
3703 : GTK_ORIENTATION_HORIZONTAL);
3704 if (!x->handlebox_widget)
3705 {
3706 x->handlebox_widget = gtk_handle_box_new ();
3707 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-detached",
3708 G_CALLBACK (xg_tool_bar_detach_callback), f);
3709 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-attached",
3710 G_CALLBACK (xg_tool_bar_attach_callback), f);
3711 gtk_container_add (GTK_CONTAINER (x->handlebox_widget),
3712 x->toolbar_widget);
3713 }
3714
3715 if (into_hbox)
3716 {
3717 gtk_box_pack_start (GTK_BOX (x->hbox_widget), x->handlebox_widget,
3718 FALSE, FALSE, 0);
3719
3720 if (EQ (pos, Qleft))
3721 gtk_box_reorder_child (GTK_BOX (x->hbox_widget),
3722 x->handlebox_widget,
3723 0);
3724 x->toolbar_in_hbox = 1;
3725 }
3726 else
3727 {
3728 int vbox_pos = x->menubar_widget ? 1 : 0;
3729 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget,
3730 FALSE, FALSE, 0);
3731
3732 if (EQ (pos, Qtop))
3733 gtk_box_reorder_child (GTK_BOX (x->vbox_widget),
3734 x->handlebox_widget,
3735 vbox_pos);
3736 x->toolbar_in_hbox = 0;
3737 }
3738 }
3739
3740 /* Create a tool bar for frame F. */
3694 3741
3695 static void 3742 static void
3696 xg_create_tool_bar (FRAME_PTR f) 3743 xg_create_tool_bar (FRAME_PTR f)
3697 { 3744 {
3698 struct x_output *x = f->output_data.x; 3745 struct x_output *x = f->output_data.x;
3873 gtk_widget_show (GTK_WIDGET (vb)); 3920 gtk_widget_show (GTK_WIDGET (vb));
3874 gtk_widget_show (GTK_WIDGET (wbutton)); 3921 gtk_widget_show (GTK_WIDGET (wbutton));
3875 gtk_widget_show (GTK_WIDGET (ti)); 3922 gtk_widget_show (GTK_WIDGET (ti));
3876 } 3923 }
3877 3924
3925 static int
3926 xg_update_tool_bar_sizes (FRAME_PTR f)
3927 {
3928 struct x_output *x = f->output_data.x;
3929 GtkRequisition req;
3930 int nl = 0, nr = 0, nt = 0, nb = 0;
3931
3932 gtk_widget_size_request (GTK_WIDGET (x->handlebox_widget), &req);
3933 if (x->toolbar_in_hbox)
3934 {
3935 int pos;
3936 gtk_container_child_get (GTK_CONTAINER (x->hbox_widget),
3937 x->handlebox_widget,
3938 "position", &pos, NULL);
3939 if (pos == 0) nl = req.width;
3940 else nr = req.width;
3941 }
3942 else
3943 {
3944 int pos;
3945 gtk_container_child_get (GTK_CONTAINER (x->vbox_widget),
3946 x->handlebox_widget,
3947 "position", &pos, NULL);
3948 if (pos == 0 || (pos == 1 && x->menubar_widget)) nt = req.height;
3949 else nb = req.height;
3950 }
3951
3952 if (nl != FRAME_TOOLBAR_LEFT_WIDTH (f)
3953 || nr != FRAME_TOOLBAR_RIGHT_WIDTH (f)
3954 || nt != FRAME_TOOLBAR_TOP_HEIGHT (f)
3955 || nb != FRAME_TOOLBAR_BOTTOM_HEIGHT (f))
3956 {
3957 FRAME_TOOLBAR_RIGHT_WIDTH (f) = FRAME_TOOLBAR_LEFT_WIDTH (f)
3958 = FRAME_TOOLBAR_TOP_HEIGHT (f) = FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = 0;
3959 FRAME_TOOLBAR_LEFT_WIDTH (f) = nl;
3960 FRAME_TOOLBAR_RIGHT_WIDTH (f) = nr;
3961 FRAME_TOOLBAR_TOP_HEIGHT (f) = nt;
3962 FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = nb;
3963 return 1;
3964 }
3965
3966 return 0;
3967 }
3968
3878 3969
3879 /* Update the tool bar for frame F. Add new buttons and remove old. */ 3970 /* Update the tool bar for frame F. Add new buttons and remove old. */
3880 3971
3881 extern Lisp_Object Qx_gtk_map_stock; 3972 extern Lisp_Object Qx_gtk_map_stock;
3882 3973
3883 void 3974 void
3884 update_frame_tool_bar (FRAME_PTR f) 3975 update_frame_tool_bar (FRAME_PTR f)
3885 { 3976 {
3886 int i; 3977 int i;
3887 GtkRequisition old_req, new_req;
3888 struct x_output *x = f->output_data.x; 3978 struct x_output *x = f->output_data.x;
3889 int hmargin = 0, vmargin = 0; 3979 int hmargin = 0, vmargin = 0;
3890 GtkToolbar *wtoolbar; 3980 GtkToolbar *wtoolbar;
3891 GtkToolItem *ti; 3981 GtkToolItem *ti;
3892 GtkTextDirection dir; 3982 GtkTextDirection dir;
3923 4013
3924 if (! x->toolbar_widget) 4014 if (! x->toolbar_widget)
3925 xg_create_tool_bar (f); 4015 xg_create_tool_bar (f);
3926 4016
3927 wtoolbar = GTK_TOOLBAR (x->toolbar_widget); 4017 wtoolbar = GTK_TOOLBAR (x->toolbar_widget);
3928 gtk_widget_size_request (GTK_WIDGET (wtoolbar), &old_req);
3929 dir = gtk_widget_get_direction (GTK_WIDGET (wtoolbar)); 4018 dir = gtk_widget_get_direction (GTK_WIDGET (wtoolbar));
3930 4019
3931 for (i = 0; i < f->n_tool_bar_items; ++i) 4020 for (i = 0; i < f->n_tool_bar_items; ++i)
3932 { 4021 {
3933 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); 4022 int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P));
4141 { 4230 {
4142 ti = gtk_toolbar_get_nth_item (GTK_TOOLBAR (wtoolbar), i++); 4231 ti = gtk_toolbar_get_nth_item (GTK_TOOLBAR (wtoolbar), i++);
4143 if (ti) gtk_widget_hide_all (GTK_WIDGET (ti)); 4232 if (ti) gtk_widget_hide_all (GTK_WIDGET (ti));
4144 } while (ti != NULL); 4233 } while (ti != NULL);
4145 4234
4146 new_req.height = 0; 4235 if (f->n_tool_bar_items != 0)
4147 if (pack_tool_bar && f->n_tool_bar_items != 0) 4236 {
4148 xg_pack_tool_bar (f); 4237 if (pack_tool_bar)
4149 4238 xg_pack_tool_bar (f, f->tool_bar_position);
4150 4239 gtk_widget_show (x->toolbar_widget);
4151 gtk_widget_size_request (GTK_WIDGET (wtoolbar), &new_req); 4240 gtk_widget_show (x->handlebox_widget);
4152 if (old_req.height != new_req.height 4241 if (xg_update_tool_bar_sizes (f))
4153 && ! FRAME_X_OUTPUT (f)->toolbar_detached) 4242 xg_height_or_width_changed (f);
4154 { 4243 }
4155 FRAME_TOOLBAR_HEIGHT (f) = new_req.height; 4244
4156 xg_height_changed (f);
4157 }
4158 UNBLOCK_INPUT; 4245 UNBLOCK_INPUT;
4159 } 4246 }
4160 4247
4161 /* Deallocate all resources for the tool bar on frame F. 4248 /* Deallocate all resources for the tool bar on frame F.
4162 Remove the tool bar. */ 4249 Remove the tool bar. */
4170 { 4257 {
4171 int is_packed = x->handlebox_widget != 0; 4258 int is_packed = x->handlebox_widget != 0;
4172 BLOCK_INPUT; 4259 BLOCK_INPUT;
4173 /* We may have created the toolbar_widget in xg_create_tool_bar, but 4260 /* We may have created the toolbar_widget in xg_create_tool_bar, but
4174 not the x->handlebox_widget which is created in xg_pack_tool_bar. */ 4261 not the x->handlebox_widget which is created in xg_pack_tool_bar. */
4175 if (is_packed) 4262 if (is_packed)
4176 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), 4263 {
4177 x->handlebox_widget); 4264 if (x->toolbar_in_hbox)
4265 gtk_container_remove (GTK_CONTAINER (x->hbox_widget),
4266 x->handlebox_widget);
4267 else
4268 gtk_container_remove (GTK_CONTAINER (x->vbox_widget),
4269 x->handlebox_widget);
4270 }
4178 else 4271 else
4179 gtk_widget_destroy (x->toolbar_widget); 4272 gtk_widget_destroy (x->toolbar_widget);
4180 4273
4181 x->toolbar_widget = 0; 4274 x->toolbar_widget = 0;
4182 x->handlebox_widget = 0; 4275 x->handlebox_widget = 0;
4183 FRAME_TOOLBAR_HEIGHT (f) = 0; 4276 FRAME_TOOLBAR_TOP_HEIGHT (f) = FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = 0;
4184 xg_height_changed (f); 4277 FRAME_TOOLBAR_LEFT_WIDTH (f) = FRAME_TOOLBAR_RIGHT_WIDTH (f) = 0;
4278
4279 xg_height_or_width_changed (f);
4185 4280
4186 UNBLOCK_INPUT; 4281 UNBLOCK_INPUT;
4187 } 4282 }
4283 }
4284
4285 int
4286 xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos)
4287 {
4288 struct x_output *x = f->output_data.x;
4289
4290 if (! x->toolbar_widget || ! x->handlebox_widget)
4291 return 1;
4292
4293 BLOCK_INPUT;
4294 g_object_ref (x->handlebox_widget);
4295 if (x->toolbar_in_hbox)
4296 gtk_container_remove (GTK_CONTAINER (x->hbox_widget),
4297 x->handlebox_widget);
4298 else
4299 gtk_container_remove (GTK_CONTAINER (x->vbox_widget),
4300 x->handlebox_widget);
4301 xg_pack_tool_bar (f, pos);
4302 g_object_unref (x->handlebox_widget);
4303 if (xg_update_tool_bar_sizes (f))
4304 xg_height_or_width_changed (f);
4305
4306 UNBLOCK_INPUT;
4307 return 1;
4188 } 4308 }
4189 4309
4190 4310
4191 4311
4192 /*********************************************************************** 4312 /***********************************************************************