summaryrefslogtreecommitdiff
path: root/src/gtkext/gtkbufferview.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtkext/gtkbufferview.c')
-rw-r--r--src/gtkext/gtkbufferview.c178
1 files changed, 147 insertions, 31 deletions
diff --git a/src/gtkext/gtkbufferview.c b/src/gtkext/gtkbufferview.c
index d5780ed..8b9b83b 100644
--- a/src/gtkext/gtkbufferview.c
+++ b/src/gtkext/gtkbufferview.c
@@ -55,6 +55,9 @@ static gboolean gtk_buffer_view_key_press(GtkWidget *, GdkEventKey *);
/* Indique les dimensions de travail du composant d'affichage. */
static void gtk_buffer_view_compute_requested_size(GtkBufferView *, gint *, gint *);
+/* Détermine la taille des bonds lors de défilements. */
+static void gtk_buffer_view_compute_scroll_inc(GtkBufferView *, gint, GtkOrientation, gdouble *, gdouble *);
+
/* Indique la position d'affichage d'une adresse donnée. */
static bool gtk_buffer_view_get_address_coordinates(const GtkBufferView *, const vmpa2t *, gint *, gint *);
@@ -66,6 +69,9 @@ static void gtk_buffer_view_cache_glance(GtkBufferView *, cairo_t *, const GtkAl
/* ------------------------------ ANIMATION DU CURSEUR ------------------------------ */
+/* Déplace le curseur en effaçant son éventuelle position. */
+static void gtk_buffer_view_relocate_caret(GtkBufferView *, const GdkRectangle *, const vmpa2t *);
+
/* Redémarre l'affichage du curseur à l'emplacement courant. */
static void restart_caret_blinking(GtkBufferView *);
@@ -109,6 +115,7 @@ static void gtk_buffer_view_class_init(GtkBufferViewClass *class)
widget_class->key_press_event = gtk_buffer_view_key_press;
panel_class->compute_size = (compute_requested_size)gtk_buffer_view_compute_requested_size;
+ panel_class->compute_inc = (compute_scroll_inc)gtk_buffer_view_compute_scroll_inc;
panel_class->get_coordinates = (get_addr_coordinates_fc)gtk_buffer_view_get_address_coordinates;
g_signal_new("caret-moved",
@@ -205,14 +212,16 @@ static gboolean gtk_buffer_view_focus(GtkWidget *widget, GtkDirectionType direct
static gboolean gtk_buffer_view_button_press(GtkWidget *widget, GdkEventButton *event)
{
GtkBufferView *view; /* Autre version du composant */
+ GtkViewPanel *pview; /* 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 */
+ const vmpa2t *addr; /* Position mémoire associée */
GdkRectangle new; /* Nouvel emplacement calculé */
view = GTK_BUFFER_VIEW(widget);
+ pview = GTK_VIEW_PANEL(widget);
gtk_widget_grab_focus(widget);
@@ -230,6 +239,11 @@ static gboolean gtk_buffer_view_button_press(GtkWidget *widget, GdkEventButton *
if (line == NULL) return FALSE;
+
+ printf(" [init ] %p - line = %p (y=%d)\n", view->buffer_view, line, real_y);
+
+
+
if (real_x < view->left_margin)
{
@@ -241,28 +255,8 @@ static gboolean gtk_buffer_view_button_press(GtkWidget *widget, GdkEventButton *
}
else
{
- return FALSE;
- /*
- 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);
-
- view->caret = new;
- view->caret_addr = addr;
-
- restart_caret_blinking(view);
-
+ addr = g_buffer_view_compute_caret(view->buffer_view, line, index, real_x, pview->display, &new);
+ gtk_buffer_view_relocate_caret(view, &new, addr);
}
return FALSE;
@@ -343,7 +337,6 @@ static gboolean gtk_buffer_view_draw(GtkWidget *widget, cairo_t *cr)
gint fake_y; /* Ordonnée virtuelle */
view = GTK_BUFFER_VIEW(widget);
- widget = GTK_WIDGET(view);
pview = GTK_VIEW_PANEL(widget);
window = gtk_widget_get_window(widget);
@@ -384,6 +377,14 @@ static gboolean gtk_buffer_view_draw(GtkWidget *widget, cairo_t *cr)
}
+ /* Curseur clignotant ? */
+
+ if (gtk_widget_is_focus(widget))
+ {
+ view->show_caret = !view->show_caret;
+ gtk_buffer_view_refresh_caret(view);
+ }
+
cairo_restore(cr);
return TRUE;
@@ -407,32 +408,78 @@ static gboolean gtk_buffer_view_draw(GtkWidget *widget, cairo_t *cr)
static gboolean gtk_buffer_view_key_press(GtkWidget *widget, GdkEventKey *event)
{
gboolean result; /* Suites à renvoyer */
+
+ GtkBufferView *view; /* Autre version du composant */
+ GtkViewPanel *pview; /* Autre version du composant */
+
+
bool ctrl; /* Statut de la touche Contrôle*/
+
+ GdkRectangle area;
+
+ const vmpa2t *addr;
+
+
result = FALSE;
+
+
+ view = GTK_BUFFER_VIEW(widget);
+ pview = GTK_VIEW_PANEL(widget);
+
+
+ area = view->caret;
+
+
ctrl = (event->state & GDK_CONTROL_MASK);
switch (event->keyval)
{
case GDK_KEY_Left:
+ printf("LEFT\n");
+ addr = g_buffer_view_move_caret(view->buffer_view, &area, ctrl, GDK_SCROLL_LEFT, pview->display);
+ gtk_buffer_view_relocate_caret(view, &area, view->caret_addr);
result = TRUE;
break;
+
case GDK_KEY_Up:
+ printf("UP\n");
+ addr = g_buffer_view_move_caret(view->buffer_view, &area, ctrl, GDK_SCROLL_UP, pview->display);
+ gtk_buffer_view_relocate_caret(view, &area, view->caret_addr);
result = TRUE;
break;
+
case GDK_KEY_Right:
+ printf("RIGHT\n");
+ addr = g_buffer_view_move_caret(view->buffer_view, &area, ctrl, GDK_SCROLL_RIGHT, pview->display);
+ gtk_buffer_view_relocate_caret(view, &area, view->caret_addr);
result = TRUE;
break;
+
case GDK_KEY_Down:
+ printf("DOWN\n");
+ addr = g_buffer_view_move_caret(view->buffer_view, &area, ctrl, GDK_SCROLL_DOWN, pview->display);
+ gtk_buffer_view_relocate_caret(view, &area, view->caret_addr);
result = TRUE;
break;
+
+ default:
+ addr = NULL;
+ break;
+
}
printf("ctrl ? %d -- keyval = %d -->> %d\n", ctrl, event->keyval, result);
+ if (addr != NULL) gtk_view_panel_scroll_to_address(pview, addr);
+
+
+ printf("\n");
+
+
return result;
}
@@ -466,6 +513,38 @@ static void gtk_buffer_view_compute_requested_size(GtkBufferView *view, gint *wi
}
+/******************************************************************************
+* *
+* Paramètres : panel = composant GTK d'affichage à mettre à jour. *
+* size = taille de l'espace dans la direction donnée. *
+* orientation = indication sur le défilement à traiter. *
+* step = valeur d'un petit pas de défilement. [OUT] *
+* page = valeur d'un grand pas de défilement. [OUT] *
+* *
+* Description : Détermine la taille des bonds lors de défilements. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_buffer_view_compute_scroll_inc(GtkBufferView *view, gint size, GtkOrientation orientation, gdouble *step, gdouble *page)
+{
+ if (orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ *step = 17; // FIXME g_buffer_view_get_line_height(view->buffer_view);
+ *page = *step * 10;
+ }
+
+ else
+ GTK_VIEW_PANEL_CLASS(gtk_buffer_view_parent_class)->compute_inc(GTK_VIEW_PANEL(view),
+ size, orientation, step, page);
+
+}
+
+
+
@@ -633,10 +712,43 @@ void gtk_buffer_view_compute_relative_coords(GtkBufferView *view, gint *x, gint
/******************************************************************************
* *
* Paramètres : view = composant GTK à manipuler. *
+* area = emplacement pour le dessin d'un curseur. *
+* addr = position dans la mémoire représentée du curseur. *
+* *
+* Description : Déplace le curseur en effaçant son éventuelle position. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void gtk_buffer_view_relocate_caret(GtkBufferView *view, const GdkRectangle *area, const vmpa2t *addr)
+{
+ if (view->caret_addr != NULL)
+ {
+ gtk_buffer_view_compute_relative_coords(view, &view->caret.x, &view->caret.y);
+
+ gtk_widget_queue_draw_area(GTK_WIDGET(view), view->caret.x, view->caret.y,
+ view->caret.width, view->caret.height);
+
+ }
+
+ view->caret = *area;
+ view->caret_addr = addr;
+
+ restart_caret_blinking(view);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : view = composant GTK à manipuler. *
* *
* Description : Redémarre l'affichage du curseur à l'emplacement courant. *
* *
-* Retour : TRUE pour poursuivre les basculements automatiques. *
+* Retour : - *
* *
* Remarques : - *
* *
@@ -644,16 +756,20 @@ void gtk_buffer_view_compute_relative_coords(GtkBufferView *view, gint *x, gint
static void restart_caret_blinking(GtkBufferView *view)
{
- if (view->caret_addr == VMPA_INVALID)
- return;
-
if (view->caret_timer != 0)
+ {
g_source_remove(view->caret_timer);
+ view->caret_timer = 0;
+ }
+
+ if (view->caret_addr != NULL)
+ {
+ view->show_caret = false;
+ gtk_buffer_view_refresh_caret(view);
- view->caret_timer = g_timeout_add_seconds(1, (GSourceFunc)gtk_buffer_view_refresh_caret, view);
+ view->caret_timer = g_timeout_add_seconds(1, (GSourceFunc)gtk_buffer_view_refresh_caret, view);
- view->show_caret = false;
- gtk_buffer_view_refresh_caret(view);
+ }
g_signal_emit_by_name(view, "caret-moved", view->caret_addr);