[g-a-devel]Tree updates in at-poke



I've attempted to get at-poke to listen for property-change events and
update the left-hand pane's tree model accordingly.

Attached is a first pass at a patch.  I'm not convinced about it yet
though as:
(i) I'm getting occasional crashes when poking things - though these
might not be due to my changes.  I'm new to at-poke, and to the
accessibility framework, and I've not implemented a GtkTreeModel before,
so there might be subtleties I've missed.
(ii) Not everything seems to be sending property-change notifications -
perhaps these are bugs in the existing applications, or is this just an
advisory, and not mandatory?
(iii) Is this a good direction to take?  Is at-poke supposed to be for
static "value-poking", or for dynamic "value-monitoring"?

Thoughts?

-- 
David Malcolm
http://www.davemalcolm.demon.co.uk
Index: src/accessible-tree-model.c
===================================================================
RCS file: /cvs/gnome/at-poke/src/accessible-tree-model.c,v
retrieving revision 1.28
diff -p -u -r1.28 accessible-tree-model.c
--- src/accessible-tree-model.c	28 May 2003 12:36:43 -0000	1.28
+++ src/accessible-tree-model.c	15 Nov 2003 08:52:34 -0000
@@ -443,6 +443,60 @@ my_SPI_dupString (const char *s)
 }
 
 static void
+get_mnode_name_from_accessible (ModelNode *mnode)
+{
+	g_assert (mnode);
+
+	if (mnode->name) {
+		SPI_freeString (mnode->name);
+	}
+	mnode->name = Accessible_getName (mnode->accessible);
+	if (!mnode->name || mnode->name [0] == '\0') {
+		if (mnode->name) {
+			SPI_freeString (mnode->name);
+		}
+
+		mnode->name = my_SPI_dupString ("<no name>");
+	}
+}
+
+static void
+get_mnode_role_from_accessible (ModelNode *mnode)
+{
+	g_assert (mnode);
+
+	if (mnode->role_name) {
+		SPI_freeString (mnode->role_name);
+	}
+	mnode->role = Accessible_getRole (mnode->accessible);
+	mnode->role_name = Accessible_getRoleName (mnode->accessible);
+
+	if (!mnode->role_name || mnode->role_name [0] == '\0') {
+		if (mnode->role_name) {
+			SPI_freeString (mnode->role_name);
+		}
+
+		mnode->role_name = my_SPI_dupString ("<no role>");
+	}
+}
+
+static void
+get_mnode_description_from_accessible (ModelNode *mnode)
+{
+	if (mnode->description) {
+		SPI_freeString (mnode->description);
+	}
+	mnode->description = Accessible_getDescription (mnode->accessible);
+	if (!mnode->description || mnode->description [0] == '\0') {
+		if (mnode->description) {
+			SPI_freeString (mnode->description);
+		}
+
+		mnode->description = my_SPI_dupString ("<no description>");
+	}	
+}
+
+static void
 accessible_tree_model_get_value (GtkTreeModel *model,
 				 GtkTreeIter  *iter,
 				 int           column,
@@ -457,9 +511,7 @@ accessible_tree_model_get_value (GtkTree
 		g_value_init (value, G_TYPE_STRING);
 
 		if (!mnode->name) {
-			mnode->name = Accessible_getName (mnode->accessible);
-			if (!mnode->name || mnode->name [0] == '\0')
-				mnode->name = my_SPI_dupString ("<no name>");
+			get_mnode_name_from_accessible (mnode);
 		}
 		g_value_set_string (value, mnode->name);
 		break;
@@ -468,9 +520,7 @@ accessible_tree_model_get_value (GtkTree
 		g_value_init (value, G_TYPE_STRING);
 
 		if (!mnode->role_name) {
-			mnode->role_name = Accessible_getRoleName (mnode->accessible);
-			if (!mnode->role_name || mnode->role_name [0] == '\0')
-				mnode->role_name = my_SPI_dupString ("<no role>");
+			get_mnode_role_from_accessible (mnode);
 		}
 		g_value_set_string (value, mnode->role_name);
 		break;
@@ -479,9 +529,7 @@ accessible_tree_model_get_value (GtkTree
 		g_value_init (value, G_TYPE_STRING);
 
 		if (!mnode->description) {
-			mnode->description = Accessible_getDescription (mnode->accessible);
-			if (!mnode->description || mnode->description [0] == '\0')
-				mnode->description = my_SPI_dupString ("<no description>");
+			get_mnode_description_from_accessible (mnode);
 		}
 		g_value_set_string (value, mnode->description);
 		break;
@@ -490,7 +538,7 @@ accessible_tree_model_get_value (GtkTree
 		GdkPixbuf *pixbuf;
 
 		if (mnode->role == SPI_ROLE_INVALID)
-			mnode->role = Accessible_getRole (mnode->accessible);
+			get_mnode_role_from_accessible (mnode);
 
 		g_value_init (value, GDK_TYPE_PIXBUF);
 
@@ -696,6 +744,33 @@ report_global_event (const AccessibleEve
 		g_print ("New active descendant: %p Role: %s Index: %ld\n",
 			 active_descendant, role_txt, event->detail1);
 		SPI_freeString (role_txt);
+	} else if (!strcmp (event->type, "object:property-change:accessible-name")) {
+		GNode *node = g_hash_table_lookup (model->accessible_to_node,
+						   event->source);
+		if (node) {
+			ModelNode *mnode = node->data;
+			
+			if (mnode) {
+				get_mnode_name_from_accessible (mnode);
+				model_node_changed (GTK_TREE_MODEL (model), node);
+			}
+		}
+		
+	} else if (!strcmp (event->type, "object:property-change:accessible-description")) {
+		GNode *node = g_hash_table_lookup (model->accessible_to_node,
+						   event->source);
+		if (node) {
+			ModelNode *mnode = node->data;
+			
+			if (mnode) {
+				get_mnode_description_from_accessible (mnode);
+				model_node_changed (GTK_TREE_MODEL (model), node);
+			}
+		}
+	} else {
+#if 0
+	        g_message ("Unhandled AccessibleEvent \"%s\"", event->type);	
+#endif
 	}
 }
 
@@ -710,6 +785,8 @@ accessible_tree_model_init (AccessibleTr
 		model->event_listener, "object:children-changed");
 	SPI_registerGlobalEventListener (
 		model->event_listener, "object:active-descendant-changed");
+	SPI_registerGlobalEventListener (
+		model->event_listener, "object:property-change");
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]