diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2015-04-20 23:09:13 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2015-04-20 23:09:13 (GMT) |
commit | ea40f74566cd813722f49ae740ca3df04e522bb2 (patch) | |
tree | 7a61557efa0a80fcf3b58df9626f7fad9bd61455 /src/glibext | |
parent | 874b812e720a8f9fb6248cb54e76bd8ab2b2a250 (diff) |
Transmitted the focus when a limit has been reached while using he keyboard.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@514 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/glibext')
-rw-r--r-- | src/glibext/gcodebuffer.c | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c index 171ba09..a7e522c 100644 --- a/src/glibext/gcodebuffer.c +++ b/src/glibext/gcodebuffer.c @@ -146,6 +146,7 @@ struct _GBufferView vmpa2t *start; /* Première ligne intégrée */ vmpa2t *end; /* Dernière ligne intégrée */ size_t first_index; /* Indice de la première ligne */ + size_t last_index; /* Indice de la dernière ligne */ gint line_height; /* Hauteur maximale des lignes */ gint max_widths[BLC_COUNT]; /* Taille cachée des colonnes */ @@ -623,25 +624,6 @@ static size_t g_code_buffer_get_index_from_address(GCodeBuffer *buffer, const vm return result; - - - - -#if 0 - size_t result; /* Indice à retourner */ - - result = _g_code_buffer_get_index_from_address(buffer, addr, first); - - /** - * Par commodités, on évite certaines instructions en cas d'échec dans les - * fonctions d'appels : la condition des boucles utilisant l'indice retourné (0) - * fait son office directement ! - */ - if (result == buffer->used) - result = 0; - - return result; -#endif } @@ -1002,8 +984,8 @@ GBufferView *g_buffer_view_new(GCodeBuffer *buffer) g_object_ref(G_OBJECT(buffer)); result->buffer = buffer; - result->start = NULL; - result->end = NULL; + + g_buffer_view_restrict(result, NULL, NULL); return result; @@ -1026,8 +1008,11 @@ GBufferView *g_buffer_view_new(GCodeBuffer *buffer) void g_buffer_view_restrict(GBufferView *view, const vmpa2t *start, const vmpa2t *end) { - view->start = dup_vmpa(start); - view->end = dup_vmpa(end); + view->start = (start != NULL ? dup_vmpa(start) : NULL); + view->end = (end != NULL ? dup_vmpa(end) : NULL); + + view->first_index = g_code_buffer_get_index_from_address(view->buffer, start, true); + view->last_index = g_code_buffer_get_index_from_address(view->buffer, end, false); } @@ -1048,6 +1033,8 @@ void g_buffer_view_restrict(GBufferView *view, const vmpa2t *start, const vmpa2t void g_buffer_view_get_restrictions(GBufferView *view, vmpa2t *start, vmpa2t *end) { + /* FIXME view->xxx == NULL -> plantage */ + if (start != NULL) copy_vmpa(start, view->start); if (end != NULL) copy_vmpa(end, view->end); @@ -1447,7 +1434,6 @@ const vmpa2t *g_buffer_view_compute_caret_full(GBufferView *view, GBufferLine *l gint offset; /* Point de travail modifiable */ gint base; /* Position absolue de segment */ GBufferSegment *segment; /* Segment visé par le pointeur*/ - size_t first; /* Première ligne intégrée */ offset = x; @@ -1459,8 +1445,9 @@ const vmpa2t *g_buffer_view_compute_caret_full(GBufferView *view, GBufferLine *l caret->x = view->left_text + base + offset; - first = g_code_buffer_get_index_from_address(view->buffer, view->start, true); - caret->y = (index - first) * view->line_height; + printf("caret Y : %zu -> %zu\n", view->first_index, index); + + caret->y = (index - view->first_index) * view->line_height; caret->width = 2; caret->height = view->line_height; @@ -1588,7 +1575,8 @@ static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, bool ctrl, GdkScrollDirection dir, const bool *display) { - vmpa2t *result; /* Actualisation à renvoyer */ + const vmpa2t *result; /* Actualisation à renvoyer */ + size_t index; /* Indice de ligne de tampon */ GBufferLine *line; /* Ligne sous le pointeur */ @@ -1600,7 +1588,7 @@ const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, b size_t first; /* Première ligne intégrée */ size_t last; /* Dernière ligne intégrée */ - size_t index; /* Indice de ligne de tampon */ + bool moved; /* Mémorisation d'une évolut° */ @@ -1652,10 +1640,8 @@ const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, b break; } - first = g_code_buffer_get_index_from_address(view->buffer, view->start, true); - last = g_code_buffer_get_index_from_address(view->buffer, view->end, false); - - first = 0; + first = view->first_index; + last = view->last_index; switch (dir) { @@ -1681,12 +1667,17 @@ const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, b case GDK_SCROLL_LEFT: + /* line = g_buffer_view_find_line_at(view, caret->y, &index); if (line == NULL) break; + */ moved = _g_buffer_view_move_caret(view, line, caret, ctrl, GDK_SCROLL_LEFT, display); - if (!moved && index > first) + if (moved) + result = get_mrange_addr(g_buffer_line_get_range(line)); + + else if (index > first) { line = view->buffer->lines[index - 1]; result = g_buffer_view_compute_caret_full(view, line, index - 1, INT_MAX, display, caret); @@ -1696,12 +1687,17 @@ const vmpa2t *g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, b case GDK_SCROLL_RIGHT: + /* line = g_buffer_view_find_line_at(view, caret->y, &index); if (line == NULL) break; + */ moved = _g_buffer_view_move_caret(view, line, caret, ctrl, GDK_SCROLL_RIGHT, display); - if (!moved && index < last) + if (moved) + result = get_mrange_addr(g_buffer_line_get_range(line)); + + else if (index < last) { line = view->buffer->lines[index + 1]; result = g_buffer_view_compute_caret_full(view, line, index + 1, left_pos, display, caret); @@ -1787,6 +1783,8 @@ bool g_buffer_view_highlight_segments(GBufferView *view, gint x, gint y, const b if (need_redraw) g_signal_emit_by_name(view, "need-redraw"); + return true; + } @@ -1813,7 +1811,6 @@ void g_buffer_view_draw(const GBufferView *view, cairo_t *cr, gint fake_x, gint gint real_x; /* Abscisse réelle pour tampon */ gint real_y; /* Ordonnée réelle pour tampon */ size_t first; /* Première ligne visée */ - size_t end; /* Dernière ligne avant limite */ size_t last; /* Dernière ligne visée + 1 */ gint y; /* Point de départ + décallage */ GBufferLine **lines; /* Liste des lignes à traiter */ @@ -1824,14 +1821,13 @@ void g_buffer_view_draw(const GBufferView *view, cairo_t *cr, gint fake_x, gint real_x = fake_x + view->left_text; real_y = fake_y + area->y; - first = g_code_buffer_get_index_from_address(view->buffer, view->start, true); + first = view->first_index; first += (real_y / view->line_height); last = first + (area->height / view->line_height); if (area->height % view->line_height > 0) last++; - end = g_code_buffer_get_index_from_address(view->buffer, view->end, false); - last = MIN(last, end); + last = MIN(last, view->last_index); y = area->y - (real_y % view->line_height); @@ -1960,6 +1956,8 @@ GBufferLine *g_buffer_view_find_line_at(GBufferView *view, gint y, size_t *idx) lheight = g_buffer_view_get_line_height(view); index = y / lheight; + index += view->first_index; + if (idx != NULL) *idx = index; |