]> Pileus Git - ~andy/gtk/commitdiff
Call gtk_tool_item_rebuild_menu().
authorSøren Sandmann <sandmann@redhat.com>
Tue, 14 Sep 2004 21:40:41 +0000 (21:40 +0000)
committerSøren Sandmann Pedersen <ssp@src.gnome.org>
Tue, 14 Sep 2004 21:40:41 +0000 (21:40 +0000)
Tue Sep 14 23:20:56 2004  Søren Sandmann  <sandmann@redhat.com>

* gtk/gtkaction.c (connect_proxy): Call
gtk_tool_item_rebuild_menu().

* gtk/gtktoolitem.c (gtk_tool_item_class_init): Update
documentation for GtkToolItem::create_menu_proxy.

* gtk/gtktoolitem.c (gtk_tool_item_rebuild_menu): New
API to make the toolbar update itself when the proxy menu item
for a tool item changes.

* gtk/gtktoolbutton.c (gtk_tool_button_construct_contents): Call
gtk_tool_item_rebuild_menu here()

* gtk/gtktoolbutton.c (gtk_tool_button_construct_contents):
Remove redundant check for need_label.

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtkaction.c
gtk/gtktoolbar.c
gtk/gtktoolbar.h
gtk/gtktoolbutton.c
gtk/gtktoolitem.c
gtk/gtktoolitem.h

index a423f7659208ad81281883cf0111cc7a97bbf1dd..ad5e2484f68b0db55e0b0604c39100d6bdb5c808 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+Tue Sep 14 23:20:56 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtkaction.c (connect_proxy): Call
+       gtk_tool_item_rebuild_menu().
+
+       * gtk/gtktoolitem.c (gtk_tool_item_class_init): Update
+       documentation for GtkToolItem::create_menu_proxy.
+
+       * gtk/gtktoolitem.c (gtk_tool_item_rebuild_menu): New
+       API to make the toolbar update itself when the proxy menu item
+       for a tool item changes.
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents): Call
+       gtk_tool_item_rebuild_menu here()
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents):
+       Remove redundant check for need_label.
+
 2004-09-14  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkmain.c (do_post_parse_initialization): Remove an unused 
index a423f7659208ad81281883cf0111cc7a97bbf1dd..ad5e2484f68b0db55e0b0604c39100d6bdb5c808 100644 (file)
@@ -1,3 +1,21 @@
+Tue Sep 14 23:20:56 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtkaction.c (connect_proxy): Call
+       gtk_tool_item_rebuild_menu().
+
+       * gtk/gtktoolitem.c (gtk_tool_item_class_init): Update
+       documentation for GtkToolItem::create_menu_proxy.
+
+       * gtk/gtktoolitem.c (gtk_tool_item_rebuild_menu): New
+       API to make the toolbar update itself when the proxy menu item
+       for a tool item changes.
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents): Call
+       gtk_tool_item_rebuild_menu here()
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents):
+       Remove redundant check for need_label.
+
 2004-09-14  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkmain.c (do_post_parse_initialization): Remove an unused 
index a423f7659208ad81281883cf0111cc7a97bbf1dd..ad5e2484f68b0db55e0b0604c39100d6bdb5c808 100644 (file)
@@ -1,3 +1,21 @@
+Tue Sep 14 23:20:56 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtkaction.c (connect_proxy): Call
+       gtk_tool_item_rebuild_menu().
+
+       * gtk/gtktoolitem.c (gtk_tool_item_class_init): Update
+       documentation for GtkToolItem::create_menu_proxy.
+
+       * gtk/gtktoolitem.c (gtk_tool_item_rebuild_menu): New
+       API to make the toolbar update itself when the proxy menu item
+       for a tool item changes.
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents): Call
+       gtk_tool_item_rebuild_menu here()
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents):
+       Remove redundant check for need_label.
+
 2004-09-14  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkmain.c (do_post_parse_initialization): Remove an unused 
index a423f7659208ad81281883cf0111cc7a97bbf1dd..ad5e2484f68b0db55e0b0604c39100d6bdb5c808 100644 (file)
@@ -1,3 +1,21 @@
+Tue Sep 14 23:20:56 2004  Søren Sandmann  <sandmann@redhat.com>
+
+       * gtk/gtkaction.c (connect_proxy): Call
+       gtk_tool_item_rebuild_menu().
+
+       * gtk/gtktoolitem.c (gtk_tool_item_class_init): Update
+       documentation for GtkToolItem::create_menu_proxy.
+
+       * gtk/gtktoolitem.c (gtk_tool_item_rebuild_menu): New
+       API to make the toolbar update itself when the proxy menu item
+       for a tool item changes.
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents): Call
+       gtk_tool_item_rebuild_menu here()
+
+       * gtk/gtktoolbutton.c (gtk_tool_button_construct_contents):
+       Remove redundant check for need_label.
+
 2004-09-14  Matthias Clasen  <mclasen@redhat.com>
 
        * gtk/gtkmain.c (do_post_parse_initialization): Remove an unused 
index c946f79b214ccd35ac346bd71ba5e81fcfa80c2c..d154b9582d625e7e1f5ee14587df468237f93906 100644 (file)
@@ -869,9 +869,9 @@ connect_proxy (GtkAction     *action,
        }
 
       if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)) == NULL)
-      g_signal_connect_object (proxy, "activate",
-                              G_CALLBACK (gtk_action_activate), action,
-                              G_CONNECT_SWAPPED);
+       g_signal_connect_object (proxy, "activate",
+                                G_CALLBACK (gtk_action_activate), action,
+                                G_CONNECT_SWAPPED);
 
     }
   else if (GTK_IS_TOOL_ITEM (proxy))
@@ -903,6 +903,8 @@ connect_proxy (GtkAction     *action,
                               G_CALLBACK (gtk_action_create_menu_proxy),
                               action, 0);
 
+      gtk_tool_item_rebuild_menu (GTK_TOOL_ITEM (proxy));
+
       /* toolbar button specific synchronisers ... */
       if (GTK_IS_TOOL_BUTTON (proxy))
        {
@@ -920,10 +922,10 @@ connect_proxy (GtkAction     *action,
          g_signal_connect_object (action, "notify::stock-id",
                                   G_CALLBACK (gtk_action_sync_property), 
                                   proxy, 0);
-      g_signal_connect_object (proxy, "clicked",
-                              G_CALLBACK (gtk_action_activate), action,
-                              G_CONNECT_SWAPPED);
-    }
+         g_signal_connect_object (proxy, "clicked",
+                                  G_CALLBACK (gtk_action_activate), action,
+                                  G_CONNECT_SWAPPED);
+       }
     }
   else if (GTK_IS_BUTTON (proxy))
     {
index a53a24ffb1862e0c6da8442199034071c7ce3aa1..d00dac3d629d67800ca699b8009f58d103642909 100644 (file)
@@ -1234,7 +1234,7 @@ gtk_toolbar_begin_sliding (GtkToolbar *toolbar)
     }
 
   /* This resize will run before the first idle handler. This
-   * will make sure that items get the right goal allocatiuon
+   * will make sure that items get the right goal allocation
    * so that the idle handler will not immediately return
    * FALSE
    */
@@ -3734,6 +3734,12 @@ internal_insert_element (GtkToolbar          *toolbar,
 /*
  * ToolbarContent methods
  */
+typedef enum {
+  UNKNOWN,
+  YES,
+  NO,
+} TriState;
+
 struct _ToolbarContent
 {
   ContentType  type;
@@ -3748,6 +3754,7 @@ struct _ToolbarContent
       GtkAllocation    goal_allocation;
       guint            is_placeholder : 1;
       guint            disappearing : 1;
+      TriState         has_menu : 2;
     } tool_item;
     
     struct
@@ -4238,8 +4245,11 @@ toolbar_content_set_child_visible (ToolbarContent *content,
        }
       else
        {
-         content->u.compatibility.space_visible = visible;
-         gtk_widget_queue_draw (GTK_WIDGET (toolbar));
+         if (content->u.compatibility.space_visible != visible)
+           {
+             content->u.compatibility.space_visible = visible;
+             gtk_widget_queue_draw (GTK_WIDGET (toolbar));
+           }
        }
       break;
     }
@@ -4470,13 +4480,34 @@ toolbar_content_retrieve_menu_item (ToolbarContent *content)
 static gboolean
 toolbar_content_has_proxy_menu_item (ToolbarContent *content)
 {
-  GtkWidget *menu_item;
+  if (content->type == TOOL_ITEM)
+    {
+      GtkWidget *menu_item;
 
-  menu_item = toolbar_content_retrieve_menu_item (content);
+      if (content->u.tool_item.has_menu == YES)
+       return TRUE;
+      else if (content->u.tool_item.has_menu == NO)
+       return FALSE;
 
-  return menu_item != NULL;
+      menu_item = toolbar_content_retrieve_menu_item (content);
+
+      content->u.tool_item.has_menu = menu_item? YES : NO;
+      
+      return menu_item != NULL;
+    }
+  else
+    {
+      return FALSE;
+    }
 }
+
+static void
+toolbar_content_set_unknown_menu_status (ToolbarContent *content)
+{
+  if (content->type == TOOL_ITEM)
+    content->u.tool_item.has_menu = UNKNOWN;
+}
+
 static gboolean
 toolbar_content_is_separator (ToolbarContent *content)
 {
@@ -4723,3 +4754,21 @@ _gtk_toolbar_elide_underscores (const gchar *original)
   
   return result;
 }
+
+void
+_gtk_toolbar_rebuild_menu (GtkToolbar *toolbar)
+{
+  GtkToolbarPrivate *priv = GTK_TOOLBAR_GET_PRIVATE (toolbar);
+  GList *list;
+
+  priv->need_rebuild = TRUE;
+
+  for (list = priv->content; list != NULL; list = list->next)
+    {
+      ToolbarContent *content = list->data;
+
+      toolbar_content_set_unknown_menu_status (content);
+    }
+  
+  gtk_widget_queue_resize (GTK_WIDGET (toolbar));
+}
index 3b005bb930ab60c32a464fe9017b0baa6281badc..fd616ddbee5594344367b5f19430a0ecdcfbc1da 100644 (file)
@@ -173,7 +173,6 @@ void            _gtk_toolbar_paint_space_line       (GtkWidget       *widget,
 gint            _gtk_toolbar_get_default_space_size (void);
 
 
-
 /* deprecated */
 #ifndef GTK_DISABLE_DEPRECATED
 void       gtk_toolbar_set_icon_size   (GtkToolbar      *toolbar,
index b96a3a009d5cc7df25cff733bbb9de157662f30f..5b5eb1cc6d25acf069ffd0b70eb8711a3d1efaff 100644 (file)
@@ -262,14 +262,6 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
   GtkIconSize icon_size;
   GtkWidget *box = NULL;
 
-  if (gtk_tool_item_get_proxy_menu_item (tool_item, MENU_ID))
-    {
-      /* Remove item, so it will be recreated on the next
-       * create_proxy_menu_item()
-       */
-      gtk_tool_item_set_proxy_menu_item (tool_item, MENU_ID, NULL);
-    }
-  
   if (button->priv->icon_widget && button->priv->icon_widget->parent)
     {
       gtk_container_remove (GTK_CONTAINER (button->priv->icon_widget->parent),
@@ -304,12 +296,7 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
     {
       need_label = TRUE;
     }
-  
-  if (style != GTK_TOOLBAR_ICONS &&
-      ((style != GTK_TOOLBAR_BOTH_HORIZ ||
-       gtk_tool_item_get_is_important (GTK_TOOL_ITEM (button)))))
-    need_label = TRUE;
-  
+
   if (need_label)
     {
       if (button->priv->label_widget)
@@ -407,6 +394,8 @@ gtk_tool_button_construct_contents (GtkToolItem *tool_item)
   gtk_button_set_relief (GTK_BUTTON (button->priv->button),
                         gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (button)));
 
+  gtk_tool_item_rebuild_menu (tool_item);
+  
   gtk_widget_queue_resize (GTK_WIDGET (button));
 }
 
index 97461f36cb7e7c05d7b9ddec1cea91bf23204bef..b33677a9907812c533f3e93d6ee44360071b3949 100644 (file)
@@ -179,8 +179,9 @@ gtk_tool_item_class_init (GtkToolItemClass *klass)
  * GtkToolItem::create-menu-proxy:
  * @toolitem: the object the signal was emitted on
  *
- * This signal is emitted when the toolbar is displaying an overflow menu.
- * In response the tool item should either 
+ * This signal is emitted when the toolbar needs information from @tool_item
+ * about whether the item should appear in the toolbar overflow menu. In
+ * response the tool item should either
  * <itemizedlist>
  * <listitem> call gtk_tool_item_set_proxy_menu_item() with a %NULL
  * pointer and return %TRUE to indicate that the item should not appear
@@ -195,7 +196,12 @@ gtk_tool_item_class_init (GtkToolItemClass *klass)
  * installs a menu item.
  * </listitem>
  * </itemizedlist>
- * 
+ *
+ * The toolbar may cache the result of this signal. When the tool item changes
+ * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
+ * to invalidate the cache and ensure that the toolbar rebuilds its overflow
+ * menu.
+ *
  * Return value: %TRUE if the signal was handled, %FALSE if not
  **/
   toolitem_signals[CREATE_MENU_PROXY] =
@@ -1004,7 +1010,8 @@ gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
   
   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
 
-  g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0, &retval);
+  g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
+                &retval);
   
   return tool_item->priv->menu_item;
 }
@@ -1040,6 +1047,34 @@ gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
   return NULL;
 }
 
+/**
+ * gtk_tool_item_rebuild_menu()
+ * @tool_item: a #GtkToolItem
+ * 
+ * Calling this function signals to the toolbar that the
+ * overflow menu item for @tool_item has changed. If the
+ * overflow menu is visible when this function it called,
+ * the menu will be rebuilt.
+ *
+ * The function must be called when the tool item
+ * changes what it will do in response to the "create_menu_proxy"
+ * signal.
+ * 
+ * Since: 2.6
+ **/
+void
+gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
+{
+  GtkWidget *widget;
+  
+  g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
+
+  widget = GTK_WIDGET (tool_item);
+  
+  if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
+    _gtk_toolbar_rebuild_menu (GTK_TOOLBAR (widget->parent));
+}
+
 /**
  * gtk_tool_item_set_proxy_menu_item:
  * @tool_item: a #GtkToolItem:
index f6d7950d12bc4f5ae046e32681dbb33b6fec41d7..1293585f6dbb2dcce1ac973861a32f3251d44354 100644 (file)
@@ -110,6 +110,7 @@ GtkWidget *     gtk_tool_item_get_proxy_menu_item      (GtkToolItem *tool_item,
 void            gtk_tool_item_set_proxy_menu_item      (GtkToolItem *tool_item,
                                                        const gchar *menu_item_id,
                                                        GtkWidget   *menu_item);
+void           gtk_tool_item_rebuild_menu             (GtkToolItem *tool_item);
 
 /* internal function */
 void       _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item);