summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkextstatusbar.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2009-07-31 23:34:56 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2009-07-31 23:34:56 (GMT)
commitd02deb2425d6559c357bdd00e1c0fb05f35d5fc9 (patch)
tree1a78849aa7d51706856a6c6127f66b48c188d0fc /src/gtkext/gtkextstatusbar.c
parentfd2abec30a224279c62a7ab4892d95e56cb08dff (diff)
Processed disassembling in a dedicated thread.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@104 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/gtkext/gtkextstatusbar.c')
-rw-r--r--src/gtkext/gtkextstatusbar.c228
1 files changed, 228 insertions, 0 deletions
diff --git a/src/gtkext/gtkextstatusbar.c b/src/gtkext/gtkextstatusbar.c
new file mode 100644
index 0000000..cb6851d
--- /dev/null
+++ b/src/gtkext/gtkextstatusbar.c
@@ -0,0 +1,228 @@
+
+/* OpenIDA - Outil d'analyse de fichiers binaires
+ * gtkextstatusbar.h - prototypes pour la barre de statut améliorée
+ *
+ * Copyright (C) 2009 Cyrille Bagard
+ *
+ * This file is part of OpenIDA.
+ *
+ * OpenIDA is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * OpenIDA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "gtkextstatusbar.h"
+
+
+#include <malloc.h>
+#include <string.h>
+
+
+
+/* Initialise la classe des barres de statut améliorées. */
+static void gtk_extended_status_bar_class_init(GtkExtStatusBarClass *);
+
+/* Initialise une instance de barre de statut améliorée. */
+static void gtk_extended_status_bar_init(GtkExtStatusBar *);
+
+
+
+/* Détermine le type de la barre de statut améliorée. */
+G_DEFINE_TYPE(GtkExtStatusBar, gtk_extended_status_bar, GTK_TYPE_STATUSBAR)
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe GTK à initialiser. *
+* *
+* Description : Initialise la classe des barres de statut améliorées. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_extended_status_bar_class_init(GtkExtStatusBarClass *klass)
+{
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bar = instance GTK à initialiser. *
+* *
+* Description : Initialise une instance de barre de statut améliorée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_extended_status_bar_init(GtkExtStatusBar *bar)
+{
+ bar->context = gtk_statusbar_get_context_id(GTK_STATUSBAR(bar), "");
+
+ bar->progress = GTK_PROGRESS_BAR(gtk_progress_bar_new());
+
+ gtk_widget_set_size_request(GTK_WIDGET(bar->progress), 200, -1);
+
+ gtk_progress_bar_set_fraction(bar->progress, 0.5);
+ gtk_progress_bar_set_text(bar->progress, "50%");
+
+ gtk_box_pack_start(GTK_BOX(bar), GTK_WIDGET(bar->progress), FALSE, FALSE, 4);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée une nouvelle instance de barre de statut. *
+* *
+* Retour : Composant GTK mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkWidget *gtk_extended_status_bar_new(void)
+{
+ return g_object_new(GTK_TYPE_EXT_STATUS_BAR, NULL);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bar = barre de statut à manipuler. *
+* message = message à afficher pour l'utilisateur. *
+* progressive = utilisation de la barre de progression. *
+* *
+* Description : Place un nouveau message dans la barre de statut. *
+* *
+* Retour : Identifiant du nouveau statut défini. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+guint gtk_extended_status_bar_push(GtkExtStatusBar *bar, const gchar *message, gboolean progressive)
+{
+ guint result; /* Identifiant à retourner */
+
+ result = gtk_statusbar_push(GTK_STATUSBAR(bar), bar->context, message);
+
+ bar->msg_count++;
+ bar->msg_id = (guint *)realloc(bar->msg_id, bar->msg_count * sizeof(guint));
+ bar->is_progressive = (gboolean *)realloc(bar->is_progressive, bar->msg_count * sizeof(gboolean));
+
+ bar->msg_id[bar->msg_count - 1] = result;
+ bar->is_progressive[bar->msg_count - 1] = progressive;
+
+ if (progressive)
+ {
+ gtk_progress_bar_set_fraction(bar->progress, 0.0);
+ gtk_progress_bar_set_text(bar->progress, "0%");
+
+ gtk_widget_show(GTK_WIDGET(bar->progress));
+
+ }
+ else gtk_widget_hide(GTK_WIDGET(bar->progress));
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bar = barre de statut à manipuler. *
+* id = identifiant du message concerné. *
+* value = valeur actuelle de la progression. *
+* *
+* Description : Met à jour la barre de progression de la barre de statut. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void gtk_extended_status_bar_update_activity(GtkExtStatusBar *bar, guint id, gdouble value)
+{
+ gchar percent[5]; /* Pourcentage en version txt. */
+
+ if (bar->msg_count == 0) return;
+
+ gdk_threads_enter();
+
+ if (id == bar->msg_id[bar->msg_count - 1] && bar->is_progressive[bar->msg_count - 1])
+ {
+ g_snprintf(percent, 5, "%.0f%%", value * 100);
+
+ gtk_progress_bar_set_fraction(bar->progress, value);
+ gtk_progress_bar_set_text(bar->progress, percent);
+
+ }
+
+ gdk_flush ();
+
+ gdk_threads_leave();
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : bar = barre de statut à manipuler. *
+* id = identifiant du statut à supprimer. *
+* *
+* Description : Retire de la barre un statut, visible ou non. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void gtk_extended_status_bar_remove(GtkExtStatusBar *bar, guint id)
+{
+ size_t i; /* Boucle de parcours */
+
+ gtk_statusbar_remove(GTK_STATUSBAR(bar), bar->context, id);
+
+ for (i = 0; i < bar->msg_count; i++)
+ if (bar->msg_id[i] == id)
+ break;
+
+ if ((i + 1) < bar->msg_count)
+ {
+ memmove(&bar->msg_id[i], &bar->msg_id[i + 1], (bar->msg_count - i - 1) * sizeof(guint));
+ memmove(&bar->is_progressive[i], &bar->is_progressive[i + 1], (bar->msg_count - i - 1) * sizeof(gboolean));
+ }
+
+ bar->msg_count--;
+ bar->msg_id = (guint *)realloc(bar->msg_id, bar->msg_count * sizeof(guint));
+ bar->is_progressive = (gboolean *)realloc(bar->is_progressive, bar->msg_count * sizeof(gboolean));
+
+ if (bar->msg_count > 0 && bar->is_progressive[bar->msg_count - 1])
+ gtk_widget_show(GTK_WIDGET(bar->progress));
+
+ else
+ gtk_widget_hide(GTK_WIDGET(bar->progress));
+
+}