From 85ab67368975beefb6beb9604988dd4d35f27ae2 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Wed, 7 Jun 2000 17:49:16 +0000 Subject: Added a "quantum" argument for making the panes move in jumps. 2000-06-07 Christopher James Lahey * widgets/e-paned/e-hpaned.c, widgets/e-paned/e-paned.c, widgets/e-paned/e-paned.h, widgets/e-paned/e-vpaned.c: Added a "quantum" argument for making the panes move in jumps. svn path=/trunk/; revision=3461 --- widgets/e-paned/e-hpaned.c | 7 ++++--- widgets/e-paned/e-paned.c | 36 ++++++++++++++++++++++++++++++++---- widgets/e-paned/e-paned.h | 5 +++++ widgets/e-paned/e-vpaned.c | 7 ++++--- 4 files changed, 45 insertions(+), 10 deletions(-) (limited to 'widgets') diff --git a/widgets/e-paned/e-hpaned.c b/widgets/e-paned/e-hpaned.c index e7aff16cd9..68fa893210 100644 --- a/widgets/e-paned/e-hpaned.c +++ b/widgets/e-paned/e-hpaned.c @@ -353,6 +353,7 @@ e_hpaned_button_press (GtkWidget *widget, if (!paned->in_drag && event->window == paned->handle && event->button == 1) { + paned->old_child1_size = paned->child1_size; paned->in_drag = TRUE; /* We need a server grab here, not gtk_grab_add(), since * we don't want to pass events on to the widget's children */ @@ -361,7 +362,7 @@ e_hpaned_button_press (GtkWidget *widget, | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); - paned->child1_size += event->x - paned->handle_size / 2; + paned->child1_size = e_paned_quantized_size(paned, paned->child1_size + event->x - paned->handle_size / 2); paned->child1_size = CLAMP (paned->child1_size, 0, widget->allocation.width - paned->handle_size @@ -419,9 +420,9 @@ e_hpaned_motion (GtkWidget *widget, if (paned->in_drag) { gint size = x - GTK_CONTAINER (paned)->border_width - paned->handle_size / 2; - + e_hpaned_xor_line (paned); - paned->child1_size = CLAMP (size, paned->min_position, paned->max_position); + paned->child1_size = CLAMP (e_paned_quantized_size(paned, size), paned->min_position, paned->max_position); e_hpaned_xor_line (paned); } diff --git a/widgets/e-paned/e-paned.c b/widgets/e-paned/e-paned.c index 5d09535ad9..ae68e10082 100644 --- a/widgets/e-paned/e-paned.c +++ b/widgets/e-paned/e-paned.c @@ -36,7 +36,8 @@ enum { ARG_0, - ARG_HANDLE_SIZE + ARG_HANDLE_SIZE, + ARG_QUANTUM, }; static void e_paned_class_init (EPanedClass *klass); @@ -122,6 +123,8 @@ e_paned_class_init (EPanedClass *klass) gtk_object_add_arg_type("EPaned::handle_size", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_HANDLE_SIZE); + gtk_object_add_arg_type("EPaned::quantum", GTK_TYPE_UINT, + GTK_ARG_READWRITE, ARG_QUANTUM); } static GtkType @@ -153,6 +156,9 @@ e_paned_init (EPaned *paned) paned->handle_xpos = -1; paned->handle_ypos = -1; + + paned->old_child1_size = 0; + paned->quantum = 1; } static void @@ -167,6 +173,11 @@ e_paned_set_arg (GtkObject *object, case ARG_HANDLE_SIZE: e_paned_set_handle_size (paned, GTK_VALUE_UINT (*arg)); break; + case ARG_QUANTUM: + paned->quantum = GTK_VALUE_UINT (*arg); + if (paned->quantum == 0) + paned->quantum = 1; + break; default: break; } @@ -184,6 +195,9 @@ e_paned_get_arg (GtkObject *object, case ARG_HANDLE_SIZE: GTK_VALUE_UINT (*arg) = paned->handle_size; break; + case ARG_QUANTUM: + GTK_VALUE_UINT (*arg) = paned->quantum; + break; default: arg->type = GTK_TYPE_INVALID; break; @@ -547,9 +561,9 @@ e_paned_set_handle_size (EPaned *paned, void e_paned_compute_position(EPaned *paned, - gint allocation, - gint child1_req, - gint child2_req) + gint allocation, + gint child1_req, + gint child2_req) { g_return_if_fail (paned != NULL); g_return_if_fail (E_IS_PANED (paned)); @@ -604,3 +618,17 @@ e_paned_handle_shown(EPaned *paned) else return TRUE; } + +gint +e_paned_quantized_size(EPaned *paned, + gint size) +{ + gint quantization = size - paned->old_child1_size; + if (quantization > 0) + quantization += paned->quantum / 2; + else + quantization -= paned->quantum / 2; + quantization /= paned->quantum; + quantization *= paned->quantum; + return paned->old_child1_size + quantization; +} diff --git a/widgets/e-paned/e-paned.h b/widgets/e-paned/e-paned.h index 1c4481b194..e3799a6bce 100644 --- a/widgets/e-paned/e-paned.h +++ b/widgets/e-paned/e-paned.h @@ -76,6 +76,9 @@ struct _EPaned gint min_position; gint max_position; + gint old_child1_size; + gint quantum; + guint position_set : 1; guint in_drag : 1; guint child1_shrink : 1; @@ -122,6 +125,8 @@ void e_paned_compute_position (EPaned *paned, gint child2_req); gboolean e_paned_handle_shown (EPaned *paned); +gint e_paned_quantized_size (EPaned *paned, + int size); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/widgets/e-paned/e-vpaned.c b/widgets/e-paned/e-vpaned.c index bfa5dced73..0a093af2d9 100644 --- a/widgets/e-paned/e-vpaned.c +++ b/widgets/e-paned/e-vpaned.c @@ -352,6 +352,7 @@ e_vpaned_button_press (GtkWidget *widget, if (!paned->in_drag && (event->window == paned->handle) && (event->button == 1)) { + paned->old_child1_size = paned->child1_size; paned->in_drag = TRUE; /* We need a server grab here, not gtk_grab_add(), since * we don't want to pass events on to the widget's children */ @@ -360,7 +361,7 @@ e_vpaned_button_press (GtkWidget *widget, | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); - paned->child1_size += event->y - paned->handle_size / 2; + paned->child1_size = e_paned_quantized_size(paned, paned->child1_size + event->y - paned->handle_size / 2); paned->child1_size = CLAMP (paned->child1_size, 0, widget->allocation.height - paned->handle_size - @@ -418,9 +419,9 @@ e_vpaned_motion (GtkWidget *widget, if (paned->in_drag) { gint size = y - GTK_CONTAINER(paned)->border_width - paned->handle_size / 2; - + e_vpaned_xor_line (paned); - paned->child1_size = CLAMP (size, paned->min_position, paned->max_position); + paned->child1_size = CLAMP (e_paned_quantized_size(paned, size), paned->min_position, paned->max_position); e_vpaned_xor_line(paned); } -- cgit