From 74642fbdeefaec21885e5fb6cad432e3e3b47cdb Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 15 Sep 2014 20:30:37 +0000 Subject: Defined a GTK3 style for binary portions. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@404 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 27 +++++ Makefile.am | 2 +- configure.ac | 3 +- src/glibext/gbinportion.c | 267 +++----------------------------------------- src/glibext/gbinportion.h | 41 ++----- src/gtkext/Makefile.am | 3 +- src/gtkext/gtkbinarystrip.c | 5 +- src/gtkext/theme.c | 102 +++++++++++++++++ src/gtkext/theme.h | 39 +++++++ src/main.c | 9 +- themes/Makefile.am | 7 ++ themes/portions.css | 65 +++++++++++ 12 files changed, 280 insertions(+), 290 deletions(-) create mode 100644 src/gtkext/theme.c create mode 100644 src/gtkext/theme.h create mode 100644 themes/Makefile.am create mode 100644 themes/portions.css diff --git a/ChangeLog b/ChangeLog index 2e512f3..7c463d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +14-09-15 Cyrille Bagard + + * configure.ac: + Add the new Makefiles from the 'themes' directory. + + * Makefile.am: + Add 'themes' to SUBDIRS. + + * src/glibext/gbinportion.c: + * src/glibext/gbinportion.h: + * src/gtkext/gtkbinarystrip.c: + Update code; remove useless parts. + + * src/gtkext/Makefile.am: + Add the themes.[ch]' files to libgtkext_la_SOURCES. + + * src/gtkext/theme.c: + * src/gtkext/theme.h: + New entries: load external style providers. + + * src/main.c: + Rely on GTK3 CSS providers for internal widgets. Update code. + + * themes/Makefile.am: + * themes/portions.css: + New entries: define a GTK3 style for binary portions. + 14-09-11 Cyrille Bagard * src/gtkext/gtkbufferview.c: diff --git a/Makefile.am b/Makefile.am index 033527f..31d97d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,6 +11,6 @@ revision.h: .svn EXTRA_DIST = config.rpath ChangeLog -SUBDIRS = pixmaps src plugins po +SUBDIRS = pixmaps src plugins po themes ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index e23a629..c788e4d 100644 --- a/configure.ac +++ b/configure.ac @@ -348,7 +348,8 @@ AC_CONFIG_FILES([Makefile src/gui/tb/Makefile src/panels/Makefile src/plugins/Makefile - src/plugins/overjump/Makefile]) + src/plugins/overjump/Makefile + themes/Makefile]) AC_OUTPUT diff --git a/src/glibext/gbinportion.c b/src/glibext/gbinportion.c index 2cc9fda..41778ba 100644 --- a/src/glibext/gbinportion.c +++ b/src/glibext/gbinportion.c @@ -36,36 +36,6 @@ -/* --------------------------- COULEURS DE REPRESENTATION --------------------------- */ - - -/* Information sur une colorisation de portion */ -typedef struct _portion_color -{ - bp_color_t code; /* Identifiant pour les usages */ - char *name; /* Désignation humaine */ - - double red; /* Taux de rouge */ - double green; /* Taux de vert */ - double blue; /* Taux de bleu */ - double alpha; /* Transparence */ - -} portion_color; - - -/* Mémoire centrale... */ -static portion_color *_portion_colors = NULL; -static size_t _portion_colors_count = 0; - - -/* Compare deux enregistrements de couleur pour portions. */ -static int compare_portion_colors(const portion_color *, const portion_color *); - -/* Tente de retrouver une couleur de portion donnée. */ -static portion_color *find_binary_portion_color(bp_color_t); - - - /* ------------------------------- PORTION DE BINAIRE ------------------------------- */ @@ -76,7 +46,7 @@ struct _GBinPortion GBinPortion *container; /* Portion parente ou racine */ - bp_color_t code; /* Code de la couleur de fond */ + char *code; /* Code de la couleur de fond */ char *desc; /* Désignation humaine */ @@ -122,207 +92,6 @@ static bool g_binary_portion_compute_sub_area(GBinPortion *, GBinPortion *, cons /* ---------------------------------------------------------------------------------- */ -/* COULEURS DE REPRESENTATION */ -/* ---------------------------------------------------------------------------------- */ - - -/****************************************************************************** -* * -* Paramètres : a = échantillon n°1 à comparer. * -* b = échantillon n°2 à comparer. * -* * -* Description : Compare deux enregistrements de couleur pour portions. * -* * -* Retour : Bilan de la comparaison. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static int compare_portion_colors(const portion_color *a, const portion_color *b) -{ - int result; /* Bilan à renvoyer */ - - if (a->code < b->code) - result = -1; - - else if (a->code > b->code) - result = 1; - - else - result = 0; - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : name = désignation humaine de la couleur. * -* red = taux de rouge dans la couleur. * -* gren = taux de vert dans la couleur. * -* blue = taux de bleu dans la couleur. * -* alpha = transparence de la couleur. * -* * -* Description : Enregistre une couleur pour le dessin de portions. * -* * -* Retour : true si l'enregistrement a pu être effectué, false sinon. * -* * -* Remarques : - * -* * -******************************************************************************/ - -bool register_binary_portion_color(const char *name, uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha) -{ - bp_color_t code; /* Accès rapide à la couleur */ - portion_color *new; /* Nouvel élément à constituer */ - - /* Vérification de l'unicité des noms */ - - code = fnv_64a_hash(name); - - new = find_binary_portion_color(code); - if (new != NULL) return false; - - /* Création du nouvel élément */ - - _portion_colors = (portion_color *)realloc(_portion_colors, - ++_portion_colors_count * sizeof(portion_color)); - - new = &_portion_colors[_portion_colors_count - 1]; - - /* Définition du nouvel élément */ - - new->name = strdup(name); - new->code = code; - - new->red = red / 255.0; - new->green = green / 255.0; - new->blue = blue / 255.0; - new->alpha = alpha / 255.0; - - /* Actualisation finale par tri */ - - qsort(_portion_colors, _portion_colors_count, sizeof(portion_color), - (__compar_fn_t)compare_portion_colors); - - return true; - -} - - -/****************************************************************************** -* * -* Paramètres : name = désignation humaine de la couleur. * -* * -* Description : Supprime une couleur pour le dessin de portions. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void unregister_binary_portion_color(const char *name) -{ - bp_color_t code; /* Accès rapide à la couleur */ - portion_color *item; /* Elément à retirer */ - size_t left; /* Quantité à déplacer */ - - code = fnv_64a_hash(name); - - item = find_binary_portion_color(code); - if (item == NULL) return; - - free(item->name); - - left = (size_t)(_portion_colors + _portion_colors_count) - (size_t)(item + 1); - - if (left > 0) - memmove(item, item + 1, left); - - _portion_colors = (portion_color *)realloc(_portion_colors, - --_portion_colors_count * sizeof(portion_color)); - -} - - -/****************************************************************************** -* * -* Paramètres : code = identifiant de la couleur à retrouver. * -* * -* Description : Tente de retrouver une couleur de portion donnée. * -* * -* Retour : Caractéristiques de la couleur visée, ou NULL. * -* * -* Remarques : - * -* * -******************************************************************************/ - -static portion_color *find_binary_portion_color(bp_color_t code) -{ - portion_color *result; /* Elément trouvé à retourner */ - - result = (portion_color *)bsearch(&code, _portion_colors, - _portion_colors_count, sizeof(portion_color), - (__compar_fn_t)compare_portion_colors); - - return result; - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Enregistre les couleurs de base pour le dessin des portions. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void init_binary_portion_colors(void) -{ - register_binary_portion_color(BPC_RAW, 0, 0, 0, 255); - register_binary_portion_color(BPC_CODE, 0, 0, 255, 255); - register_binary_portion_color(BPC_DATA, 255, 255, 0, 255); - register_binary_portion_color(BPC_DATA_RO, 0, 255, 0, 255); - -} - - -/****************************************************************************** -* * -* Paramètres : - * -* * -* Description : Supprime les couleurs de base pour le dessin des portions. * -* * -* Retour : - * -* * -* Remarques : - * -* * -******************************************************************************/ - -void exit_binary_portion_colors(void) -{ - while (_portion_colors_count > 0) - unregister_binary_portion_color(_portion_colors[0].name); - - if (_portion_colors != NULL) - { - free(_portion_colors); - _portion_colors = NULL; - } - -} - - - -/* ---------------------------------------------------------------------------------- */ /* PORTION DE BINAIRE */ /* ---------------------------------------------------------------------------------- */ @@ -412,6 +181,8 @@ static void g_binary_portion_dispose(GBinPortion *portion) static void g_binary_portion_finalize(GBinPortion *portion) { + free(portion->code); + if (portion->desc != NULL) free(portion->desc); @@ -441,7 +212,7 @@ GBinPortion *g_binary_portion_new(const char *code) result = g_object_new(G_TYPE_BIN_PORTION, NULL); - result->code = fnv_64a_hash(code); + result->code = strdup(code); return result; @@ -874,6 +645,11 @@ gboolean g_binary_portion_query_tooltip(GBinPortion *portion, gint x, gint y, co +extern GtkCssProvider *__provider; /* Fournisseur par défaut */ + + + + /****************************************************************************** * * * Paramètres : portion = description de partie à consulter. * @@ -888,36 +664,27 @@ gboolean g_binary_portion_query_tooltip(GBinPortion *portion, gint x, gint y, co * * ******************************************************************************/ -void g_binary_portion_draw(GBinPortion *portion, cairo_t *cr, const GdkRectangle *area) +void g_binary_portion_draw(GBinPortion *portion, GtkStyleContext *context, cairo_t *cr, const GdkRectangle *area) { - portion_color *color; /* Couleur du fond */ size_t i; /* Boucle de parcours */ GBinPortion *sub; /* Portion incluse à montrer */ GdkRectangle sub_area; /* Etendue d'une sous-portion */ /* Dessin de la portion courante */ - cairo_set_line_width(cr, 1.0); + //cairo_set_line_width(cr, 1.0); cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE); - color = find_binary_portion_color(portion->code); + gtk_style_context_save(context); - if (color != NULL) - cairo_set_source_rgba(cr, - color->red, color->green, color->blue, - color->alpha); + gtk_style_context_add_class(context, portion->code); - cairo_rectangle(cr, area->x, area->y, area->width, area->height); - cairo_fill(cr); + gtk_render_background(context, cr, area->x, area->y, area->width, area->height); - if (color != NULL) - cairo_set_source_rgba(cr, - color->red * 0.7, color->green * 0.7, color->blue * 0.7, - color->alpha); + gtk_render_frame(context, cr, area->x, area->y, area->width, area->height); - cairo_rectangle(cr, area->x, area->y, area->width, area->height); - cairo_stroke(cr); + gtk_style_context_restore(context); /* Dessin des portions incluses */ @@ -931,7 +698,7 @@ void g_binary_portion_draw(GBinPortion *portion, cairo_t *cr, const GdkRectangle if (!g_binary_portion_compute_sub_area(portion, sub, area, &sub_area)) continue; - g_binary_portion_draw(sub, cr, &sub_area); + g_binary_portion_draw(sub, context, cr, &sub_area); } diff --git a/src/glibext/gbinportion.h b/src/glibext/gbinportion.h index c10d54d..fd1336b 100644 --- a/src/glibext/gbinportion.h +++ b/src/glibext/gbinportion.h @@ -35,38 +35,15 @@ -/* --------------------------- COULEURS DE REPRESENTATION --------------------------- */ - - -/* Converion code -> identifiant unique */ -typedef fnv64_t bp_color_t; - -/* Identifiant non valide */ -#define BP_NO_COLOR 0 - -/* Identifiant pour la transparence */ -#define BP_INHERIT_COLOR 1 - - -#define BPC_RAW "raw" -#define BPC_CODE "code" -#define BPC_DATA "data" -#define BPC_DATA_RO "data-ro" -#define BPC_DISASS_ERROR "disassembly-error" - - -/* Enregistre une couleur pour le dessin de portions. */ -bool register_binary_portion_color(const char *, uint8_t, uint8_t, uint8_t, uint8_t); - -/* Supprime une couleur pour le dessin de portions. */ -void unregister_binary_portion_color(const char *); - -/* Enregistre les couleurs de base pour le dessin des portions. */ -void init_binary_portion_colors(void); - -/* Supprime les couleurs de base pour le dessin des portions. */ -void exit_binary_portion_colors(void); +/** + * Couleurs de représentation. + */ +#define BPC_RAW "binportion-raw" +#define BPC_CODE "binportion-code" +#define BPC_DATA "binportion-data" +#define BPC_DATA_RO "binportion-data-ro" +#define BPC_DISASS_ERROR "binportion-disassembly-error" #define G_TYPE_BIN_PORTION (g_binary_portion_get_type()) @@ -135,7 +112,7 @@ bool g_binary_portion_get_pos_from_addr(GBinPortion *, vmpa_t, const GdkRectangl gboolean g_binary_portion_query_tooltip(GBinPortion *, gint, gint, const GdkRectangle *, GtkTooltip *); /* Représente la portion sur une bande dédiée. */ -void g_binary_portion_draw(GBinPortion *, cairo_t *, const GdkRectangle *); +void g_binary_portion_draw(GBinPortion *, GtkStyleContext *, cairo_t *, const GdkRectangle *); diff --git a/src/gtkext/Makefile.am b/src/gtkext/Makefile.am index 5c1dec4..c028f6b 100644 --- a/src/gtkext/Makefile.am +++ b/src/gtkext/Makefile.am @@ -14,7 +14,8 @@ libgtkext_la_SOURCES = \ gtksourceview.h gtksourceview.c \ gtkviewpanel-int.h \ gtkviewpanel.h gtkviewpanel.c \ - support.h support.c + support.h support.c \ + theme.h theme.c libgtkext_la_LIBADD = \ graph/libgtkextgraph.la diff --git a/src/gtkext/gtkbinarystrip.c b/src/gtkext/gtkbinarystrip.c index 2381fd6..4ed5cf9 100644 --- a/src/gtkext/gtkbinarystrip.c +++ b/src/gtkext/gtkbinarystrip.c @@ -311,6 +311,7 @@ static gboolean gtk_binary_strip_draw(GtkWidget *widget, cairo_t *cr) GExeFormat *format; /* Format du binaire */ GBinPortion *portions; /* Portions binaires à dessiner*/ GdkRectangle full; /* Taille totale de la surface */ + GtkStyleContext *context; /* Contexte du thème actuel */ GdkRGBA *color; /* Couleur du curseur */ strip = GTK_BINARY_STRIP(widget); @@ -328,7 +329,9 @@ static gboolean gtk_binary_strip_draw(GtkWidget *widget, cairo_t *cr) full.width = gtk_widget_get_allocated_width(widget); full.height = gtk_widget_get_allocated_height(widget) - 1; - g_binary_portion_draw(portions, cr, &full); + context = gtk_widget_get_style_context(widget); + + g_binary_portion_draw(portions, context, cr, &full); /* Dessin de la position */ diff --git a/src/gtkext/theme.c b/src/gtkext/theme.c new file mode 100644 index 0000000..493692a --- /dev/null +++ b/src/gtkext/theme.c @@ -0,0 +1,102 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * theme.c - prototypes pour l'ajout d'extensions au thème GTK + * + * Copyright (C) 2009-2012 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#include "theme.h" + + +#include + + + +static const char *_themes_directories[] = { + + PACKAGE_SOURCE_DIR G_DIR_SEPARATOR_S "themes", + PACKAGE_DATA_DIR G_DIR_SEPARATOR_S "themes", + NULL + +}; + + + +/****************************************************************************** +* * +* Paramètres : - * +* * +* Description : Charge le thème GTK pour les composants spécifiques. * +* * +* Retour : true ou false selon le bilan de l'opération. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool load_extra_gtk_theme(void) +{ + GdkScreen *screen; /* Ecran(s) concerné(s) */ + GtkCssProvider *provider; /* Fournisseur par défaut */ + const char **iter_f; /* Boucle de parcours #1 */ + bool done; /* Traitement d'un fichier */ + const char **iter_d; /* Boucle de parcours #2 */ + gchar *filename; /* Chemin d'accès constitué */ + + static const char *css_files[] = { + "portions.css", + NULL + }; + + screen = gdk_screen_get_default(); + provider = gtk_css_provider_get_default(); + + done = true; + + for (iter_f = css_files; *iter_f != NULL; iter_f++) + { + done = false; + + for (iter_d = _themes_directories; *iter_d != NULL && !done; iter_d++) + { + filename = g_strdup_printf("%s%s%s", *iter_d, G_DIR_SEPARATOR_S, *iter_f); + + if (g_file_test(filename, G_FILE_TEST_EXISTS)) + { + done = gtk_css_provider_load_from_path(provider, filename, NULL); + + if (done) + gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(provider), + GTK_STYLE_PROVIDER_PRIORITY_USER); + + } + + g_free(filename); + + } + + if (!done) + break; + + } + + return done; + +} diff --git a/src/gtkext/theme.h b/src/gtkext/theme.h new file mode 100644 index 0000000..78650cb --- /dev/null +++ b/src/gtkext/theme.h @@ -0,0 +1,39 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * theme.h - prototypes pour l'ajout d'extensions au thème GTK + * + * Copyright (C) 2014 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _GTKEXT_THEME_H +#define _GTKEXT_THEME_H + + +#include +#include + + + +/* Charge le thème GTK pour les composants spécifiques. */ +bool load_extra_gtk_theme(void); + + + +#endif /* _GTKEXT_THEME_H */ diff --git a/src/main.c b/src/main.c index 0fdfe31..724659a 100644 --- a/src/main.c +++ b/src/main.c @@ -22,11 +22,11 @@ */ -#include #include #include #include +#include #include #include "editor.h" @@ -39,6 +39,7 @@ #include "glibext/delayed.h" #include "glibext/gbinportion.h" #include "gtkext/support.h" +#include "gtkext/theme.h" #include "plugins/pglist.h" #include "../revision.h" @@ -114,6 +115,9 @@ int main(int argc, char **argv) setlocale (LC_ALL, ""); gtk_init(&argc, &argv); + if (!load_extra_gtk_theme()) + return EXIT_FAILURE; + if (!load_all_basic_components()) return EXIT_FAILURE; @@ -130,7 +134,6 @@ int main(int argc, char **argv) /* Initialisation du programme */ init_all_processors(); init_all_formats(); - init_binary_portion_colors(); /* Création de l'interface */ @@ -190,8 +193,6 @@ int main(int argc, char **argv) exit_all_plugins(); - exit_binary_portion_colors(); - unload_all_basic_components(); return EXIT_SUCCESS; diff --git a/themes/Makefile.am b/themes/Makefile.am new file mode 100644 index 0000000..c790aad --- /dev/null +++ b/themes/Makefile.am @@ -0,0 +1,7 @@ + +GTK3_CSS = \ + portions.css + +cssdir = $(datadir)/themes + +css_DATA = $(GTK3_CSS) diff --git a/themes/portions.css b/themes/portions.css new file mode 100644 index 0000000..3c5c582 --- /dev/null +++ b/themes/portions.css @@ -0,0 +1,65 @@ + + + +@define-color binportion-raw-color #808080; + +@define-color binportion-code-color #4150ae; + +@define-color binportion-data-color #ae4141; + +@define-color binportion-data-ro-color #aeaa41; + +@define-color binportion-disassembly-error #000000; + + + + +.binportion-raw { + + background-color: @binportion-raw-color; + + border-color: darker(@binportion-raw-color); + border-width: 1px; + border-style: solid; + +} + +.binportion-code { + + background-color: @binportion-code-color; + + border-color: darker(@binportion-code-color); + border-width: 1px; + border-style: solid; + +} + +.binportion-data { + + background-color: @binportion-data-color; + + border-color: darker(@binportion-data-color); + border-width: 1px; + border-style: solid; + +} + +.binportion-data-ro { + + background-color: @binportion-data-ro-color; + + border-color: darker(@binportion-data-ro-color); + border-width: 1px; + border-style: solid; + +} + +.binportion-disassembly-error { + + background-color: @binportion-disassembly-error-color; + + border-color: darker(@binportion-disassembly-error-color); + border-width: 1px; + border-style: solid; + +} -- cgit v0.11.2-87-g4458