-/* This callback is called when a tool item should create a proxy item,
- such as for the overflow menu. Also called when the tool bar is detached.
- If we don't create a proxy menu item, the detached tool bar will be
- blank. */
-
-static gboolean
-xg_tool_bar_menu_proxy (GtkToolItem *toolitem, gpointer user_data)
-{
- GtkButton *wbutton = GTK_BUTTON (XG_BIN_CHILD (XG_BIN_CHILD (toolitem)));
- GtkWidget *vb = XG_BIN_CHILD (wbutton);
- GtkWidget *c1;
- GtkLabel *wlbl = GTK_LABEL (xg_get_tool_bar_widgets (vb, &c1));
- GtkImage *wimage = GTK_IMAGE (c1);
- GtkWidget *wmenuitem = gtk_image_menu_item_new_with_label
- (wlbl ? gtk_label_get_text (wlbl) : "");
- GtkWidget *wmenuimage;
-
-
- if (gtk_button_get_use_stock (wbutton))
- wmenuimage = gtk_image_new_from_stock (gtk_button_get_label (wbutton),
- GTK_ICON_SIZE_MENU);
- else
- {
- GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (wbutton));
- GtkImageType store_type = gtk_image_get_storage_type (wimage);
-
- g_object_set (G_OBJECT (settings), "gtk-menu-images", TRUE, NULL);
-
- if (store_type == GTK_IMAGE_STOCK)
- {
- gchar *stock_id;
- gtk_image_get_stock (wimage, &stock_id, NULL);
- wmenuimage = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
- }
- else if (store_type == GTK_IMAGE_ICON_SET)
- {
- GtkIconSet *icon_set;
- gtk_image_get_icon_set (wimage, &icon_set, NULL);
- wmenuimage = gtk_image_new_from_icon_set (icon_set,
- GTK_ICON_SIZE_MENU);
- }
- else if (store_type == GTK_IMAGE_PIXBUF)
- {
- gint width, height;
-
- if (settings &&
- gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU,
- &width, &height))
- {
- GdkPixbuf *src_pixbuf, *dest_pixbuf;
-
- src_pixbuf = gtk_image_get_pixbuf (wimage);
- dest_pixbuf = gdk_pixbuf_scale_simple (src_pixbuf, width, height,
- GDK_INTERP_BILINEAR);
-
- wmenuimage = gtk_image_new_from_pixbuf (dest_pixbuf);
- }
- else
- {
- fprintf (stderr, "internal error: GTK_IMAGE_PIXBUF failed\n");
- emacs_abort ();
- }
- }
- else if (store_type == GTK_IMAGE_ICON_NAME)
- {
- const gchar *icon_name;
- GtkIconSize icon_size;
-
- gtk_image_get_icon_name (wimage, &icon_name, &icon_size);
- wmenuimage = gtk_image_new_from_icon_name (icon_name,
- GTK_ICON_SIZE_MENU);
- }
- else
- {
- fprintf (stderr, "internal error: store_type is %d\n", store_type);
- emacs_abort ();
- }
- }
- if (wmenuimage)
- gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (wmenuitem), wmenuimage);
-
- g_signal_connect (G_OBJECT (wmenuitem),
- "activate",
- G_CALLBACK (xg_tool_bar_proxy_callback),
- user_data);
-
-
- g_object_set_data (G_OBJECT (wmenuitem), XG_TOOL_BAR_PROXY_BUTTON,
- (gpointer) wbutton);
- gtk_tool_item_set_proxy_menu_item (toolitem, "Emacs toolbar item", wmenuitem);
- gtk_widget_set_sensitive (wmenuitem,
- gtk_widget_get_sensitive (GTK_WIDGET (wbutton)));
-
- /* Use enter/leave notify to show help. We use the events
- rather than the GtkButton specific signals "enter" and
- "leave", so we can have only one callback. The event
- will tell us what kind of event it is. */
- g_signal_connect (G_OBJECT (wmenuitem),
- "enter-notify-event",
- G_CALLBACK (xg_tool_bar_proxy_help_callback),
- user_data);
- g_signal_connect (G_OBJECT (wmenuitem),
- "leave-notify-event",
- G_CALLBACK (xg_tool_bar_proxy_help_callback),
- user_data);
-
- return TRUE;
-}
-
-/* This callback is called when a tool bar is detached. We must set
- the height of the tool bar to zero when this happens so frame sizes
- are correctly calculated.
- WBOX is the handle box widget that enables detach/attach of the tool bar.
- W is the tool bar widget.
- CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
-
-static void
-xg_tool_bar_detach_callback (GtkHandleBox *wbox,
- GtkWidget *w,
- gpointer client_data)
-{
- struct frame *f = client_data;
-
- g_object_set (G_OBJECT (w), "show-arrow", !x_gtk_whole_detached_tool_bar,
- NULL);
-
- if (f)
- {
- GtkRequisition req, req2;
-
- gtk_widget_get_preferred_size (GTK_WIDGET (wbox), NULL, &req);
- gtk_widget_get_preferred_size (w, NULL, &req2);
- req.width -= req2.width;
- req.height -= req2.height;
- if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
- FRAME_TOOLBAR_TOP_HEIGHT (f) = req.height;
- else if (FRAME_TOOLBAR_BOTTOM_HEIGHT (f) != 0)
- FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = req.height;
- else if (FRAME_TOOLBAR_RIGHT_WIDTH (f) != 0)
- FRAME_TOOLBAR_RIGHT_WIDTH (f) = req.width;
- else if (FRAME_TOOLBAR_LEFT_WIDTH (f) != 0)
- FRAME_TOOLBAR_LEFT_WIDTH (f) = req.width;
- xg_height_or_width_changed (f);
- }
-}
-
-/* This callback is called when a tool bar is reattached. We must set
- the height of the tool bar when this happens so frame sizes
- are correctly calculated.
- WBOX is the handle box widget that enables detach/attach of the tool bar.
- W is the tool bar widget.
- CLIENT_DATA is a pointer to the frame the tool bar belongs to. */
-
-static void
-xg_tool_bar_attach_callback (GtkHandleBox *wbox,
- GtkWidget *w,
- gpointer client_data)
-{
- struct frame *f = client_data;
- g_object_set (G_OBJECT (w), "show-arrow", TRUE, NULL);
-
- if (f)
- {
- GtkRequisition req, req2;
-
- gtk_widget_get_preferred_size (GTK_WIDGET (wbox), NULL, &req);
- gtk_widget_get_preferred_size (w, NULL, &req2);
- req.width += req2.width;
- req.height += req2.height;
- if (FRAME_TOOLBAR_TOP_HEIGHT (f) != 0)
- FRAME_TOOLBAR_TOP_HEIGHT (f) = req.height;
- else if (FRAME_TOOLBAR_BOTTOM_HEIGHT (f) != 0)
- FRAME_TOOLBAR_BOTTOM_HEIGHT (f) = req.height;
- else if (FRAME_TOOLBAR_RIGHT_WIDTH (f) != 0)
- FRAME_TOOLBAR_RIGHT_WIDTH (f) = req.width;
- else if (FRAME_TOOLBAR_LEFT_WIDTH (f) != 0)
- FRAME_TOOLBAR_LEFT_WIDTH (f) = req.width;
- xg_height_or_width_changed (f);
- }
-}
-