From e25b4d02bba5dbd5cbc34b8f24a8c980396f86fb Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Mon, 14 Apr 2014 16:43:36 +0000 Subject: Handled mouse clicks in view margins. git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@370 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a --- ChangeLog | 9 ++++++++- src/glibext/gcodebuffer.c | 13 ++++--------- src/glibext/gcodebuffer.h | 2 +- src/gtkext/gtkbufferview.c | 29 +++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index e708191..325fb4f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,11 @@ -07-04-20 Cyrille Bagard +14-04-14 Cyrille Bagard + + * src/glibext/gcodebuffer.c: + * src/glibext/gcodebuffer.h: + * src/gtkext/gtkbufferview.c: + Handle mouse clicks in view margins. + +14-04-07 Cyrille Bagard * pixmaps/bookmark.png: New entry: create bookmark in buffer views. diff --git a/src/glibext/gcodebuffer.c b/src/glibext/gcodebuffer.c index 4a4e38f..fdfaa71 100644 --- a/src/glibext/gcodebuffer.c +++ b/src/glibext/gcodebuffer.c @@ -1072,8 +1072,9 @@ gint g_buffer_view_get_height(const GBufferView *view) /****************************************************************************** * * * Paramètres : view = vue de tampon à mettre à jour. * +* line = ligne correspondant à la position. * +* index = indice de cette même ligne dans le tampon. * * x = abscisse de la zone principale à traiter. * -* y = ordonnée de la zone principale à traiter. * * caret = position du curseur à construire. [OUT] * * * * Description : Calcule la position idéale de curseur pour un point donné. * @@ -1084,24 +1085,18 @@ gint g_buffer_view_get_height(const GBufferView *view) * * ******************************************************************************/ -vmpa_t g_buffer_view_compute_caret(GBufferView *view, gint x, gint y, GdkRectangle *caret) +vmpa_t g_buffer_view_compute_caret(GBufferView *view, GBufferLine *line, size_t index, gint x, GdkRectangle *caret) { - size_t index; /* Indice de la ligne trouvée */ - GBufferLine *line; /* Ligne sous le pointeur */ gint tmp_x; /* Copie de travail modifiable */ GBufferSegment *segment; /* Segment visé par le pointeur*/ size_t first; /* Première ligne intégrée */ - line = g_buffer_view_find_line_at(view, y, &index); - if (line == NULL) return VMPA_INVALID; - tmp_x = x; tmp_x -= view->left_text; if (tmp_x < 0) return VMPA_INVALID; segment = g_buffer_line_get_segment_at(line, view->max_widths, &tmp_x, true); - if (segment == NULL) printf("no segment\n"); if (segment == NULL) return VMPA_INVALID; caret->x = (x - tmp_x) + g_buffer_segment_get_caret_position(segment, tmp_x); @@ -1233,7 +1228,7 @@ vmpa_t g_buffer_view_move_caret(GBufferView *view, GdkRectangle *caret, bool ctr } if (result && !computed) - result = g_buffer_view_compute_caret(view, caret->x, caret->y, caret); + /*result = g_buffer_view_compute_caret(view, caret->x, caret->y, caret, NULL)*/; return result; diff --git a/src/glibext/gcodebuffer.h b/src/glibext/gcodebuffer.h index e2ff8b0..2e2d483 100644 --- a/src/glibext/gcodebuffer.h +++ b/src/glibext/gcodebuffer.h @@ -128,7 +128,7 @@ gint g_buffer_view_get_width(GBufferView *, bool, bool); gint g_buffer_view_get_height(const GBufferView *); /* Calcule la position idéale de curseur pour un point donné. */ -vmpa_t g_buffer_view_compute_caret(GBufferView *, gint, gint, GdkRectangle *); +vmpa_t g_buffer_view_compute_caret(GBufferView *, GBufferLine *, size_t, gint, GdkRectangle *); /* Déplace le curseur au sein d'une vue de tampon. */ vmpa_t g_buffer_view_move_caret(GBufferView *, GdkRectangle *, bool, GdkScrollDirection, bool, bool); diff --git a/src/gtkext/gtkbufferview.c b/src/gtkext/gtkbufferview.c index 877b041..ac1a8e5 100644 --- a/src/gtkext/gtkbufferview.c +++ b/src/gtkext/gtkbufferview.c @@ -216,6 +216,8 @@ static gboolean gtk_buffer_view_button_press(GtkWidget *widget, GdkEventButton * GtkBufferView *view; /* Autre version du composant */ gint real_x; /* Abscisse absolue réelle */ gint real_y; /* Ordonnée absolue réelle */ + size_t index; /* Indice de ligne de tampon */ + GBufferLine *line; /* Ligne à la position courante*/ vmpa_t addr; /* Position mémoire associée */ GdkRectangle new; /* Nouvel emplacement calculé */ @@ -227,19 +229,38 @@ static gboolean gtk_buffer_view_button_press(GtkWidget *widget, GdkEventButton * real_y = event->y; gtk_buffer_view_compute_real_coord(view, &real_x, &real_y); - printf(" mouse :: (%g ; %g) -> (%d ; %d)\n", + printf(" !mouse! :: (%g ; %g) -> (%d ; %d)\n", event->x, event->y, real_x, real_y); - addr = g_buffer_view_compute_caret(view->buffer_view, real_x, real_y, &new); - if (addr != VMPA_INVALID) + + line = g_buffer_view_find_line_at(view->buffer_view, real_y, &index); + if (line == NULL) return FALSE; + + + if (real_x < view->left_margin) { + + + + printf("Border Line :: %p\n", line); + + + } + else + { + addr = g_buffer_view_compute_caret(view->buffer_view, line, index, real_x, &new); + if (addr == VMPA_INVALID) return FALSE; + gtk_buffer_view_compute_relative_coords(view, &view->caret.x, &view->caret.y); printf(" mouse --old-- :: (%d ; %d)\n", view->caret.x, view->caret.y); + printf(" mouse --new-- :: (%d ; %d)\n", + new.x, new.y); + gtk_widget_queue_draw_area(GTK_WIDGET(view), view->caret.x, view->caret.y, view->caret.width, view->caret.height); @@ -503,7 +524,7 @@ static gboolean gtk_buffer_view_draw(GtkWidget *widget, cairo_t *cr) gtk_style_context_get(gtk_widget_get_style_context(widget), state, GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &color, NULL); - cairo_rectangle(cr, fake_x, area.y,view->left_margin, area.y + area.height); + cairo_rectangle(cr, fake_x, area.y, view->left_margin, area.y + area.height); cairo_fill(cr); gtk_style_context_get(gtk_widget_get_style_context(widget), state, -- cgit v0.11.2-87-g4458