00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <libheraia.h>
00030
00031 static gboolean delete_goto_dialog_event(GtkWidget *widget, GdkEvent *event, gpointer data);
00032 static void destroy_goto_dialog_event(GtkWidget *widget, GdkEvent *event, gpointer data);
00033 static void goto_dialog_canceled(GtkWidget *widget, gpointer data);
00034 static void goto_dialog_connect_signal(heraia_struct_t *main_struct);
00035
00036
00037
00038
00039
00040
00041
00042 void on_goto_activate(GtkWidget *widget, gpointer data)
00043 {
00044 heraia_struct_t *main_struct = (heraia_struct_t *) data;
00045 GtkWidget *dialog = NULL;
00046
00047 if (main_struct != NULL && main_struct->current_doc != NULL)
00048 {
00049 dialog = heraia_get_widget(main_struct->xmls->main, "goto_dialog");
00050 show_hide_widget(dialog, TRUE, main_struct->win_prop->goto_window);
00051 }
00052 }
00053
00054
00055
00056
00057
00058
00059 void goto_dialog_init_interface(heraia_struct_t *main_struct)
00060 {
00061 if (main_struct != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
00062 {
00063 goto_dialog_connect_signal(main_struct);
00064 }
00065 }
00066
00067
00068
00069
00070
00071
00072
00073
00074 static gboolean delete_goto_dialog_event(GtkWidget *widget, GdkEvent *event, gpointer data)
00075 {
00076 goto_dialog_canceled(widget, data);
00077
00078 return TRUE;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088 static void destroy_goto_dialog_event(GtkWidget *widget, GdkEvent *event, gpointer data)
00089 {
00090 goto_dialog_canceled(widget, data);
00091 }
00092
00093
00094
00095
00096
00097
00098
00099 static void goto_dialog_canceled(GtkWidget *widget, gpointer data)
00100 {
00101 heraia_struct_t *main_struct = (heraia_struct_t *) data;
00102 GtkWidget *dialog = NULL;
00103
00104 if (main_struct != NULL)
00105 {
00106 dialog = heraia_get_widget(main_struct->xmls->main, "goto_dialog");
00107 show_hide_widget(dialog, FALSE, main_struct->win_prop->goto_window);
00108 }
00109 }
00110
00111
00112
00113
00114
00115
00116
00117 static void goto_dialog_ok(GtkWidget *widget, gpointer data)
00118 {
00119 heraia_struct_t *main_struct = (heraia_struct_t *) data;
00120 GtkWidget *radio_button = NULL;
00121 GtkWidget *radio_active = NULL;
00122 const gchar *widget_name = NULL;
00123 const gchar *entry_text = NULL;
00124 guint64 offset = 0;
00125 gboolean convert_ok = FALSE;
00126
00127
00128 radio_button = heraia_get_widget(main_struct->xmls->main, "goto_from_beginning");
00129
00130 if (radio_button != NULL && main_struct->current_doc != NULL)
00131 {
00132 entry_text = gtk_entry_get_text(GTK_ENTRY(heraia_get_widget(main_struct->xmls->main, "goto_entry")));
00133
00134 if (entry_text[0] == '0' && entry_text[1] == 'x')
00135 {
00136 convert_ok = (sscanf(entry_text, "%llx", (long long unsigned int *) &offset) == 1);
00137 }
00138 else
00139 {
00140 convert_ok = (sscanf(entry_text, "%llu", (long long unsigned int *) &offset) == 1);
00141 }
00142
00143 if (convert_ok == TRUE)
00144 {
00145
00146 radio_active = gtk_radio_button_get_active_from_widget(GTK_RADIO_BUTTON(radio_button));
00147
00148 if (radio_active != NULL)
00149 {
00150 widget_name = gtk_buildable_get_name(GTK_BUILDABLE(radio_active));
00151 }
00152
00153
00154 if (widget_name != NULL)
00155 {
00156 if (g_ascii_strcasecmp(widget_name, "goto_from_beginning") == 0)
00157 {
00158 ghex_set_cursor_position(main_struct->current_doc->hex_widget, offset - 1);
00159 }
00160 else if (g_ascii_strcasecmp(widget_name, "goto_from_here_fwd") == 0)
00161 {
00162 offset += ghex_get_cursor_position(main_struct->current_doc->hex_widget);
00163 ghex_set_cursor_position(main_struct->current_doc->hex_widget, offset);
00164 }
00165 else if (g_ascii_strcasecmp(widget_name, "goto_from_here_rwd") == 0)
00166 {
00167 offset = ghex_get_cursor_position(main_struct->current_doc->hex_widget) - offset ;
00168 ghex_set_cursor_position(main_struct->current_doc->hex_widget, offset);
00169 }
00170 else
00171 {
00172 offset = ghex_file_size(GTK_HEX(main_struct->current_doc->hex_widget)) - offset;
00173 ghex_set_cursor_position(main_struct->current_doc->hex_widget, offset);
00174 }
00175 }
00176 }
00177 }
00178 }
00179
00180
00181
00182
00183
00184
00185
00186 static void goto_dialog_connect_signal(heraia_struct_t *main_struct)
00187 {
00188
00189 g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "gtd_cancel_bt")), "clicked",
00190 G_CALLBACK(goto_dialog_canceled), main_struct);
00191
00192
00193 g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "gtd_ok_bt")), "clicked",
00194 G_CALLBACK(goto_dialog_ok), main_struct);
00195
00196
00197
00198 g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "goto_dialog")), "delete_event",
00199 G_CALLBACK(delete_goto_dialog_event), main_struct);
00200
00201 g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "goto_dialog")), "destroy",
00202 G_CALLBACK(destroy_goto_dialog_event), main_struct);
00203 }