Mercurial > dwindows
comparison gtk/dw.c @ 1511:9d342b67eed5
Switched to using built-in splitbar positioning for GTK2 like
was done earlier with GTK3. This resolves some issues I was
having with the old code... which is officially unsuported.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 28 Dec 2011 16:05:54 +0000 |
parents | 218c85939040 |
children | ff78ae1d7429 |
comparison
equal
deleted
inserted
replaced
1510:218c85939040 | 1511:9d342b67eed5 |
---|---|
11552 | 11552 |
11553 /* Reposition the bar according to the percentage */ | 11553 /* Reposition the bar according to the percentage */ |
11554 static gint _splitbar_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data) | 11554 static gint _splitbar_size_allocate(GtkWidget *widget, GtkAllocation *event, gpointer data) |
11555 { | 11555 { |
11556 float *percent = (float *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent"); | 11556 float *percent = (float *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent"); |
11557 int lastwidth = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), "_dw_lastwidth")); | |
11558 int lastheight = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(widget), "_dw_lastheight")); | |
11559 | 11557 |
11560 /* Prevent infinite recursion ;) */ | 11558 /* Prevent infinite recursion ;) */ |
11561 if(!percent || (lastwidth == event->width && lastheight == event->height)) | 11559 if(!percent || event->width < 20 || event->height < 20) |
11562 return FALSE; | 11560 return FALSE; |
11563 | 11561 |
11564 lastwidth = event->width; lastheight = event->height; | 11562 if(GTK_IS_HPANED(widget)) |
11565 | |
11566 gtk_object_set_data(GTK_OBJECT(widget), "_dw_lastwidth", GINT_TO_POINTER(lastwidth)); | |
11567 gtk_object_set_data(GTK_OBJECT(widget), "_dw_lastheight", GINT_TO_POINTER(lastheight)); | |
11568 | |
11569 if(GTK_IS_HPANED(widget)) | |
11570 gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * (*percent / 100.0))); | 11563 gtk_paned_set_position(GTK_PANED(widget), (int)(event->width * (*percent / 100.0))); |
11571 if(GTK_IS_VPANED(widget)) | 11564 if(GTK_IS_VPANED(widget)) |
11572 gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * (*percent / 100.0))); | 11565 gtk_paned_set_position(GTK_PANED(widget), (int)(event->height * (*percent / 100.0))); |
11573 gtk_object_set_data(GTK_OBJECT(widget), "_dw_waiting", NULL); | 11566 gtk_object_set_data(GTK_OBJECT(widget), "_dw_percent", NULL); |
11567 free(percent); | |
11574 return FALSE; | 11568 return FALSE; |
11575 } | 11569 } |
11576 | |
11577 #if GTK_MAJOR_VERSION > 1 | |
11578 /* Figure out the new percentage */ | |
11579 static void _splitbar_accept_position(GObject *object, GParamSpec *pspec, gpointer data) | |
11580 { | |
11581 GtkWidget *widget = (GtkWidget *)data; | |
11582 float *percent = (float *)gtk_object_get_data(GTK_OBJECT(widget), "_dw_percent"); | |
11583 int size = 0, position = gtk_paned_get_position(GTK_PANED(widget)); | |
11584 | |
11585 if(!percent || gtk_object_get_data(GTK_OBJECT(widget), "_dw_waiting")) | |
11586 return; | |
11587 | |
11588 if(GTK_IS_VPANED(widget)) | |
11589 size = widget->allocation.height; | |
11590 else if(GTK_IS_HPANED(widget)) | |
11591 size = widget->allocation.width; | |
11592 | |
11593 if(size > 0) | |
11594 *percent = ((float)(position * 100) / (float)size); | |
11595 } | |
11596 #endif | |
11597 | 11570 |
11598 /* | 11571 /* |
11599 * Creates a splitbar window (widget) with given parameters. | 11572 * Creates a splitbar window (widget) with given parameters. |
11600 * Parameters: | 11573 * Parameters: |
11601 * type: Value can be DW_VERT or DW_HORZ. | 11574 * type: Value can be DW_VERT or DW_HORZ. |
11613 DW_MUTEX_LOCK; | 11586 DW_MUTEX_LOCK; |
11614 if(type == DW_HORZ) | 11587 if(type == DW_HORZ) |
11615 tmp = gtk_hpaned_new(); | 11588 tmp = gtk_hpaned_new(); |
11616 else | 11589 else |
11617 tmp = gtk_vpaned_new(); | 11590 tmp = gtk_vpaned_new(); |
11618 gtk_paned_add1(GTK_PANED(tmp), topleft); | 11591 gtk_paned_pack1(GTK_PANED(tmp), topleft, TRUE, TRUE); |
11619 gtk_paned_add2(GTK_PANED(tmp), bottomright); | 11592 gtk_paned_pack2(GTK_PANED(tmp), bottomright, TRUE, TRUE); |
11620 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); | 11593 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_id", GINT_TO_POINTER(id)); |
11621 *percent = 50.0; | 11594 *percent = 50.0; |
11622 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_percent", (gpointer)percent); | 11595 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_percent", (gpointer)percent); |
11623 gtk_object_set_data(GTK_OBJECT(tmp), "_dw_waiting", GINT_TO_POINTER(1)); | |
11624 gtk_signal_connect(GTK_OBJECT(tmp), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_size_allocate), NULL); | 11596 gtk_signal_connect(GTK_OBJECT(tmp), "size-allocate", GTK_SIGNAL_FUNC(_splitbar_size_allocate), NULL); |
11625 #if GTK_MAJOR_VERSION > 1 | 11597 #if GTK_MAJOR_VERSION < 2 |
11626 g_signal_connect(G_OBJECT(tmp), "notify::position", (GCallback)_splitbar_accept_position, (gpointer)tmp); | |
11627 #else | |
11628 gtk_paned_set_handle_size(GTK_PANED(tmp), 3); | 11598 gtk_paned_set_handle_size(GTK_PANED(tmp), 3); |
11629 #endif | 11599 #endif |
11630 gtk_widget_show(tmp); | 11600 gtk_widget_show(tmp); |
11631 DW_MUTEX_UNLOCK; | 11601 DW_MUTEX_UNLOCK; |
11632 return tmp; | 11602 return tmp; |