Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gal/ChangeLog,v
retrieving revision 1.830
diff -u -r1.830 ChangeLog
--- ChangeLog	2 Dec 2003 06:14:33 -0000	1.830
+++ ChangeLog	2 Dec 2003 07:33:05 -0000
@@ -1,3 +1,10 @@
+2003-12-02  Bolian Yin  <bolian.yin@sun.com>
+
+	Fixes #51139
+
+	* gal/a11y/gal-a11y-e-table-item: (gal_a11y_e_table_item_ref_selection)
+	(gal_a11y_e_table_item_unref_selection): new functions.
+
 2003-12-02  Tim Wo  <tim.wo@sun.com>
 
 	* gal/a11y/e-table/gal-a11y-e-cell-toggle.c:
Index: gal/e-table/ChangeLog
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/ChangeLog,v
retrieving revision 1.920
diff -u -r1.920 ChangeLog
--- gal/e-table/ChangeLog	17 Nov 2003 21:05:14 -0000	1.920
+++ gal/e-table/ChangeLog	2 Dec 2003 07:33:18 -0000
@@ -1,3 +1,9 @@
+2003-11-19  Bolian Yin  <bolian.yin@sun.com>
+
+	Fixes #51139
+
+	* e-table-item.c : change the place of emitting ""selection_model_removed" signal.
+
 2003-11-17  Mike Kestner  <mkestner@ximian.com>
 
 	* e-table-config.c : use new gal_combo_* namespace.
Index: gal/e-table/e-table-item.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-table-item.c,v
retrieving revision 1.230
diff -u -r1.230 e-table-item.c
--- gal/e-table/e-table-item.c	14 Nov 2003 10:07:26 -0000	1.230
+++ gal/e-table/e-table-item.c	2 Dec 2003 07:33:25 -0000
@@ -553,8 +553,6 @@
 				     eti->cursor_change_id);
 	g_signal_handler_disconnect (eti->selection,
 				     eti->cursor_activated_id);
-        g_signal_emit_by_name (G_OBJECT(eti),
-                               "selection_model_removed", eti->selection);
 	g_object_unref (eti->selection);
 
 	eti->selection_change_id = 0;
@@ -1466,6 +1464,8 @@
 		break;
 		
 	case PROP_SELECTION_MODEL:
+		g_signal_emit_by_name (G_OBJECT(eti),
+				       "selection_model_removed", eti->selection);
 		eti_remove_selection_model (eti);
 		if (g_value_get_object (value))
 			eti_add_selection_model (eti, E_SELECTION_MODEL(g_value_get_object(value)));
Index: gal/a11y/e-table/gal-a11y-e-table-item.c
===================================================================
RCS file: /cvs/gnome/gal/gal/a11y/e-table/gal-a11y-e-table-item.c,v
retrieving revision 1.7
diff -u -r1.7 gal-a11y-e-table-item.c
--- gal/a11y/e-table/gal-a11y-e-table-item.c	2 Dec 2003 05:27:11 -0000	1.7
+++ gal/a11y/e-table/gal-a11y-e-table-item.c	2 Dec 2003 07:33:28 -0000
@@ -39,8 +39,13 @@
 	int selection_change_id;
 	int cursor_change_id;
 	ETableCol ** columns;
+	ESelectionModel *selection;
 };
 
+static gboolean gal_a11y_e_table_item_ref_selection (GalA11yETableItem *a11y,
+						     ESelectionModel *selection);
+static gboolean gal_a11y_e_table_item_unref_selection (GalA11yETableItem *a11y);
+
 #if 0
 static void
 unref_accessible (gpointer user_data, GObject *obj_loc)
@@ -99,6 +104,8 @@
 
 	if (parent_class->dispose)
 		parent_class->dispose (object);
+	if (priv->selection)
+		gal_a11y_e_table_item_unref_selection (a11y);
 }
 
 /* Static functions */
@@ -527,7 +534,8 @@
 
 	if (table_is_row_selected (table, row))
 		return TRUE;
-	e_selection_model_toggle_single_row (item->selection, view_to_model_row (item, row));
+	e_selection_model_toggle_single_row (item->selection,
+					     view_to_model_row (item, row));
 
 	return TRUE;
 }
@@ -909,6 +917,7 @@
 	priv->index_in_parent = -1;
 	priv->selection_change_id = 0;
 	priv->cursor_change_id = 0;
+	priv->selection = NULL;
 }
 
 /* atk selection */
@@ -1034,16 +1043,9 @@
 				  G_CALLBACK (eti_a11y_selection_model_removed_cb), NULL);
 		g_signal_connect (G_OBJECT(item), "selection_model_added",
 				  G_CALLBACK (eti_a11y_selection_model_added_cb), NULL);
-		if (item->selection) {
-			GET_PRIVATE (a11y)->selection_change_id = g_signal_connect (
-				    G_OBJECT(item->selection), "selection_changed",
-				    G_CALLBACK (eti_a11y_selection_changed_cb), a11y);
-			GET_PRIVATE (a11y)->cursor_change_id = g_signal_connect (
- 				    G_OBJECT(item->selection), "cursor_changed",
-				    G_CALLBACK (eti_a11y_cursor_changed_cb), a11y);
-
-			g_object_ref (item->selection);
-		}
+		if (item->selection)
+			gal_a11y_e_table_item_ref_selection (a11y,
+							     item->selection);
 	}
 	if (parent)
 		g_object_ref (parent);
@@ -1058,6 +1060,53 @@
 	return ATK_OBJECT (a11y);
 }
 
+static gboolean
+gal_a11y_e_table_item_ref_selection (GalA11yETableItem *a11y,
+				     ESelectionModel *selection)
+{
+	GalA11yETableItemPrivate *priv;
+
+	g_return_val_if_fail (a11y && selection, FALSE);
+
+	priv = GET_PRIVATE (a11y);
+	priv->selection_change_id = g_signal_connect (
+	    G_OBJECT(selection), "selection_changed",
+	    G_CALLBACK (eti_a11y_selection_changed_cb), a11y);
+	priv->cursor_change_id = g_signal_connect (
+            G_OBJECT(selection), "cursor_changed",
+	    G_CALLBACK (eti_a11y_cursor_changed_cb), a11y);
+
+	priv->selection = selection;
+	g_object_ref (selection);
+
+	return TRUE;
+}
+
+static gboolean
+gal_a11y_e_table_item_unref_selection (GalA11yETableItem *a11y)
+{
+	GalA11yETableItemPrivate *priv;
+
+	g_return_val_if_fail (a11y, FALSE);
+
+	priv = GET_PRIVATE (a11y);
+
+	g_return_val_if_fail (priv->selection_change_id != 0, FALSE);
+	g_return_val_if_fail (priv->cursor_change_id != 0, FALSE);
+
+
+	g_signal_handler_disconnect (priv->selection,
+				     priv->selection_change_id);
+	g_signal_handler_disconnect (priv->selection,
+				     priv->cursor_change_id);
+	priv->cursor_change_id = 0;
+	priv->selection_change_id = 0;
+
+	g_object_unref (priv->selection);
+	priv->selection = NULL;
+
+	return TRUE;
+}
 
 /* callbacks */
 
@@ -1074,16 +1123,8 @@
 	atk_obj = atk_gobject_accessible_for_object (G_OBJECT (eti));
 	a11y = GAL_A11Y_E_TABLE_ITEM (atk_obj);
 
-	if (GET_PRIVATE (a11y)->selection_change_id != 0 &&
-	    GET_PRIVATE (a11y)->cursor_change_id != 0) {
-		g_signal_handler_disconnect (selection,
-					     GET_PRIVATE (a11y)->selection_change_id);
-		g_signal_handler_disconnect (selection,
-					     GET_PRIVATE (a11y)->cursor_change_id);
-		GET_PRIVATE (a11y)->cursor_change_id = 0;
-		GET_PRIVATE (a11y)->selection_change_id = 0;
-		g_object_unref (selection);
-	}
+	if (selection == GET_PRIVATE (a11y)->selection)
+		gal_a11y_e_table_item_unref_selection (a11y);
 }
 
 static void
@@ -1099,14 +1140,9 @@
 	atk_obj = atk_gobject_accessible_for_object (G_OBJECT (eti));
 	a11y = GAL_A11Y_E_TABLE_ITEM (atk_obj);
 
-	GET_PRIVATE (a11y)->selection_change_id = g_signal_connect (
-		    G_OBJECT(selection), "selection_changed",
-		    G_CALLBACK (eti_a11y_selection_changed_cb), a11y);
-	GET_PRIVATE (a11y)->cursor_change_id = g_signal_connect (
-                    G_OBJECT(selection), "cursor_changed",
-		    G_CALLBACK (eti_a11y_cursor_changed_cb), a11y);
-
-	g_object_ref (selection);
+	if (GET_PRIVATE (a11y)->selection)
+		gal_a11y_e_table_item_unref_selection (a11y);
+	gal_a11y_e_table_item_ref_selection (a11y, selection);
 }
 
 static void
