diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2010-10-24 12:58:53 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2010-10-24 12:58:53 (GMT) |
commit | 6ab5a66388182e6cb9a49b8d6e54a9348de4f264 (patch) | |
tree | 5dfdd4d9125423226cd44cc6e6c18502f362fbd2 /src/gtkext/gtkviewpanel.c | |
parent | 7e53295ae7e67c8473aca2974e519aa0a593788e (diff) |
Introduced new views for rendering source code.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@184 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/gtkext/gtkviewpanel.c')
-rw-r--r-- | src/gtkext/gtkviewpanel.c | 361 |
1 files changed, 361 insertions, 0 deletions
diff --git a/src/gtkext/gtkviewpanel.c b/src/gtkext/gtkviewpanel.c new file mode 100644 index 0000000..03279b2 --- /dev/null +++ b/src/gtkext/gtkviewpanel.c @@ -0,0 +1,361 @@ + +/* OpenIDA - Outil d'analyse de fichiers binaires + * gtkviewpanel.c - affichage de contenu de binaire + * + * Copyright (C) 2010 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 "gtkviewpanel.h" + + +#include "gtkviewpanel-int.h" +#include "iodamarshal.h" + + + +/* Procède à l'initialisation de l'afficheur générique. */ +static void gtk_view_panel_class_init(GtkViewPanelClass *); + +/* Procède à l'initialisation de l'afficheur générique. */ +static void gtk_view_panel_init(GtkViewPanel *); + +/* Enregistre les défilements à associer au composant GTK. */ +static void gtk_view_panel_set_scroll_adjustments(GtkViewPanel *, GtkAdjustment *, GtkAdjustment *); + +/* Prend acte d'un nouveau défilement. */ +static void gtk_view_panel_adj_value_changed(GtkAdjustment *, GtkViewPanel *); + +/* Encadre la construction graphique initiale de l'affichage. */ +static void gtk_view_panel_realize(GtkWidget *); + +/* Met à jour l'affichage du composant d'affichage. */ +static gboolean gtk_view_panel_expose(GtkWidget *, GdkEventExpose *); + + + +/* Détermine le type du composant d'affichage générique. */ +G_DEFINE_TYPE(GtkViewPanel, gtk_view_panel, GTK_TYPE_FIXED) + + +/****************************************************************************** +* * +* Paramètres : class = classe GTK à initialiser. * +* * +* Description : Procède à l'initialisation de l'afficheur générique. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_view_panel_class_init(GtkViewPanelClass *class) +{ + GtkWidgetClass *widget_class; /* Classe de haut niveau */ + + widget_class = GTK_WIDGET_CLASS(class); + + widget_class->realize = gtk_view_panel_realize; + widget_class->expose_event = gtk_view_panel_expose; + + class->set_scroll_adjustments = gtk_view_panel_set_scroll_adjustments; + + widget_class->set_scroll_adjustments_signal = + g_signal_new(("set_scroll_adjustments"), + GTK_TYPE_VIEW_PANEL, + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET(GtkViewPanelClass, set_scroll_adjustments), + NULL, NULL, + g_cclosure_user_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, + GTK_TYPE_ADJUSTMENT, + GTK_TYPE_ADJUSTMENT); + +} + + +/****************************************************************************** +* * +* Paramètres : view = composant GTK à initialiser. * +* * +* Description : Procède à l'initialisation de l'afficheur générique. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_view_panel_init(GtkViewPanel *panel) +{ + gtk_fixed_set_has_window(GTK_FIXED(panel), TRUE); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = vue à compléter. * +* hadjustment = nouveau défilement horizontal à intégrer. * +* vadjustment = nouveau défilement vertical à intégrer. * +* * +* Description : Enregistre les défilements à associer au composant GTK. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_view_panel_set_scroll_adjustments(GtkViewPanel *panel, GtkAdjustment *hadjustment, GtkAdjustment *vadjustment) +{ + panel->hadjustment = hadjustment; + panel->vadjustment = vadjustment; + + g_signal_connect(hadjustment, "value_changed", + G_CALLBACK(gtk_view_panel_adj_value_changed), panel); + + g_signal_connect(vadjustment, "value_changed", + G_CALLBACK(gtk_view_panel_adj_value_changed), panel); + +} + + +/****************************************************************************** +* * +* Paramètres : adj = défilement à l'origine de l'action. * +* panel = composant GTK à redessiner. * +* * +* Description : Prend acte d'un nouveau défilement. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_view_panel_adj_value_changed(GtkAdjustment *adj, GtkViewPanel *panel) +{ + panel->scroll(panel); + +} + + +/****************************************************************************** +* * +* Paramètres : adj = valeurs de défilement à consulter. * +* changed = note une mise à jour de valeur. [OUT] * +* * +* Description : S'assure que la valeur de défilement actuelle est valable. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_view_panel_reclamp_adjustment(GtkAdjustment *adj, gboolean *changed) +{ + gdouble value; /* Valeur actuelle */ + + value = adj->value; + + value = CLAMP(value, 0, adj->upper - adj->page_size); + + if (value != adj->value) + { + adj->value = value; + *changed = TRUE; + } + else *changed = FALSE; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à consulter. * +* alloc = étendue à accorder à la vue. * +* * +* Description : Calcule la surface pleine utilisable pour le panneau. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_view_panel_compute_allocation(GtkViewPanel *panel, GtkAllocation *alloc) +{ + GtkWidget *widget; /* Autre version de la vue */ + GtkAllocation *allocation; /* Raccourci d'utilisation #1 */ + gint border_width; /* Raccourci d'utilisation #2 */ + + widget = GTK_WIDGET(panel); + allocation = &widget->allocation; + border_width = GTK_CONTAINER(panel)->border_width; + + alloc->x = 0; + alloc->y = 0; + + /* + if (viewport->shadow_type != GTK_SHADOW_NONE) + { + alloc->x = widget->style->xthickness; + alloc->y = widget->style->ythickness; + } + */ + + alloc->width = MAX(1, allocation->width - alloc->x * 2 - border_width * 2); + alloc->height = MAX(1, allocation->height - alloc->y * 2 - border_width * 2); + +} + + +/****************************************************************************** +* * +* Paramètres : widget = composant GTK à préparer. * +* * +* Description : Encadre la construction graphique initiale de l'affichage. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void gtk_view_panel_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_VIEW_PANEL(widget)->gc = gdk_gc_new(GDK_DRAWABLE(widget->window)); + +} + + +/****************************************************************************** +* * +* Paramètres : widget = composant GTK à redessiner. * +* event = informations liées à l'événement. * +* * +* Description : Met à jour l'affichage du composant d'affichage. * +* * +* Retour : FALSE pour poursuivre la propagation de l'événement. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static gboolean gtk_view_panel_expose(GtkWidget *widget, GdkEventExpose *event) +{ + GtkViewPanel *panel; + 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 */ + + panel = GTK_VIEW_PANEL(widget); + + if (panel->show_border) + { + gdk_gc_get_values(panel->gc, &values); + style = gtk_widget_get_style(widget); + + gtk_widget_get_size_request(widget, &width, &height); + + gdk_gc_set_foreground(panel->gc, &style->dark[GTK_WIDGET_STATE(widget)]); + + gdk_draw_rectangle(GDK_DRAWABLE(widget->window), panel->gc, + FALSE, 0, 0, width - 1, height - 1); + + gdk_gc_set_foreground(panel->gc, &values.foreground); + + } + + return FALSE; + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à mettre à jour. * +* binary = binaire associé à intégrer. * +* * +* Description : Associe à un panneau d'affichage un binaire chargé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void gtk_view_panel_attach_binary(GtkViewPanel *panel, GOpenidaBinary *binary) +{ + g_object_ref(G_OBJECT(binary)); + panel->binary = binary; + + panel->attach(panel, binary); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = composant GTK à consulter. * +* * +* Description : Fournit le binaire associé à la représentation. * +* * +* Retour : Représentation de contenu binaire. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GOpenidaBinary *gtk_view_panel_get_binary(const GtkViewPanel *panel) +{ + return panel->binary; + +} |