diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2012-09-27 21:48:32 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2012-09-27 21:48:32 (GMT) |
commit | fa83bc71888fed39bcc77ad610ffd6f6980444f8 (patch) | |
tree | 38144f021e53bc5bfcf163002191076ef4766794 /src/glibext/gbufferline.c | |
parent | f32b173243cf46f8a9cf84b610139b3d4bd20803 (diff) |
Selected segments for highlighting.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@264 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/glibext/gbufferline.c')
-rw-r--r-- | src/glibext/gbufferline.c | 169 |
1 files changed, 151 insertions, 18 deletions
diff --git a/src/glibext/gbufferline.c b/src/glibext/gbufferline.c index 08f5ae7..7f88bff 100644 --- a/src/glibext/gbufferline.c +++ b/src/glibext/gbufferline.c @@ -35,6 +35,14 @@ +/* Espace entre les colonnes */ +#define COL_MARGIN 23 + + + +/* ---------------------------- REGROUPEMENT PAR COLONNE ---------------------------- */ + + /* Informations sur le contenu d'une colonne */ typedef struct _buffer_line_column { @@ -56,11 +64,19 @@ static gint get_column_width(buffer_line_column *); /* Ajoute un fragment de texte à une colonne de ligne. */ static void add_segment_to_column(buffer_line_column *, GBufferSegment *); +/* Donne le segment d'une colonne présent à une abscisse donnée. */ +static GBufferSegment *get_segment_at(const buffer_line_column *, gint); + +/* Met en surbrillance des segments similaires. */ +GSList *highlight_all_same_segments(const buffer_line_column *, GSList *, const GBufferSegment *); + /* Imprime le contenu d'une colonne de ligne de texte. */ static void draw_segments_of_column(buffer_line_column *, GdkDrawable *, GdkGC *, gint, gint); +/* ---------------------------- GESTION DE LINE COMPLETE ---------------------------- */ + /* Représentation de fragments de texte en ligne (instance) */ struct _GBufferLine @@ -93,6 +109,10 @@ static void g_buffer_line_init(GBufferLine *); +/* ---------------------------------------------------------------------------------- */ +/* REGROUPEMENT PAR COLONNE */ +/* ---------------------------------------------------------------------------------- */ + @@ -130,7 +150,7 @@ static void reset_column(buffer_line_column *column) static gint get_column_width(buffer_line_column *column) { - size_t i; + size_t i; /* Boucle de parcours */ if (column->max_width == -1) { @@ -176,52 +196,106 @@ static void add_segment_to_column(buffer_line_column *column, GBufferSegment *se /****************************************************************************** * * -* Paramètres : column = colonne de ligne de texte à manipuler. * -* drawable = surface de rendu où travailler. * -* gc = contexte graphique à utiliser pour les pinceaux. * -* x_init = abscisse du point d'impression de départ. * -* y = ordonnée du point d'impression. * +* Paramètres : column = colonne de ligne de texte à consulter. * +* x = position de recherche à ajuster. * * * -* Description : Imprime le contenu d'une colonne de ligne de texte. * +* Description : Donne le segment d'une colonne présent à une abscisse donnée.* * * -* Retour : - * +* Retour : Segment trouvé ou NULL si hors borne. * * * * Remarques : - * * * ******************************************************************************/ -static void draw_segments_of_column(buffer_line_column *column, GdkDrawable *drawable, GdkGC *gc, gint x_init, gint y) +static GBufferSegment *get_segment_at(const buffer_line_column *column, gint x) { - gint x; - size_t i; + GBufferSegment *result; /* Trouvaille à retourner */ + size_t i; /* Boucle de parcours */ + gint width; /* Largeur à retirer */ - x = x_init; - - for (i = 0; i < column->count; i++) - g_buffer_segment_draw(column->segments[i], drawable, gc, &x, y); - -} + result = NULL; + for (i = 0; i < column->count && result == NULL; i++) + { + width = g_buffer_segment_get_width(column->segments[i]); + if (width <= x) + x -= width; + else + result = column->segments[i]; + } + return result; +} +/****************************************************************************** +* * +* Paramètres : column = colonne de ligne de texte à consulter. * +* list = liste de segments identiques à constituer. * +* ref = segment de référence à comparer avec les autres. * +* * +* Description : Met en surbrillance des segments similaires. * +* * +* Retour : Liste de segments identiques complétée. * +* * +* Remarques : - * +* * +******************************************************************************/ +GSList *highlight_all_same_segments(const buffer_line_column *column, GSList *list, const GBufferSegment *ref) +{ + size_t i; /* Boucle de parcours */ + for (i = 0; i < column->count; i++) + if (g_buffer_segment_compare(column->segments[i], ref)) + { + g_buffer_segment_set_style(column->segments[i], SRS_HIGHLIGHT_SAME); + g_object_ref(G_OBJECT(column->segments[i])); + list = g_slist_prepend(list, column->segments[i]); + } + return list; +} +/****************************************************************************** +* * +* Paramètres : column = colonne de ligne de texte à manipuler. * +* drawable = surface de rendu où travailler. * +* gc = contexte graphique à utiliser pour les pinceaux. * +* x_init = abscisse du point d'impression de départ. * +* y = ordonnée du point d'impression. * +* * +* Description : Imprime le contenu d'une colonne de ligne de texte. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ +static void draw_segments_of_column(buffer_line_column *column, GdkDrawable *drawable, GdkGC *gc, gint x_init, gint y) +{ + gint x; + size_t i; + x = x_init; + for (i = 0; i < column->count; i++) + g_buffer_segment_draw(column->segments[i], drawable, gc, &x, y); +} +/* ---------------------------------------------------------------------------------- */ +/* GESTION DE LINE COMPLETE */ +/* ---------------------------------------------------------------------------------- */ /* Détermine le type de la représentation de fragments de texte en ligne. */ @@ -469,6 +543,65 @@ void g_buffer_line_add_segment(GBufferLine *line, BufferLineColumn index, GBuffe /****************************************************************************** * * +* Paramètres : line = ligne à venir consulter. * +* max_widths = largeurs de colonne à respecter. * +* x = position à la colonne visée par la procédure. * +* * +* Description : Donne le segment présent à une abscisse donnée. * +* * +* Retour : Segment trouvé ou NULL si hors borne. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GBufferSegment *g_buffer_line_get_segment_at(const GBufferLine *line, const gint max_widths[BLC_COUNT], gint x) +{ + GBufferSegment *result; /* Trouvaille à retourner */ + BufferLineColumn i; /* Boucle de parcours */ + + result = NULL; + + for (i = BLC_ADDRESS; i < BLC_COUNT; i++) + if (x < max_widths[i]) break; + else x -= (max_widths[i] + COL_MARGIN); + + if (i < BLC_COUNT) + result = get_segment_at(&line->columns[i], x); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : line = ligne à venir consulter. * +* list = liste de segments identiques à constituer. * +* ref = segment de référence à comparer avec tous les autres. * +* * +* Description : Met en surbrillance des segments similaires. * +* * +* Retour : Liste de segments identiques complétée. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GSList *g_buffer_line_highlight_all_same_segments(const GBufferLine *line, GSList *list, const GBufferSegment *ref) +{ + BufferLineColumn i; /* Boucle de parcours */ + + for (i = BLC_ADDRESS; i < BLC_COUNT; i++) + list = highlight_all_same_segments(&line->columns[i], list, ref); + + return list; + +} + + +/****************************************************************************** +* * * Paramètres : line = ligne à venir compléter. * * column = colonne de la ligne visée par l'insertion. * * text = texte à insérer dans l'existant. * @@ -605,7 +738,7 @@ void g_buffer_line_draw(GBufferLine *line, GdkDrawable *drawable, GdkGC *gc, con draw_segments_of_column(&line->columns[i], drawable, gc, x, y); if (i < line->merge_start) - x += max_widths[i] + 23; + x += max_widths[i] + COL_MARGIN; } |