From 33c1281b6a4e46e94daa3d165e32024f7d85d856 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sun, 28 Jun 2009 22:35:31 +0000
Subject: Drawn a border around the views when needed.

git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@82 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
---
 ChangeLog                   |   9 ++++
 src/gtkext/gtkbinview-int.h |   4 ++
 src/gtkext/gtkbinview.c     | 112 ++++++++++++++++++++++++++++++++++++++++++++
 src/gtkext/gtkbinview.h     |   3 ++
 src/gtkext/gtkblockview.c   |  75 +++++++++++++----------------
 src/gtkext/gtkgraphview.c   |  58 +++--------------------
 6 files changed, 167 insertions(+), 94 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7d2186d..6678b02 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+09-06-29  Cyrille Bagard <nocbos@gmail.com>
+
+	* src/gtkext/gtkbinview.c:
+	* src/gtkext/gtkbinview.h:
+	* src/gtkext/gtkbinview-int.h:
+	* src/gtkext/gtkblockview.c:
+	* src/gtkext/gtkgraphview.c:
+	Reorganize the code. Draw a border around the views when needed.
+
 09-06-28  Cyrille Bagard <nocbos@gmail.com>
 
 	* src/graph/dot.c:
diff --git a/src/gtkext/gtkbinview-int.h b/src/gtkext/gtkbinview-int.h
index 0c17554..63334d5 100644
--- a/src/gtkext/gtkbinview-int.h
+++ b/src/gtkext/gtkbinview-int.h
@@ -47,6 +47,10 @@ struct _GtkBinview
 {
     GtkFixed parent;                        /* A laisser en premier        */
 
+    GdkGC *gc;                              /* Contexte graphique du rendu */
+
+    bool show_border;                       /* Affichage d'une bordure ?   */
+
     openida_binary *binary;                 /* Contenu binaire affiché     */
 
     GRenderingLine *lines;                  /* Contenu à représenter       */
diff --git a/src/gtkext/gtkbinview.c b/src/gtkext/gtkbinview.c
index 2cb046f..ccb533f 100644
--- a/src/gtkext/gtkbinview.c
+++ b/src/gtkext/gtkbinview.c
@@ -29,7 +29,11 @@
 
 
 
+/* Encadre la construction graphique initiale de la visualisation. */
+static void gtk_bin_view_realize(GtkWidget *);
 
+/* Met à jour l'affichage de la visualisation de code binaire. */
+static gboolean gtk_bin_view_expose(GtkBinView *, GdkEventExpose *);
 
 
 
@@ -61,6 +65,9 @@ static void gtk_binview_class_init(GtkBinviewClass *class)
 
     widget_class = GTK_WIDGET_CLASS(class);
 
+    widget_class->realize = gtk_bin_view_realize;
+    widget_class->expose_event = gtk_bin_view_expose;
+
 }
 
 
@@ -102,8 +109,113 @@ GtkWidget* gtk_binview_new(void)
 }
 
 
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : widget = composant GTK à redessiner.                         *
+*                                                                             *
+*  Description : Encadre la construction graphique initiale de la visualisat°.*
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_bin_view_realize(GtkWidget *widget)
+{
+    GdkWindowAttr attributes;               /* Propriétés du composant     */
+    guint attributes_mask;                  /* Masque de prise en compte   */
+    GdkColor white;                         /* Couleur de fond normale     */
+
+    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
+
+    attributes.window_type = GDK_WINDOW_CHILD;
+    attributes.x = widget->allocation.x;
+    attributes.y = widget->allocation.y;
+    attributes.width = widget->allocation.width;
+    attributes.height = widget->allocation.height;
+
+    attributes.wclass = GDK_INPUT_OUTPUT;
+    attributes.event_mask = gtk_widget_get_events(widget)
+        | GDK_BUTTON_PRESS_MASK | GDK_EXPOSURE_MASK;
+
+    attributes_mask = GDK_WA_X | GDK_WA_Y;
+
+    widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
+                                    &attributes, attributes_mask);
+
+    gdk_window_set_user_data(widget->window, widget);
+
+    widget->style = gtk_style_attach(widget->style, widget->window);
+
+    gdk_color_white(gtk_widget_get_colormap(widget), &white);
+    gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &white);
+
+    GTK_BIN_VIEW(widget)->gc = gdk_gc_new(GDK_DRAWABLE(widget->window));
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : view  = composant GTK à redessiner.                          *
+*                event = informations liées à l'événement.                    *
+*                                                                             *
+*  Description : Met à jour l'affichage de la visualisation de code binaire.  *
+*                                                                             *
+*  Retour      : FALSE pour poursuivre la propagation de l'événement.         *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static gboolean gtk_bin_view_expose(GtkBinView *view, GdkEventExpose *event)
+{
+    GdkGCValues values;                     /* Propriétés du contexte      */
+    GtkStyle *style;                        /* Style associé au composant  */
+    int width;                              /* Largeur de l'élément        */
+    int height;                             /* Hauteur de l'élément        */
+
+    if (view->show_border)
+    {
+        gdk_gc_get_values(view->gc, &values);
+        style = gtk_widget_get_style(GTK_WIDGET(view));
+
+        gtk_widget_get_size_request(GTK_WIDGET(view), &width, &height);
+
+        gdk_gc_set_foreground(view->gc, &style->black);
+
+        gdk_draw_rectangle(GDK_DRAWABLE(GTK_WIDGET(view)->window), view->gc,
+                           FALSE, 0, 0, width - 1, height - 1);
+
+        gdk_gc_set_foreground(view->gc, &values.foreground);
+
+    }
+
+    return FALSE;
+
+}
+
+
 
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : view = composant GTK à mettre à jour.                        *
+*                show = état de l'affichage auquel parvenir.                  *
+*                                                                             *
+*  Description : Définit si une bordure est à afficher.                       *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
 
+void gtk_bin_view_show_border(GtkBinview *view, bool show)
+{
+    view->show_border = show;
+
+}
 
 
 
diff --git a/src/gtkext/gtkbinview.h b/src/gtkext/gtkbinview.h
index 10f1c2f..978c146 100644
--- a/src/gtkext/gtkbinview.h
+++ b/src/gtkext/gtkbinview.h
@@ -54,6 +54,9 @@ GType gtk_binview_get_type(void);
 /* Crée un nouveau composant pour l'affichage de morceaux. */
 GtkWidget* gtk_binview_new(void);
 
+/* Définit si une bordure est à afficher. */
+void gtk_bin_view_show_border(GtkBinview *, bool);
+
 
 
 /* Définit les lignes à associer à la représentation. */
diff --git a/src/gtkext/gtkblockview.c b/src/gtkext/gtkblockview.c
index 10941ab..b03bbff 100644
--- a/src/gtkext/gtkblockview.c
+++ b/src/gtkext/gtkblockview.c
@@ -45,7 +45,6 @@ struct _GtkBlockView
     bool show_code;                         /* Affichage du code brut ?    */
 
     PangoLayout *layout;                    /* Moteur de rendu du code ASM */
-    GdkGC *gc;                              /* Contexte graphique du rendu */
     int line_height;                        /* Hauteur maximale des lignes */
 
     const exe_format *format;               /* Format du contenu bianire   */
@@ -64,6 +63,12 @@ struct _GtkBlockViewClass
 static void gtk_block_view_init(GtkBlockView *);
 
 
+
+/* Encadre la construction graphique initiale de la visualisation. */
+static void gtk_block_view_realize(GtkWidget *);
+
+
+
 /* Définit les lignes du bloc de représentation. */
 static void gtk_block_view_set_rendering_lines(GtkBlockView *, GRenderingLine *, GRenderingLine *);
 
@@ -98,7 +103,6 @@ static void gtk_block_view_size_request(GtkWidget *widget,
     GtkRequisition *requisition);
 static void gtk_block_view_size_allocate(GtkWidget *widget,
     GtkAllocation *allocation);
-static void gtk_block_view_realize(GtkWidget *widget);
 
 
 static gboolean gtk_block_view_button_press(GtkWidget *, GdkEventButton *event);
@@ -205,45 +209,28 @@ gtk_block_view_size_allocate(GtkWidget *widget,
 }
 
 
-static void
-gtk_block_view_realize(GtkWidget *widget)
-{
-    GdkWindowAttr attributes;
-    guint attributes_mask;
-    GdkColor white;                         /* Couleur de fond normale     */
-
-  g_return_if_fail(widget != NULL);
-  g_return_if_fail(GTK_IS_BLOCK_VIEW(widget));
-
-  GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
-
-  attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.x = widget->allocation.x;
-  attributes.y = widget->allocation.y;
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
-
-  attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.event_mask = gtk_widget_get_events(widget) | GDK_BUTTON_PRESS_MASK | GDK_EXPOSURE_MASK;
-
-  attributes_mask = GDK_WA_X | GDK_WA_Y;
-
-  widget->window = gdk_window_new(
-     gtk_widget_get_parent_window (widget),
-     & attributes, attributes_mask
-  );
-
-  gdk_window_set_user_data(widget->window, widget);
 
-    widget->style = gtk_style_attach(widget->style, widget->window);
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : widget = composant GTK à redessiner.                         *
+*                                                                             *
+*  Description : Encadre la construction graphique initiale de la visualisat°.*
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
 
+static void gtk_block_view_realize(GtkWidget *widget)
+{
+    GtkBinViewClass *parent_class;          /* Version pure du parent      */
 
-    gdk_color_white(gtk_widget_get_colormap(widget), &white);
-    gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &white);
+    parent_class = GTK_BIN_VIEW_CLASS(g_type_class_peek_parent(GTK_BLOCK_VIEW_GET_CLASS(widget)));
 
+    GTK_WIDGET_CLASS(parent_class)->realize(widget);
 
     GTK_BLOCK_VIEW(widget)->layout = gtk_widget_create_pango_layout(widget, NULL);
-    GTK_BLOCK_VIEW(widget)->gc = gdk_gc_new(GDK_DRAWABLE(widget->window));
 
 }
 
@@ -329,6 +316,8 @@ void gtk_block_view_update_margin(GRenderingLine *line, GtkBlockView *view)
 
 static gboolean gtk_block_view_expose(GtkWidget *widget, GdkEventExpose *event)
 {
+    GtkBinViewClass *parent_class;          /* Version pure du parent      */
+
   g_return_val_if_fail(widget != NULL, FALSE);
   g_return_val_if_fail(GTK_IS_BLOCK_VIEW(widget), FALSE);
   g_return_val_if_fail(event != NULL, FALSE);
@@ -353,8 +342,9 @@ void                gdk_window_end_paint                (GdkWindow *window);
 
 
 
+    parent_class = GTK_BIN_VIEW_CLASS(g_type_class_peek_parent(GTK_BLOCK_VIEW_GET_CLASS(widget)));
 
-
+    GTK_WIDGET_CLASS(parent_class)->expose_event(widget, event);
 
     return TRUE;
 
@@ -373,19 +363,19 @@ gtk_block_view_paint(GtkBlockView *view)
     GRenderingLine *iter;                   /* Boucle de parcours          */
 
     widget = GTK_WIDGET(view);
-    gdk_gc_get_values(view->gc, &values);
+    gdk_gc_get_values(GTK_BIN_VIEW(view)->gc, &values);
 
     gdk_color_white(gtk_widget_get_colormap(widget), &white);
-    gdk_gc_set_foreground(view->gc, &white);
+    gdk_gc_set_foreground(GTK_BIN_VIEW(view)->gc, &white);
 
     gtk_widget_get_size_request(widget, &width, &height);
 
-    gdk_draw_rectangle(GDK_DRAWABLE(widget->window), GTK_BLOCK_VIEW(widget)->gc,
+    gdk_draw_rectangle(GDK_DRAWABLE(widget->window), GTK_BIN_VIEW(widget)->gc,
                        TRUE, 0, 0, width, height);
 
-    gdk_gc_set_foreground(view->gc, &values.foreground);
+    gdk_gc_set_foreground(GTK_BIN_VIEW(view)->gc, &values.foreground);
 
-    gdk_draw_layout(GDK_DRAWABLE(widget->window), view->gc,
+    gdk_draw_layout(GDK_DRAWABLE(widget->window), GTK_BIN_VIEW(view)->gc,
                     2 * MARGIN_SPACE + view->line_height, 0,
                     view->layout);
 
@@ -395,7 +385,7 @@ gtk_block_view_paint(GtkBlockView *view)
          iter != NULL;
          iter = g_rendering_line_get_next_iter(GTK_BIN_VIEW(view)->lines, iter, GTK_BIN_VIEW(view)->last))
     {
-        g_rendering_line_draw(iter, GDK_DRAWABLE(widget->window), view->gc,
+        g_rendering_line_draw(iter, GDK_DRAWABLE(widget->window), GTK_BIN_VIEW(view)->gc,
                               MARGIN_SPACE, 2 * MARGIN_SPACE + view->line_height,
                               y, view->line_height);
 
@@ -403,6 +393,7 @@ gtk_block_view_paint(GtkBlockView *view)
 
     }
 
+
 }
 
 
diff --git a/src/gtkext/gtkgraphview.c b/src/gtkext/gtkgraphview.c
index 8a25940..dae1d54 100644
--- a/src/gtkext/gtkgraphview.c
+++ b/src/gtkext/gtkgraphview.c
@@ -37,8 +37,6 @@ struct _GtkGraphView
 {
     GtkBinView parent;                      /* A laisser en premier        */
 
-    GdkGC *gc;                              /* Contexte graphique du rendu */
-
     vmpa_t start;                           /* Début de la portion vue     */
     vmpa_t end;                             /* Fin de la portion affichée  */
 
@@ -64,8 +62,6 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *);
 /* Initialise une instance d'afficheur de code en graphique. */
 static void gtk_graph_view_init(GtkGraphView *);
 
-static void gtk_graph_view_realize(GtkWidget *widget);
-
 /*  Met à jour l'affichage de la vue sous forme graphique. */
 static gboolean gtk_graph_view_expose(GtkGraphView *, GdkEventExpose *);
 
@@ -107,7 +103,6 @@ static void gtk_graph_view_class_init(GtkGraphViewClass *klass)
 
     widget_class = (GtkWidgetClass *)klass;
 
-    widget_class->realize = gtk_graph_view_realize;
     widget_class->expose_event = gtk_graph_view_expose;
 
 }
@@ -162,52 +157,6 @@ GtkWidget* gtk_graph_view_new(void)
 
 
 
-
-
-static void
-gtk_graph_view_realize(GtkWidget *widget)
-{
-    GdkWindowAttr attributes;
-    guint attributes_mask;
-    GdkColor white;                         /* Couleur de fond normale     */
-
-  g_return_if_fail(widget != NULL);
-  g_return_if_fail(GTK_IS_GRAPH_VIEW(widget));
-
-  GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
-
-  attributes.window_type = GDK_WINDOW_CHILD;
-  attributes.x = widget->allocation.x;
-  attributes.y = widget->allocation.y;
-  attributes.width = widget->allocation.width;
-  attributes.height = widget->allocation.height;
-
-  attributes.wclass = GDK_INPUT_OUTPUT;
-  attributes.event_mask = gtk_widget_get_events(widget) | GDK_BUTTON_PRESS_MASK | GDK_EXPOSURE_MASK;
-
-  attributes_mask = GDK_WA_X | GDK_WA_Y;
-
-  widget->window = gdk_window_new(
-     gtk_widget_get_parent_window (widget),
-     & attributes, attributes_mask
-  );
-
-  gdk_window_set_user_data(widget->window, widget);
-
-    widget->style = gtk_style_attach(widget->style, widget->window);
-
-
-    gdk_color_white(gtk_widget_get_colormap(widget), &white);
-    gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &white);
-
-
-    GTK_GRAPH_VIEW(widget)->gc = gdk_gc_new(GDK_DRAWABLE(widget->window));
-
-}
-
-
-
-
 /******************************************************************************
 *                                                                             *
 *  Paramètres  : view  = composant GTK à redessiner.                          *
@@ -226,7 +175,9 @@ static gboolean gtk_graph_view_expose(GtkGraphView *view, GdkEventExpose *event)
     size_t i;                               /* Boucle de parcours          */
 
     for (i = 0; i < view->links_count; i++)
-        gtk_link_renderer_draw(view->links[i], GDK_DRAWABLE(GTK_WIDGET(view)->window), view->gc);
+        gtk_link_renderer_draw(view->links[i],
+                               GDK_DRAWABLE(GTK_WIDGET(view)->window),
+                               GTK_BIN_VIEW(view)->gc);
 
     return FALSE;
 
@@ -457,6 +408,7 @@ static GtkBinView **gtk_graph_view_load_nodes(openida_binary *binary, GRendering
             result[*count - 1] = GTK_BIN_VIEW(gtk_block_view_new());
             gtk_widget_show(GTK_WIDGET(result[*count - 1]));
 
+            gtk_bin_view_show_border(result[*count - 1], true);
             gtk_bin_view_set_rendering_lines(result[*count - 1], binary, begin, end);
 
             begin = NULL;
@@ -473,6 +425,7 @@ static GtkBinView **gtk_graph_view_load_nodes(openida_binary *binary, GRendering
             result[*count - 1] = GTK_BIN_VIEW(gtk_block_view_new());
             gtk_widget_show(GTK_WIDGET(result[*count - 1]));
 
+            gtk_bin_view_show_border(result[*count - 1], true);
             gtk_bin_view_set_rendering_lines(result[*count - 1], binary, begin, end);
 
             begin = NULL;
@@ -488,6 +441,7 @@ static GtkBinView **gtk_graph_view_load_nodes(openida_binary *binary, GRendering
         result[*count - 1] = GTK_BIN_VIEW(gtk_block_view_new());
         gtk_widget_show(GTK_WIDGET(result[*count - 1]));
 
+        gtk_bin_view_show_border(result[*count - 1], true);
         gtk_bin_view_set_rendering_lines(result[*count - 1], binary, begin, end);
 
     }
-- 
cgit v0.11.2-87-g4458