aboutsummaryrefslogtreecommitdiffstats
path: root/src/gtkutil.c
diff options
context:
space:
mode:
authorJoakim Verona2012-12-31 00:04:10 +0100
committerJoakim Verona2012-12-31 00:04:10 +0100
commit42a61fa6a6cbcfde79d812bbbba372d579dc1016 (patch)
tree96f29a95b6a443d93875882b1d7a7dbbd6fcc849 /src/gtkutil.c
parentea2da3d8fbf19765a9bd82292bfc73918f74048d (diff)
parent84cc1ab62539eed7869a88003a017330d79e8cac (diff)
downloademacs-42a61fa6a6cbcfde79d812bbbba372d579dc1016.tar.gz
emacs-42a61fa6a6cbcfde79d812bbbba372d579dc1016.zip
auto upstream
Diffstat (limited to 'src/gtkutil.c')
-rw-r--r--src/gtkutil.c98
1 files changed, 68 insertions, 30 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 7f50b67d1e5..7b05cff71c0 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -2416,6 +2416,8 @@ make_menu_item (const char *utf8_label,
2416 return w; 2416 return w;
2417} 2417}
2418 2418
2419#ifdef HAVE_GTK_TEAROFF_MENU_ITEM_NEW
2420
2419static int xg_detached_menus; 2421static int xg_detached_menus;
2420 2422
2421/* Return true if there are detached menus. */ 2423/* Return true if there are detached menus. */
@@ -2454,7 +2456,13 @@ tearoff_activate (GtkWidget *widget, gpointer client_data)
2454 G_CALLBACK (tearoff_remove), 0); 2456 G_CALLBACK (tearoff_remove), 0);
2455 } 2457 }
2456} 2458}
2457 2459#else /* ! HAVE_GTK_TEAROFF_MENU_ITEM_NEW */
2460bool
2461xg_have_tear_offs (void)
2462{
2463 return false;
2464}
2465#endif /* ! HAVE_GTK_TEAROFF_MENU_ITEM_NEW */
2458 2466
2459/* Create a menu item widget, and connect the callbacks. 2467/* Create a menu item widget, and connect the callbacks.
2460 ITEM describes the menu item. 2468 ITEM describes the menu item.
@@ -2526,7 +2534,8 @@ xg_create_one_menuitem (widget_value *item,
2526 HIGHLIGHT_CB is the callback to call when entering/leaving menu items. 2534 HIGHLIGHT_CB is the callback to call when entering/leaving menu items.
2527 If POP_UP_P, create a popup menu. 2535 If POP_UP_P, create a popup menu.
2528 If MENU_BAR_P, create a menu bar. 2536 If MENU_BAR_P, create a menu bar.
2529 If ADD_TEAROFF_P, add a tearoff menu item. Ignored if MENU_BAR_P. 2537 If ADD_TEAROFF_P, add a tearoff menu item. Ignored if MENU_BAR_P or
2538 the Gtk+ version used does not have tearoffs.
2530 TOPMENU is the topmost GtkWidget that others shall be placed under. 2539 TOPMENU is the topmost GtkWidget that others shall be placed under.
2531 It may be NULL, in that case we create the appropriate widget 2540 It may be NULL, in that case we create the appropriate widget
2532 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P) 2541 (menu bar or menu item depending on POP_UP_P and MENU_BAR_P)
@@ -2599,6 +2608,7 @@ create_menus (widget_value *data,
2599 "selection-done", deactivate_cb, 0); 2608 "selection-done", deactivate_cb, 0);
2600 } 2609 }
2601 2610
2611#ifdef HAVE_GTK_TEAROFF_MENU_ITEM_NEW
2602 if (! menu_bar_p && add_tearoff_p) 2612 if (! menu_bar_p && add_tearoff_p)
2603 { 2613 {
2604 GtkWidget *tearoff = gtk_tearoff_menu_item_new (); 2614 GtkWidget *tearoff = gtk_tearoff_menu_item_new ();
@@ -2607,6 +2617,7 @@ create_menus (widget_value *data,
2607 g_signal_connect (G_OBJECT (tearoff), "activate", 2617 g_signal_connect (G_OBJECT (tearoff), "activate",
2608 G_CALLBACK (tearoff_activate), 0); 2618 G_CALLBACK (tearoff_activate), 0);
2609 } 2619 }
2620#endif
2610 2621
2611 for (item = data; item; item = item->next) 2622 for (item = data; item; item = item->next)
2612 { 2623 {
@@ -2897,11 +2908,13 @@ xg_update_menubar (GtkWidget *menubar,
2897 2908
2898 gtk_label_set_text (wlabel, utf8_label); 2909 gtk_label_set_text (wlabel, utf8_label);
2899 2910
2911#ifdef HAVE_GTK_TEAROFF_MENU_ITEM_NEW
2900 /* If this item has a submenu that has been detached, change 2912 /* If this item has a submenu that has been detached, change
2901 the title in the WM decorations also. */ 2913 the title in the WM decorations also. */
2902 if (submenu && gtk_menu_get_tearoff_state (GTK_MENU (submenu))) 2914 if (submenu && gtk_menu_get_tearoff_state (GTK_MENU (submenu)))
2903 /* Set the title of the detached window. */ 2915 /* Set the title of the detached window. */
2904 gtk_menu_set_title (GTK_MENU (submenu), utf8_label); 2916 gtk_menu_set_title (GTK_MENU (submenu), utf8_label);
2917#endif
2905 2918
2906 if (utf8_label) g_free (utf8_label); 2919 if (utf8_label) g_free (utf8_label);
2907 iter = g_list_next (iter); 2920 iter = g_list_next (iter);
@@ -3129,7 +3142,8 @@ xg_update_submenu (GtkWidget *submenu,
3129 { 3142 {
3130 GtkWidget *w = GTK_WIDGET (iter->data); 3143 GtkWidget *w = GTK_WIDGET (iter->data);
3131 3144
3132 /* Skip tearoff items, they have no counterpart in val. */ 3145#ifdef HAVE_GTK_TEAROFF_MENU_ITEM_NEW
3146 /* Skip tearoff items, they have no counterpart in val. */
3133 if (GTK_IS_TEAROFF_MENU_ITEM (w)) 3147 if (GTK_IS_TEAROFF_MENU_ITEM (w))
3134 { 3148 {
3135 has_tearoff_p = 1; 3149 has_tearoff_p = 1;
@@ -3137,6 +3151,7 @@ xg_update_submenu (GtkWidget *submenu,
3137 if (iter) w = GTK_WIDGET (iter->data); 3151 if (iter) w = GTK_WIDGET (iter->data);
3138 else break; 3152 else break;
3139 } 3153 }
3154#endif
3140 3155
3141 /* Remember first radio button in a group. If we get a mismatch in 3156 /* Remember first radio button in a group. If we get a mismatch in
3142 a radio group we must rebuild the whole group so that the connections 3157 a radio group we must rebuild the whole group so that the connections
@@ -4269,6 +4284,12 @@ xg_tool_bar_item_expose_callback (GtkWidget *w,
4269 gtk_toolbar_set_orientation (GTK_TOOLBAR (w), o) 4284 gtk_toolbar_set_orientation (GTK_TOOLBAR (w), o)
4270#endif 4285#endif
4271 4286
4287#ifdef HAVE_GTK_HANDLE_BOX_NEW
4288#define TOOLBAR_TOP_WIDGET(x) ((x)->handlebox_widget)
4289#else
4290#define TOOLBAR_TOP_WIDGET(x) ((x)->toolbar_widget)
4291#endif
4292
4272/* Attach a tool bar to frame F. */ 4293/* Attach a tool bar to frame F. */
4273 4294
4274static void 4295static void
@@ -4276,14 +4297,16 @@ xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos)
4276{ 4297{
4277 struct x_output *x = f->output_data.x; 4298 struct x_output *x = f->output_data.x;
4278 bool into_hbox = EQ (pos, Qleft) || EQ (pos, Qright); 4299 bool into_hbox = EQ (pos, Qleft) || EQ (pos, Qright);
4300 GtkWidget *top_widget = TOOLBAR_TOP_WIDGET (x);
4279 4301
4280 toolbar_set_orientation (x->toolbar_widget, 4302 toolbar_set_orientation (x->toolbar_widget,
4281 into_hbox 4303 into_hbox
4282 ? GTK_ORIENTATION_VERTICAL 4304 ? GTK_ORIENTATION_VERTICAL
4283 : GTK_ORIENTATION_HORIZONTAL); 4305 : GTK_ORIENTATION_HORIZONTAL);
4306#ifdef HAVE_GTK_HANDLE_BOX_NEW
4284 if (!x->handlebox_widget) 4307 if (!x->handlebox_widget)
4285 { 4308 {
4286 x->handlebox_widget = gtk_handle_box_new (); 4309 top_widget = x->handlebox_widget = gtk_handle_box_new ();
4287 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-detached", 4310 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-detached",
4288 G_CALLBACK (xg_tool_bar_detach_callback), f); 4311 G_CALLBACK (xg_tool_bar_detach_callback), f);
4289 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-attached", 4312 g_signal_connect (G_OBJECT (x->handlebox_widget), "child-attached",
@@ -4291,34 +4314,40 @@ xg_pack_tool_bar (FRAME_PTR f, Lisp_Object pos)
4291 gtk_container_add (GTK_CONTAINER (x->handlebox_widget), 4314 gtk_container_add (GTK_CONTAINER (x->handlebox_widget),
4292 x->toolbar_widget); 4315 x->toolbar_widget);
4293 } 4316 }
4317#endif
4294 4318
4295 if (into_hbox) 4319 if (into_hbox)
4296 { 4320 {
4321#ifdef HAVE_GTK_HANDLE_BOX_NEW
4297 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (x->handlebox_widget), 4322 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (x->handlebox_widget),
4298 GTK_POS_TOP); 4323 GTK_POS_TOP);
4299 gtk_box_pack_start (GTK_BOX (x->hbox_widget), x->handlebox_widget, 4324#endif
4325 gtk_box_pack_start (GTK_BOX (x->hbox_widget), top_widget,
4300 FALSE, FALSE, 0); 4326 FALSE, FALSE, 0);
4301 4327
4302 if (EQ (pos, Qleft)) 4328 if (EQ (pos, Qleft))
4303 gtk_box_reorder_child (GTK_BOX (x->hbox_widget), 4329 gtk_box_reorder_child (GTK_BOX (x->hbox_widget),
4304 x->handlebox_widget, 4330 top_widget,
4305 0); 4331 0);
4306 x->toolbar_in_hbox = 1; 4332 x->toolbar_in_hbox = true;
4307 } 4333 }
4308 else 4334 else
4309 { 4335 {
4310 bool vbox_pos = x->menubar_widget != 0; 4336 bool vbox_pos = x->menubar_widget != 0;
4337#ifdef HAVE_GTK_HANDLE_BOX_NEW
4311 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (x->handlebox_widget), 4338 gtk_handle_box_set_handle_position (GTK_HANDLE_BOX (x->handlebox_widget),
4312 GTK_POS_LEFT); 4339 GTK_POS_LEFT);
4313 gtk_box_pack_start (GTK_BOX (x->vbox_widget), x->handlebox_widget, 4340#endif
4341 gtk_box_pack_start (GTK_BOX (x->vbox_widget), top_widget,
4314 FALSE, FALSE, 0); 4342 FALSE, FALSE, 0);
4315 4343
4316 if (EQ (pos, Qtop)) 4344 if (EQ (pos, Qtop))
4317 gtk_box_reorder_child (GTK_BOX (x->vbox_widget), 4345 gtk_box_reorder_child (GTK_BOX (x->vbox_widget),
4318 x->handlebox_widget, 4346 top_widget,
4319 vbox_pos); 4347 vbox_pos);
4320 x->toolbar_in_hbox = 0; 4348 x->toolbar_in_hbox = false;
4321 } 4349 }
4350 x->toolbar_is_packed = true;
4322} 4351}
4323 4352
4324/* Create a tool bar for frame F. */ 4353/* Create a tool bar for frame F. */
@@ -4561,13 +4590,14 @@ xg_update_tool_bar_sizes (FRAME_PTR f)
4561 struct x_output *x = f->output_data.x; 4590 struct x_output *x = f->output_data.x;
4562 GtkRequisition req; 4591 GtkRequisition req;
4563 int nl = 0, nr = 0, nt = 0, nb = 0; 4592 int nl = 0, nr = 0, nt = 0, nb = 0;
4593 GtkWidget *top_widget = TOOLBAR_TOP_WIDGET (x);
4564 4594
4565 gtk_widget_get_preferred_size (GTK_WIDGET (x->handlebox_widget), NULL, &req); 4595 gtk_widget_get_preferred_size (GTK_WIDGET (top_widget), NULL, &req);
4566 if (x->toolbar_in_hbox) 4596 if (x->toolbar_in_hbox)
4567 { 4597 {
4568 int pos; 4598 int pos;
4569 gtk_container_child_get (GTK_CONTAINER (x->hbox_widget), 4599 gtk_container_child_get (GTK_CONTAINER (x->hbox_widget),
4570 x->handlebox_widget, 4600 top_widget,
4571 "position", &pos, NULL); 4601 "position", &pos, NULL);
4572 if (pos == 0) nl = req.width; 4602 if (pos == 0) nl = req.width;
4573 else nr = req.width; 4603 else nr = req.width;
@@ -4576,7 +4606,7 @@ xg_update_tool_bar_sizes (FRAME_PTR f)
4576 { 4606 {
4577 int pos; 4607 int pos;
4578 gtk_container_child_get (GTK_CONTAINER (x->vbox_widget), 4608 gtk_container_child_get (GTK_CONTAINER (x->vbox_widget),
4579 x->handlebox_widget, 4609 top_widget,
4580 "position", &pos, NULL); 4610 "position", &pos, NULL);
4581 if (pos == 0 || (pos == 1 && x->menubar_widget)) nt = req.height; 4611 if (pos == 0 || (pos == 1 && x->menubar_widget)) nt = req.height;
4582 else nb = req.height; 4612 else nb = req.height;
@@ -4611,7 +4641,6 @@ update_frame_tool_bar (FRAME_PTR f)
4611 GtkToolbar *wtoolbar; 4641 GtkToolbar *wtoolbar;
4612 GtkToolItem *ti; 4642 GtkToolItem *ti;
4613 GtkTextDirection dir; 4643 GtkTextDirection dir;
4614 bool pack_tool_bar = x->handlebox_widget == NULL;
4615 Lisp_Object style; 4644 Lisp_Object style;
4616 bool text_image, horiz; 4645 bool text_image, horiz;
4617 struct xg_frame_tb_info *tbinfo; 4646 struct xg_frame_tb_info *tbinfo;
@@ -4865,9 +4894,9 @@ update_frame_tool_bar (FRAME_PTR f)
4865 4894
4866 if (f->n_tool_bar_items != 0) 4895 if (f->n_tool_bar_items != 0)
4867 { 4896 {
4868 if (pack_tool_bar) 4897 if (! x->toolbar_is_packed)
4869 xg_pack_tool_bar (f, f->tool_bar_position); 4898 xg_pack_tool_bar (f, f->tool_bar_position);
4870 gtk_widget_show_all (GTK_WIDGET (x->handlebox_widget)); 4899 gtk_widget_show_all (TOOLBAR_TOP_WIDGET (x));
4871 if (xg_update_tool_bar_sizes (f)) 4900 if (xg_update_tool_bar_sizes (f))
4872 xg_height_or_width_changed (f); 4901 xg_height_or_width_changed (f);
4873 } 4902 }
@@ -4886,24 +4915,26 @@ free_frame_tool_bar (FRAME_PTR f)
4886 if (x->toolbar_widget) 4915 if (x->toolbar_widget)
4887 { 4916 {
4888 struct xg_frame_tb_info *tbinfo; 4917 struct xg_frame_tb_info *tbinfo;
4889 bool is_packed = x->handlebox_widget != 0; 4918 GtkWidget *top_widget = TOOLBAR_TOP_WIDGET (x);
4919
4890 block_input (); 4920 block_input ();
4891 /* We may have created the toolbar_widget in xg_create_tool_bar, but 4921 /* We may have created the toolbar_widget in xg_create_tool_bar, but
4892 not the x->handlebox_widget which is created in xg_pack_tool_bar. */ 4922 not the x->handlebox_widget which is created in xg_pack_tool_bar. */
4893 if (is_packed) 4923 if (x->toolbar_is_packed)
4894 { 4924 {
4895 if (x->toolbar_in_hbox) 4925 if (x->toolbar_in_hbox)
4896 gtk_container_remove (GTK_CONTAINER (x->hbox_widget), 4926 gtk_container_remove (GTK_CONTAINER (x->hbox_widget),
4897 x->handlebox_widget); 4927 top_widget);
4898 else 4928 else
4899 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), 4929 gtk_container_remove (GTK_CONTAINER (x->vbox_widget),
4900 x->handlebox_widget); 4930 top_widget);
4901 } 4931 }
4902 else 4932 else
4903 gtk_widget_destroy (x->toolbar_widget); 4933 gtk_widget_destroy (x->toolbar_widget);
4904 4934
4905 x->toolbar_widget = 0; 4935 x->toolbar_widget = 0;
4906 x->handlebox_widget = 0; 4936 TOOLBAR_TOP_WIDGET (x) = 0;
4937 x->toolbar_is_packed = false;
4907 FRAME_TOOLBAR_TOP_HEIGHT (f) = FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = 0; 4938 FRAME_TOOLBAR_TOP_HEIGHT (f) = FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = 0;
4908 FRAME_TOOLBAR_LEFT_WIDTH (f) = FRAME_TOOLBAR_RIGHT_WIDTH (f) = 0; 4939 FRAME_TOOLBAR_LEFT_WIDTH (f) = FRAME_TOOLBAR_RIGHT_WIDTH (f) = 0;
4909 4940
@@ -4927,20 +4958,25 @@ void
4927xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos) 4958xg_change_toolbar_position (FRAME_PTR f, Lisp_Object pos)
4928{ 4959{
4929 struct x_output *x = f->output_data.x; 4960 struct x_output *x = f->output_data.x;
4961 GtkWidget *top_widget = TOOLBAR_TOP_WIDGET (x);
4930 4962
4931 if (! x->toolbar_widget || ! x->handlebox_widget) 4963 if (! x->toolbar_widget || ! top_widget)
4932 return; 4964 return;
4933 4965
4934 block_input (); 4966 block_input ();
4935 g_object_ref (x->handlebox_widget); 4967 g_object_ref (top_widget);
4936 if (x->toolbar_in_hbox) 4968 if (x->toolbar_is_packed)
4937 gtk_container_remove (GTK_CONTAINER (x->hbox_widget), 4969 {
4938 x->handlebox_widget); 4970 if (x->toolbar_in_hbox)
4939 else 4971 gtk_container_remove (GTK_CONTAINER (x->hbox_widget),
4940 gtk_container_remove (GTK_CONTAINER (x->vbox_widget), 4972 top_widget);
4941 x->handlebox_widget); 4973 else
4974 gtk_container_remove (GTK_CONTAINER (x->vbox_widget),
4975 top_widget);
4976 }
4977
4942 xg_pack_tool_bar (f, pos); 4978 xg_pack_tool_bar (f, pos);
4943 g_object_unref (x->handlebox_widget); 4979 g_object_unref (top_widget);
4944 if (xg_update_tool_bar_sizes (f)) 4980 if (xg_update_tool_bar_sizes (f))
4945 xg_height_or_width_changed (f); 4981 xg_height_or_width_changed (f);
4946 4982
@@ -4966,7 +5002,9 @@ xg_initialize (void)
4966 5002
4967 gdpy_def = NULL; 5003 gdpy_def = NULL;
4968 xg_ignore_gtk_scrollbar = 0; 5004 xg_ignore_gtk_scrollbar = 0;
5005#ifdef HAVE_GTK_TEAROFF_MENU_ITEM_NEW
4969 xg_detached_menus = 0; 5006 xg_detached_menus = 0;
5007#endif
4970 xg_menu_cb_list.prev = xg_menu_cb_list.next = 5008 xg_menu_cb_list.prev = xg_menu_cb_list.next =
4971 xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0; 5009 xg_menu_item_cb_list.prev = xg_menu_item_cb_list.next = 0;
4972 5010