]> git.eshelyaron.com Git - emacs.git/commitdiff
(update_frame_tool_bar): Connect create-menu-proxy with
authorJan Djärv <jan.h.d@swipnet.se>
Sun, 31 Dec 2006 18:31:49 +0000 (18:31 +0000)
committerJan Djärv <jan.h.d@swipnet.se>
Sun, 31 Dec 2006 18:31:49 +0000 (18:31 +0000)
xg_tool_bar_menu_proxy.
(xg_tool_bar_menu_proxy): New function.
(xg_tool_bar_proxy_callback): New function.

src/ChangeLog
src/gtkutil.c

index 71464f365ae1d377a2575b34476b21a11ca58ebc..3dc5a094d4a63dcf5bc27c570ab0e9f39955df1c 100644 (file)
@@ -1,3 +1,10 @@
+2006-12-31  Jan Dj\e,Ad\e(Brv  <jan.h.d@swipnet.se>
+
+       * gtkutil.c (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.
+
 2006-12-30  Jan Dj\e,Ad\e(Brv  <jan.h.d@swipnet.se>
 
        * gtkutil.c (xg_tool_bar_button_cb): Save last modifier on widget.
index b276c9fe7a10481869ec97661eb04cabd9d7f814..3dcdef2b0ae19315844f0e33a76ccaf5e0b2acf1 100644 (file)
@@ -3350,6 +3350,8 @@ xg_set_toolkit_scroll_bar_thumb (bar, portion, position, whole)
    get them.  */
 #define XG_TOOL_BAR_LAST_MODIFIER "emacs-tool-bar-modifier"
 
+/* The key for storing the button widget in its proxy menu item. */
+#define XG_TOOL_BAR_PROXY_BUTTON "emacs-tool-bar-proxy-button"
 
 static gboolean
 xg_tool_bar_button_cb (widget, event, user_data)
@@ -3406,6 +3408,92 @@ xg_tool_bar_callback (w, client_data)
   kbd_buffer_store_event (&event);
 }
 
+/* Callback function invoked when a tool bar item is pressed in a detached
+   tool bar or the overflow drop down menu.
+   We just call xg_tool_bar_callback.
+   W is the menu item widget that got pressed,
+   CLIENT_DATA is an integer that is the index of the button in the
+   tool bar.  0 is the first button.  */
+
+static void
+xg_tool_bar_proxy_callback (w, client_data)
+     GtkWidget *w;
+     gpointer client_data;
+{
+  GtkWidget *wbutton = GTK_WIDGET (g_object_get_data (G_OBJECT (w),
+                                                      XG_TOOL_BAR_PROXY_BUTTON));
+  xg_tool_bar_callback (wbutton, client_data);
+}
+
+/* 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 (toolitem, user_data)
+     GtkToolItem *toolitem;
+     gpointer user_data;
+{
+  GtkWidget *weventbox = gtk_bin_get_child (GTK_BIN (toolitem));
+  GtkButton *wbutton = GTK_BUTTON (gtk_bin_get_child (GTK_BIN (weventbox)));
+  GtkWidget *wmenuitem = gtk_image_menu_item_new ();
+  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
+    {
+      GtkImage *wimage = GTK_IMAGE (gtk_bin_get_child (GTK_BIN (wbutton)));
+      GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (wbutton));
+      GtkImageType store_type = gtk_image_get_storage_type (wimage);
+      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);
+            }
+        }
+    }
+  if (wmenuimage)
+    gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (wmenuitem), wmenuimage);
+
+  g_signal_connect (G_OBJECT (wmenuitem),
+                    "activate",
+                    GTK_SIGNAL_FUNC (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);
+
+  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.
@@ -3727,6 +3815,7 @@ update_frame_tool_bar (f)
               /* Insert an empty (non-image) button */
               weventbox = gtk_event_box_new ();
               wbutton = gtk_button_new ();
+              gtk_button_set_focus_on_click (GTK_BUTTON (wbutton), FALSE);
               gtk_button_set_relief (GTK_BUTTON (wbutton), GTK_RELIEF_NONE);
               gtk_container_add (GTK_CONTAINER (weventbox), wbutton);
               ti = gtk_tool_item_new ();
@@ -3741,6 +3830,7 @@ update_frame_tool_bar (f)
           GtkWidget *w = xg_get_image_for_pixmap (f, img, x->widget, NULL);
           gtk_misc_set_padding (GTK_MISC (w), hmargin, vmargin);
           wbutton = gtk_button_new ();
+          gtk_button_set_focus_on_click (GTK_BUTTON (wbutton), FALSE);
           gtk_button_set_relief (GTK_BUTTON (wbutton), GTK_RELIEF_NONE);
           gtk_container_add (GTK_CONTAINER (wbutton), w);
           weventbox = gtk_event_box_new ();
@@ -3751,7 +3841,11 @@ update_frame_tool_bar (f)
 
 
           /* The EMACS_INT cast avoids a warning. */
-          g_signal_connect (wbutton, "clicked",
+          g_signal_connect (G_OBJECT (ti), "create-menu-proxy",
+                            GTK_SIGNAL_FUNC (xg_tool_bar_menu_proxy),
+                            (gpointer) (EMACS_INT) i);
+
+          g_signal_connect (G_OBJECT (wbutton), "clicked",
                             GTK_SIGNAL_FUNC (xg_tool_bar_callback),
                             (gpointer) (EMACS_INT) i);