main_pref_window.c

Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /*
00003  *  main_pref_window.c
00004  *  heraia - an hexadecimal file editor and analyser based on ghex
00005  *
00006  *  (C) Copyright 2008 - 2010 Olivier Delhomme
00007  *  e-mail : heraia@delhomme.org
00008  *  URL    : http://heraia.tuxfamily.org
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2, or  (at your option)
00013  *  any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY;  without even the implied warranty of
00017  *  MERCHANTABILITY  or  FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024 /**
00025  * @file main_pref_window.c
00026  * Handles main preference window
00027  */
00028 
00029 #include <libheraia.h>
00030 
00031 static gboolean pref_window_delete(GtkWidget *widget, GdkEvent  *event, gpointer data);
00032 static void main_pref_window_connect_signals(heraia_struct_t *main_struct);
00033 
00034 /* ToolBar buttons */
00035 static void on_mp_tb_fp_bt_toggled(GtkToggleToolButton *tool_button, gpointer data);
00036 static void on_mp_tb_display_bt_toggled(GtkToggleToolButton *tool_button, gpointer data);
00037 
00038 /* Toogle Buttons */
00039 static void on_mp_thousand_bt_toggled(GtkToggleButton *toggle_button, gpointer data);
00040 static void on_mp_display_offset_bt_toggled(GtkToggleButton *toggle_button, gpointer data);
00041 
00042 
00043 /******************************** The Signals *********************************/
00044 
00045 /**
00046  * @fn gboolean pref_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
00047  *  Closing the window
00048  * @param widget : calling widget (may be NULL as we don't use this here)
00049  * @param event : event associated (may be NULL as we don't use this here)
00050  * @param data : MUST be heraia_struct_t *main_struct main structure and not NULL
00051  * @return Always returns TRUE in order to propagate the signal
00052  */
00053 static gboolean pref_window_delete(GtkWidget *widget, GdkEvent *event, gpointer data)
00054 {
00055     heraia_struct_t *main_struct = (heraia_struct_t *) data;
00056     GtkWidget *pref_window = NULL;
00057 
00058     if (main_struct != NULL && main_struct->win_prop != NULL && main_struct->win_prop->main_pref_window != NULL)
00059         {
00060             pref_window = heraia_get_widget(main_struct->xmls->main, "main_preferences_window");
00061             save_preferences(main_struct);
00062             record_and_hide_dialog_box(pref_window, main_struct->win_prop->main_pref_window);
00063         }
00064 
00065     return TRUE;
00066 }
00067 
00068 
00069 /**
00070  * @fn void main_pref_window_connect_signals(heraia_struct_t *main_struct)
00071  *  Connecting the window signals to the right functions
00072  * @param main_struct : main structure
00073  */
00074 static void main_pref_window_connect_signals(heraia_struct_t *main_struct)
00075 {
00076     /* Closing the window */
00077     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "main_preferences_window")), "delete-event",
00078                      G_CALLBACK(pref_window_delete), main_struct);
00079 
00080     /* Clicking on the file preference button of the toolbar */
00081     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_tb_fp_bt")), "toggled",
00082                      G_CALLBACK(on_mp_tb_fp_bt_toggled), main_struct);
00083 
00084     /* Clicking on the display button of the toolbar */
00085     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_tb_display_bt")), "toggled",
00086                      G_CALLBACK(on_mp_tb_display_bt_toggled), main_struct);
00087 
00088     /* Toggling the button to choose to display with separated thousand or not */
00089     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_thousand_bt")), "toggled",
00090                      G_CALLBACK(on_mp_thousand_bt_toggled), main_struct);
00091 
00092     /* Toggling the button to choose to display the offsets or not */
00093     g_signal_connect(G_OBJECT(heraia_get_widget(main_struct->xmls->main, "mp_display_offset_bt")), "toggled",
00094                      G_CALLBACK(on_mp_display_offset_bt_toggled), main_struct);
00095 }
00096 
00097 
00098 /**
00099  * Tool buttons
00100  */
00101 
00102 /**
00103  * @fn void on_mp_tb_fp_bt_toggled(GtkToolButton *toolbutton, gpointer data)
00104  *  Main Preferences, ToolBar, File Preference Button
00105  * @param toolbutton : button that was clicked
00106  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
00107  */
00108 static void on_mp_tb_fp_bt_toggled(GtkToggleToolButton *tool_button, gpointer data)
00109 {
00110     heraia_struct_t *main_struct = (heraia_struct_t *) data;
00111     GtkWidget *notebook = NULL;  /* Main Preference Window's Notebook */
00112 
00113     if (main_struct != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
00114         {
00115             notebook = heraia_get_widget(main_struct->xmls->main, "mp_first_notebook");
00116             gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
00117         }
00118 }
00119 
00120 
00121 /**
00122  * @fn void on_mp_tb_display_bt_toggled(GtkToolButton *toolbutton, gpointer data)
00123  * Main Preferences, ToolBar, Display Button
00124  * @param toolbutton : button that was clicked
00125  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
00126  */
00127 static void on_mp_tb_display_bt_toggled(GtkToggleToolButton *tool_button, gpointer data)
00128 {
00129     heraia_struct_t *main_struct = (heraia_struct_t *) data;
00130     GtkWidget *notebook = NULL;  /* Main Preference Window's Notebook */
00131 
00132     if (main_struct != NULL && main_struct->xmls != NULL && main_struct->xmls->main != NULL)
00133         {
00134 
00135             notebook = heraia_get_widget(main_struct->xmls->main, "mp_first_notebook");
00136             gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
00137         }
00138 }
00139 
00140 
00141 /**
00142  * @fn void on_mp_thousand_bt_toggled(GtkToggleButton *togglebutton, gpointer data)
00143  * Refreshes the file labels as an option has been sat
00144  * @param togglebutton : button that was toggled
00145  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
00146  */
00147 static void on_mp_thousand_bt_toggled(GtkToggleButton *toggle_button, gpointer data)
00148 {
00149     heraia_struct_t *main_struct = (heraia_struct_t *) data;
00150 
00151     refresh_file_labels(main_struct);
00152 }
00153 
00154 
00155 /**
00156  * Displays or not offsets
00157  * @param togglebutton : button that was toggled
00158  * @param data : user data : MUST be heraia_struct_t *main_struct main structure
00159  */
00160 static void on_mp_display_offset_bt_toggled(GtkToggleButton *toggle_button, gpointer data)
00161 {
00162     heraia_struct_t *main_struct = (heraia_struct_t *) data;
00163     doc_t *document = NULL;
00164     guint i = 0;
00165 
00166     if (toggle_button != NULL && main_struct != NULL && main_struct->documents != NULL)
00167         {
00168 
00169              for(i = 0; i < main_struct->documents->len; i++)
00170                 {
00171                     document = g_ptr_array_index(main_struct->documents, i);
00172                     gtk_hex_show_offsets(GTK_HEX(document->hex_widget), gtk_toggle_button_get_active(toggle_button));
00173                 }
00174         }
00175 }
00176 
00177 /******************************** End Signals *********************************/
00178 
00179 
00180 /**
00181  * @fn main_pref_window_init_interface(heraia_struct_t *main_struct)
00182  *  Inits the main preferences window interface
00183  * @param main_struct : main structure
00184  */
00185 void main_pref_window_init_interface(heraia_struct_t *main_struct)
00186 {
00187     main_pref_window_connect_signals(main_struct);
00188 }
Generated on Tue Aug 10 18:29:02 2010 for Heraia by  doxygen 1.6.3