add new function proto_tree_move_item(), which will move an already existing proto_it...
authorulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 2 Jun 2005 18:35:20 +0000 (18:35 +0000)
committerulfl <ulfl@f5534014-38df-0310-8fa8-9805f1628bb7>
Thu, 2 Jun 2005 18:35:20 +0000 (18:35 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@14524 f5534014-38df-0310-8fa8-9805f1628bb7

epan/proto.c
epan/proto.h

index 0a1b81de534f2415addbfec749efbc8bfa3adebc..01f660a8f580b0248bdbb5b8ddf9992524df5d99 100644 (file)
@@ -2497,6 +2497,45 @@ proto_tree_get_parent(proto_tree *tree) {
 }
 
 
+void
+proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move)
+{
+    proto_item *curr_item;
+
+
+    /*** cut item_to_move out ***/
+
+    /* is item_to_move the first? */
+    if(tree->first_child == item_to_move) {
+        /* simply change first child to next */
+        tree->first_child = item_to_move->next;
+    } else {
+        /* find previous and change it's next */
+        for(curr_item = tree->first_child; curr_item != NULL; curr_item = curr_item->next) {
+            if(curr_item->next == item_to_move) {
+                break;
+            }
+        }
+
+        DISSECTOR_ASSERT(curr_item);
+
+        curr_item->next = item_to_move->next;
+
+        /* fix last_child if required */
+        if(tree->last_child == item_to_move) {
+            tree->last_child = curr_item;
+        } 
+    }
+
+    /*** insert to_move after fixed ***/
+    item_to_move->next = fixed_item->next;
+    fixed_item->next = item_to_move;
+    if(tree->last_child == fixed_item) {
+        tree->last_child = item_to_move;
+    }
+}
+
+
 int
 proto_register_protocol(char *name, char *short_name, char *filter_name)
 {
index 30564b23da13b320aac8fa9d2764d6e2981b68a2..6f0e7d85cd560bbb18c0b959027ae685a760665c 100644 (file)
@@ -239,16 +239,16 @@ typedef proto_node proto_item;
 
 /** is this protocol field hidden from the protocol tree display (used for filtering only)? */
 #define PROTO_ITEM_IS_HIDDEN(proto_item)        \
-       ((proto_item) ? FI_GET_FLAG(proto_item->finfo, FI_HIDDEN) : 0)
+       ((proto_item) ? FI_GET_FLAG((proto_item)->finfo, FI_HIDDEN) : 0)
 /** mark this protocol field to be hidden from the protocol tree display (used for filtering only) */
 #define PROTO_ITEM_SET_HIDDEN(proto_item)       \
-       ((proto_item) ? FI_SET_FLAG(proto_item->finfo, FI_HIDDEN) : 0)
+       ((proto_item) ? FI_SET_FLAG((proto_item)->finfo, FI_HIDDEN) : 0)
 /** is this protocol field generated by Ethereal (and not read from the packet data)? */
 #define PROTO_ITEM_IS_GENERATED(proto_item)    \
-       ((proto_item) ? FI_GET_FLAG(proto_item->finfo, FI_GENERATED) : 0)
+       ((proto_item) ? FI_GET_FLAG((proto_item)->finfo, FI_GENERATED) : 0)
 /** mark this protocol field as generated by Ethereal (and not read from the packet data) */
 #define PROTO_ITEM_SET_GENERATED(proto_item)   \
-       ((proto_item) ? FI_SET_FLAG(proto_item->finfo, FI_GENERATED) : 0)
+       ((proto_item) ? FI_SET_FLAG((proto_item)->finfo, FI_GENERATED) : 0)
 
 
 typedef void (*proto_tree_foreach_func)(proto_node *, gpointer);
@@ -378,6 +378,12 @@ proto_tree_prime_hfid(proto_tree *tree, int hfid);
  @return parent item */
 extern proto_item* proto_tree_get_parent(proto_tree *tree);
 
+/** Move an existing item behind another existing item.
+ @param tree the tree to which both items belong
+ @param item the item which keeps it's position
+ @param item_to_move the item which will be moved */
+extern void proto_tree_move_item(proto_tree *tree, proto_item *fixed_item, proto_item *item_to_move);
+
 
 
 /** Add an item to a proto_tree, using the text label registered to that item.