File:  [mozdev] / epiphany / eggpatch
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Jul 22 11:11:49 2003 UTC (14 years, 4 months ago) by mpeseng
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

? libegg_diff
? libegg/dock
? libegg/combo/Makefile
? libegg/combo/Makefile.in
? libegg/recent-files/bonobo_view_test
? libegg/recent-files/gtk_view_test
? libegg/recent-files/populate_recent
? libegg/toolbar/test-drag
? libegg/treeviewutils/test-union
Index: libegg/menu/Makefile.am
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/Makefile.am,v
retrieving revision 1.11
diff -u -r1.11 Makefile.am
--- libegg/menu/Makefile.am	29 Jun 2003 18:11:35 -0000	1.11
+++ libegg/menu/Makefile.am	22 Jul 2003 11:09:10 -0000
@@ -3,8 +3,9 @@
   $(EGG_CFLAGS) \
   -DEGG_COMPILATION \
   -DGDK_DISABLE_DEPRECATED \
-  -DG_DISABLE_DEPRECATED
-
+  -DG_DISABLE_DEPRECATED \
+  -I$(top_builddir)/libegg/toolbar \
+  -I$(top_builddir)/libegg/util
 
 noinst_LTLIBRARIES = libegg-menu.la
 
Index: libegg/menu/egg-action-group.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-action-group.c,v
retrieving revision 1.6
diff -u -r1.6 egg-action-group.c
--- libegg/menu/egg-action-group.c	8 Jun 2002 13:00:48 -0000	1.6
+++ libegg/menu/egg-action-group.c	22 Jul 2003 11:09:11 -0000
@@ -1,10 +1,7 @@
 #include "egg-action-group.h"
 #include "egg-toggle-action.h"
 #include "egg-radio-action.h"
-
-#ifndef _
-# define _(s) (s)
-#endif
+#include "eggintl.h"
 
 static void egg_action_group_init       (EggActionGroup *self);
 static void egg_action_group_class_init (EggActionGroupClass *class);
Index: libegg/menu/egg-action-group.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-action-group.h,v
retrieving revision 1.3
diff -u -r1.3 egg-action-group.h
--- libegg/menu/egg-action-group.h	26 May 2002 09:13:37 -0000	1.3
+++ libegg/menu/egg-action-group.h	22 Jul 2003 11:09:11 -0000
@@ -2,7 +2,7 @@
 #define EGG_ACTION_GROUP_H
 
 #include <gtk/gtk.h>
-#include <libegg/menu/egg-action.h>
+#include <egg-action.h>
 
 #define EGG_TYPE_ACTION_GROUP              (egg_action_group_get_type ())
 #define EGG_ACTION_GROUP(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_ACTION_GROUP, EggActionGroup))
Index: libegg/menu/egg-action.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-action.c,v
retrieving revision 1.17
diff -u -r1.17 egg-action.c
--- libegg/menu/egg-action.c	9 May 2003 15:15:27 -0000	1.17
+++ libegg/menu/egg-action.c	22 Jul 2003 11:09:15 -0000
@@ -1,9 +1,8 @@
 #include "egg-action.h"
-#include "../toolbar/eggtoolbutton.h"
+#include "eggtoolbutton.h"
+#include "eggtoolbar.h"
+#include "eggintl.h"
 
-#ifndef _
-# define _(s) (s)
-#endif
 
 /* some code for making arbitrary GtkButtons that act like toolbar
  * buttons */
@@ -173,6 +172,8 @@
 static void
 egg_action_init (EggAction *action)
 {
+  static GtkTooltips *egg_action_tooltips = NULL;
+
   action->name = NULL;
   action->label = NULL;
   action->short_label = NULL;
@@ -188,6 +189,17 @@
   action->accel_quark = 0;
 
   action->proxies = NULL;
+
+  if (egg_action_tooltips == NULL)
+  {
+    egg_action_tooltips = gtk_tooltips_new ();
+    action->tooltips = g_object_ref (egg_action_tooltips);
+    gtk_object_sink (GTK_OBJECT (egg_action_tooltips));
+  }
+  else
+  {
+    action->tooltips = g_object_ref (egg_action_tooltips);
+  }
 }
 
 static void
@@ -197,6 +209,8 @@
 
   action = EGG_ACTION (object);
 
+  g_object_unref (action->tooltips);
+
   g_free (action->name);
   g_free (action->label);
   g_free (action->short_label);
@@ -370,6 +384,18 @@
 }
 
 static void
+egg_action_sync_tooltip (EggAction *action, GParamSpec *pspec, GtkWidget *proxy)
+{
+	if (action->tooltip != NULL)
+	{
+		egg_tool_item_set_tooltip (EGG_TOOL_ITEM (proxy),
+					   action->tooltips,
+					   action->tooltip,
+					   NULL);
+	}
+}
+
+static void
 egg_action_sync_label (EggAction *action, GParamSpec *pspec, GtkWidget *proxy)
 {
   GtkWidget *label = NULL;
@@ -536,6 +562,14 @@
 			       G_CALLBACK (egg_action_activate), action,
 			       G_CONNECT_SWAPPED);
     }
+
+    if (EGG_IS_TOOL_ITEM (proxy))
+    {
+      egg_action_sync_tooltip (action, NULL, proxy);
+      g_signal_connect_object (action, "notify::tooltip",
+			       G_CALLBACK (egg_action_sync_tooltip),
+			       proxy, 0);
+    }
 }
 
 static void
@@ -566,6 +600,10 @@
 
   g_signal_handlers_disconnect_by_func (action,
 				G_CALLBACK (egg_action_sync_stock_id), proxy);
+
+  g_signal_handlers_disconnect_by_func (proxy,
+					G_CALLBACK (egg_action_sync_tooltip),
+					action);			
 
   /* menu item specific synchronisers ... */
   g_signal_handlers_disconnect_by_func (action,
Index: libegg/menu/egg-action.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-action.h,v
retrieving revision 1.6
diff -u -r1.6 egg-action.h
--- libegg/menu/egg-action.h	8 Jun 2002 13:00:48 -0000	1.6
+++ libegg/menu/egg-action.h	22 Jul 2003 11:09:15 -0000
@@ -33,6 +33,8 @@
 
   /* list of proxy widgets */
   GSList *proxies;
+
+  GtkTooltips *tooltips;
 };
 
 struct _EggActionClass
Index: libegg/menu/egg-menu-merge.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-menu-merge.c,v
retrieving revision 1.26
diff -u -r1.26 egg-menu-merge.c
--- libegg/menu/egg-menu-merge.c	20 Apr 2003 14:28:50 -0000	1.26
+++ libegg/menu/egg-menu-merge.c	22 Jul 2003 11:09:20 -0000
@@ -1,11 +1,8 @@
 #include <string.h>
 #include "egg-menu-merge.h"
-#include "../toolbar/eggtoolbar.h"
-#include "../toolbar/eggseparatortoolitem.h"
-
-#ifndef _
-#  define _(string) (string)
-#endif
+#include "eggtoolbar.h"
+#include "eggseparatortoolitem.h"
+#include "eggintl.h"
 
 #define NODE_INFO(node) ((EggMenuMergeNode *)node->data)
 
@@ -75,9 +72,30 @@
   return type;
 }
 
+static GObjectClass *parent_class = NULL;
+
+static void
+egg_menu_merge_finalize (GObject *object)
+{
+  EggMenuMerge *merge;
+
+  merge = EGG_MENU_MERGE (object);
+  if (merge->update_tag != 0)
+    {
+      g_source_remove(merge->update_tag);
+    }
+}
+
 static void
 egg_menu_merge_class_init (EggMenuMergeClass *class)
 {
+  GObjectClass *object_class;
+
+  parent_class = g_type_class_peek_parent (class);
+  object_class = G_OBJECT_CLASS(class);
+
+  object_class->finalize     = egg_menu_merge_finalize;
+
   if (!merge_node_chunk)
     merge_node_chunk = g_mem_chunk_create(EggMenuMergeNode, 64,
 					  G_ALLOC_AND_FREE);
@@ -198,14 +216,6 @@
 		  /* if undecided about node type, set it */
 		  if (NODE_INFO(child)->type == EGG_MENU_MERGE_UNDECIDED)
 		    NODE_INFO(child)->type = node_type;
-		  
-		  /* warn about type mismatch */
-		  if (NODE_INFO(child)->type != EGG_MENU_MERGE_UNDECIDED &&
-		      NODE_INFO(child)->type != node_type)
-		    g_warning("node type doesn't match %d (%s is type %d)",
-			      node_type, NODE_INFO(child)->name,
-			      NODE_INFO(child)->type);
-		  
 		  return child;
 		}
 	    }
@@ -690,7 +700,7 @@
 
 guint
 egg_menu_merge_add_ui_from_string (EggMenuMerge *self,
-				   const gchar *buffer, guint length,
+				   const gchar *buffer, size_t length,
 				   GError **error)
 {
   ParseContext ctx = { 0 };
@@ -732,7 +742,7 @@
 				 GError **error)
 {
   gchar *buffer;
-  gint length;
+  size_t length;
   guint res;
 
   if (!g_file_get_contents (filename, &buffer, &length, error))
@@ -935,15 +945,10 @@
 
   info = NODE_INFO(node);
 
-  g_print("update_node name=%s dirty=%d (", info->name, info->dirty);
   for (tmp = info->uifiles; tmp != NULL; tmp = tmp->next)
     {
       NodeUIReference *ref = tmp->data;
-      g_print("%s:%u", g_quark_to_string(ref->action_quark), ref->merge_id);
-      if (tmp->next)
-	g_print(", ");
     }
-  g_print(")\n");
 
   if (NODE_INFO(node)->dirty)
     {
@@ -984,11 +989,7 @@
 	  goto recurse_children;
 	}
       
-      if (info->action)
-	g_object_unref (info->action);
       info->action = action;
-      if (info->action)
-	g_object_ref (info->action);
 
       switch (info->type)
 	{
@@ -1022,8 +1023,15 @@
 	      {
 		GtkWidget *menushell;
 		gint pos;
+		GNode *parent;
 
-		if (find_menu_position(node, &menushell, &pos))
+		parent = node->parent;
+
+		if (parent && NODE_INFO (parent)->type == EGG_MENU_MERGE_POPUPS)
+		  {
+		    info->proxy = gtk_menu_new();
+		  }
+		else if (find_menu_position(node, &menushell, &pos))
 		  {
 		    GtkWidget *menu;
 		    info->proxy = egg_action_create_menu_item (info->action);
@@ -1255,6 +1263,7 @@
 	   NODE_INFO(node)->type == EGG_MENU_MERGE_TOOLBAR_PLACEHOLDER) &&
 	  NODE_INFO(node)->extra)
 	gtk_widget_destroy(NODE_INFO(node)->extra);
+      g_free (NODE_INFO(node)->name);
       g_chunk_free(NODE_INFO(node), merge_node_chunk);
       g_node_destroy(node);
     }
@@ -1275,8 +1284,6 @@
    *    the proxy is reconnected to the new action (or a new proxy widget
    *    is created and added to the parent container).
    */
-
-  g_message("do_updates");
 
   update_node (self, self->root_node);
 
Index: libegg/menu/egg-menu-merge.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-menu-merge.h,v
retrieving revision 1.7
diff -u -r1.7 egg-menu-merge.h
--- libegg/menu/egg-menu-merge.h	7 Sep 2002 03:41:14 -0000	1.7
+++ libegg/menu/egg-menu-merge.h	22 Jul 2003 11:09:22 -0000
@@ -4,8 +4,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include <libegg/menu/egg-action.h>
-#include <libegg/menu/egg-action-group.h>
+#include <egg-action.h>
+#include <egg-action-group.h>
 
 #define EGG_TYPE_MENU_MERGE            (egg_menu_merge_get_type ())
 #define EGG_MENU_MERGE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_MENU_MERGE, EggMenuMerge))
@@ -55,7 +55,7 @@
 struct _EggMenuMergeNode {
   EggMenuMergeNodeType type;
 
-  const gchar *name;
+  gchar *name;
 
   GQuark action_name;
   EggAction *action;
@@ -86,7 +86,7 @@
  * interface */
 guint         egg_menu_merge_add_ui_from_string  (EggMenuMerge *self,
 						  const gchar *buffer,
-						  guint length,
+						  size_t length,
 						  GError **error);
 guint         egg_menu_merge_add_ui_from_file    (EggMenuMerge *self,
 						  const gchar *filename,
Index: libegg/menu/egg-radio-action.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-radio-action.c,v
retrieving revision 1.3
diff -u -r1.3 egg-radio-action.c
--- libegg/menu/egg-radio-action.c	14 Sep 2002 20:24:32 -0000	1.3
+++ libegg/menu/egg-radio-action.c	22 Jul 2003 11:09:22 -0000
@@ -1,4 +1,5 @@
 #include "egg-radio-action.h"
+#include "eggradiotoolbutton.h"
 
 static void egg_radio_action_init       (EggRadioAction *action);
 static void egg_radio_action_class_init (EggRadioActionClass *class);
@@ -45,6 +46,9 @@
   parent_class = g_type_class_peek_parent (class);
   object_class = G_OBJECT_CLASS (class);
   action_class = EGG_ACTION_CLASS (class);
+
+  action_class->menu_item_type = GTK_TYPE_RADIO_MENU_ITEM;
+  action_class->toolbar_item_type = EGG_TYPE_RADIO_TOOL_BUTTON;
 
   object_class->finalize = egg_radio_action_finalize;
 
Index: libegg/menu/egg-radio-action.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-radio-action.h,v
retrieving revision 1.1
diff -u -r1.1 egg-radio-action.h
--- libegg/menu/egg-radio-action.h	27 Apr 2002 12:57:27 -0000	1.1
+++ libegg/menu/egg-radio-action.h	22 Jul 2003 11:09:22 -0000
@@ -2,8 +2,8 @@
 #define EGG_RADIO_ACTION_H
 
 #include <gtk/gtk.h>
-#include <libegg/menu/egg-action.h>
-#include <libegg/menu/egg-toggle-action.h>
+#include <egg-action.h>
+#include <egg-toggle-action.h>
 
 #define EGG_TYPE_RADIO_ACTION            (egg_radio_action_get_type ())
 #define EGG_RADIO_ACTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_RADIO_ACTION, EggRadioAction))
Index: libegg/menu/egg-toggle-action.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-toggle-action.c,v
retrieving revision 1.6
diff -u -r1.6 egg-toggle-action.c
--- libegg/menu/egg-toggle-action.c	6 Sep 2002 14:13:44 -0000	1.6
+++ libegg/menu/egg-toggle-action.c	22 Jul 2003 11:09:22 -0000
@@ -1,5 +1,5 @@
 #include "egg-toggle-action.h"
-#include "../toolbar/eggtoggletoolbutton.h"
+#include "eggtoggletoolbutton.h"
 
 enum {
   TOGGLED,
Index: libegg/menu/egg-toggle-action.h
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/egg-toggle-action.h,v
retrieving revision 1.1
diff -u -r1.1 egg-toggle-action.h
--- libegg/menu/egg-toggle-action.h	27 Apr 2002 12:57:27 -0000	1.1
+++ libegg/menu/egg-toggle-action.h	22 Jul 2003 11:09:22 -0000
@@ -2,7 +2,7 @@
 #define EGG_TOGGLE_ACTION_H
 
 #include <gtk/gtk.h>
-#include <libegg/menu/egg-action.h>
+#include <egg-action.h>
 
 #define EGG_TYPE_TOGGLE_ACTION            (egg_toggle_action_get_type ())
 #define EGG_TOGGLE_ACTION(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), EGG_TYPE_TOGGLE_ACTION, EggToggleAction))
Index: libegg/menu/test-merge.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/menu/test-merge.c,v
retrieving revision 1.16
diff -u -r1.16 test-merge.c
--- libegg/menu/test-merge.c	5 Oct 2002 08:03:53 -0000	1.16
+++ libegg/menu/test-merge.c	22 Jul 2003 11:09:24 -0000
@@ -81,11 +81,11 @@
   { "StockHelpMenuAction", N_("_Help"), NULL, NULL, NULL, NULL, NULL },
   { "Test", N_("Test"), NULL, NULL, NULL, NULL, NULL },
 
-  { "NewAction", NULL, GTK_STOCK_NEW, "<control>n", NULL,
+  { "NewAction", NULL, GTK_STOCK_NEW, "F1", NULL,
     G_CALLBACK (activate_action), NULL },
   { "New2Action", NULL, GTK_STOCK_NEW, "<control>m", NULL,
     G_CALLBACK (activate_action), NULL },
-  { "OpenAction", NULL, GTK_STOCK_OPEN, "<control>o", NULL,
+  { "OpenAction", NULL, GTK_STOCK_OPEN, "h", NULL,
     G_CALLBACK (activate_action), NULL },
   { "QuitAction", NULL, GTK_STOCK_QUIT, "<control>q", NULL,
     G_CALLBACK (gtk_main_quit), NULL },
Index: libegg/toolbar/eggtoolbar.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/eggtoolbar.c,v
retrieving revision 1.59
diff -u -r1.59 eggtoolbar.c
--- libegg/toolbar/eggtoolbar.c	29 Jun 2003 18:11:36 -0000	1.59
+++ libegg/toolbar/eggtoolbar.c	22 Jul 2003 11:09:36 -0000
@@ -36,7 +36,7 @@
 #include <gtk/gtktoolbar.h>
 #include <gtk/gtkbindings.h>
 #include <gdk/gdkkeysyms.h>
-#include "../util/eggmarshalers.h"
+#include "eggmarshalers.h"
 #include <gtk/gtkmain.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtklabel.h>
@@ -82,6 +82,7 @@
 };
 
 static void egg_toolbar_init       (EggToolbar      *toolbar);
+static void egg_toolbar_finalize   (GObject         *object);
 static void egg_toolbar_class_init (EggToolbarClass *klass);
 
 static void egg_toolbar_set_property (GObject      *object,
@@ -283,6 +284,7 @@
   
   gobject_class->set_property = egg_toolbar_set_property;
   gobject_class->get_property = egg_toolbar_get_property;
+  gobject_class->finalize = egg_toolbar_finalize;
 
   widget_class->button_press_event = egg_toolbar_button_press;
   widget_class->expose_event = egg_toolbar_expose;
@@ -486,6 +488,18 @@
 
   add_ctrl_tab_bindings (binding_set, 0, GTK_DIR_RIGHT);
   add_ctrl_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_LEFT);
+}
+
+static void
+egg_toolbar_finalize (GObject *object)
+{
+  EggToolbar *toolbar = EGG_TOOLBAR (object);
+  GList *list;
+
+  if (toolbar->tooltips)
+    g_object_unref (GTK_OBJECT (toolbar->tooltips));
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 static void
Index: libegg/toolbar/eggtoolbutton.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/eggtoolbutton.c,v
retrieving revision 1.34
diff -u -r1.34 eggtoolbutton.c
--- libegg/toolbar/eggtoolbutton.c	29 Jun 2003 18:11:36 -0000	1.34
+++ libegg/toolbar/eggtoolbutton.c	22 Jul 2003 11:09:38 -0000
@@ -513,6 +513,15 @@
   g_free (button->stock_id);
   button->stock_id = NULL;
 
+  g_free (button->label_text);
+  button->label_text = NULL;
+
+  if (button->label_widget)
+    g_object_unref (G_OBJECT (button->label_widget));
+
+  if (button->icon_widget)
+    g_object_unref (G_OBJECT (button->icon_widget));
+
   parent_class->finalize (object);
 }
 
Index: libegg/toolbar/gtkexample.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/gtkexample.c,v
retrieving revision 1.2
diff -u -r1.2 gtkexample.c
--- libegg/toolbar/gtkexample.c	28 Apr 2003 16:19:41 -0000	1.2
+++ libegg/toolbar/gtkexample.c	22 Jul 2003 11:09:41 -0000
@@ -199,14 +199,12 @@
 set_toolbar_enable (GtkWidget *widget,
 		    gpointer   data)
 {
-  egg_toolbar_set_tooltips (EGG_TOOLBAR (data), TRUE);
 }
 
 static void
 set_toolbar_disable (GtkWidget *widget,
 		     gpointer   data)
 {
-  egg_toolbar_set_tooltips (EGG_TOOLBAR (data), FALSE);
 }
 
 static void
@@ -284,15 +282,6 @@
 
       egg_toolbar_append_space (EGG_TOOLBAR (toolbar));
 
-      egg_toolbar_append_item (EGG_TOOLBAR (toolbar),
-			       "Enable", "Enable tooltips", NULL,
-			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
-			       G_CALLBACK (set_toolbar_enable), toolbar);
-      egg_toolbar_append_item (EGG_TOOLBAR (toolbar),
-			       "Disable", "Disable tooltips", NULL,
-			       new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
-			       G_CALLBACK (set_toolbar_disable), toolbar);
-
       egg_toolbar_append_space (EGG_TOOLBAR (toolbar));
 
       egg_toolbar_append_item (EGG_TOOLBAR (toolbar),
@@ -369,15 +358,6 @@
 			   NULL, toolbar);
 
   egg_toolbar_append_space (EGG_TOOLBAR (toolbar));
-
-  egg_toolbar_append_item (EGG_TOOLBAR (toolbar),
-			   "Enable", "Enable tooltips", NULL,
-			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
-			   G_CALLBACK (set_toolbar_enable), toolbar);
-  egg_toolbar_append_item (EGG_TOOLBAR (toolbar),
-			   "Disable", "Disable tooltips", NULL,
-			   new_pixmap ("test.xpm", window->window, &window->style->bg[GTK_STATE_NORMAL]),
-			   G_CALLBACK (set_toolbar_disable), toolbar);
 
   egg_toolbar_append_space (EGG_TOOLBAR (toolbar));
   
Index: libegg/toolbar/test-drag.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/test-drag.c,v
retrieving revision 1.5
diff -u -r1.5 test-drag.c
--- libegg/toolbar/test-drag.c	19 Apr 2003 12:42:10 -0000	1.5
+++ libegg/toolbar/test-drag.c	22 Jul 2003 11:09:41 -0000
@@ -69,7 +69,7 @@
 main (int argc, char **argv)
 {
   GtkWidget *window;
-  GtkWidget *toolbar;
+  GtkWidget *toolbar, *box, *box1;
   EggToolItem *item;
   GtkWidget *entry;
   gint i;
@@ -80,10 +80,58 @@
   gtk_window_set_default_size (GTK_WINDOW (window), 600, -1);
 
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+box1 = gtk_vbox_new (FALSE, 0);
+gtk_container_add (window, box1);
+
+box = gtk_vbox_new (FALSE, 0);
+gtk_box_pack_start (box1, box, FALSE, FALSE, 0);
+gtk_widget_show (box);
+toolbar = egg_toolbar_new();
+  egg_toolbar_set_show_arrow (EGG_TOOLBAR (toolbar), TRUE);
+  gtk_box_pack_start (GTK_CONTAINER (box), toolbar, FALSE, FALSE, 0);
+
+  gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP,
+		     target_table, G_N_ELEMENTS (target_table),
+		     GDK_ACTION_COPY | GDK_ACTION_MOVE);
+  g_signal_connect (toolbar, "drag_drop",
+		    G_CALLBACK (toolbar_drop), NULL);
+
+  for (i = 0; i < G_N_ELEMENTS (tool_items); i++)
+    {
+      if (tool_items[i])
+	item = egg_tool_button_new_from_stock (tool_items[i]);
+      else
+	item = egg_separator_tool_item_new ();
+
+      egg_tool_item_set_use_drag_window (EGG_TOOL_ITEM (item), TRUE);
+      egg_toolbar_insert (EGG_TOOLBAR (toolbar), item, -1);
+      gtk_drag_source_set (GTK_WIDGET (item),
+			   GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+			   target_table, G_N_ELEMENTS (target_table),
+			   GDK_ACTION_COPY | GDK_ACTION_MOVE);
+      g_signal_connect (item, "drag_begin",
+			G_CALLBACK (toolitem_drag_begin), NULL);
+    }
+
+  item = egg_tool_item_new();
+  egg_tool_item_set_homogeneous (item, FALSE);
+  egg_tool_item_set_expand (item, TRUE);
+  entry = gtk_entry_new();
+  gtk_container_add (GTK_CONTAINER (item), entry);
+
+  egg_tool_item_set_use_drag_window (EGG_TOOL_ITEM (item), TRUE);
+  egg_toolbar_insert (EGG_TOOLBAR (toolbar), item, -1);
+  gtk_drag_source_set (GTK_WIDGET (item),
+		       GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+		       target_table, G_N_ELEMENTS (target_table),
+		       GDK_ACTION_COPY | GDK_ACTION_MOVE);
+  g_signal_connect (item, "drag_begin",
+		    G_CALLBACK (toolitem_drag_begin), NULL);
+
 
   toolbar = egg_toolbar_new();
   egg_toolbar_set_show_arrow (EGG_TOOLBAR (toolbar), TRUE);
-  gtk_container_add (GTK_CONTAINER (window), toolbar);
+  gtk_box_pack_start (GTK_CONTAINER (box), toolbar, FALSE, FALSE, 0);
 
   gtk_drag_dest_set (toolbar, GTK_DEST_DEFAULT_DROP,
 		     target_table, G_N_ELEMENTS (target_table),
Index: libegg/toolbar/test-toolbar.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/toolbar/test-toolbar.c,v
retrieving revision 1.25
diff -u -r1.25 test-toolbar.c
--- libegg/toolbar/test-toolbar.c	29 Jun 2003 13:25:58 -0000	1.25
+++ libegg/toolbar/test-toolbar.c	22 Jul 2003 11:09:43 -0000
@@ -379,6 +379,7 @@
   gtk_container_add (GTK_CONTAINER (window), table);
 
   toolbar = egg_toolbar_new ();
+  egg_toolbar_get_nth_item (EGG_TOOLBAR (toolbar), 1);
   gtk_table_attach (GTK_TABLE (table), toolbar,
 		    0,2, 0,1, GTK_FILL|GTK_EXPAND, GTK_FILL, 0, 0);
 
Index: libegg/treeviewutils/eggtreemodelfilter.c
===================================================================
RCS file: /cvs/gnome/libegg/libegg/treeviewutils/eggtreemodelfilter.c,v
retrieving revision 1.9
diff -u -r1.9 eggtreemodelfilter.c
--- libegg/treeviewutils/eggtreemodelfilter.c	18 Apr 2003 19:21:18 -0000	1.9
+++ libegg/treeviewutils/eggtreemodelfilter.c	22 Jul 2003 11:09:54 -0000
@@ -182,15 +182,19 @@
                                                                            gboolean            build_levels,
                                                                            gboolean            fetch_childs);
 
-static gboolean     egg_tree_model_filter_fetch_child         (EggTreeModelFilter *filter,
+static FilterElt   *egg_tree_model_filter_fetch_child         (EggTreeModelFilter *filter,
 						               FilterLevel        *level,
-						               gint                offset);
+						               gint                offset,
+							       gint               *index);
 static void         egg_tree_model_filter_remove_node         (EggTreeModelFilter *filter,
 					                       GtkTreeIter        *iter,
 					                       gboolean            emit_signal);
 static void         egg_tree_model_filter_update_childs       (EggTreeModelFilter *filter,
 						               FilterLevel        *level,
 						               FilterElt          *elt);
+static FilterElt   *bsearch_elt_with_offset                   (GArray             *array,
+                                                               gint                offset,
+                                                               gint               *index);
 
 
 static GObjectClass *parent_class = NULL;
@@ -659,12 +663,14 @@
     }
 }
 
-static gboolean
+static FilterElt *
 egg_tree_model_filter_fetch_child (EggTreeModelFilter *filter,
 				   FilterLevel        *level,
-				   gint                offset)
+				   gint                offset,
+                                   gint               *index)
 {
   gint i = 0;
+  gint start, middle, end;
   gint len;
   GtkTreePath *c_path = NULL;
   GtkTreeIter c_iter;
@@ -680,7 +686,7 @@
 					    level->parent_elt,
 					    filter->virtual_root);
       if (!c_parent_path)
-	return FALSE;
+	return NULL;
     }
   else
     {
@@ -712,7 +718,7 @@
   gtk_tree_path_free (c_path);
 
   if (offset >= len || !egg_tree_model_filter_visible (filter, &c_iter))
-    return FALSE;
+    return NULL;
 
   /* add child */
   elt.offset = offset;
@@ -725,21 +731,41 @@
   if (EGG_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
     elt.iter = c_iter;
 
-  /* find index */
-  for (i = 0; i < level->array->len; i++)
-    if (g_array_index (level->array, FilterElt, i).offset > offset)
-      break;
+  /* find index (binary search on offset) */
+  start = 0;
+  end = level->array->len;
+
+  if (start != end)
+    {
+      while (start != end)
+        {
+          middle = (start + end) / 2;
+
+          if (g_array_index (level->array, FilterElt, middle).offset <= offset)
+            start = middle + 1;
+          else
+            end = middle;
+        }
+
+      if (g_array_index (level->array, FilterElt, middle).offset <= offset)
+        i = middle + 1;
+      else
+        i = middle;
+    }
+  else
+    i = 0;
 
   g_array_insert_val (level->array, i, elt);
+  *index = i;
 
-  for (i = 0; i < level->array->len; i++)
+  for (i = MAX (--i, 0); i < level->array->len; i++)
     {
       FilterElt *e = &(g_array_index (level->array, FilterElt, i));
       if (e->children)
 	e->children->parent_elt = e;
     }
 
-  return TRUE;
+  return &g_array_index (level->array, FilterElt, *index);
 }
 
 static void
@@ -799,21 +825,24 @@
     }
   else
     {
-      /* remove the node */
-      for (i = 0; i < level->array->len; i++)
-        if (elt->offset == g_array_index (level->array, FilterElt, i).offset)
-          break;
+      FilterElt *tmp;
 
-      g_array_remove_index (level->array, i);
+      /* remove the node */
+      tmp = bsearch_elt_with_offset (level->array, elt->offset, &i);
 
-      for (i = 0; i < level->array->len; i++)
+      if (tmp)
         {
-          /* NOTE: here we do *not* decrease offsets, because the node was
-           * not removed from the child model
-           */
-          elt = &g_array_index (level->array, FilterElt, i);
-          if (elt->children)
-	    elt->children->parent_elt = elt;
+          g_array_remove_index (level->array, i);
+
+          for (i = MAX (--i, 0); i < level->array->len; i++)
+            {
+              /* NOTE: here we do *not* decrease offsets, because the node was
+               * not removed from the child model
+               */
+              elt = &g_array_index (level->array, FilterElt, i);
+              if (elt->children)
+	        elt->children->parent_elt = elt;
+            }
         }
     }
 
@@ -870,6 +899,56 @@
     }
 }
 
+static FilterElt *
+bsearch_elt_with_offset (GArray *array,
+                         gint    offset,
+                         gint   *index)
+{
+  gint start, middle, end;
+  FilterElt *elt;
+
+  start = 0;
+  end = array->len;
+
+  if (array->len < 1)
+    return NULL;
+
+  if (start == end)
+    {
+      elt = &g_array_index (array, FilterElt, 0);
+
+      if (elt->offset == offset)
+        {
+          *index = 0;
+          return elt;
+        }
+      else
+        return NULL;
+    }
+
+  while (start != end)
+    {
+      middle = (start + end) / 2;
+
+      elt = &g_array_index (array, FilterElt, middle);
+
+      if (elt->offset < offset)
+        start = middle + 1;
+      else if (elt->offset > offset)
+        end = middle;
+      else
+        break;
+    }
+
+  if (elt->offset == offset)
+    {
+      *index = middle;
+      return elt;
+    }
+
+  return NULL;
+}
+
 /* TreeModel signals */
 static void
 egg_tree_model_filter_row_changed (GtkTreeModel *c_model,
@@ -879,14 +958,15 @@
 {
   EggTreeModelFilter *filter = EGG_TREE_MODEL_FILTER (data);
   GtkTreeIter iter;
+  GtkTreeIter childs;
   GtkTreeIter real_c_iter;
-  GtkTreePath *path;
+  GtkTreePath *path = NULL;
 
   FilterElt *elt;
   FilterLevel *level;
-  gint offset;
 
-  gboolean new;
+  gboolean requested_state;
+  gboolean current_state;
   gboolean free_c_path = FALSE;
 
   g_return_if_fail (c_path != NULL || c_iter != NULL);
@@ -902,21 +982,72 @@
   else
     gtk_tree_model_get_iter (c_model, &real_c_iter, c_path);
 
+  /* what's the requested state? */
+  requested_state = egg_tree_model_filter_visible (filter, &real_c_iter);
+
+  /* now, let's see whether the item is there */
+  path = egg_real_tree_model_filter_convert_child_path_to_path (filter,
+                                                                c_path,
+                                                                FALSE,
+                                                                FALSE);
+
+  if (path)
+    {
+      gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
+      current_state = FILTER_ELT (iter.user_data2)->visible;
+    }
+  else
+    current_state = FALSE;
+
+  if (current_state == FALSE && requested_state == FALSE)
+    /* no changes required */
+    goto done;
+
+  if (current_state == TRUE && requested_state == FALSE)
+    {
+      /* get rid of this node */
+      gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
+      egg_tree_model_filter_remove_node (filter, &iter, TRUE);
+
+      level = FILTER_LEVEL (iter.user_data);
+
+      if (!level->parent_level)
+        filter->root_level_visible--;
+
+      goto done;
+    }
+
+  if (current_state == TRUE && requested_state == TRUE)
+    {
+      /* progate the signal */
+      gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
+      gtk_tree_model_row_changed (GTK_TREE_MODEL (filter), path, &iter);
+
+      level = FILTER_LEVEL (iter.user_data);
+      elt = FILTER_ELT (iter.user_data2);
+
+      /* and update the childs */
+      if (gtk_tree_model_iter_children (c_model, &childs, &real_c_iter))
+        egg_tree_model_filter_update_childs (filter, level, elt);
+
+      goto done;
+    }
+
+  /* only current == FALSE and requested == TRUE is left,
+   * pull in the child
+   */
+  g_return_if_fail (current_state == FALSE && requested_state == TRUE);
+
+  /* make sure the new item has been pulled in */
   if (!filter->root)
     {
       gint i;
       FilterLevel *root;
 
-      /* build root level */
       egg_tree_model_filter_build_level (filter, NULL, NULL);
 
       root = FILTER_LEVEL (filter->root);
 
-      /* FIXME:
-       * we set the visibilities to FALSE here, so we ever emit
-       * a row_inserted. maybe it's even better to emit row_inserted
-       * here, not sure.
-       */
       if (root)
         {
           for (i = 0; i < root->array->len; i++)
@@ -925,63 +1056,35 @@
 	}
     }
 
-  path = egg_real_tree_model_filter_convert_child_path_to_path (filter,
-								c_path,
-								FALSE,
-								TRUE);
   if (!path)
-    goto done;
+    path = egg_real_tree_model_filter_convert_child_path_to_path (filter,
+								  c_path,
+								  FALSE,
+								  TRUE);
+
+  g_return_if_fail (path != NULL);
 
+  egg_tree_model_filter_increment_stamp (filter);
   gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
 
   level = FILTER_LEVEL (iter.user_data);
   elt = FILTER_ELT (iter.user_data2);
-  offset = elt->offset;
-  new = egg_tree_model_filter_visible (filter, c_iter);
 
-  if (elt->visible == TRUE && new == FALSE)
-    {
-      egg_tree_model_filter_remove_node (filter, &iter, TRUE);
+  elt->visible = TRUE;
 
-      if (!level->parent_level)
-	filter->root_level_visible--;
-    }
-  else if (elt->visible == FALSE && new == TRUE)
-    {
-      GtkTreeIter childs;
+  if (!level->parent_level)
+    filter->root_level_visible++;
 
-      elt->visible = TRUE;
+  /* update stamp */
+  gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter), path, &iter);
 
-      egg_tree_model_filter_increment_stamp (filter);
-
-      if (!level->parent_level)
-	filter->root_level_visible++;
-
-      /* update stamp */
-      gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
-      gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter), path, &iter);
-
-      if (gtk_tree_model_iter_children (c_model, &childs, c_iter))
-	egg_tree_model_filter_update_childs (filter, level, elt);
-    }
-  else if (elt->visible == FALSE && new == FALSE)
-    {
-      egg_tree_model_filter_remove_node (filter, &iter, FALSE);
-    }
-  else
-    {
-      GtkTreeIter childs;
-
-      gtk_tree_model_row_changed (GTK_TREE_MODEL (filter), path, &iter);
-
-      if (gtk_tree_model_iter_children (c_model, &childs, c_iter) &&
-	  elt->visible)
-	egg_tree_model_filter_update_childs (filter, level, elt);
-    }
-
-  gtk_tree_path_free (path);
+  if (gtk_tree_model_iter_children (c_model, &childs, c_iter))
+    egg_tree_model_filter_update_childs (filter, level, elt);
 
 done:
+  if (path)
+    gtk_tree_path_free (path);
+
   if (free_c_path)
     gtk_tree_path_free (c_path);
 }
@@ -1073,14 +1176,9 @@
 	    /* we don't cover this signal */
 	    goto done;
 
-	  elt = NULL;
-	  for (j = 0; j < level->array->len; j++)
-	    if (g_array_index (level->array, FilterElt, j).offset ==
-		gtk_tree_path_get_indices (real_path)[i])
-	      {
-		elt = &g_array_index (level->array, FilterElt, j);
-		break;
-	      }
+          elt = bsearch_elt_with_offset (level->array,
+                                         gtk_tree_path_get_indices (real_path)[i],
+                                         &j);
 
 	  if (!elt)
 	    /* parent is probably being filtered out */
@@ -1332,14 +1430,10 @@
 		      return;
 		    }
 
-		  elt = NULL;
-		  for (j = 0; j < level->array->len; j++)
-		    if (g_array_index (level->array, FilterElt, j).offset ==
-			gtk_tree_path_get_indices (real_path)[i])
-		      {
-			elt = &g_array_index (level->array, FilterElt, j);
-			break;
-		      }
+                  elt = bsearch_elt_with_offset (level->array,
+                                                 gtk_tree_path_get_indices (real_path)[i],
+                                                 &j);
+
 
 		  if (!elt || !elt->children)
 		    {
@@ -1414,15 +1508,15 @@
     }
   else
     {
+      FilterElt *tmp;
+
       /* remove the row */
-      for (i = 0; i < level->array->len; i++)
-        if (elt->offset == g_array_index (level->array, FilterElt, i).offset)
-          break;
+      tmp = bsearch_elt_with_offset (level->array, elt->offset, &i);
 
-      offset = g_array_index (level->array, FilterElt, i).offset;
+      offset = tmp->offset;
       g_array_remove_index (level->array, i);
 
-      for (i = 0; i < level->array->len; i++)
+      for (i = MAX (--i, 0); i < level->array->len; i++)
         {
           elt = &g_array_index (level->array, FilterElt, i);
           if (elt->offset > offset)
@@ -2391,6 +2485,7 @@
   GtkTreePath *retval;
   GtkTreePath *real_path;
   FilterLevel *level;
+  FilterElt *tmp;
   gint i;
 
   g_return_val_if_fail (EGG_IS_TREE_MODEL_FILTER (filter), NULL);
@@ -2425,25 +2520,24 @@
           return NULL;
         }
 
-      for (j = 0; j < level->array->len; j++)
+      tmp = bsearch_elt_with_offset (level->array, child_indices[i], &j);
+      if (tmp)
         {
-          if ((g_array_index (level->array, FilterElt, j)).offset == child_indices[i])
-            {
-              gtk_tree_path_append_index (retval, j);
-              if (g_array_index (level->array, FilterElt, j).children == NULL && build_levels)
-                egg_tree_model_filter_build_level (filter,
-                                                   level,
-                                                   &g_array_index (level->array, FilterElt, j));
-              level = g_array_index (level->array, FilterElt, j).children;
-              found_child = TRUE;
-              break;
-            }
+          gtk_tree_path_append_index (retval, j);
+          if (!tmp->children && build_levels)
+            egg_tree_model_filter_build_level (filter, level, tmp);
+          level = tmp->children;
+          found_child = TRUE;
         }
 
       if (!found_child && fetch_childs)
         {
+          tmp = egg_tree_model_filter_fetch_child (filter, level,
+                                                   child_indices[i],
+                                                   &j);
+
           /* didn't find the child, let's try to bring it back */
-          if (!egg_tree_model_filter_fetch_child (filter, level, child_indices[i]))
+          if (!tmp || tmp->offset != child_indices[i])
             {
               /* not there */
               gtk_tree_path_free (real_path);
@@ -2451,29 +2545,11 @@
               return NULL;
             }
 
-          /* yay, let's search for the child again */
-          for (j = 0; j < level->array->len; j++)
-            {
-              if ((g_array_index (level->array, FilterElt, j)).offset == child_indices[i])
-                {
-                  gtk_tree_path_append_index (retval, j);
-                  if (g_array_index (level->array, FilterElt, j).children == NULL && build_levels)
-                    egg_tree_model_filter_build_level (filter,
-                                                       level,
-                                                       &g_array_index (level->array, FilterElt, j));
-                  level = g_array_index (level->array, FilterElt, j).children;
-                  found_child = TRUE;
-                  break;
-                }
-            }
-
-          if (!found_child)
-            {
-              /* our happy fun fetch attempt failed ?!?!?! no child! */
-              gtk_tree_path_free (real_path);
-              gtk_tree_path_free (retval);
-              return NULL;
-            }
+          gtk_tree_path_append_index (retval, j);
+          if (!tmp->children && build_levels)
+            egg_tree_model_filter_build_level (filter, level, tmp);
+          level = tmp->children;
+          found_child = TRUE;
         }
       else if (!found_child && !fetch_childs)
         {
@@ -2588,7 +2664,8 @@
                                        GtkTreeIter  *iter,
                                        gpointer      data)
 {
-  gtk_tree_model_row_changed (model, path, iter);
+  /* evil, don't try this at home, but certainly speeds things up */
+  egg_tree_model_filter_row_changed (model, path, iter, data);
 
   return FALSE;
 }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>