From 1d3c3cb7b108c0bbe05b9853ed4640d35ddf9bcb Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 8 Sep 2009 23:38:46 +0000 Subject: Restored the previous/original rendering of disassemblies. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@111 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 22 +++ pixmaps/breakpoint.png | Bin 0 -> 885 bytes pixmaps/entry.png | Bin 0 -> 631 bytes pixmaps/stopped.png | Bin 0 -> 859 bytes src/analysis/exporter-int.h | 2 +- src/analysis/exporter.c | 5 +- src/analysis/exporter.h | 2 +- src/analysis/line_code.c | 9 +- src/analysis/line_comment.c | 4 +- src/analysis/line_prologue.c | 4 +- src/gtkext/gtkbinview.c | 2 +- src/gtkext/gtkblockview.c | 329 +++++++++++++++++++++++++++++++------------ 12 files changed, 279 insertions(+), 100 deletions(-) create mode 100644 pixmaps/breakpoint.png create mode 100644 pixmaps/entry.png create mode 100644 pixmaps/stopped.png diff --git a/ChangeLog b/ChangeLog index f15e9c9..02ac18b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +09-09-09 Cyrille Bagard + + * pixmaps/breakpoint.png: + * pixmaps/entry.png: + * pixmaps/stopped.png: + New entries: draw external pictures in the left margin of views. + + * src/analysis/exporter.c: + * src/analysis/exporter.h: + * src/analysis/exporter-int.h: + * src/analysis/line_code.c: + * src/analysis/line_comment.c: + * src/analysis/line_prologue.c: + Track the lengths of the main parts of the lines. + + * src/gtkext/gtkbinview.c: + Draw a border using the style of the view. + + * src/gtkext/gtkblockview.c: + Restore the previous/original rendering of disassemblies (pictures in the + left margin + space between the main parts of each line). + 09-09-06 Cyrille Bagard * configure.ac: diff --git a/pixmaps/breakpoint.png b/pixmaps/breakpoint.png new file mode 100644 index 0000000..79d8871 Binary files /dev/null and b/pixmaps/breakpoint.png differ diff --git a/pixmaps/entry.png b/pixmaps/entry.png new file mode 100644 index 0000000..76e1505 Binary files /dev/null and b/pixmaps/entry.png differ diff --git a/pixmaps/stopped.png b/pixmaps/stopped.png new file mode 100644 index 0000000..1b50292 Binary files /dev/null and b/pixmaps/stopped.png differ diff --git a/src/analysis/exporter-int.h b/src/analysis/exporter-int.h index 0c93980..097b48b 100644 --- a/src/analysis/exporter-int.h +++ b/src/analysis/exporter-int.h @@ -30,7 +30,7 @@ /* Ajoute à un texte GTK le contenu de la ligne de rendu. */ -typedef void (* add_to_gtk_buffer_fc) (GContentExporter *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); +typedef void (* add_to_gtk_buffer_fc) (GContentExporter *, MainRendering, GtkTextBuffer *, GtkTextIter *, size_t [SAR_COUNT]); /* Traduit une instruction en version humainement lisible. */ typedef void (* add_arch_to_gtk_buffer_fc) (const GContentExporter *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *); diff --git a/src/analysis/exporter.c b/src/analysis/exporter.c index dd0f6c0..8a41abf 100644 --- a/src/analysis/exporter.c +++ b/src/analysis/exporter.c @@ -212,6 +212,7 @@ void g_content_exporter_insert_with_gtk_tag(GContentExporter *exporter, GtkTextB * rendering = support effectif final des lignes de code. * * buffer = zone de texte à venir compléter. * * iter = point d'insertion du nouveau texte. * +* lengths = taille des différentes composantes de la ligne. * * * * Description : Ajoute à un texte GTK le contenu de l'instance spécifiée. * * * @@ -221,10 +222,10 @@ void g_content_exporter_insert_with_gtk_tag(GContentExporter *exporter, GtkTextB * * ******************************************************************************/ -void g_content_exporter_add_to_gtk_buffer(GContentExporter *exporter, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter) +void g_content_exporter_add_to_gtk_buffer(GContentExporter *exporter, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, size_t lengths[SAR_COUNT]) { if (exporter->add_to_gtk_buffer != NULL) - exporter->add_to_gtk_buffer(exporter, rendering, buffer, iter, NULL); + exporter->add_to_gtk_buffer(exporter, rendering, buffer, iter, lengths); } diff --git a/src/analysis/exporter.h b/src/analysis/exporter.h index 76725ad..9e8d54a 100644 --- a/src/analysis/exporter.h +++ b/src/analysis/exporter.h @@ -84,7 +84,7 @@ GtkTextTagTable *_get_gtk_tag_table(GtkTextTagTable *); #define get_gtk_tag_table() _get_gtk_tag_table(NULL) /* Ajoute à un texte GTK le contenu de l'instance spécifiée. */ -void g_content_exporter_add_to_gtk_buffer(GContentExporter *, MainRendering, GtkTextBuffer *, GtkTextIter *); +void g_content_exporter_add_to_gtk_buffer(GContentExporter *, MainRendering, GtkTextBuffer *, GtkTextIter *, size_t [SAR_COUNT]); /* Ajoute à un texte GTK le contenu d'une architecture. */ void g_content_exporter_add_arch_to_gtk_buffer(const GContentExporter *, const GExeFormat *, AsmSyntax, GtkTextBuffer *, GtkTextIter *); diff --git a/src/analysis/line_code.c b/src/analysis/line_code.c index 4ceabec..8f9f925 100644 --- a/src/analysis/line_code.c +++ b/src/analysis/line_code.c @@ -62,7 +62,7 @@ static void g_code_line_init(GCodeLine *); void g_code_line_get_binary_len(GCodeLine *, off_t *); /* Ajoute à un texte GTK le contenu de la ligne de code. */ -static void g_code_line_add_to_gtk_buffer(GCodeLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); +static void g_code_line_add_to_gtk_buffer(GCodeLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, size_t [SAR_COUNT]); @@ -159,7 +159,7 @@ void g_code_line_get_binary_len(GCodeLine *line, off_t *blen) * * ******************************************************************************/ -static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT]) +static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, size_t lengths[SAR_COUNT]) { bool show_address; /* Affichage de l'adresse ? */ bool show_code; /* Affichage du code brut ? */ @@ -182,6 +182,7 @@ static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering renderi msize = g_arch_processor_get_memory_size(g_rendering_options_get_processor(line->options)); len = vmpa_to_string(G_RENDERING_LINE(line)->offset, msize, address); + lengths[SAR_ADDRESS] = len; g_content_exporter_insert_with_gtk_tag(G_CONTENT_EXPORTER(line), buffer, iter, address, len, RTT_NONE); @@ -198,6 +199,8 @@ static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering renderi content = g_binary_format_get_content(G_BIN_FORMAT(g_rendering_options_get_format(line->options)), NULL); g_arch_instruction_get_location(line->instr, &bin_offset, &bin_len, NULL); + lengths[SAR_CODE] = MAX(lengths[SAR_CODE], bin_len * 3 - 1); + bin_code = (char *)calloc(bin_len * 3, sizeof(char)); for (i = 0; i < bin_len; i++) @@ -224,6 +227,8 @@ static void g_code_line_add_to_gtk_buffer(GCodeLine *line, MainRendering renderi g_rendering_options_get_format(line->options), ASX_INTEL/*FIXME*/, buffer, iter); + lengths[SAR_INSTRUCTION] = MAX(lengths[SAR_INSTRUCTION], 4 /* FIXME */); + } diff --git a/src/analysis/line_comment.c b/src/analysis/line_comment.c index 2a3030c..aa6ae10 100644 --- a/src/analysis/line_comment.c +++ b/src/analysis/line_comment.c @@ -58,7 +58,7 @@ static void g_comment_line_class_init(GCommentLineClass *); static void g_comment_line_init(GCommentLine *); /* Ajoute à un texte GTK le contenu de la ligne de commentaires. */ -static void g_comment_line_add_to_gtk_buffer(GCommentLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); +static void g_comment_line_add_to_gtk_buffer(GCommentLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, size_t [SAR_COUNT]); @@ -129,7 +129,7 @@ static void g_comment_line_init(GCommentLine *line) * * ******************************************************************************/ -static void g_comment_line_add_to_gtk_buffer(GCommentLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT]) +static void g_comment_line_add_to_gtk_buffer(GCommentLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, size_t lengths[SAR_COUNT]) { bool show_address; /* Affichage de l'adresse ? */ bool show_code; /* Affichage du code brut ? */ diff --git a/src/analysis/line_prologue.c b/src/analysis/line_prologue.c index 13f0c1e..f0f5db9 100644 --- a/src/analysis/line_prologue.c +++ b/src/analysis/line_prologue.c @@ -57,7 +57,7 @@ static void g_prologue_line_class_init(GPrologueLineClass *); static void g_prologue_line_init(GPrologueLine *); /* Ajoute à un texte GTK le contenu de la ligne d'ouverture. */ -static void g_prologue_line_add_to_gtk_buffer(GPrologueLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, gint [SAR_COUNT]); +static void g_prologue_line_add_to_gtk_buffer(GPrologueLine *, MainRendering, GtkTextBuffer *, GtkTextIter *, size_t [SAR_COUNT]); @@ -128,7 +128,7 @@ static void g_prologue_line_init(GPrologueLine *line) * * ******************************************************************************/ -static void g_prologue_line_add_to_gtk_buffer(GPrologueLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, gint lengths[SAR_COUNT]) +static void g_prologue_line_add_to_gtk_buffer(GPrologueLine *line, MainRendering rendering, GtkTextBuffer *buffer, GtkTextIter *iter, size_t lengths[SAR_COUNT]) { size_t len; /* Taille de l'élément inséré */ diff --git a/src/gtkext/gtkbinview.c b/src/gtkext/gtkbinview.c index 802a115..f049470 100644 --- a/src/gtkext/gtkbinview.c +++ b/src/gtkext/gtkbinview.c @@ -183,7 +183,7 @@ static gboolean gtk_bin_view_expose(GtkBinView *view, GdkEventExpose *event) gtk_widget_get_size_request(GTK_WIDGET(view), &width, &height); - gdk_gc_set_foreground(view->gc, &style->black); + gdk_gc_set_foreground(view->gc, &style->dark[GTK_WIDGET_STATE(GTK_WIDGET(view))]); gdk_draw_rectangle(GDK_DRAWABLE(GTK_WIDGET(view)->window), view->gc, FALSE, 0, 0, width - 1, height - 1); diff --git a/src/gtkext/gtkblockview.c b/src/gtkext/gtkblockview.c index 7161762..23f86ce 100644 --- a/src/gtkext/gtkblockview.c +++ b/src/gtkext/gtkblockview.c @@ -32,12 +32,13 @@ #include "gtkbinview-int.h" +#include "support.h" #include "../analysis/exporter.h" #include "../common/dllist.h" -#define MARGIN_SPACE 4 +#define MARGIN_SPACE 4 /* TODO : delete me ! */ @@ -51,10 +52,12 @@ struct _GtkBlockView bool show_code; /* Affichage du code brut ? */ GtkTextBuffer *buffer; /* Code sous forme de texte */ - GtkTextLayout *_layout; /* Disposition du texte */ + GtkTextLayout *layout; /* Disposition du texte */ + + gint line_height; /* Hauteur maximale des lignes */ + gint left_margin; /* Marge gauche + espace */ + gint left_text; /* Début d'impression du code */ - PangoLayout *layout; /* Moteur de rendu du code ASM */ - int line_height; /* Hauteur maximale des lignes */ const exe_format *format; /* Format du contenu bianire */ @@ -64,6 +67,10 @@ struct _GtkBlockViewClass { GtkBinViewClass parent; /* A laisser en premier */ + GdkPixbuf *entry_pix; /* Image du point d'entrée */ + GdkPixbuf *breakpoint_pix; /* Image de point d'arrêt */ + GdkPixbuf *stopped_pix; /* Image de point actif */ + }; @@ -178,6 +185,7 @@ static void gtk_block_view_class_init(GtkBlockViewClass *klass) GtkWidgetClass *widget_class; /* Classe version Widget */ GtkObjectClass *object_class; + gchar *filename; /* Fichier d'image à charger */ widget_class = (GtkWidgetClass *) klass; object_class = (GtkObjectClass *) klass; @@ -190,6 +198,38 @@ static void gtk_block_view_class_init(GtkBlockViewClass *klass) widget_class->expose_event = gtk_block_view_expose; object_class->destroy = gtk_block_view_destroy; + + + + /* Image de la marge gauche */ + + filename = find_pixmap_file("entry.png"); + + if (filename == NULL) klass->entry_pix = NULL; + else + { + klass->entry_pix = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + } + + filename = find_pixmap_file("breakpoint.png"); + + if (filename == NULL) klass->breakpoint_pix = NULL; + else + { + klass->breakpoint_pix = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + } + + filename = find_pixmap_file("stopped.png"); + + if (filename == NULL) klass->stopped_pix = NULL; + else + { + klass->stopped_pix = gdk_pixbuf_new_from_file(filename, NULL); + g_free(filename); + } + } @@ -210,10 +250,7 @@ static void gtk_block_view_init(GtkBlockView *view) GtkBinView *binview; /* Instance parente */ - PangoTabArray *tabs; - gint current_y; PangoFontDescription *font_desc; - GList *child_exposes; PangoContext *ltr_context, *rtl_context; GtkTextAttributes *style; static bool done = false; @@ -230,8 +267,8 @@ static void gtk_block_view_init(GtkBlockView *view) - view->_layout = gtk_text_layout_new(); - gtk_text_layout_set_buffer(view->_layout, view->buffer); + view->layout = gtk_text_layout_new(); + gtk_text_layout_set_buffer(view->layout, view->buffer); @@ -239,9 +276,9 @@ static void gtk_block_view_init(GtkBlockView *view) { done = true; - gtk_text_layout_set_cursor_visible(GTK_BLOCK_VIEW(view)->_layout, FALSE); + gtk_text_layout_set_cursor_visible(GTK_BLOCK_VIEW(view)->layout, FALSE); - gtk_text_layout_set_overwrite_mode(GTK_BLOCK_VIEW(view)->_layout, FALSE); + gtk_text_layout_set_overwrite_mode(GTK_BLOCK_VIEW(view)->layout, FALSE); ltr_context = gtk_widget_create_pango_context(view); @@ -249,18 +286,10 @@ static void gtk_block_view_init(GtkBlockView *view) rtl_context = gtk_widget_create_pango_context(view); pango_context_set_base_dir(rtl_context, PANGO_DIRECTION_RTL); - gtk_text_layout_set_contexts(GTK_BLOCK_VIEW(view)->_layout, ltr_context, rtl_context); + gtk_text_layout_set_contexts(GTK_BLOCK_VIEW(view)->layout, ltr_context, rtl_context); - tabs = pango_tab_array_new_with_positions(5, TRUE, - PANGO_TAB_LEFT, 120, - PANGO_TAB_LEFT, 290, - PANGO_TAB_LEFT, 50, - PANGO_TAB_LEFT, 50, - PANGO_TAB_LEFT, 50); - - style = gtk_text_attributes_new (); gtk_widget_ensure_style(view); @@ -279,7 +308,6 @@ static void gtk_block_view_init(GtkBlockView *view) style->indent = 10;*/ style->left_margin = 10; style->right_margin = 10; - style->tabs = tabs; style->wrap_mode = GTK_WRAP_WORD; style->justification = GTK_JUSTIFY_LEFT; @@ -287,22 +315,18 @@ static void gtk_block_view_init(GtkBlockView *view) style->direction = gtk_widget_get_direction(view); - gtk_text_layout_set_default_style(GTK_BLOCK_VIEW(view)->_layout, style); + gtk_text_layout_set_default_style(GTK_BLOCK_VIEW(view)->layout, style); gtk_text_attributes_unref(style); - //gtk_text_layout_get_size (GTK_BLOCK_VIEW(view)->_layout, &width, &height); + //gtk_text_layout_get_size (GTK_BLOCK_VIEW(view)->layout, &width, &height); - gtk_text_layout_set_screen_width (GTK_BLOCK_VIEW(view)->_layout, + gtk_text_layout_set_screen_width (GTK_BLOCK_VIEW(view)->layout, MAX (1, 1000)); } - - gtk_text_buffer_set_text(view->buffer, "\t|\t|\t|\t|\t|\n", -1); - - } @@ -362,8 +386,6 @@ static void gtk_block_view_realize(GtkWidget *widget) GTK_WIDGET_CLASS(parent_class)->realize(widget); - GTK_BLOCK_VIEW(widget)->layout = gtk_widget_create_pango_layout(widget, NULL); - font_desc = pango_font_description_from_string("mono 10"); gtk_widget_modify_font(widget, font_desc); pango_font_description_free(font_desc); @@ -375,25 +397,24 @@ static gboolean gtk_block_view_button_press(GtkWidget *widget, GdkEventButton *e { gboolean result; /* Décision à retourner */ GtkBlockView *view; /* Composant GTK réel */ - int y; /* Position à manipuler */ - GRenderingLine *line; /* Ligne de rendu visée */ + GtkTextIter iter; /* Point d'insertion */ + GtkTextMark *mark; /* Marquage de ligne associée */ + GRenderingLine *line; /* Ligne de rendu */ result = FALSE; view = GTK_BLOCK_VIEW(widget); - y = event->y; - line = g_rendering_line_find_by_y(GTK_BIN_VIEW(view)->lines, GTK_BIN_VIEW(view)->last, &y); + gtk_text_layout_get_line_at_y(view->layout, &iter, event->y, NULL); + mark = gtk_text_iter_get_marks(&iter)->data; - if (line != NULL) - { - /* Clic dans la marge */ - if (event->type == GDK_BUTTON_PRESS && event->x < (2 * MARGIN_SPACE + view->line_height)) - { - result = TRUE; - g_rendering_line_toggle_flag(line, RLF_BREAK_POINT); - } + line = g_object_get_data(G_OBJECT(mark), "line"); + /* Clic dans la marge */ + if (event->type == GDK_BUTTON_PRESS && event->x < view->left_margin) + { + result = TRUE; + g_rendering_line_toggle_flag(line, RLF_BREAK_POINT); } return result; @@ -447,66 +468,156 @@ void gtk_block_view_update_margin(GRenderingLine *line, GtkBlockView *view) static gboolean gtk_block_view_expose(GtkWidget *widget, GdkEventExpose *event) { - GtkBinView *view; /* Autre version du composant */ - GdkGCValues values; /* Propriétés du contexte */ - GdkColor white; /* Couleur du fond */ - int width; /* Largeur de l'élément */ - int height; /* Hauteur de l'élément */ - int y; /* Ordonnée du haut d'une ligne*/ - GRenderingLine *iter; /* Boucle de parcours */ + GtkBlockView *view; + + + //GtkWidget *widget; /* Autre version du composant */ + GtkBinView *bview; /* Autre version du composant */ + GtkStyle *style; /* Style associé au composant */ + GtkBinViewClass *parent_class; /* Version pure du parent */ + GtkTextIter iter; /* Point d'insertion */ + GdkRectangle rect; /* Zone d'un point */ + GtkTextMark *mark; /* Marquage de ligne associée */ + GRenderingLine *line; /* Ligne de rendu */ + RenderingLineFlag flags; /* Propriétés de la ligne */ + GdkPixbuf *pixbuf; /* Données utiles au dessin */ + + + //GdkGCValues values; /* Propriétés du contexte */ + //GdkColor white; /* Couleur du fond */ + //int width; /* Largeur de l'élément */ + //int height; /* Hauteur de l'élément */ + //int y; /* Ordonnée du haut d'une ligne*/ + //GRenderingLine *iter; /* Boucle de parcours */ - PangoFontDescription *font_desc; GList *child_exposes; - view = GTK_BIN_VIEW(widget); + view = GTK_BLOCK_VIEW(widget); + + widget = GTK_WIDGET(view); + bview = GTK_BIN_VIEW(widget); + + gdk_window_begin_paint_region(GDK_DRAWABLE(widget->window), event->region); + + gdk_gc_set_clip_region(bview->gc, event->region); + + style = gtk_widget_get_style(GTK_WIDGET(view)); + + + //gtk_widget_get_size_request(widget, &width, &height); + + + /* Dessin de la marge gauche */ + + gdk_gc_set_foreground(bview->gc, &style->mid[GTK_WIDGET_STATE(widget)]); + + gdk_draw_rectangle(GDK_DRAWABLE(widget->window), bview->gc, TRUE, + 0, event->area.y, view->left_margin, event->area.y + event->area.height); + + gdk_gc_set_foreground(bview->gc, &style->dark[GTK_WIDGET_STATE(widget)]); + + gdk_draw_line(GDK_DRAWABLE(widget->window), bview->gc, + view->left_margin, event->area.y, + view->left_margin, event->area.y + event->area.height); + + /* Eventuelle bordure globale */ + + parent_class = GTK_BIN_VIEW_CLASS(g_type_class_peek_parent(GTK_BLOCK_VIEW_GET_CLASS(view))); + + GTK_WIDGET_CLASS(parent_class)->expose_event(widget, event); + + /* Informations individuelles des lignes */ + + gtk_text_layout_get_line_at_y(view->layout, &iter, event->area.y, NULL); + gtk_text_layout_get_iter_location(view->layout, &iter, &rect); + + while (rect.y < (event->area.y + event->area.height)) + { + mark = gtk_text_iter_get_marks(&iter)->data; + + line = g_object_get_data(G_OBJECT(mark), "line"); + flags = g_rendering_line_get_flags(line); + + if (flags & RLF_RUNNING_BP) + pixbuf = GTK_BLOCK_VIEW_GET_CLASS(view)->stopped_pix; + + else if (flags & RLF_BREAK_POINT) + pixbuf = GTK_BLOCK_VIEW_GET_CLASS(view)->breakpoint_pix; + + else pixbuf = NULL; + + if (pixbuf != NULL) + gdk_draw_pixbuf(GDK_DRAWABLE(widget->window), bview->gc, pixbuf, 0, 0, 10, rect.y, + gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), + GDK_RGB_DITHER_NORMAL, 0, 0); + + /* Le point d'entrée prime */ + if (flags & RLF_ENTRY_POINT) + { + pixbuf = GTK_BLOCK_VIEW_GET_CLASS(view)->entry_pix; + + gdk_draw_pixbuf(GDK_DRAWABLE(widget->window), bview->gc, pixbuf, 0, 0, 10, rect.y, + gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), + GDK_RGB_DITHER_NORMAL, 0, 0); + + } + + if (!gtk_text_layout_move_iter_to_next_line(view->layout, &iter)) break; + gtk_text_layout_get_iter_location(view->layout, &iter, &rect); + + } + + /* Impression du désassemblage */ + + + #if 0 gdk_window_begin_paint_region(GDK_DRAWABLE(widget->window), event->region); - gdk_gc_set_clip_region(view->gc, event->region); + gdk_gc_set_clip_region(bview->gc, event->region); - gdk_gc_get_values(view->gc, &values); + gdk_gc_get_values(bview->gc, &values); gdk_color_white(gtk_widget_get_colormap(widget), &white); - gdk_gc_set_foreground(view->gc, &white); + gdk_gc_set_foreground(bview->gc, &white); gtk_widget_get_size_request(widget, &width, &height); - gdk_draw_rectangle(GDK_DRAWABLE(widget->window), view->gc, + gdk_draw_rectangle(GDK_DRAWABLE(widget->window), bview->gc, TRUE, 0, 0, width, height); - gdk_gc_set_foreground(view->gc, &values.foreground); + gdk_gc_set_foreground(bview->gc, &values.foreground); /* y = event->area.y; - iter = g_rendering_line_find_by_y(view->lines, view->last, &y); + iter = g_rendering_line_find_by_y(bview->lines, bview->last, &y); y = event->area.y - y; for ( ; iter != NULL && y < (event->area.y + event->area.height); - iter = g_rendering_line_get_next_iter(view->lines, iter, view->last)) + iter = g_rendering_line_get_next_iter(bview->lines, iter, bview->last)) { - g_rendering_line_draw(iter, GDK_DRAWABLE(widget->window), view->gc, - MARGIN_SPACE, 2 * MARGIN_SPACE + GTK_BLOCK_VIEW(view)->line_height, - y, GTK_BLOCK_VIEW(view)->line_height, GTK_BLOCK_VIEW(view)->rendering); + g_rendering_line_draw(iter, GDK_DRAWABLE(widget->window), bview->gc, + MARGIN_SPACE, 2 * MARGIN_SPACE + GTK_BLOCK_VIEW(bview)->line_height, + y, GTK_BLOCK_VIEW(bview)->line_height, GTK_BLOCK_VIEW(bview)->rendering); - y += GTK_BLOCK_VIEW(view)->line_height; + y += GTK_BLOCK_VIEW(bview)->line_height; } */ gdk_window_end_paint(GDK_DRAWABLE(widget->window)); #endif - gtk_text_layout_set_screen_width (GTK_BLOCK_VIEW(view)->_layout, + gtk_text_layout_set_screen_width (GTK_BLOCK_VIEW(bview)->layout, MAX (1, 1000)); - //gtk_text_buffer_set_text(GTK_BLOCK_VIEW(view)->buffer, "Hello, this some text\n", -1); - font_desc = pango_font_description_from_string ("mono 10"); - gtk_widget_modify_font (view, font_desc); - pango_font_description_free (font_desc); - gtk_text_layout_draw(GTK_BLOCK_VIEW(view)->_layout, widget, GDK_DRAWABLE(widget->window), - NULL, 0, 0, 0, 0, 5000, 50000, &child_exposes); + gtk_text_layout_draw(GTK_BLOCK_VIEW(bview)->layout, widget, GDK_DRAWABLE(widget->window), + NULL, view->left_text, 0, 0, 0, 5000, 50000, &child_exposes); + + + gdk_window_end_paint(GDK_DRAWABLE(widget->window)); return TRUE; @@ -619,8 +730,16 @@ void gtk_block_view_set_format(GtkBlockView *view, const exe_format *format) static void gtk_block_view_set_rendering_lines(GtkBlockView *view, GRenderingLine *lines, GRenderingLine *last) { + size_t lengths[SAR_COUNT]; /* Différentes tailles de zone */ GRenderingLine *iter; /* Boucle de parcours */ GtkTextIter pos; /* Point d'insertion */ + GtkTextMark *mark; /* Marquage de ligne associée */ + PangoTabArray *tabs; /* Tailles de tabulation */ + GdkRectangle rect; /* Zone d'un point */ + + lengths[SAR_ADDRESS] = 0; + lengths[SAR_CODE] = 0; + lengths[SAR_INSTRUCTION] = 0; for (iter = GTK_BIN_VIEW(view)->lines; iter != NULL; @@ -636,12 +755,56 @@ static void gtk_block_view_set_rendering_lines(GtkBlockView *view, GRenderingLin } gtk_text_buffer_get_end_iter(view->buffer, &pos); + + mark = gtk_text_buffer_create_mark(view->buffer, NULL, &pos, TRUE); + g_object_set_data(G_OBJECT(mark), "line", iter); + g_content_exporter_add_to_gtk_buffer(G_CONTENT_EXPORTER(iter), view->rendering, - view->buffer, &pos); + view->buffer, &pos, lengths); } - gtk_text_layout_validate(GTK_BLOCK_VIEW(view)->_layout, 100000); + gtk_text_layout_move_iter_visually(view->layout, &pos, -1); + gtk_text_layout_get_iter_location(view->layout, &pos, &rect); + + /* Taille des tabulations */ + + if (lengths[SAR_ADDRESS] > 0 && lengths[SAR_CODE] > 0) + tabs = pango_tab_array_new_with_positions(3, TRUE, + PANGO_TAB_LEFT, rect.width * (lengths[SAR_ADDRESS] + 3), + PANGO_TAB_LEFT, rect.width * (lengths[SAR_ADDRESS] + 3 + lengths[SAR_CODE] + 3), + PANGO_TAB_LEFT, rect.width * (lengths[SAR_ADDRESS] + 3 + lengths[SAR_CODE] + 3 + lengths[SAR_INSTRUCTION] + 4)); + + else if (lengths[SAR_ADDRESS] > 0 && lengths[SAR_CODE] == 0) + tabs = pango_tab_array_new_with_positions(2, TRUE, + PANGO_TAB_LEFT, rect.width * (lengths[SAR_ADDRESS] + 3), + PANGO_TAB_LEFT, rect.width * (lengths[SAR_ADDRESS] + 3 + lengths[SAR_INSTRUCTION] + 4)); + + else if (lengths[SAR_ADDRESS] == 0 && lengths[SAR_CODE] > 0) + tabs = pango_tab_array_new_with_positions(2, TRUE, + PANGO_TAB_LEFT, rect.width * (lengths[SAR_CODE] + 3), + PANGO_TAB_LEFT, rect.width * (lengths[SAR_CODE] + 3 + lengths[SAR_INSTRUCTION] + 4)); + + else + tabs = pango_tab_array_new_with_positions(1, TRUE, + PANGO_TAB_LEFT, rect.width * (lengths[SAR_INSTRUCTION] + 4)); + + if (view->layout->default_style->tabs) + pango_tab_array_free(view->layout->default_style->tabs); + + view->layout->default_style->tabs = tabs; + + gtk_text_layout_default_style_changed(view->layout); + + /* Taille des marges */ + + view->line_height = rect.height; + view->left_margin = 2 * rect.height; + view->left_text = -2.5 * rect.height; + + /* Validation finale */ + + gtk_text_layout_validate(GTK_BLOCK_VIEW(view)->layout, 100000); gtk_block_view_recompute_size_request(view); @@ -665,28 +828,16 @@ static void gtk_block_view_set_rendering_lines(GtkBlockView *view, GRenderingLin void gtk_block_view_recompute_size_request(GtkBlockView *view) { - int width; /* Largeur de l'objet actuelle */ - int height; /* Hauteur de l'objet actuelle */ + gint width; /* Largeur de l'objet actuelle */ + gint height; /* Hauteur de l'objet actuelle */ - gtk_text_layout_get_size(view->_layout, &width, &height); + gtk_text_layout_get_size(view->layout, &width, &height); - gtk_widget_set_size_request(GTK_WIDGET(view), - width + 2 * MARGIN_SPACE + 20/*view->line_height*/, - height); + width += -view->left_text + 1; + height += 1; + gtk_widget_set_size_request(GTK_WIDGET(view), width, height); - printf("req size :: (%d ; %d)\n", width, height); - - /* - g_rendering_line_get_size(GTK_BIN_VIEW(view)->lines, - GTK_BIN_VIEW(view)->last, - view->rendering, - &width, &height, &view->line_height); - - gtk_widget_set_size_request(GTK_WIDGET(view), - width + 2 * MARGIN_SPACE + view->line_height, - height); - */ } -- cgit v0.11.2-87-g4458