diff options
author | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-06-20 23:28:35 +0000 |
---|---|---|
committer | Jakub Zawadzki <darkjames-ws@darkjames.pl> | 2013-06-20 23:28:35 +0000 |
commit | 1b69a2b3c8dbc64b0bd203fa638b6f0bbe0daf01 (patch) | |
tree | 38c50a3a05dbd0227f663100cc135015ba792f73 /ui | |
parent | 3258f1297e9ee49ef0b2776db9999775f611b9e2 (diff) |
Highlight protocol bytes in grey, idea stolen from qtshark
svn path=/trunk/; revision=50095
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gtk/bytes_view.c | 40 | ||||
-rw-r--r-- | ui/gtk/bytes_view.h | 5 | ||||
-rw-r--r-- | ui/gtk/packet_panes.c | 57 |
3 files changed, 78 insertions, 24 deletions
diff --git a/ui/gtk/bytes_view.c b/ui/gtk/bytes_view.c index 7e6748044b..86256a0645 100644 --- a/ui/gtk/bytes_view.c +++ b/ui/gtk/bytes_view.c @@ -77,9 +77,9 @@ struct _BytesView bytes_view_type format; /* bytes in hex or bytes as bits */ guint8 *pd; /* packet data */ int len; /* length of packet data in bytes */ -/* data-highlight */ - int start[2]; - int end[2]; +/* data-highlight (field, appendix, protocol) */ + int start[3]; + int end[3]; int per_line; /* number of bytes shown per line */ int use_digits; /* number of hex digits of byte offset */ @@ -473,12 +473,12 @@ bytes_view_flush_render(BytesView *bv, void *data, int x, int y, const char *str context = gtk_widget_get_style_context(GTK_WIDGET(bv)); #endif - if (bv->state == GTK_STATE_SELECTED) { + if (bv->state == GTK_STATE_SELECTED || bv->state == GTK_STATE_INSENSITIVE) { str_width = _pango_runs_width(line_runs); /* background */ #if GTK_CHECK_VERSION(3, 0, 0) - gtk_style_context_get_background_color(context, (GtkStateFlags)(GTK_STATE_FLAG_FOCUSED | GTK_STATE_FLAG_SELECTED), &bg_color); + gtk_style_context_get_background_color(context, (GtkStateFlags)( (bv->state == GTK_STATE_SELECTED ? GTK_STATE_FLAG_FOCUSED : 0) | GTK_STATE_FLAG_SELECTED), &bg_color); gdk_cairo_set_source_rgba(cr, &bg_color); #else gdk_cairo_set_source_color(cr, >k_widget_get_style(GTK_WIDGET(bv))->base[bv->state]); @@ -564,7 +564,7 @@ bytes_view_flush_pos(BytesView *bv, void *data, int x, int search_x, const char static void bytes_view_render_state(BytesView *bv, int state) { - g_assert(state == GTK_STATE_NORMAL || state == GTK_STATE_SELECTED); + g_assert(state == GTK_STATE_NORMAL || state == GTK_STATE_SELECTED || state == GTK_STATE_INSENSITIVE); if (bv->bold_highlight) { pango_font_description_set_weight(bv->font, @@ -621,11 +621,19 @@ _bytes_view_line_common(BytesView *bv, void *data, const int org_off, int xx, in gboolean byte_highlighted = (off >= bv->start[0] && off < bv->end[0]) || (off >= bv->start[1] && off < bv->end[1]); + gboolean proto_byte_highlighted = + (off >= bv->start[2] && off < bv->end[2]); + int state_cur = (off < len && byte_highlighted) ? - GTK_STATE_SELECTED : GTK_STATE_NORMAL; + GTK_STATE_SELECTED : + (off < len && proto_byte_highlighted) ? + GTK_STATE_INSENSITIVE : + GTK_STATE_NORMAL; if (state_cur != state) { - if (state == GTK_STATE_NORMAL && byten) { + /* ok, we want to put space, we prefer to put it in STATE_NORMAL, but if it's transition from field-highlight to proto-highlight (common), do it now */ + /* below shorter version of: ((state != GTK_STATE_NORMAL && state_cur != GTK_STATE_NORMAL) || (state == GTK_STATE_NORMAL)) */ + if (state_cur != GTK_STATE_NORMAL && byten) { str[cur++] = ' '; /* insert a space every BYTE_VIEW_SEP bytes */ if ((off % BYTE_VIEW_SEP) == 0) @@ -697,11 +705,17 @@ _bytes_view_line_common(BytesView *bv, void *data, const int org_off, int xx, in gboolean byte_highlighted = (off >= bv->start[0] && off < bv->end[0]) || (off >= bv->start[1] && off < bv->end[1]); + gboolean proto_byte_highlighted = + (off >= bv->start[2] && off < bv->end[2]); + int state_cur = (off < len && byte_highlighted) ? - GTK_STATE_SELECTED : GTK_STATE_NORMAL; + GTK_STATE_SELECTED : + (off < len && proto_byte_highlighted) ? + GTK_STATE_INSENSITIVE : + GTK_STATE_NORMAL; if (state_cur != state) { - if (state == GTK_STATE_NORMAL && byten) { + if (state_cur != GTK_STATE_NORMAL && byten) { /* insert a space every BYTE_VIEW_SEP bytes */ if ((off % BYTE_VIEW_SEP) == 0) str[cur++] = ' '; @@ -1442,10 +1456,10 @@ bytes_view_set_highlight(BytesView *bv, int start, int end, guint32 mask _U_, in } void -bytes_view_set_highlight_appendix(BytesView *bv, int start, int end) +bytes_view_set_highlight_extra(BytesView *bv, int id, int start, int end) { - bv->start[1] = start; - bv->end[1] = end; + bv->start[id] = start; + bv->end[id] = end; } void diff --git a/ui/gtk/bytes_view.h b/ui/gtk/bytes_view.h index 4c09a74ad7..d6924ea600 100644 --- a/ui/gtk/bytes_view.h +++ b/ui/gtk/bytes_view.h @@ -28,6 +28,9 @@ #define BYTES_VIEW_TYPE (bytes_view_get_type()) #define BYTES_VIEW(object) (G_TYPE_CHECK_INSTANCE_CAST((object), BYTES_VIEW_TYPE, BytesView)) +#define BYTE_VIEW_HIGHLIGHT_APPENDIX 1 +#define BYTE_VIEW_HIGHLIGHT_PROTOCOL 2 + typedef struct _BytesView BytesView; GType bytes_view_get_type(void); @@ -41,7 +44,7 @@ void bytes_view_set_format(BytesView *bv, int format); void bytes_view_set_highlight_style(BytesView *bv, gboolean bold); void bytes_view_set_highlight(BytesView *bv, int start, int end, guint32 mask, int maskle); -void bytes_view_set_highlight_appendix(BytesView *bv, int start, int end); +void bytes_view_set_highlight_extra(BytesView *bv, int id, int start, int end); void bytes_view_refresh(BytesView *bv); int bytes_view_byte_from_xy(BytesView *bv, int x, int y); diff --git a/ui/gtk/packet_panes.c b/ui/gtk/packet_panes.c index 7e760b6b03..2cff89223c 100644 --- a/ui/gtk/packet_panes.c +++ b/ui/gtk/packet_panes.c @@ -93,6 +93,8 @@ #define E_BYTE_VIEW_MASKLE_KEY "byte_view_mask_le" #define E_BYTE_VIEW_APP_START_KEY "byte_view_app_start" #define E_BYTE_VIEW_APP_END_KEY "byte_view_app_end" +#define E_BYTE_VIEW_PROTO_START_KEY "byte_view_proto_start" +#define E_BYTE_VIEW_PROTO_END_KEY "byte_view_proto_end" #define E_BYTE_VIEW_ENCODE_KEY "byte_view_encode" /* Get the current text window for the notebook. */ @@ -807,7 +809,9 @@ savehex_cb(GtkWidget * w _U_, gpointer data _U_) static void packet_hex_update(GtkWidget *bv, const guint8 *pd, int len, int bstart, int bend, guint32 bmask, int bmask_le, - int astart, int aend, int encoding) + int astart, int aend, + int pstart, int pend, + int encoding) { bytes_view_set_encoding(BYTES_VIEW(bv), encoding); bytes_view_set_format(BYTES_VIEW(bv), recent.gui_bytes_view); @@ -816,7 +820,8 @@ packet_hex_update(GtkWidget *bv, const guint8 *pd, int len, int bstart, bytes_view_set_highlight_style(BYTES_VIEW(bv), prefs.gui_hex_dump_highlight_style); bytes_view_set_highlight(BYTES_VIEW(bv), bstart, bend, bmask, bmask_le); - bytes_view_set_highlight_appendix(BYTES_VIEW(bv), astart, aend); + bytes_view_set_highlight_extra(BYTES_VIEW(bv), BYTE_VIEW_HIGHLIGHT_APPENDIX, astart, aend); + bytes_view_set_highlight_extra(BYTES_VIEW(bv), BYTE_VIEW_HIGHLIGHT_PROTOCOL, pstart, pend); if (bstart != -1 && bend != -1) bytes_view_scroll_to_byte(BYTES_VIEW(bv), bstart); @@ -833,7 +838,7 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, int bstart = -1, bend = -1, blen = -1; guint32 bmask = 0x00; int bmask_le = 0; int astart = -1, aend = -1, alen = -1; - + int pstart = -1, pend = -1, plen = -1; if (finfo != NULL) { @@ -864,6 +869,27 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, astart = finfo->appendix_start; alen = finfo->appendix_length; + if (finfo->hfinfo->parent != -1) { + proto_tree *tree = (proto_tree *)g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_TREE_PTR); + GPtrArray *finfo_array; + guint i; + + finfo_array = proto_find_finfo(tree, finfo->hfinfo->parent); + + for (i = 0; i < g_ptr_array_len(finfo_array); i++) { + field_info *parent_finfo = (field_info *) finfo_array->pdata[i]; + + if (parent_finfo->ds_tvb == finfo->ds_tvb) { + pstart = parent_finfo->start; + plen = parent_finfo->length; + break; + } + } + + g_ptr_array_free(finfo_array, TRUE); + + } + if (FI_GET_FLAG(finfo, FI_LITTLE_ENDIAN)) bmask_le = 1; else if (FI_GET_FLAG(finfo, FI_BIG_ENDIAN)) @@ -889,12 +915,14 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, } } - if (bstart >= 0 && blen > 0 && (guint)bstart < len) { + if (pstart >= 0 && plen > 0 && (guint)pstart < len) + pend = pstart + plen; + + if (bstart >= 0 && blen > 0 && (guint)bstart < len) bend = bstart + blen; - } - if (astart >= 0 && alen > 0 && (guint)astart < len) { + + if (astart >= 0 && alen > 0 && (guint)astart < len) aend = astart + alen; - } if (bend == -1 && aend != -1) { bstart = astart; @@ -906,6 +934,7 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, /* don't exceed the end of available data */ if (aend != -1 && (guint)aend > len) aend = len; if (bend != -1 && (guint)bend > len) bend = len; + if (pend != -1 && (guint)pend > len) pend = len; /* save the information needed to redraw the text */ /* should we save the fd & finfo pointers instead ?? */ @@ -915,13 +944,15 @@ packet_hex_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_MASKLE_KEY, GINT_TO_POINTER(bmask_le)); g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_APP_START_KEY, GINT_TO_POINTER(astart)); g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_APP_END_KEY, GINT_TO_POINTER(aend)); + g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_PROTO_START_KEY, GINT_TO_POINTER(pstart)); + g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_PROTO_END_KEY, GINT_TO_POINTER(pend)); g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_ENCODE_KEY, GUINT_TO_POINTER((guint)fd->flags.encoding)); /* stig: it should be done only for bitview... */ if (recent.gui_bytes_view != BYTES_BITS) bmask = 0x00; - packet_hex_update(bv, pd, len, bstart, bend, bmask, bmask_le, astart, aend, fd->flags.encoding); + packet_hex_update(bv, pd, len, bstart, bend, bmask, bmask_le, astart, aend, pstart, pend, fd->flags.encoding); } void @@ -933,6 +964,7 @@ packet_hex_editor_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, int off int bstart = offset, bend = (bstart != -1) ? offset+1 : -1; guint32 bmask=0; int bmask_le = 0; int astart = -1, aend = -1; + int pstart = -1, pend = -1; switch (recent.gui_bytes_view) { case BYTES_HEX: @@ -957,8 +989,10 @@ packet_hex_editor_print(GtkWidget *bv, const guint8 *pd, frame_data *fd, int off g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_APP_END_KEY, GINT_TO_POINTER(aend)); g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_ENCODE_KEY, GUINT_TO_POINTER((guint)fd->flags.encoding)); + g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_PROTO_START_KEY, GINT_TO_POINTER(pstart)); + g_object_set_data(G_OBJECT(bv), E_BYTE_VIEW_PROTO_END_KEY, GINT_TO_POINTER(pend)); - packet_hex_update(bv, pd, len, bstart, bend, bmask, bmask_le, astart, aend, fd->flags.encoding); + packet_hex_update(bv, pd, len, bstart, bend, bmask, bmask_le, astart, aend, pstart, pend, fd->flags.encoding); } /* @@ -970,6 +1004,7 @@ packet_hex_reprint(GtkWidget *bv) { int start, end, mask, mask_le, encoding; int astart, aend; + int pstart, pend; const guint8 *data; guint len = 0; @@ -979,6 +1014,8 @@ packet_hex_reprint(GtkWidget *bv) mask_le = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_MASKLE_KEY)); astart = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_APP_START_KEY)); aend = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_APP_END_KEY)); + pstart = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_PROTO_START_KEY)); + pend = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_PROTO_END_KEY)); data = get_byte_view_data_and_length(bv, &len); g_assert(data != NULL); encoding = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(bv), E_BYTE_VIEW_ENCODE_KEY)); @@ -986,7 +1023,7 @@ packet_hex_reprint(GtkWidget *bv) /* stig: it should be done only for bitview... */ if (recent.gui_bytes_view != BYTES_BITS) mask = 0x00; - packet_hex_update(bv, data, len, start, end, mask, mask_le, astart, aend, encoding); + packet_hex_update(bv, data, len, start, end, mask, mask_le, astart, aend, pstart, pend, encoding); } /* List of all protocol tree widgets, so we can globally set the selection |