From 90303fb17f8bb45b6955c80856907cdfeb87cd86 Mon Sep 17 00:00:00 2001 From: Stephen Fisher Date: Tue, 14 Nov 2006 22:35:22 +0000 Subject: New feature to automatically highlight the field found when doing a find. This works for both string and hex searches. This resolves feature request bug #776. svn path=/trunk/; revision=19897 --- gtk/main.c | 14 ++++++++++++++ gtk/proto_draw.c | 33 ++++++++++++++++++++++++++++----- gtk/proto_draw.h | 18 ++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) (limited to 'gtk') diff --git a/gtk/main.c b/gtk/main.c index 17a257ac93..3782fecff8 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1861,6 +1861,20 @@ main_cf_cb_packet_selected(gpointer data) add_main_byte_views(cf->edt); main_proto_tree_draw(cf->edt->tree); + /* The user is searching for a string in the data or a hex value, + * highlight the field that is found in the tree and hex displays. */ +#if GTK_MAJOR_VERSION < 2 + if((cfile.string || cfile.hex) && cfile.search_pos != 0) { + highlight_field(cf->edt->tvb, cfile.search_pos, + (GtkCTree *)tree_view, cf->edt->tree); +#else + if((cfile.string || cfile.hex) && cfile.search_pos != 0) { + highlight_field(cf->edt->tvb, cfile.search_pos, + (GtkTreeView *)tree_view, cf->edt->tree); +#endif + cfile.search_pos = 0; /* Reset the position */ + } + /* A packet is selected. */ set_menus_for_selected_packet(cf); } diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c index cd0c047de7..f7221e50f5 100644 --- a/gtk/proto_draw.c +++ b/gtk/proto_draw.c @@ -386,15 +386,10 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event) GtkText *bv = GTK_TEXT(widget); #else GtkTreeView *tree_view; - GtkTreeModel *model; - GtkTreePath *first_path, *path; - GtkTreeIter parent; GtkTextView *bv = GTK_TEXT_VIEW(widget); gint x, y; GtkTextIter iter; - struct field_lookup_info fli; #endif - field_info *finfo; int row, column; int byte; tvbuff_t *tvb; @@ -546,6 +541,34 @@ byte_view_select(GtkWidget *widget, GdkEventButton *event) /* Get the data source tvbuff */ tvb = OBJECT_GET_DATA(widget, E_BYTE_VIEW_TVBUFF_KEY); +#if GTK_MAJOR_VERSION < 2 + return highlight_field(tvb, byte, ctree, tree); +#else + return highlight_field(tvb, byte, tree_view, tree); +#endif +} + +/* This highlights the field in the proto tree that is at position byte */ +#if GTK_MAJOR_VERSION < 2 +gboolean +highlight_field(tvbuff_t *tvb, gint byte, GtkCTree *ctree, + proto_tree *tree) +#else +gboolean +highlight_field(tvbuff_t *tvb, gint byte, GtkTreeView *tree_view, + proto_tree *tree) +#endif +{ +#if GTK_MAJOR_VERSION < 2 + GtkCTreeNode *node, *parent; +#else + GtkTreeModel *model; + GtkTreePath *first_path, *path; + GtkTreeIter parent; + struct field_lookup_info fli; +#endif + field_info *finfo; + /* Find the finfo that corresponds to our byte. */ finfo = proto_find_field_from_offset(tree, byte, tvb); diff --git a/gtk/proto_draw.h b/gtk/proto_draw.h index d49930c03f..094b0bf0a9 100644 --- a/gtk/proto_draw.h +++ b/gtk/proto_draw.h @@ -102,6 +102,24 @@ extern void add_byte_views(epan_dissect_t *edt, GtkWidget *tree_view, */ extern gboolean byte_view_select(GtkWidget *widget, GdkEventButton *event); +/** This highlights the field in the proto tree that is at position byte + * + * @param tvb the current tvbuff + * @param byte the byte offset within the packet to highlight + * @param tree_view the current tree_view + * @param tree the current tree + * @return TRUE if highlighting was successful + */ +#if GTK_MAJOR_VERSION < 2 +gboolean +highlight_field(tvbuff_t *tvb, gint byte, GtkCTree *ctree, + proto_tree *tree); +#else +gboolean +highlight_field(tvbuff_t *tvb, gint byte, GtkTreeView *tree_view, + proto_tree *tree); +#endif + /** Callback for "Export Selected Packet Bytes" operation. * * @param w unused -- cgit v1.2.3