From e90eea58a2109961faa8632ac5e5783d9970366b Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 25 May 2000 04:45:10 +0000 Subject: Made the handlebar disappear if either side is empty, hidden, or requests 2000-05-25 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: Made the handlebar disappear if either side is empty, hidden, or requests 0 size. svn path=/trunk/; revision=3198 --- widgets/e-paned/e-hpaned.c | 119 +++++++++++++++++++++++++++++---------------- widgets/e-paned/e-paned.c | 41 +++++++++++----- widgets/e-paned/e-paned.h | 5 ++ widgets/e-paned/e-vpaned.c | 118 ++++++++++++++++++++++++++++---------------- 4 files changed, 186 insertions(+), 97 deletions(-) (limited to 'widgets/e-paned') diff --git a/widgets/e-paned/e-hpaned.c b/widgets/e-paned/e-hpaned.c index b43630fff0..0729e7c84e 100644 --- a/widgets/e-paned/e-hpaned.c +++ b/widgets/e-paned/e-hpaned.c @@ -49,6 +49,7 @@ static gboolean e_hpaned_button_release (GtkWidget *widget, GdkEventButton *event); static gboolean e_hpaned_motion (GtkWidget *widget, GdkEventMotion *event); +static gboolean e_hpaned_handle_shown (EPaned *paned); GtkType e_hpaned_get_type (void) @@ -76,11 +77,13 @@ e_hpaned_get_type (void) } static void -e_hpaned_class_init (EHPanedClass *class) +e_hpaned_class_init (EHPanedClass *klass) { GtkWidgetClass *widget_class; + EPanedClass *paned_class; - widget_class = (GtkWidgetClass *) class; + widget_class = (GtkWidgetClass *) klass; + paned_class = E_PANED_CLASS (klass); widget_class->size_request = e_hpaned_size_request; widget_class->size_allocate = e_hpaned_size_allocate; @@ -88,6 +91,8 @@ e_hpaned_class_init (EHPanedClass *class) widget_class->button_press_event = e_hpaned_button_press; widget_class->button_release_event = e_hpaned_button_release; widget_class->motion_notify_event = e_hpaned_motion; + + paned_class->handle_shown = e_hpaned_handle_shown; } static void @@ -144,8 +149,11 @@ e_hpaned_size_request (GtkWidget *widget, requisition->width += child_requisition.width; } - requisition->width += GTK_CONTAINER (paned)->border_width * 2 + paned->handle_size; + + requisition->width += GTK_CONTAINER (paned)->border_width * 2; requisition->height += GTK_CONTAINER (paned)->border_width * 2; + if (e_paned_handle_shown(paned)) + requisition->width += paned->handle_size; } static void @@ -158,6 +166,7 @@ e_hpaned_size_allocate (GtkWidget *widget, GtkAllocation child1_allocation; GtkAllocation child2_allocation; gint border_width; + gboolean handle_shown; g_return_if_fail (widget != NULL); g_return_if_fail (E_IS_HPANED (widget)); @@ -167,42 +176,52 @@ e_hpaned_size_allocate (GtkWidget *widget, paned = E_PANED (widget); border_width = GTK_CONTAINER (paned)->border_width; - if (paned->child1) + if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) gtk_widget_get_child_requisition (paned->child1, &child1_requisition); else child1_requisition.width = 0; - if (paned->child2) + if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) gtk_widget_get_child_requisition (paned->child2, &child2_requisition); else child2_requisition.width = 0; e_paned_compute_position (paned, MAX (1, (gint) widget->allocation.width - - (gint) paned->handle_size - 2 * border_width), child1_requisition.width, child2_requisition.width); /* Move the handle before the children so we don't get extra expose events */ - - paned->handle_xpos = paned->child1_size + border_width; - paned->handle_ypos = border_width; - paned->handle_width = paned->handle_size; - paned->handle_height = MAX (1, (gint) widget->allocation.height - 2 * border_width); - - if (GTK_WIDGET_REALIZED (widget)) + + gdk_window_move_resize (widget->window, + allocation->x, allocation->y, + allocation->width, + allocation->height); + + handle_shown = e_paned_handle_shown(paned); + if (handle_shown) + { + paned->handle_xpos = paned->child1_size + border_width; + paned->handle_ypos = border_width; + paned->handle_width = paned->handle_size; + paned->handle_height = MAX (1, (gint) widget->allocation.height - 2 * border_width); + + if (GTK_WIDGET_REALIZED (widget)) + { + gdk_window_move_resize (paned->handle, + paned->handle_xpos, + paned->handle_ypos, + paned->handle_size, + paned->handle_height); + if (paned->handle) + gdk_window_show(paned->handle); + } + } + else { - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, - allocation->height); - - gdk_window_move_resize (paned->handle, - paned->handle_xpos, - paned->handle_ypos, - paned->handle_size, - paned->handle_height); + if (paned->handle && GTK_WIDGET_REALIZED (widget)) + gdk_window_hide(paned->handle); } child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2); @@ -210,7 +229,10 @@ e_hpaned_size_allocate (GtkWidget *widget, child1_allocation.x = border_width; child1_allocation.y = child2_allocation.y = border_width; - child2_allocation.x = child1_allocation.x + child1_allocation.width + paned->handle_width; + if (handle_shown) + child2_allocation.x = child1_allocation.x + child1_allocation.width + paned->handle_width; + else + child2_allocation.x = child1_allocation.x + child1_allocation.width; child2_allocation.width = MAX (1, (gint) allocation->width - child2_allocation.x - border_width); /* Now allocate the childen, making sure, when resizing not to @@ -252,26 +274,29 @@ e_hpaned_draw (GtkWidget *widget, area->x, area->y, area->width, area->height); - handle_area.x = paned->handle_xpos; - handle_area.y = paned->handle_ypos; - handle_area.width = paned->handle_size; - handle_area.height = paned->handle_height; - - if (gdk_rectangle_intersect (&handle_area, area, &child_area)) + if (e_paned_handle_shown(paned)) { - child_area.x -= paned->handle_xpos; - child_area.y -= paned->handle_ypos; - - gtk_paint_handle (widget->style, - paned->handle, - GTK_STATE_NORMAL, - GTK_SHADOW_NONE, - &child_area, - widget, - "paned", - 0, 0, -1, -1, - GTK_ORIENTATION_VERTICAL); - + handle_area.x = paned->handle_xpos; + handle_area.y = paned->handle_ypos; + handle_area.width = paned->handle_size; + handle_area.height = paned->handle_height; + + if (gdk_rectangle_intersect (&handle_area, area, &child_area)) + { + child_area.x -= paned->handle_xpos; + child_area.y -= paned->handle_ypos; + + gtk_paint_handle (widget->style, + paned->handle, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + &child_area, + widget, + "paned", + 0, 0, -1, -1, + GTK_ORIENTATION_VERTICAL); + + } } /* Redraw the children */ @@ -401,3 +426,11 @@ e_hpaned_motion (GtkWidget *widget, return TRUE; } + +static gboolean +e_hpaned_handle_shown (EPaned *paned) +{ + return ((paned->child1 && paned->child2) && + (GTK_WIDGET_VISIBLE (paned->child1) && GTK_WIDGET_VISIBLE (paned->child2)) && + (GTK_WIDGET(paned->child1)->requisition.width > 0 && GTK_WIDGET(paned->child2)->requisition.width > 0)); +} diff --git a/widgets/e-paned/e-paned.c b/widgets/e-paned/e-paned.c index f2db002e6e..5d09535ad9 100644 --- a/widgets/e-paned/e-paned.c +++ b/widgets/e-paned/e-paned.c @@ -92,15 +92,15 @@ e_paned_get_type (void) } static void -e_paned_class_init (EPanedClass *class) +e_paned_class_init (EPanedClass *klass) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; + object_class = (GtkObjectClass *) klass; + widget_class = (GtkWidgetClass *) klass; + container_class = (GtkContainerClass *) klass; parent_class = gtk_type_class (GTK_TYPE_CONTAINER); @@ -118,6 +118,8 @@ e_paned_class_init (EPanedClass *class) container_class->forall = e_paned_forall; container_class->child_type = e_paned_child_type; + klass->handle_shown = NULL; + gtk_object_add_arg_type("EPaned::handle_size", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_HANDLE_SIZE); } @@ -239,7 +241,8 @@ e_paned_realize (GtkWidget *widget) gdk_window_set_back_pixmap (widget->window, NULL, TRUE); - gdk_window_show (paned->handle); + if (e_paned_handle_shown(paned)) + gdk_window_show (paned->handle); } static void @@ -255,7 +258,7 @@ e_paned_map (GtkWidget *widget) if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && - !GTK_WIDGET_MAPPED (paned->child1)) + !GTK_WIDGET_MAPPED (paned->child1)) gtk_widget_map (paned->child1); if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2) && @@ -318,12 +321,15 @@ e_paned_expose (GtkWidget *widget, { paned = E_PANED (widget); - if (event->window == paned->handle) + if (paned->handle && event->window == paned->handle) { - child_event = *event; - event->area.x += paned->handle_xpos; - event->area.y += paned->handle_ypos; - gtk_widget_draw (widget, &event->area); + if (e_paned_handle_shown(paned)) + { + child_event = *event; + event->area.x += paned->handle_xpos; + event->area.y += paned->handle_ypos; + gtk_widget_draw (widget, &event->area); + } } else { @@ -547,6 +553,9 @@ e_paned_compute_position(EPaned *paned, { g_return_if_fail (paned != NULL); g_return_if_fail (E_IS_PANED (paned)); + + if (e_paned_handle_shown(paned)) + allocation -= (gint) paned->handle_size; paned->min_position = paned->child1_shrink ? 0 : child1_req; @@ -585,3 +594,13 @@ e_paned_compute_position(EPaned *paned, paned->last_allocation = allocation; } + +gboolean +e_paned_handle_shown(EPaned *paned) +{ + EPanedClass *klass = E_PANED_CLASS(GTK_OBJECT(paned)->klass); + if (klass->handle_shown) + return (*klass->handle_shown)(paned); + else + return TRUE; +} diff --git a/widgets/e-paned/e-paned.h b/widgets/e-paned/e-paned.h index 2b07a24bda..1c4481b194 100644 --- a/widgets/e-paned/e-paned.h +++ b/widgets/e-paned/e-paned.h @@ -90,6 +90,9 @@ struct _EPaned struct _EPanedClass { GtkContainerClass parent_class; + + /* Protected virtual method. */ + gboolean (*handle_shown) (EPaned *paned); }; @@ -117,6 +120,8 @@ void e_paned_compute_position (EPaned *paned, gint allocation, gint child1_req, gint child2_req); + +gboolean e_paned_handle_shown (EPaned *paned); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/widgets/e-paned/e-vpaned.c b/widgets/e-paned/e-vpaned.c index 9a71b9acd9..9eb9407a23 100644 --- a/widgets/e-paned/e-vpaned.c +++ b/widgets/e-paned/e-vpaned.c @@ -49,6 +49,7 @@ static gboolean e_vpaned_button_release (GtkWidget *widget, GdkEventButton *event); static gboolean e_vpaned_motion (GtkWidget *widget, GdkEventMotion *event); +static gboolean e_vpaned_handle_shown (EPaned *paned); GtkType e_vpaned_get_type (void) @@ -76,11 +77,13 @@ e_vpaned_get_type (void) } static void -e_vpaned_class_init (EVPanedClass *class) +e_vpaned_class_init (EVPanedClass *klass) { GtkWidgetClass *widget_class; + EPanedClass *paned_class; - widget_class = (GtkWidgetClass *) class; + widget_class = (GtkWidgetClass *) klass; + paned_class = E_PANED_CLASS (klass); widget_class->size_request = e_vpaned_size_request; widget_class->size_allocate = e_vpaned_size_allocate; @@ -88,6 +91,8 @@ e_vpaned_class_init (EVPanedClass *class) widget_class->button_press_event = e_vpaned_button_press; widget_class->button_release_event = e_vpaned_button_release; widget_class->motion_notify_event = e_vpaned_motion; + + paned_class->handle_shown = e_vpaned_handle_shown; } static void @@ -115,7 +120,7 @@ e_vpaned_new (void) static void e_vpaned_size_request (GtkWidget *widget, - GtkRequisition *requisition) + GtkRequisition *requisition) { EPaned *paned; GtkRequisition child_requisition; @@ -144,13 +149,15 @@ e_vpaned_size_request (GtkWidget *widget, requisition->height += child_requisition.height; } - requisition->height += GTK_CONTAINER (paned)->border_width * 2 + paned->handle_size; + requisition->height += GTK_CONTAINER (paned)->border_width * 2; requisition->width += GTK_CONTAINER (paned)->border_width * 2; + if (e_paned_handle_shown(paned)) + requisition->height += paned->handle_size; } static void e_vpaned_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) + GtkAllocation *allocation) { EPaned *paned; GtkRequisition child1_requisition; @@ -158,6 +165,7 @@ e_vpaned_size_allocate (GtkWidget *widget, GtkAllocation child1_allocation; GtkAllocation child2_allocation; gint border_width; + gboolean handle_shown; g_return_if_fail (widget != NULL); g_return_if_fail (E_IS_VPANED (widget)); @@ -167,42 +175,52 @@ e_vpaned_size_allocate (GtkWidget *widget, paned = E_PANED (widget); border_width = GTK_CONTAINER (widget)->border_width; - if (paned->child1) + if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) gtk_widget_get_child_requisition (paned->child1, &child1_requisition); else child1_requisition.height = 0; - if (paned->child2) + if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) gtk_widget_get_child_requisition (paned->child2, &child2_requisition); else child2_requisition.height = 0; e_paned_compute_position (paned, MAX (1, (gint) widget->allocation.height - - (gint) paned->handle_size - 2 * border_width), child1_requisition.height, child2_requisition.height); /* Move the handle before the children so we don't get extra expose events */ - paned->handle_xpos = border_width; - paned->handle_ypos = paned->child1_size + border_width; - paned->handle_width = MAX (1, (gint) widget->allocation.width - 2 * border_width); - paned->handle_height = paned->handle_size; + gdk_window_move_resize (widget->window, + allocation->x, allocation->y, + allocation->width, + allocation->height); + + handle_shown = e_paned_handle_shown(paned); + if (handle_shown) + { + paned->handle_xpos = border_width; + paned->handle_ypos = paned->child1_size + border_width; + paned->handle_width = MAX (1, (gint) widget->allocation.width - 2 * border_width); + paned->handle_height = paned->handle_size; - if (GTK_WIDGET_REALIZED(widget)) + if (GTK_WIDGET_REALIZED(widget)) + { + gdk_window_move_resize (paned->handle, + paned->handle_xpos, + paned->handle_ypos, + paned->handle_width, + paned->handle_size); + if (paned->handle) + gdk_window_show(paned->handle); + } + } + else { - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, - allocation->height); - - gdk_window_move_resize (paned->handle, - paned->handle_xpos, - paned->handle_ypos, - paned->handle_width, - paned->handle_size); + if (paned->handle && GTK_WIDGET_REALIZED (widget)) + gdk_window_hide(paned->handle); } child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2); @@ -210,7 +228,10 @@ e_vpaned_size_allocate (GtkWidget *widget, child1_allocation.x = child2_allocation.x = border_width; child1_allocation.y = border_width; - child2_allocation.y = child1_allocation.y + child1_allocation.height + paned->handle_height; + if (handle_shown) + child2_allocation.y = child1_allocation.y + child1_allocation.height + paned->handle_height; + else + child2_allocation.y = child1_allocation.y + child1_allocation.height; child2_allocation.height = MAX(1, (gint) allocation->height - child2_allocation.y - border_width); /* Now allocate the childen, making sure, when resizing not to @@ -252,26 +273,29 @@ e_vpaned_draw (GtkWidget *widget, area->x, area->y, area->width, area->height); - handle_area.x = paned->handle_xpos; - handle_area.y = paned->handle_ypos; - handle_area.width = paned->handle_width; - handle_area.height = paned->handle_size; - - if (gdk_rectangle_intersect (&handle_area, area, &child_area)) + if (e_paned_handle_shown(paned)) { - child_area.x -= paned->handle_xpos; - child_area.y -= paned->handle_ypos; - - gtk_paint_handle (widget->style, - paned->handle, - GTK_STATE_NORMAL, - GTK_SHADOW_NONE, - &child_area, - widget, - "paned", - 0, 0, -1, -1, - GTK_ORIENTATION_HORIZONTAL); - + handle_area.x = paned->handle_xpos; + handle_area.y = paned->handle_ypos; + handle_area.width = paned->handle_width; + handle_area.height = paned->handle_size; + + if (gdk_rectangle_intersect (&handle_area, area, &child_area)) + { + child_area.x -= paned->handle_xpos; + child_area.y -= paned->handle_ypos; + + gtk_paint_handle (widget->style, + paned->handle, + GTK_STATE_NORMAL, + GTK_SHADOW_NONE, + &child_area, + widget, + "paned", + 0, 0, -1, -1, + GTK_ORIENTATION_HORIZONTAL); + + } } /* Redraw the children */ @@ -401,3 +425,11 @@ e_vpaned_motion (GtkWidget *widget, return TRUE; } + +static gboolean +e_vpaned_handle_shown (EPaned *paned) +{ + return ((paned->child1 && paned->child2) && + (GTK_WIDGET_VISIBLE (paned->child1) && GTK_WIDGET_VISIBLE (paned->child2)) && + (GTK_WIDGET(paned->child1)->requisition.height > 0 && GTK_WIDGET(paned->child2)->requisition.height > 0)); +} -- cgit v1.2.3