goto_dialog.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003   goto_dialog.c
00004   goto_dialog.c - everything to manage the dialog that lets one go everywhere
00005                   in the file
00006 
00007   (C) Copyright 2010 - 2011 Olivier Delhomme
00008   e-mail : heraia@delhomme.org
00009   URL    : http://heraia.tuxfamily.org
00010 
00011   This program is free software; you can redistribute it and/or modify
00012   it under the terms of the GNU General Public License as published by
00013   the Free Software Foundation; either version 2, or  (at your option)
00014   any later version.
00015 
00016   This program is distributed in the hope that it will be useful,
00017   but WITHOUT ANY WARRANTY;  without even the implied warranty of
00018   MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the
00019   GNU General Public License for more details.
00020 
00021   You should have received a copy of the GNU General Public License
00022   along with this program; if not, write to the Free Software
00023   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00024 */
00025 /**
00026  * @file goto_dialog.c
00027  *  File for the goto dialog window that lets one go everywhere in the file.
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  * Go to..., edit menu
00039  * @param widget : the widget that issued the signal
00040  * @param data : user data MUST be heraia_struct_t *main_struct main structure
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;   /**< dialog window itself */
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  * Inits all the things in the goto dialog window (signal and such)
00057  * @param main_struct : heraia's main structure
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  * Call back function for the goto dialog window destruction
00070  * @param widget : calling widget (may be NULL as we don't use this here)
00071  * @param event : event associated (may be NULL as we don't use this here)
00072  * @param data :  MUST be heraia_struct_t *main_struct main structure
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  * Call back function for the goto dialog window destruction
00084  * @param widget : calling widget (may be NULL as we don't use this here)
00085  * @param event : event associated (may be NULL as we don't use this here)
00086  * @param data : user data - not used (may be NULL)
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  * Closing the window effectively
00096  * @param widget : calling widget
00097  * @param data : MUST be heraia_struct_t *main_struct main structure and not NULL
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;   /**< dialog window itself */
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  * Ok button has been clicked we want to go to the byte number from the entry
00114  * @param widget : calling widget
00115  * @param data : MUST be heraia_struct_t *main_struct main structure and not NULL
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;   /**< a radio button from the group                      */
00121      GtkWidget *radio_active = NULL;   /**< the radio button which is active within this group */
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                     /* guessing which radio is active (by name) */
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  * Signal connections for the goto dialog window
00184  * @param main_struct : heraia's main structure
00185  */
00186 static void goto_dialog_connect_signal(heraia_struct_t *main_struct)
00187 {
00188     /* Cancel button */
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     /* Ok button */
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     /* When goto dialog's window is killed or destroyed */
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 }
Generated on Mon May 2 21:04:49 2011 for Heraia by  doxygen 1.6.3