diff options
-rw-r--r-- | src/notebook.c | 14 | ||||
-rw-r--r-- | src/tree.c | 44 | ||||
-rw-r--r-- | src/tree.h | 7 |
3 files changed, 25 insertions, 40 deletions
diff --git a/src/notebook.c b/src/notebook.c index 5124d7b..305a2da 100644 --- a/src/notebook.c +++ b/src/notebook.c @@ -41,6 +41,7 @@ struct _MqNotebook { GtkNotebook parent_instance; MqWindow *window; MqTabTree *tree; + MqTabPage *find_page; MqTabTree *found_node; MqTabPage *current_page; }; @@ -175,15 +176,13 @@ mq_notebook_new(MqWindow *window) } static gboolean -find_node_compare(MqTree *node, va_list ap) +find_node_compare(MqTree *node, gpointer user_data) { MqNotebook *notebook; - MqTabPage *page; - notebook = va_arg(ap, MqNotebook *); - page = va_arg(ap, MqTabPage *); + notebook = MQ_NOTEBOOK(user_data); - if (MQ_TAB_TREE(node)->page == page) { + if (MQ_TAB_TREE(node)->page == notebook->find_page) { notebook->found_node = MQ_TAB_TREE(node); return MQ_TREE_STOP; } else { @@ -194,9 +193,10 @@ find_node_compare(MqTree *node, va_list ap) static void find_node(MqNotebook *notebook, MqTabPage *page) { + notebook->find_page = page; notebook->found_node = NULL; - mq_tree_foreach(MQ_TREE(notebook->tree), find_node_compare, notebook, - page); + mq_tree_foreach(MQ_TREE(notebook->tree), find_node_compare, notebook); + notebook->find_page = NULL; g_assert(notebook->found_node); } @@ -148,34 +148,28 @@ mq_tree_seek(MqTree *node, gint offset) } static gboolean -foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), va_list ap) +foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) { - va_list aq; gboolean ret; ret = MQ_TREE_CONTINUE; for (; node; node = node->next) { /* XXX: Warning: Does not skip root node */ - va_copy(ap, aq); - ret = cb(node, aq); - va_end(aq); + ret = cb(node, user_data); if (ret == MQ_TREE_STOP) { break; } if (node->first_child) { - va_copy(ap, aq); - ret = foreach(node->first_child, cb, aq); - va_end(aq); + ret = foreach(node->first_child, cb, user_data); if (ret == MQ_TREE_STOP) { break; } } if (node->parent && node->parent->next) { - va_copy(ap, aq); - ret = foreach(node->parent->next, cb, aq); - va_end(aq); + ret = foreach(node->parent->next, cb, user_data); if (ret == MQ_TREE_STOP) { break; } @@ -186,27 +180,21 @@ foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), va_list ap) } void -mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), ...) +mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) { - va_list ap; - - va_start(ap, cb); - foreach(node->root->first_child, cb, ap); - va_end(ap); + foreach(node->root->first_child, cb, user_data); } static gboolean -foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), - va_list ap) +foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data) { - va_list aq; gboolean ret; ret = MQ_TREE_CONTINUE; for (node = node->first_child; node; node = node->next) { - va_copy(ap, aq); - ret = cb(node, aq); - va_end(aq); + ret = cb(node, user_data); if (ret == MQ_TREE_STOP) { break; } @@ -216,12 +204,8 @@ foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), } void -mq_tree_foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), - ...) +mq_tree_foreach_child(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data) { - va_list ap; - - va_start(ap, cb); - foreach_child(node->root->first_child, cb, ap); - va_end(ap); + foreach_child(node->root->first_child, cb, user_data); } @@ -74,11 +74,12 @@ MqTree * mq_tree_seek(MqTree *node, gint offset); void -mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), ...); +mq_tree_foreach(MqTree *node, gboolean (*cb)(MqTree *node, gpointer user_data), + gpointer user_data); void -mq_tree_foreach_child(MqTree *node, gboolean (*cb)(MqTree *node, va_list ap), - ...); +mq_tree_foreach_child(MqTree *node, + gboolean (*cb)(MqTree *node, gpointer user_data), gpointer user_data); G_END_DECLS |