Palmer.
What we really should do is add this to the Edit menu as well.
svn path=/trunk/; revision=11883
Neil Piercy <Neil.Piercy [AT] ipaccess.com>
RĂ©mi Denis-Courmont <courmisch [AT] via.ecp.fr>
Francisco Alcoba <francisco.alcoba [AT] ericsson.com>
+Thomas Palmer <tpalmer [AT] elmore.rr.com>
Alain Magloire <alainm[AT]rcsm.ece.mcgill.ca> was kind enough to
give his permission to use his version of snprintf.c.
ITEM_FACTORY_ENTRY("/Display Filters...", NULL, dfilter_dialog_cb,
0, NULL, NULL),
ITEM_FACTORY_ENTRY("/Export Selected Packet Bytes...", NULL, savehex_cb,
+ 0, NULL, NULL),
+ ITEM_FACTORY_ENTRY("/Copy Packet Bytes into Clipboard", NULL, copy_hex_cb,
0, NULL, NULL)
};
savehex_dlg = NULL;
}
+extern void
+copy_hex_cb(GtkWidget * w _U_, gpointer data _U_)
+{
+ GtkWidget *bv;
+ int len;
+ int i=0;
+ const guint8 *data_p = NULL;
+ GString *ASCII_representation = g_string_new("");
+ GString *byte_str = g_string_new("");
+
+ bv = get_notebook_bv_ptr(byte_nb_ptr);
+ if (bv == NULL) {
+ /* shouldn't happen */
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Could not find the corresponding text window!");
+ return;
+ }
+
+ data_p = get_byte_view_data_and_length(GTK_WIDGET(bv), &len);
+
+ g_string_append_printf(byte_str,"%04x ",i); /* Offset 0000 */
+ for (i=0; i<len; i++){
+ g_string_append_printf(ASCII_representation,"%c",isprint(*data_p) ? *data_p : '.');
+ g_string_append_printf(byte_str," %02x",*data_p++);
+ if ((i+1)%16==0 && i!=0){
+ g_string_append_printf(byte_str," %s\n%04x ",ASCII_representation->str,i+1);
+ g_string_assign (ASCII_representation,"");
+ }
+ }
+
+ if(ASCII_representation->len){
+ for (i=ASCII_representation->len; i<16; i++){
+ g_string_append_printf(byte_str," ");
+ }
+ g_string_append_printf(byte_str," %s\n",ASCII_representation->str);
+ }
+ /* Now that we have the byte data, copy it into the default clipboard */
+ copy_to_clipboard(byte_str);
+ g_string_free(byte_str, TRUE); /* Free the memory */
+ g_string_free(ASCII_representation, TRUE); /* Free the memory */
+}
+
/* save the current highlighted hex data */
static void
savehex_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_)
*/
extern void savehex_cb(GtkWidget * w, gpointer data);
+/** Callback for "Copy packet bytes to clipboard" operation.
+ *
+ * @param w unused
+ * @param data unused
+ */
+extern void copy_hex_cb(GtkWidget * w, gpointer data);
+
#if GTK_MAJOR_VERSION < 2
/** Redraw a given byte view window.
*
return plugins_list;
}
+extern void
+copy_to_clipboard(GString *str)
+{
+#if (GTK_MAJOR_VERSION >= 2)
+ GtkClipboard *cb;
+
+ cb = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD); /* Get the default clipboard */
+ gtk_clipboard_set_text(cb, str->str, -1); /* Copy the byte data into the clipboard */
+#else
+ GtkWidget *window;
+ GtkWidget *text;
+
+ window = window_new (GTK_WINDOW_TOPLEVEL,"");
+ text = gtk_text_new (NULL, NULL); /* Create the GtkText widget */
+ gtk_container_add (GTK_CONTAINER (window), text); /* Avoid a GTK assertion */
+ gtk_widget_realize (text); /* Realizing a widget creates a window for it, ready for us to insert some text */
+ gtk_text_insert (GTK_TEXT (text), NULL, NULL, NULL, str->str, -1);
+ gtk_editable_select_region((GtkEditable *)text, 0, -1); /* Select ALL text */
+ gtk_editable_copy_clipboard((GtkEditable *)text); /* Copy the byte data into the clipboard */
+#endif
+}
*/
extern GtkWidget *xpm_to_widget_from_parent(GtkWidget *parent, const char ** xpm);
+/** Copy a GString to the clipboard.
+ *
+ * @param str GString that is to be copied to the clipboard.
+ */
+extern void copy_to_clipboard(GString *str);
+
#endif /* __GTKGUIUI_UTIL_H__ */